[bugfix] Taupy didn't check return of get_coordinates

For a station not in the metadata, get_coordinates would return None which wasn't checked for.
This includes a test for a station which is not in metadata.
This commit is contained in:
Darius Arnold
2018-08-13 22:42:19 +02:00
parent 96adbddeba
commit 6936cfcfa6
2 changed files with 25 additions and 4 deletions

View File

@@ -49,7 +49,7 @@ class MockMetadata:
self.coordinates = [gra1, gra2, ech, fiesa, a106]
def get_coordinates(self, station_id):
def get_coordinates(self, station_id, time=None):
"""
Mocks the method get_coordinates from obspy.io.xseed.parser.Parser object
to avoid building a parser for the unit tests
@@ -87,6 +87,7 @@ class TestAutopickStation(unittest.TestCase):
self.ech = self.wfstream.select(station='ECH')
self.fiesa = self.wfstream.select(station='FIESA')
self.a106 = self.wfstream.select(station='A106A')
self.a005a = self.wfstream.select(station='A005A')
# Create input parameter container
self.inputfile_taupy_enabled = os.path.join(os.path.dirname(__file__), 'autoPyLoT_global_taupy_true.in')
self.inputfile_taupy_disabled = os.path.join(os.path.dirname(__file__), 'autoPyLoT_global_taupy_false.in')
@@ -196,5 +197,15 @@ class TestAutopickStation(unittest.TestCase):
result, station = autopickstation(wfstream=self.a106, pickparam=self.pickparam_taupy_enabled, metadata=self.metadata, origin=self.origin)
self.assertEqual(expected, result)
def test_autopickstation_station_missing_in_metadata(self):
"""This station is not in the metadata, but Taupy is enabled. Taupy should exit cleanly and modify the starttime
relative to the theoretical onset to one relative to the traces starttime, eg never negative.
"""
self.pickparam_taupy_enabled.setParamKV('pstart', -100) # modify starttime to be relative to theoretical onset
expected = {'P': {'picker': 'auto', 'snrdb': 14.464757855513506, 'network': u'Z3', 'weight': 0, 'Mo': None, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 41, 39, 605000), 'Mw': None, 'fc': None, 'snr': 27.956048519707181, 'marked': [], 'mpp': UTCDateTime(2016, 1, 24, 10, 41, 38, 605000), 'w0': None, 'spe': 1.6666666666666667, 'epp': UTCDateTime(2016, 1, 24, 10, 41, 35, 605000), 'fm': None, 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': 10.112844176301248, 'network': u'Z3', 'weight': 1, 'Mo': None, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 50, 51, 605000), 'Mw': None, 'fc': None, 'snr': 10.263238413785425, 'marked': [], 'mpp': UTCDateTime(2016, 1, 24, 10, 50, 48, 605000), 'w0': None, 'spe': 4.666666666666667, 'epp': UTCDateTime(2016, 1, 24, 10, 50, 40, 605000), 'fm': None, 'channel': u'LHE'}}
with HidePrints():
result, station = autopickstation(wfstream = self.a005a, pickparam=self.pickparam_taupy_enabled, metadata=self.metadata, origin=self.origin)
self.assertEqual(expected, result)
if __name__ == '__main__':
unittest.main()