Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #424 from mhearne-usgs/logtest
Browse files Browse the repository at this point in the history
Fixing issues with event ids that have underscores in them.
  • Loading branch information
emthompson-usgs authored Sep 23, 2019
2 parents d53f0bf + f1c45bc commit 9b675e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
26 changes: 21 additions & 5 deletions gmprocess/io/asdf/stream_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def getLabels(self):
all_tags = []
for w in self.dataset.waveforms:
all_tags.extend(w.get_waveform_tags())
all_labels = list(set([at.split('_')[1] for at in all_tags]))
all_labels = list(set([at.split('_')[-1] for at in all_tags]))
labels = list(set(all_labels))
return labels

Expand Down Expand Up @@ -338,7 +338,12 @@ def getStreams(self, eventid, stations=None, labels=None):
for waveform in self.dataset.waveforms:
tags = waveform.get_waveform_tags()
for tag in tags:
teventid, tlabel = tag.split('_')
parts = tag.split('_')
if len(parts) > 2:
tlabel = parts[-1]
teventid = '_'.join(parts[0:-1])
else:
teventid, tlabel = tag.split('_')
if eventid != teventid:
continue
if tlabel not in labels:
Expand Down Expand Up @@ -491,7 +496,12 @@ def calcStationMetrics(self, eventid, stations=None, labels=None):
event = self.getEvent(eventid)
for stream in streams:
tag = stream.tag
_, label = tag.split('_')
parts = tag.split('_')
if len(parts) > 2:
label = parts[-1]
eventid = '_'.join(parts[0:-1])
else:
eventid, label = tag.split('_')
elat = event.latitude
elon = event.longitude
edepth = event.depth_km
Expand Down Expand Up @@ -564,7 +574,13 @@ def calcStreamMetrics(self, eventid, stations=None,
for stream in streams:
tag = stream.tag
instrument = stream.get_id()
eventid, label = tag.split('_')
logging.info('Calculating stream metrics for %s...' % instrument)
parts = tag.split('_')
if len(parts) > 2:
label = parts[-1]
eventid = '_'.join(parts[0:-1])
else:
eventid, label = tag.split('_')
if label not in labels:
continue
try:
Expand Down Expand Up @@ -805,7 +821,7 @@ def summarizeLabels(self):
cols = ['Label', 'UserID', 'UserName',
'UserEmail', 'Software', 'Version']
df = pd.DataFrame(columns=cols, index=None)
labels = list(set([ptag.split('_')[5] for ptag in provtags]))
labels = list(set([ptag.split('_')[-1] for ptag in provtags]))
labeldict = {}
for label in labels:
for ptag in provtags:
Expand Down
15 changes: 10 additions & 5 deletions gmprocess/streamcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ def validate(self):
all_labels = []
for stream in self:
if hasattr(stream, 'tag'):
eventid, label = stream.tag.split('_')
parts = stream.tag.split('_')
if len(parts) > 2:
label = parts[-1]
eventid = '_'.join(parts[0:-1])
else:
eventid, label = stream.tag.split('_')
all_labels.append(label)
else:
all_labels.append("")
Expand Down Expand Up @@ -729,10 +734,10 @@ def are_duplicates(tr1, tr2, max_dist_tolerance):
tr1.stats.coordinates.latitude, tr1.stats.coordinates.longitude,
tr2.stats.coordinates.latitude, tr2.stats.coordinates.longitude)[0]
if (tr1.stats.station == tr2.stats.station
and tr1.stats.location == tr2.stats.location
and tr1.stats.channel[:2] == tr2.stats.channel[:2]
and len(orientation_codes) == 1
and distance < max_dist_tolerance):
and tr1.stats.location == tr2.stats.location
and tr1.stats.channel[:2] == tr2.stats.channel[:2]
and len(orientation_codes) == 1
and distance < max_dist_tolerance):
return True
else:
return False
Expand Down

0 comments on commit 9b675e6

Please sign in to comment.