From 9f164fc075e4284b32e337a4e9237aca9b0a6330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 21 Jun 2017 16:42:26 +0200 Subject: [PATCH] Still in progress: flexible local magnitude estimation. --- autoPyLoT.py | 8 ++++---- pylot/core/analysis/magnitude.py | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index 2b571dac..a7d76002 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -253,8 +253,8 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even picks[station]['P'].update(props) evt = moment_mag.updated_event() local_mag = LocalMagnitude(corr_dat, evt, - parameter.get('sstop'), True,\ - iplot) + 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() @@ -311,8 +311,8 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even picks[station]['P'].update(props) evt = moment_mag.updated_event() local_mag = LocalMagnitude(corr_dat, evt, - parameter.get('sstop'), True, \ - iplot) + 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() diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index 88659cff..ff4dca18 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -38,10 +38,10 @@ class Magnitude(object): def __init__(self, stream, event, verbosity=False, iplot=0): self._type = "M" + self._stream = stream self._plot_flag = iplot self._verbosity = verbosity self._event = event - self._stream = stream self._magnitudes = dict() def __str__(self): @@ -153,10 +153,11 @@ class LocalMagnitude(Magnitude): _amplitudes = dict() - def __init__(self, stream, event, calc_win, verbosity=False, iplot=0): + def __init__(self, stream, event, calc_win, wascaling=None, verbosity=False, iplot=0): super(LocalMagnitude, self).__init__(stream, event, verbosity, iplot) self._calc_win = calc_win + self._wascaling = wascaling self._type = 'ML' self.calc() @@ -168,6 +169,10 @@ class LocalMagnitude(Magnitude): def calc_win(self, value): self._calc_win = value + @property + def wascaling(self): + return self._wascaling + @property def amplitudes(self): return self._amplitudes @@ -251,10 +256,16 @@ class LocalMagnitude(Magnitude): self.event.amplitudes.append(amplitude) self.amplitudes = (station, amplitude) # using standard Gutenberg-Richter relation - # TODO make the ML calculation more flexible by allowing - # use of custom relation functions - magnitude = ope.StationMagnitude( - mag=np.log10(a0) + richter_magnitude_scaling(delta)) + # or scale WA amplitude with given scaling relation + if self.wascaling == None: + print("Calculating original Richter magnitude ...") + magnitude = ope.StationMagnitude(mag=np.log10(a0) \ + + richter_magnitude_scaling(delta)) + else: + print("Calculating scaled local magnitude ...") + magnitude = ope.StationMagnitude(mag=np.log10(a0) \ + + self.wascaling[0] * np.log10(delta) + self.wascaling[1] + * delta + self.wascaling[2]) magnitude.origin_id = self.origin_id magnitude.waveform_id = pick.waveform_id magnitude.amplitude_id = amplitude.resource_id