|
From: Phil E. <pel...@gm...> - 2014-04-16 08:14:34
|
Hi Chao, The warning you are getting: WARNING: x coordinate not monotonically increasing - contour plot may not be what you expect. If it looks odd, your can either adjust the map projection region to be consistent with your data, or (if your data is on a global lat/lon grid) use the shiftgrid function to adjust the data to be consistent with the map projection region (see examples/contour_demo.py). Is important here. It looks like the x coordinate is not in appropriate longitudes. Printing the first 5 and last 5 longitudes gives us our first clue: First 5: [-180. -178.99720764 -177.99443054 -176.99163818 -175.98886108] Last 5 : [ 175.98886108 176.9916687 177.9944458 178.9972229 180.00003052] Notice that the last longitude wraps around beyond 180. So if we were to clip these numbers to -180 and +180 we will see that the warning disappears and the contour is correct. This can be achieved with: lon = np.clip(lon, -180, 180) Alternatively, we can just construct the latitudes and longitudes ourselves directly with: lon, lat = np.meshgrid(np.linspace(-180, 180, 360), np.linspace(-90, 90, 180)) Incidentally, I tried these numbers with cartopy which has been designed to handle dateline wrapping automatically, and the contour worked with the unmodified longitudes (http://nbviewer.ipython.org/gist/pelson/10830039). --------------------------- @JeffWhitaker - This looks like a bug with float tolerances in the makegrid function. It currently does: def makegrid(self,nx,ny,returnxy=False): dx = (self.urcrnrx-self.llcrnrx)/(nx-1) dy = (self.urcrnry-self.llcrnry)/(ny-1) But might be better if it did: def makegrid(self,nx,ny,returnxy=False): x = np.linspace(self.llcrnrx, self.urcrnrx, nx) y = np.linspace(self.llcrnry, self.urcrnry, ny) To avoid the multiplicative floating point drift that is currently being seen. HTH, Phil |