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

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

View File

@ -168,7 +168,6 @@ class MainWindow(QMainWindow):
"Enter authority/institution name:", "Enter authority/institution name:",
"Authority") "Authority")
settings.setValue("agency_id", agency) settings.setValue("agency_id", agency)
self.fname = dict(manual=None, auto=None, loc=None)
self.fnames = None self.fnames = None
self._stime = None self._stime = None
structure_setting = settings.value("data/Structure", "PILOT") structure_setting = settings.value("data/Structure", "PILOT")
@ -199,8 +198,6 @@ class MainWindow(QMainWindow):
'S': FilterOptions(s_filter['filtertype'], 'S': FilterOptions(s_filter['filtertype'],
s_filter['freq'], s_filter['freq'],
s_filter['order'])} s_filter['order'])}
self.pylot_picks = {}
self.pylot_autopicks = {}
self.loc = False self.loc = False
def setupUi(self): def setupUi(self):
@ -714,7 +711,7 @@ class MainWindow(QMainWindow):
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc) fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
self.load_data(fname_dict, type=type) self.load_data(fname_dict, type=type)
def load_multiple_data(self, type='manual'): def load_multiple_data(self):
if not self.okToContinue(): if not self.okToContinue():
return return
refresh = False refresh = False
@ -733,7 +730,7 @@ class MainWindow(QMainWindow):
self.refreshEvents() self.refreshEvents()
self.setDirty(True) self.setDirty(True)
def load_data(self, fname=None, type='manual', loc=False, draw=True, event=None, overwrite=False): def load_data(self, fname=None, loc=False, draw=True, event=None, overwrite=False):
if not overwrite: if not overwrite:
if not self.okToContinue(): if not self.okToContinue():
return return
@ -743,8 +740,6 @@ class MainWindow(QMainWindow):
fname = self.filename_from_action(action) fname = self.filename_from_action(action)
if not fname: if not fname:
return return
self.set_fname(fname, type)
# data = dict(auto=self.autodata, manual=self.data)
if not event: if not event:
event = self.get_current_event() event = self.get_current_event()
data = Data(self, event) data = Data(self, event)
@ -767,11 +762,12 @@ class MainWindow(QMainWindow):
return return
self.data = data self.data = data
print('Loading {} picks from file {}.'.format(type, fname)) print('Loading event info from file {}.'.format(fname))
if not loc: if not loc:
self.updatePicks(type=type, event=event) self.updatePicks(type='auto', event=event)
self.updatePicks(type='manual', event=event)
if draw: if draw:
if self.get_current_event().pylot_picks: if self.get_current_event().pylot_picks or self.get_current_event().pylot_autopicks:
self.refreshEvents() self.refreshEvents()
self.setDirty(True) self.setDirty(True)
@ -1092,14 +1088,6 @@ class MainWindow(QMainWindow):
fname = str(action.data().toString()) fname = str(action.data().toString())
return fname return fname
def get_fnames(self, type='manual'):
return self.fname[type]
def set_fname(self, fname, type):
if self.get_fnames(type) is not None:
self.add_recentfile(self.get_fnames(type))
self.fname[type] = fname
def getEventFileName(self, type='manual'): def getEventFileName(self, type='manual'):
if self.get_fnames(type) is None: if self.get_fnames(type) is None:
self.set_fname(self.get_data().getEventFileName(), type) self.set_fname(self.get_data().getEventFileName(), type)
@ -1180,9 +1168,7 @@ class MainWindow(QMainWindow):
def setComponent(self, component): def setComponent(self, component):
self.dispComponent = component self.dispComponent = component
def get_data(self, type='manual'): def get_data(self):
if type == 'auto':
return self.autodata
return self.data return self.data
def getPicks(self, type='manual'): def getPicks(self, type='manual'):
@ -1190,8 +1176,6 @@ class MainWindow(QMainWindow):
return self.get_current_event().getPicks() return self.get_current_event().getPicks()
if type == 'auto': if type == 'auto':
return self.get_current_event().getAutopicks() return self.get_current_event().getAutopicks()
# rdict = dict(auto=self.pylot_autopicks, manual=self.pylot_picks)
# return rdict[type]
def getPicksOnStation(self, station, type='manual'): def getPicksOnStation(self, station, type='manual'):
try: try:
@ -1327,15 +1311,6 @@ class MainWindow(QMainWindow):
event = self.get_current_event() event = self.get_current_event()
if not event: if not event:
return return
# update picks saved in GUI mainwindow (to be changed in future!!) MP MP
if not event.pylot_picks:
self.pylot_picks = {}
else:
self.pylot_picks = event.pylot_picks
if not event.pylot_autopicks:
self.pylot_autopicks = {}
else:
self.pylot_autopicks = event.pylot_autopicks
# if current tab is waveformPlot-tab and the data in this tab was not yet refreshed # if current tab is waveformPlot-tab and the data in this tab was not yet refreshed
if self.tabs.currentIndex() == 0: if self.tabs.currentIndex() == 0:
if self._eventChanged[0]: if self._eventChanged[0]:
@ -1482,11 +1457,9 @@ class MainWindow(QMainWindow):
self.enableSaveEventAction() self.enableSaveEventAction()
event = self.get_current_event() event = self.get_current_event()
if event.pylot_picks: if event.pylot_picks:
self.pylot_picks = event.pylot_picks
self.drawPicks(picktype='manual') self.drawPicks(picktype='manual')
self.locateEvent.setEnabled(True) self.locateEvent.setEnabled(True)
if event.pylot_autopicks: if event.pylot_autopicks:
self.pylot_autopicks = event.pylot_autopicks
self.drawPicks(picktype='auto') self.drawPicks(picktype='auto')
self.compare_action.setEnabled(True) self.compare_action.setEnabled(True)
self.draw() self.draw()
@ -1930,16 +1903,20 @@ class MainWindow(QMainWindow):
def updatePicks(self, type='manual', event=None): def updatePicks(self, type='manual', event=None):
if not event: if not event:
event = self.get_current_event() event = self.get_current_event()
picks = picksdict_from_picks(evt=self.get_data(type).get_evt_data()) picksdict = picksdict_from_picks(evt=self.get_data().get_evt_data())
if type == 'manual': if type == 'manual':
event.addPicks(picks) event.addPicks(picksdict['manual'])
self.pylot_picks.update(picks) #event.picks.update(picks) MP MP idea
elif type == 'auto': elif type == 'auto':
event.addAutopicks(picks) event.addAutopicks(picksdict['auto'])
self.pylot_autopicks.update(picks)
self.check4Comparison() self.check4Comparison()
def drawPicks(self, station=None, picktype='manual'): def drawPicks(self, station=None, picktype=None):
# if picktype not specified, draw both
if not picktype:
self.drawPicks(station, 'manual')
self.drawPicks(station, 'auto')
return
# if picks to draw not specified, draw all picks available # if picks to draw not specified, draw all picks available
if not station: if not station:
for station in self.getPicks(type=picktype): for station in self.getPicks(type=picktype):

View File

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

View File

@ -255,7 +255,7 @@ class PDFDictionary(object):
if len(cat) > 1: if len(cat) > 1:
raise NotImplementedError('reading more than one event at the same ' raise NotImplementedError('reading more than one event at the same '
'time is not implemented yet! Sorry!') '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): def get_all(self, phase):
rlist = list() rlist = list()

View File

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