From 71876638c8811743f81868f0b1cd722c5d10195c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Thu, 22 Jun 2017 15:04:16 +0200 Subject: [PATCH 1/3] Flexible calculation of local magnitude including station magntiude scaling as well as network magnitude scaling. auoPyLot-output-file names have prefix event ID. --- autoPyLoT.py | 38 +++++++++++++++----------- pylot/RELEASE-VERSION | 2 +- pylot/core/analysis/magnitude.py | 41 ++++++++++++++++++----------- pylot/core/io/default_parameters.py | 10 ++++--- 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index 66db76a6..db3a83f6 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -18,7 +18,7 @@ import pylot.core.loc.nll as nll #from PySide.QtGui import QWidget, QInputDialog from pylot.core.analysis.magnitude import MomentMagnitude, LocalMagnitude from pylot.core.io.data import Data -from pylot.core.io.inputs import PylotParameter +from pylot.core.io.inputs import AutoPickParameter from pylot.core.pick.autopick import autopickevent, iteratepicker from pylot.core.util.dataprocessing import restitute_data, read_metadata, \ remove_underscores @@ -35,7 +35,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even :param inputfile: path to the input file containing all parameter information for automatic picking (for formatting details, see. - `~pylot.core.io.inputs.PylotParameter` + `~pylot.core.io.inputs.AutoPickParameter` :type inputfile: str :return: @@ -71,13 +71,13 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even if not parameter: if inputfile: - parameter = PylotParameter(inputfile) + parameter = AutoPickParameter(inputfile) iplot = parameter['iplot'] else: print('No parameters set and no input file given. Choose either of both.') return else: - if not type(parameter) == PylotParameter: + if not type(parameter) == AutoPickParameter: print('Wrong input type for parameter: {}'.format(type(parameter))) return if inputfile: @@ -252,12 +252,17 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even for station, props in moment_mag.moment_props.items(): picks[station]['P'].update(props) evt = moment_mag.updated_event() + net_mw = moment_mag.net_magnitude() + print("Network moment magnitude: %4.1f" % net_mw.mag) + # calculate local (Richter) magntiude local_mag = LocalMagnitude(corr_dat, evt, parameter.get('sstop'), parameter.get('WAscaling'), \ True, iplot) for station, amplitude in local_mag.amplitudes.items(): picks[station]['S']['Ao'] = amplitude.generic_amplitude - evt = local_mag.updated_event() + evt = local_mag.updated_event(parameter.get('magscaling')) + net_ml = local_mag.net_magnitude() + print("Network local magnitude: %4.1f" % net_ml.mag) else: print("autoPyLoT: No NLLoc-location file available!") print("No source parameter estimation possible!") @@ -310,14 +315,17 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even for station, props in moment_mag.moment_props.items(): picks[station]['P'].update(props) evt = moment_mag.updated_event() + net_mw = moment_mag.net_magnitude() + print("Network moment magnitude: %4.1f" % net_mw.mag) + # calculate local (Richter) magntiude local_mag = LocalMagnitude(corr_dat, evt, parameter.get('sstop'), parameter.get('WAscaling'), \ True, iplot) for station, amplitude in local_mag.amplitudes.items(): picks[station]['S']['Ao'] = amplitude.generic_amplitude - evt = local_mag.updated_event() - net_mw = moment_mag.net_magnitude() - print("Network moment magnitude: %4.1f" % net_mw.mag) + evt = local_mag.updated_event(parameter.get('magscaling')) + net_ml = local_mag.net_magnitude(parameter.get('magscaling')) + print("Network local magnitude: %4.1f" % net_ml.mag) else: print("autoPyLoT: No NLLoc-location file available! Stop iteration!") locflag = 9 @@ -328,26 +336,26 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even data.applyEVTData(picks) if evt is not None: data.applyEVTData(evt, 'event') - fnqml = '%s/autoPyLoT' % event + fnqml = '%s/picks_%s' % (event, evID) data.exportEvent(fnqml) # HYPO71 - hypo71file = '%s/autoPyLoT_HYPO71_phases' % event + hypo71file = '%s/%s_HYPO71_phases' % (event, evID) hypo71.export(picks, hypo71file, parameter) # HYPOSAT - hyposatfile = '%s/autoPyLoT_HYPOSAT_phases' % event + hyposatfile = '%s/%s_HYPOSAT_phases' % (event, evID) hyposat.export(picks, hyposatfile, parameter) if locflag == 1: # VELEST - velestfile = '%s/autoPyLoT_VELEST_phases.cnv' % event + velestfile = '%s/%s_VELEST_phases.cnv' % (event, evID) velest.export(picks, velestfile, parameter, evt) # hypoDD - hypoddfile = '%s/autoPyLoT_hypoDD_phases.pha' % event + hypoddfile = '%s/%s_hypoDD_phases.pha' % (event, evID) hypodd.export(picks, hypoddfile, parameter, evt) # FOCMEC - focmecfile = '%s/autoPyLoT_FOCMEC.in' % event + focmecfile = '%s/%s_FOCMEC.in' % (event, evID) focmec.export(picks, focmecfile, parameter, evt) # HASH - hashfile = '%s/autoPyLoT_HASH' % event + hashfile = '%s/%s_HASH' % (event, evID) hash.export(picks, hashfile, parameter, evt) endsplash = '''------------------------------------------\n' diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index 6bf29797..31812905 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -f91e1-dirty +8e8b-dirty diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index ff4dca18..867a302d 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- """ Created autumn/winter 2015. +Revised/extended summer 2017. :author: Ludger Küperkoch / MAGS2 EP3 working group """ @@ -115,23 +116,30 @@ class Magnitude(object): def calc(self): pass - def updated_event(self): - self.event.magnitudes.append(self.net_magnitude()) + def updated_event(self, magscaling=None): + self.event.magnitudes.append(self.net_magnitude(magscaling)) return self.event - def net_magnitude(self): + def net_magnitude(self, magscaling=None): if self: - # TODO if an average Magnitude instead of the median is calculated - # StationMagnitudeContributions should be added to the returned - # Magnitude object - # mag_error => weights (magnitude error estimate from peak_to_peak, calcsourcespec?) - # weights => StationMagnitdeContribution - mag = ope.Magnitude( - mag=np.median([M.mag for M in self.magnitudes.values()]), - magnitude_type=self.type, - origin_id=self.origin_id, - station_count=len(self.magnitudes), - azimuthal_gap=self.origin_id.get_referred_object().quality.azimuthal_gap) + if magscaling is not None and str(magscaling) is not '[0.0, 0.0]': + # scaling necessary + print("Scaling network magnitude ...") + mag = ope.Magnitude( + mag=np.median([M.mag for M in self.magnitudes.values()]) *\ + magscaling[0] + magscaling[1], + magnitude_type=self.type, + origin_id=self.origin_id, + station_count=len(self.magnitudes), + azimuthal_gap=self.origin_id.get_referred_object().quality.azimuthal_gap) + else: + # no saling necessary + mag = ope.Magnitude( + mag=np.median([M.mag for M in self.magnitudes.values()]), + magnitude_type=self.type, + origin_id=self.origin_id, + station_count=len(self.magnitudes), + azimuthal_gap=self.origin_id.get_referred_object().quality.azimuthal_gap) return mag return None @@ -153,7 +161,7 @@ class LocalMagnitude(Magnitude): _amplitudes = dict() - def __init__(self, stream, event, calc_win, wascaling=None, verbosity=False, iplot=0): + def __init__(self, stream, event, calc_win, wascaling, verbosity=False, iplot=0): super(LocalMagnitude, self).__init__(stream, event, verbosity, iplot) self._calc_win = calc_win @@ -257,12 +265,13 @@ class LocalMagnitude(Magnitude): self.amplitudes = (station, amplitude) # using standard Gutenberg-Richter relation # or scale WA amplitude with given scaling relation - if self.wascaling == None: + if str(self.wascaling) == '[0.0, 0.0, 0.0]': print("Calculating original Richter magnitude ...") magnitude = ope.StationMagnitude(mag=np.log10(a0) \ + richter_magnitude_scaling(delta)) else: print("Calculating scaled local magnitude ...") + a0 = a0 * 1e03 # mm to nm (see Havskov & Ottemöller, 2010) magnitude = ope.StationMagnitude(mag=np.log10(a0) \ + self.wascaling[0] * np.log10(delta) + self.wascaling[1] * delta + self.wascaling[2]) diff --git a/pylot/core/io/default_parameters.py b/pylot/core/io/default_parameters.py index 93d55ae4..22d0268b 100644 --- a/pylot/core/io/default_parameters.py +++ b/pylot/core/io/default_parameters.py @@ -278,12 +278,14 @@ defaults = {'rootpath': {'type': str, 'value': 1.0}, 'WAscaling': {'type': (float, float, float), - 'tooltip': 'Scaling relation (log(Ao)+Alog(r)+Br+C) of Wood-Anderson amplitude Ao [nm]', - 'value': (1.0, 1.0, 1.0)}, + 'tooltip': 'Scaling relation (log(Ao)+Alog(r)+Br+C) of Wood-Anderson amplitude Ao [nm] \ + If zeros are set, original Richter magnitude is calculated!', + 'value': (0., 0., 0.)}, 'magscaling': {'type': (float, float), - 'tooltip': 'Scaling relation for derived local magnitude [a*Ml+b]', - 'value': (1.0, 1.0)} + 'tooltip': 'Scaling relation for derived local magnitude [a*Ml+b]. \ + If zeros are set, no scaling is of network magnitude is applied.', + 'value': (0., 0.)} } settings_main={ From 9f9d492b8b92bd997408c69c6685fbc711d5cab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Thu, 22 Jun 2017 15:09:40 +0200 Subject: [PATCH 2/3] Restored former changes of Marcel (AutoPickParameter - PyLoTParameter). --- autoPyLoT.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index db3a83f6..41db89ca 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -18,7 +18,7 @@ import pylot.core.loc.nll as nll #from PySide.QtGui import QWidget, QInputDialog from pylot.core.analysis.magnitude import MomentMagnitude, LocalMagnitude from pylot.core.io.data import Data -from pylot.core.io.inputs import AutoPickParameter +from pylot.core.io.inputs import PyLoTParameter from pylot.core.pick.autopick import autopickevent, iteratepicker from pylot.core.util.dataprocessing import restitute_data, read_metadata, \ remove_underscores @@ -35,7 +35,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even :param inputfile: path to the input file containing all parameter information for automatic picking (for formatting details, see. - `~pylot.core.io.inputs.AutoPickParameter` + `~pylot.core.io.inputs.PyLoTParameter` :type inputfile: str :return: @@ -71,13 +71,13 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even if not parameter: if inputfile: - parameter = AutoPickParameter(inputfile) + parameter = PyLoTParameter(inputfile) iplot = parameter['iplot'] else: print('No parameters set and no input file given. Choose either of both.') return else: - if not type(parameter) == AutoPickParameter: + if not type(parameter) == PyLoTParameter: print('Wrong input type for parameter: {}'.format(type(parameter))) return if inputfile: From 33d81eb5382af7ca207e94ed7758ffe651987a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Thu, 22 Jun 2017 15:18:19 +0200 Subject: [PATCH 3/3] Bugfix: Wrong naming of module in previous commit: PyLoTParameter - PylotParameter. --- autoPyLoT.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index 41db89ca..7841487d 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -18,7 +18,7 @@ import pylot.core.loc.nll as nll #from PySide.QtGui import QWidget, QInputDialog from pylot.core.analysis.magnitude import MomentMagnitude, LocalMagnitude from pylot.core.io.data import Data -from pylot.core.io.inputs import PyLoTParameter +from pylot.core.io.inputs import PylotParameter from pylot.core.pick.autopick import autopickevent, iteratepicker from pylot.core.util.dataprocessing import restitute_data, read_metadata, \ remove_underscores @@ -35,7 +35,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even :param inputfile: path to the input file containing all parameter information for automatic picking (for formatting details, see. - `~pylot.core.io.inputs.PyLoTParameter` + `~pylot.core.io.inputs.PylotParameter` :type inputfile: str :return: @@ -71,13 +71,13 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even if not parameter: if inputfile: - parameter = PyLoTParameter(inputfile) + parameter = PylotParameter(inputfile) iplot = parameter['iplot'] else: print('No parameters set and no input file given. Choose either of both.') return else: - if not type(parameter) == PyLoTParameter: + if not type(parameter) == PylotParameter: print('Wrong input type for parameter: {}'.format(type(parameter))) return if inputfile: