Browse Source

give proper error message when phase does not exist for given geometry

dev-scenario
Sebastian Heimann 1 year ago
committed by Sebastian Heimann
parent
commit
a0586fa7ab
  1. 5
      src/analysers/noise_analyser/analyser.py
  2. 34
      src/meta.py
  3. 3
      src/qc.py
  4. 6
      src/targets/waveform/target.py
  5. 7
      src/targets/waveform_phase_ratio/measure.py
  6. 2
      test/test_optimiser.py

5
src/analysers/noise_analyser/analyser.py

@ -7,6 +7,7 @@ from pyrocko.guts import Int, Bool, Float, String, StringChoice
from pyrocko.gf.meta import OutOfBounds
from ..base import Analyser, AnalyserConfig, AnalyserResult
from grond.dataset import NotFound
from grond.meta import store_t
logger = logging.getLogger('grond.analysers.NoiseAnalyser')
@ -35,9 +36,7 @@ def get_phase_arrival_time(engine, source, target, wavename):
scalar, float of the arrival time of the wave
"""
store = engine.get_store(target.store_id)
dist = target.distance_to(source)
depth = source.depth
return store.t(wavename, (depth, dist)) + source.time
return store_t(store, wavename, source, target) + source.time
def seismic_noise_variance(traces, engine, source, targets,

34
src/meta.py

@ -5,7 +5,7 @@ import numpy as num
import os.path as op
from string import Template
from pyrocko.guts import Object, String, Float, Unicode, StringPattern, Bool
from pyrocko import util
from pyrocko import util, gf
guts_prefix = 'grond'
@ -136,6 +136,35 @@ class GrondError(Exception):
pass
class PhaseMissContext(Object):
store_id = gf.StringID.T()
timing = gf.Timing.T()
source = gf.Source.T()
target = gf.Target.T()
class PhaseMissError(GrondError):
def __init__(self, store_id, timing, source, target):
GrondError.__init__(self)
self._context = PhaseMissContext(
store_id=store_id,
timing=timing,
source=source,
target=target)
def __str__(self):
return 'Phase not available for given geometry. Context:\n%s' \
% self._context
def store_t(store, tdef, source, target):
tt = store.t(tdef, source, target)
if tt is None:
raise PhaseMissError(store.config.id, tdef, source, target)
return tt
def expand_template(template, d):
try:
return Template(template).substitute(d)
@ -431,6 +460,9 @@ def selected(expression, data, types):
__all__ = '''
Forbidden
GrondError
PhaseMissContext
PhaseMissError
store_t
Path
HasPaths
Parameter

3
src/qc.py

@ -8,6 +8,7 @@ from mpl_toolkits.axes_grid1 import ImageGrid
from pyrocko import gf, orthodrome as od, plot, model, trace
from grond import dataset
from grond.meta import store_t
km = 1000.
@ -71,7 +72,7 @@ def polarization(
continue
if nsl_to_time is None:
tp = event.time + store.t(timing, source, station)
tp = event.time + store_t(store, timing, source, station)
else:
if nsl not in nsl_to_time:

6
src/targets/waveform/target.py

@ -10,7 +10,7 @@ from pyrocko.guts import (Object, String, Float, Bool, Int, StringChoice,
from pyrocko.guts_array import Array
from grond.dataset import NotFound
from grond.meta import GrondError, nslcs_to_patterns
from grond.meta import GrondError, store_t, nslcs_to_patterns
from ..base import (MisfitConfig, MisfitTarget, MisfitResult, TargetGroup)
from grond.meta import has_get_plot_classes
@ -404,8 +404,8 @@ class WaveformMisfitTarget(gf.Target, MisfitTarget):
def get_taper_params(self, engine, source):
store = engine.get_store(self.store_id)
config = self.misfit_config
tmin_fit = source.time + store.t(config.tmin, source, self)
tmax_fit = source.time + store.t(config.tmax, source, self)
tmin_fit = source.time + store_t(store, config.tmin, source, self)
tmax_fit = source.time + store_t(store, config.tmax, source, self)
if config.fmin > 0.0:
tfade = 1.0/config.fmin
else:

7
src/targets/waveform_phase_ratio/measure.py

@ -2,6 +2,7 @@ import numpy as num
from pyrocko import gf, trace
from pyrocko.guts import Object, Float, StringChoice, List, String
from pyrocko.gui import marker
from grond.meta import store_t
guts_prefix = 'grond'
@ -131,8 +132,10 @@ class FeatureMeasure(Object):
store = engine.get_store(target.store_id)
tmin = source.time + store.t(self.timing_tmin, source, target)
tmax = source.time + store.t(self.timing_tmax, source, target)
tmin = source.time + store_t(
store, self.timing_tmin, source, target)
tmax = source.time + store_t(
store, self.timing_tmax, source, target)
if self.fmin is not None and self.fmax is not None:
freqlimits = [

2
test/test_optimiser.py

@ -3,7 +3,7 @@ from __future__ import absolute_import
import glob
from .common import grond, run_in_project
from grond import config
from grond import config, check
def test_starting_point():

Loading…
Cancel
Save