mergeUpDownTimes: Determine overlaps in two sets of upDownTimes.

mergeUpDownTimesR Documentation

Determine overlaps in two sets of upDownTimes.


The mergeUpDownTimes function determines the overlaps in two sets of times representing up/down (on/off) periods for a single or a set of channels. This function can be used to determine overall station up/down periods.


mergeUpDownTimes(udt1, udt2, bothOn)



vector of POSIXct times representing up/down transitions


vector of POSIXct times representing up/down transitions


logical specifying whether overlaps are determined with AND or OR (default=FALSE: udt1 OR udt2)


When bothOn=FALSE, the default, this function returns the times of transitions from "either to neither" and back. When bothOn=TRUE, this function returns the times of transitions from "both to either" and back.

If an empty vector is passed in for udt1 or udt2 then the other vector is returned unchanged. This can be useful when merging the upDownTimes for multiple channels. See the example below.


A vector of POSIXct datetimes associated with on/off transitions.


The vector of times in udt1 and udt2 has no information on the values of min_signal or min_gap that were used to generate the timeseries. It is up to the user to make sure that the incoming vectors are appropriate for comparison. See getUpDownTimes.


Jonathan Callahan

See Also

getUpDownTimes, plotUpDownTimes


## Not run: 
# Open a connection to IRIS DMC webservices
iris <- new("IrisClient")

# Three Streams, each with different upDownTimes
starttime <- as.POSIXct("2012-07-01", tz="GMT")
endtime <- as.POSIXct("2012-07-02", tz="GMT")
stE <- getDataselect(iris,"IU","XMAS","10","BHE",starttime,endtime)
stN <- getDataselect(iris,"IU","XMAS","10","BHN",starttime,endtime)
stZ <- getDataselect(iris,"IU","XMAS","10","BHZ",starttime,endtime)
udtE <- getUpDownTimes(stE)
udtN <- getUpDownTimes(stN)
udtZ <- getUpDownTimes(stZ)

udtAll <- c()
udtAny <- c()
for (udt in list(udtE, udtN, udtZ)) {
  udtAll <- mergeUpDownTimes(udtAll,udt,bothOn=TRUE)
  udtAny <- mergeUpDownTimes(udtAny,udt,bothOn=FALSE)

# 5 rows

# Plot the results
par(mar=c(3,4,3,2)) # adjust margins
plotUpDownTimes(udtE); title("BHE")
plotUpDownTimes(udtN); title("BHN")
plotUpDownTimes(udtZ); title("BHZ")
plotUpDownTimes(udtAll); title("ALL channels up")
plotUpDownTimes(udtAny); title("ANY channel up")

# Restore default layout

## End(Not run)

IRISSeismic documentation built on Oct. 16, 2022, 1:09 a.m.