mc_agg | R Documentation |
mc_agg has two basic uses:
aggregate (upscale) time step of microclimatic records with specified function (e. g. 15 min records to daily mean);
convert myClim object from Raw-format to Agg-format see myClim-package without time-series modification,
this behavior appears when fun=NULL
, period=NULL
.
mc_agg(
data,
fun = NULL,
period = NULL,
use_utc = TRUE,
percentiles = NULL,
min_coverage = 1,
custom_start = NULL,
custom_end = NULL,
custom_functions = NULL
)
data |
cleaned myClim object in Raw-format: output of |
fun |
aggregation function; one of ( |
period |
Time period for aggregation - same as breaks in cut.POSIXt, e.g. ( There are special periods Start day of week is Monday. |
use_utc |
default TRUE using UTC time, if set FALSE, the time is shifted by offset if available in locality metadata.
Shift can be e.g. to solar time |
percentiles |
vector of percentile numbers; numbers are from range 0-100; each specified percentile number generate new virtual sensor, see details |
min_coverage |
value from range 0-1 (default 1); the threshold specifying how many missing values can you accept within aggregation period.
e.g. when aggregating from 15 min to monthly mean and set |
custom_start |
date of start, only use for |
custom_end |
date of end only use for |
custom_functions |
user define one or more functions in format |
Any output of mc_agg is in Agg-format. That means the hierarchical level of logger is removed (Locality<-Logger<-Sensor<-Record), and all microclimatic records within the sensors are on the level of locality (Locality<-Sensor<-Record). See myClim-package.
In case mc_agg()
is used only for conversion from Raw-format to Agg-format (fun=NULL, period=NULL
) then microclimatic
records are not modified. Equal step in all sensors is required for conversion from Raw-format to Agg-format, otherwise
period must be specified.
When fun and period are specified, microclimatic records are aggregated based on a selected function into a specified period.
The name of the aggregated variable will contain also the name of the function used for the aggregation (e.g. TMS_T1_mean).
Aggregated time step is named after the first time step of selected period i.e. day = c(2022-12-29 00:00, 2022-12-30 00:00...);
week = c(2022-12-19 00:00, 2022-12-28 00:00...); month = c(2022-11-01 00:00, 2022-12-01 00:00...);
year = c(2021-01-01 00:00, 2022-01-01 00:00...).
When first or last period is incomplete in original data, the incomplete part is extended with NA values to match specified period.
For example, when you want to aggregate time-series to monthly mean, but your time-series starts on January 15 ending December 20,
myClim will extend the time-series to start on January 1 and end on December 31.
If you want to still use the data from the aggregation periods with not complete data coverage, you can adjust the parameter min_coverage
.
Empty sensors with no records are excluded. mc_agg()
return NA for empty vector except from fun=count
which returns 0.
When aggregation functions are provided as vector or list e.g. c(mean, min, max), than they are all applied to all the sensors
and multiple results are returned from each sensors. When named list (names are the sensor ids) of functions is provided then mc_agg()
apply specific functions to the specific sensors based on the named list list(TMS_T1=c("max", "min"), TMS_T2="mean")
.
mc_agg returns new sensors on the localities putting aggregation
function in its name (TMS_T1 -> TMS_T1_max), despite sensor names contains aggregation
function, sensor_id stays the same as before aggregation in sensor metadata (e.g. TMS_T1 -> TMS_T1).
Sensors created with functions min
, max
, mean
, percentile
, sum
, range
keeps identical sensor_id and value_type as original input sensors.
When function sum
is applied on logical
sensor (e.g. snow as TRUE, FALSE) the
output is integer
i.e. number of TRUE
values.
Sensors created with functions count
has sensor_id count
and value_type integer
,
function coverage
has sensor_id coverage
and value_type real
If the myClim object contains any states (tags) table, such as error tags or quality tags, the datetime defining the start and end of the tag will be rounded according to the aggregation period parameter.
Returns new myClim object in Agg-format see myClim-package When fun=NULL, period=NULL records are not modified but only converted to Agg-format. When fun and period are provided then time step is aggregated based on function.
hour_data <- mc_agg(mc_data_example_clean, c("min", "max", "percentile"),
"hour", percentiles = 50, min_coverage=0.5)
day_data <- mc_agg(mc_data_example_clean, list(TMS_T1=c("max", "min"), TMS_T2="mean"),
"day", min_coverage=1)
month_data <- mc_agg(mc_data_example_clean, fun=list(TMS_T3="below5"),period = "month",
custom_functions = list(below5=function(x){length(x[x<(-5)])}))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.