Skip to content

Instantly share code, notes, and snippets.

@smeschke
Last active August 17, 2016 20:57
Show Gist options
  • Save smeschke/351a97dd8b0d81482817404d3c7b5e53 to your computer and use it in GitHub Desktop.
Save smeschke/351a97dd8b0d81482817404d3c7b5e53 to your computer and use it in GitHub Desktop.
Plotting the Proliferation of Mormon Temples with Basemap
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import csv
#get list of temple name, location, dedication data, lat, and lon
path = '/home/sm/Desktop/temple_data.csv'
temples = [] #create a list to store the temple data from the spread sheet
with open(path, 'rb') as csvfile: #open the csv file
temple_data = csv.reader(csvfile, delimiter=',', quotechar='"') #load temple data
for temple in temple_data: #iterate through data to change year to int
try:
year = int(temple[2][-4:])
temples.append((temple[0],temple[1],year,temple[3],temple[4]))
except: temples.append((temple[0],temple[1],2016,temple[3],temple[4]))
#sort list by dedication date
temples = sorted(temples, key=lambda temple: temple[2])
year = temples[0][2] - 10 #ten years before the earliest dedication date
while year < 2040: #iterate through years, mapping each temple
m = Basemap(projection='mill') #create map (m)
m.drawcoastlines()
#m.drawcountries()
#m.bluemarble()
print 'Year: ', year #print the year in the terminal (to monitor progress)
temples_plotted = 0 #let's count the number of temples on the map
for temple in temples: #check to see of each temple should be plotted
if temple[2] <= year: #if the temple was built
x, y = m(float(temple[4]), float(temple[3])) #interpolate coordinates
size = temple[2]-year+15 #more recently built temples are larger
if size<5: size=5 #minimum size is 5
m.plot(x, y, 'go', markersize=size, alpha=1, color='r') #plot the temple on the map
if temple[2]==2016: m.plot(x, y, 'go', markersize=size, alpha=1, color='b') #future planned temples are blue
temples_plotted += 1
#make the title
y = 2016
if year < y: y = year
plt.text(0,0,' # of temples built:'+str(temples_plotted))
plt.title('Mormon Temples built by year '+str(y))
#plt.show() #show the map
plt.savefig('/home/sm/Desktop/mormon_img/'+str(year)+'.png') #save the map
plt.clf() #clear the plot
year+=1 #go to the next year and repeat
@smeschke
Copy link
Author

smeschke commented Aug 3, 2016

@smeschke
Copy link
Author

smeschke commented Aug 3, 2016

  1. Collect data from https://www.lds.org/church/temples/find-a-temple?lang=eng.

  2. Copy and paste to a spread sheet, format. Title: temple_data. (there is a link to this spreadsheet above)

  3. Use batch geocode (Google, 'batch geocode') to find lat and lon coordinates

  4. Run python program.

  5. Complile images into a .gif using the following terminal commands:

    sudo apt-get install imagemagick

    convert =delay 10 -loop0 *.png morman_gif.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment