-
Notifications
You must be signed in to change notification settings - Fork 247
Fix plot_perturbation to ensure nbl is not plotted #2797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fix plotting of nbl
EdCaunt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment, but generally a useful fix. Thanks!
examples/seismic/plotting.py
Outdated
| dv = np.transpose(model.vp.data) - np.transpose(model1.vp.data) | ||
| slices = tuple(slice(model.nbl, -model.nbl) for _ in range(2)) | ||
| slices1 = tuple(slice(model1.nbl, -model1.nbl) for _ in range(2)) | ||
| dv = np.transpose(model.vp.data[slices]) - np.transpose(model1.vp.data[slices1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally check model.nbl == model1.nbl and raise a suitable ValueError if not (probably also check the size of both models match whilst you're at it).
That way you only need a single slices which would be tidier and easier to read in my opinion.
Minor note, you can also do slices = (slice(model.nbl, -model.nbl),) * 2 for concision, although this is arguably less explicit. A matter of personal preference I would say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in b2d1d4f!
| 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]] | ||
| assert model.nbl == model1.nbl, ValueError("model and model1 have different values for nbl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an fstring here so you get the actual names of the model objects
| extent = [model.origin[0], model.origin[0] + domain_size[0], | ||
| model.origin[1] + domain_size[1], model.origin[1]] | ||
| dv = np.transpose(model.vp.data) - np.transpose(model1.vp.data) | ||
| assert model.nbl == model1.nbl, ValueError("model and model1 have different values for nbl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the correct synthax is
if model.nbl != model1.nbl:
raise ValueError("model and model1 have different values for nbl")
the second arg of assert a, b is a plain string passed to AssertionError
Description
plot_perturbationhas a small bug where the nbl is not properly addressed when plotting. This PR addressed that by applying the same slicing asplot_velocity.