Skip to content

Commit

Permalink
version 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillian Sharer authored and cran-robot committed Oct 1, 2020
1 parent bf484cb commit 61f3780
Show file tree
Hide file tree
Showing 29 changed files with 948 additions and 279 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Type: Package
Package: IRISSeismic
Version: 1.5.2
Version: 1.6.0
Title: Classes and Methods for Seismic Data Analysis
Authors@R: c(
person("Jonathan", "Callahan", email="jonathan@mazamascience.com", role=c("aut")),
Expand All @@ -16,19 +16,19 @@ Suggests: knitr,rmarkdown
VignetteBuilder: knitr
Description: Provides classes and methods for seismic data analysis. The
base classes and methods are inspired by the python code found in
the 'ObsPy' python toolbox <https://github.com/obsypy/obspy>. Additional classes and
the 'ObsPy' python toolbox <https://github.com/obspy/obspy>. Additional classes and
methods support data returned by web services provided by the 'IRIS DMC'
<http://service.iris.edu/>.
Collate: Class-Trace.R Class-Stream.R Class-IrisClient.R
mseedWrappers.R Utils.R spectralUtils.R
License: GPL (>= 2)
Repository: CRAN
NeedsCompilation: yes
Packaged: 2019-10-22 18:29:20 UTC; gillian
Packaged: 2020-10-01 17:39:38 UTC; gilliansharer
Author: Jonathan Callahan [aut],
Rob Casey [aut],
Gillian Sharer [aut, cre],
Mary Templeton [aut],
Chad Trabant [ctb]
Maintainer: Gillian Sharer <gillian@iris.washington.edu>
Date/Publication: 2019-10-22 20:00:02 UTC
Date/Publication: 2020-10-01 18:50:02 UTC
54 changes: 28 additions & 26 deletions MD5
@@ -1,43 +1,44 @@
050ac237d97c530fc6a5befdf9a842b4 *DESCRIPTION
bd2057865e80bf3c13427750eae7d42d *NAMESPACE
3721248756b41b8147f92b68acbb94e7 *R/Class-IrisClient.R
5616a9f8d8e224c49464a51f1dd5e1d8 *R/Class-Stream.R
b75e3c8b5a1c8e39c56413de15afbdf7 *R/Class-Trace.R
2e7af04710d339078a371a81b45d0bb0 *DESCRIPTION
53386287e1d1e79ae5c6af60296e0636 *NAMESPACE
88c0e9ef094fc77d20f5cd9233dea5ae *R/Class-IrisClient.R
add32763a630d724d98e9997dc9b949d *R/Class-Stream.R
8739893ef6fbbf71f92779549a85bf04 *R/Class-Trace.R
884619e7253c3037340ec0b725eaca04 *R/Utils.R
17258addfe8d9ef274ac38a1964572af *R/mseedWrappers.R
32216779191642f0c914d7870b8325fc *R/spectralUtils.R
6d5b101a5e415b2d30ea937ffdfceb7d *build/vignette.rds
cc4cdbfab2f40242859aba4aa45e66b6 *inst/doc/IRISSeismic-intro.R
7054a20fc3ca17d3daf9f1088a6886ba *inst/doc/IRISSeismic-intro.Rmd
4b063ce19ac127780ccf17d2a64f416e *inst/doc/IRISSeismic-intro.html
36366e041f5981f475f317576f9dfe82 *R/spectralUtils.R
ab7c140c7fcf183b59e1bb0b1fc887df *build/vignette.rds
fef1cc7e8fe6b99af1f9cbfe8f52edc2 *inst/doc/IRISSeismic-intro.R
55bc7cd1e0fd74a3b209cc2d44f2f404 *inst/doc/IRISSeismic-intro.Rmd
55201079a97c9f99c6c8c3a5cf98649e *inst/doc/IRISSeismic-intro.html
b1346e5656dd2a3cb6996891b8e3c487 *man/DDT.Rd
53c1fd551b2d5da51b07bf9f31c0db34 *man/IRISSeismic-package.Rd
88e74b20dbaced98de268ba146e35207 *man/IrisClient-class.Rd
9fb0c686fb2d0ae45244ade29a941039 *man/IRISSeismic-package.Rd
0286938591fb8d8fe60b31a35db1dd29 *man/IrisClient-class.Rd
7017b6bb847e8fe56768c5ccd8fcc042 *man/McNamaraBins.Rd
e2a904b2e92a17e376ae3d73a72b29e6 *man/McNamaraPSD.Rd
44cf545c211f8ae60203e44e4b4a41ee *man/STALTA.Rd
78333d61099b33000f49092c23024f8b *man/Stream-class.Rd
6d59d072cc54253c469d24f0601ec94e *man/Trace-class.Rd
2b86b9a5e8901f5d920ed93306fb0d83 *man/TraceHeader-class.Rd
862726d65bab0588450ba57bb76ed2ca *man/STALTA.Rd
b60369fed60b09e8fa0d518aa1f5b076 *man/Stream-class.Rd
ec34fd9305ac1d9ee2c3147c3bb2e77e *man/Trace-class.Rd
3d6071066913914b81b4efdbcb5a0c55 *man/TraceHeader-class.Rd
2e5cc96857019cfb98fac62304944231 *man/basicStats.Rd
00382bcd083ec432df1ac87437ffa292 *man/butterworth.Rd
53fd2671a8b19ce6b16d9118bdee6250 *man/crossSpectrum.Rd
11521a6994302f796b21a9e6cd20e4e4 *man/crossSpectrum.Rd
b2f77fe7483b0e1d3db066f2be3849b8 *man/envelope.Rd
950ed50c7e36304f828d319a76064ca4 *man/eventWindow.Rd
0c85b257fbb794844307a64b3dddd279 *man/getAvailability.Rd
9d7b5fb93e3996d801e3a9ba85035f85 *man/getChannel.Rd
5b252b34bef034fefcbb357094696b2e *man/getAvailability.Rd
5ec06b46d6f0275f15d3001dbd2a6615 *man/getChannel.Rd
075e584e080aac7cf0e5ca7cc5ad1140 *man/getDataAvailability.Rd
9c56d942f7787756a1d97eed2b948401 *man/getDataselect.Rd
cbc3d3230e67880f9ea31c6c8f3a25cf *man/getDataselect.Rd
4775f0327fe39c8f591920f40a0a8a02 *man/getDistaz.Rd
d40da4877a6ec5e9bb5ff439b5cacf91 *man/getEvalresp.Rd
7fe3b5db2d04a730856d9e5603b4a5d5 *man/getEvent.Rd
080c93bd7ab11a282a10e3274a69d88f *man/getEvent.Rd
76beba9f77bd36bb59b7025f7a662047 *man/getGaps.Rd
db335d3df26c3b148136ad330b0e9ce4 *man/getNetwork.Rd
7e23427481524bfc87a29a9f0024e816 *man/getNetwork.Rd
33a3fbda3af5fef7c90f30139c8d9676 *man/getRotation.Rd
b99f52ee5050b8310d56c4be016ae680 *man/getSNCL.Rd
789c37821305b1fb69ab5d94ed3e7e98 *man/getStation.Rd
942ba5a7369e4bf513d5470f1543cad0 *man/getStation.Rd
7881f95897f53fc034267f3be54aab72 *man/getTimeseries.Rd
c9c9654d7fac83cb5f97eac7a0de8d81 *man/getTraveltime.Rd
893fdad1b6291b0c5323eb4b9afdb8f1 *man/getUnavailability.Rd
342f62ea3a7b22b90380f94688784fb2 *man/getUnavailability.Rd
bb05c9f5a8e647952bfb0812f4d7a984 *man/getUpDownTimes.Rd
57b9feba101176f8763b7557c9c031bb *man/hilbert.Rd
adcf91b532bf810b748fa8f75c67b371 *man/hilbertFFT.Rd
Expand All @@ -56,7 +57,8 @@ fa66b1a1bf8cf6b04f24c0262265f5d6 *man/psdList.Rd
ffed92be190d1ce9da51517e0b618df5 *man/rmsVariance.Rd
a08787ff5d9b41c706bc93131da51d1a *man/rotate2D.Rd
076c259e8dd1f25a8567ae35997e053c *man/slice.Rd
bdbacc4bc92019a67cfb834b81e03d36 *man/surfaceDistance.Rd
dcfe3e4c0d6d9e7b4af4a7d0bd26eb30 *man/surfaceDistance.Rd
e1a72aa6a12f9b6f28d6b1ccbe85d847 *man/transferFunctionSpectra.Rd
1cdfa5c36107e8786b61e548e23c9b58 *man/triggerOnset.Rd
5502755d9d3bef1e349826e6234b92e8 *man/unHistogram.Rd
a1968590a918532db8db5c3c94a94574 *src/Makevars
Expand Down Expand Up @@ -201,6 +203,6 @@ a4b49353b5038a3c7824df585450a65b *src/libmseed/unpack.c
44494f7cd97a44702900777c56cb3fbf *src/libmseed/unpackdata.c
a2e3c3038b58a98c7865e3e839532077 *src/libmseed/unpackdata.h
cf675a1443ae88914c0b2b8b3111d0d6 *src/parseMiniSEED.c
7054a20fc3ca17d3daf9f1088a6886ba *vignettes/IRISSeismic-intro.Rmd
55bc7cd1e0fd74a3b209cc2d44f2f404 *vignettes/IRISSeismic-intro.Rmd
7c30695653c4728536070dbf0099f699 *vignettes/rstudio-IRISSeismic.png
236b60893fcdcc65318ace39d042c44f *vignettes/rstudio-windows.png
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -50,6 +50,7 @@ exportMethods(
"getStation",
"getSNCL",
"getDataAvailability",
"getTimeseries",
"getTraveltime",
"getUnavailability",
"getUpDownTimes",
Expand Down Expand Up @@ -113,6 +114,7 @@ export("crossSpectrum",
"psdList2NoiseMatrix",
"psdPlot",
"psdStatistics",
"transferFunctionSpectra",
"unHistogram"
)

Expand Down
225 changes: 223 additions & 2 deletions R/Class-IrisClient.R
Expand Up @@ -67,7 +67,7 @@ if (Sys.getenv("IrisClient_site") != "") {
# e.g. irisNetrc <- "/home/mustang/mustang.netrc"
# we will use no default here
irisNetrc <- NULL
if (Sys.getenv("IrisClient_netrc") != "") {
if (Sys.getenv("IrisClient_netrc") != "") {
irisNetrc <- Sys.getenv("IrisClient_netrc")
}

Expand Down Expand Up @@ -137,6 +137,9 @@ getDataselect.IrisClient <- function(obj, network, station, location, channel, s
# if we have a netrc definition, then use queryauth to access data
# else, use standard query call
url <- NULL

#print(paste0("irisNetrc=",irisNetrc))

if (! is.null(irisNetrc)) {
url <- paste(obj@site,obj@service_type,"dataselect/1/queryauth?",sep="/")
} else {
Expand Down Expand Up @@ -344,6 +347,224 @@ setMethod("getSNCL", signature(obj="IrisClient", sncl="character", starttime="PO
function(obj, sncl, starttime, endtime, ...)
getSNCL.IrisClient(obj, sncl, starttime, endtime, ...))

################################################################################
# getTimeseries method returns a Stream object
#
# Data are obtained from the timeseries web service:
#
# http://service.iris.edu/irisws/timeseries/1/
#
# This method functions much like getDataselect() but allows for various types
# of signal processing.
#
################################################################################

if (!isGeneric("getTimeseries")) {
setGeneric("getTimeseries", function(obj, network, station, location, channel, starttime, endtime, ...) {
standardGeneric("getTimeseries")
})
}

getTimeseries.IrisClient <- function(obj, network, station, location, channel, starttime, endtime, processing=NULL,
repository=NULL,inclusiveEnd=TRUE, ignoreEpoch=FALSE) {
if (!is.logical(inclusiveEnd)) {
stop(paste("getTimeseries.IrisClient: option inclusiveEnd must be TRUE or FALSE"))
}
if (!is.logical(ignoreEpoch)) {
stop(paste("getTimeseries.IrisClient: option inclusiveEnd must be TRUE or FALSE"))
}

url <- NULL
if (! is.null(irisNetrc)) {
url <- paste(obj@site,"irisws/timeseries/1/queryauth?",sep="/")
} else {
url <- paste(obj@site,"irisws/timeseries/1/query?",sep="/")
}

url <- paste(url,"net=", network,sep="")

url <- paste(url,"&sta=", station,sep="")
# NOTE: Locations with blanks must be converted into "--" when creating the URL
# NOTE: For getTimeseries only, convert "" to "--"
location <- ifelse(location=="","--",location)
url <- paste(url,"&loc=", str_replace(location," ","--"),sep="")
url <- paste(url,"&cha=", channel,sep="")
url <- paste(url,"&start=", format(starttime,"%Y-%m-%dT%H:%M:%OS6", tz="GMT"),sep="")
if (! inclusiveEnd) {
endtime <- endtime-0.000001
url <- paste(url,"&end=", format(endtime,"%Y-%m-%dT%H:%M:%OS6", tz="GMT"),sep="")
} else {
url <- paste(url,"&end=", format(endtime,"%Y-%m-%dT%H:%M:%OS6", tz="GMT"),sep="")
}
if (!is.null(repository) && obj@service_type != "ph5ws"){
if (repository %in% c("realtime","primary","bud","primary,realtime","realtime,primary")){
url <- paste(url,"&repository=",repository,sep="")
} else {
err_msg <- c("Invalid repository, acceptable values are 'realtime' and 'primary'. To search both, do not specify a repository.")
stop(paste("getTimeseries.IrisClient:",err_msg))
}
}

if (!is.null(processing)) {
url <- paste(url,processing,sep="")
}

url <- paste(url,"&format=miniseed",sep="")

if (obj@debug) {
write(paste("<debug>URL =",url), stdout())
}

# Make webservice request
# Make authenticated request using a netrc file
if (! is.null(irisNetrc)) {
h <- RCurl::basicTextGatherer()
result <- try( timeseriesResponse <- RCurl::getBinaryURL(url, useragent=obj@useragent,
netrc=1, netrc.file=irisNetrc, .opts = list(headerfunction = h$update,followlocation = TRUE, timeout=300, connecttimeout=300)),
silent=TRUE)

# Handle error response
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}

result <- try(header <- RCurl::parseHTTPHeader(h$value()))
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}
if (header["status"] == "401") { # authentication error, try again
Sys.sleep(3)
h <- RCurl::basicTextGatherer()
result <- try( timeseriesResponse <- RCurl::getBinaryURL(url, useragent=obj@useragent,
netrc=1, netrc.file=irisNetrc, .opts = list(headerfunction = h$update,followlocation = TRUE, timeout=300, connecttimeout=300)),
silent=TRUE)
# Handle error response
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}

result <- try(header <- RCurl::parseHTTPHeader(h$value()))
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}
}
if (header["status"] == "500") { # internal server error, try again
Sys.sleep(3)
h <- RCurl::basicTextGatherer()
result <- try( timeseriesResponse <- RCurl::getBinaryURL(url, useragent=obj@useragent,
netrc=1, netrc.file=irisNetrc, .opts = list(headerfunction = h$update,followlocation = TRUE, timeout=300, connecttimeout=300)),
silent=TRUE)
# Handle error response
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}
result <- try(header <- RCurl::parseHTTPHeader(h$value()))
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}
}

} else {
h <- RCurl::basicTextGatherer()
result <- try( timeseriesResponse <- RCurl::getBinaryURL(url, useragent=obj@useragent, .opts = list(headerfunction = h$update,followlocation = TRUE, timeout=300, connecttimeout=300)),
silent=TRUE)

# Handle error response
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg,url))
}

