library(dplyr) library(ggplot2)
When downloading time series with the get_timeseries_tsid()
method, the ts_id
argument provides the link with the variable, location and frequency of the time series, but not the extent/period to download.
The time period to download is defined by a combination of the arguments from
, to
and period
. The usage is similar with the VMM documentation for the API itself. The main difference is that the wateRinfo
package uses existing R functions to interpret the date strings given by the user before sending these to the API (as a formatted string according to %Y-%m-%d %H:%M:%S
).
This vignette aims to briefly explain how to define the arguments.
In order to define a period, a start and end date is required. Defining all three will result in an error, but any combination of from/to
, from/period
and to/period
is allowed. Moreover, if only period
or from
are defined, the waterinfo.be API will automatically define to
as the current time. Hence, defining the last x days/months/years/... can be achieved by only using the period
option.
The package will both except valid date strings as well as valid date objects (POSIXct
, POSIXt
) as input for the from
and to
arguments. When using a string value, it can be defined on different resolutions:
According to the lubridate
package, these orders are accepted: ymd_hms
, ymd
, ym
, y
. As a result, also "2017/01/01"
, "2017 01 01"
or "20170101"
are valid date string inputs. Make sure the order of year-month-day is respected. For example, "01/01/2017"
, "01-01-2017"
and "01-2017"
are NOT valid.
The period string provides a flexible way to extract a time period starting (in combination with from
) or ending (in combination with to
) at a given moment. Moreover, by using only the period
as argument, it will cover all cases where one is interested in the last x days/months/years/....
Some examples are:
P3D
: period of three daysP2Y
: period of 2 yearsPT6H
: period of 6 hoursP2DT6H
: period of 2 days and 6 hoursIn general, the period string should be provided as P#Y#M#DT#H#M#S
, where P defines Period
(always required!) and each # is an integer value expressing the number of.... The codes define a specific time interval:
Y
- yearsM
- monthsD
- daysW
- weeksH
- hoursM
- minutesS
- secondsT
is required if codes about sub-day resolution (day, minutes, hours) is part of the period string. Furthermore, D
and W
are mutually exclusive.
More examples of valid period strings are:
P1DT12H
: period of 1 day and 12 hoursP2WT12H
: period of 2 weeks and 12 hoursP1Y6M3DT4H20M30S
: period of 1 year, six months, 3 days, 4 hours, 20 minutes and 30 secondslibrary(wateRinfo)
When interested in irradiance (15min frequency) data, the following stations provide time series:
get_stations("irradiance")
Focusing on the data of Herentals, the ts_id
to use is 78930042
. We have different options to define the period to get data from:
period
only:irr_lastday <- get_timeseries_tsid("78930042", period = "P1D") ggplot(irr_lastday, aes(Timestamp, Value)) + geom_line() + xlab("") + ylab("irradiance (W/m2)")
period
only:irr_lasthours <- get_timeseries_tsid("78930042", period = "PT12H30M") ggplot(irr_lasthours, aes(Timestamp, Value)) + geom_line() + xlab("") + ylab("irradiance (W/m2)")
from
and to
on month levelirr_2014 <- get_timeseries_tsid("78930042", from = "2014-07-01", to = "2014-08-01") ggplot(irr_2014, aes(Timestamp, Value)) + geom_line() + xlab("") + ylab("irradiance (W/m2)")
from
and period
irr_2014day <- get_timeseries_tsid("78930042", from = "2014-07-01", period = "P1D") ggplot(irr_2014day, aes(Timestamp, Value)) + geom_line() + xlab("") + ylab("irradiance (W/m2)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.