Summarise operational days by user-defined seasons
Source:R/cam_summarise_op_by_season.R
cam_summarise_op_by_season.RdTakes the output from cam_get_op_days() and sums the number of
operational days per season. Seasons are defined
by Julian day start cutoffs and can be 1..n segments that wrap the year.
Arguments
- calendar_df
A tibble/data.frame with at least
date(Date) andoperating(logical/NA), typically the output ofcam_get_op_days().- grouping
Character vector of grouping columns to keep in the summary. Defaults to
c("project","project_id","location","location_id"); only columns present are used. If none are present, aggregation is global.- seasons
Season starts. Named numeric, unnamed numeric +
labels, or a data frame withseasonandstartcolumns. Defaults toc(spring = 99, summer = 143, winter = 288).- labels
Optional labels if
seasonsis an unnamed numeric vector.- date_col
Name of the date column in
calendar_df. Default"date".- operating_col
Name of the logical operating column. Default
"operating".- na_as
Logical: treat
NAinoperatingas TRUE when counting? DefaultFALSE.- by_year
Logical: also summarise by calendar year? Default
FALSE.- wide
Logical: return one column per season (
TRUE) or a long table withseasonandoperating_days(FALSE). DefaultTRUE.
Value
A tibble. In wide mode: grouping cols (+ year if by_year),
one column per season (counts), and total_days (row sum). In long mode:
grouping cols (+ year), season, operating_days, and total_days.
Details
Season definitions (seasons) can be supplied in any of these forms:
Named numeric vector (recommended): e.g.,
c(spring = 99, summer = 143, winter = 288).Unnamed numeric +
labels=: e.g.,seasons = c(99, 143, 288), labels = c("spring","summer","winter").Data frame with columns
season(labels) andstart(Julian day).
Rules:
Starts must be integers in
1..366, unique, and will be sorted.Classification is circular: the last season runs to day 366, then wraps to the first start.
Grouping: By default the function looks for c("project","project_id","location", "location_id)
but only use the ones actually present in calendar_df. If none are present,
the result is aggregated across all records.
Operating NA handling: By default operating = NA is counted as FALSE
(na_as = FALSE). Set na_as = TRUE to count unknown days as operational.
Examples
if (FALSE) { # \dontrun{
cal <- cam_get_op_days(image_reports,
grouping = c("project_id","location","location_id"),
span = "operational", missing_as = FALSE)
# Default seasons, by year, wide format
sum1 <- cam_summarise_op_by_season(cal, by_year = TRUE, wide = TRUE)
# Two-season example, long format
sum2 <- cam_summarise_op_by_season(
calendar_df = cal,
seasons = c(IceFree = 120, FreezeUp = 305),
by_year = FALSE,
wide = FALSE
)
} # }