rvn_apply_wyearly calculates a function FUN for the periods defined by the water year, similar to other functions of the form apply.<time period>, for example apply.daily, apply.monthly, etc.
rvn_apply_wyearly(x, FUN, ..., mm = 9, dd = 30)
xts vector to calculate FUN for
the function to be applied
optional arguments to FUN
month of water year ending (default 9)
day of water year ending (default 30)
The default water year start is October 1st, but may be adjusted with the mm and dd arguments. The values for mm and dd indicate the end of the water year period (i.e. mm=9 and dd=30 indicates a new water year on Oct 1).
Note that if using FUN=mean
, please use FUN=colMeans
instead.
rvn_wyear_indices
for obtaining endpoints in the water year
# use sample forcing data (or use forcings_read to read in ForcingFunctions.csv)
data(rvn_forcing_data)
# apply mean (with colMeans) as FUN to daily average temperature
rvn_apply_wyearly(rvn_forcing_data$forcings$temp_daily_ave,colMeans,na.rm=TRUE)
#> temp_daily_ave
#> 2003-09-30 04:00:00 6.177794
#> 2004-09-30 04:00:00 6.931585
# apply mean as FUN to all forcings
rvn_apply_wyearly(rvn_forcing_data$forcings,colMeans,na.rm=TRUE)
#> day_angle rain snow temp temp_daily_min
#> 2003-09-30 04:00:00 3.141640 1.469701 0.3513806 6.177794 1.359503
#> 2004-09-30 04:00:00 3.141037 2.082020 0.2436921 6.931585 2.209062
#> temp_daily_max temp_daily_ave temp_monthly_min
#> 2003-09-30 04:00:00 10.99609 6.177794 -33333.3
#> 2004-09-30 04:00:00 11.65411 6.931585 -33333.3
#> temp_monthly_max air.dens air.pres rel.hum cloud.cover
#> 2003-09-30 04:00:00 -33333.3 1.206490 97.02194 0.5 0
#> 2004-09-30 04:00:00 -33333.3 1.202985 97.03452 0.5 0
#> ET.radiation SW.radiation LW.radiation wind.vel PET
#> 2003-09-30 04:00:00 316.8497 238.5254 -64.25976 2 2.177175
#> 2004-09-30 04:00:00 316.9300 238.5925 -63.84922 2 2.185220
#> OW.PET daily.correction potential.melt
#> 2003-09-30 04:00:00 2.177175 1 29.18804
#> 2004-09-30 04:00:00 2.185220 1 30.80885
# apply maximum via RavenR::cmax as FUN to all forcings (takes the max in each column)
## note that the base::max will not work properly here
rvn_apply_wyearly(rvn_forcing_data$forcings,cmax,na.rm=TRUE)
#> day_angle rain snow temp temp_daily_min
#> 2003-09-30 04:00:00 6.27458 32.2238 8.62851 25.2944 20.0068
#> 2004-09-30 04:00:00 6.27458 34.7881 6.71767 24.5248 21.1044
#> temp_daily_max temp_daily_ave temp_monthly_min
#> 2003-09-30 04:00:00 30.8448 25.2944 -33333.3
#> 2004-09-30 04:00:00 29.8234 24.5248 -33333.3
#> temp_monthly_max air.dens air.pres rel.hum cloud.cover
#> 2003-09-30 04:00:00 -33333.3 1.33513 97.2976 0.5 0
#> 2004-09-30 04:00:00 -33333.3 1.33700 97.2879 0.5 0
#> ET.radiation SW.radiation LW.radiation wind.vel PET
#> 2003-09-30 04:00:00 485.248 369.573 -36.6262 2 6.30455
#> 2004-09-30 04:00:00 485.248 371.919 -38.2550 2 5.68431
#> OW.PET daily.correction potential.melt
#> 2003-09-30 04:00:00 6.30455 1 118.251
#> 2004-09-30 04:00:00 5.68431 1 111.782
# apply to Australian water year (July 1)
rvn_apply_wyearly(rvn_forcing_data$forcings,cmax,na.rm=TRUE, mm=6, dd=30)
#> day_angle rain snow temp temp_daily_min
#> 2003-06-30 04:00:00 6.27458 32.2238 8.62851 25.0006 20.0068
#> 2004-06-30 04:00:00 6.27458 34.7881 6.71767 25.2944 19.7439
#> 2004-09-30 04:00:00 4.67805 26.3546 0.00000 24.5248 21.1044
#> temp_daily_max temp_daily_ave temp_monthly_min
#> 2003-06-30 04:00:00 30.2276 25.0006 -33333.3
#> 2004-06-30 04:00:00 30.8448 25.2944 -33333.3
#> 2004-09-30 04:00:00 29.3994 24.5248 -33333.3
#> temp_monthly_max air.dens air.pres rel.hum cloud.cover
#> 2003-06-30 04:00:00 -33333.3 1.33513 97.2945 0.5 0
#> 2004-06-30 04:00:00 -33333.3 1.33700 97.2976 0.5 0
#> 2004-09-30 04:00:00 -33333.3 1.18121 97.2879 0.5 0
#> ET.radiation SW.radiation LW.radiation wind.vel PET
#> 2003-06-30 04:00:00 485.248 369.573 -37.2143 2 6.30455
#> 2004-06-30 04:00:00 485.248 371.919 -36.6262 2 5.89993
#> 2004-09-30 04:00:00 482.730 361.562 -38.2550 2 5.68431
#> OW.PET daily.correction potential.melt
#> 2003-06-30 04:00:00 6.30455 1 117.654
#> 2004-06-30 04:00:00 5.89993 1 118.251
#> 2004-09-30 04:00:00 5.68431 1 109.244