Smathermather's Weblog

Remote Sensing, GIS, Ecology, and Oddball Techniques

Posts Tagged ‘Karisoke’

Gorilla Food Plants Biomass and Ranging

Posted by smathermather on July 4, 2017

The last two days, I have been working with Olivier Jean Leonce Manzi here at Karisoke Research Center on the question of the relationship between gorilla food plants biomass and the ranging patterns of gorillas outside Volcanoes National Park (VNP) in Rwanda.

A view from the edge of VNP looking toward Mounts Mgahinga and Muhabura

A view from the edge of VNP looking toward Mounts Mgahinga and Muhabura

Even though Volcanoes National Park is set aside and gorillas thrive inside, they don’t strictly stay within the bounds of the park — often leaving the park to forage in the adjacent farming communities. This tendency is an opportunity for human / wildlife conflict, and thus it is important to understand the relationship between gorilla browsing habits outside the park and their food resources in these farming communities.

Among the food plants in the study, eucalyptus, a non-native, is planted widely in Rwanda as a fast growing timber source. Gorillas like to climb up eucalyptus, stripping the outer bark, and use their teeth to scrape the inner bark from the tree. For larger trees, this seems to have little effect. For smaller trees, it can kill the tree easily, either by the weight of the gorilla on the tree or the damage to the vascular system of the tree.


Eucalyptus trees planted near VNP. Eating the inner bark of Eucalyptus is a favorite food of gorillas. For larger trees, this seems to have no effect. For smaller trees, this can maim or kill the non-native tree plantings.

Eucalyptus trees planted near VNP. Eating the inner bark of Eucalyptus is a favorite food of gorillas. For larger trees, this seems to have no effect. For smaller trees, this can maim or kill the non-native tree plantings.

Bamboo, native to the region, is widely planted outside VNP (and grows in forests inside VNP). As it sprouts during rainy season, it is a favorite food of gorillas both inside and outside the park.

Small bamboo stand outside VNP.

Small bamboo stand outside VNP.

Olivier’s study area is in the farming area along the base of Karisimbi and Bisoke Volcanoes just outside VNP.  (Quick aside: it was a combination of Karisimbi and Bisoke names that formed Karisoke Research Center’s name).

Map of study area near Karisimbi and Bisoke Volcanoes outside Volcanoes National Park.

Map of study area near Karisimbi and Bisoke Volcanoes outside Volcanoes National Park.

The two datasets we want to compare for the study are counts of gorillas ranging outside the park and transects of gorilla plant food biomass, also outside the park.

Gorilla from the Amahoro (Peace) group in a bamboo stand during rainy season. (Amahoro group is not part of this study.)

Gorilla from the Amahoro (Peace) group in a bamboo stand during rainy season. (Amahoro group is not part of this study.)



Map of gorilla sightings outside VNP within our study area.

The measurements that Olivier made on gorilla plant food biomass is that of herbs (overall), trees (overall), eucalyptus, bamboo, and rubus (a group commonly known as raspberries, blackberries, dewberries, etc.) — favored foods for gorillas especially outside the park.


Vegetation plot locations along border of VNP

For the purposes of analysis, Olivier grouped the vegetation plots and gorilla counts into 18 approximately equal zones. Gorilla counts and vegetation plots were summarized per zone and compared.


I remember his project as one of the more difficult ones to wrap my head around when I was here in December. In summary, here’s the problem that we wanted to solve: given a dataset of gorilla food biomass outside the park, and counts of gorillas outside the park, can we establish a relationship between the two. It should be an easy problem: on one side of the equation, we have count data, on the other ratio data. My first thought would be to apply a Poisson approach.

Gorilla.count ~ Herbs.biomass + Tree.biomass + Eucalyptus.biomass + Bamboo.biomass + Rubus.biomass

But we quickly run into a problem: our data are not independent in time or in space, and so a simple Poisson approach is likely not appropriate.

For as much work as I’ve done in the geospatial space, I have done precious little with spatial statistics, so this posed a conundrum to me. I can’t remember now if it was through much googling, or the great stewardship of Dr. Patrick Lorch, the research manager at my institution, that we settled upon using a Markov chain Monte Carlo (MCMC) approach to the problem. The advantage to this approach is that we can do the analysis using a Poisson distribution without regard to autocorrelation. In the R statistical package, this is an easy analysis to set up.

Finally, we’ll close with a picture of Olivier working on his literature review for the methods section:


Posted in Ecology, Gorillas, Karisoke, National Park, R | Tagged: , , , , , , | 1 Comment »

A little Gorilla Time

Posted by smathermather on June 12, 2017

I miss my mountain gorilla friends in Rwanda. Let’s write a little more code to support them. I’ll be visiting Karisoke again next week, so it seems timely to post a little more code (HT Jean Pierre Samedi Mucyo for working with me on this one).

