Skip to content

Commit 0a40f61

Browse files
committed
Update plots
1 parent 87c83ab commit 0a40f61

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

examples/marmousi_2D.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@
8282
# remove damping extension from u_full
8383
u_full = space_model.remove_nbl(u_full)
8484

85-
extent = [0, 17000, 3500, 0]
86-
8785
print("u_full shape:", u_full.shape)
8886
print("timesteps:", time_model.timesteps)
89-
plot_velocity_model(space_model.velocity_model, extent=extent)
90-
plot_wavefield(u_full[-1], extent=extent)
87+
plot_velocity_model(space_model.velocity_model, solver=solver)
88+
plot_wavefield(u_full[-1], solver=solver)
9189
plot_shotrecord(recv)

simwave/plots/plot.py

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def plot_wavefield(wavefield, file_name="wavefield", colorbar=True,
9-
cmap="gray", extent=None, show=False, clim=[-5, 5]):
9+
cmap="gray", solver=None, show=False, clim=[-5, 5]):
1010
"""
1111
Plot the wavefield.
1212
@@ -23,8 +23,9 @@ def plot_wavefield(wavefield, file_name="wavefield", colorbar=True,
2323
The Colormap instance or registered colormap name
2424
used to map scalar data to colors.
2525
Default is gray.
26-
extent : floats(left, right, bottom, top), optional
27-
The bounding box in data coordinates that the image will fill.
26+
solver : Solver, optional
27+
Solver object. If provided, the plot sets
28+
the extent values.
2829
show : bool, optional
2930
If True, show the image on a pop up window.
3031
Default is False.
@@ -35,6 +36,17 @@ def plot_wavefield(wavefield, file_name="wavefield", colorbar=True,
3536

3637
# create the destination dir
3738
os.makedirs("plots", exist_ok=True)
39+
40+
if solver is not None:
41+
#left, right, bottom, top
42+
left = solver.space_model.bounding_box[2]
43+
right = solver.space_model.bounding_box[3]
44+
bottom = solver.space_model.bounding_box[1]
45+
top = solver.space_model.bounding_box[0]
46+
47+
extent = [left, right, bottom, top]
48+
else:
49+
extent = None
3850

3951
# process data and generate the plot
4052
plot = plt.imshow(wavefield, cmap=cmap, extent=extent)
@@ -63,7 +75,8 @@ def plot_wavefield(wavefield, file_name="wavefield", colorbar=True,
6375
print("Wavefield saved in plots/{}.png".format(file_name))
6476

6577

66-
def plot_shotrecord(rec, file_name="shotrecord", colorbar=True, show=False):
78+
def plot_shotrecord(rec, file_name="shotrecord", colorbar=True,
79+
show=False, solver=None):
6780
"""
6881
Plot a shot record (receiver values over time).
6982
@@ -79,10 +92,28 @@ def plot_shotrecord(rec, file_name="shotrecord", colorbar=True, show=False):
7992
show : bool, optional
8093
If True, show the image on a pop up window.
8194
Default is False.
95+
solver : Solver, optional
96+
Solver object. If provided, the plot sets
97+
the extent values.
8298
"""
8399
scale = np.max(rec) / 10.0
84-
plot = plt.imshow(rec, vmin=-scale, vmax=scale, cmap=cm.gray)
85-
plt.xlabel("Receivers")
100+
101+
if solver is not None:
102+
#left, right, bottom, top
103+
left = solver.space_model.bounding_box[2]
104+
right = solver.space_model.bounding_box[3]
105+
bottom = solver.time_model.tf * 1000
106+
top = solver.time_model.t0 * 1000
107+
108+
extent = [left, right, bottom, top]
109+
x_label = "Width (m)"
110+
else:
111+
extent = None
112+
x_label = "Receivers"
113+
114+
plot = plt.imshow(rec, vmin=-scale, vmax=scale,
115+
cmap=cm.gray, extent=extent)
116+
plt.xlabel(x_label)
86117
plt.ylabel("Time (ms)")
87118

88119
# Create colorbar on the right
@@ -106,7 +137,7 @@ def plot_shotrecord(rec, file_name="shotrecord", colorbar=True, show=False):
106137

107138
def plot_velocity_model(model, sources=None, receivers=None,
108139
file_name="velocity_model", colorbar=True,
109-
extent=None, cmap="jet", show=False):
140+
solver=None, cmap="jet", show=False):
110141
"""
111142
Plot the velocity model.
112143
@@ -127,15 +158,27 @@ def plot_velocity_model(model, sources=None, receivers=None,
127158
The Colormap instance or registered colormap name
128159
used to map scalar data to colors.
129160
Default is jet.
130-
extent : floats(left, right, bottom, top), optional
131-
The bounding box in data coordinates that the image will fill.
161+
solver : Solver, optional
162+
Solver object. If provided, the plot sets
163+
the extent values.
132164
show : bool, optional
133165
If True, show the image on a pop up window.
134166
Default is False.
135167
"""
136168

137169
# create the destination dir
138170
os.makedirs("plots", exist_ok=True)
171+
172+
if solver is not None:
173+
#left, right, bottom, top
174+
left = solver.space_model.bounding_box[2]
175+
right = solver.space_model.bounding_box[3]
176+
bottom = solver.space_model.bounding_box[1]
177+
top = solver.space_model.bounding_box[0]
178+
179+
extent = [left, right, bottom, top]
180+
else:
181+
extent = None
139182

140183
# process data and generate the plot
141184
plot = plt.imshow(model, cmap=cmap, extent=extent)

0 commit comments

Comments
 (0)