nf_to_total: Convert between intervening and total flow

View source: R/nf_to_total.R

nf_to_interveningR Documentation

Convert between intervening and total flow

Description

nf_to_total() converts intervening flow to total flow for the Colorado River natural flow network, while nf_to_intervening() converts total flow to intervening flow. The functions only work if the objects have the 29 Colorado River natural flow sites, and that dimension's names match nf_gage_abbrv(). xts, nfd, crss_nf, and crssi objects can all be converted between total and intervening flow. For xts objects, the flow is converted without any additional checks, i.e., it is assumed the user passed in intervening flow if nf_to_total() is called. For the other three types of objects, they must have the required existing data already, i.e., intervening data must exist when calling nf_to_total(), and total data must exist when calling nf_to_intervening(). If the objects have both annual and monthly data, both will be converted.

Usage

nf_to_intervening(x, ...)

## S3 method for class 'crss_nf'
nf_to_intervening(x, keep_total = TRUE, recompute = FALSE, ...)

## S3 method for class 'nfd'
nf_to_intervening(x, keep_total = TRUE, recompute = FALSE, ...)

## S3 method for class 'xts'
nf_to_intervening(x, ...)

nf_to_total(x, ...)

## S3 method for class 'crss_nf'
nf_to_total(x, keep_intervening = TRUE, recompute = FALSE, ...)

## S3 method for class 'nfd'
nf_to_total(x, keep_intervening = TRUE, recompute = FALSE, ...)

## S3 method for class 'xts'
nf_to_total(x, ...)

Arguments

x

An object inheriting from xts::xts, nfd, crss_nf, or crssi.

...

Other parameters passed to subsequent methods.

keep_total

When FALSE, the total flow are removed from the object. Otherwise those data remain in the returned object.

recompute

If x already has total flow, the function will fail with an error when FALSE. If TRUE, then the total flow will be recomputed and the existing data will be overwritten.

keep_intervening

When FALSE, the intervening flow are removed from the object. Otherwise those data remain in the returned object.

Details

When keep_intervening is FALSE and x is either a crss_nf object or a crssi object, then the returned object will be an nfd object, and a warning will post. This is because crss_nf and crssi objects must have monthly intervening natural flow stored in them.

Value

An object of the same class as x, except when x is either a crss_nf obect or crssi object and keep_intervening is FALSE. See Details.

Examples

# start with an nfd object with intervening annual data
nf_int <- nfd(
  CoRiverNF::cyAnnInt, 
  n_sites = 29, 
  flow_space = "intervening", 
  time_step = "annual"
)

# convert to total
nf <- nf_to_total(nf_int, keep_intervening = FALSE)

# It matches the total natural flow that exists in the CoRiverNF package 
# (except it doesn't have the sheet name attribute)
all.equal(
  zoo::coredata(CoRiverNF::cyAnnTot),
  zoo::coredata(
    nfd_get_trace(nf, 1, flow_space = "total", time_step = "annual")
  )
)

# converting back will result in original data
nf2 <- nf_to_intervening(nf, keep_total = FALSE)
all.equal(nf2, nf_int)


BoulderCodeHub/CRSSIO documentation built on July 2, 2023, 5:15 p.m.