extractPeaks: Extracting peaks

View source: R/extractPeaks.R

extractPeaksR Documentation

Extracting peaks

Description

Extracts independent peaks

Usage

extractPeaks(vecTime = NULL, vecObs, mintimeDiff = 73, thrConst = (2/3))

Arguments

vecTime

an optional numeric vector containing information on the time variable. The vector is used to order the vecObs variable, so it should be provided if the data are not in chronological order If vecTime = NULL (the default) it is assumed that the data are correctly ordered.

vecObs

the vector of observations, the variable from which peaks should be extracted

mintimeDiff

the time after which peaks should be considered independent

thrConst

the constant defining how much the through should be smaller than the peaks to identify independent peaks

Details

This functions has been (sort of) tested in extracting peaks from 15 minutes data. The function assumes that two peaks are independent if they are at least mintimeDiff steps apart and if the minimumn amount of water in the though is less than thrConst the value of the maximum peak. mintimeDiff can not be given as an actual time measuraments, it is just an indicator of how many postions apart in the vecTIme vector two peaks need to be to be considered independent. Therefore vecTIme needs to be equally spaced, e.g. if missing values are present in the original file they should be infilled.

Value

a list of 0-1 values which indicate whether the vecObsvalue is a peak

Examples

zz <- data.frame(hour=seq(1, 240),
                 flow=sample(c(rnorm(200, 50, 5),rgev(40, 70,3,0.2))))
zz$isPeak <- extractPeaks(vecTime=zz$hour,vecObs=zz$flow,mintimeDiff=4)
plot(zz$hour, zz$flow, type = "l")
points(zz$hour[zz$isPeak==1], zz$flow[zz$isPeak==1], col=2)
## more hours needed to be assumed independent
zz$isPeak <- extractPeaks(vecTime=zz$hour,vecObs=zz$flow,mintimeDiff=8)
points(zz$hour[zz$isPeak==1], zz$flow[zz$isPeak==1], col=4)

ilapros/ilaprosUtils documentation built on April 6, 2023, 4:44 a.m.