Learn R Programming

IRISSeismic (version 1.6.6)

mergeUpDownTimes: Determine overlaps in two sets of upDownTimes.

Description

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.

Usage

mergeUpDownTimes(udt1, udt2, bothOn)

Value

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

Arguments

udt1

vector of POSIXct times representing up/down transitions

udt2

vector of POSIXct times representing up/down transitions

bothOn

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

Author

Jonathan Callahan jonathan@mazamascience.com

Details

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.

See Also

getUpDownTimes, plotUpDownTimes

Examples

Run this code
if (FALSE) {
# 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
layout(matrix(seq(5)))

# 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
layout(1)
}

Run the code above in your browser using DataLab