From a54ffe01f8dd8f2f889bebbf14a8c7047a5e6f1c Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Tue, 20 Sep 2016 13:45:49 +0200 Subject: [PATCH 1/3] [new, bugfix] use new metadata concept in the scope of QtPyLoT; consistent use of input variables input variables should always be used; avoid hard-coded parameters --- QtPyLoT.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index d946de14..90ae45be 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -54,6 +54,7 @@ from pylot.core.util.defaults import FILTERDEFAULTS, COMPNAME_MAP, \ from pylot.core.util.errors import FormatError, DatastructureError, \ OverwriteError from pylot.core.util.connection import checkurl +from pylot.core.util.dataprocessing import read_metadata from pylot.core.util.utils import fnConstructor, getLogin, \ full_range from pylot.core.io.location import create_creation_info, create_event @@ -987,6 +988,7 @@ class MainWindow(QMainWindow): if ans == QMessageBox.Yes: settings.setValue("inventoryFile", fninv) settings.sync() + metadata = read_metadata(fninv) for a in o.arrivals: if a.phase in 'sS': continue @@ -997,12 +999,14 @@ class MainWindow(QMainWindow): continue onset = pick.time dist = degrees2kilometers(a.distance) - w0, fc = calcsourcespec(wf, onset, fninv, self.inputs.get('vp'), dist, + w0, fc = calcsourcespec(wf, onset, metadata, self.inputs.get('vp'), dist, a.azimuth, a.takeoff_angle, self.inputs.get('Qp'), 0) if w0 is None or fc is None: continue - station_mag = calcMoMw(wf, w0, 2700., 3000., dist, fninv) + station_mag = calcMoMw(wf, w0, self.inputs.get('rho'), self.inputs.get('vp'), + dist, + fninv) mags[station] = station_mag mag = np.median([M[1] for M in mags.values()]) # give some information on the processing From 777941b66968dab5b62189c07325da08ae6e0ce9 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Wed, 21 Sep 2016 10:13:25 +0200 Subject: [PATCH 2/3] [fix] corrected docstring for new signature --- pylot/core/analysis/magnitude.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index ad54b138..dc894f67 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -321,8 +321,9 @@ def calcsourcespec(wfstream, onset, metadata, vp, delta, azimuth, incidence, :param: onset, P-phase onset time :type: float - :param: inventory, path/name of inventory or dataless-SEED file - :type: string + :param: metadata, tuple or list containing type of inventory and either + list of files or inventory object + :type: tuple or list :param: vp, Vp-wave velocity :type: float From ca7ce5f13c4c4968f2686743c698d5539f0c2e88 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Wed, 21 Sep 2016 10:27:47 +0200 Subject: [PATCH 3/3] [change] signature of calcMoMw changed; renamed getinvdir to get_metadata removed an unused remnant parameter invdir from definition of calcMoMw; method getinvdir from Magnitude class has been renamed and modified and returns now the metadata information and not only the inventory directory --- QtPyLoT.py | 5 ++--- pylot/core/analysis/magnitude.py | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 90ae45be..ef494399 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1004,9 +1004,8 @@ class MainWindow(QMainWindow): self.inputs.get('Qp'), 0) if w0 is None or fc is None: continue - station_mag = calcMoMw(wf, w0, self.inputs.get('rho'), self.inputs.get('vp'), - dist, - fninv) + station_mag = calcMoMw(wf, w0, self.inputs.get('rho'), + self.inputs.get('vp'), dist) mags[station] = station_mag mag = np.median([M[1] for M in mags.values()]) # give some information on the processing diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index dc894f67..b65c9ab2 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -14,7 +14,7 @@ from pylot.core.util.utils import getPatternLine from scipy.optimize import curve_fit from scipy import integrate, signal from pylot.core.io.data import Data -from pylot.core.util.dataprocessing import restitute_data +from pylot.core.util.dataprocessing import restitute_data, read_metadata from pylot.core.util.utils import common_range @@ -141,8 +141,8 @@ class Magnitude(object): def setinvdir(self, invdir): self.invdir = invdir - def getinvdir(self): - return self.invdir + def get_metadata(self): + return read_metadata(self.invdir) def getpicdic(self): return self.picdic @@ -243,7 +243,7 @@ class M0Mw(Magnitude): # call subfunction to estimate source spectrum # and to derive w0 and fc [w0, fc] = calcsourcespec(selwf, picks[key]['P']['mpp'], \ - self.getinvdir(), self.getvp(), delta, az, \ + self.get_metadata(), self.getvp(), delta, az, \ inc, self.getQp(), self.getiplot()) if w0 is not None: @@ -251,8 +251,8 @@ class M0Mw(Magnitude): zdat = selwf.select(component="Z") if len(zdat) == 0: # check for other components zdat = selwf.select(component="3") - [Mo, Mw] = calcMoMw(zdat, w0, self.getrho(), self.getvp(), \ - delta, self.getinvdir()) + [Mo, Mw] = calcMoMw(zdat, w0, self.getrho(), self.getvp(), + delta) else: Mo = None Mw = None @@ -265,7 +265,7 @@ class M0Mw(Magnitude): self.picdic = picks -def calcMoMw(wfstream, w0, rho, vp, delta, inv): +def calcMoMw(wfstream, w0, rho, vp, delta): ''' Subfunction of run_calcMoMw to calculate individual seismic moments and corresponding moment magnitudes.