[add] differentiation between automatic and manual picks imported from new
style XML file
This commit is contained in:
parent
29165aadc7
commit
acaf7f5172
57
QtPyLoT.py
57
QtPyLoT.py
@ -168,7 +168,6 @@ class MainWindow(QMainWindow):
|
||||
"Enter authority/institution name:",
|
||||
"Authority")
|
||||
settings.setValue("agency_id", agency)
|
||||
self.fname = dict(manual=None, auto=None, loc=None)
|
||||
self.fnames = None
|
||||
self._stime = None
|
||||
structure_setting = settings.value("data/Structure", "PILOT")
|
||||
@ -199,8 +198,6 @@ class MainWindow(QMainWindow):
|
||||
'S': FilterOptions(s_filter['filtertype'],
|
||||
s_filter['freq'],
|
||||
s_filter['order'])}
|
||||
self.pylot_picks = {}
|
||||
self.pylot_autopicks = {}
|
||||
self.loc = False
|
||||
|
||||
def setupUi(self):
|
||||
@ -714,7 +711,7 @@ class MainWindow(QMainWindow):
|
||||
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
|
||||
self.load_data(fname_dict, type=type)
|
||||
|
||||
def load_multiple_data(self, type='manual'):
|
||||
def load_multiple_data(self):
|
||||
if not self.okToContinue():
|
||||
return
|
||||
refresh = False
|
||||
@ -733,7 +730,7 @@ class MainWindow(QMainWindow):
|
||||
self.refreshEvents()
|
||||
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 self.okToContinue():
|
||||
return
|
||||
@ -743,8 +740,6 @@ class MainWindow(QMainWindow):
|
||||
fname = self.filename_from_action(action)
|
||||
if not fname:
|
||||
return
|
||||
self.set_fname(fname, type)
|
||||
# data = dict(auto=self.autodata, manual=self.data)
|
||||
if not event:
|
||||
event = self.get_current_event()
|
||||
data = Data(self, event)
|
||||
@ -767,11 +762,12 @@ class MainWindow(QMainWindow):
|
||||
return
|
||||
|
||||
self.data = data
|
||||
print('Loading {} picks from file {}.'.format(type, fname))
|
||||
print('Loading event info from file {}.'.format(fname))
|
||||
if not loc:
|
||||
self.updatePicks(type=type, event=event)
|
||||
self.updatePicks(type='auto', event=event)
|
||||
self.updatePicks(type='manual', event=event)
|
||||
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.setDirty(True)
|
||||
|
||||
@ -1092,14 +1088,6 @@ class MainWindow(QMainWindow):
|
||||
fname = str(action.data().toString())
|
||||
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'):
|
||||
if self.get_fnames(type) is None:
|
||||
self.set_fname(self.get_data().getEventFileName(), type)
|
||||
@ -1180,9 +1168,7 @@ class MainWindow(QMainWindow):
|
||||
def setComponent(self, component):
|
||||
self.dispComponent = component
|
||||
|
||||
def get_data(self, type='manual'):
|
||||
if type == 'auto':
|
||||
return self.autodata
|
||||
def get_data(self):
|
||||
return self.data
|
||||
|
||||
def getPicks(self, type='manual'):
|
||||
@ -1190,8 +1176,6 @@ class MainWindow(QMainWindow):
|
||||
return self.get_current_event().getPicks()
|
||||
if type == 'auto':
|
||||
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'):
|
||||
try:
|
||||
@ -1327,15 +1311,6 @@ class MainWindow(QMainWindow):
|
||||
event = self.get_current_event()
|
||||
if not event:
|
||||
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 self.tabs.currentIndex() == 0:
|
||||
if self._eventChanged[0]:
|
||||
@ -1482,11 +1457,9 @@ class MainWindow(QMainWindow):
|
||||
self.enableSaveEventAction()
|
||||
event = self.get_current_event()
|
||||
if event.pylot_picks:
|
||||
self.pylot_picks = event.pylot_picks
|
||||
self.drawPicks(picktype='manual')
|
||||
self.locateEvent.setEnabled(True)
|
||||
if event.pylot_autopicks:
|
||||
self.pylot_autopicks = event.pylot_autopicks
|
||||
self.drawPicks(picktype='auto')
|
||||
self.compare_action.setEnabled(True)
|
||||
self.draw()
|
||||
@ -1930,16 +1903,20 @@ class MainWindow(QMainWindow):
|
||||
def updatePicks(self, type='manual', event=None):
|
||||
if not 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':
|
||||
event.addPicks(picks)
|
||||
self.pylot_picks.update(picks)
|
||||
event.addPicks(picksdict['manual'])
|
||||
#event.picks.update(picks) MP MP idea
|
||||
elif type == 'auto':
|
||||
event.addAutopicks(picks)
|
||||
self.pylot_autopicks.update(picks)
|
||||
event.addAutopicks(picksdict['auto'])
|
||||
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 not station:
|
||||
for station in self.getPicks(type=picktype):
|
||||
|
@ -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
|
||||
|
||||
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):
|
||||
|
@ -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()
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user