1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

import logging 

 

import numpy as num 

 

from pyrocko import orthodrome as pod 

from pyrocko.guts import Float, Bool, Tuple 

 

from pyrocko.plot import automap 

 

from grond.plot.collection import PlotItem 

from grond.plot.config import PlotConfig 

 

logger = logging.getLogger('grond.problem.double_sf.plot') 

 

guts_prefix = 'grond' 

 

km = 1e3 

 

 

class SFForcePlot(PlotConfig): 

''' Maps showing horizontal and vertical force 

of the best double single force model ''' 

 

name = 'forces_double_singleforce' 

 

size_cm = Tuple.T( 

2, Float.T(), 

default=(15., 15.), 

help='width and length of the figure in cm') 

show_topo = Bool.T( 

default=False, 

help='show topography') 

show_grid = Bool.T( 

default=True, 

help='show the lat/lon grid') 

show_rivers = Bool.T( 

default=True, 

help='show rivers on the map') 

radius = Float.T( 

optional=True, 

help='radius of the map around campaign center lat/lon') 

 

def make(self, environ): 

cm = environ.get_plot_collection_manager() 

history = environ.get_history(subset='harvest') 

optimiser = environ.get_optimiser() 

ds = environ.get_dataset() 

 

environ.setup_modelling() 

 

cm.create_group_automap( 

self, 

self.draw_best_sf(ds, history, optimiser), 

title=u'Single Force Source Forces', 

section='solution', 

feather_icon='map', 

description=u''' 

Maps show located force vectors of the best double Single Force Source model. 

 

Arrows show the modelled forces (red arrows). The top plot shows the horizontal 

forces and the bottom plot the vertical force. The dot indicates the location 

of the best double single force source model. 

''') 

 

def draw_best_sf(self, ds, history, optimiser, vertical=False): 

from grond.core import make_stats 

 

source = history.get_best_source() 

 

problem = history.problem 

models = history.models 

 

stats = make_stats( 

problem, models, history.get_primary_chain_misfits()) 

 

def plot_double_sf(source, stats, ifig, vertical=False): 

orient = 'vertical' if vertical else 'horizontal' 

 

item = PlotItem( 

name='fig_%i' % ifig, 

attributes={}, 

title=u'Best %s double single force model force vector' % ( 

orient), 

description=u''' 

Double single force source %s force vector for the best model (red). The circle 

shows the 95%% confidence ellipse. 

''' % orient) 

 

event = source.pyrocko_event() 

 

radius = self.radius 

if radius is None or radius < 30.*km: 

logger.warn( 

'Radius too small, defaulting to 30 km') 

radius = 30*km 

 

m = automap.Map( 

width=self.size_cm[0], 

height=self.size_cm[1], 

lat=event.lat, 

lon=event.lon, 

radius=radius, 

show_topo=self.show_topo, 

show_grid=self.show_grid, 

show_rivers=self.show_rivers, 

color_wet=(216, 242, 254), 

color_dry=(238, 236, 230)) 

 

offset_scale = source.force 

size = num.linalg.norm(self.size_cm) 

 

scale = (size / 5.) / offset_scale 

 

lat, lon = pod.ne_to_latlon( 

event.lat, 

event.lon, 

source.north_shift, 

source.east_shift) 

 

source.lat, source.lon = lat, lon 

sf1, sf2 = source.split() 

 

stats_dict = stats.get_values_dict() 

 

if vertical: 

rows = [[ 

sf1.effective_lon, sf1.effective_lat, 

0., -sf1.fd * scale, 

(stats_dict['rfn1.std'] + stats_dict['rfe1.std']), 

stats_dict['rfd1.std'], 

0.]] 

 

rows.append([ 

sf2.effective_lon, sf2.effective_lat, 

0., -sf2.fd * scale, 

(stats_dict['rfn2.std'] + stats_dict['rfe2.std']), 

stats_dict['rfd2.std'], 

0.]) 

 

else: 

rows = [[ 

sf1.effective_lon, sf1.effective_lat, 

sf1.fe * scale, sf1.fn * scale, 

stats_dict['rfe1.std'], 

stats_dict['rfn1.std'], 

0.]] 

 

rows.append([ 

sf2.effective_lon, sf2.effective_lat, 

sf2.fe * scale, sf2.fn * scale, 

stats_dict['rfe2.std'], 

stats_dict['rfn2.std'], 

0.]) 

 

fontsize = 10. 

 

default_psxy_style = { 

'h': 0, 

'W': '2.0p,red', 

'A': '+p4p,black+e+a40', 

'G': 'red', 

't': 30, 

'L': True, 

'S': 'e1c/0.95/%d' % fontsize, 

} 

 

m.gmt.psvelo( 

in_rows=rows, 

*m.jxyr, 

**default_psxy_style) 

 

m.gmt.psxy( 

S='c10p', 

in_rows=[[lon, lat]], 

W='1p,black', 

G='orange3', 

*m.jxyr) 

 

return (item, m) 

 

ifig = 0 

for vertical in (False, True): 

yield plot_double_sf(source, stats, ifig, vertical) 

ifig += 1