pcolormesh in transforms branch

Hi Michael: I've been testing basemap with the transforms branch. All the examples now run, but the ones that use pcolormesh don't work correctly. I've attached an example. In the trunk, using either pcolor or pcolormesh produce an identical plot. In the transforms branch, using pcolor produces the correct plot, but using pcolormesh seems to scramble the image.

-Jeff

test_pcolormesh.py (979 Bytes)

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

Thanks for finding this. It was an x,y reversal indexing the mesh array. Fixed in r4565.

Cheers,
Mike

Jeff Whitaker wrote:

···

Hi Michael: I've been testing basemap with the transforms branch. All the examples now run, but the ones that use pcolormesh don't work correctly. I've attached an example. In the trunk, using either pcolor or pcolormesh produce an identical plot. In the transforms branch, using pcolor produces the correct plot, but using pcolormesh seems to scramble the image.

-Jeff

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

Thanks for finding this. It was an x,y reversal indexing the mesh array. Fixed in r4565.

Cheers,
Mike

Jeff Whitaker wrote:

Hi Michael: I've been testing basemap with the transforms branch. All the examples now run, but the ones that use pcolormesh don't work correctly. I've attached an example. In the trunk, using either pcolor or pcolormesh produce an identical plot. In the transforms branch, using pcolor produces the correct plot, but using pcolormesh seems to scramble the image.

-Jeff

OK - since you fixed that one so fast, here's another one! Seems like images don't quite fill up the entire axes - running this script with the transforms branch you'll see a white strip around the top and right side of the image.

-Jeff

P.S. the data this script needs is in the basemap examples directory.

test_imshow.py (858 Bytes)

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

Jeff Whitaker wrote:

Michael Droettboom wrote:

Thanks for finding this. It was an x,y reversal indexing the mesh array. Fixed in r4565.

Cheers,
Mike

Jeff Whitaker wrote:

Hi Michael: I've been testing basemap with the transforms branch. All the examples now run, but the ones that use pcolormesh don't work correctly. I've attached an example. In the trunk, using either pcolor or pcolormesh produce an identical plot. In the transforms branch, using pcolor produces the correct plot, but using pcolormesh seems to scramble the image.

-Jeff

OK - since you fixed that one so fast, here's another one! Seems like images don't quite fill up the entire axes - running this script with the transforms branch you'll see a white strip around the top and right side of the image.

-Jeff

P.S. the data this script needs is in the basemap examples directory.

Michael: And one more - contourf will die if you there are no contours at the requested levels. The error message looks like this:

Traceback (most recent call last):
  File "plotprecip.py", line 52, in <module>
    cs = m.contourf(x,y,data,clevs,cmap=cm.s3pcpn)
  File "/Users/jsw/lib/python/matplotlib/toolkits/basemap/basemap.py", line 2425, in contourf
    CS = ax.contourf(x,y,data,*args,**kwargs)
  File "/Users/jsw/lib/python/matplotlib/axes.py", line 5017, in contourf
    return mcontour.ContourSet(self, *args, **kwargs)
  File "/Users/jsw/lib/python/matplotlib/contour.py", line 460, in __init__
    self.ax.add_collection(col)
  File "/Users/jsw/lib/python/matplotlib/axes.py", line 1140, in add_collection
    self.update_datalim(collection.get_datalim(self.transData))
  File "/Users/jsw/lib/python/matplotlib/collections.py", line 142, in get_datalim
    offsets, transOffset.frozen())
  File "/Users/jsw/lib/python/matplotlib/path.py", line 481, in get_path_collection_extents
    raise ValueError("No paths provided")

To trigger this, try running the plotprecip.py basemap example.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

It seems to have broken when I upgraded the branch to Agg 2.4. Agg 2.4 now handles interpolating the edges of the image with a background color more-or-less "correctly", and no longer needs the hack that adds boundary pixels to the image before sending it to Agg for interpolation. Should also be much faster with large images. Fixed in r4568.

Cheers,
Mike

Jeff Whitaker wrote:

···

Michael Droettboom wrote:

Thanks for finding this. It was an x,y reversal indexing the mesh array. Fixed in r4565.

Cheers,
Mike

Jeff Whitaker wrote:

Hi Michael: I've been testing basemap with the transforms branch. All the examples now run, but the ones that use pcolormesh don't work correctly. I've attached an example. In the trunk, using either pcolor or pcolormesh produce an identical plot. In the transforms branch, using pcolor produces the correct plot, but using pcolormesh seems to scramble the image.

-Jeff

