Curvelinear grid support

Jae-Joon,

I just saw your curvelinear grid support fall into SVN. Very impressive! We actually may have a use for it here at Space Telescope for drawing "World Coordinate System (WCS)" plots.

One quick question though -- it seems that this functionality is completely independent of the axes_grid stuff, which is primarily about layout out axes within a figure, correct? Is there a reason why it's part of the axes_grid toolkit that I'm missing?

Cheers,
Mike

···

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

Jae-Joon,

I just saw your curvelinear grid support fall into SVN. Very
impressive! We actually may have a use for it here at Space Telescope
for drawing "World Coordinate System (WCS)" plots.

I am getting an exception with a clean numpy/mpl build from svn HEAD>
This appears platform specific because I am only seeing it on my
solaris box at work, not on a linux box I am also testing on.

johnh@...539...:axes_grid> uname -a
SunOS flag 5.10 Generic_118855-15 i86pc i386 i86pc

Here is the complete traceback:
Traceback (most recent call last):
  File "demo_curvelinear_grid.py", line 127, in ?
    plt.draw()
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/pyplot.py",
line 350, in draw
    get_current_fig_manager().canvas.draw()
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/backends/backend_tkagg.py",
line 215, in draw
    FigureCanvasAgg.draw(self)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 314, in draw
    self.figure.draw(self.renderer)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/artist.py",
line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/figure.py",
line 774, in draw
    for a in self.axes: a.draw(renderer)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/axislines.py",
line 1350, in draw
    super(Axes, self).draw(renderer, inframe)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/artist.py",
line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/axes.py",
line 1826, in draw
    a.draw(renderer)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/axislines.py",
line 874, in draw
    self._grid_helper.update_lim(self.axes)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/axislines.py",
line 564, in update_lim
    self._update(x1, x2, y1, y2)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/grid_helper_curvelinear.py",
line 114, in _update
    self._update_grid(x1, y1, x2, y2)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/grid_helper_curvelinear.py",
line 149, in _update_grid
    self.grid_info = self.grid_finder.get_grid_info(x1, y1, x2, y2)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/grid_finder.py",
line 241, in get_grid_info
    x1, y1, x2, y2)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/grid_finder.py",
line 118, in get_grid_info
    bb)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/grid_finder.py",
line 163, in _clip_grid_lines_and_find_ticks
    xy, tcks = clip_line_to_rect(lx, ly, bb)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/clip_path.py",
line 72, in clip_line_to_rect
    ly3, lx3, c_top_ = clip(ly2, lx2, y1, clip="right")
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/clip_path.py",
line 51, in clip
    a = degrees(atan2(dy, dx))
ValueError: math domain error

In the debugger:

In [3]: %debug

/home/titan/johnh/dev/lib/python2.4/site-packages/mpl_toolkits/axes_grid/clip_path.py(51)clip()

     50
---> 51 a = degrees(atan2(dy, dx))
     52 _pos_angles.append((x0, y0, a))

print dy, dx

-0 0.0

print type(dy), type(dx)

<type 'numpy.float64'> <type 'numpy.float64'>

print atan2(dy, dx)

*** ValueError: math domain error

The root cause seems to be the math.atan2 function on solaris

In [4]: import math

In [5]: math.atan2(0., 0.)

···

On Wed, Jun 3, 2009 at 10:04 AM, Michael Droettboom <mdroe@...31...> wrote:
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in ?
ValueError: math domain error

so we may want to special case the code to handle 0.0, 0.0 as inputs.

JDH

Jae-Joon,

I just saw your curvelinear grid support fall into SVN. Very
impressive! We actually may have a use for it here at Space Telescope
for drawing "World Coordinate System (WCS)" plots.

Well, the WCS support is actually my whole motivation for this (I'm
also in astronomy).

One quick question though -- it seems that this functionality is
completely independent of the axes_grid stuff, which is primarily about
layout out axes within a figure, correct? Is there a reason why it's
part of the axes_grid toolkit that I'm missing?

Well, axes_grid is actually a byproduct of my effort to nicely
display FITS image with matplotlib. And I tend to put everything that
is not astronomy-specific into axes_grid toolkit, which may not be
such a good idea.

While one needs to use a custom Axes class (axes_grid.axislines.Axes)
to support the curvelinear grid, this part of the code can be easily
separated out. But I'm not sure if creating another mpl_toolkit
package is best way to do here. Any suggestion will be welcomed.
Regards,

-JJ

···

On Wed, Jun 3, 2009 at 11:04 AM, Michael Droettboom <mdroe@...31...> wrote:

Cheers,
Mike

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

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options

Thanks a lot for tracking this down!
It would be best if my algorithm does not produce such a case, but
evidently it does. Yes, I'll put some code to treat this special case
and also see if I can avoid such cases by improving my algorithm.

Thanks again.

-JJ

···

On Wed, Jun 3, 2009 at 11:22 AM, John Hunter <jdh2358@...149...> wrote:

so we may want to special case the code to handle 0.0, 0.0 as inputs.

John,

This should now be fixed in the svn, although I haven't actually
tested it in solaris machine.
Please check if this works.

-JJ

···

On Wed, Jun 3, 2009 at 4:01 PM, Jae-Joon Lee<lee.j.joon@...149...> wrote:

On Wed, Jun 3, 2009 at 11:22 AM, John Hunter <jdh2358@...149...> wrote:

so we may want to special case the code to handle 0.0, 0.0 as inputs.

Thanks a lot for tracking this down!
It would be best if my algorithm does not produce such a case, but
evidently it does. Yes, I'll put some code to treat this special case
and also see if I can avoid such cases by improving my algorithm.

Thanks again.

-JJ