Skip to content

ImagePlot fails on some [0, 360] data #1915

@dopplershift

Description

@dopplershift

This example:

from metpy.plots import ImagePlot, MapPanel, PanelContainer
from metpy.units import units
import xarray as xr

ds_z500 = xr.open_dataset('/Users/rmay/Downloads/gfs.t00z.pgrb2.0p25.f024', engine='cfgrib', filter_by_keys={'typeOfLevel': 'isobaricInhPa', 'level': 500})

img = ImagePlot()
img.data = ds_z500
img.field = 't'
img.colormap = 'plasma'

panel = MapPanel()
panel.area = 'us'
panel.title = 'GFS 500mb Temp Forecast Example'
panel.plots = [img]

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

produces the following with 1.0 and main:
image

Taken from a Stack Overflow question. This pretty clearly relates to this code that wraps longitude:

@property
def plotdata(self):
"""Return the data for plotting.
The data array, x coordinates, and y coordinates.
"""
x = self.griddata.metpy.x
y = self.griddata.metpy.y
# At least currently imshow with cartopy does not like this
if 'degree' in x.units:
x = x.data
x[x > 180] -= 360
return x, y, self.griddata

because without it the same code gives:
image

The code is pretty clearly incorrect because it results in an x array where x[0] is 0 and x[-1] is -0.25, since this full dataset has a longitude range of [0, 360].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: PlotsPertains to producing plotsType: BugSomething is not working like it should

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions