-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsnuffling.py
179 lines (147 loc) · 7.14 KB
/
snuffling.py
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
import numpy
from matplotlib import pylab as plt
from pyrocko.gui.snuffling import Snuffling, Param
from pyrocko import io
from pyrocko import util
from pyrocko import trace
import logging
logger = logging.getLogger('pyrocko.gui.snuffling.okada')
try:
import okada
except OSError as e:
logger.warn('''\n %s
--> run 'make' in okada snuffling directory <--''' % e)
except ImportError as e:
logger.warn(e)
class okadaforward(Snuffling):
'''
<html>
<body>
<head>
<style type="text/css">
body { margin-left:10px };
</style>
</head>
<body>
<h1 align="center">Plot rect. dislocation forward modelling </h1>
<p>
Plot a rectangular dislocation source in a elastic half-space.<br>
Plots in a seperate window.
Standard figure is given in C-Band and the signal is re-wrapped with
into LOS. <br>
If <b>Auto-Run</b> is activated the figure is updated automatically when
modifying a value on the panel. Note that the fault trace will not be drawn in this mode. <br>
The save buttion will <b>Save</b> the displacment three traces (U,N,E)
and will be saved to the current directory. <br>
</body>
</html>
'''
def setup(self):
self.set_name("Geodetic Okada forward modelling")
self.add_parameter(Param(
'Dip [deg.]', 't_dip', 45., 0., 90.))
self.add_parameter(Param(
'Strike [deg.]', 't_strike', 130., 0.1, 360.))
self.add_parameter(Param(
'Rake [deg.]', 't_rake', 120., -180., 180.))
self.add_parameter(Param(
'Slip [m]', 't_slip', 1., 0.1, 20.))
self.add_parameter(Param(
'Depth of Top edge [m]', 't_ztop', -1.5e3, -50e3, 0.))
self.add_parameter(Param(
'Depth of bottom edge [m]', 't_zbot', -4e3, -50e3, 0.))
self.add_parameter(Param(
'Length [m]', 't_length', 10e3, 1, 50e3))
self.add_parameter(Param(
'Grid extent [m]', 't_ext', 25e3, 10e3, 200e3))
self.add_parameter(Param(
'X-shift of fault centre from 0 [m]', 't_xtrace', 0, 0., 200e3))
self.add_parameter(Param(
'Y-shfit of fault centre from 0 [m]', 't_ytrace', 0, 0., 200e3))
self.add_parameter(Param(
'Wavelength for rewrapping [m]', 't_wavelength', 0.056, 0., 0.325))
self.add_parameter(Param(
'LOS 1', 't_los1', 0.3815, 0., 1.))
self.add_parameter(Param(
'LOS 2', 't_los2', 0.0843, 0., 1.))
self.add_parameter(Param(
'LOS 3', 't_los3', 0.9205, 0., 1.))
self.add_trigger('Save as displ. Traces', self.save)
self.add_trigger('Save as LOS displ. Traces', self.savelos)
self.set_live_update(False)
self.fig = None
def call(self):
self.cleanup()
viewer = self.get_viewer()
los = self.t_los1, self.t_los2, self.t_los3 # unit vector
wavelength = self.t_wavelength # meter C-Band
extent = -self.t_ext, self.t_ext, -self.t_ext, self.t_ext # meter (xmin,xmax,ymin,ymax)
fault = okada.OkadaSource(
strike=self.t_strike, dip=self.t_dip, rake=self.t_strike, # degree
slip=self.t_slip, # meter
ztop=self.t_ztop, zbottom=self.t_zbot, length=self.t_length, # meter
xtrace=self.t_xtrace, ytrace=self.t_ytrace ) # meter
Y, X = numpy.meshgrid(
numpy.linspace( extent[2], extent[3], 500 ),
numpy.linspace( extent[0], extent[1], 500 ) )
XYZ = numpy.array([ X, Y, numpy.zeros_like(X) ]).T
disp = fault.displacement( XYZ, poisson=.25 )
disp_los = numpy.dot( disp, los )
phase = ( numpy.mod( disp_los / ( .5 * wavelength ) * 2 + 1, 2 ) - 1 ) * numpy.pi
if self.fig is None or self.fframe.closed is True or not self._live_update:
self.fframe = self.pylab(get='figure_frame')
self.fig = self.fframe.gcf()
if self._live_update:
self.fig.clf()
ax = self.fig.add_subplot(111)
ax.imshow( phase, extent=extent, cmap=plt.cm.jet, origin='lower' )
if not self._live_update:
dx = numpy.array((-.5,.5)) * fault.length * numpy.sin( fault.strike * numpy.pi / 180 )
dy = numpy.array((-.5,.5)) * fault.length * numpy.cos( fault.strike * numpy.pi / 180 )
ax.plot( fault.xtrace + dx, fault.ytrace + dy, 'w-', linewidth=5, solid_capstyle='round' )
ax.plot( fault.xtrace + dx, fault.ytrace + dy, 'k--', linewidth=2, dash_capstyle='round' )
formatter = plt.FuncFormatter( lambda x, pos: '%dkm' % int( x / 1e3 ) if x else '0' )
ax.xaxis.set_major_formatter( formatter )
ax.yaxis.set_major_formatter( formatter )
ax.grid()
self.fig.canvas.draw()
if self._live_update:
self.fig.canvas.show()
def save(self):
fault = okada.OkadaSource(
strike=self.t_strike, dip=self.t_dip, rake=self.t_strike, # degree
slip=self.t_slip, # meter
ztop=self.t_ztop, zbottom=self.t_zbot, length=self.t_length, # meter
xtrace=self.t_xtrace, ytrace=self.t_ytrace ) # meter
extent = -self.t_ext, self.t_ext, -self.t_ext, self.t_ext # meter (xmin,xmax,ymin,ymax)
Y, X = numpy.linspace( extent[2], extent[3] ),numpy.linspace( extent[0], extent[1])
XYZ = numpy.array([ X, Y, numpy.zeros_like(X) ]).T
disp = fault.displacement( XYZ, poisson=.25 )
tmint = util.str_to_time('1970-01-01 00:05:00.000')
tr_U = trace.Trace(station='disp', channel='Z', deltat=0.5, tmin=tmint, ydata=disp[:,0])
io.save([tr_U], 'up_displacement.mseed')
tr_N = trace.Trace(station='disp', channel='N', deltat=0.5, tmin=tmint, ydata=disp[:,1])
io.save([tr_N], 'north_displacement.mseed')
tr_N = trace.Trace(station='disp', channel='E', deltat=0.5, tmin=tmint, ydata=disp[:,2])
io.save([tr_N], 'east_displacement.mseed')
def savelos(self):
fault = okada.OkadaSource(
strike=self.t_strike, dip=self.t_dip, rake=self.t_strike, # degree
slip=self.t_slip, # meter
ztop=self.t_ztop, zbottom=self.t_zbot, length=self.t_length, # meter
xtrace=self.t_xtrace, ytrace=self.t_ytrace ) # meter
extent = -self.t_ext, self.t_ext, -self.t_ext, self.t_ext # meter (xmin,xmax,ymin,ymax)
Y, X = numpy.linspace( extent[2], extent[3] ),numpy.linspace( extent[0], extent[1])
XYZ = numpy.array([ X, Y, numpy.zeros_like(X) ]).T
los = self.t_los1, self.t_los2, self.t_los3 # unit vector
disp = fault.displacement( XYZ, poisson=.25 )
disp_los = numpy.dot( disp, los )
tmint = util.str_to_time('1970-01-01 00:05:00.000')
tr_U = trace.Trace(station='disp_los', channel='Z', deltat=0.5, tmin=tmint, ydata=disp_los[:,0])
io.save([tr_U], 'up_displacement_los.mseed')
tr_N = trace.Trace(station='disp_los', channel='N', deltat=0.5, tmin=tmint, ydata=disp_los[:,1])
io.save([tr_N], 'north_displacement_los.mseed')
tr_N = trace.Trace(station='disp_los', channel='E', deltat=0.5, tmin=tmint, ydata=disp_los[:,2])
io.save([tr_N], 'east_displacement_los.mseed')
def __snufflings__():
return [okadaforward()]