[add] differentiation between automatic and manual picks imported from new

style XML file
This commit is contained in:
2017-08-09 14:15:50 +02:00
parent 29165aadc7
commit acaf7f5172
4 changed files with 66 additions and 63 deletions

View File

@@ -194,16 +194,25 @@ def picksdict_from_picks(evt):
PyLoT
:param evt: Event object contain all available information
:type evt: `~obspy.core.event.Event`
:return: pick dictionary
:return: pick dictionary (auto and manual)
"""
picks = {}
picksdict = {
'manual': {},
'auto': {}
}
for pick in evt.picks:
phase = {}
station = pick.waveform_id.station_code
channel = pick.waveform_id.channel_code
network = pick.waveform_id.network_code
try:
onsets = picks[station]
picker = str(pick.method_id)
if picker.startswith('smi:local/'):
picker = picker.split('smi:local/')[1]
except IndexError:
picker = 'manual' # MP MP TODO maybe improve statement
try:
onsets = picksdict[picker][station]
except KeyError as e:
# print(e)
onsets = {}
@@ -223,17 +232,11 @@ def picksdict_from_picks(evt):
phase['spe'] = spe
phase['channel'] = channel
phase['network'] = network
try:
picker = str(pick.method_id)
if picker.startswith('smi:local/'):
picker = picker.split('smi:local/')[1]
phase['picker'] = picker
except IndexError:
pass
phase['picker'] = picker
onsets[pick.phase_hint] = phase.copy()
picks[station] = onsets.copy()
return picks
picksdict[picker][station] = onsets.copy()
return picksdict
def picks_from_picksdict(picks, creation_info=None):

View File

@@ -255,7 +255,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(picksdict_from_picks(cat[0]))
return PDFDictionary(picksdict_from_picks(cat[0])) # MP MP TODO: change function argument (auto/manu)
def get_all(self, phase):
rlist = list()

View File

@@ -67,18 +67,27 @@ class Event(ObsPyEvent):
self._testEvent = bool
if bool: self._refEvent = False
def clearObsPyPicks(self, picktype):
for index, pick in reversed(list(enumerate(self.picks))):
if pick.method_id == picktype:
self.picks.pop(index)
def addPicks(self, picks):
'''
add pylot picks and overwrite existing
add pylot picks and overwrite existing ones
'''
for station in picks:
self.pylot_picks[station] = picks[station]
# add ObsPy picks
self.picks = picks_from_picksdict(self.pylot_picks)
# add ObsPy picks (clear old manual and copy all new manual from pylot)
self.clearObsPyPicks('manual')
self.picks += picks_from_picksdict(self.pylot_picks)
def addAutopicks(self, autopicks):
for station in autopicks:
self.pylot_autopicks[station] = autopicks[station]
# add ObsPy picks (clear old auto and copy all new auto from pylot)
self.clearObsPyPicks('auto')
self.picks += picks_from_picksdict(self.pylot_autopicks)
def setPick(self, station, pick):
if pick:
@@ -88,14 +97,16 @@ class Event(ObsPyEvent):
self.pylot_picks.pop(station)
except Exception as e:
print('Could not remove pick {} from station {}: {}'.format(pick, station, e))
self.picks = picks_from_picksdict(self.pylot_picks)
self.clearObsPyPicks('manual')
self.picks += picks_from_picksdict(self.pylot_picks)
def setPicks(self, picks):
'''
set pylot picks and delete and overwrite all existing
'''
self.pylot_picks = picks
self.picks = picks_from_picksdict(self.pylot_picks)
self.clearObsPyPicks('manual')
self.picks += picks_from_picksdict(self.pylot_picks)
def getPick(self, station):
if station in self.pylot_picks.keys():
@@ -104,12 +115,24 @@ class Event(ObsPyEvent):
def getPicks(self):
return self.pylot_picks
def setAutopick(self, station, autopick):
if autopick:
self.pylot_autopicks[station] = autopick
def setAutopick(self, station, pick):
if pick:
self.pylot_autopicks[station] = pick
else:
try:
self.pylot_autopicks.pop(station)
except Exception as e:
print('Could not remove pick {} from station {}: {}'.format(pick, station, e))
self.clearObsPyPicks('auto')
self.picks += picks_from_picksdict(self.pylot_autopicks)
def setAutopicks(self, autopicks):
self.pylot_autopicks = autopicks
def setAutopicks(self, picks):
'''
set pylot picks and delete and overwrite all existing
'''
self.pylot_autopicks = picks
self.clearObsPyPicks('auto')
self.picks += picks_from_picksdict(self.pylot_autopicks)
def getAutopick(self, station):
if station in self.pylot_autopicks.keys():