From 455733ea19bf985d5d0abc28f8e866326882d258 Mon Sep 17 00:00:00 2001 From: Darius Arnold Date: Tue, 22 May 2018 19:21:29 +0200 Subject: [PATCH] [Add] Unittest for autopickstation function picking with and without taupy --- tests/autoPyLoT_global_taupy_false.in | 104 ++++++++++++++++++++ tests/autoPyLoT_global_taupy_true.in | 104 ++++++++++++++++++++ tests/test_autopickstation.py | 133 ++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 tests/autoPyLoT_global_taupy_false.in create mode 100644 tests/autoPyLoT_global_taupy_true.in create mode 100644 tests/test_autopickstation.py diff --git a/tests/autoPyLoT_global_taupy_false.in b/tests/autoPyLoT_global_taupy_false.in new file mode 100644 index 00000000..bcc7b7e4 --- /dev/null +++ b/tests/autoPyLoT_global_taupy_false.in @@ -0,0 +1,104 @@ +%This is a parameter input file for PyLoT/autoPyLoT. +%All main and special settings regarding data handling +%and picking are to be set here! +%Parameters are optimized for %extent data sets! +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#main settings# +/home/darius #rootpath# %project path +alparray #datapath# %data path +waveforms_used #database# %name of data base +e0093.173.16 #eventID# %event ID for single event processing (* for all events found in database) +/home/darius/alparray/metadata #invdir# %full path to inventory or dataless-seed file +PILOT #datastructure# %choose data structure +True #apverbose# %choose 'True' or 'False' for terminal output +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#NLLoc settings# +/progs/bin #nllocbin# %path to NLLoc executable +/home/darius/alparray/auto #nllocroot# %root of NLLoc-processing directory +AUTOPHASES.obs #phasefile# %name of autoPyLoT-output phase file for NLLoc +Insheim_min1d032016_auto.in #ctrfile# %name of autoPyLoT-output control file for NLLoc +ttime #ttpatter# %pattern of NLLoc ttimes from grid +AUTOLOC_nlloc #outpatter# %pattern of NLLoc-output file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#parameters for seismic moment estimation# +3530.0 #vp# %average P-wave velocity +2500.0 #rho# %average rock density [kg/m^3] +300.0 0.8 #Qp# %quality factor for P waves (Qp*f^a); list(Qp, a) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#settings local magnitude# +1.0 1.0 1.0 #WAscaling# %Scaling relation (log(Ao)+Alog(r)+Br+C) of Wood-Anderson amplitude Ao [nm] If zeros are set, original Richter magnitude is calculated! +1.0 1.0 #magscaling# %Scaling relation for derived local magnitude [a*Ml+b]. If zeros are set, no scaling of network magnitude is applied! +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#filter settings# +0.01 0.01 #minfreq# %Lower filter frequency [P, S] +0.5 0.5 #maxfreq# %Upper filter frequency [P, S] +3 3 #filter_order# %filter order [P, S] +bandpass bandpass #filter_type# %filter type (bandpass, bandstop, lowpass, highpass) [P, S] +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#common settings picker# +global #extent# %extent of array ("local", "regional" or "global") +-100.0 #pstart# %start time [s] for calculating CF for P-picking (if TauPy: seconds relative to estimated onset) +350.0 #pstop# %end time [s] for calculating CF for P-picking (if TauPy: seconds relative to estimated onset) +200.0 #sstart# %start time [s] relative to P-onset for calculating CF for S-picking +875.0 #sstop# %end time [s] after P-onset for calculating CF for S-picking +False #use_taup# %use estimated traveltimes from TauPy for calculating windows for CF +IASP91 #taup_model# %define TauPy model for traveltime estimation. Possible values: 1066a, 1066b, ak135, ak135f, herrin, iasp91, jb, prem, pwdk, sp6 +0.01 0.1 #bpz1# %lower/upper corner freq. of first band pass filter Z-comp. [Hz] +0.001 0.5 #bpz2# %lower/upper corner freq. of second band pass filter Z-comp. [Hz] +0.01 0.5 #bph1# %lower/upper corner freq. of first band pass filter H-comp. [Hz] +0.001 0.5 #bph2# %lower/upper corner freq. of second band pass filter z-comp. [Hz] +#special settings for calculating CF# +%!!Edit the following only if you know what you are doing!!% +#Z-component# +HOS #algoP# %choose algorithm for P-onset determination (HOS, ARZ, or AR3) +100.0 #tlta# %for HOS-/AR-AIC-picker, length of LTA window [s] +4 #hosorder# %for HOS-picker, order of Higher Order Statistics +2 #Parorder# %for AR-picker, order of AR process of Z-component +24.0 #tdet1z# %for AR-picker, length of AR determination window [s] for Z-component, 1st pick +20.0 #tpred1z# %for AR-picker, length of AR prediction window [s] for Z-component, 1st pick +16.0 #tdet2z# %for AR-picker, length of AR determination window [s] for Z-component, 2nd pick +8.0 #tpred2z# %for AR-picker, length of AR prediction window [s] for Z-component, 2nd pick +0.5 #addnoise# %add noise to seismogram for stable AR prediction +30.0 5.0 20.0 10.0 #tsnrz# %for HOS/AR, window lengths for SNR-and slope estimation [tnoise, tsafetey, tsignal, tslope] [s] +55.0 #pickwinP# %for initial AIC pick, length of P-pick window [s] +20.0 #Precalcwin# %for HOS/AR, window length [s] for recalculation of CF (relative to 1st pick) +6.0 #aictsmooth# %for HOS/AR, take average of samples for smoothing of AIC-function [s] +4.0 #tsmoothP# %for HOS/AR, take average of samples for smoothing CF [s] +0.5 #ausP# %for HOS/AR, artificial uplift of samples (aus) of CF (P) +1.1 #nfacP# %for HOS/AR, noise factor for noise level determination (P) +50.0 #checkwindowP# %time window before HOS/AR-maximum to check for smaller maxima [s] +0.7 #minfactorP# %Second maximum must be at least minfactor * first maximum [-] +#H-components# +ARH #algoS# %choose algorithm for S-onset determination (ARH or AR3) +30.0 #tdet1h# %for HOS/AR, length of AR-determination window [s], H-components, 1st pick +18.0 #tpred1h# %for HOS/AR, length of AR-prediction window [s], H-components, 1st pick +16.0 #tdet2h# %for HOS/AR, length of AR-determinaton window [s], H-components, 2nd pick +8.0 #tpred2h# %for HOS/AR, length of AR-prediction window [s], H-components, 2nd pick +4 #Sarorder# %for AR-picker, order of AR process of H-components +30.0 #Srecalcwin# %for AR-picker, window length [s] for recalculation of CF (2nd pick) (H) +195.0 #pickwinS# %for initial AIC pick, length of S-pick window [s] +30.0 10.0 15.0 10.0 #tsnrh# %for ARH/AR3, window lengths for SNR-and slope estimation [tnoise, tsafetey, tsignal, tslope] [s] +22.0 #aictsmoothS# %for AIC-picker, take average of samples for smoothing of AIC-function [s] +10.0 #tsmoothS# %for AR-picker, take average of samples for smoothing CF [s] (S) +0.001 #ausS# %for HOS/AR, artificial uplift of samples (aus) of CF (S) +1.2 #nfacS# %for AR-picker, noise factor for noise level determination (S) +250.0 #checkwindowS# %time window before AR-maximum to check for smaller maxima [s] +0.4 #minfactorS# %Second maximum must be at least minfactor * first maximum [-] +#first-motion picker# +1 #minfmweight# %minimum required P weight for first-motion determination +3.0 #minFMSNR# %miniumum required SNR for first-motion determination +10.0 #fmpickwin# %pick window around P onset for calculating zero crossings +#quality assessment# +4.0 8.0 12.0 16.0 #timeerrorsP# %discrete time errors [s] corresponding to picking weights [0 1 2 3] for P +4.0 8.0 12.0 16.0 #timeerrorsS# %discrete time errors [s] corresponding to picking weights [0 1 2 3] for S +1.0 #minAICPslope# %below this slope [counts/s] the initial P pick is rejected +1.1 #minAICPSNR# %below this SNR the initial P pick is rejected +1.0 #minAICSslope# %below this slope [counts/s] the initial S pick is rejected +1.1 #minAICSSNR# %below this SNR the initial S pick is rejected +12.0 #minsiglength# %length of signal part for which amplitudes must exceed noiselevel [s] +1.1 #noisefactor# %noiselevel*noisefactor=threshold +20.0 #minpercent# %required percentage of amplitudes exceeding threshold +1.25 #zfac# %P-amplitude must exceed at least zfac times RMS-S amplitude +60.0 #mdttolerance# %maximum allowed deviation of P picks from median [s] +60.0 #wdttolerance# %maximum allowed deviation from Wadati-diagram +5.0 #jackfactor# %pick is removed if the variance of the subgroup with the pick removed is larger than the mean variance of all subgroups times safety factor diff --git a/tests/autoPyLoT_global_taupy_true.in b/tests/autoPyLoT_global_taupy_true.in new file mode 100644 index 00000000..dc71193c --- /dev/null +++ b/tests/autoPyLoT_global_taupy_true.in @@ -0,0 +1,104 @@ +%This is a parameter input file for PyLoT/autoPyLoT. +%All main and special settings regarding data handling +%and picking are to be set here! +%Parameters are optimized for %extent data sets! +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#main settings# +/home/darius #rootpath# %project path +alparray #datapath# %data path +waveforms_used #database# %name of data base +e0093.173.16 #eventID# %event ID for single event processing (* for all events found in database) +/home/darius/alparray/metadata #invdir# %full path to inventory or dataless-seed file +PILOT #datastructure# %choose data structure +True #apverbose# %choose 'True' or 'False' for terminal output +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#NLLoc settings# +/progs/bin #nllocbin# %path to NLLoc executable +/home/darius/alparray/auto #nllocroot# %root of NLLoc-processing directory +AUTOPHASES.obs #phasefile# %name of autoPyLoT-output phase file for NLLoc +Insheim_min1d032016_auto.in #ctrfile# %name of autoPyLoT-output control file for NLLoc +ttime #ttpatter# %pattern of NLLoc ttimes from grid +AUTOLOC_nlloc #outpatter# %pattern of NLLoc-output file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#parameters for seismic moment estimation# +3530.0 #vp# %average P-wave velocity +2500.0 #rho# %average rock density [kg/m^3] +300.0 0.8 #Qp# %quality factor for P waves (Qp*f^a); list(Qp, a) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#settings local magnitude# +1.0 1.0 1.0 #WAscaling# %Scaling relation (log(Ao)+Alog(r)+Br+C) of Wood-Anderson amplitude Ao [nm] If zeros are set, original Richter magnitude is calculated! +1.0 1.0 #magscaling# %Scaling relation for derived local magnitude [a*Ml+b]. If zeros are set, no scaling of network magnitude is applied! +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#filter settings# +0.01 0.01 #minfreq# %Lower filter frequency [P, S] +0.5 0.5 #maxfreq# %Upper filter frequency [P, S] +3 3 #filter_order# %filter order [P, S] +bandpass bandpass #filter_type# %filter type (bandpass, bandstop, lowpass, highpass) [P, S] +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#common settings picker# +global #extent# %extent of array ("local", "regional" or "global") +-100.0 #pstart# %start time [s] for calculating CF for P-picking (if TauPy: seconds relative to estimated onset) +350.0 #pstop# %end time [s] for calculating CF for P-picking (if TauPy: seconds relative to estimated onset) +200.0 #sstart# %start time [s] relative to P-onset for calculating CF for S-picking +875.0 #sstop# %end time [s] after P-onset for calculating CF for S-picking +True #use_taup# %use estimated traveltimes from TauPy for calculating windows for CF +IASP91 #taup_model# %define TauPy model for traveltime estimation. Possible values: 1066a, 1066b, ak135, ak135f, herrin, iasp91, jb, prem, pwdk, sp6 +0.01 0.1 #bpz1# %lower/upper corner freq. of first band pass filter Z-comp. [Hz] +0.001 0.5 #bpz2# %lower/upper corner freq. of second band pass filter Z-comp. [Hz] +0.01 0.5 #bph1# %lower/upper corner freq. of first band pass filter H-comp. [Hz] +0.001 0.5 #bph2# %lower/upper corner freq. of second band pass filter z-comp. [Hz] +#special settings for calculating CF# +%!!Edit the following only if you know what you are doing!!% +#Z-component# +HOS #algoP# %choose algorithm for P-onset determination (HOS, ARZ, or AR3) +100.0 #tlta# %for HOS-/AR-AIC-picker, length of LTA window [s] +4 #hosorder# %for HOS-picker, order of Higher Order Statistics +2 #Parorder# %for AR-picker, order of AR process of Z-component +24.0 #tdet1z# %for AR-picker, length of AR determination window [s] for Z-component, 1st pick +20.0 #tpred1z# %for AR-picker, length of AR prediction window [s] for Z-component, 1st pick +16.0 #tdet2z# %for AR-picker, length of AR determination window [s] for Z-component, 2nd pick +8.0 #tpred2z# %for AR-picker, length of AR prediction window [s] for Z-component, 2nd pick +0.5 #addnoise# %add noise to seismogram for stable AR prediction +30.0 5.0 20.0 10.0 #tsnrz# %for HOS/AR, window lengths for SNR-and slope estimation [tnoise, tsafetey, tsignal, tslope] [s] +55.0 #pickwinP# %for initial AIC pick, length of P-pick window [s] +20.0 #Precalcwin# %for HOS/AR, window length [s] for recalculation of CF (relative to 1st pick) +6.0 #aictsmooth# %for HOS/AR, take average of samples for smoothing of AIC-function [s] +4.0 #tsmoothP# %for HOS/AR, take average of samples for smoothing CF [s] +0.5 #ausP# %for HOS/AR, artificial uplift of samples (aus) of CF (P) +1.1 #nfacP# %for HOS/AR, noise factor for noise level determination (P) +50.0 #checkwindowP# %time window before HOS/AR-maximum to check for smaller maxima [s] +0.7 #minfactorP# %Second maximum must be at least minfactor * first maximum [-] +#H-components# +ARH #algoS# %choose algorithm for S-onset determination (ARH or AR3) +30.0 #tdet1h# %for HOS/AR, length of AR-determination window [s], H-components, 1st pick +18.0 #tpred1h# %for HOS/AR, length of AR-prediction window [s], H-components, 1st pick +16.0 #tdet2h# %for HOS/AR, length of AR-determinaton window [s], H-components, 2nd pick +8.0 #tpred2h# %for HOS/AR, length of AR-prediction window [s], H-components, 2nd pick +4 #Sarorder# %for AR-picker, order of AR process of H-components +30.0 #Srecalcwin# %for AR-picker, window length [s] for recalculation of CF (2nd pick) (H) +195.0 #pickwinS# %for initial AIC pick, length of S-pick window [s] +30.0 10.0 15.0 10.0 #tsnrh# %for ARH/AR3, window lengths for SNR-and slope estimation [tnoise, tsafetey, tsignal, tslope] [s] +22.0 #aictsmoothS# %for AIC-picker, take average of samples for smoothing of AIC-function [s] +10.0 #tsmoothS# %for AR-picker, take average of samples for smoothing CF [s] (S) +0.001 #ausS# %for HOS/AR, artificial uplift of samples (aus) of CF (S) +1.2 #nfacS# %for AR-picker, noise factor for noise level determination (S) +250.0 #checkwindowS# %time window before AR-maximum to check for smaller maxima [s] +0.4 #minfactorS# %Second maximum must be at least minfactor * first maximum [-] +#first-motion picker# +1 #minfmweight# %minimum required P weight for first-motion determination +3.0 #minFMSNR# %miniumum required SNR for first-motion determination +10.0 #fmpickwin# %pick window around P onset for calculating zero crossings +#quality assessment# +4.0 8.0 12.0 16.0 #timeerrorsP# %discrete time errors [s] corresponding to picking weights [0 1 2 3] for P +4.0 8.0 12.0 16.0 #timeerrorsS# %discrete time errors [s] corresponding to picking weights [0 1 2 3] for S +1.0 #minAICPslope# %below this slope [counts/s] the initial P pick is rejected +1.1 #minAICPSNR# %below this SNR the initial P pick is rejected +1.0 #minAICSslope# %below this slope [counts/s] the initial S pick is rejected +1.1 #minAICSSNR# %below this SNR the initial S pick is rejected +12.0 #minsiglength# %length of signal part for which amplitudes must exceed noiselevel [s] +1.1 #noisefactor# %noiselevel*noisefactor=threshold +20.0 #minpercent# %required percentage of amplitudes exceeding threshold +1.25 #zfac# %P-amplitude must exceed at least zfac times RMS-S amplitude +60.0 #mdttolerance# %maximum allowed deviation of P picks from median [s] +60.0 #wdttolerance# %maximum allowed deviation from Wadati-diagram +5.0 #jackfactor# %pick is removed if the variance of the subgroup with the pick removed is larger than the mean variance of all subgroups times safety factor diff --git a/tests/test_autopickstation.py b/tests/test_autopickstation.py new file mode 100644 index 00000000..170c9959 --- /dev/null +++ b/tests/test_autopickstation.py @@ -0,0 +1,133 @@ +import unittest +import obspy +from obspy import UTCDateTime +import os +import sys +from pylot.core.pick.autopick import autopickstation +from pylot.core.io.inputs import PylotParameter +from pylot.core.io.data import Data +from pylot.core.util.utils import trim_station_components + + +class HidePrints: + """ + Used to hide all standard output the Function to be tested have, since it clutters the test results. + """ + def __enter__(self): + self._original_stdout = sys.stdout + devnull = open(os.devnull, "w") + sys.stdout = devnull + + def __exit__(self, exc_type, exc_val, exc_tb): + sys.stdout = self._original_stdout + + +class MockParser: + + @staticmethod + def get_coordinates(station_id): + """ + Mocks the method get_coordinates from obspy.io.xseed.parser.Parser object + to avoid building a parser for the unit tests + :param station_id: 'GR.GRA1..LHZ' or similar + :type station_id: str + :return: dictionary containing azimuth, dip, elevation, latitude, longitude, + local depth as keys + :rtype: dict + + >>>MockParser.get_coordinates('GR.GRA2') + {u'azimuth': 0.0, u'dip': -90.0, u'elevation': 512.0, u'latitude': 49.655208, u'local_depth': 0.0, u'longitude': 11.359444} + """ + station_names = ['GR.GRA1', 'GR.GRA2', 'G.ECH'] + gra1 = {u'azimuth': 0.0, u'dip': -90.0, u'elevation': 499.5, u'latitude': 49.691888, u'local_depth': 0.0, u'longitude': 11.22172} + gra2 = {u'azimuth': 0.0, u'dip': -90.0, u'elevation': 512.0, u'latitude': 49.655208, u'local_depth': 0.0, u'longitude': 11.359444} + ech = {u'azimuth': 90.0, u'dip': 0.0, u'elevation': 580.0, u'latitude': 48.216313, u'local_depth': 250.0, u'longitude': 7.158961} + coordinates = [gra1, gra2, ech] + + for index, name in enumerate(station_names): + if station_id.startswith(name): + return coordinates[index] + + +class TestAutopickStation(unittest.TestCase): + """ + Test the autopickstation function as if it were called from GUI. + Three stations (GR.GRA1, GR.GRA2, G.ECH) are tested with and without TauPy respectively + """ + + def setUp(self): + self.event_id = 'e0001.024.16' + # Create wfstream for picking + mseed_relative_path = os.path.join(self.event_id, '*.mseed') + self.wfstream = obspy.read(mseed_relative_path) + # trim waveform to get the same results as the GUI call + with HidePrints(): + self.wfstream = trim_station_components(self.wfstream, trim_start=True, trim_end=False) + self.gra1 = self.wfstream.select(station='GRA1') + self.gra2 = self.wfstream.select(station='GRA2') + self.ech = self.wfstream.select(station='ECH') + # Create input parameter container + self.inputfile_taupy_enabled = 'autoPyLoT_global_taupy_true.in' + self.inputfile_taupy_disabled = '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')) + # 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 + Expeceted: {exp}\n + Got: {got}\n""".format(station_id=station_id, status='enabled' if taupy_status else 'disabled', exp=expected, got=got) + return error_message + + 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(): + result = autopickstation(wfstream=self.gra1, pickparam=self.pickparam_taupy_disabled, metadata=(None, None)) + error_message = self.construct_error_message('GR.GRA1', False, expected, result) + self.assertEqual(expected, result, msg=error_message) + + def test_autopickstation_taupy_enabled_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(): + result = autopickstation(wfstream=self.gra1, pickparam=self.pickparam_taupy_enabled, metadata=self.metadata, origin=self.origin) + error_message = self.construct_error_message('GR.GRA1', True, expected, result) + self.assertEqual(expected, result, msg=error_message) + + 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(): + result = autopickstation(wfstream=self.gra2, pickparam=self.pickparam_taupy_disabled, metadata=(None, None)) + error_message = self.construct_error_message('GR.GRA2', False, expected, result) + self.assertEqual(expected, result, msg=error_message) + + 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(): + result = autopickstation(wfstream=self.gra2, pickparam=self.pickparam_taupy_enabled, metadata=self.metadata, origin = self.origin) + error_message = self.construct_error_message('GR.GRA2', True, expected, result) + self.assertEqual(expected, result, msg=error_message) + + 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(): + result = autopickstation(wfstream=self.ech, pickparam=self.pickparam_taupy_disabled) + error_message = self.construct_error_message('G.ECH', False, expected, result) + self.assertEqual(expected, result, msg=error_message) + + 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'} + with HidePrints(): + result = autopickstation(wfstream=self.ech, pickparam=self.pickparam_taupy_enabled, metadata=self.metadata, origin=self.origin) + error_message = self.construct_error_message('G.ECH', True, expected, result) + self.assertEqual(expected, result, msg=error_message) + + +if __name__ == '__main__': + unittest.main()