Title: | Detect and Characterize Sub-Daily Flow Fluctuations |
---|---|
Description: | An important environmental impact on running water ecosystems is caused by hydropeaking - the discontinuous release of turbine water because of peaks of energy demand. An event-based algorithm is implemented to detect flow fluctuations referring to increase events (IC) and decrease events (DC). For each event, a set of parameters related to the fluctuation intensity is calculated. The framework is introduced in Greimel et al. (2016) "A method to detect and characterize sub-daily flow fluctuations" <doi:10.1002/hyp.10773> and can be used to identify different fluctuation types according to the potential source: e.g., sub-daily flow fluctuations caused by hydropeaking, rainfall, or snow and glacier melt. This is a companion to the package 'hydroroute', which is used to detect and follow hydropower plant-specific hydropeaking waves at the sub-catchment scale and to describe how hydropeaking flow parameters change along the longitudinal flow path as proposed and validated in Greimel et al. (2022). |
Authors: | Bettina Grün [cre, ctb] , Julia Haider [aut], Franz Greimel [ctb] |
Maintainer: | Bettina Grün <[email protected]> |
License: | GPL-2 |
Version: | 0.1.2 |
Built: | 2024-12-11 07:13:50 UTC |
Source: | CRAN |
Given an event with equal flow trend, all metrics implemented in the package hydropeak are computed and combined to a data frame. It includes also an identifier of the gauging station provided by the user and the starting time of the event.
all_metrics(x, id, event_type)
all_metrics(x, id, event_type)
x |
Data frame (time series) from an event with equal flow trend. The
data frame must contain a date-time column ( |
id |
Character string which refers to the identifier of the gauging station (in Austria: HZBCODE). |
event_type |
Numeric value which indicates the event type. By using
|
A data frame including all computed metrics, IDs of gauging stations,
event type (see event_type()
for an overview of
possible event types), and starting time of an event x
.
Included metrics are amp()
, mafr()
,
mefr()
, dur()
, ratio()
.
data(Q) # decreasing event: Q4 <- flow(Q[3:4, ]) all_metrics(Q4, id = Q$ID[1], event_type = 4) all_metrics(Q4, id = Q$ID[1], event_type = event_type(Q4)) # increasing event: Q2 <- flow(Q[486:487, ]) all_metrics(Q2, id = Q$ID[1], event_type = 2) all_metrics(Q2, id = Q$ID[1], event_type = event_type(Q2)) # constant event (at beginning or after NA event): Q0 <- flow(Q[1:3, ]) all_metrics(Q0, id = Q$ID[1], event_type = 0) all_metrics(Q0, id = Q$ID[1], event_type = event_type(Q0))
data(Q) # decreasing event: Q4 <- flow(Q[3:4, ]) all_metrics(Q4, id = Q$ID[1], event_type = 4) all_metrics(Q4, id = Q$ID[1], event_type = event_type(Q4)) # increasing event: Q2 <- flow(Q[486:487, ]) all_metrics(Q2, id = Q$ID[1], event_type = 2) all_metrics(Q2, id = Q$ID[1], event_type = event_type(Q2)) # constant event (at beginning or after NA event): Q0 <- flow(Q[1:3, ]) all_metrics(Q0, id = Q$ID[1], event_type = 0) all_metrics(Q0, id = Q$ID[1], event_type = event_type(Q0))
The amplitude (AMP, unit: ) of an event is defined as
the difference between the flow maximum (
) and the
flow minimum (
).
Given an event with equal flow trend, the amplitude is computed and returned.
amp(x)
amp(x)
x |
Data frame (time series) from an event with equal flow trend. The
data frame must contain a date-time column ( |
Returns a positive numeric value which is the difference of
max(x$Q)
and min(x$Q)
of an event. If a data frame containing
NA
flow rates (Q
) is given, NA
is returned.
data(Q) Q <- flow(Q[3:4, ]) amp(Q)
data(Q) Q <- flow(Q[3:4, ]) amp(Q)
The duration of an event is specified as the number of consecutive time steps with equal flow trend.
dur(x)
dur(x)
x |
Data frame (time series) from an event with equal flow trend. The
data frame must contain a date-time column ( |
Returns an integer value which is the number of consecutive time steps.
data(Q) Q <- flow(Q[3:4, ]) dur(Q)
data(Q) Q <- flow(Q[3:4, ]) dur(Q)
Given a data frame (time series) of equal flow (Q) trend, it is determined whether the flow is increasing or decreasing, constant or if missing values occur. It returns a numeric value which indicates the event type. As the event type is already determined when the change points are computed, this function is mainly used for demonstration purpose or if metrics should be computed individually.
event_type(x)
event_type(x)
x |
Data frame (time series) from an event with equal flow trend. Data
frame must contain a date-time column ( |
Returns an numeric value which indicates the event type. Event types are defined as follows:
0: Constant event after NA event or constant event as first event in time series
1: Constant event after DC
2: Increasing event (IC)
3: Constant event after IC
4: Decreasing event (DC)
5: NA event
data(Q) # decreasing event Q4 <- flow(Q[3:4, ]) event_type(Q4) # increasing event Q2 <- flow(Q[486:487, ]) event_type(Q2)
data(Q) # decreasing event Q4 <- flow(Q[3:4, ]) event_type(Q4) # increasing event Q2 <- flow(Q[486:487, ]) event_type(Q2)
A complementary dataset to the flow fluctuation dataset Q. It contains
the events and metrics such as computed by get_events()
.
Events
Events
A data frame with 165 rows and 8 variables:
Character string which refers to the identifier of the gauging station (in Austria: HZBCODE)
Event types are defined as follows:
0: Constant event after NA event or constant event as first event in time series
1: Constant event after DC
2: Increasing event (IC)
3: Constant event after IC
4: Decreasing event (DC)
5: NA event
Date-time of event starting point
Amplitude (amp()
)
Maximum flow fluctuation rate (mafr()
)
Mean flow fluctuation rate (mefr()
)
Duration (dur()
)
Flow ratio (ratio()
)
The function flow()
creates a flow rate time series object
which is formatted to be compatible with the functions in the hydropeak
package.
flow( x, format = "%d.%m.%Y %H:%M", tz = "Etc/GMT-1", cols = c(1, 2, 3), steplength = 15, full = TRUE ) validate_flow(x)
flow( x, format = "%d.%m.%Y %H:%M", tz = "Etc/GMT-1", cols = c(1, 2, 3), steplength = 15, full = TRUE ) validate_flow(x)
x |
Data frame which contains at least a column with an ID of the gauging station, a column with date-time values in character representation and a column with flow rates |
format |
Character string giving the date-time format of the date-time
column in the input data frame (default: |
tz |
Character string specifying the time zone to be used for the conversion
(default: |
cols |
Integer vector specifying column indices in the input data frame which contain gauging station ID, date-time and flow rate to be renamed. The default indices are 1 (ID), 2 (date-time) and 3 (flow rate, Q). |
steplength |
Numeric value which specifies the distance between (equispaced)
time steps in minutes. (default: |
full |
A logical. If |
Returns a flow
object which inherits from data frame (time series).
It contains at least a gauging station ID column (ID
) converted to
character values, a date-time column (Time
) converted to class "POSIXlt"
(see base::strptime()
) and a flow rate column
(Q
), which is converted to numeric values. The flow()
object
ensures that input flow fluctuation time series data can be processed with
the functions in the hydropeak package. Therefore, it is mandatory
to provide the correct indices (see argument cols
) and the correct
date-time format (see argument format
) of the input data frame.
data(Q) Q <- flow(Q)
data(Q) Q <- flow(Q)
Given a data frame (time series) of stage measurements, all
increase (IC) and decrease (DC) events are determined and all metrics
implemented in the package hydropeak
(see all_metrics()
) are computed and combined
to a data frame. Optionally, NA events and constant events can be included.
NA events occur due to missing stage measurement values. The beginning
of NA events refers to the last measurement with a non-missing Q value.
Constant events are events where the Q values stay constant over time.
An event is uniquely identifiable through the combination of the event starting
time (Time
) and the gauging station identifier (ID
).
get_events(x, mc.cores = 2L, omit.constant = TRUE, omit.na = TRUE, ...)
get_events(x, mc.cores = 2L, omit.constant = TRUE, omit.na = TRUE, ...)
x |
Data frame (time series) of stage measurements which contains at
least a column with ID of the gauging station (default: column index 1)
column with date-time values (default: columns index 2) in character
representation and a column with flow rates (default: column index 3).
If the column indices differ from |
mc.cores |
Number of cores to use with
|
omit.constant |
A logical. If |
omit.na |
A logical. If |
... |
Arguments to be passed to |
A data frame which contains for every event in a given time series all
metrics (all_metrics()
), gauging station ID,
event type, and starting time of an event.
Included metrics are amp()
, mafr()
,
mefr()
, dur()
,
ratio()
. These metrics are only computed for
increasing (IC) and decreasing (DC) events. For all other events the
values are set to 0 except for flow ratio that is set to 1.
Event types are defined as follows:
0: Constant event after NA event or constant event as first event in time series
1: Constant event after DC
2: Increasing event (IC)
3: Constant event after IC
4: Decreasing event (DC)
5: NA event
# Data with multiple events and different stations data(Q) get_events(Q) # including constant events get_events(Q, omit.constant = FALSE)
# Data with multiple events and different stations data(Q) get_events(Q) # including constant events get_events(Q, omit.constant = FALSE)
Given a directory path it calls
get_events_file()
for each file in the directory,
recursively. The resulting events are split into separate files for each
gauging station ID (ID
) and Event_Type
and are written to
the given output directory.
get_events_dir( Q_dir, inputsep = ";", inputdec = ".", outdir = file.path(tempdir(), "Events"), mc.cores = 2L, ... )
get_events_dir( Q_dir, inputsep = ";", inputdec = ".", outdir = file.path(tempdir(), "Events"), mc.cores = 2L, ... )
Q_dir |
A character string containing the path name where the input data are located. |
inputsep |
Field separator character string for input data. |
inputdec |
Character string for decimal points in input data. |
outdir |
A character string naming a directory where the output file(s) should be written to. |
mc.cores |
Number of cores to use with
|
... |
Arguments to be passed to |
No return value, called for side effects.
Q_dir <- "./inst/extdata" get_events_dir(Q_dir, inputsep = ",", inputdec = ".")
Q_dir <- "./inst/extdata" get_events_dir(Q_dir, inputsep = ",", inputdec = ".")
Given a file path it reads a data frame (time series) of stage
measurements and calls get_events()
.
The resulting events can be optionally written to a single file or to
separate files for each gauging station ID (ID
) and Event_Type
.
Files which produce errors return NULL
.
get_events_file( Q_file, inputsep = ";", inputdec = ".", save = FALSE, split = TRUE, outdir = file.path(tempdir(), "Events"), mc.cores = 2L, return = TRUE, ... )
get_events_file( Q_file, inputsep = ";", inputdec = ".", save = FALSE, split = TRUE, outdir = file.path(tempdir(), "Events"), mc.cores = 2L, return = TRUE, ... )
Q_file |
A character string containing the name of the file which the data
are to be read from with |
inputsep |
Field separator character string for input data. |
inputdec |
Character string for decimal points in input data. |
save |
A logical. If |
split |
A logical. If |
outdir |
A character string naming a directory where the output file(s) should be written to. |
mc.cores |
Number of cores to use with
|
return |
A logical. If |
... |
Arguments to be passed to |
A data frame which contains for every increase or decrease event in a
given time series all metrics (all_metrics()
),
gauging station ID, event type, and starting time of an event.
Included metrics are amp()
, mafr()
,
mefr()
, dur()
, ratio()
.
The returned data frame is not split. Returns NULL
, if argument
return
is set to FALSE
.
Q_file <- system.file("extdata", "Q.csv", package = "hydropeak") # save to tempdir() events <- get_events_file(Q_file, inputsep = ",", inputdec = ".", save = TRUE, split = TRUE, return = TRUE)
Q_file <- system.file("extdata", "Q.csv", package = "hydropeak") # save to tempdir() events <- get_events_file(Q_file, inputsep = ",", inputdec = ".", save = TRUE, split = TRUE, return = TRUE)
The maximum flow fluctuation rate (MAFR, unit: )
represents the highest absolute flow change of two consecutive time steps
within an event. Given an event with equal flow trend, the maximum flow
fluctuation rate is computed and returned.
mafr(x)
mafr(x)
x |
Data frame (time series) from an event with equal flow trend. The
data frame must contain a date-time column ( |
Returns a numeric value which is the maximum (absolute) flow
fluctuation rate. If a data frame containing NA
flow rates (Q
)
is given, NA
is returned.
data(Q) Q <- flow(Q[3:4, ]) mafr(Q)
data(Q) Q <- flow(Q[3:4, ]) mafr(Q)
The mean flow fluctuation rate (MEFR, unit: ) is
calculated by the event amplitude divided by the number of time steps
(duration) within an event. Given an event with equal flow trend, amplitude
and duration are computed. From these metrics the mean flow fluctuation
rate is calculated and returned.
mefr(x)
mefr(x)
x |
Data frame (time series) from an event with equal flow trend. The
data frame must contain a date-time column ( |
Returns a numeric value which is the mean flow fluctuation rate computed
by the event amplitude amp()
divided by the number of
time steps dur()
. If a data frame containing NA
flow rates (Q
) is given, NA
is returned.
data(Q) Q <- flow(Q[3:4, ]) mefr(Q)
data(Q) Q <- flow(Q[3:4, ]) mefr(Q)
A dataset containing sub-daily flow fluctuations of five consecutive days from two different gauging stations. One time step is 15 minutes.
Q
Q
A data frame with 960 rows and 3 variables:
Character string which refers to the identifier of the gauging station (in Austria: HZBCODE)
Character string with date-time information of stage measurements
which needs to be converted to a compatible format (see flow()
)
Flow, stage measurements in
The metric flow ratio (RATIO) is defined as the flow maximum
divided by the flow minimum, .
Given an event with equal flow trend, the flow ratio is computed and returned.
ratio(x, event_type)
ratio(x, event_type)
x |
Data frame (time series) from an event with equal flow trend. The
data frame must contain a date-time column ( |
event_type |
Numeric value which specifies the event type. See
|
Returns a numeric value which is the flow ratio computed by
max(x$Q)
divided by min(x$Q)
. If a data frame containing
NA
flow rates (Q
) is given, NA
is returned.
data(Q) Q <- flow(Q[3:4, ]) ratio(Q, event_type(Q))
data(Q) Q <- flow(Q[3:4, ]) ratio(Q, event_type(Q))