Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/scenario/sources/rectangularsource.py: 85%
41 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 15:01 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 15:01 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Rectangular fault random source generator.
8'''
10import numpy as num
12from pyrocko.guts import Float, Int
13from pyrocko import moment_tensor, gf, util
15from .base import SourceGenerator
17km = 1e3
18guts_prefix = 'pf.scenario'
21class RectangularSourceGenerator(SourceGenerator):
22 depth_min = Float.T(
23 default=0.0)
24 depth_max = Float.T(
25 default=5*km)
26 decimation_factor = Int.T(
27 default=4)
29 strike = Float.T(
30 optional=True)
31 dip = Float.T(
32 optional=True)
33 rake = Float.T(
34 optional=True)
35 depth = Float.T(
36 optional=True)
38 width = Float.T(
39 optional=True)
40 length = Float.T(
41 optional=True)
43 def get_source(self, ievent):
44 rstate = self.get_rstate(ievent)
45 time = self.time_min + rstate.uniform(
46 0., float(self.time_max - self.time_min)) # hptime aware
47 lat, lon = self.get_latlon(ievent)
48 depth = rstate.uniform(self.depth_min, self.depth_max)
50 magnitude = self.draw_magnitude(rstate)
51 moment = moment_tensor.magnitude_to_moment(magnitude)
53 # After Mai and Beroza (2000)
54 length = num.exp(-6.27 + 0.4*num.log(moment))
55 width = num.exp(-4.24 + 0.32*num.log(moment))
57 length = length if not self.length else self.length
58 width = width if not self.width else self.width
59 depth = depth if not self.depth else self.depth
61 if self.strike is None and self.dip is None and self.rake is None:
62 strike, rake = rstate.uniform(-180., 180., 2)
63 dip = rstate.uniform(0., 90.)
64 else:
65 if None in (self.strike, self.dip, self.rake):
66 raise ValueError(
67 'RectangularSourceGenerator: '
68 'strike, dip, rake must be used in combination.')
70 strike = self.strike
71 dip = self.dip
72 rake = self.rake
74 source = gf.RectangularSource(
75 time=util.to_time_float(time),
76 lat=float(lat),
77 lon=float(lon),
78 anchor='top',
79 depth=float(depth),
80 length=float(length),
81 width=float(width),
82 strike=float(strike),
83 dip=float(dip),
84 rake=float(rake),
85 magnitude=magnitude,
86 decimation_factor=self.decimation_factor)
88 return source
90 def add_map_artists(self, automap):
91 for source in self.get_sources():
92 automap.gmt.psxy(
93 in_rows=source.outline(cs='lonlat'),
94 L='+p2p,black',
95 W='1p,black',
96 G='black',
97 t=50,
98 *automap.jxyr)