ReadObs: Read HYPE observation data files

View source: R/functioncollection_import.R

ReadObsR Documentation

Read HYPE observation data files

Description

Import single-variable HYPE observation files into R.

Usage

ReadObs(
  filename,
  variable = "",
  dt.format = NULL,
  nrows = -1,
  type = c("df", "dt"),
  select = NULL,
  obsid = NULL
)

ReadPTQobs(
  filename,
  variable = "",
  dt.format = NULL,
  nrows = -1,
  type = c("df", "dt"),
  select = NULL,
  obsid = NULL
)

Arguments

filename

Path to and file name of the file to import. Windows users: Note that Paths are separated by '/', not '\'.

variable

Character string, HYPE variable ID of file contents. If "" (default), the ID is extracted from filename, which only works with HYPE input data file names or file names including those names (e.g. 'Pobs_old.txt', 'testSFobs.txt'). Some of the observation data files have no corresponding HYPE variable ID. In these cases, a dummy ID is used, see table in Details. If automatic extraction fails, attribute variable is set to "other". Alternatively, any other variable name can be provided.

dt.format

Optional date-time format string as in strptime. If NULL, then HYPEtools will try to identify the format automatically.

nrows

Number of rows to import. A value of -1 indicates all rows, a positive integer gives the number of rows to import.

type

Character, keyword for data type to return. "df" to return a standard data frame or "dt" to return a data.table object.

select

Integer vector, column numbers to import. Note: first column with dates must be imported and will be added if missing.

obsid

Integer vector, HYPE OBSIDs to import. Alternative to argument select, takes precedence if both are provided.

Details

ReadObs is a convenience wrapper function of fread from package data.table::data.table, with conversion of date-time strings to POSIX time representations. Observation IDs (SUBIDs or IDs connected to SUBIDs with a ForcKey.txt file) are returned as integer attribute obsid (directly accessible through obsid).

Observation file types with automatic (dummy) variable attribute assignment:

File HYPE variable ID
(*: dummy ID)
Pobs.txt prec
Tobs.txt temp
Qobs.txt rout
TMINobs.txt tmin*
TMAXobs.txt tmax*
VWobs.txt vwnd*
UWobs.txt uwnd*
SFobs.txt snff*
SWobs.txt swrd*
RHobs.txt rhum*
Uobs.txt wind*

Value

ReadObs returns a data frame or data table with additional attributes: obsid with observation IDs, timestep with a time step string, either "day" or "nhour" (only daily or n-hourly time steps supported), and variable with a HYPE variable ID string.

Note

For the conversion of date/time strings, time zone "UTC" is assumed. This is done to avoid potential daylight saving time side effects when working with the imported data (and e.g. converting to string representations during the process).

See Also

WriteObs ReadXobs for multi-variable HYPE observation files

Examples

te <- ReadObs(filename = system.file("demo_model", "Tobs.txt", package = "HYPEtools"))
head(te)


HYPEtools documentation built on Sept. 11, 2024, 8:34 p.m.