From 7846e1303a242ee551e44aef73178f56cd7cb198 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 11 Aug 2017 10:24:25 +0200 Subject: [PATCH 1/5] [bugfix] in tuneautopicker --- pylot/core/util/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 67f80d6f..c77c7d18 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -2248,7 +2248,7 @@ class TuneAutopicker(QWidget): else: self.disable_autopickTabs() try: - main_fig.tight_layout() + self.fig_dict['main_fig'].tight_layout() except: pass self.figure_tabs.setCurrentIndex(0) From fe2a2a9714f02d5be81e7b388a278438939f0ab6 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 11 Aug 2017 10:28:35 +0200 Subject: [PATCH 2/5] [add] trim_station_comp also for tuneAutopicker --- pylot/core/util/widgets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index c77c7d18..e5ce7950 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -21,7 +21,7 @@ except: pg = None from matplotlib.figure import Figure -from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase +from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase, trim_station_components try: from matplotlib.backends.backend_qt4agg import FigureCanvas @@ -2058,6 +2058,9 @@ class TuneAutopicker(QWidget): def fill_stationbox(self): fnames = self.parent.getWFFnames_from_eventbox(eventbox=self.eventBox) self.data.setWFData(fnames) + wfdat = self.data.getWFData() # all available streams + # trim station components to same start value + trim_station_components(wfdat, trim_start=True, trim_end=False) self.stationBox.clear() stations = [] for trace in self.data.getWFData(): From e6aa1ad031a133f936b56903afdfcc3cc5c79198 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 11 Aug 2017 14:50:12 +0200 Subject: [PATCH 3/5] [add] continue if no station coords [bugfix] return if no isignal window --- pylot/core/pick/autopick.py | 22 +++++++++++++++------- pylot/core/pick/picker.py | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 17209378..1c06bd7c 100644 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -24,7 +24,7 @@ from pylot.core.util.utils import getPatternLine, gen_Pool, identifyPhase, loopI from obspy.taup import TauPyModel -def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None, origin=None): +def autopickevent(data, param, iplot=0, fig_dict=None, ncores=1, metadata=None, origin=None): stations = [] all_onsets = {} input_tuples = [] @@ -87,6 +87,15 @@ def call_autopickstation(input_tuple): return autopickstation(wfstream, pickparam, verbose, iplot=0, metadata=metadata, origin=origin) +def get_source_coords(parser, station_id): + station_coords = None + try: + station_coords = parser.get_coordinates(station_id) + except Exception as e: + print('Could not get source coordinates for station {}: {}'.format(station_id, e)) + return station_coords + + def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None, metadata=None, origin=None): """ @@ -224,11 +233,11 @@ def autopickstation(wfstream, pickparam, verbose=False, if not metadata[1]: print('Warning: Could not use TauPy to estimate onsets as there are no metadata given.') else: - if origin: + station_id = wfstream[0].get_id() + parser = metadata[1] + station_coords = get_source_coords(parser, station_id) + if station_coords and origin: source_origin = origin[0] - station_id = wfstream[0].get_id() - parser = metadata[1] - station_coords = parser.get_coordinates(station_id) model = TauPyModel(taup_model) arrivals = model.get_travel_times_geo( source_origin.depth, @@ -254,9 +263,8 @@ def autopickstation(wfstream, pickparam, verbose=False, Lc = pstop - pstart print('autopick: CF calculation times respectively:' ' pstart: {} s, pstop: {} s'.format(pstart, pstop)) - else: + elif not origin: print('No source origins given!') - else: Lc = pstop - pstart Lwf = zdat[0].stats.endtime - zdat[0].stats.starttime diff --git a/pylot/core/pick/picker.py b/pylot/core/pick/picker.py index 84a7107a..67b114ce 100644 --- a/pylot/core/pick/picker.py +++ b/pylot/core/pick/picker.py @@ -219,11 +219,13 @@ class AICPicker(AutoPicker): # check, if these are counts or m/s, important for slope estimation! # this is quick and dirty, better solution? if max(self.Data[0].data < 1e-3) and max(self.Data[0].data >= 1e-6): - self.Data[0].data = self.Data[0].data * 1000000 + self.Data[0].data = self.Data[0].data * 1000000. elif max(self.Data[0].data < 1e-6): self.Data[0].data = self.Data[0].data * 1e13 # get signal window isignal = getsignalwin(self.Tcf, self.Pick, self.TSNR[2]) + if len(isignal) == 0: + return ii = min([isignal[len(isignal) - 1], len(self.Tcf)]) isignal = isignal[0:ii] try: From 039f98a811cedad061478677a2966babeb1a75e1 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 11 Aug 2017 15:01:32 +0200 Subject: [PATCH 4/5] [add] check for nsamples and negative slope of cf --- pylot/core/pick/autopick.py | 2 +- pylot/core/pick/picker.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 1c06bd7c..25a781b2 100644 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -24,7 +24,7 @@ from pylot.core.util.utils import getPatternLine, gen_Pool, identifyPhase, loopI from obspy.taup import TauPyModel -def autopickevent(data, param, iplot=0, fig_dict=None, ncores=1, metadata=None, origin=None): +def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None, origin=None): stations = [] all_onsets = {} input_tuples = [] diff --git a/pylot/core/pick/picker.py b/pylot/core/pick/picker.py index 67b114ce..f89d0036 100644 --- a/pylot/core/pick/picker.py +++ b/pylot/core/pick/picker.py @@ -397,8 +397,14 @@ class PragPicker(AutoPicker): # prominent trend: decrease aus # flat: use given aus cfdiff = np.diff(cfipick) + if len(cfdiff)<20: + print('PragPicker: Very few samples for CF. Check LTA window dimensions!') i0diff = np.where(cfdiff > 0) cfdiff = cfdiff[i0diff] + if len(cfdiff)<1: + print('PragPicker: Negative slope for CF. Check LTA window dimensions! STOP') + self.Pick = None + return minaus = min(cfdiff * (1 + self.aus)) aus1 = max([minaus, self.aus]) From 255453475907c24a3a0c3edaf487e1fcfc672d78 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 11 Aug 2017 16:07:23 +0200 Subject: [PATCH 5/5] [bugfix] a lot of different bugfixes --- pylot/core/pick/autopick.py | 20 ++++++++++++-------- pylot/core/pick/picker.py | 6 +++++- pylot/core/pick/utils.py | 4 ++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 25a781b2..bdf76c5b 100644 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -68,9 +68,10 @@ def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None, pool.close() for pick in result: - station = pick['station'] - pick.pop('station') - all_onsets[station] = pick + if pick: + station = pick['station'] + pick.pop('station') + all_onsets[station] = pick return all_onsets @@ -206,13 +207,14 @@ def autopickstation(wfstream, pickparam, verbose=False, if len(ndat) == 0: # check for other components ndat = wfstream.select(component="1") - - wfstart, wfend = full_range(wfstream) + if not zdat: + print('No z-component found for station {}. STOP'.format(wfstream[0].stats.station)) + return if algoP == 'HOS' or algoP == 'ARZ' and zdat is not None: msg = '##################################################\nautopickstation:' \ ' Working on P onset of station {station}\nFiltering vertical ' \ - 'trace ...\n{data}'.format(station=zdat[0].stats.station, + 'trace ...\n{data}'.format(station=wfstream[0].stats.station, data=str(zdat)) if verbose: print(msg) z_copy = zdat.copy() @@ -972,14 +974,16 @@ def autopickstation(wfstream, pickparam, verbose=False, else: # dummy values (start of seismic trace) in order to derive # theoretical onset times for iteratve picking - try: + if edat: lpickS = edat[0].stats.starttime + timeerrorsS[3] epickS = edat[0].stats.starttime - timeerrorsS[3] mpickS = edat[0].stats.starttime - except: + elif ndat: lpickS = ndat[0].stats.starttime + timeerrorsS[3] epickS = ndat[0].stats.starttime - timeerrorsS[3] mpickS = ndat[0].stats.starttime + else: + return # create dictionary # for P phase diff --git a/pylot/core/pick/picker.py b/pylot/core/pick/picker.py index f89d0036..4a7c0dc9 100644 --- a/pylot/core/pick/picker.py +++ b/pylot/core/pick/picker.py @@ -244,7 +244,11 @@ class AICPicker(AutoPicker): & (self.Tcf >= self.Pick)) # find maximum within slope determination window # 'cause slope should be calculated up to first local minimum only! - imax = np.argmax(self.Data[0].data[islope[0][0]:islope[0][len(islope[0])-1]]) + dataslope = self.Data[0].data[islope[0][0]:islope[0][len(islope[0]) - 1]] + if len(dataslope) < 1: + print('No data in slope window found!') + return + imax = np.argmax(dataslope) iislope = islope[0][0:imax+1] if len(iislope) <= 2: # calculate slope from initial onset to maximum of AIC function diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 41a5509a..6a73849b 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -228,6 +228,10 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None): if len(zc1) == 3: break + if len(zc1) < 3: + print('fmpicker: Could not determine zero crossings!') + return + # if time difference betweeen 1st and 2cnd zero crossing # is too short, get time difference between 1st and 3rd # to derive maximum