Move test_autopickstation to subdirectory in pylot/tests

This commit is contained in:
Darius Arnold 2018-07-13 09:45:57 +02:00
parent 2c92f6f2fd
commit c308415aa5
13 changed files with 49 additions and 8 deletions

View File

@ -0,0 +1,21 @@
<?xml version='1.0' encoding='utf-8'?>
<q:quakeml xmlns:q="http://quakeml.org/xmlns/quakeml/1.2" xmlns="http://quakeml.org/xmlns/bed/1.2">
<eventParameters publicID="smi:local/53a38563-739a-48b2-9f34-bf40ee7b656a">
<event publicID="smi:local/e0001.024.16">
<origin publicID="smi:local/e0001.024.16">
<time>
<value>2016-01-24T10:30:30.000000Z</value>
</time>
<latitude>
<value>59.66</value>
</latitude>
<longitude>
<value>-153.45</value>
</longitude>
<depth>
<value>128.0</value>
</depth>
</origin>
</event>
</eventParameters>
</q:quakeml>

View File

@ -0,0 +1 @@
/data/AlpArray/mini_SEED_LH/2016-01-24T10:30:30

View File

@ -1,4 +1,5 @@
import unittest
from unittest import skip
import obspy
from obspy import UTCDateTime
import os
@ -58,7 +59,7 @@ class TestAutopickStation(unittest.TestCase):
def setUp(self):
self.event_id = 'e0001.024.16'
# Create wfstream for picking
mseed_relative_path = os.path.join(self.event_id, '*.mseed')
mseed_relative_path = os.path.join(os.path.dirname(__file__), self.event_id, '*.mseed')
self.wfstream = obspy.read(mseed_relative_path)
# trim waveform to get the same results as the GUI call
with HidePrints():
@ -66,25 +67,27 @@ class TestAutopickStation(unittest.TestCase):
self.gra1 = self.wfstream.select(station='GRA1')
self.gra2 = self.wfstream.select(station='GRA2')
self.ech = self.wfstream.select(station='ECH')
self.fiesa = self.wfstream.select(station='FIESA')
# Create input parameter container
self.inputfile_taupy_enabled = 'autoPyLoT_global_taupy_true.in'
self.inputfile_taupy_disabled = 'autoPyLoT_global_taupy_false.in'
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')
self.pickparam_taupy_enabled = PylotParameter(fnin=self.inputfile_taupy_enabled)
self.pickparam_taupy_disabled = PylotParameter(fnin=self.inputfile_taupy_disabled)
self.current_directory = os.getcwd()
self.data = Data(evtdata=os.path.join(self.current_directory+'/'+self.event_id, 'PyLoT_'+self.event_id+'.xml'))
self.xml_file = os.path.join(os.path.dirname(__file__),self.event_id, 'PyLoT_'+self.event_id+'.xml')
self.data = Data(evtdata=self.xml_file)
# create origin for taupy testing
self.origin = [obspy.core.event.origin.Origin(magnitude=7.1, latitude=59.66, longitude=-153.45, depth=128.0, time=UTCDateTime("2016-01-24T10:30:30.0"))]
# mocking metadata since reading it takes a long time to read from file
self.metadata = ('dless', MockParser())
@staticmethod
def construct_error_message(station_id, taupy_status, expected, got):
error_message = """Difference in auto picks for station {station_id} with taupy {status}.\n
def construct_error_message(station_id, taupy_status, expected, got, phase=''):
error_message = """Difference in auto {phase} picks for station {station_id} with taupy {status}.\n
Expeceted: {exp}\n
Got: {got}\n""".format(station_id=station_id, status='enabled' if taupy_status else 'disabled', exp=expected, got=got)
Got: {got}\n""".format(station_id=station_id, status='enabled' if taupy_status else 'disabled', phase=phase, exp=expected, got=got)
return error_message
#@skip("Works")
def test_autopickstation_taupy_disabled_gra1(self):
expected = {'P': {'picker': 'auto', 'snrdb': 15.405649120980094, 'weight': 0, 'Mo': None, 'marked': [], 'Mw': None, 'fc': None, 'snr': 34.718816470730317, 'mpp': UTCDateTime(2016, 1, 24, 10, 41, 31, 690000), 'w0': None, 'spe': 0.93333333333333235, 'network': u'GR', 'epp': UTCDateTime(2016, 1, 24, 10, 41, 28, 890000), 'lpp': UTCDateTime(2016, 1, 24, 10, 41, 32, 690000), 'fm': 'D', 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': 10.669661906545489, 'network': u'GR', 'weight': 0, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 50, 30, 690000), 'snr': 11.667187857573905, 'epp': UTCDateTime(2016, 1, 24, 10, 50, 21, 690000), 'mpp': UTCDateTime(2016, 1, 24, 10, 50, 29, 690000), 'fm': None, 'spe': 2.6666666666666665, 'channel': u'LHE'}, 'station': u'GRA1'}
with HidePrints():
@ -94,6 +97,7 @@ class TestAutopickStation(unittest.TestCase):
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
#@skip("Works")
def test_autopickstation_taupy_enabled_gra1(self):
expected = {'P': {'picker': 'auto', 'snrdb': 15.599905299126778, 'weight': 0, 'Mo': None, 'marked': [], 'Mw': None, 'fc': None, 'snr': 36.307013769185403, 'mpp': UTCDateTime(2016, 1, 24, 10, 41, 27, 690000), 'w0': None, 'spe': 0.93333333333333235, 'network': u'GR', 'epp': UTCDateTime(2016, 1, 24, 10, 41, 24, 890000), 'lpp': UTCDateTime(2016, 1, 24, 10, 41, 28, 690000), 'fm': 'U', 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': 10.669661906545489, 'network': u'GR', 'weight': 0, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 50, 30, 690000), 'snr': 11.667187857573905, 'epp': UTCDateTime(2016, 1, 24, 10, 50, 21, 690000), 'mpp': UTCDateTime(2016, 1, 24, 10, 50, 29, 690000), 'fm': None, 'spe': 2.6666666666666665, 'channel': u'LHE'}, 'station': u'GRA1'}
with HidePrints():
@ -103,6 +107,7 @@ class TestAutopickStation(unittest.TestCase):
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
#@skip("works")
def test_autopickstation_taupy_disabled_gra2(self):
expected = {'P': {'picker': 'auto', 'snrdb': None, 'weight': 9, 'Mo': None, 'marked': 'shortsignallength', 'Mw': None, 'fc': None, 'snr': None, 'mpp': UTCDateTime(2016, 1, 24, 10, 36, 59, 150000), 'w0': None, 'spe': None, 'network': u'GR', 'epp': UTCDateTime(2016, 1, 24, 10, 36, 43, 150000), 'lpp': UTCDateTime(2016, 1, 24, 10, 37, 15, 150000), 'fm': 'N', 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': None, 'network': u'GR', 'weight': 4, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 37, 15, 150000), 'snr': None, 'epp': UTCDateTime(2016, 1, 24, 10, 36, 43, 150000), 'mpp': UTCDateTime(2016, 1, 24, 10, 36, 59, 150000), 'fm': None, 'spe': None, 'channel': u'LHE'}, 'station': u'GRA2'}
with HidePrints():
@ -112,6 +117,7 @@ class TestAutopickStation(unittest.TestCase):
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
#skip("")
def test_autopickstation_taupy_enabled_gra2(self):
expected = {'P': {'picker': 'auto', 'snrdb': 13.957959025719253, 'weight': 0, 'Mo': None, 'marked': [], 'Mw': None, 'fc': None, 'snr': 24.876879503607871, 'mpp': UTCDateTime(2016, 1, 24, 10, 41, 29, 150000), 'w0': None, 'spe': 1.0, 'network': u'GR', 'epp': UTCDateTime(2016, 1, 24, 10, 41, 26, 150000), 'lpp': UTCDateTime(2016, 1, 24, 10, 41, 30, 150000), 'fm': None, 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': 10.573236990555648, 'network': u'GR', 'weight': 1, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 50, 34, 150000), 'snr': 11.410999834108294, 'epp': UTCDateTime(2016, 1, 24, 10, 50, 21, 150000), 'mpp': UTCDateTime(2016, 1, 24, 10, 50, 33, 150000), 'fm': None, 'spe': 4.666666666666667, 'channel': u'LHE'}, 'station': u'GRA2'}
with HidePrints():
@ -121,6 +127,7 @@ class TestAutopickStation(unittest.TestCase):
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
#@skip("Works")
def test_autopickstation_taupy_disabled_ech(self):
expected = {'P': {'picker': 'auto', 'snrdb': None, 'weight': 9, 'Mo': None, 'marked': 'SinsteadP', 'Mw': None, 'fc': None, 'snr': None, 'mpp': UTCDateTime(2016, 1, 24, 10, 26, 57), 'w0': None, 'spe': None, 'network': u'G', 'epp': UTCDateTime(2016, 1, 24, 10, 26, 41), 'lpp': UTCDateTime(2016, 1, 24, 10, 27, 13), 'fm': 'N', 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': None, 'network': u'G', 'weight': 4, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 27, 13), 'snr': None, 'epp': UTCDateTime(2016, 1, 24, 10, 26, 41), 'mpp': UTCDateTime(2016, 1, 24, 10, 26, 57), 'fm': None, 'spe': None, 'channel': u'LHE'}, 'station': u'ECH'}
with HidePrints():
@ -130,6 +137,7 @@ class TestAutopickStation(unittest.TestCase):
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
#@skip("Works")
def test_autopickstation_taupy_enabled_ech(self):
# this station has a long time of before the first onset, so taupy will help during picking
expected = {'P': {'picker': 'auto', 'snrdb': 9.9753586609166316, 'weight': 0, 'Mo': None, 'marked': [], 'Mw': None, 'fc': None, 'snr': 9.9434218804137107, 'mpp': UTCDateTime(2016, 1, 24, 10, 41, 34), 'w0': None, 'spe': 1.6666666666666667, 'network': u'G', 'epp': UTCDateTime(2016, 1, 24, 10, 41, 29), 'lpp': UTCDateTime(2016, 1, 24, 10, 41, 35), 'fm': None, 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': 12.698999454169567, 'network': u'G', 'weight': 0, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 50, 44), 'snr': 18.616581906366577, 'epp': UTCDateTime(2016, 1, 24, 10, 50, 33), 'mpp': UTCDateTime(2016, 1, 24, 10, 50, 43), 'fm': None, 'spe': 3.3333333333333335, 'channel': u'LHE'}, 'station': u'ECH'}
@ -140,5 +148,16 @@ class TestAutopickStation(unittest.TestCase):
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
@skip("Results are just a copy of ech")
def test_autopickstation_taupy_disabled_fiesa(self):
# this station has a long time of before the first onset, so taupy will help during picking
expected = {'P': {'picker': 'auto', 'snrdb': 9.9753586609166316, 'weight': 0, 'Mo': None, 'marked': [], 'Mw': None, 'fc': None, 'snr': 9.9434218804137107, 'mpp': UTCDateTime(2016, 1, 24, 10, 41, 34), 'w0': None, 'spe': 1.6666666666666667, 'network': u'G', 'epp': UTCDateTime(2016, 1, 24, 10, 41, 29), 'lpp': UTCDateTime(2016, 1, 24, 10, 41, 35), 'fm': None, 'channel': u'LHZ'}, 'S': {'picker': 'auto', 'snrdb': 12.698999454169567, 'network': u'G', 'weight': 0, 'Ao': None, 'lpp': UTCDateTime(2016, 1, 24, 10, 50, 44), 'snr': 18.616581906366577, 'epp': UTCDateTime(2016, 1, 24, 10, 50, 33), 'mpp': UTCDateTime(2016, 1, 24, 10, 50, 43), 'fm': None, 'spe': 3.3333333333333335, 'channel': u'LHE'}, 'station': u'ECH'}
with HidePrints():
result = autopickstation(wfstream=self.fiesa, pickparam=self.pickparam_taupy_disabled)
error_message = self.construct_error_message('CH.FIESE', True, expected, result)
self.assertDictContainsSubset(expected=expected['P'], actual=result['P'])
self.assertDictContainsSubset(expected=expected['S'], actual=result['S'])
self.assertEqual(expected['station'], result['station'])
if __name__ == '__main__':
unittest.main()