Skip to contents

This function estimates twilight (i.e., datetime of sunrise and sunset) by searching for the first and last light of the day which is defined as the time when light exceeds or falls below the light threshold twl_thr.

Usage

twilight_create(
  tag,
  twl_thr = NULL,
  twl_offset = NULL,
  transform_light = TRUE,
  twl_time_tolerance = 180
)

Arguments

tag

a GeoPressureR tag object.

twl_thr

Light threshold that defines twilight. By default (NULL), it uses the smallest value of light (i.e, first and last light of day). When transform_light = TRUE, twl_thr is expressed on the transformed light scale.

twl_offset

Shift of the middle of the night compared to 00:00 UTC (in hours). If not provided, it uses the middle of all nights.

transform_light

logical to use a log transformation of light

twl_time_tolerance

Maximum allowed time difference in seconds between observations and the regular grid. Observations beyond this threshold will be set to NA. Default is 180 seconds (3 minutes). Half the sampling interval is always allowed, so that drift-corrected timestamps sliding against the grid are kept.

Value

a tag list containing a new data.frame twilight with columns:

  • twilight (date-time of twilight)

  • rise (logical) indicating sunrise (TRUE) or sunset (FALSE).

  • stap_id if tag$stap exists.

Examples

withr::with_dir(system.file("extdata", package = "GeoPressureR"), {
  tag <- tag_create("18LX", quiet = TRUE) |> tag_label(quiet = TRUE)
})

# Create twilight data.frame
tag <- twilight_create(tag)

str(tag$twilight)
#> 'data.frame':	28 obs. of  3 variables:
#>  $ twilight: POSIXct, format: "2017-07-27 03:05:00" "2017-07-27 18:30:00" ...
#>  $ rise    : logi  TRUE FALSE TRUE FALSE TRUE FALSE ...
#>  $ stap_id : num  1 1 1 1 1 1 1 1 1 1 ...

plot(tag, type = "twilight")