Python makes the world go ’round

One of our projects involves running the VIC model over the globe at 1-degree cell resolution. We’ve been doing all the post-processing and plotting in Python. Here are some examples that you might be able to use.

First, we want to plot our data on a flat map projection. There’s a nice plugin for Matplotlib called Basemap (just Google it), which is akin to Matlab’s mapping toolbox. Here’s an example of the nice output you can get using Basemap’s “shaded relief” function. You may want to click the image to view it in a new tab to get the full effect.

Maps_Fraction_Below_Error_marble

Here’s a gist with the code for this example. You’ll have to use your own data, obviously, but you should be able to pull the important Basemap functions. Note this figure was combined in Illustrator; the four panels were generated separately.

Ok, that’s all well and good, but it’s so … static. Just for kicks, let’s make a globe that spins around! (Here’s the gist). You can see the main loop that changes the point of focus on the globe, which gradually creates the effect of seeing it spin around.

It’s not quite as easy as just making an animation. You have to save separate image files, and then stitch them together with ImageMagick on the command line. This could be something like:


convert -delay 7 -loop 0 globeframes/*.png globe_error_new.gif

But I realized I had too many frames, and I wanted to choose just every other frame to combine into a gif. There might be better ways of doing this, but I came upon an awk one-liner:


convert -delay 7 -loop 0 `find globeframes/ -type f | awk 'NR % 2 == 0'` globe_error_new.gif

And voila! (Click the figure below to watch the animation–it’s too big to put inline).

globe_error_new

Advertisements

One thought on “Python makes the world go ’round

  1. Pingback: Water Programming Blog Guide (Part 2) – Water Programming: A Collaborative Research Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s