Skip to content

Commit d3130fe

Browse files
Merge pull request #30 from EarthScope/lk-ph5-fixes
PH5 fixes
2 parents 8d59b28 + 78b25e9 commit d3130fe

File tree

5 files changed

+61
-52
lines changed

5 files changed

+61
-52
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ path to a directory containing miniSEED files (_See: "Using Local Data Files", b
323323
* `station_url:` should indicate a metadata location as an FDSN web service alias, EARTHSCOPE (an alias of 'IRIS'),
324324
the EarthScope PH5 web service alias 'IRISPH5',
325325
an explicit URL, or a path to a file containing metadata in [StationXML](https://www.fdsn.org/xml/station/) format
326-
([schema](https://www.fdsn.org/xml/station/fdsn-station-1.0.xsd)). For web services, this should point to the same place as
327-
`dataselect_url` (e.g. `https://service.earthscope.org`). For local metadata, StationXML is read at the channel level and any
326+
([schema](https://www.fdsn.org/xml/station/fdsn-station-1.0.xsd)). If both `dataselect_url` and `station_url` point to web services, they should point to the same location (e.g. `https://service.earthscope.org`). For local metadata, StationXML is read at the channel level and any
328327
response information is ignored. Local instrument response (if used) is expected to be in RESP file format and specified
329328
in the `resp_dir` entry (see below). If neither webservices or StationXML is available for metadata, the `station_url` entry
330329
should be left unspecified (blank). In this case, metrics that do not require metadata will still be calculated. Metrics that
@@ -344,7 +343,7 @@ orientation_check*). The EarthScope event service is deprecated and event_urls d
344343
redirect to the USGS event service at https://earthquake.usgs.gov.
345344
346345
* `resp_dir:` should be unspecified or absent if local response files are not used. The default behavior
347-
is to retrieve response information from the EarthScope web service [Evalresp](https://service.earthscope.org/irisws/evalresp/1/).
346+
is to retrieve response information from the EarthScope web service [Evalresp](https://service.earthscope.org/irisws/evalresp/1/). If the Earthscope PH5 service (IRISPH5) is the source for the `station_url`, then it will default to the [ph5 Evalresp] (https://service.earthscope.org/ph5ws/evalresp/1/) instead.
348347
To use local instrument responses instead of [Evalresp](https://service.earthscope.org/irisws/evalresp/1/),
349348
this parameter should indicate a path to a directory containing response files
350349
in [RESP](https://ds.iris.edu/ds/nodes/dmc/data/formats/resp/) format. Local response files are expected to be

ispaq/PSD_metrics.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,12 @@ def do_psd(concierge,starttime,endtime):
103103
# Run the PSD metric ----------------------------------------
104104
if any(key in function_metadata for key in ("PSD","PSDText")) :
105105
try:
106-
evalresp = None
107-
if (concierge.resp_dir): # if resp_dir: run evalresp on local RESP file instead of web service
108-
sampling_rate = utils.get_slot(r_stream, 'sampling_rate')
109-
evalresp = utils.getSpectra(r_stream, sampling_rate, "PSD", concierge)
110-
if (concierge.dataselect_type == "ph5ws"):
106+
try:
111107
sampling_rate = utils.get_slot(r_stream, 'sampling_rate')
112108
evalresp = utils.getSpectra(r_stream, sampling_rate, "PSD", concierge)
109+
except Exception as e:
110+
logger.warning('"PSD_metric" metric calculation failed for %s: %s' % (av.snclId, e))
111+
113112
# get corrected PSD
114113
try:
115114
(df, PSDcorrected, PDF) = irismustangmetrics.apply_PSD_metric(concierge, r_stream, evalresp=evalresp)

ispaq/concierge.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -140,37 +140,34 @@ def __init__(self, user_request=None, logger=None):
140140
if (user_request.event_url == "IRIS" or user_request.event_url.upper() == "EARTHSCOPE"):
141141
user_request.event_url = "USGS"
142142

143-
# Add dataselect clients and URLs or reference a local file
143+
## Add dataselect clients and URLs or reference a local file
144144
self.dataselect_type = None
145145
if user_request.dataselect_url in URL_MAPPINGS.keys():
146146
# Get data from FDSN dataselect service
147147
self.dataselect_url = URL_MAPPINGS[user_request.dataselect_url]
148148
self.dataselect_type = "fdsnws"
149+
150+
if user_request.dataselect_url == "IRISPH5":
151+
self.dataselect_type = "ph5ws"
152+
149153
try:
150-
self.dataselect_client = Client(self.dataselect_url)
154+
self.dataselect_client = Client(user_request.dataselect_url)
151155
except Exception as e:
152156
err_msg = e
153157
self.logger.critical(err_msg)
154158
raise SystemExit
155159

156-
if user_request.station_url is not None:
157-
if user_request.station_url != user_request.dataselect_url:
158-
self.logger.warning("Station_url should be the same as dataselect_url when retrieving data from FDSN webservices. Station_url '%s' does not match dataselect_url '%s'"
159-
% (user_request.station_url, user_request.dataselect_url))
160-
161-
elif user_request.dataselect_url == "IRISPH5":
162-
self.dataselect_url = "https://service.earthscope.org"
163-
self.dataselect_type = "ph5ws"
164-
self.dataselect_client = "PH5"
165-
166160
if user_request.station_url is not None:
167161
if user_request.station_url != user_request.dataselect_url:
168-
self.logger.warning("Station_url should be the same as dataselect_url when retreiving data from IRIS PH5 webservices. Station_url '%s' does not match dataselect_url '%s'"
169-
% (user_request.station_url, user_request.dataselect_url))
162+
self.logger.warning("Station_url should be the same as dataselect_url when retrieving data from FDSN or PH5 web services. Station_url '%s' does not match dataselect_url '%s'")
170163

171164
elif "http://" in user_request.dataselect_url or "https://" in user_request.dataselect_url:
172165
self.dataselect_url = user_request.dataselect_url
173166
self.dataselect_type = "fdsnws"
167+
168+
if "ph5ws" in user_request.dataselect_url:
169+
self.dataselect_type = "ph5ws"
170+
174171
try:
175172
self.dataselect_client = Client(self.dataselect_url)
176173
except Exception as e:
@@ -180,7 +177,7 @@ def __init__(self, user_request=None, logger=None):
180177

181178
if user_request.station_url is not None:
182179
if user_request.station_url != user_request.dataselect_url:
183-
self.logger.warning("Station_url should be the same as dataselect_url when retreiving data from FDSN webservices. Station_url '%s' does not match dataselect_url '%s'"
180+
self.logger.warning("Station_url should be the same as dataselect_url when retrieving data from FDSN webservices. Station_url '%s' does not match dataselect_url '%s'"
184181
% (user_request.station_url, user_request.dataselect_url))
185182

186183
else:
@@ -193,43 +190,48 @@ def __init__(self, user_request=None, logger=None):
193190
self.logger.critical(err_msg)
194191
raise SystemExit
195192

196-
# Add station clients and URLs or reference a local file
193+
## Add station clients and URLs or reference a local file
194+
self.station_type = None
197195
if user_request.station_url is None:
198196
if ("http://" in self.dataselect_url or "https://" in self.dataselect_url):
199197
self.station_url = self.dataselect_url
198+
self.station_type = self.dataselect_type
200199
self.logger.info("Using station_url = %s" % self.dataselect_url)
201-
if (self.dataselect_type == "ph5ws"):
202-
self.station_type = "ph5ws"
203-
self.station_client = "PH5"
204-
else:
205-
try:
206-
self.station_client = Client(self.station_url)
207-
except Exception as e:
208-
self.logger.warning(e)
209-
self.logger.info("Metrics that require metadata information cannot be calculated")
210-
self.station_url = None
211-
self.station_client = None
200+
201+
try:
202+
self.station_client = Client(self.station_url)
203+
except Exception as e:
204+
self.logger.warning(e)
205+
self.logger.info("Metrics that require metadata information cannot be calculated")
206+
self.station_url = None
207+
self.station_client = None
212208
else:
213209
self.logger.info("No station_url found")
214210
self.logger.info("Metrics that require metadata information cannot be calculated")
215211
self.station_url = None
216212
self.station_client = None
217213
elif user_request.station_url in URL_MAPPINGS.keys():
218214
self.station_url = URL_MAPPINGS[user_request.station_url]
215+
self.station_type = "fdsnws"
216+
217+
if user_request.station_url == "IRISPH5":
218+
self.station_type = "ph5ws"
219+
219220
try:
220-
self.station_client = Client(self.station_url)
221+
self.station_client = Client(user_request.station_url)
221222
except Exception as e:
222223
self.logger.warning(e)
223224
self.logger.info("Metrics that require metadata information cannot be calculated")
224225
self.station_url = None
225226
self.station_client = None
226-
elif user_request.station_url == "IRISPH5":
227-
self.station_url = "https://service.earthscope.org"
228-
self.station_type = "ph5ws"
229-
self.station_client = "PH5"
230227

231228
elif "http://" in user_request.station_url or "https://" in user_request.station_url:
232229
self.station_url = user_request.station_url
230+
self.station_type = 'fdsnws'
231+
232+
if "ph5ws" in user_request.station_url:
233+
self.station_type = 'ph5ws'
234+
233235
try:
234236
self.station_client = Client(self.station_url)
235237
except Exception as e:
@@ -381,9 +383,9 @@ def __init__(self, user_request=None, logger=None):
381383
self.filtered_availability = None
382384

383385
# Add local response files if used
384-
if user_request.resp_dir is None: # use irisws/evalresp
385-
self.resp_dir = None # use irisws/evalresp
386-
elif user_request.resp_dir in URL_MAPPINGS.keys(): # use irisws/evalresp
386+
if user_request.resp_dir is None: # use EarthScope evalresp web service
387+
self.resp_dir = None # use EarthScope evalresp web service
388+
elif user_request.resp_dir in URL_MAPPINGS.keys(): # use EarthScope evalresp web service
387389
self.resp_dir = None
388390
else:
389391
if os.path.exists(os.path.abspath(user_request.resp_dir)):
@@ -398,7 +400,9 @@ def __init__(self, user_request=None, logger=None):
398400
self.logger.debug("metric_names %s", self.metric_names)
399401
self.logger.debug("sncl_patterns %s", self.sncl_patterns)
400402
self.logger.debug("dataselect_url %s", self.dataselect_url)
403+
self.logger.debug("dataselect_type %s", self.dataselect_type)
401404
self.logger.debug("station_url %s", self.station_url)
405+
self.logger.debug("station_type %s", self.station_type)
402406
self.logger.debug("event_url %s", self.event_url)
403407
self.logger.debug("resp_dir %s", self.resp_dir)
404408
self.logger.debug("output %s", self.output)
@@ -753,6 +757,8 @@ def get_availability(self, metric,
753757
else:
754758
_channel = channel
755759

760+
761+
756762
_sncl_pattern = self.get_sncl_pattern(_network, _station, _location, _channel)
757763

758764

@@ -773,7 +779,7 @@ def get_availability(self, metric,
773779

774780
if df is None:
775781
continue
776-
elif self.station_client == "PH5":
782+
elif self.station_type == "ph5ws":
777783
self.logger.debug("read IRISPH5 station web services %s/%s for %s,%s,%s,%s,%s,%s" % (self.station_url,self.station_type,_network, _station, _location, _channel, _starttime.strftime('%Y.%j'), _endtime.strftime('%Y.%j')))
778784
try:
779785
df = irisseismic.getAvailability(self.station_url,self.station_type,network=_network, station=_station,
@@ -972,14 +978,14 @@ def get_availability(self, metric,
972978
next
973979
df = df[df.dist.str.contains("KEEP")]
974980
df = df.drop('dist', 1)
981+
975982

976983
# Append this dataframe
977984
if df.shape[0] == 0:
978985
self.logger.debug("No SNCLS found matching '%s' (sncl_format=%s)" % (_sncl_pattern,self.sncl_format))
979986
else:
980987
#if df.snclId not in sncl_pattern_dataframes[:].snclId:
981988
sncl_pattern_dataframes.append(df) # tack the dataframes together
982-
983989
# END of sncl_patterns loop --------------------------------------------
984990

985991
if len(sncl_pattern_dataframes) == 0:

ispaq/ispaq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from _ast import Try
1616
from numpy.random import sample
1717

18-
__version__ = "3.2.1"
18+
__version__ = "3.3.0"
1919

2020
# dictionary of currently defined ISPAQ metric groups and business logic
2121
# for comparison with R package IRISMustangMetrics/ISPAQUtils.R json

ispaq/utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def getSpectra(st, sampling_rate, metric, concierge):
648648

649649
try:
650650
evalResp = evresp.getEvalresp(localFiles, network, station, location, channel, starttime,
651-
minfreq, maxfreq, nfreq, units.upper(), output.upper(), "LOG", debugMode)
651+
minfreq, maxfreq, nfreq, units.upper(), output.upper(), "LOG", debugMode)
652652
except Exception as e:
653653
raise
654654

@@ -657,12 +657,17 @@ def getSpectra(st, sampling_rate, metric, concierge):
657657
if evalResp is None:
658658
raise EvalrespException('No RESP file found at %s[.txt] or %s[.txt]' % (localFile,localFile2))
659659

660-
else:
661-
# calling the web service
662-
concierge.logger.debug('calling IRIS evalresp web service')
660+
else:
661+
## Use web services
663662
try:
664-
evalResp = irisseismic.getEvalresp(concierge.dataselect_url, concierge.dataselect_type, network, station, location, channel, starttime,
665-
minfreq, maxfreq, nfreq, units.lower(), output.lower())
663+
if concierge.station_type == None:
664+
concierge.logger.debug(f'calling irisws evalresp web service')
665+
evalResp = irisseismic.getEvalresp(network=network, station=station, location=location, channel=channel, time=starttime,
666+
minfreq=minfreq, maxfreq=maxfreq, nfreq=nfreq, units=units.lower(), output=output.lower())
667+
else:
668+
concierge.logger.debug(f'calling {concierge.station_url} - {concierge.station_type} evalresp web service')
669+
evalResp = irisseismic.getEvalresp(client_url=concierge.station_url, client_type=concierge.station_type,network=network, station=station, location=location, channel=channel, time=starttime,
670+
minfreq=minfreq, maxfreq=maxfreq, nfreq=nfreq, units=units.lower(), output=output.lower())
666671
except Exception as e:
667672
raise
668673
return(evalResp)

0 commit comments

Comments
 (0)