Browse Source

refactored waveform overall amplitude constraint

whitelist
Sebastian Heimann 2 years ago
parent
commit
c0f7a8c027
5 changed files with 79 additions and 62 deletions
  1. +1
    -1
      setup.py
  2. +1
    -1
      src/targets/__init__.py
  3. +29
    -1
      src/targets/waveform/target.py
  4. +0
    -0
      src/targets/waveform_oac/__init__.py
  5. +48
    -59
      src/targets/waveform_oac/target.py

+ 1
- 1
setup.py View File

@ -15,7 +15,7 @@ setup(
'grond.targets',
'grond.targets.waveform',
'grond.targets.waveform_phase_ratio',
'grond.targets.waveform_piggyback',
'grond.targets.waveform_oac',
'grond.targets.satellite',
'grond.targets.gnss_campaign',
'grond.problems',


+ 1
- 1
src/targets/__init__.py View File

@ -1,6 +1,6 @@
from .base import * # noqa
from .waveform import * # noqa
from .waveform_phase_ratio import * # noqa
from .waveform_piggyback import * # noqa
from .waveform_oac import * # noqa
from .satellite import * # noqa
from .gnss_campaign import * # noqa

+ 29
- 1
src/targets/waveform/target.py View File

@ -11,7 +11,6 @@ from grond.dataset import NotFound
from grond.analysers.base import AnalyserResult
from ..base import (MisfitConfig, MisfitTarget, MisfitResult, TargetGroup)
from ..waveform_piggyback.target import WaveformPiggybackSubresult
guts_prefix = 'grond'
logger = logging.getLogger('grond.targets.waveform.target')
@ -206,6 +205,33 @@ class TraceSpectrum(Object):
return self.fmin + num.arange(self.ydata.size) * self.deltaf
class WaveformPiggybackSubtarget(Object):
piggy_id = Int.T()
_next_piggy_id = 0
@classmethod
def new_piggy_id(cls):
piggy_id = WaveformPiggybackSubtarget._next_piggy_id
WaveformPiggybackSubtarget._next_piggy_id += 1
return piggy_id
def __init__(self, piggy_id=None, **kwargs):
if piggy_id is None:
piggy_id = self.new_piggy_id()
Object.__init__(self, piggy_id=piggy_id, **kwargs)
def evaluate(
self, tr_proc_obs, trspec_proc_obs, tr_proc_syn, trspec_proc_syn):
raise NotImplemented()
class WaveformPiggybackSubresult(Object):
piggy_id = Int.T()
class WaveformMisfitResult(gf.Result, MisfitResult):
'''Carries the observations for a target and corresponding synthetics.
@ -650,4 +676,6 @@ __all__ = '''
WaveformMisfitConfig
WaveformMisfitTarget
WaveformMisfitResult
WaveformPiggybackSubtarget
WaveformPiggybackSubresult
'''.split()

src/targets/waveform_piggyback/__init__.py → src/targets/waveform_oac/__init__.py View File


src/targets/waveform_piggyback/target.py → src/targets/waveform_oac/target.py View File

@ -2,40 +2,20 @@ import logging
import numpy as num
from pyrocko.guts import Float, Object, Int
from pyrocko.guts import Float, Int
from pyrocko import gf
from ..base import (
MisfitTarget, TargetGroup, MisfitResult)
from ..waveform.target import WaveformPiggybackSubtarget, \
WaveformPiggybackSubresult
guts_prefix = 'grond'
logger = logging.getLogger('grond.targets.waveform_piggyback.target')
class WaveformPiggybackTargetGroup(TargetGroup):
associated_path = gf.StringID.T()
norm_exponent = Int.T(default=2)
def get_targets(self, ds, event, default_path):
logger.debug('Selecting waveform piggyback targets...')
target = WaveformPiggybackTarget(
path=self.path,
norm_exponent=self.norm_exponent,
associated_path=self.associated_path)
return [target]
class WaveformPiggybackSubresult(Object):
piggy_id = Int.T()
amplitude_obs = Float.T()
amplitude_syn = Float.T()
class WaveformPiggybackSubtarget(Object):
piggy_id = Int.T()
class WOACSubtarget(WaveformPiggybackSubtarget):
def evaluate(
self, tr_proc_obs, trspec_proc_obs, tr_proc_syn, trspec_proc_syn):
@ -43,7 +23,7 @@ class WaveformPiggybackSubtarget(Object):
a_obs = num.sqrt(num.mean(num.abs(tr_proc_obs.ydata**2)))
a_syn = num.sqrt(num.mean(num.abs(tr_proc_syn.ydata**2)))
res = WaveformPiggybackSubresult(
res = WOACSubresult(
piggy_id=self.piggy_id,
amplitude_obs=float(a_obs),
amplitude_syn=float(a_syn))
@ -51,26 +31,34 @@ class WaveformPiggybackSubtarget(Object):
return res
class WaveformPiggybackMisfitResult(MisfitResult):
pass
class WOACSubresult(WaveformPiggybackSubresult):
amplitude_obs = Float.T()
amplitude_syn = Float.T()
class WaveformPiggybackTarget(MisfitTarget):
class WaveformOverallAmplitudeConstraint(TargetGroup):
associated_path = gf.StringID.T()
norm_exponent = Int.T(default=2)
_next_piggy_id = 0
def get_targets(self, ds, event, default_path):
logger.debug('Selecting waveform piggyback targets...')
target = WOACTarget(
path=self.path,
norm_exponent=self.norm_exponent,
associated_path=self.associated_path)
return [target]
class WOACTarget(MisfitTarget):
associated_path = gf.StringID.T()
norm_exponent = Int.T(default=2)
def __init__(self, **kwargs):
MisfitTarget.__init__(self, **kwargs)
self.piggy_ids = set()
@classmethod
def new_piggy_id(cls):
piggy_id = cls._next_piggy_id
cls._next_piggy_id += 1
return piggy_id
def string_id(self):
return self.path
@ -87,14 +75,9 @@ class WaveformPiggybackTarget(MisfitTarget):
if isinstance(target, WaveformMisfitTarget) \
and target.path == self.associated_path:
piggy_id = self.new_piggy_id()
self.piggy_ids.add(piggy_id)
target.add_piggyback_subtarget(
WaveformPiggybackSubtarget(
piggy_id=piggy_id))
st = WOACSubtarget()
self.piggy_ids.add(st.piggy_id)
target.add_piggyback_subtarget(st)
relevant.append(target)
return relevant
@ -103,35 +86,41 @@ class WaveformPiggybackTarget(MisfitTarget):
self, engine, source, modelling_targets, modelling_results):
from ..waveform.target import WaveformMisfitResult
amps_obs = []
amps_syn = []
amps = []
for mtarget, mresult in zip(modelling_targets, modelling_results):
if isinstance(mresult, WaveformMisfitResult):
for sr in mresult.piggyback_subresults:
for sr in list(mresult.piggyback_subresults):
try:
self.piggy_ids.remove(sr.piggy_id)
amps_obs.append(sr.amplitude_obs)
amps_syn.append(sr.amplitude_syn)
amps.append((sr.amplitude_obs, sr.amplitude_syn))
mresult.piggyback_subresults.remove(sr)
except KeyError:
logger.error(
'found inconsistency while gathering piggyback '
'results')
pass
amps_obs = num.array(amps_obs)
amps_syn = num.array(amps_syn)
amps = num.array(amps, dtype=num.float)
mask = num.all(num.isfinite(amps), axis=1)
amp_obs = num.median(amps_obs[num.isfinite(amps_obs)])
amp_syn = num.median(amps_syn[num.isfinite(amps_syn)])
amp_obs = num.median(amps[mask, 0])
amp_syn = num.median(amps[mask, 1])
m = num.abs(num.log(amp_obs / amp_syn))**self.norm_exponent
result = WaveformPiggybackMisfitResult(
result = WOACMisfitResult(
misfits=num.array([[m, 1.]], dtype=num.float))
return result
class WOACMisfitResult(MisfitResult):
pass
__all__ = '''
WaveformPiggybackTargetGroup
WaveformPiggybackTarget
WaveformPiggybackMisfitResult
WaveformPiggybackSubtarget
WaveformPiggybackSubresult
WOACSubtarget
WOACSubresult
WaveformOverallAmplitudeConstraint
WOACTarget
WOACMisfitResult
'''.split()

Loading…
Cancel
Save