Examples of Work

Throughout my Academic research, I have encountered a number of projects where I have put in a lot of work, only to have it not result in publishable material. The purpose of this page is to allow me to put some material out into the world that I have spent a long time working on, but have never presented in a meaningful way.


Double Graphing in R

A former colleague asked me for some graphing help, and I suggested she port the process to R. Her previous workflow involved editing lots of excel graphs by hand, which is anathema to me. She sent me the data and it looked like a pretty obvious scripting example. Below is the final image and the script

This image was created from the code below


library(foreign)
rm(list=ls(all=T))
options(scipen = 50, digits=6)

setwd("C:/Temp/Mary")
metals <- read.csv("Premier_Total.csv")
metals$CollectDate = as.Date(metals$Collect_Date, "%d/%m/%Y")

stn_list <- unique(metals$Stn_Code)
stn_name_list <- unique(metals$Station_Name)

for (i in (1:length(stn_list))){
#Get the current station data
current_stn_code <- stn_list[i]
current_stn_name <- stn_name_list[i]
current_stn <- metals[which(metals$Stn_Code == current_stn_code),]

#Store the resultant image as a png
png(filename=paste("C:\\Temp\\Mary/", current_stn_code, ".png", sep=""), width=640, height=450)
par(mar=c(5,4,4,4))

#Remove NAs
cdTotal = current_stn$CD.TOTAL
cdTotal[!is.finite(cdTotal)] = 0

yLimit = range(c(0.005, 0.000017, cdTotal))

plot(current_stn$CollectDate, cdTotal, type="l",
main = paste(current_stn_name, " (", current_stn_code, ")", sep =""),
xlab = "Date", ylab = "CD: TOTAL CADMIUM (mg/l)", col = "Red", axes=F, ylim=yLimit)
points(current_stn$CollectDate, cdTotal, pch=20, col="Red")
abline(h = 0.005, col = "lightgray")
abline(h = 0.000017, col = "lightgray")

# Set the labels for the x axis
startDate = (min(current_stn$CollectDate))
maxDate = (max(current_stn$CollectDate))
axis(1, at=seq(startDate, maxDate, by=(maxDate - startDate)/5),
lab=as.Date(seq(startDate, maxDate, by=(maxDate - startDate)/5)))
axis(2)

# Add the second plot and y axis
par(new=T)
#Convert NA to 0
flow = current_stn$FLOW_RATE
flow[!is.finite(flow)] = 0
if (sum(flow) > 0) {
#flow = density(flow)
plot(current_stn$CollectDate, flow, type="l", pch=20, col="blue", axes=F, ylab="", xlab="")
points(current_stn$CollectDate, flow, pch=20, col="blue")
axis(4)
mtext("Flow Rate (m3/s)",side=4,line=3)
}
legend("topright", c("= CD", "= FLOW"), col = c("Red", "Blue"), pch = c(20,20), bg = "White", inset = 0.01)
dev.off()
}


Topographic Ruggedness Index

Someone sent me an AML script to calculate TRI and asked if I could help. I couldn't because, like most people born after the age of punchcards, I don't get AML; I don't even have ArcInfo Workstation installed. Rather than learn how to do this in AML, I wrote an IDL scipt to do it. This is moving window stuff, which I think I am programming effectively, but very slowly

Riley, S. J., S. D. DeGloria and R. Elliot (1999). A terrain ruggedness index that quantifies topographic heterogeneity, Intermountain Journal of Sciences, vol. 5, No. 1-4, 1999.

Download script here

Web Mapping with Google Maps

This example is my first foray into web mapping using the Google Maps javascript API. The goal of the page is to:

Web Map Showing South American Back Packing Trip


Calculating directional distance

A friend of mine in the Geography Department asked if I could assist in some "basic" GIS processing. I quote basic as I assumed it would be relatively easy. The idea was to determine directional distance from a feature in one layer to the nearest feature in another layer. The direction of search is based on 360 degree geographic direction (North is 0, clockwise increase). This turned out to be more difficult than originally expected, however the final result works rather well.

The solution was to create a polyline object that ran from the point of interest 1000000 m in the search direction and intersecting with the other layer. The distance to the intersecting point was calculated, and the minimum distance was kept. The zip file below contains the .vb file and the associated form. Feel free to contact if this interests you. Problems encountered included:

Download Zip File


Spatially Autoregressive Models

For part of my first thesis paper, I attempted to implement spatially autoregressive models to explain the association between grizzly bear location and the location of landscape edges. See this Google Scholar Link for a series of associated research articles. My basic understanding of these models is that they use local neighbourhood definitions to eliminate spatial auto-correlation in spatial data. As my data are telemetry locations collected every hour or two, there is inherent spatial auto-correlation, so SAR models made sense

Unfortunately, after discussion with my supervisor, we decided to investigate a randomization process to determine an expected distribution, and the SAR model stuff was put by the wayside. However, I would like to make this information available somehow, so feel free to peruse the code below to see how it was implemented.

Download Code