README.md

CRSSIO

Stable version (v0.9.1): R build
status Codecov test
coverage

Development version: R build
status Codecov test
coverage

R Package to manipulate the CRSS input and output data.

Installation

Only available from GitHub. Use the following to install:

install.packages('devtools')
library(devtools)
devtools::install_github('BoulderCodeHub/CRSSIO')

Usage

The CRSSIO package includes functions for manipulating and creating input data necessary to run CRSS and for processing CRSS output data. It uses a “prefix_verb_noun” naming system for most functions. Functions that create input for CRSS use the crssi_ prefix, while those that process CRSS output use the crsso_ prefix. The nf_, natsalt_, and ism_ prefixes are also used for multiple functions that deal with natural flow names, natural salt names, and with ISM related functions.

Functions that use the create verb will create files on the user’s computer. Functions that use the change verb will edit files that already exist on the user’s computer. Functions that use the get verb will return data.

The final noun of the function describes what is created or retrieved. Ex: crssi_create_dnf_files() creates the DNF (direct natural flow) files.

The package also includes other functions for conveniently manipulating other data related to CRSS, e.g., converting between elevation and storage for modeled reservoirs. Finally, the package provides several functions that extend/modify ggplots.

Classes

CRSSIO defines three classes for storing multi-trace natural flow data: nfd, crss_nf, and crssi. crss_nf inherits from nfd and crssi inherits from both nfd and crss_nf. These classes intend to make working with CRSS input natural flow data easier and more uniform.

nfd stores multi-trace, multi-site data for annual and/or monthly time steps and for intervening and/or total natural flow (flow space). nfd() creates the object from arrays, matrices, or xts objects. The object can contain any/all of the four combinations of time step and flow space.

crss_nf objects require that there are exactly 29 sites: the 29 sites required for input into CRSS, and that there are monthly intervening natural flows, which are also required input to CRSS. Other time step and flow space combinations are allowed, but there must be monthly intervening data.

crssi objects add additional required input into CRSS: the Sacramento year type index and a scenario number.

Several methods exist to work with these objects. reindex() changes the underlying time component so that historical data can be used for future projections in CRSS; ism() applies the Index Sequential Method to a single trace; plot() will quickly show the data; write_crssi() will create the input files necessary for CRSS; nfd_stats() and nfd_pdf() compute statistics across the different traces and can then be plotted with plot(). nf_to_total() and nf_to_intervening() will convert between total and intervening flow.

Example

Apply ISM to the 1988-present period, and then plot the resulting statistics.

library(CRSSIO)
flows <- crss_nf(CoRiverNF::monthlyInt["1988/"])
#> nfd: Natural Flow Data
#>  ----------------------
#>  n traces: 1 
#>  dates: Jan 1988 - Dec 2019 
#>  flow space:
#>  - monthly intervening
ism_flows <- ism(flows, n_years_keep = 15)
#> nfd: Natural Flow Data
#>  ----------------------
#>  n traces: 32 
#>  dates: Jan 1988 - Dec 2002 
#>  flow space:
#>  - monthly intervening
hist_stats <- nfd_stats(flows, "Cameo", "intervening", "monthly")
ism_stats <- nfd_stats(ism_flows, "Cameo", "intervening", "monthly")
plot(ism_stats, ref = hist_stats, base_units = "acre-feet")

crssi_

crsso_

library(CRSSIO)
library(RWDataPlyr) # install.packages("RWDataPlyr")
# create the RiverWare data aggregator
rwa <- sys_cond_rwa()

# use example data in RWDataPlyr to create system condition table
# first get all of the data
scenFolder <- "ISM1988_2014,2007Dems,IG,Most"
scenName <- "scenA"
scenPath <- system.file('extdata','Scenario/',package = 'RWDataPlyr')
sysData <- RWDataPlyr::rdf_aggregate(
  rwa,
  rdf_dir = file.path(scenPath, scenFolder),
  scenario = scenName
)

# then create the system condition table
sysCondTable <- crsso_get_sys_cond_table(sysData, 2018:2022)
# sysCondTable[['limitedTable']] to access results

Natural Flow and Salt Names

Other CRSS Functions

Plotting

Log:

For details, see the News



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