rvn_rvt_write: Write Raven rvt file from Time Series

View source: R/rvn_rvt_write.R

rvn_rvt_writeR Documentation

Write Raven rvt file from Time Series

Description

Generates a Raven rvt file of the specified type from an xts time series.

Usage

rvn_rvt_write(
  x,
  filename = NULL,
  rvt_type = "ObservationData",
  data_type = "HYDROGRAPH",
  basin_ID = NULL,
  NA_value = -1.2345
)

Arguments

x

time series in xts format to write to file

filename

name of output file (with rvt extension)

rvt_type

type of rvt file to write (e.g. ObservationData)

data_type

type of data in x (e.g. HYDROGRAPH)

basin_ID

subbasin (or HRU) ID corresponding to the time series

NA_value

value to use for NA values in rvt file (default -1.2345 for Raven format)

Details

Writes the rvt file for a given time series dataset. The type of rvt file to write is determined by the rvt_type argument, which must match one of the supported Raven types. Note that this function does not support the writing of meteorological data, this is handled by the rvn_rvt_write_met function.

The format of the rvt file, including required fields to write to file, are determined from the supplied rvt_type parameter and from the mapping provided by data("rvn_rvt_mappings_data"). The data_type is also checked against the provided mappings to check for valid state variables and accompanying units.

If the data is found to have an inconsistent timestep, the function will attempt to correct it by infilling missing time steps with rvn_ts_infill. If successful, a warning is issued to the user and the function will proceed, else an error will be raised.

The timezone of the xts object is used as supplied to write to file, no assumption on changing the time zone is done in this function.

No other quality control of the data is performed here. Some rvt types, such as ObservationWeights, cannot have missing values in the data; it is the responsibility of the user to supply x with no missing values if required. Any missing values in x are written to file with the missing value code provided by NA_value.

x should be an xts time series object with multiple rows of data and a single column.

Value

TRUE if the function executed successfully

See Also

rvn_rvt_read to read in rvt data files, and rvn_rvt_write_met to write meteorological rvt files.

Examples


# load sample flow data
system.file('extdata','run1_Hydrographs.csv', package = "RavenR") %>%
rvn_hyd_read() -> mydata

# temporary filename
tf <- file.path(tempdir(), 'mydata.rvt')

# write time series to rvt file using data from subbasin 36 as observed data
rvn_rvt_write(x=mydata$hyd$Sub36,
  rvt_type = "ObservationData",
  data_type = "HYDROGRAPH",
  basin_ID = 36,
  filename = tf)


rchlumsk/RavenR documentation built on April 19, 2024, 5:15 a.m.