Creates a daily climatology from a time series of daily temperatures using a user-specified sliding window for the mean and threshold calculation, followed by an optional moving average smoother as used by Hobday et al. (2016).
ts2clm(data, x = t, y = temp, climatologyPeriod, robust = TRUE,
maxPadLength = 3, windowHalfWidth = 5, pctile = 90,
smoothPercentile = TRUE, smoothPercentileWidth = 31, clmOnly = FALSE)
A data frame with two columns. In the default setting (i.e. ommitting
the arguments x
and y
; see immediately below), the data set is
expected to have the headers t
and temp
. The t
column is a
vector of dates of class Date
, while temp
is the measured variable
(by default it is assumed to be temperature).
This column is expected to contain a vector of dates. If a column
headed t
is present in the dataframe, this argument may be ommitted;
otherwise, specify the name of the column with dates here.
This is a column containing the measurement variable. If the column
name differs from the default (i.e. temp
), specify the name here.
Required. To this argument should be passed two values (see example below). The first value should be the chosen date for the start of the climatology period, and the second value the end date of said period. This chosen period (preferably 30 years in length) is then used to calculate the seasonal cycle and the extreme value threshold.
This switch selects between a slower, but more robust (default is
TRUE
), function that checks for the completeness of the date vector (i.e.
it must be regular and with no duplicates), or a faster one, which assumes that
the user has verified that no missing dates are present in the time series or
whether or not some measurements are replicated (in which case it takes the mean).
Internally, this decides whether make_whole
or make_whole_fast
will be used.
Specifies the maximum length of days over which to
interpolate (pad) missing data (specified as NA
) in the input
temperature time series; i.e., any consecutive blocks of NAs with length
greater than maxPadLength
will be left as NA
. Set as an
integer. The default is 3
days.
Width of sliding window about day-of-year (to one
side of the center day-of-year) used for the pooling of values and
calculation of climatology and threshold percentile. Default is 5
days, which gives a window width of 11 days centered on the 6th day of the
series of 11 days.
Threshold percentile (%) for detection of events (MHWs).
Default is 90
th percentile. Should the intent be to use these
threshold data for MCSs, set pctile = 10
. Or some other low value.
Boolean switch selecting whether to smooth the
climatology and threshold percentile time series with a moving average of
smoothPercentileWidth
. Default is TRUE
.
Full width of moving average window for smoothing
climatology and threshold. The default is 31
days.
Choose to calculate and return only the climatologies.
The default is FALSE
.
The function will return a tibble (see the tidyverse
) with the
input time series and the newly calculated climatology. The climatology contains
the seasonal climatology and the threshold for calculating MHWs. The software was
designed for creating climatologies of daily temperatures, and the units
specified below reflect that intended purpose. However, various other kinds
of climatologies may be created, and if that is the case, the appropriate
units need to be determined by the user.
Julian day (day-of-year). For non-leap years it runs 1...59 and 61...366, while leap years run 1...366.
The date vector in the original time series supplied in data
. If
an alternate column was provided to the x
argument, that name will rather
be used for this column.
The measurement vector as per the the original data
supplied
to the function. If a different column was given to the y
argument that
will be shown here.
Climatological seasonal cycle [deg. C].
Seasonally varying threshold (e.g., 90th
percentile) [deg. C]. This is used in detect_event
for the
detection/calculation of events (MHWs).
Seasonally varying variance (standard deviation) [deg. C].
This function assumes that the input time series consists of continuous daily values with few missing values. Time ranges which start and end part-way through the calendar year are supported.
It is recommended that a period of at least 30 years is specified in
order to produce a climatology that smooths out any decadal thermal
periodicities that may be present. It is further advised that full the start
and end dates for the climatology period result in full years, e.g.
"1982-01-01" to "2011-12-31" or "1982-07-01" to "2012-06-30"; if not, this
may result in an unequal weighting of data belonging with certain months
within a time series. A daily climatology will be created; that is, the
climatology will be comprised of one mean temperature for each day of the
year (365 or 366 days, depending on how leap years are dealt with), and the
mean will be based on a sample size that is a function of the length of time
determined by the start and end values given to climatologyPeriod
and
the width of the sliding window specified in windowHalfWidth
.
This function supports leap years. This is done by ignoring Feb 29s for the initial calculation of the climatology and threshold. The values for Feb 29 are then linearly interpolated from the values for Feb 28 and Mar 1.
Previous versions of ts2clm()
tested to see if some rows
are duplicated, or if replicate temperature readings are present per day, but
this has now been disabled. Should the user be concerned about such repeated
measurements, we suggest that the necessary checks and fixes are implemented
prior to feeding the time series to ts2clm()
.
The original Python algorithm was written by Eric Oliver, Institute for Marine and Antarctic Studies, University of Tasmania, Feb 2015, and is documented by Hobday et al. (2016).
Hobday, A.J. et al. (2016). A hierarchical approach to defining marine heatwaves, Progress in Oceanography, 141, pp. 227-238, doi:10.1016/j.pocean.2015.12.014
# NOT RUN {
res <- ts2clm(sst_WA, climatologyPeriod = c("1983-01-01", "2012-12-31"))
res[1:10, ]
# Or if one only wants the 366 day climatology
res_clim <- ts2clm(sst_WA, climatologyPeriod = c("1983-01-01", "2012-12-31"),
clmOnly = TRUE)
res_clim[1:10, ]
# }
Run the code above in your browser using DataLab