OK - since you fixed that one so fast, here's another one! Seems like images don't quite fill up the entire axes - running this script with the transforms branch you'll see a white strip around the top and right side of the image.

-Jeff

P.S. the data this script needs is in the basemap examples directory.

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

The transforms branch has seen very little outside of the matplotlib examples, so it's good to find all of these error cases. Fixed in r4569.

Cheers,
Mike

···

Michael: And one more - contourf will die if you there are no contours at the requested levels. The error message looks like this:

Traceback (most recent call last):
File "plotprecip.py", line 52, in <module>
   cs = m.contourf(x,y,data,clevs,cmap=cm.s3pcpn)
File "/Users/jsw/lib/python/matplotlib/toolkits/basemap/basemap.py", line 2425, in contourf
   CS = ax.contourf(x,y,data,*args,**kwargs)
File "/Users/jsw/lib/python/matplotlib/axes.py", line 5017, in contourf
   return mcontour.ContourSet(self, *args, **kwargs)
File "/Users/jsw/lib/python/matplotlib/contour.py", line 460, in __init__
   self.ax.add_collection(col)
File "/Users/jsw/lib/python/matplotlib/axes.py", line 1140, in add_collection
   self.update_datalim(collection.get_datalim(self.transData))
File "/Users/jsw/lib/python/matplotlib/collections.py", line 142, in get_datalim
   offsets, transOffset.frozen())
File "/Users/jsw/lib/python/matplotlib/path.py", line 481, in get_path_collection_extents
   raise ValueError("No paths provided")

To trigger this, try running the plotprecip.py basemap example.

-Jeff

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

The transforms branch has seen very little outside of the matplotlib examples, so it's good to find all of these error cases. Fixed in r4569.

Cheers,
Mike

Michael: And one more - contourf will die if you there are no contours at the requested levels. The error message looks like this:

Traceback (most recent call last):
File "plotprecip.py", line 52, in <module>
   cs = m.contourf(x,y,data,clevs,cmap=cm.s3pcpn)
File "/Users/jsw/lib/python/matplotlib/toolkits/basemap/basemap.py", line 2425, in contourf
   CS = ax.contourf(x,y,data,*args,**kwargs)
File "/Users/jsw/lib/python/matplotlib/axes.py", line 5017, in contourf
   return mcontour.ContourSet(self, *args, **kwargs)
File "/Users/jsw/lib/python/matplotlib/contour.py", line 460, in __init__
   self.ax.add_collection(col)
File "/Users/jsw/lib/python/matplotlib/axes.py", line 1140, in add_collection
   self.update_datalim(collection.get_datalim(self.transData))
File "/Users/jsw/lib/python/matplotlib/collections.py", line 142, in get_datalim
   offsets, transOffset.frozen())
File "/Users/jsw/lib/python/matplotlib/path.py", line 481, in get_path_collection_extents
   raise ValueError("No paths provided")

To trigger this, try running the plotprecip.py basemap example.

-Jeff

Thanks Mike - all of the basemap examples are now working as expected with the transforms branch. The only significant change I had to make was to wrap axes.get_position in a try/except block, i.e.

try:
    l,b,w,h = ax.get_position()
except:
    l,b,w,h = (ax.get_position()).bounds

so that they would work both with the trunk and the transforms branch.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

In general, blanket excepts are bad practice because they can mask
other bugs. You might catch the AttributeError, or do something like:

pos = ax.get_position()
l, b, w, h = getattr(pos, 'bounds', pos)

or maybe a version or other check to see if you are on the branch

JDH

···

On Dec 3, 2007 2:08 PM, Jeff Whitaker <jswhit@...196...> wrote:

try:
    l,b,w,h = ax.get_position()
except:
    l,b,w,h = (ax.get_position()).bounds

John Hunter wrote:

···

On Dec 3, 2007 2:08 PM, Jeff Whitaker <jswhit@...196...> wrote:

try:
    l,b,w,h = ax.get_position()
except:
    l,b,w,h = (ax.get_position()).bounds
    
In general, blanket excepts are bad practice because they can mask
other bugs. You might catch the AttributeError, or do something like:

pos = ax.get_position()
l, b, w, h = getattr(pos, 'bounds', pos)

or maybe a version or other check to see if you are on the branch

JDH
  

John: You're right, I should do that. This is only in the examples, not in the basemap code itself though.

-Jeff

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

Jeff Whitaker wrote:

John Hunter wrote:

try:
    l,b,w,h = ax.get_position()
except:
    l,b,w,h = (ax.get_position()).bounds
    
