IIO352 CP04b 2023 04 05 hydroTS Knitr
IIO352 CP04b 2023 04 05 hydroTS Knitr
mauricio.zambrano @ ufrontera.cl
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
Today the following package will be explored: hydroTSM, which has several useful
functions for hydrologic and environmental data analysis.
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
Temporal sequences - I
The main functions used for temporal sequences generation or for calculating the number of
elements of a given sequence are:
hip: generates a sequence of hours between an initial and final hour.
Temporal sequences - II
date.fmt: indicates the format in which the data is given from y to. By default,
date.fmt="%Y-%m-%d.
out.type: indicates if the result is a temporal sequence between from y to or the number
of elements between from and to.
Traditional way:
require(zoo)
## Loading required package: zoo
##
## Attaching package: ’zoo’
## The following objects are masked from ’package:base’:
##
## as.Date, as.Date.numeric
dates1 <- seq(from=as.Date("2014-01-01"),
to=as.Date("2014-06-12"), by="days")
With hydroTSM:
require(hydroTSM)
## Loading required package: hydroTSM
## Loading required package: xts
dates2 <- dip(from="2014-01-01", to="2014-06-12")
Temporal sequences - IV
Examples; generation of a hourly sequence between two dates:
Traditional way:
require(zoo)
hrs1 <- seq(from=as.POSIXlt("2012-01-01 21:00"),
to=as.POSIXct("2012-01-01 23:00"), by="hour")
Con hydroTSM:
require(hydroTSM)
hrs2 <- hip(from="2012-01-01 21", to="2012-01-01 23")
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
Extraction - I
The main function used to extract all the values belonging to a determined month, year or
season is:
Where:
trgt: integer indicating the number of the month (trgt ≤ 12) or year to be extracted, or
also a character indicating the season to be extracted (e.g., DJF, MAM, JJA, SON, etc).
Extraction - II
Some examples of values extraction:
Loading the daily rainfall data:
data(SanMartinoPPts)
x <- SanMartinoPPts
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
Conversions - I
item daily2monthly: converts series of daily frequency (or lower) to monthly values.
Conversions - II
FUN: function that will be applied to the elements of x to obtain the new object with the
needed frequency.
na.rm: indicates if the missing values in x should be ignored during the conversion.
Conversions - III
Conversion exaples:
Loading precipitation daily values:
data(SanMartinoPPts)
x <- SanMartinoPPts
Daily to monthly series:
m <- daily2monthly(x, FUN=sum, na.rm=TRUE)
Conversions - IV
Conversions examples:
Loading daily precipitation data:
data(SanMartinoPPts)
x <- SanMartinoPPts
Daily to monthly series:
a <- daily2annual(x, FUN=sum, na.rm=TRUE)
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
The next functions are used to obtain representative mensual, annual ir seasonal values:
1 monthlyfunction: function that allows to obtain 12 monthly values, applying an additive
function to ALL the values of an zoo/xts object that belongs to a given month
(Jan...Dec).
FUN: function that will be applied to the elements of x that belong to a determined
month or season.
na.rm: indicates if the missing values in x should be ignored during the computation.
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
hydroplot - I
hydroplot
The function hydroplot creates the daily, monthly and seasonal temporal series plots.
The value of the argument pfreq controls the temporal frequency of the shown series
(daily, monthly, annual, seasonal).
The value of the argument ptype controls the plot type that is produced: time series,
boxplots and/or histogramas.
Loading the daily discharge data of Oca station in Ona (Ebro River Basin, Spain).
hydroplot - II
require(hydroTSM)
## Loading daily streamflows at the station ##
data(OcaEnOnaQts)
El siguiente comando crea un gráfico sólo con la serie temporal, durante todo el perı́odo
hydroplot - III
El siguiente comando crea un gráfico sólo para el año 1962:
hydroplot - IV
The following comand creates a plot of the daily discharge for each season (personalyzed for the Southern Hemisphere):
OcaEnOnaQts
11
11
6 8
6 8
1961 1962 1963
Time
OcaEnOnaQts
9
9
7
7
5
5
1961 1962 1963
Time
OcaEnOnaQts
2.8
2.8
2.2
2.2
1961 1962 1963
Time
OcaEnOnaQts
3.5
3.5
2.0
2.0
hydroplot - V
The following command creates a plot with 3 temporal series, 3 boxplots and 3 hystograms:
Q [m3/s/day]
Daily series
40
40
0.15
Pbb
20
20
0.00
0
Q [m3/s/month]
Monthly series
0.08
5 10
5 10
Pbb
0.00
Jan Jan Jan Dec Jan Mar May Jul Sep Nov 0 5 10 15
1961 1962 1963 1963
Time months Q [m3/s/month]
Q [m3/s/year]
6.0
Pbb
5.0
5.0
Tabla de Contenidos
1 Context
2 Temporal sequences
3 Extraction
4 Conversions/aggregation
6 Plots
7 References
Referencias - I
hydroTSM vignette
hydroTSM manual
Thank you !
mauricio.zambrano @ ufrontera.cl
Teléfono: +56 45 259 2812