Add a time component to input
add_time_to_weather_data.RdEnsure, if possible, that input data that varies over time has a "time"
component. See the documentation for time for more information
about this quantity.
It is rare for users to call this function directly because it is called
internally by run_biocro.
Value
If drivers has doy and hour columns, then it is assumed
to represent weather data, and will be modified as follows:
A new
timecolumn will be computed fromdoyandhour.The original
doyandhourcolumns will be removed.
In this case, it is expected that the BioCro:format_time direct module
will be used to re-compute doy and hour from time.
If drivers does not have doy and hour columns, then
drivers will be returned as-is.
Note
Preconditions:
If
driversis a list, the values should be vectors of equal length.If
driversalready contains atimecomponent, then it shouldn't contain either adoyor anhourcomponent unless it contains both of them and the values are mutually consistent.
Why is the 'BioCro:format_time' module necessary?
If values of doy and hour are supplied to run_biocro in
the drivers, undesired results may happen during interpolation. For example,
if two sequential rows have (time = 3599, doy = 150, hour = 23) and
(time = 3600, doy = 151, hour = 0), and the results are to be returned
at half-hour time intervals, then linear interpolation between these rows
would produce (time = 3599.5, doy = 150.5, hour = 11.5). Typically it
is expected that doy takes only integer values, so this may cause
issues. Using the BioCro:format_time module to calculate doy and
hour from time will ensure that the result includes
(time = 3599.5, doy = 150, hour = 23.5) instead.
Examples
# Add a time column to the buit-in 2002 weather data
new_weather <- add_time_to_weather_data(weather[['2002']])
# Compare column names
colnames(weather[['2002']])
#> [1] "year" "doy" "hour" "time_zone_offset"
#> [5] "precip" "rh" "solar" "temp"
#> [9] "windspeed"
colnames(new_weather)
#> [1] "year" "time_zone_offset" "precip" "rh"
#> [5] "solar" "temp" "windspeed" "time"