The problem today is simple — given a time series of gorilla locations and dates, can we calculate rate of travel using PostgreSQL? Well, of course we can. We can do anything in Postgre.

We have two tricks here:

  1. The first is to order our data so we can just compare one row to the next.
  2. Once we do that, we need simply to use PostGIS to calculate distance, and ordinary time functions from Postgres to calculate time difference.

This is my first use of WITH RECURSIVE, and it’s probably unnecessary (could be replaced with windowing functions), but I was very proud to finally get over my fear of WITH RECURSIVE . (We actually use one windowing function in our prep of the data. But there we are… ).


For the record, WITH RECURSIVE isn’t recursive, but it is useful here in allowing us to compare the current row with the previous.

Posted in Database, Ecology, Gorillas, Karisoke, National Park, PostgreSQL, SQL | Tagged: , , , , | Leave a Comment »

Quantitative analysis of gorilla and monkey movement and R-Stat (part 3)

Posted by smathermather on February 16, 2017

This blog post is from a series of posts on gorilla and biodiversity research in Rwanda. I have introduced the people, the place, and a little on the beasties there. Now we’ll talk some R-code for doing home range estimation.

Home range estimation is a pretty deep and also abstract concept. Heuristically, it is the process looking at where an animal or group of animals move in the world. If one were to create a home range map for me, it’d be a pretty simple bimodal map of home and work.

Where it gets funky, is what does one do with the unusual places that an animal travels. So, for my home range, I am mostly at work, home, church on Sundays, yoga, and the grocery store. But I did spend 2 weeks in Rwanda, one week in Tanzania, one week in Belgium and the Netherlands, one week in Seattle, one in Raleigh, etc. etc.. Should these places be part of my home range?

All this to say usually home ranges are calculated with some means to not include the less common places. I would be happy if East Africa were part of my home range, but I think it’s arguable that it is not yet so.

Also, depending on the approach we use, travel between places may or may not be considered part of the home range. Back to my home range: ideally even if we concluded that 2 weeks living in Rwanda expanded my home range to include Musanze, the flight there and back probably shouldn’t be included in my home range. For our work today, we are not going to be excluding travel from our home range calculations, but understand that it can be relevant to some home range calculations.

For our home range calculation today, the following assumptions will be made:

  • We won’t be explicitly excluding travel from our home range calculations.
  • We’ll use simple techniques to exclude ephemeral portions of the home range

For basic home range analysis, we’ll use R’s adehabitat home range (adehabitatHR) package.

# Load the adehabitatHR library
# Load appropriate libraries for loading and manipulating data
library(sp) # Spatial data objects in R
library(rgdal) # Geospatial Data Abstraction Library
library(adehabitatHR) # Adehabitat HomeRange
library(readr) # File read capacity
library(rgeos) # Geometric calculation to be used later
library(maptools) # more spatial stuff

Now that we have every library we need loaded (and maybe then some) let’s load the data.

# We need to add a data filter here... .
# For now, we assign just the columns we need for HR calculation
loc_int_totf <- loc_int_tot[,c('X','Y', 'id')]

We’ll want to explicitly turn these data into geospatial data.

# Use sp library to assign coordinates and projection
coordinates(loc_int_totf) <- c("X", "Y")
# Our projection is UTM Zone 35S
# proj4string acquired at
proj4string(loc_int_totf) <- CRS("+proj=utm +zone=35 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs") 

Now we are ready to do some home range calculations. We’ll use the kernelUD function to convert our data into a surface representing our home range estimate. The total of all the pixels in this surface (as represented by a raster) will total to 1, or 100 of the home range.

# Estimating the utilization distribution using "reference" bandwidth
kud <- kernelUD(loc_int_totf)

# Display the utilization distribution

Kernel density map

Recall that the total of all the pixel values here is 1. This means that this image represents 100 percent of the calculated range of the Golden Monkeys. If we want to calculate the 70% homerange (what we estimate the golden monkeys spend 70% of their time in) we would do so as follows:

# Estimate the homerange from the utilization distribution
homerange <- getverticeshr(kud, 70)

Outline of 70% home range

Now it would be useful to convert this to a data frame so that we can further manipulate and understand the data. For example, what is the home range size for any given percentile?

# Calculate home range sizes

# Calculate home range sizes for every 5% from 50-95%
ii <- kernel.area(kud, percent=seq(1, 99, by=1))

Plot comparing home range % vs hectares

Finally, it would be nice to be able to get these data out of R and display alongside other GIS data. We’ll use writeOGR as part of RGDAL to do so.

# Write out data
writeOGR(homerange, getwd(),
         "homerange", driver="ESRI Shapefile")

