Skip to content
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

Misfit lune plot in matplotlib backed for deviatoric solutions #273

Closed
SeismoFelix opened this issue Sep 13, 2024 · 2 comments
Closed

Misfit lune plot in matplotlib backed for deviatoric solutions #273

SeismoFelix opened this issue Sep 13, 2024 · 2 comments

Comments

@SeismoFelix
Copy link
Contributor

Hi!

I am having issues with plotting the lune plot in the new matplotlib visualization backend. The problem seems to arise when a deviatoric grid-search (DC + CLVD). Although in this case, we are only using the lune longitude, this feature used to be functional in the previous backend with deviatoric solutions (see attached figures).

Here is the error I am getting:

Traceback (most recent call last): File "/home/scoped/inversiones/FK_GridSearch.DEV+Magnitude+Depth_Iceland.py", line 270, in <module> plot_misfit_lune(event_id+'DEV+Z_misfit.png', results) File "/home/scoped/mtuq/mtuq/graphics/uq/lune.py", line 63, in plot_misfit_lune _plot_lune(filename, misfit, **kwargs) File "/home/scoped/mtuq/mtuq/graphics/uq/lune.py", line 261, in _plot_lune backend(filename, File "/home/scoped/mtuq/mtuq/graphics/uq/_matplotlib.py", line 85, in _plot_lune_matplotlib im = ax.contourf(x, y, values, cmap=colormap, levels=levels, zorder=10) File "/opt/conda/lib/python3.10/site-packages/matplotlib/__init__.py", line 1465, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) File "/opt/conda/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 6536, in contourf contours = mcontour.QuadContourSet(self, *args, **kwargs) File "/opt/conda/lib/python3.10/site-packages/matplotlib/contour.py", line 858, in __init__ kwargs = self._process_args(*args, **kwargs) File "/opt/conda/lib/python3.10/site-packages/matplotlib/contour.py", line 1523, in _process_args x, y, z = self._contour_args(args, kwargs) File "/opt/conda/lib/python3.10/site-packages/matplotlib/contour.py", line 1563, in _contour_args x, y, z = self._check_xyz(x, y, z_orig, kwargs) File "/opt/conda/lib/python3.10/site-packages/matplotlib/contour.py", line 1591, in _check_xyz raise TypeError(f"Input z must be at least a (2, 2) shaped array, " TypeError: Input z must be at least a (2, 2) shaped array, but has shape (1, 30)

It looks like the contour function in matplotlib expects a symmetric array and a deviatoric grid search has no points in the lune latitude.

Thanks for your help,

Felix
Screenshot 2024-09-12 at 8 13 04 PM

@thurinj
Copy link
Member

thurinj commented Nov 26, 2024

Hi @SeismoFelix ,

Sorry for the late reply: I got a solution for this -- you have to use the colormesh plot type instead of the default (which is based on matplotlib contourf plot).

plot_misfit_lune(event_id+'DEV_misfit_lune.png', results, plot_type='colormesh')
plot_misfit_lune(event_id+'DEV_misfit_lune_tradeoffs.png', results, plot_type='colormesh', show_tradeoffs=True)

should both be working and plot a result similar to what we had with GMT.

The fix for this issue is going to be a small check in the code, to try to use the contour plot and fall back to the colormesh if the error you have encountered is raised. I'll close the issue then.

thurinj added a commit that referenced this issue Nov 27, 2024
…sue #273

Added a conditional statement for the 'contour' plot mode. If the contour plot fails, it now produces an equivalent 'colormesh' plot.
thurinj added a commit that referenced this issue Nov 27, 2024
Update misfit lune plot to account for deviatoric grids. Addresses issue #273
@thurinj
Copy link
Member

thurinj commented Nov 27, 2024

Solved with #288

@thurinj thurinj closed this as completed Nov 27, 2024
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

No branches or pull requests

2 participants