Skip to content

Conversation

@cako
Copy link

@cako cako commented Nov 29, 2025

Description

plot_perturbation has a small bug where the nbl is not properly addressed when plotting. This PR addressed that by applying the same slicing as plot_velocity.

Fix plotting of nbl
Copy link
Contributor

@EdCaunt EdCaunt left a 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!

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])
Copy link
Contributor

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.

Copy link
Author

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")
Copy link
Contributor

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")
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants