diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 17209378..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 @@ -87,6 +88,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): """ @@ -197,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() @@ -224,11 +235,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 +265,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 @@ -964,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 84a7107a..4a7c0dc9 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: @@ -242,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 @@ -395,8 +401,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]) diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 212928d0..1f73b22f 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 diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 67f80d6f..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(): @@ -2248,7 +2251,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)