66
77
88def 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
107138def 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