-
Notifications
You must be signed in to change notification settings - Fork 415
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
smooth_contour makes FilledContourPlot disappear #3672
Comments
This variation doesn't depend on a local file: import datetime
import numpy as np
import xarray as xr
from xarray.backends import NetCDF4DataStore
import metpy.calc as mpcalc
from metpy.plots import FilledContourPlot, MapPanel, PanelContainer
from metpy.units import units
from siphon.catalog import TDSCatalog
level = 850*units.hPa
plot_time = datetime.datetime(2024, 10, 31, 12)
ds_name = 'NAM_CONUS_80km_20241031_1200.grib1'
cat_name = ('https://thredds.ucar.edu/thredds/catalog/grib/NCEP/NAM/'
'CONUS_80km/' + ds_name + '/catalog.xml')
cat = TDSCatalog(cat_name)
ds = cat.datasets[ds_name]
ncss = ds.subset()
query = ncss.query()
query.time(plot_time).variables('all')
nc = ncss.get_data(query)
data = xr.open_dataset(NetCDF4DataStore(nc)).metpy.parse_cf()
u = data['u-component_of_wind_isobaric'].metpy.sel(vertical=level)
v = data['v-component_of_wind_isobaric'].metpy.sel(vertical=level)
T = data['Temperature_isobaric'].metpy.sel(vertical=level)
th = mpcalc.potential_temperature(level, T)
frnt = mpcalc.frontogenesis(th, u, v)
f = FilledContourPlot()
f.data = frnt
f.scale = 1.08e9
f.contours = list(np.arange(-2.5, 2.6, .5))
f.colormap = 'PuOr'
f.colorbar = 'horizontal'
f.smooth_contour = 2
mp = MapPanel()
mp.area = (-105, -70, 30, 50)
mp.layers = 'coastline', 'states', 'borders'
mp.layers_edgecolor = 'brown'
mp.plots = f,
pc = PanelContainer()
pc.size = (11, 8.5)
pc.panels = mp,
pc.show()
omeg = data['Vertical_velocity_pressure_isobaric'].metpy.sel(vertical=level)
o = FilledContourPlot()
o.data = omeg
o.contours = range(-9, 10, 1)
o.colormap = 'BrBG_r'
o.colorbar = 'horizontal'
o.smooth_contour = 2
o.plot_units = 'microbar/s'
mp = MapPanel()
mp.area = (-105, -70, 30, 50)
mp.layers = 'coastline', 'states', 'borders'
mp.layers_edgecolor = 'brown'
mp.plots = o,
pc = PanelContainer()
pc.size = (11, 8.5)
pc.panels = mp,
pc.show() |
So I was able to look into this a bit and it appears that it is an issue with the fact that there are NAN values that result from the frontogenesis calculation. Underlying the The following will use the MetPy version of the function that makes it easier to work with an xarray DataArray mpcalc.zoom_xarray(frnt[0]*1.08e9, 2, order=3) The output ends up being all So the question is do we want to handle or Work on our documentation and examples to highlight when something like this might fail and point users to other methods that should work for them. For example, using |
Ahh, good find! I do see one gridpoint in the Bahamas where the frontogenesis is NaN; the total deformation is very small there, and I did get a warning: While I agree that making I'll submit a separate bug report for this. |
What went wrong?
As written, I get no contours in my frontogenesis plot, but if I comment out
f.smooth_contour = 2
I do get the expected plot.
Oddly, in the second plot, I see the contours whether I have
o.smooth_contour = 2
or not.This is with matplotlib 3.8.2
Operating System
Linux
Version
Current main branch
Python Version
3.12.0
Code to Reproduce
Errors, Traceback, and Logs
No response
The text was updated successfully, but these errors were encountered: