compare_weather: Compare two weather datasets: produces comparison plots for...

View source: R/swWeatherGenerator.R

compare_weatherR Documentation

Compare two weather datasets: produces comparison plots for means, quantiles, and Markov weather generator input parameters for all time steps

Description

Compare two weather datasets: produces comparison plots for means, quantiles, and Markov weather generator input parameters for all time steps

Usage

compare_weather(
  ref_weather,
  weather,
  N,
  WET_limit_cm = 0,
  path = ".",
  tag = format(Sys.time(), "%Y%m%d-%H%M")
)

Arguments

ref_weather

A list of or a two-dimensional numerical object, e.g., data.frame or matrix. If a list then four suitable elements one for each time_step. Otherwise, daily weather data with columns Year, DOY, Tmax_C, Tmin_C, and PPT_cm; for instance, the result of function dbW_weatherData_to_dataframe. This represents the reference weather against which weather is compared.

weather

A list of elements such as described for ref_weather or an object such as ref_weather. This represents the weather data (potentially from many sites and/or runs) that are compared against ref_weather.

N

An integer number representing the number of runs or sites contained in weather.

WET_limit_cm

A numeric value. A day with more precipitation than this value is considered wet instead of dry. Default is 0. This values should be equal to the corresponding value used in SOILWAT2's function SW_MKV_today().

path

A character string. The directory path in which output figures will be saved.

tag

A character string to uniquely identify a set of output figures.

Value

This function is called for its side effects of producing figures that are saved as png files on the disk.

Notes

The number of days represented by ref_weather and by weather does not need to be the same.

See also the Weather generator integration tests (in file "tests/testthat/test_WeatherGenerator_functionality.R).

Examples

path <- tempdir()

## Example with default rSOILWAT2 weather data
w0 <- dbW_weatherData_to_dataframe(rSOILWAT2::weatherData)
w1 <- w0
w1[, "Tmax_C"] <- w1[, "Tmax_C"] + 2
w1[, "Tmin_C"] <- w1[, "Tmin_C"] - 2

compare_weather(
  ref_weather = w0,
  weather = w1,
  N = 1,
  path = path,
  tag = "Example1-Silly"
)

## Example with STEPWAT2 output data averaged across iterations (`-o` option)
fname_main <- "file_STEPWAT2_main.csv"
fname_dev <- "file_STEPWAT2_dev.csv"
if (all(file.exists(fname_main, fname_dev))) {
  cols_STEPWAT2 <- c(
    "Year", "Day", "PRECIP_ppt_Mean", "TEMP_max_C_Mean", "TEMP_min_C_Mean"
  )
  cols_rSOILWAT2 <- c("Year", "Day", "PPT_cm", "Tmax_C", "Tmin_C")
  w0 <- utils::read.csv(fname_main)[, cols_STEPWAT2]
  colnames(w0) <- cols_rSOILWAT2
  w1 <- utils::read.csv(fname_dev)[, cols_STEPWAT2]
  colnames(w1) <- cols_rSOILWAT2

  # Note: Since values are averages across many iterations, most days
  # have average precipitation values > 0; thus, we need to adjust
  # `WET_limit_cm` accordingly (here, with a guess)
  compare_weather(
    ref_weather = w0,
    weather = w1,
    N = 1,
    WET_limit_cm = 0.1,
    path = path,
    tag = "Example2-STEPWAT2"
  )
}

## Cleanup
unlink(list.files(path), force = TRUE)


Burke-Lauenroth-Lab/rSOILWAT2 documentation built on Dec. 9, 2023, 1:46 a.m.