dbW_convert_to_GregorianYears: Transfer existing weather data to a different (Gregorian)...

View source: R/sw_dbW_WeatherDatabase.R

dbW_convert_to_GregorianYearsR Documentation

Transfer existing weather data to a different (Gregorian) calendar (period)

Description

This function can transfer from existing weather data to, e.g., different years / a subset of years (partially overlapping or not), or can convert from a non-leap to a Gregorian calendar.

Usage

dbW_convert_to_GregorianYears(
  weatherData,
  new_startYear = NULL,
  new_endYear = NULL,
  type = c("asis", "sequential"),
  name_year = "Year",
  name_DOY = "DOY",
  name_data = weather_dataColumns(),
  valNA = NULL
)

Arguments

weatherData

A list of elements of class swWeatherData that each hold daily weather data for one calendar year.

new_startYear

An integer value. The first Calendar year of the new time period. If NULL, then the first year of weatherData.

new_endYear

An integer value. The last Calendar year of the new time period. If NULL, then the last year of weatherData.

type

A string that affects how years of weatherData are used for transfer. If "asis", then years of are used as is. If "sequential", then years are re-coded to start with new_startYear.

name_year

A string. Column name of the weather data that corresponds to year.

name_DOY

A string. Column name of the weather data that corresponds to day of year.

name_data

A vector of strings. Column names of the weather data.

valNA

The (numerical) value of missing weather data. If NULL, then default values are interpreted as missing.

Value

A data.frame formatted as a return object from function dbW_weatherData_to_dataframe with column names as given by name_year, name_DOY, and name_data.

Note

The returned object may contain NA, e.g., for leap days that were added. Use function dbW_generateWeather to fill in.

Examples

wdata <- rSOILWAT2::weatherData

## Transfer to different years (partially overlapping)
wnew <- dbW_convert_to_GregorianYears(
  wdata,
  new_startYear = 2000,
  new_endYear = 2020
)
all.equal(unique(wnew[, "Year"]), 2000:2020)
anyNA(wnew) # --> use `dbW_generateWeather`

## Transfer to a subset of years (i.e., subset)
wnew <- dbW_convert_to_GregorianYears(
  wdata,
  new_startYear = 2000,
  new_endYear = 2005
)
all.equal(unique(wnew[, "Year"]), 2000:2005)
anyNA(wnew)

## Correct/convert from a non-leap to a Gregorian calendar
wempty <- data.frame(
  dbW_weatherData_to_dataframe(weatherHistory())
)[1:365, ]

wnew <- dbW_convert_to_GregorianYears(
  wempty,
  new_startYear = 2016,
  new_endYear = 2016
)
all.equal(unique(wnew[, "Year"]), 2016:2016)
all.equal(nrow(wnew), 366) # leap year


Burke-Lauenroth-Lab/Rsoilwat documentation built on Dec. 9, 2023, 12:41 a.m.