| Title: | Automated Calibration and Analysis of GLS (Global Location Sensor) Data |
|---|---|
| Description: | Provides a fully automated workflow for calibrating and analyzing light-level geolocation (GLS) data from seabirds and other wildlife. The package auto-discovers birds from directory structures, automatically detects calibration periods from the first days of deployment, processes multiple individuals in batch mode, and generates standardized outputs including position estimates, diagnostic plots, and quality control metrics. Implements the established threshold workflow internally, following the methods described in SGAT, GeoLight, and TwGeos. |
| Authors: | Fabio Favoretto [aut, cre] (ORCID: <https://orcid.org/0000-0002-6493-4254>), Cecilia Soldatini [aut] (ORCID: <https://orcid.org/0000-0002-8112-3162>) |
| Maintainer: | Fabio Favoretto <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-12 07:49:49 UTC |
| Source: | https://github.com/fabbiologia/glscalibrator |
Automatically detects a suitable calibration period from the beginning of the light data. This assumes the bird was at a known location (typically the colony) at the start of deployment.
auto_detect_calibration( light_data, colony_lat, colony_lon, threshold = 2, min_twilights = 2 )auto_detect_calibration( light_data, colony_lat, colony_lon, threshold = 2, min_twilights = 2 )
light_data |
A data.frame with columns |
colony_lat |
Numeric latitude of known calibration location |
colony_lon |
Numeric longitude of known calibration location |
threshold |
Light threshold for twilight detection (default: 2) |
min_twilights |
Minimum number of twilights required (default: 2) |
The function tries calibration periods of different lengths (2, 3, 1, 4, 5 days) and returns the first period that yields sufficient twilights with both sunrise and sunset events.
A list with:
start |
POSIXct start of calibration period |
end |
POSIXct end of calibration period |
twilights |
Number of twilights detected |
duration_days |
Duration in days |
# Auto-detect calibration from example data (requires SGAT) example_file <- gls_example("W086") light_data <- read_lux_file(example_file) calib <- auto_detect_calibration(light_data, colony_lat = 27.85, colony_lon = -115.17) print(calib)# Auto-detect calibration from example data (requires SGAT) example_file <- gls_example("W086") light_data <- read_lux_file(example_file) calib <- auto_detect_calibration(light_data, colony_lat = 27.85, colony_lon = -115.17) print(calib)
Main function for automated batch processing of GLS data. Auto-discovers all birds in a directory, detects calibration periods, performs an internal gamma-style sun elevation calibration, and generates standardized outputs.
calibrate_gls_batch( data_dir, output_dir, colony_lat, colony_lon, light_threshold = 2, exclude_equinoxes = NULL, min_positions = 10, create_plots = TRUE, verbose = TRUE )calibrate_gls_batch( data_dir, output_dir, colony_lat, colony_lon, light_threshold = 2, exclude_equinoxes = NULL, min_positions = 10, create_plots = TRUE, verbose = TRUE )
data_dir |
Character path to directory containing .lux files |
output_dir |
Character path for output files |
colony_lat |
Numeric latitude of colony/capture location |
colony_lon |
Numeric longitude of colony/capture location |
light_threshold |
Numeric light threshold in lux (default: 2) |
exclude_equinoxes |
List of date ranges to exclude (optional) |
min_positions |
Minimum number of valid positions required (default: 10) |
create_plots |
Logical, whether to create diagnostic plots (default: TRUE) |
verbose |
Logical, print progress messages (default: TRUE) |
This function implements a complete automated workflow:
Auto-discovers .lux files in the data directory
For each bird:
Reads light data
Auto-detects calibration period
Detects and filters twilights
Learns a sun elevation angle directly from the calibration data
Calculates positions using threshold method
Generates diagnostic plots
Combines results into standardized formats
Creates summary statistics and quality control metrics
A list containing:
summary |
data.frame with calibration summary for all birds |
results |
List of position estimates for each bird |
processing_log |
Detailed processing log |
## Not run: # Basic usage results <- calibrate_gls_batch( data_dir = "data/raw/birds", output_dir = "data/processed/calibration", colony_lat = 27.85178, colony_lon = -115.17390 ) # With equinox exclusions equinoxes <- list( c("2024-08-24", "2024-10-23"), c("2024-02-19", "2024-04-19") ) results <- calibrate_gls_batch( data_dir = "data/raw/birds", output_dir = "data/processed/calibration", colony_lat = 27.85, colony_lon = -115.17, exclude_equinoxes = equinoxes ) ## End(Not run)## Not run: # Basic usage results <- calibrate_gls_batch( data_dir = "data/raw/birds", output_dir = "data/processed/calibration", colony_lat = 27.85178, colony_lon = -115.17390 ) # With equinox exclusions equinoxes <- list( c("2024-08-24", "2024-10-23"), c("2024-02-19", "2024-04-19") ) results <- calibrate_gls_batch( data_dir = "data/raw/birds", output_dir = "data/processed/calibration", colony_lat = 27.85, colony_lon = -115.17, exclude_equinoxes = equinoxes ) ## End(Not run)
Converts calibrated position data to the standard GLSmerge format used by many researchers and analysis tools.
convert_to_glsmerge(results, bird_id, zenith)convert_to_glsmerge(results, bird_id, zenith)
results |
data.frame of position estimates |
bird_id |
Character ID of the bird |
zenith |
Numeric zenith angle used for calibration |
data.frame in GLSmerge format
Detects sunrise and sunset times from light intensity data using a threshold-crossing method. This is a proven, simple approach that identifies transitions between day and night.
detect_twilights(light_data, threshold = 2)detect_twilights(light_data, threshold = 2)
light_data |
A data.frame with columns |
threshold |
Numeric light threshold in lux for day/night distinction (default: 2) |
A data.frame with columns:
Twilight |
POSIXct datetime of twilight event |
Rise |
Logical, TRUE for sunrise, FALSE for sunset |
# Detect twilights from example data example_file <- gls_example("W086") light_data <- read_lux_file(example_file) twilights <- detect_twilights(light_data, threshold = 2) head(twilights)# Detect twilights from example data example_file <- gls_example("W086") light_data <- read_lux_file(example_file) twilights <- detect_twilights(light_data, threshold = 2) head(twilights)
Uses observed calibration twilights at a known location to learn the sun elevation angle required by the threshold method. The calculation minimizes the median absolute difference between observed and predicted twilights using the NOAA solar equations.
estimate_sun_elevation(twilight, rise, lon, lat, interval = c(-12, 2))estimate_sun_elevation(twilight, rise, lon, lat, interval = c(-12, 2))
twilight |
POSIXct vector of twilight times from the calibration period. |
rise |
Logical vector marking whether each event is a sunrise (TRUE) or sunset (FALSE). |
lon, lat
|
Numeric longitude and latitude of the calibration site. |
interval |
Numeric length-two vector giving the search interval (in degrees) for the sun elevation. |
Named numeric vector containing the inferred zenith angle ('z1'), the sun elevation ('degElevation'), and the objective value.
Applies quality filters to twilight data to remove spurious detections caused by shading, logger malfunction, or other artifacts.
filter_twilights(twilights, light_data = NULL, threshold = 2, strict = TRUE)filter_twilights(twilights, light_data = NULL, threshold = 2, strict = TRUE)
twilights |
A data.frame with columns |
light_data |
The original light data (optional, for quality checks) |
threshold |
Light threshold used for twilight detection |
strict |
Logical, if TRUE applies stricter filtering (default: TRUE) |
Filters applied:
Remove twilights too close together (< 1-2 hours)
Remove twilights with unusual intervals (far from 12 or 24 hours)
Optionally check light quality around twilight (if light_data provided)
A filtered data.frame of twilights
# Filter twilights from example data example_file <- gls_example("W086") light_data <- read_lux_file(example_file) twilights <- detect_twilights(light_data, threshold = 2) twilights_clean <- filter_twilights(twilights, light_data, threshold = 2) nrow(twilights_clean)# Filter twilights from example data example_file <- gls_example("W086") light_data <- read_lux_file(example_file) twilights <- detect_twilights(light_data, threshold = 2) twilights_clean <- filter_twilights(twilights, light_data, threshold = 2) nrow(twilights_clean)
Helper function to get the path to example .lux files included with the package.
Three example files are available and their metadata is exposed via
glscalibrator_example_metadata.
gls_example(which = "all")gls_example(which = "all")
which |
Character string specifying which example file:
|
Character vector of file path(s) to example data
# Inspect available example datasets list_gls_examples() # Read the bundled W086 seabird deployment light_data <- read_lux_file(gls_example("W086")) # Run calibration on the synthetic dataset (quick demo) synt_path <- gls_example("synthetic") synthetic_data <- read_lux_file(synt_path) twl <- detect_twilights(synthetic_data, threshold = 2)# Inspect available example datasets list_gls_examples() # Read the bundled W086 seabird deployment light_data <- read_lux_file(gls_example("W086")) # Run calibration on the synthetic dataset (quick demo) synt_path <- gls_example("synthetic") synthetic_data <- read_lux_file(synt_path) twl <- detect_twilights(synthetic_data, threshold = 2)
The package ships with three light-level geolocation (.lux) files that are used throughout the documentation, vignettes, and tests. This metadata table records their origin and recommended use so that analysts can reference the contents programmatically.
Named character vector of the filenames stored in
inst/extdata/, keyed by the identifiers recognised by
gls_example().
glscalibrator_example_metadata glscalibrator_example_filesglscalibrator_example_metadata glscalibrator_example_files
A data frame with 3 rows and 7 variables:
Short identifier used by gls_example()
Filename stored under inst/extdata/
"real" or "synthetic" dataset
Summary of the dataset contents
Approximate deployment duration represented
Approximate file size in kilobytes
Additional guidance for analysis and demonstrations
A data frame (tibble) with metadata for each example dataset.
Named character vector. Use with system.file("extdata", ...).
All files are plain-text .lux exports that can be read directly with
read_lux_file(). Real datasets were collected from tropical seabirds
breeding near 27.85°N, 115.17°W and are approved for demonstration and
teaching purposes. The synthetic dataset contains idealised sunrise/sunset
curves for rapid testing.
gls_example(), list_gls_examples()
Shows information about example datasets included with the package.
list_gls_examples()list_gls_examples()
A data.frame with columns: name, file, type,
description, duration_days, size_kb, notes
list_gls_examples()list_gls_examples()
Creates diagnostic plots showing light data and detected twilights during the calibration period.
plot_calibration(light_data, twilights, threshold, bird_id, output_dir)plot_calibration(light_data, twilights, threshold, bird_id, output_dir)
light_data |
data.frame with Date and Light columns |
twilights |
data.frame with Twilight and Rise columns |
threshold |
Numeric light threshold |
bird_id |
Character ID for plot title |
output_dir |
Directory to save plot |
NULL (creates PNG file)
Creates a map showing the estimated movement track of a bird
plot_track( results, colony_lat, colony_lon, bird_id, output_dir, hemisphere = "" )plot_track( results, colony_lat, colony_lon, bird_id, output_dir, hemisphere = "" )
results |
data.frame with Latitude and Longitude columns |
colony_lat |
Numeric latitude of colony |
colony_lon |
Numeric longitude of colony |
bird_id |
Character ID for plot title |
output_dir |
Directory to save plot |
hemisphere |
Character hemisphere check result |
NULL (creates PNG file)
Reads and parses light intensity data from .lux files generated by geolocation loggers. Handles various formats and automatically detects the start of data.
read_lux_file(file_path)read_lux_file(file_path)
file_path |
Character string specifying the path to the .lux file |
A data.frame with columns:
Date |
POSIXct datetime in UTC |
Light |
Numeric light intensity in lux |
# Read example data included with package example_file <- gls_example("W086") light_data <- read_lux_file(example_file) head(light_data)# Read example data included with package example_file <- gls_example("W086") light_data <- read_lux_file(example_file) head(light_data)