uafgeotools / mtuq

moment tensor uncertainty quantification
BSD 2-Clause "Simplified" License
68 stars 23 forks source link

Misfit lune plot in matplotlib backed for deviatoric solutions #273

Open SeismoFelix opened 2 months ago

SeismoFelix commented 2 months ago

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 commented 23 hours ago

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.