That’s it for today. This bit of R will serve as the core code for a range of different analyses. Stay tuned!

Posted in Gorillas, Karisoke, R | Tagged: , , , , | Leave a Comment »

Gorilla research in Musanze, Rwanda: Hillshades continued

Posted by smathermather on January 30, 2017

I’ve been working on base cartography for the research area in Rwanda. Unlike here in Cleveland, we have some great topography to work with, so we can leverage that for basemaps. But, it’s such a beautiful landscape, I didn’t want to sell these hillshades short by doing a halfway job, so I’ve been diving deep.


First, some legacy. I read three great blog posts on hillshades. One was from ESRI revealing their “Next Generation Hillshade”. Drawing on Swiss Cartographic Traditions, these are some nice looking hillshades using lighting sources from multiple directions (more on this later):

ESRIs Hillshades

Next, we look to Peter Richardsons’s recent post on Mapzen’s blog regarding terrain simplification.

Terrain Generalization example from Mapzen

Terrain Generalization example from Mapzen

I tried (not nearly as hard as I should have) to understand their code, when I saw a link to Daniel Huffman’s blog post from 2011 on terrain generalization: On Generalization Blending for Shaded Relief.

That’s when I saw the equation:

((Generalized DEM * Weight) + (Detailed DEM * (WeightMax – Weight))) / WeightMax

I’ll let you read these posts, rather than rehashing, but here’s what I did toward adding to them. The gist of Daniel and Peter’s approach is to blend together a high resolution and lower resolution version of the DEM based on a weighting factor. Both use a standard deviation filter to determine where to use the high resolution DEM vs resampled version — if the location is much higher or lower than it’s neighbors, it is considered an important feature, and given detail, otherwise the low resolution version is used (actually, I suspect Mapzen’s approach is only highlighting top features based on their diagrams, but I haven’t dived into the code to verify).

The Need

Excuse the colors, we’ll fix those at the end, but this allows us to simplify something that looks like this:

Multicolor hillshade with no simplification

Multicolor hillshade with no simplification

Into something that looks like this:

Multicolor hillshade with simplification

Multicolor hillshade with simplification

See how the hilltops and valleys remain in place and at full detail, but some of the minor facets of the hillsides are simplified? This is our aim.

I developed a pure GDAL approach for the simplification. It is purely command line, has hardcoded file names, etc, but could be done with a python or other API and turned into a proper function. TL:DR: this is not yet refined but quite effective.

Landscape Position

If you’ve been following my blog for a while, you may recall a series of blog posts on determining landscape position using gdal.

Landscape position as calculated on a DEM

Landcape position

This, with small modification, is a perfect tool for determining where to retain DEM features and where to generalize. The one modification is to calculate standard deviation from our simple difference data.

The Tools


Back to those ugly colors on my hillshade version of the map. They go deeper than just color choice — it’s hard not to get a metallic look to digital hillshades. We see it in ESRI’s venerable map and in Mapbox’s Outdoor style. Mapzen may have avoided it by muting the multiple-light approach that ESRI lauds and Mapbox uses — I’m not sure.

HDRI (Shading)

To avoid this with our process (HT Brandon Garmin) I am using HDRI environment mapping for my lighting scheme. This allows for more complicated and realistic lighting that is pleasing to the eye and easy to interpret. Anyone who has followed me for long enough knows where this is going: straight to Pov-Ray… :


The results? Stunning (am I allowed to say that?):

Example of simplified and HDRI rendered hillshade.

Example of simplified and HDRI rendered hillshade.

Hillshade over the hills of Rwanda

The color is very simple here, as we’ll be overlaying data. Please stay tuned.

Posted in GDAL, Gorillas, Karisoke, Optics, POV-Ray, QGIS, R | Tagged: , , , , , , , | Leave a Comment »

Gorilla research in Musanze, Rwanda: Hillshades!

Posted by smathermather on January 22, 2017

In previous posts here1, here2, and here3 discussed a then and future trip to Rwanda to help with GIS and gorilla research.

No more in depth write up yet, but I’ve been working on some of the cartographic products to show in the background of maps. Since Rwanda is so beautifully hilly (read: mountainous) and the research is focused on the Virunga Mountains (volcanoes) themselves, this is a huge opportunity for some hillshades to figure in the background of some maps.

So… the following image probably won’t make its way into production maps, but it is very painterly and beautiful, so I thought I’d share it:

Hillshade of the Virungas and surrounding areas.

Hillshade of the Virungas and surrounding areas.

Posted in Gorillas, Karisoke, QGIS, R | Tagged: , , , , , , | Leave a Comment »

Gorilla research in Musanze, Rwanda

Posted by smathermather on January 18, 2017

In previous posts here1 and here2, I discussed a (then future) trip to Rwanda to help with GIS and gorilla research.

