
Read an LPJmL hydrology variable into a tidy tibble.
Source:R/lpjml_hydrology.R
read_lpjml_hydrology.RdReads one monthly LPJmL hydrology output (drainage, evapotranspiration
components, precipitation, irrigation, runoff, discharge or soil water
content) from a finished run's NetCDF files and returns it in tidy long
form. The logical var name is mapped to the on-disk file and in-file
variable name, so callers need not know the LPJmL naming quirks. The
synthetic "aet" variable sums the three actual-evapotranspiration
components (transpiration, evaporation, interception).
Usage
read_lpjml_hydrology(
var = c("drainage", "transp", "evap", "interc", "aet", "prec", "rain", "irrig",
"runoff", "discharge", "swc", "cft_nir", "cft_consump_water_b",
"cft_consump_water_g"),
run_dir = NULL,
years = NULL,
first_year = 1901L,
monthly = TRUE,
agg = c("sum", "mean"),
data = NULL,
example = FALSE
)Arguments
- var
Logical variable name, one of
"drainage","transp","evap","interc","aet","prec","rain","irrig","runoff","discharge","swc","cft_nir"(per-CFT net irrigation requirement) or the per-CFT consumptive-water cubes"cft_consump_water_b"(blue) and"cft_consump_water_g"(green). The per-CFT variables keep theirbanddimension, and carryband_namewhen the file names its bands.- run_dir
Path to the LPJmL run output directory. Defaults to
Sys.getenv("WHEP_LPJML_RUN_DIR").- years
Optional integer vector of calendar years to keep.
NULLkeeps every year present in the file. A requested year the run does not have aborts, naming the coverage it does have: LPJmL runs ending in different years sit side by side in one folder, so the coverage is a property ofrun_dir, never an assumption of this reader.- first_year
First calendar year of the run's monthly time axis. The last year is not an argument — it is read from the file's own time dimension.
- monthly
If
TRUE, return one row per cell-month; ifFALSE, aggregate the 12 months of each year per cell (flux variables summed, soil water content averaged). Immaterial for the annual per-CFT consumptive-water variables, which LPJmL writes one step per year: they carry nomonthcolumn either way, and aggregating them groups rows that are already one per cell-year-band.- agg
Annual aggregation for
monthly = FALSE,"sum"(flux default) or"mean"(soil-water default).- data
Optional pre-read tibble (
lon,lat,year,month,value, pluslayerfor"swc"orbandfor"cft_nir") used in place of reading NetCDF, for testing.- example
If
TRUE, return a small fixture instead of reading remote data. Defaults toFALSE.