Basemap OO interface

Michael: By popular demand, I put this back in 0.5.1. You

    > can now pass an axes instance to any Basemap method. The
    > default is 'ax=None', in which case pylab.gca is used to get
    > the current one. Does this solve your problem?

You can potentially get into trouble by simply importing the pylab
module at all since pylab will try and import the default backend.
This usually isn't fatal, but isn't ideal either. I would suggest
conditionally importing pylab only if it is needed, eg when ax=None.

The use case you would be avoiding is for example when the user hasn't
changed the default backend (GTKAgg) from .matplotlibrc. They may be
using non-pylab basemap in pure agg mode over a web app server. When
you import pylab, the module will try and import pygtk, which will
fail if pygtk is not installed or if there is no X11 connection. Of
course, the user could change the default backend in the rc file, but
one point of the OO interface is to have as little magic as possible.
By conditionally importing pylab, you can avoid these kinds of
problems.

JDH

John Hunter wrote:

"Jeff" == Jeff Whitaker <jswhit@...146...> writes:
           
   > Michael: By popular demand, I put this back in 0.5.1. You
   > can now pass an axes instance to any Basemap method. The
   > default is 'ax=None', in which case pylab.gca is used to get
   > the current one. Does this solve your problem?

You can potentially get into trouble by simply importing the pylab
module at all since pylab will try and import the default backend.
This usually isn't fatal, but isn't ideal either. I would suggest
conditionally importing pylab only if it is needed, eg when ax=None.

The use case you would be avoiding is for example when the user hasn't
changed the default backend (GTKAgg) from .matplotlibrc. They may be
using non-pylab basemap in pure agg mode over a web app server. When
you import pylab, the module will try and import pygtk, which will
fail if pygtk is not installed or if there is no X11 connection. Of
course, the user could change the default backend in the rc file, but
one point of the OO interface is to have as little magic as possible.
By conditionally importing pylab, you can avoid these kinds of
problems.

JDH

John: OK, I've fixed it so pylab is not imported at all if either (1) the 'ax' keyword is used in Basemap.__init__ (in which case only one axes instance is used by that Basemap instance), or (2) the 'ax' keyword is used in all Basemap method calls that do drawing (in which case different axes may be used by the same Basemap instance). If you don't use the 'ax' keyword, basemap methods behave like their pylab counterparts (i.e. pylab.gca is used to get the current axis).

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/CDC1 FAX : (303)497-6449
325 Broadway Web : http://www.cdc.noaa.gov/~jsw
Boulder, CO, USA 80305-3328 Office: Skaggs Research Cntr 1D-124

Jeff Whitaker wrote:

John: OK, I've fixed it so pylab is not imported at all if either (1) the 'ax' keyword is used in Basemap.__init__ (in which case only one axes instance is used by that Basemap instance), or (2) the 'ax' keyword is used in all Basemap method calls that do drawing (in which case different axes may be used by the same Basemap instance). If you don't use the 'ax' keyword, basemap methods behave like their pylab counterparts (i.e. pylab.gca is used to get the current axis).

Nice job Jeff. You've come up with a solution that satisfies a wide variety of uses. Hurray for keyword arguments!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Great! That's perfect for us. Thanks for the quick response.

We have exactly the setup that John was describing. We use Basemap in cron jobs that don't have any X windows support. Our default backend is Qt, and Qt itself aborts and core dumps (!) if you try to use it when there's no X server present. So we wanted to avoid pylab loading a backend.

I guess we'll see these changes in the next release, 0.5.2 or 0.6, whichever is next, yes?

Thanks again,

Michael

···

On Tue, 28 Jun 2005, Jeff Whitaker wrote:

John: OK, I've fixed it so pylab is not imported at all if either (1) the 'ax' keyword is used in Basemap.__init__ (in which case only one axes instance is used by that Basemap instance), or (2) the 'ax' keyword is used in all Basemap method calls that do drawing (in which case different axes may be used by the same Basemap instance). If you don't use the 'ax' keyword, basemap methods behave like their pylab counterparts (i.e. pylab.gca is used to get the current axis).

========================================================================
  Michael Brady
  Jet Propulsion Laboratory (M/S 301-140L)
  4800 Oak Grove Drive
  Pasadena, CA 91109 E-mail: Michael.Brady@...369... ========================================================================