Flexible calculation of local magnitude including station magntiude scaling as well as network magnitude scaling.

auoPyLot-output-file names have prefix event ID.
This commit is contained in:
Ludger Küperkoch 2017-06-22 15:04:16 +02:00
parent 8e8b3e0462
commit 71876638c8
4 changed files with 55 additions and 36 deletions

View File

@ -18,7 +18,7 @@ import pylot.core.loc.nll as nll
#from PySide.QtGui import QWidget, QInputDialog #from PySide.QtGui import QWidget, QInputDialog
from pylot.core.analysis.magnitude import MomentMagnitude, LocalMagnitude from pylot.core.analysis.magnitude import MomentMagnitude, LocalMagnitude
from pylot.core.io.data import Data 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.pick.autopick import autopickevent, iteratepicker
from pylot.core.util.dataprocessing import restitute_data, read_metadata, \ from pylot.core.util.dataprocessing import restitute_data, read_metadata, \
remove_underscores 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 :param inputfile: path to the input file containing all parameter
information for automatic picking (for formatting details, see. information for automatic picking (for formatting details, see.
`~pylot.core.io.inputs.PylotParameter` `~pylot.core.io.inputs.AutoPickParameter`
:type inputfile: str :type inputfile: str
:return: :return:
@ -71,13 +71,13 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
if not parameter: if not parameter:
if inputfile: if inputfile:
parameter = PylotParameter(inputfile) parameter = AutoPickParameter(inputfile)
iplot = parameter['iplot'] iplot = parameter['iplot']
else: else:
print('No parameters set and no input file given. Choose either of both.') print('No parameters set and no input file given. Choose either of both.')
return return
else: else:
if not type(parameter) == PylotParameter: if not type(parameter) == AutoPickParameter:
print('Wrong input type for parameter: {}'.format(type(parameter))) print('Wrong input type for parameter: {}'.format(type(parameter)))
return return
if inputfile: 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(): for station, props in moment_mag.moment_props.items():
picks[station]['P'].update(props) picks[station]['P'].update(props)
evt = moment_mag.updated_event() 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, local_mag = LocalMagnitude(corr_dat, evt,
parameter.get('sstop'), parameter.get('WAscaling'), \ parameter.get('sstop'), parameter.get('WAscaling'), \
True, iplot) True, iplot)
for station, amplitude in local_mag.amplitudes.items(): for station, amplitude in local_mag.amplitudes.items():
picks[station]['S']['Ao'] = amplitude.generic_amplitude 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: else:
print("autoPyLoT: No NLLoc-location file available!") print("autoPyLoT: No NLLoc-location file available!")
print("No source parameter estimation possible!") 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(): for station, props in moment_mag.moment_props.items():
picks[station]['P'].update(props) picks[station]['P'].update(props)
evt = moment_mag.updated_event() 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, local_mag = LocalMagnitude(corr_dat, evt,
parameter.get('sstop'), parameter.get('WAscaling'), \ parameter.get('sstop'), parameter.get('WAscaling'), \
True, iplot) True, iplot)
for station, amplitude in local_mag.amplitudes.items(): for station, amplitude in local_mag.amplitudes.items():
picks[station]['S']['Ao'] = amplitude.generic_amplitude picks[station]['S']['Ao'] = amplitude.generic_amplitude
evt = local_mag.updated_event() evt = local_mag.updated_event(parameter.get('magscaling'))
net_mw = moment_mag.net_magnitude() net_ml = local_mag.net_magnitude(parameter.get('magscaling'))
print("Network moment magnitude: %4.1f" % net_mw.mag) print("Network local magnitude: %4.1f" % net_ml.mag)
else: else:
print("autoPyLoT: No NLLoc-location file available! Stop iteration!") print("autoPyLoT: No NLLoc-location file available! Stop iteration!")
locflag = 9 locflag = 9
@ -328,26 +336,26 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
data.applyEVTData(picks) data.applyEVTData(picks)
if evt is not None: if evt is not None:
data.applyEVTData(evt, 'event') data.applyEVTData(evt, 'event')
fnqml = '%s/autoPyLoT' % event fnqml = '%s/picks_%s' % (event, evID)
data.exportEvent(fnqml) data.exportEvent(fnqml)
# HYPO71 # HYPO71
hypo71file = '%s/autoPyLoT_HYPO71_phases' % event hypo71file = '%s/%s_HYPO71_phases' % (event, evID)
hypo71.export(picks, hypo71file, parameter) hypo71.export(picks, hypo71file, parameter)
# HYPOSAT # HYPOSAT
hyposatfile = '%s/autoPyLoT_HYPOSAT_phases' % event hyposatfile = '%s/%s_HYPOSAT_phases' % (event, evID)
hyposat.export(picks, hyposatfile, parameter) hyposat.export(picks, hyposatfile, parameter)
if locflag == 1: if locflag == 1:
# VELEST # VELEST
velestfile = '%s/autoPyLoT_VELEST_phases.cnv' % event velestfile = '%s/%s_VELEST_phases.cnv' % (event, evID)
velest.export(picks, velestfile, parameter, evt) velest.export(picks, velestfile, parameter, evt)
# hypoDD # hypoDD
hypoddfile = '%s/autoPyLoT_hypoDD_phases.pha' % event hypoddfile = '%s/%s_hypoDD_phases.pha' % (event, evID)
hypodd.export(picks, hypoddfile, parameter, evt) hypodd.export(picks, hypoddfile, parameter, evt)
# FOCMEC # FOCMEC
focmecfile = '%s/autoPyLoT_FOCMEC.in' % event focmecfile = '%s/%s_FOCMEC.in' % (event, evID)
focmec.export(picks, focmecfile, parameter, evt) focmec.export(picks, focmecfile, parameter, evt)
# HASH # HASH
hashfile = '%s/autoPyLoT_HASH' % event hashfile = '%s/%s_HASH' % (event, evID)
hash.export(picks, hashfile, parameter, evt) hash.export(picks, hashfile, parameter, evt)
endsplash = '''------------------------------------------\n' endsplash = '''------------------------------------------\n'

