forked from fpicetti/occamypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting.py
160 lines (137 loc) · 4.96 KB
/
plotting.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
import numpy as np
try:
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.axes_grid1 import make_axes_locatable
mpl.rc('font', size=16)
mpl.rc('figure', figsize=(8, 6))
except:
plt = None
cm = None
def plot_perturbation(model, model1, colorbar=True):
"""
Plot a two-dimensional velocity perturbation from two devitoseismic `Model`
objects.
Parameters
----------
model : Model
The first velocity model.
model1 : Model
The second velocity model.
colorbar : bool
Option to plot the colorbar.
"""
domain_size = 1.e-3 * np.array(model.domain_size)
extent = [model.origin[0], model.origin[0] + domain_size[0],
model.origin[1] + domain_size[1], model.origin[1]]
dv = np.transpose(model.vp.csg_nonlinear) - np.transpose(model1.vp.csg_nonlinear)
plot = plt.imshow(dv, animated=True, cmap=cm.jet,
vmin=min(dv.reshape(-1)), vmax=max(dv.reshape(-1)),
extent=extent)
plt.xlabel('X position (km)')
plt.ylabel('Depth (km)')
# Create aligned colorbar on the right
if colorbar:
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(plot, cax=cax)
cbar.set_label('Velocity perturbation (km/s)')
plt.show()
def plot_velocity(model, source=None, receiver=None, colorbar=True, cmap="jet"):
"""
Plot a two-dimensional velocity field from a devitoseismic `Model`
object. Optionally also includes point markers for sources and receivers.
Parameters
----------
model : Model
Object that holds the velocity model.
source : array_like or float
Coordinates of the source point.
receiver : array_like or float
Coordinates of the receiver points.
colorbar : bool
Option to plot the colorbar.
"""
domain_size = 1.e-3 * np.array(model.domain_size)
extent = [model.origin[0], model.origin[0] + domain_size[0],
model.origin[1] + domain_size[1], model.origin[1]]
slices = tuple(slice(model.nbl, -model.nbl) for _ in range(2))
if getattr(model, 'vp', None) is not None:
field = model.vp.data[slices]
else:
field = model.lam.data[slices]
plot = plt.imshow(np.transpose(field), animated=True, cmap=cmap,
vmin=np.min(field), vmax=np.max(field),
extent=extent)
plt.xlabel('X position (km)')
plt.ylabel('Depth (km)')
# Plot source points, if provided
if receiver is not None:
plt.scatter(1e-3*receiver[:, 0], 1e-3*receiver[:, 1],
s=25, c='green', marker='D')
# Plot receiver points, if provided
if source is not None:
plt.scatter(1e-3*source[:, 0], 1e-3*source[:, 1],
s=25, c='red', marker='o')
# Ensure axis limits
plt.xlim(model.origin[0], model.origin[0] + domain_size[0])
plt.ylim(model.origin[1] + domain_size[1], model.origin[1])
# Create aligned colorbar on the right
if colorbar:
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(plot, cax=cax)
cbar.set_label('Velocity (km/s)')
plt.show()
def plot_shotrecord(rec, model, t0, tn, colorbar=True):
"""
Plot a shot record (receiver values over time).
Parameters
----------
rec :
Receiver data with shape (time, points).
model : Model
object that holds the velocity model.
t0 : int
Start of time dimension to plot.
tn : int
End of time dimension to plot.
"""
scale = np.max(rec) / 10.
extent = [model.origin[0], model.origin[0] + 1e-3*model.domain_size[0],
1e-3*tn, t0]
plot = plt.imshow(rec, vmin=-scale, vmax=scale, cmap=cm.gray, extent=extent)
plt.xlabel('X position (km)')
plt.ylabel('Time (s)')
# Create aligned colorbar on the right
if colorbar:
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(plot, cax=cax)
plt.show()
def plot_image(data, vmin=None, vmax=None, colorbar=True, cmap="gray"):
"""
Plot image data, such as RTM images or FWI gradients.
Parameters
----------
data : ndarray
Image data to plot.
cmap : str
Choice of colormap. Defaults to gray scale for images as a
devitoseismic convention.
"""
plot = plt.imshow(np.transpose(data),
vmin=vmin or 0.9 * np.min(data),
vmax=vmax or 1.1 * np.max(data),
cmap=cmap)
# Create aligned colorbar on the right
if colorbar:
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(plot, cax=cax)
plt.show()