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-12 07:58 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6''' 

7Rectangular fault random source generator. 

8''' 

9 

10import numpy as num 

11 

12from pyrocko.guts import Float, Int 

13from pyrocko import moment_tensor, gf, util 

14 

15from .base import SourceGenerator 

16 

17km = 1e3 

18guts_prefix = 'pf.scenario' 

19 

20 

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) 

28 

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) 

37 

38 width = Float.T( 

39 optional=True) 

40 length = Float.T( 

41 optional=True) 

42 

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) 

49 

50 magnitude = self.draw_magnitude(rstate) 

51 moment = moment_tensor.magnitude_to_moment(magnitude) 

52 

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)) 

56 

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 

60 

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.') 

69 

70 strike = self.strike 

71 dip = self.dip 

72 rake = self.rake 

73 

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) 

87 

88 return source 

89 

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)