1

I have a 2D array of satellite data, and two corresponding 2D arrays giving the latitude and longitude of each pixel.

The data array is a masked array.

When I plot it up using pcolormesh, it looks like this:

m.pcolormesh(lon, lat, data)

enter image description here

I am attempting to grid this data on to a 0.25x0.25 deg grid.

lonGrid = arange(0, 360, 0.25)
latGrid = arange(-90, 90 0.25)
dataGridded = griddata(lon.ravel(),lat.ravel(),data.ravel(),latGrid,lonGrid, interp='linear')
m.pcolormesh(lonGrid, latGrid, dataGridded)

However, the resulting plot comes out as this: enter image description here

It seems like this error has something to do with pcolormesh filling in the space between masked values. But I am unsure how to fix this.

Thanks

EDIT:

I was able to use the scipy version of griddata to get this to work...but its much slower and the syntax is more clunky. I would still appreciate some help getting the mpl(?) version above to work

from scipy.interpolate import griddata as griddata2

lonGrid,latGrid = meshgrid(lonGrid,latGrid)
dataGrid = griddata2((lon.ravel(),lat.ravel()),data.ravel(),(lonGrid,latGrid), method = 'linear')
dataGrid = ma.masked_where((dataGrid < 0) | isnan(dataGrid), dataGrid)
m.pcolormesh(lonGrid, latGrid, dataGridded)

enter image description here

hm8
  • 1,381
  • 3
  • 21
  • 41

1 Answers1

1

Here are a couple initial troubleshooting ideas.

  1. What version of Numpy are you using? If 1.09 or earlier the .ravel() will not return a masked array if given a masked array. See here.
  2. The data array "wind" became "data". Is "data" truly masked? What happened between the two? Some more code would be useful.

    dataGridded = griddata(lon.ravel(),lat.ravel(),XXXX.ravel(),latGrid,lonGrid, interp='linear')
    
  • I am using a NumPy version later than 1.09. Ravel() is returning a masked array. Sorry about using the word wind, I meant to change that to data. I edited the original post. Both data and dataGridded are masked arrays. – hm8 Nov 09 '16 at 18:47