From: Jeff W. <js...@fa...> - 2004-07-13 22:51:49
|
On Tue, 13 Jul 2004, John Hunter wrote: John: > > OK, made some headway here. > > When profiling for performace, I often turn off the GUI so my numbers > aren't influenced by the user interface > > > /usr/local/lib/python/profile.py plotmap.py -dAgg > prof.out > > Here are the profile results sorted by cumulative time for your script > - only the most expensive functions are shown > > 7.590 proj.py:43(__call__) > 7.080 os.py:611(popen2) > 7.050 popen2.py:31(__init__) > 7.050 popen2.py:143(popen2) > 2.610 matlab.py:1305(savefig) > > On my system, over half the time is spent running your popen process. > Can't help you with this one :-). To get better numbers and focus on > matplotlib, I cached the xy points that the popen process is > generating to a pickled list. OK - looks like I have to work on the proj module. I probably should make it a C extension that calls the proj library directly instead of communicating with the proj application via pipes. > > You're using pcolor to generate the colormap. pcolor uses > collections, which is already pretty fast (agg implements collection > drawing in extension code, no python loops needed to make a pcolor). > However, you can get better performace still from imshow with the data > limits set. This will approximately double the performance of the > image part of the map. I had to make some changes to matplotlib (see > below) because image origin wasn't playing nicely with image extent - > this also fixes Andrew's bug. > > For the line part of the map, I extended the > matplotlib.collections.LineCollection class to handle a sequence of > lines, where each line is defined by a list of tuples (x0,y0), (x1, > y1), ... Thus all of your lines are handled by a single object, > rather than having 1800+ separate line objects created in plot. > Again, no python loops required. > > In the current form, the code takes about 1.15s to run on my machine > and is about 30x faster than the original code you posted which > includes the data loading part. Nonetheless, the matplotlib part is > much faster too, as you'll see when you interact with the data. > > I'm including a link to a matplotlib snapshot below which includes the > required changes. As a bonus, you can try out the new navigation > toolbar (in progress, only works w/ gtk and gtkagg). It includes a > view limits stack, hand pan, and zoom to rectangle. Much nicer for > map navigation. And with the changes, you can actually interact with > your data with reasonable performance. I need to add some more > features to the toolbar, but give it a test drive and let me know if > you have suggestions. Set 'toolbar: toolbar2' in matplotlibrc Excellent! I'll do some more work on it and repost a (hopefully) faster version. Thanks for the quick response. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/CDC R/CDC1 Email : Jef...@no... 325 Broadway Web : www.cdc.noaa.gov/~jsw Boulder, CO, USA 80303-3328 Office : Skaggs Research Cntr 1D-124 |