bright_dark_period: Brightest or darkest continuous period

View source: R/bright_dark_period.R

bright_dark_periodR Documentation

Brightest or darkest continuous period

Description

This function finds the brightest or darkest continuous period of a given timespan and calculates its mean light level, onset, midpoint, and offset. Defined as the period with the maximum or minimum mean light level.

Usage

bright_dark_period(
  lightVar,
  timeVar,
  period_type,
  timespan,
  sampling_int,
  loop = FALSE,
  as_df = TRUE,
  wide = TRUE
)

Arguments

lightVar

Numeric vector containing the light data.

timeVar

Vector containing the time data. Can be POSIXct or numeric.

period_type

String indicating the type of period. Must be "bright" or "dark".

timespan

Single string or vector of strings with the timespan(s). Timespans must be in the format "[numeric] [unit]", with possible units ("seconds","minutes","hours","days"). Units can be abbreviated. See parse_timeunit_tosecs.

sampling_int

Numeric. Sampling interval in seconds.

loop

Logical. Should the data be looped? Defaults to FALSE.

as_df

Logical. Should the output be returned as a data frame? Defaults to TRUE.

wide

Logical. Should the output be returned in wide format? Defaults to TRUE.

Details

Assumes regular 24h light data. Otherwise, results may not be meaningful. Looping the data is recommended for finding the darkest period. Missing light values will be removed by default.

Value

Data frame or matrix with pairs of timespan and calculated values. If wide is TRUE then variable names will be concatenated with the timespan.


steffenhartmeyer/lightdosimetry documentation built on Jan. 29, 2024, 12:48 p.m.