Saturday, March 30, 2013

Playing with data from NOAA Global Forecast System using python

Bugger! Blogger barfs out an error when I attempt to upload my ipython notebook. You can find the notebook on github or as a rendered html here.

Here are some pretty generated images:
Horn of Africa zoomed in (Mar 27 2013)

Global 2M temperature in degrees C (Mar 27 2013)

Thursday, March 28, 2013

Kenya DOB density plot

Here is a density plot of a sample of Kenyans  based on their year of birth. It's interesting to see the dips correlate with turbulent times; political and military. In the diagram below, the largest unexplained dip is in the early 1970s. Anyone care to explain it; Google and Wikipedia don't return any results?
Click here for a larger image

EDIT:
Could it be the 1969 Kisumu incident?



 


Here is the code used to produce the graph in R
require(ggplot2)
# load the data and cast the dob into dates
data <- read.table("/tmp/data.raw")
names(data) <- c("dob")
data$dob_date <- as.Date(as.character(data$dob), "%Y")
# build graph and preview
p = ggplot(data, aes(dob_date))
p = p + geom_density()
p = p + scale_x_date(breaks = "5 year", minor_breaks = "1 year", labels = date_format("%Y"))
p + annotate("text", x = as.Date("1952", "%Y"), y=0, label = "MauMau", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1941", "%Y"), y=0, label = "WW2", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1963", "%Y"), y=0, label = "Independence", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1982", "%Y"), y=0, label = "Coup attempt", angle=90, hjust=0, size = 5)
#save to png
png("/tmp/kenya_population_density.png", 1600, 800)
p + annotate("text", x = as.Date("1952", "%Y"), y=0, label = "MauMau", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1941", "%Y"), y=0, label = "WW2", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1963", "%Y"), y=0, label = "Independence", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1982", "%Y"), y=0, label = "Coup attempt", angle=90, hjust=0, size = 5)
dev.off()