View File

@ -1 +1 @@
f91e1-dirty 8e8b-dirty

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created autumn/winter 2015. Created autumn/winter 2015.
Revised/extended summer 2017.
:author: Ludger Küperkoch / MAGS2 EP3 working group :author: Ludger Küperkoch / MAGS2 EP3 working group
""" """
@ -115,23 +116,30 @@ class Magnitude(object):
def calc(self): def calc(self):
pass pass
def updated_event(self): def updated_event(self, magscaling=None):
self.event.magnitudes.append(self.net_magnitude()) self.event.magnitudes.append(self.net_magnitude(magscaling))
return self.event return self.event
def net_magnitude(self): def net_magnitude(self, magscaling=None):
if self: if self:
# TODO if an average Magnitude instead of the median is calculated if magscaling is not None and str(magscaling) is not '[0.0, 0.0]':
# StationMagnitudeContributions should be added to the returned # scaling necessary
# Magnitude object print("Scaling network magnitude ...")
# mag_error => weights (magnitude error estimate from peak_to_peak, calcsourcespec?) mag = ope.Magnitude(
# weights => StationMagnitdeContribution mag=np.median([M.mag for M in self.magnitudes.values()]) *\
mag = ope.Magnitude( magscaling[0] + magscaling[1],
mag=np.median([M.mag for M in self.magnitudes.values()]), magnitude_type=self.type,
magnitude_type=self.type, origin_id=self.origin_id,
origin_id=self.origin_id, station_count=len(self.magnitudes),
station_count=len(self.magnitudes), azimuthal_gap=self.origin_id.get_referred_object().quality.azimuthal_gap)
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 mag
return None return None
@ -153,7 +161,7 @@ class LocalMagnitude(Magnitude):
_amplitudes = dict() _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) super(LocalMagnitude, self).__init__(stream, event, verbosity, iplot)
self._calc_win = calc_win self._calc_win = calc_win
@ -257,12 +265,13 @@ class LocalMagnitude(Magnitude):
self.amplitudes = (station, amplitude) self.amplitudes = (station, amplitude)
# using standard Gutenberg-Richter relation # using standard Gutenberg-Richter relation
# or scale WA amplitude with given scaling 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 ...") print("Calculating original Richter magnitude ...")
magnitude = ope.StationMagnitude(mag=np.log10(a0) \ magnitude = ope.StationMagnitude(mag=np.log10(a0) \
+ richter_magnitude_scaling(delta)) + richter_magnitude_scaling(delta))
else: else:
print("Calculating scaled local magnitude ...") print("Calculating scaled local magnitude ...")
a0 = a0 * 1e03 # mm to nm (see Havskov & Ottemöller, 2010)
magnitude = ope.StationMagnitude(mag=np.log10(a0) \ magnitude = ope.StationMagnitude(mag=np.log10(a0) \
+ self.wascaling[0] * np.log10(delta) + self.wascaling[1] + self.wascaling[0] * np.log10(delta) + self.wascaling[1]
* delta + self.wascaling[2]) * delta + self.wascaling[2])

View File

@ -278,12 +278,14 @@ defaults = {'rootpath': {'type': str,
'value': 1.0}, 'value': 1.0},
'WAscaling': {'type': (float, float, float), 'WAscaling': {'type': (float, float, float),
'tooltip': 'Scaling relation (log(Ao)+Alog(r)+Br+C) of Wood-Anderson amplitude Ao [nm]', 'tooltip': 'Scaling relation (log(Ao)+Alog(r)+Br+C) of Wood-Anderson amplitude Ao [nm] \
'value': (1.0, 1.0, 1.0)}, If zeros are set, original Richter magnitude is calculated!',
'value': (0., 0., 0.)},
'magscaling': {'type': (float, float), 'magscaling': {'type': (float, float),
'tooltip': 'Scaling relation for derived local magnitude [a*Ml+b]', 'tooltip': 'Scaling relation for derived local magnitude [a*Ml+b]. \
'value': (1.0, 1.0)} If zeros are set, no scaling is of network magnitude is applied.',
'value': (0., 0.)}
} }
settings_main={ settings_main={