Skip to content

Speed up Basemap / Pickling? #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ddale opened this issue Jun 20, 2011 · 2 comments
Closed

Speed up Basemap / Pickling? #265

ddale opened this issue Jun 20, 2011 · 2 comments

Comments

@ddale
Copy link
Contributor

ddale commented Jun 20, 2011

Original report at SourceForge, opened Mon Jun 12 02:49:17 2006

Thanks in advance for taking the time to reply to
this request.

I am using the Basemap package of matplotlib to
generate plots upon request from a website. The
website interface generates a datafile to be loaded
and ploted on top a global coastline map. Typically,
the following line of code takes about 4.5 seconds:

map = Basemap(projection='cyl',resolution='c')
map.fillcontinents ...

Having resorted to the crude resolution level, there
appears to be little else that can be done to
expedite this line of code.

One thought was to pickle the object and recover the
picked map object, although this was rather
unsuccessful:

from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import
FigureCanvasAgg as FigureCanvas

fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_axes([0.125,0.175,0.75,0.75])
pickle_file = open(pickle_path+"/glm.map.obj",'r')
map = pickle.load(pickle_file)
pickle_file.close()
map.set_axes_limits(ax=ax)
fig.set_figsize_inches((8,map.aspect*8.))
map.fillcontinents ...

This not only resulted in map being diassociated with
the figure axis (since the Basemap could not be
pickled after calling it with the ax=ax parameter)
but the pickle.load command took over 7 seconds
(worse than simply generating the plot from scratch
every time).

Is there a way to store the map object into a file
and plot the data on top of the loaded map object
each time the python script executes rather than
regenerating the Basemap each time and wasting 4.5
seconds?

Alternatively, perhaps there is a method I am not
aware of for writing a png or svg file and then
reloading the image and ploting on top of it to avoid
pickling?

Thanks again for the help.

Rupert Minnett
UCSD - SIO
IGPP - Scripps Institute of Oceanography

@ddale ddale closed this as completed Jun 20, 2011
@pelson
Copy link
Member

pelson commented Jul 18, 2012

One to be aware of #1020, which implements pickling of matplotlib figures (and their associated artists). This work could then potentially lead on to pickling of Basemap's, but I am not sure.

@pelson
Copy link
Member

pelson commented Jul 18, 2012

For the record, basemaps are already picklable: https://github.com/matplotlib/basemap/blob/master/examples/hires.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants