diff --git a/QtPyLoT.py b/QtPyLoT.py index 1a0ff6d2..413d0d76 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -40,6 +40,7 @@ import numpy as np import subprocess from obspy import UTCDateTime +from pylot.core.analysis.magnitude import calcsourcespec, calcMoMw from pylot.core.io.data import Data from pylot.core.io.inputs import FilterOptions, AutoPickParameter from pylot.core.pick.autopick import autopickevent @@ -945,16 +946,31 @@ class MainWindow(QMainWindow): os.remove(phasepath) self.getData().applyEVTData(lt.read_location(locpath), type='event') + self.calc_magnitude() def calc_magnitude(self): e = self.getData().getEvtData() + settings = QSettings() if e.origins: o = e.origins[0] + mags = dict() for a in o.arrivals: - pid = a.pick_id - pick = pid.get_referred_object() - station = self.getStationID(pick.waveform_id.station_code) + pick = a.pick_id.get_referred_object() + station = pick.waveform_id.station_code wf = self.getData().getWFData().select(station=station) + onset = pick.time + fninv = settings.value("inventoryFile", None) + if fninv is None: + fninv = QFileDialog.getOpenFileName() + ans = QMessageBox.question(self, self.tr("Make default..."), + self.tr("New inventory filename set.\n" + \ + "Do you want to make it the default value?"), + QMessageBox.Yes | QMessageBox.No, + QMessageBox.No) + print(ans) + settings.setValue("inventoryFile", fninv) + #w0, fc = calcsourcespec(wf, onset, ) + #mags[station] = mag = None return mag else: diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 1f4a6008..0477507a 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -10,7 +10,7 @@ from obspy.core.event import Event from obspy.io.xseed import Parser from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \ - picksdict_from_pilot + picksdict_from_pilot, merge_picks from pylot.core.util.errors import FormatError, OverwriteError from pylot.core.util.utils import fnConstructor, getGlobalTimes @@ -454,9 +454,9 @@ class Data(object): if not self.isNew(): self.setEvtData(event) else: - # prevent overwriting uncertainty information + # prevent overwriting original pick information picks = copy.deepcopy(self.getEvtData().picks) - event.picks = picks + event = merge_picks(event, picks) # apply event information from location self.getEvtData().update(event) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 0de1d40a..bd255b34 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -527,3 +527,26 @@ def writephases(arrivals, fformat, filename): Ao)) fid.close() + + +def merge_picks(event, picks): + """ + takes an event object and a list of picks and searches for matching + entries by comparing station name and phase_hint and overwrites the time + and time_errors value of the event picks' with those from the picks + without changing the resource identifiers + :param event: `obspy.core.event.Event` object (e.g. from NLLoc output) + :param picks: list of `obspy.core.event.Pick` objects containing the + original time and time_errors values + :return: merged `obspy.core.event.Event` object + """ + for pick in picks: + time = pick.time + err = pick.time_errors + phase = pick.phase_hint + station = pick.waveform_id.station_code + for p in event.picks: + if p.waveform_id.station_code == station and p.phase_hint == phase: + p.time, p.time_errors = time, err + del time, err, phase, station + return event \ No newline at end of file