Simple aggregation functions for monthly matrix data
Simple aggregation functions for monthly matrix data
A family of functions that take a matrix containing monthly data (months by traces) that has a "timespan" attribute, annualizes the data by summing, or finding the minimum or maximum monthly values. Returns a years by traces matrix. Matrices returned by rdf_get_slot() have the timespan attribute added to them.
rwslot: A matrix (months by traces) such as that returned by rdf_get_slot(). Function will error if the rwslot does not contain "regular" monthly data, i.e., the data must start in January and end in December, or start in October and end in September (water year), and the rwslot must have the timespan attribute.
multFactor: A factor the annual sum will be multiplied by. Can be used to convert from flow to volume, or to scale all results in another manor.
mass: A matrix (months by traces), such as that returned by rdf_get_slot(), of mass in tons.
flow: A matrix (months by traces), such as that returned by rdf_get_slot(), of flow in acre-ft/month.
Returns
Other functions: Annual matrix (years x traces)
rwslot_fwaac(): Annual matrix (years x traces). Units are mg/L.
Functions
sumMonth2Annual(): Deprecated version of rwslot_annual_sum().
rwslot_annual_min(): finds the minimum annual value for all years and traces.
getMinAnnValue(): Deprecated version of rwslot_annual_min().
rwslot_annual_max(): finds the maximum annual value for all years and traces.
getMaxAnnValue(): Deprecated version of rwslot_annual_max().
rwslot_fwaac(): calculates the flow-weighted average annual concentration (fwaac). Given mass and flow at the monthly basis, the flow-weighted average annual concentration is computed. mass and flow
should be monthly data. rwslot_fwaac() expects flow to be in acre-ft/month and mass to be in tons; however, there are no checks to ensure this is true. Return value will be in mg/L.
Examples
zz <- rdf_get_slot(keyRdf,'Powell.Outflow')# returns in original units, e.g., acre-ftannualTotVal <- rwslot_annual_sum(zz)# returns in scaled units, e.g., kafannualTotVal <- rwslot_annual_sum(zz,0.001)pe <- rdf_get_slot(keyRdf,'Mead.Pool Elevation')peMax <- rwslot_annual_min(pe)pe <- rdf_get_slot(keyRdf,'Mead.Pool Elevation')peMax <- rwslot_annual_max(pe)flow <- rdf_get_slot(keyRdf,'Powell.Outflow')# make up mass, since it's not stored in the example datarr <- matrix( rnorm((nrow(flow)* ncol(flow)), mean =1000, sd =200), nrow = nrow(flow), ncol = ncol(flow))mass <- flow /1000000* rr^2- rr +1500fwaac <- rwslot_fwaac(mass, flow)