Search code examples
pythonnetcdfmetpy

Problem with generating Countour Plot using MetPy


I am trying to generate isobars using MetPy and ContourPlot. I use pressure data from my own netCDF file. The background heatmap is generated correctly, but for contours, there seems to be a kind of an interpolation error. Does anyone know how to fix the problem of horizontal white lines?

Here is the code which I use for plot generation:

cams = xr.open_dataset('20191129.nc')
contour = ContourPlot(clabels=True)
contour.data = cams
contour.field = 'PN'
contour.time = datetime.strptime('2020-11-29 00:00', '%Y-%m-%d %H:%M')
contour.level = units.Quantity(1000,units.hPa)
contour.linecolor = 'white'
contour.contours = 10

img = ImagePlot(colormap='jet',colorbar='horizontal')
img.data = cams
img.field = 'PN'
img.level = units.Quantity(1000,units.hPa)
img.time = datetime.strptime('2020-11-29 00:00', '%Y-%m-%d %H:%M')

panel = MapPanel()
panel.layers = ['coastline', 'borders', 'states',  'ocean', 'land']    
panel.title = 'Pressure @ Sea level '+date_str+' 00:00 UTC'
panel.plots = [contour,img]

pc = PanelContainer()
pc.size = (10, 8)
pc.panels = [panel]

pc.save('tt.png')

contour MetPy


Solution

  • Looks like I have found a bug within the MetPy code, which appear when plotting the data which cover both sides of the zero meridian: https://github.com/Unidata/MetPy/pull/1595

    A temporal solution is to edit the file src/metpy/plots/declarative.py and replace the line:

    x = x[:, 0] % 360
    

    with

    x = x[:, 0]
    

    No it works fine.enter image description here