result <- try(header <- RCurl::parseHTTPHeader(h$value()))
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}

if (header["status"] == "500") { # internal server error, try again
Sys.sleep(3)
h <- RCurl::basicTextGatherer()
result <- try( timeseriesResponse <- RCurl::getBinaryURL(url, useragent=obj@useragent,
netrc=1, netrc.file=irisNetrc, .opts = list(headerfunction = h$update,followlocation = TRUE, timeout=300, connecttimeout=300)),
silent=TRUE)
# Handle error response
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}
result <- try(header <- RCurl::parseHTTPHeader(h$value()))
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}
}

}


if (header["status"] == "204") { #irisws timeseries returned nothing
stop(paste("getTimeseries.IrisClient: No Data:",header["status"],url))
}

if (header["status"] != "200") { #irisws timeseries returned something unexpected
if (header["status"] == "400") {
stop(paste("getTimeseries.IrisClient: Bad Request:",url))
} else if (header["status"] == "404") {
stop(paste("getTimeseries.IrisClient: URL Not Found:",url))
} else {
stop(paste("getTimeseriesIrisClient: Unexpected http status code",header["status"],header["statusMessage"],url))
}
}


# No errors so proceed

# Channel metadata is required to properly apply InstrumentSensitivity corrections
result <- try( channels <- getChannel(obj, network, station, location, channel, starttime, endtime),
silent=TRUE)

# Handle error response
if (class(result) == "try-error" ) {
err_msg <- geterrmessage()
stop(paste("getTimeseries.IrisClient:",err_msg, url))
}

# NOTE: Sometimes, the station webservice will return multiple records for the same SNCL
# NOTE: each with a different scale or starttime. This still represents a single SNCL.
# NOTE: What to do about multiple scales in the following getChannel request?
# Solution 1: if ignoreEpoch==TRUE, then just take the first epoch presented
# http://service.iris.edu/fdsnws/station/1/query?net=H2&sta=H2O&loc=00&cha=LHZ&starttime=2001-02-28T18:29:44&endtime=2001-02-28T19:29:44&includerestricted=false&format=text&level=channel

sncls <- paste(channels$network,channels$station,channels$location,channels$channel)
if (nrow(channels) > 1 && !ignoreEpoch) {
stop(paste("getTimeseries.IrisClient: Multiple epochs: getChannel returned",length(sncls),"records"))
} else {
channelInfo <- channels[1,]
}

# No errors so proceed

stream <- miniseed2Stream(timeseriesResponse,url,starttime,endtime,
channelInfo$instrument,channelInfo$scale,channelInfo$scalefreq,channelInfo$scaleunits,channelInfo$latitude,
channelInfo$longitude,channelInfo$elevation,channelInfo$depth,channelInfo$azimuth,channelInfo$dip)

return(stream)
}

# All arguments specified
setMethod("getTimeseries", signature(obj="IrisClient", network="character", station="character", location="character",
channel="character", starttime="POSIXct", endtime="POSIXct"),
function(obj, network, station, location, channel, starttime, endtime, ...)
getTimeseries.IrisClient(obj, network, station, location, channel, starttime, endtime, ...))



################################################################################
# getRotation method returns a list of three Stream objects
#
Expand Down Expand Up @@ -1095,7 +1316,7 @@ setMethod("getUnavailability", signature(obj="IrisClient",
# getDataAvailability method returns a dataframe with information from the output
# of the iris availability web service with "format=text&level=channel".
#
# http://service.iris.edu/irisws/availability/1/
# http://service.iris.edu/fdsnws/availability/1/
#
################################################################################
if (!isGeneric("getDataAvailability")) {
Expand Down

0 comments on commit 61f3780

Please sign in to comment.