Skip to content

Commit 2eb7b6a

Browse files
Merge pull request #213 from mhearne-usgs/usmagfix
Fixed authoritative info to show nan for magnitude when it is obtaine…
2 parents e7152ff + ff9f4fb commit 2eb7b6a

6 files changed

Lines changed: 41 additions & 42 deletions

File tree

libcomcat/classes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,11 @@ def toDict(self, catalog=None,
648648
phase_url = phase_data.getContentURL('quakeml.xml')
649649
catalog = read_events(phase_url)
650650
event = catalog.events[0]
651-
imag = 1
652-
for magnitude in event.magnitudes:
651+
for imag, magnitude in enumerate(event.magnitudes):
653652
edict['magnitude%i' % imag] = magnitude.mag
654653
edict['magtype%i' %
655654
imag] = magnitude.magnitude_type
656-
imag += 1
655+
edict['magsource%i' % imag] = magnitude.creation_info.agency_id
657656

658657
return edict
659658

libcomcat/search.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,12 @@ def get_authoritative_info(eventid):
610610
origins = detail.getProducts('origin', source='all')
611611
for origin in origins:
612612
source = origin.source
613-
magtype = origin['magnitude-type']
614-
magval = float(origin['magnitude'])
613+
if origin['magnitude-source'].lower() != source.lower():
614+
magval = np.nan
615+
magtype = 'NA'
616+
else:
617+
magval = float(origin['magnitude'])
618+
magtype = origin['magnitude-type']
615619
colname = '%s-%s' % (source, magtype)
616620
mag_row[colname] = magval
617621
latname = '%s-%s' % (origin.source, 'latitude')

notebooks/ComparingMagnitudes.ipynb

Lines changed: 30 additions & 34 deletions
Large diffs are not rendered by default.

notebooks/data/events.xlsx

1.22 KB
Binary file not shown.

tests/bin/getmags_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_mag():
5555
shutil.rmtree(tmpdir)
5656
# The largest recorded earthquake is a relatively stable check
5757
target_columns = ['id', 'time', 'lat', 'lon', 'depth', 'location',
58-
'url', 'hypo_src', 'official-mw', 'us-mw']
58+
'url', 'hypo_src', 'official-mw', 'us-NA']
5959
np.testing.assert_array_equal(df.columns, target_columns)
6060
target_id = 'official19600522191120_30'
6161
target_location = '1960 Great Chilean Earthquake (Valdivia Earthquake)'
@@ -78,7 +78,7 @@ def test_mag():
7878
shutil.rmtree(tmpdir)
7979
# The largest recorded earthquake is a relatively stable check
8080
target_columns = ['id', 'time', 'lat', 'lon', 'depth', 'location',
81-
'url', 'hypo_src', 'official-mw', 'us-mw']
81+
'url', 'hypo_src', 'official-mw', 'us-NA']
8282
np.testing.assert_array_equal(df.columns, target_columns)
8383
target_id = 'official19600522191120_30'
8484
target_location = '1960 Great Chilean Earthquake (Valdivia Earthquake)'

tests/libcomcat/classes_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_detail():
200200
assert atdict['depth'] == 9.0
201201

202202
ncdict_allmags = event.toDict(get_all_magnitudes=True)
203-
assert ncdict_allmags['magtype3'] == 'Ml'
203+
assert ncdict_allmags['magtype1'] == 'Md'
204204

205205
ncdict_alltensors = event.toDict(get_tensors='all')
206206
assert ncdict_alltensors['us_Mwb_mrr'] == 7.63e+16

0 commit comments

Comments
 (0)