I cannot say enough good about the experience. The people of Rwanda are warm and welcoming, the research team at Karisoke (Dian Fossey Gorilla Fund International) hard working, brilliant, and fun. For now we’ll do some pictures to give flavor. Then I’ll build out the narrative and code in the next few blog posts:

Mount Mgahinga over Musanze Town

Mount Mgahinga over Musanze Town

Mount Sabinyo over Musanze Town

Mount Sabinyo over Musanze Town


Class on QGIS, First Day

A little Karisoke Soccer/Football. No GIS Managers were injured in the filming of this video:


Samedi Mucyo working on some QGIS2ThreeJS for visualizing Golden Monkey ranging data

Potato fields below Mount Bisoke

Stay tuned for more!

Posted in Gorillas, Karisoke, QGIS, R | Tagged: , , , , | 1 Comment »

Quantitative analysis of gorilla movement and R-Stat (part 2)

Posted by smathermather on November 23, 2016

In my previous post, I did a bit of setup on the who and what for analyzing gorilla data. Now let’s move into R-Stat a little bit, specifically installation and configuration.

For R, we’ll install whatever package is the correct one for your machine, and then also install R-Studio. This gives us a nice development environment for R.

Screen shot of R-Studio

We’re going to leverage a few packages in our work. The first is the “sp” package. This gives us “CLasses and Methods for Spatial Data” in R:


We’ll also “rgdal”. This package gives us “Bindings for the Geospatial Data Abstraction Library”. For our use case here, this allows us to read shapefiles, geotiffs, and other spatial data.


We’ll use “rmarkdown” also. This allows us to build a markdown file (think HTML but much simpler) that includes our code in code blocks, and can be compiled to a document whether a web page, pdf, etc.. This encourages us to write code and document it in one place, and ultimately will allow us to build some really great reporting functionality while getting our analysis work done.


Finally, we’ll need the adehabitatLT package for aiding in our analysis of animal movement and habitat use.


We can, of course install all this in one swell foop as follows:


Now we have all the building blocks we need to start analyzing our data. Stick around for part 3.

Posted in Gorillas, Karisoke, R | Tagged: , , , , | 2 Comments »

Quantitative analysis of gorilla movement and R-Stat

Posted by smathermather on November 21, 2016

At this point in my career, it is a rare request that intimidates me. Most requests are either solved, largely solved (and I know how to find the answer), or broadly improbably / excessively expensive.

XKCD cartoon demonstrating the difficulty of distinguishing difficult problems in computer science

This is a nice place to be. I have a bit of calmness with every request, a vision for how to execute, or the escape valve of saying, “That’s harder / more expensive than you think. Perhaps we should look at these alternatives.”

Recently, I got a request that was tougher — a theoretically possible project at the edge of my knowledge domain, a desire to deliver at any reasonable cost, and no clear sense of who to ask for help.

Specifically, how does one take volumes of gorilla tracking data, and make sense of the behaviors and intentions implicit in their movement? Many know the story of Dian Fossey, the primatologist who lived with the mountain gorillas in Rwanda. What many may not know, is her research continues in Rwanda at Karisoke Research Center (and has continued for 50 years), following the troops of gorillas in Rwanda, and the project has expanded quite a bit under auspices of the Dian Fossey Gorilla fund:

Map of Africa

Map of East Africa centered on Rwanda

Map of Rwanda

Zoomed in map of Rwanda centered near Karisoke

Image of Karisoke then and now

I have the privilege of being sponsored by the Cleveland Zoological Society to got to Karisoke, observe the research, and help where needed with GIS infrastructure development and geospatial analyses. I am excited beyond belief.

So, what’s the test here? I know how to do geospatial infrastructure. Ask me to improve infrastructure and I have a decade of experience chasing down these problems, trying out different technologies, developing new ones. I also know how to perform advanced analyses. I pride myself on my analytic skills, even as I’ve moved from analyst to programmer to manager, etc.. But, I’ve never done the more advanced quantitative analyses of movement necessary to deepen understanding beyond work already done at Karisoke. Lots of great minds have already been looking at the data for years and decades. The basic question in my mind — how can I meaningfully help?

Thanks to my colleague Dr. Patrick Lorch, I have some sources. Pat did his thesis work studying the movements and behavior of Mormon crickets in the western US, and his experience with quantitative analysis of movement is directly applicable.

First we looked to Peter Turchin’s Quantitative Analysis of Movement. Then we found the adehabitat R-Stat module.

In short, the next few blog posts will be about the apparently incomparably beautiful nation of Rwanda, mountain gorillas, R-Stat, and adehabitat. There will be PostGIS mixed in for good measure. Stay tuned.

Posted in Gorillas, Karisoke, R | Tagged: , , , , | 3 Comments »