In general, blanket excepts are bad practice because they can mask
other bugs. You might catch the AttributeError, or do something like:

pos = ax.get_position()
l, b, w, h = getattr(pos, 'bounds', pos)

or maybe a version or other check to see if you are on the branch

JDH
  

John: You're right, I should do that. This is only in the examples, not in the basemap code itself though.

Just out of curiosity -- were there significant changes to the basemap code itself?

Glad to hear things are working with basemap. That was a lot faster than I expected. I feel much better about moving the transforms changes to the trunk...

Cheers,
Mike

···

On Dec 3, 2007 2:08 PM, Jeff Whitaker <jswhit@...196...> wrote:

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

Jeff Whitaker wrote:

John Hunter wrote:

try:
    l,b,w,h = ax.get_position()
except:
    l,b,w,h = (ax.get_position()).bounds
    
In general, blanket excepts are bad practice because they can mask
other bugs. You might catch the AttributeError, or do something like:

pos = ax.get_position()
l, b, w, h = getattr(pos, 'bounds', pos)

or maybe a version or other check to see if you are on the branch

JDH
  

John: You're right, I should do that. This is only in the examples, not in the basemap code itself though.

Just out of curiosity -- were there significant changes to the basemap code itself?

No, none. I did uncover one bug though!

-Jeff

···

On Dec 3, 2007 2:08 PM, Jeff Whitaker <jswhit@...196...> wrote:

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

That's great! I just assumed I had trampled over all kinds of semi-public APIs... :wink:

Cheers,
Mike

Jeff Whitaker wrote:

···

Michael Droettboom wrote:

Jeff Whitaker wrote:

John Hunter wrote:

On Dec 3, 2007 2:08 PM, Jeff Whitaker <jswhit@...196...> wrote:

try:
    l,b,w,h = ax.get_position()
except:
    l,b,w,h = (ax.get_position()).bounds
    
In general, blanket excepts are bad practice because they can mask
other bugs. You might catch the AttributeError, or do something like:

pos = ax.get_position()
l, b, w, h = getattr(pos, 'bounds', pos)

or maybe a version or other check to see if you are on the branch

JDH
  

John: You're right, I should do that. This is only in the examples, not in the basemap code itself though.

Just out of curiosity -- were there significant changes to the basemap code itself?

No, none. I did uncover one bug though!

-Jeff

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

The transforms branch has seen very little outside of the matplotlib examples, so it's good to find all of these error cases. Fixed in r4569.

Cheers,
Mike

Michael: And one more - contourf will die if you there are no contours at the requested levels. The error message looks like this:

Traceback (most recent call last):
File "plotprecip.py", line 52, in <module>
   cs = m.contourf(x,y,data,clevs,cmap=cm.s3pcpn)
File "/Users/jsw/lib/python/matplotlib/toolkits/basemap/basemap.py", line 2425, in contourf
   CS = ax.contourf(x,y,data,*args,**kwargs)
File "/Users/jsw/lib/python/matplotlib/axes.py", line 5017, in contourf
   return mcontour.ContourSet(self, *args, **kwargs)
File "/Users/jsw/lib/python/matplotlib/contour.py", line 460, in __init__
   self.ax.add_collection(col)
File "/Users/jsw/lib/python/matplotlib/axes.py", line 1140, in add_collection
   self.update_datalim(collection.get_datalim(self.transData))
File "/Users/jsw/lib/python/matplotlib/collections.py", line 142, in get_datalim
   offsets, transOffset.frozen())
File "/Users/jsw/lib/python/matplotlib/path.py", line 481, in get_path_collection_extents
   raise ValueError("No paths provided")

To trigger this, try running the plotprecip.py basemap example.

-Jeff

Michael: The fix for missing contours may have broken pcolor:

Traceback (most recent call last):
  File "test.py", line 553, in <module>
    p = m.pcolormesh(x,y,topodatin,shading='flat')
  File "/Users/jsw/lib/python/matplotlib/toolkits/basemap/basemap.py", line 2294, in pcolormesh
    ret = ax.pcolormesh(x,y,data,**kwargs)
  File "/Users/jsw/lib/python/matplotlib/axes.py", line 4836, in pcolormesh
    self.add_collection(collection)
  File "/Users/jsw/lib/python/matplotlib/axes.py", line 1140, in add_collection
    if len(collection._paths):
TypeError: object of type 'NoneType' has no len()

changing

if len(collection._paths):

to

if collection._paths and len(collection._paths)

in axes.py seems to fix it.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...236...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory