Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Spinning World Population Density
# Resulting video from this code can be seen here:
# or
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import os
file = 'gl_gpwv3_pcount_00_ascii_25/glp00g.asc'
pop_data = np.loadtxt(file, skiprows=6)
# data file from here:
xo = np.arange(-180,180,0.0416666666667)
yo = np.arange(-58,85,0.0416666666667)
xx,yy = np.meshgrid(xo,yo,indexing='xy')
# go from positive to negative, make globe spin correctly
for lon in xrange(180,-180,-1):
print(i+1, ' ', lon)
map = Basemap(projection='ortho', lat_0=10, lon_0=lon, resolution='l')
xm, ym = map(xx,yy)
map.contourf(xm, ym, np.log10(pop_data[::-1, :] +1),
map.drawmeridians(np.arange(-180, 181., 60.))
plt.savefig("img/frame" + format(i, '04') + '.jpeg')
i = i+1
# render the video file using FFMPEG
os.system('ffmpeg -r 20 -i img/frame%04d.jpeg -qscale 1 movie.mp4')

This comment has been minimized.

Copy link

dfm commented Feb 23, 2015

My heart stops when I see people overload built-in functions like map!


This comment has been minimized.

Copy link
Owner Author

jradavenport commented Jan 29, 2016

Ahhhhh.... good call. That is very sloppy on my behalf.

Kids, don't do what I did! On Line 24, that should have read:

bmap = Basemap(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.