water_year: Compute the water year

View source: R/hyear.R

water_yearR Documentation

Compute the water year

Description

Given a date, compute the corresponding water year (hydrological year).

Usage

water_year(x, origin = "din", as.POSIX = FALSE,
           assign = c("majority", "start", "end"), ...)

Arguments

x

a vector, implicit coercion to class 'POSIXlt' is performed.

origin

a vector of length one specifying the month in which the hydrological year starts. Four different ways of defining the beginning of a hydrological year are supported: a character string like 'din' or 'usgs' representing a definition of an institution (see Details), an integer number between 1 and 12, a character string of the month name (possibly abbreviated) or POSIX/Date object from which only the month is taken.

as.POSIX

logical, if TRUE return value is of class POSIXct. Otherwise a factor is returned.

assign

a character vector of length one, deciding how a hydrological year is labelled. Depending on the climate, the hydrological year can start earlier or later than the calendar year. Usually the hydrological year "equals" the calendar year for the longest period of months they have in common. Alternatively a water year can also be designated by the calendar year in which it starts or ends.

...

arguments, passed on to as.POSIXlt, e.g. such as format

Details

Currently, it is only supported to start a hydrological year on the 1st of a month.

There are abbreviations for a few established definitions:

start description
'din' 1st of November DIN 4049 (default), as used in Austria and Germany
'usgs' 1st of October USGS, the United States Geological Survey
'swiss' 1st of October as defined by the Swiss "Bundesamt f. Energie" (BFE)
'glacier' 1st of September Widely used in glaciology

Its convenient to have the water year as a factor with levels even for year without observations. For example, otherwise years without observations don't appear after aggregation.

Value

a factor representing the hydrological year.

Examples

# generating monthly sequence
x <- seq(from = as.Date("1992-01-01"),
         by = "months", length.out = 12)

# specifying the beginning with a decimal number
water_year(x, origin = 10)

# using a month name
water_year(x, origin = "Jul")      # can be abbreviated
water_year(x, origin = "july")     # case insensitive

# using an POSIX or Date object
water_year(x, origin = as.Date("2012-08-22"))     # only month is taken
water_year(x, origin = as.POSIXct("2012-08-22"))

# or by specifying an institution
water_year(x, origin = "usgs")

lfstat documentation built on Nov. 10, 2022, 5:42 p.m.