From a82c1d39c6a54f1f72edba04c59371d655c361f6 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Tue, 3 May 2016 09:35:31 +0200 Subject: [PATCH 01/13] [fix] fixing obvious problems in advance --- pylot/core/io/data.py | 17 ++++++++--------- pylot/core/io/phases.py | 12 +++++++----- pylot/core/pick/utils.py | 4 ---- scripts/pylot-reasses-pilot-event.py | 1 - 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index faa07cb8..01c36d4f 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -411,19 +411,18 @@ class Data(object): :raise OverwriteError: raises an OverwriteError if the picks list is not empty. The GUI will then ask for a decision. """ - firstonset = None + + #firstonset = find_firstonset(picks) if self.getEvtData().picks: raise OverwriteError('Actual picks would be overwritten!') - picks, firstonset = picks_from_dict(picks) + picks = picks_from_dict(picks) self.getEvtData().picks = picks + # if 'smi:local' in self.getID() and firstonset: + # fonset_str = firstonset.strftime('%Y_%m_%d_%H_%M_%S') + # ID = ResourceIdentifier('event/' + fonset_str) + # ID.convertIDToQuakeMLURI(authority_id=authority_id) + # self.getEvtData().resource_id = ID - if 'smi:local' in self.getID() and firstonset: - fonset_str = firstonset.strftime('%Y_%m_%d_%H_%M_%S') - ID = ResourceIdentifier('event/' + fonset_str) - ID.convertIDToQuakeMLURI(authority_id=authority_id) - self.getEvtData().resource_id = ID - else: - print('No picks to apply!') def applyArrivals(arrivals): """ diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index f3c6c96a..50d4f228 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -230,7 +230,7 @@ def picks_to_dict(evt): return picks def picks_from_dict(picks): - firstonset = None + picks_list = list() for station, onsets in picks.items(): print('Reading picks on station %s' % station) for label, phase in onsets.items(): @@ -262,9 +262,9 @@ def picks_from_dict(picks): else: pick.polarity = 'undecidable' except KeyError as e: - print('No polarity information found for %s' % phase) - if firstonset is None or firstonset > onset: - firstonset = onset + print(e.message, 'No polarity information found for %s' % phase) + picks_list.append(pick) + return picks_list def reassess_pilot_event(root_dir, event_id): @@ -303,7 +303,9 @@ def reassess_pilot_event(root_dir, event_id): evt = ope.Event(resource_id=event_id) evt.picks = picks_from_dict(picks_dict) # write phase information to file - evt.write('{0}.xml'.format(event_id), format='QUAKEML') + fnout_prefix = os.path.join(root_dir, event_id, '{0}.'.format(event_id)) + evt.write(fnout_prefix + 'xml', format='QUAKEML') + evt.write(fnout_prefix + 'cnv', format='VELEST') def writephases(arrivals, fformat, filename): diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index b8cf358d..6e7fe2f5 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -938,10 +938,6 @@ def checkZ4S(X, pick, zfac, checkwin, iplot): return returnflag -def reassess_pilot_event(): - pass - - if __name__ == '__main__': import doctest diff --git a/scripts/pylot-reasses-pilot-event.py b/scripts/pylot-reasses-pilot-event.py index 074f5218..f48a08f2 100644 --- a/scripts/pylot-reasses-pilot-event.py +++ b/scripts/pylot-reasses-pilot-event.py @@ -3,7 +3,6 @@ import argparse -from pylot.core.pick.utils import reassess_pilot_event from pylot.core.util.version import get_git_version as _getVersionString from pylot.core.io.phases import reassess_pilot_event From 41991c5d81929736cef32c92779335d906d628bb Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Tue, 3 May 2016 13:54:59 +0200 Subject: [PATCH 02/13] [edit] further restructuring and bugfixing --- QtPyLoT.py | 4 ++-- pylot/core/io/data.py | 4 ++-- pylot/core/io/phases.py | 26 +++++++++++++++----------- pylot/core/pick/compare.py | 4 ++-- pylot/core/pick/utils.py | 31 +++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 11aa6719..6daaffa6 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -43,7 +43,7 @@ from obspy import UTCDateTime from pylot.core.io.data import Data from pylot.core.io.inputs import FilterOptions, AutoPickParameter from pylot.core.pick.autopick import autopickevent -from pylot.core.io.phases import picks_to_dict +from pylot.core.io.phases import picksdict_from_picks from pylot.core.loc.nll import locate as locateNll from pylot.core.util.defaults import FILTERDEFAULTS, COMPNAME_MAP,\ AUTOMATIC_DEFAULTS @@ -735,7 +735,7 @@ class MainWindow(QMainWindow): return rval def updatePicks(self, type='manual'): - picks = picks_to_dict(evt=self.getData().getEvtData()) + picks = picksdict_from_picks(evt=self.getData().getEvtData()) if type == 'manual': self.picks.update(picks) elif type == 'auto': diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 01c36d4f..4f869932 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -9,7 +9,7 @@ from obspy.core import read, Stream, UTCDateTime from obspy import read_events, read_inventory from obspy.core.event import Event, ResourceIdentifier, Pick, WaveformStreamID -from pylot.core.io.phases import readPILOTEvent, picks_from_dict +from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict from pylot.core.util.utils import fnConstructor, getGlobalTimes from pylot.core.util.errors import FormatError, OverwriteError @@ -415,7 +415,7 @@ class Data(object): #firstonset = find_firstonset(picks) if self.getEvtData().picks: raise OverwriteError('Actual picks would be overwritten!') - picks = picks_from_dict(picks) + picks = picks_from_picksdict(picks) self.getEvtData().picks = picks # if 'smi:local' in self.getID() and firstonset: # fonset_str = firstonset.strftime('%Y_%m_%d_%H_%M_%S') diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 50d4f228..707b57ed 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -8,9 +8,10 @@ import scipy.io as sio import obspy.core.event as ope from obspy.core import UTCDateTime +from pylot.core.pick.utils import select_for_phase from pylot.core.util.utils import getOwner, createPick, createArrival, \ createEvent, createOrigin, createMagnitude - +from pylot.core.util.defaults import AUTOMATIC_DEFAULTS def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs): """ @@ -192,7 +193,7 @@ def picksdict_from_obs(fn): return picks -def picks_to_dict(evt): +def picksdict_from_picks(evt): ''' Takes an Event object and return the pick dictionary commonly used within PyLoT @@ -229,7 +230,7 @@ def picks_to_dict(evt): picks[station] = onsets.copy() return picks -def picks_from_dict(picks): +def picks_from_picksdict(picks): picks_list = list() for station, onsets in picks.items(): print('Reading picks on station %s' % station) @@ -267,17 +268,19 @@ def picks_from_dict(picks): return picks_list -def reassess_pilot_event(root_dir, event_id): +def reassess_pilot_event(root_dir, event_id, fn_param=AUTOMATIC_DEFAULTS): from obspy import read - from pylot.core.util.defaults import AUTOMATIC_DEFAULTS + from pylot.core.io.inputs import AutoPickParameter from pylot.core.pick.utils import earllatepicker - default = AutoPickParameter(AUTOMATIC_DEFAULTS) + default = AutoPickParameter(fn_param) search_base = os.path.join(root_dir, event_id) phases_file = glob.glob(os.path.join(search_base, 'PHASES.mat')) - picks_dict = picks_from_pilot(phases_file) + if not phases_file: + return + picks_dict = picks_from_pilot(phases_file[0]) for station in picks_dict.keys(): fn_pattern = os.path.join(search_base, '{0}*'.format(station)) try: @@ -293,19 +296,20 @@ def reassess_pilot_event(root_dir, event_id): except KeyError as e: print(e.message, station) continue - epp, lpp, spe = earllatepicker(st, + sel_st = select_for_phase(st, phase) + epp, lpp, spe = earllatepicker(sel_st, default.get('nfac{0}'.format(phase)), default.get('tsnrz' if phase == 'P' else 'tsnrh'), - mpp + mpp, None, True ) picks_dict[station][phase] = dict(epp=epp, mpp=mpp, lpp=lpp, spe=spe) # create Event object for export evt = ope.Event(resource_id=event_id) - evt.picks = picks_from_dict(picks_dict) + evt.picks = picks_from_picksdict(picks_dict) # write phase information to file fnout_prefix = os.path.join(root_dir, event_id, '{0}.'.format(event_id)) evt.write(fnout_prefix + 'xml', format='QUAKEML') - evt.write(fnout_prefix + 'cnv', format='VELEST') + #evt.write(fnout_prefix + 'cnv', format='VELEST') def writephases(arrivals, fformat, filename): diff --git a/pylot/core/pick/compare.py b/pylot/core/pick/compare.py index d4927ead..74a193ac 100644 --- a/pylot/core/pick/compare.py +++ b/pylot/core/pick/compare.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt from obspy import read_events -from pylot.core.io.phases import picks_to_dict +from pylot.core.io.phases import picksdict_from_picks from pylot.core.util.pdf import ProbabilityDensityFunction from pylot.core.util.version import get_git_version as _getVersionString @@ -227,7 +227,7 @@ class PDFDictionary(object): if len(cat) > 1: raise NotImplementedError('reading more than one event at the same ' 'time is not implemented yet! Sorry!') - return PDFDictionary(picks_to_dict(cat[0])) + return PDFDictionary(picksdict_from_picks(cat[0])) def pdf_data(self, type='exp'): """ diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 6e7fe2f5..1577abb3 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -464,6 +464,37 @@ def getResolutionWindow(snr): return time_resolution / 2 +def select_for_phase(st, phase): + ''' + takes a STream object and a phase name and returns that particular component + which presumably shows the chosen PHASE best + + :param st: stream object containing one or more component[s] + :type st: `~obspy.core.stream.Stream` + :param phase: label of the phase for which the stream selection is carried + out; 'P' or 'S' + :type phase: str + :return: + ''' + from pylot.core.util.defaults import COMPNAME_MAP + + sel_st = Stream() + if phase.upper() is 'P': + comp = 'Z' + alter_comp = COMPNAME_MAP[comp] + sel_st += st.select(component=comp) + sel_st += st.select(component=alter_comp) + elif phase.upper() is 'S': + comps = 'NE' + for comp in comps: + alter_comp = COMPNAME_MAP[comp] + sel_st += st.select(component=comp) + sel_st += st.select(component=alter_comp) + else: + raise TypeError('Unknown phase label: {0}'.format(phase)) + return sel_st + + def wadaticheck(pickdic, dttolerance, iplot): ''' Function to calculate Wadati-diagram from given P and S onsets in order From fd27a43110be683e5a14b8cf6f91668b4f886099 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Tue, 3 May 2016 15:09:51 +0200 Subject: [PATCH 03/13] fixing import problems --- pylot/core/io/phases.py | 16 ++++++++++++---- pylot/core/pick/utils.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 707b57ed..4604576a 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -10,8 +10,7 @@ from obspy.core import UTCDateTime from pylot.core.pick.utils import select_for_phase from pylot.core.util.utils import getOwner, createPick, createArrival, \ - createEvent, createOrigin, createMagnitude -from pylot.core.util.defaults import AUTOMATIC_DEFAULTS + createEvent, createOrigin, createMagnitude, getGlobalTimes def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs): """ @@ -268,12 +267,16 @@ def picks_from_picksdict(picks): return picks_list -def reassess_pilot_event(root_dir, event_id, fn_param=AUTOMATIC_DEFAULTS): +def reassess_pilot_event(root_dir, event_id, fn_param=None): from obspy import read from pylot.core.io.inputs import AutoPickParameter from pylot.core.pick.utils import earllatepicker + if fn_param is None: + import pylot.core.util.defaults as defaults + fn_param = defaults.AUTOMATIC_DEFAULTS + default = AutoPickParameter(fn_param) search_base = os.path.join(root_dir, event_id) @@ -297,11 +300,16 @@ def reassess_pilot_event(root_dir, event_id, fn_param=AUTOMATIC_DEFAULTS): print(e.message, station) continue sel_st = select_for_phase(st, phase) + stime, etime = getGlobalTimes(sel_st) + rel_pick = mpp - stime epp, lpp, spe = earllatepicker(sel_st, default.get('nfac{0}'.format(phase)), default.get('tsnrz' if phase == 'P' else 'tsnrh'), - mpp, None, True + Pick1=rel_pick, + iplot=None, ) + epp = stime + epp + lpp = stime + lpp picks_dict[station][phase] = dict(epp=epp, mpp=mpp, lpp=lpp, spe=spe) # create Event object for export evt = ope.Event(resource_id=event_id) diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 1577abb3..e603cfa4 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -479,12 +479,12 @@ def select_for_phase(st, phase): from pylot.core.util.defaults import COMPNAME_MAP sel_st = Stream() - if phase.upper() is 'P': + if phase.upper() == 'P': comp = 'Z' alter_comp = COMPNAME_MAP[comp] sel_st += st.select(component=comp) sel_st += st.select(component=alter_comp) - elif phase.upper() is 'S': + elif phase.upper() == 'S': comps = 'NE' for comp in comps: alter_comp = COMPNAME_MAP[comp] From 4480854ee5edd8cf32caa438ec5d3f99c75ec6b9 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Fri, 6 May 2016 12:04:27 +0200 Subject: [PATCH 04/13] [workaround] set minimum difference of mpp with lpp and epp this workaround elevates the difference between the uncertainty-picks and the mpp to a minimum value of three samples (needed for a reasonable pdf represetation of the pick) --- pylot/core/io/phases.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 4604576a..13ad3eeb 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -310,6 +310,11 @@ def reassess_pilot_event(root_dir, event_id, fn_param=None): ) epp = stime + epp lpp = stime + lpp + min_diff = 3 * st[0].stats.delta + if lpp - mpp < min_diff: + lpp = mpp + min_diff + if mpp - epp < min_diff: + epp = mpp - min_diff picks_dict[station][phase] = dict(epp=epp, mpp=mpp, lpp=lpp, spe=spe) # create Event object for export evt = ope.Event(resource_id=event_id) From 3705eb567bc624ec700a4e72d56cbe096bf91649 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Mon, 9 May 2016 12:06:47 +0200 Subject: [PATCH 05/13] [fix] overcome numerical instabilities due to the usage of large absolute values (timestamp) on time axis the estimation of the expectation value gets instable --- pylot/core/util/pdf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pylot/core/util/pdf.py b/pylot/core/util/pdf.py index 776192aa..1a233aed 100644 --- a/pylot/core/util/pdf.py +++ b/pylot/core/util/pdf.py @@ -256,9 +256,10 @@ class ProbabilityDensityFunction(object): ''' rval = 0 - for n, x in enumerate(self.axis): + axis = self.axis - self.x0 + for n, x in enumerate(axis): rval += x * self.data[n] - return rval * self.incr + return rval * self.incr + self.x0 def standard_deviation(self): mu = self.expectation() From c7d7acd7e3770f9fe3d7e6cab8169b064c3b2d6b Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Tue, 10 May 2016 09:54:21 +0200 Subject: [PATCH 06/13] [edit] implemented loop over PILOT database for reassessment additionally the output of reassess_pilot_event is more verbose now --- pylot/core/io/phases.py | 18 ++++++++++++++++-- scripts/pylot-reasses-pilot-event.py | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 13ad3eeb..a46c263b 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -267,7 +267,16 @@ def picks_from_picksdict(picks): return picks_list -def reassess_pilot_event(root_dir, event_id, fn_param=None): +def reassess_pilot_db(root_dir, out_dir=None, fn_param=None): + import glob + + evt_list = glob.glob1(root_dir,'e????.???.??') + + for evt in evt_list: + reassess_pilot_event(root_dir, evt, out_dir, fn_param) + + +def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None): from obspy import read from pylot.core.io.inputs import AutoPickParameter @@ -283,7 +292,9 @@ def reassess_pilot_event(root_dir, event_id, fn_param=None): phases_file = glob.glob(os.path.join(search_base, 'PHASES.mat')) if not phases_file: return + print('Opening PILOT phases file: {fn}'.format(fn=phases_file[0])) picks_dict = picks_from_pilot(phases_file[0]) + print('Dictionary read from PHASES.mat:\n{0}'.format(picks_dict)) for station in picks_dict.keys(): fn_pattern = os.path.join(search_base, '{0}*'.format(station)) try: @@ -320,7 +331,10 @@ def reassess_pilot_event(root_dir, event_id, fn_param=None): evt = ope.Event(resource_id=event_id) evt.picks = picks_from_picksdict(picks_dict) # write phase information to file - fnout_prefix = os.path.join(root_dir, event_id, '{0}.'.format(event_id)) + if not out_dir: + fnout_prefix = os.path.join(root_dir, event_id, '{0}.'.format(event_id)) + else: + fnout_prefix = os.path.join(out_dir, event_id, '{0}.'.format(event_id)) evt.write(fnout_prefix + 'xml', format='QUAKEML') #evt.write(fnout_prefix + 'cnv', format='VELEST') diff --git a/scripts/pylot-reasses-pilot-event.py b/scripts/pylot-reasses-pilot-event.py index f48a08f2..939bf860 100644 --- a/scripts/pylot-reasses-pilot-event.py +++ b/scripts/pylot-reasses-pilot-event.py @@ -21,4 +21,4 @@ if __name__ == '__main__': ) args = parser.parse_args() - reassess_pilot_event(args.dir, args.id) + reassess_pilot_event(args.dir, args.id, None) From 63ac0107d01b440993ad7de88b4042888c4b92c6 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 11 May 2016 06:01:26 +0200 Subject: [PATCH 07/13] [edit] implemented a plotting method for pdf dictionaries --- pylot/core/pick/compare.py | 70 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/pylot/core/pick/compare.py b/pylot/core/pick/compare.py index 74a193ac..2be4d7aa 100644 --- a/pylot/core/pick/compare.py +++ b/pylot/core/pick/compare.py @@ -86,8 +86,8 @@ class Comparison(object): """ compare_pdfs = dict() - pdf_a = self.get(self.names[0]).pdf_data(type) - pdf_b = self.get(self.names[1]).pdf_data(type) + pdf_a = self.get(self.names[0]).generate_pdf_data(type) + pdf_b = self.get(self.names[1]).generate_pdf_data(type) for station, phases in pdf_a.items(): if station in pdf_b.keys(): @@ -206,6 +206,7 @@ class PDFDictionary(object): def __init__(self, data): self._pickdata = data + self._pdfdata = self.generate_pdf_data() def __nonzero__(self): if len(self.pick_data) < 1: @@ -213,6 +214,14 @@ class PDFDictionary(object): else: return True + @property + def pdf_data(self): + return self._pdfdata + + @pdf_data.setter + def pdf_data(self, data): + self._pdfdata = data + @property def pick_data(self): return self._pickdata @@ -221,6 +230,14 @@ class PDFDictionary(object): def pick_data(self, data): self._pickdata = data + @property + def stations(self): + return self.pick_data.keys() + + @property + def nstations(self): + return len(self.stations) + @classmethod def from_quakeml(self, fn): cat = read_events(fn) @@ -229,7 +246,7 @@ class PDFDictionary(object): 'time is not implemented yet! Sorry!') return PDFDictionary(picksdict_from_picks(cat[0])) - def pdf_data(self, type='exp'): + def generate_pdf_data(self, type='exp'): """ Returns probabiliy density function dictionary containing the representation of the actual pick_data. @@ -251,3 +268,50 @@ class PDFDictionary(object): return pdf_picks + def plot(self, stations=None): + assert stations is not None or not isinstance(stations, list), \ + 'parameter stations should be a list not {0}'.format(type(stations)) + if not stations: + nstations = self.nstations + stations = self.stations + else: + nstations = len(stations) + + istations = range(nstations) + fig, axarr = plt.subplots(nstations, 2, sharex='col', sharey='row') + + for n in istations: + station = stations[n] + pdfs = self.pdf_data[station] + for l, phase in enumerate(pdfs.keys()): + hide_labels = True + try: + axarr[n, l].plot(pdfs[phase].axis, pdfs[phase].data) + if n is 0: + axarr[n, l].set_title(phase) + if l is 0: + axann = axarr[n, l].annotate(station, xy=(.05, .5), + xycoords='axes fraction') + bbox_props = dict(boxstyle='round', facecolor='lightgrey', + alpha=.7) + axann.set_bbox(bbox_props) + if n == int(np.median(istations)) and l is 0: + label = 'probability density (qualitative)' + axarr[n, l].set_ylabel(label) + except IndexError as e: + print('trying aligned plotting\n{0}'.format(e)) + hide_labels = False + axarr[l].plot(pdfs[phase].axis, pdfs[phase].data) + axarr[l].set_title(phase) + if l is 0: + axann = axarr[l].annotate(station, xy=(.05, .5), + xycoords='axes fraction') + bbox_props = dict(boxstyle='round', facecolor='lightgrey', + alpha=.7) + axann.set_bbox(bbox_props) + if hide_labels: + plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False) + plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False) + plt.setp([a.get_yticklabels() for a in axarr[:, 0]], visible=False) + + plt.show() From f8807a7ea68b64ee5db5ab808d80c40ba88a0a9a Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Wed, 11 May 2016 09:49:19 +0200 Subject: [PATCH 08/13] [edit] docstring added and returning the figure instead of showing the plot additionally hide_labels is now defined only once before going into the loop --- pylot/core/pick/compare.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pylot/core/pick/compare.py b/pylot/core/pick/compare.py index 2be4d7aa..1a828c2a 100644 --- a/pylot/core/pick/compare.py +++ b/pylot/core/pick/compare.py @@ -269,6 +269,13 @@ class PDFDictionary(object): return pdf_picks def plot(self, stations=None): + ''' + plots the all probability density function for either desired STATIONS + or all available date + :param stations: list of stations to be plotted + :type stations: list + :return: matplotlib figure object containing the plot + ''' assert stations is not None or not isinstance(stations, list), \ 'parameter stations should be a list not {0}'.format(type(stations)) if not stations: @@ -279,12 +286,12 @@ class PDFDictionary(object): istations = range(nstations) fig, axarr = plt.subplots(nstations, 2, sharex='col', sharey='row') + hide_labels = True for n in istations: station = stations[n] pdfs = self.pdf_data[station] for l, phase in enumerate(pdfs.keys()): - hide_labels = True try: axarr[n, l].plot(pdfs[phase].axis, pdfs[phase].data) if n is 0: @@ -314,4 +321,4 @@ class PDFDictionary(object): plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False) plt.setp([a.get_yticklabels() for a in axarr[:, 0]], visible=False) - plt.show() + return fig From f7e1247060b13e5798e69f21db0cbba83d58f9d5 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Wed, 11 May 2016 12:01:10 +0200 Subject: [PATCH 09/13] [fix] make all scripts executable new script for pilot data base reassessmant --- scripts/pylot-noisewindow.py | 0 scripts/pylot-reasses-pilot-db.py | 33 ++++++++++++++++++++++++++++ scripts/pylot-reasses-pilot-event.py | 22 ++++++++++++++----- scripts/pylot-signalwindow.py | 0 scripts/pylot-snr.py | 0 5 files changed, 50 insertions(+), 5 deletions(-) mode change 100644 => 100755 scripts/pylot-noisewindow.py create mode 100755 scripts/pylot-reasses-pilot-db.py mode change 100644 => 100755 scripts/pylot-reasses-pilot-event.py mode change 100644 => 100755 scripts/pylot-signalwindow.py mode change 100644 => 100755 scripts/pylot-snr.py diff --git a/scripts/pylot-noisewindow.py b/scripts/pylot-noisewindow.py old mode 100644 new mode 100755 diff --git a/scripts/pylot-reasses-pilot-db.py b/scripts/pylot-reasses-pilot-db.py new file mode 100755 index 00000000..5bb4441d --- /dev/null +++ b/scripts/pylot-reasses-pilot-db.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +from pylot.core.util.version import get_git_version as _getVersionString +from pylot.core.io.phases import reassess_pilot_db + +__version__ = _getVersionString() +__author__ = 'S. Wehling-Benatelli' + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='reassess old PILOT event data base in terms of consistent ' + 'automatic uncertainty estimation', + epilog='Script written by {author} belonging to PyLoT version' + ' {version}\n'.format(author=__author__, + version=__version__) + ) + + parser.add_argument( + 'dbroot', type=str, help='specifies the root directory (in ' + 'most cases PILOT database folder)' + ) + parser.add_argument( + '--output', '-o', type=str, help='path to the output directory', dest='output' + ) + parser.add_argument( + '--parameterfile', '-p', type=str, help='full path to the parameterfile', dest='parfile' + ) + + args = parser.parse_args() + reassess_pilot_db(args.dbroot, args.output, args.parfile) diff --git a/scripts/pylot-reasses-pilot-event.py b/scripts/pylot-reasses-pilot-event.py old mode 100644 new mode 100755 index 939bf860..1852e680 --- a/scripts/pylot-reasses-pilot-event.py +++ b/scripts/pylot-reasses-pilot-event.py @@ -7,18 +7,30 @@ from pylot.core.util.version import get_git_version as _getVersionString from pylot.core.io.phases import reassess_pilot_event __version__ = _getVersionString() -__author__ = 'sebastianw' +__author__ = 'S. Wehling-Benatelli' if __name__ == '__main__': - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser( + description='reassess old PILOT event data in terms of consistent ' + 'automatic uncertainty estimation', + epilog='Script written by {author} belonging to PyLoT version' + ' {version}\n'.format(author=__author__, + version=__version__) + ) parser.add_argument( - '--directory', '-d', type=str, help='specifies the root directory (in ' + 'dbroot', type=str, help='specifies the root directory (in ' 'most cases PILOT database folder)' ) parser.add_argument( - '--eventid', '-i', type=str, help='PILOT event identifier' + 'id', type=str, help='PILOT event identifier' + ) + parser.add_argument( + '--output', '-o', type=str, help='path to the output directory', dest='output' + ) + parser.add_argument( + '--parameterfile', '-p', type=str, help='full path to the parameterfile', dest='parfile' ) args = parser.parse_args() - reassess_pilot_event(args.dir, args.id, None) + reassess_pilot_event(args.dbroot, args.id, args.output, args.parfile) diff --git a/scripts/pylot-signalwindow.py b/scripts/pylot-signalwindow.py old mode 100644 new mode 100755 diff --git a/scripts/pylot-snr.py b/scripts/pylot-snr.py old mode 100644 new mode 100755 From 79e429db8d25c67bb0ece6468e4aac053a0e0aed Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Wed, 11 May 2016 14:50:52 +0200 Subject: [PATCH 10/13] [edit] rearrangement fastens up a bit --- pylot/core/io/phases.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index a46c263b..b5770385 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -234,7 +234,7 @@ def picks_from_picksdict(picks): for station, onsets in picks.items(): print('Reading picks on station %s' % station) for label, phase in onsets.items(): - if not isinstance(phase, dict): + if not isinstance(phase, dict) or len(phase) < 3: continue onset = phase['mpp'] epp = phase['epp'] @@ -276,7 +276,7 @@ def reassess_pilot_db(root_dir, out_dir=None, fn_param=None): reassess_pilot_event(root_dir, evt, out_dir, fn_param) -def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None): +def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbosity=0): from obspy import read from pylot.core.io.inputs import AutoPickParameter @@ -298,12 +298,10 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None): for station in picks_dict.keys(): fn_pattern = os.path.join(search_base, '{0}*'.format(station)) try: - st = read(fn_pattern) + st = read(fn_pattern, format='GSE2') except TypeError as e: print(e.message) - st = read(fn_pattern, format='GSE2') - if not st: - raise RuntimeError('no waveform data found for station {station}'.format(station=station)) + st = read(fn_pattern) for phase in picks_dict[station].keys(): try: mpp = picks_dict[station][phase]['mpp'] @@ -311,6 +309,11 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None): print(e.message, station) continue sel_st = select_for_phase(st, phase) + if not sel_st: + raise warnings.formatwarning( + 'no waveform data found for station {station}'.format( + station=station), category=RuntimeWarning) + print(sel_st) stime, etime = getGlobalTimes(sel_st) rel_pick = mpp - stime epp, lpp, spe = earllatepicker(sel_st, @@ -319,6 +322,8 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None): Pick1=rel_pick, iplot=None, ) + if epp is None or lpp is None: + continue epp = stime + epp lpp = stime + lpp min_diff = 3 * st[0].stats.delta @@ -334,7 +339,7 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None): if not out_dir: fnout_prefix = os.path.join(root_dir, event_id, '{0}.'.format(event_id)) else: - fnout_prefix = os.path.join(out_dir, event_id, '{0}.'.format(event_id)) + fnout_prefix = os.path.join(out_dir, '{0}.'.format(event_id)) evt.write(fnout_prefix + 'xml', format='QUAKEML') #evt.write(fnout_prefix + 'cnv', format='VELEST') From f09af1612066262129480f8bec3677045660526c Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Thu, 12 May 2016 10:08:29 +0200 Subject: [PATCH 11/13] [task] started to implement data processing step for checking corrupted GSE files --- pylot/core/util/dataprocessing.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pylot/core/util/dataprocessing.py diff --git a/pylot/core/util/dataprocessing.py b/pylot/core/util/dataprocessing.py new file mode 100644 index 00000000..f91e2ba2 --- /dev/null +++ b/pylot/core/util/dataprocessing.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import glob +from obspy import UTCDateTime + +def gse_time_header(lines): + ''' + takes a path FILE to a GSE data file and returns the time header of the file + :param file: path to GSE data file + :type file: str + :return: time header from FILE + :rtype: str + + >>> gse_time_header('test.gse') + "WID2 2005/10/09 20:17:25.000 ATH SHZ NSP CM6 9000 50.000000 0.10E+01 1.000 NSP -1.0 0.0" + ''' + + return lines[1] + +def time_from_header(header): + timeline = header.split(' ') + time = timeline[1].split('/') + timeline[2].split(':') + time = time[:-1] + time[-1].split('.') + time[-1] += '000' + return [int(t) for t in time] + +def check_time(time): + try: + UTCDateTime(time) + return True + except ValueError: + return False \ No newline at end of file From e62ff9d68c6272c3a5a011095ad1ac8dd9fd5cac Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 18 May 2016 12:55:04 +0200 Subject: [PATCH 12/13] [fix] returning variables now, docstrings corrected to be able to use single quotes in docstrings --- pylot/core/io/phases.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index f3c6c96a..92c327e0 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -193,13 +193,13 @@ def picksdict_from_obs(fn): def picks_to_dict(evt): - ''' + """ Takes an Event object and return the pick dictionary commonly used within PyLoT :param evt: Event object contain all available information :type evt: `~obspy.core.event.Event` :return: pick dictionary - ''' + """ picks = {} for pick in evt.picks: phase = {} @@ -229,6 +229,7 @@ def picks_to_dict(evt): picks[station] = onsets.copy() return picks + def picks_from_dict(picks): firstonset = None for station, onsets in picks.items(): @@ -265,6 +266,7 @@ def picks_from_dict(picks): print('No polarity information found for %s' % phase) if firstonset is None or firstonset > onset: firstonset = onset + return pick, firstonset def reassess_pilot_event(root_dir, event_id): @@ -307,7 +309,7 @@ def reassess_pilot_event(root_dir, event_id): def writephases(arrivals, fformat, filename): - ''' + """ Function of methods to write phases to the following standard file formats used for locating earthquakes: @@ -325,7 +327,7 @@ def writephases(arrivals, fformat, filename): :param: filename, full path and name of phase file :type: string - ''' + """ if fformat == 'NLLoc': print ("Writing phases to %s for NLLoc" % filename) @@ -387,7 +389,6 @@ def writephases(arrivals, fformat, filename): sweight)) fid.close() - elif fformat == 'HYPO71': print ("Writing phases to %s for HYPO71" % filename) fid = open("%s" % filename, 'w') From dc5d76efb86889f21043fed859934858847aee25 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 18 May 2016 13:17:05 +0200 Subject: [PATCH 13/13] [fix] fixing docstring problem caused by merge of conflicting files --- pylot/core/io/phases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index bf2ba499..3924ddd3 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -193,7 +193,7 @@ def picksdict_from_obs(fn): def picksdict_from_picks(evt): - ''' + """ Takes an Event object and return the pick dictionary commonly used within PyLoT :param evt: Event object contain all available information