Coverage for /usr/local/lib/python3.11/dist-packages/grond/problems/vlvd/problem.py: 57%
47 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-26 16:25 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-26 16:25 +0000
1import logging
3from pyrocko import gf, util
4from pyrocko.guts import String, Float, Dict
6from grond.meta import expand_template, Parameter, \
7 has_get_plot_classes
9from ..base import Problem, ProblemConfig
11guts_prefix = 'grond'
12logger = logging.getLogger('grond.problems.volume_point')
13km = 1e3
14as_km = dict(scale_factor=km, scale_unit='km')
15as_km3 = dict(scale_factor=km**3, scale_unit='km^3')
18class VLVDProblemConfig(ProblemConfig):
19 ranges = Dict.T(String.T(), gf.Range.T())
20 distance_min = Float.T(default=0.0)
22 def get_problem(self, event, target_groups, targets):
23 self.check_deprecations()
24 if event.depth is None:
25 event.depth = 0.
27 base_source = gf.VLVDSource.from_pyrocko_event(event)
28 base_source.stf = gf.HalfSinusoidSTF(duration=event.duration or 0.0)
30 subs = dict(
31 event_name=event.name,
32 event_time=util.time_to_str(event.time))
34 problem = VLVDProblem(
35 name=expand_template(self.name_template, subs),
36 base_source=base_source,
37 target_groups=target_groups,
38 targets=targets,
39 ranges=self.ranges,
40 distance_min=self.distance_min,
41 norm_exponent=self.norm_exponent)
43 return problem
46@has_get_plot_classes
47class VLVDProblem(Problem):
49 problem_parameters = [
50 Parameter('north_shift', 'm', label='Northing', **as_km),
51 Parameter('east_shift', 'm', label='Easting', **as_km),
52 Parameter('depth', 'm', label='Depth', **as_km),
54 Parameter('dip', 'deg', label='Dip'),
55 Parameter('azimuth', 'deg', label='Azimuth'),
56 Parameter('clvd_moment', 'Nm', label='CLVD Moment'),
57 Parameter('volume_change', 'm^3', label='Volume Change', **as_km3),
59 ]
61 problem_waveform_parameters = [
62 Parameter('time', 's', label='Time'),
63 Parameter('duration', 's', label='Duration')
64 ]
66 distance_min = Float.T(default=0.0)
68 def pack(self, source):
69 arr = self.get_parameter_array(source)
70 for ip, p in enumerate(self.parameters):
71 if p.name == 'time':
72 arr[ip] -= self.base_source.time
73 return arr
75 def get_source(self, x):
76 d = self.get_parameter_dict(x)
78 p = {k: float(self.ranges[k].make_relative(self.base_source[k], d[k]))
79 for k in self.base_source.keys() if k in d}
81 stf = None
82 if self.has_waveforms:
83 stf = gf.HalfSinusoidSTF(duration=float(d.duration))
85 source = self.base_source.clone(stf=stf, **p)
86 return source
88 @classmethod
89 def get_plot_classes(cls):
90 from . import plot
91 plots = super(VLVDProblem, cls).get_plot_classes()
92 plots.extend([plot.VLVDLocationPlot])
93 return plots