Right-to-left longitude with Basemap

Hi,
  I'm looking at Basemap as a backend for plotting maps of the sky in
different projections, and so far it seems like a really good match!
Excellent work!

  The only problem that I don't know how to solve is that in astronomy
the longitude on maps typically increases from right to left (we're
looking at the celestial sphere from the "inside"). Is there any way (or
a trick) to make Basemap do this?

Regards,

···

--
Mario Juric,
Hubble Fellow, Harvard-Smithsonian Center for Astrophysics
Web : http://www.sns.ias.edu/~mjuric/
Phone : +1 617 744-9003 PGP: ~mjuric/crypto/public.key

E-mail reading/answering policy: http://majuric.org/email/

Not my field, but I recently bumped into this
http://www.astro.rug.nl/software/kapteyn-beta/index.html

Maybe it's useful to you?

Cheers,
Scott

···

On 16 September 2010 20:38, Mario Juric <mjuric@...1081...> wrote:

   I&#39;m looking at Basemap as a backend for plotting maps of the sky in

different projections, and so far it seems like a really good match!
Excellent work!

   The only problem that I don&#39;t know how to solve is that in astronomy

the longitude on maps typically increases from right to left (we're
looking at the celestial sphere from the "inside"). Is there any way (or
a trick) to make Basemap do this?

Mario: Are you asking whether the basemap coordinate system can be reversed, or just the longitude labelling? If it's the former, the answer is no. If you just want the labels reversed, you can pass the drawmeridians method a custom formatting function with the 'fmt' keyword.

-Jeff

···

On 9/16/10 12:38 PM, Mario Juric wrote:

Hi,
  I'm looking at Basemap as a backend for plotting maps of the sky in
different projections, and so far it seems like a really good match!
Excellent work!

  The only problem that I don't know how to solve is that in astronomy
the longitude on maps typically increases from right to left (we're
looking at the celestial sphere from the "inside"). Is there any way (or
a trick) to make Basemap do this?

Regards,

Hi Mario,

(Sorry for the reply to a reply, but I was not on the list when the original message was posted)

This may not be useful for Basemap, but I did this with the matplotlib.projections.geo HammerAxes projection. I got it to work by subclassing that and modifying the _get_affine_transform() to negate the x-axis scale. I also seem to have had to fiddle with _set_lim_and_transforms() to account for this, though I don't remember the details.

In any case, I don't know how Basemap works and whether this is helpful. Maybe as inspiration... The code is below if it helps.

joey

Hi,
  I'm looking at Basemap as a backend for plotting maps of the sky in
different projections, and so far it seems like a really good match!
Excellent work!

  The only problem that I don't know how to solve is that in astronomy
the longitude on maps typically increases from right to left (we're
looking at the celestial sphere from the "inside"). Is there any way (or
a trick) to make Basemap do this?

Regards,

class AstroHammerAxes(HammerAxes):
    """Astronomical hammer projection.

    This is just a Hammer projection with the longitude axis
    reversed left-right.

    """
    name='astrohammer'

    def _get_affine_transform(self):
        """get affine transform

        This is cribbed from GeoAxes, but negates the xscale
        to put positive longitude to the left. Not sure this
        is actually robust.

        """
        transform=self._get_core_transform(1)
        xscale,_=transform.transform_point((pi,0))
        _,yscale=transform.transform_point((0,pi/2.0))
        return Affine2D()\
               .scale(-0.5/xscale, 0.5/yscale)\
               .translate(0.5,0.5)

    def _set_lim_and_transforms(self):
        HammerAxes._set_lim_and_transforms(self)
        yaxis_stretch = Affine2D().scale(pi * 2.0, 1.0).translate(pi, 0.0)
        yaxis_space = Affine2D().scale(1.0, 1.1)
        yaxis_text_base = \
            yaxis_stretch + \
            self.transProjection + \
            (yaxis_space + \
             self.transAffine + \
             self.transAxes)
        self._yaxis_text1_transform = \
            yaxis_text_base + \
            Affine2D().translate(-8.0, 0.0)
        self._yaxis_text2_transform = \
            yaxis_text_base + \
            Affine2D().translate(8.0, 0.0)

# register the projection on import
register_projection(AstroHammerAxes)

···

On Sep 18, 2010, at 6:02 AM, Jeff Whitaker wrote:

On 9/16/10 12:38 PM, Mario Juric wrote: