Beginners Guide: Using MODIS in R
This tutorial is going to assume that you are a beginner in R and Windows and working with MODIS. Obviously, if you already know R and Windows pretty well you can skip a bunch of steps. However, it will be good for you to walk through all the steps as I may do some things in the beginning that influence downstream work. As an overview here is what we are going to do. First we are going to update our R tools and make sure we have the fresh bits. Then we are going to spend some time getting familiar with the bits of the windows system that matter. Basically the console. If you don’t know how to build a package in R under windows, go walk through my package building tutorial.
Then we are going to download some MODIS data by hand and get some tools and utilities for working with MODIS data. If you just have a small job sometime it may be better to work “by hand”. At the end we will start using the MODIS package instead of doing things by hand. In very simple terms the MODIS package allows you to find and download MODIS data using “R” commands. More importantly, it allows you to control the tools, MTR and GDAL, from within R. So, first we do some things by hand downloading a file, using the tools by hand, and then we will use R programming to do the same thing. Trust me, when you have hundreds of MODIS files to download reproject and crop, working by hand is a PITA.
First things first however. I want to thank the MODIS R team for all the hard work they have done.
Matteo Mattiuzzi, Jan Verbesselt, Forrest Stevens, Tomislav Hengl, Anja Klisch, Bradley Evans and Agustin Lobo. Conrats on a great package
While it’s not necessary to start your process of building a package by updating your version of R to the current version, I started my process that way. Ordinarily I like to stay current with R and with all my tools. For this example I will be using version 2.15.1 The exact url for version 2.15.1 is
Its best to use this and actually see what version we are on
GET RSTUDIO (optional)
In addition to using R I also use RStudio which is a great cross platform IDE. I recommend it use. After updating my R I updated my RStudio from the following URL
I’m using version .96.331
When you have finished that it’s time to do a little review of your Windows System. For some of the tools we will need updating the PATH variables in windows may be required. If you never worked back in DOS and the early days of windows you may not be familiar with the PATH variable.
In order to build a package in R there are a couple things you need to understand about your Windows System. These are fairly trivial but if your coming from a different platform (like MAC) then you might not know where these things are. I will take some time to take you to a couple places on your Windows system. There are two bits that we are going to get familiar with: The console application, and the PATH variable.
First , we are going to locate the console application. You find this application by going to your start button in the lower left hand corner of your desktop
Open the start button select “All Programs” –>”Accessories” –>”Command Prompt”. The old reliable “DOS” Prompt.
The bit of the windows we may have to track down is the PATH Variable. Again, this is an environmental variable that the windows system uses to locate programs and insure that commands get interpreted correctly. To locate your PATH variable Start by clicking on the Start button. At the start panel select the control panel.
Next Select system and security
Next select System
Next on your left select Advanced system settings
At the bottom select Environmental Variables
In the lower Panel select the “Path Variable” and select Edit
That is how you will access your path variable when it comes time to edit it. At this stage I would copy the PATH variable and paste it to a simple txt document. Just in case we screw anything up and we need to recover. What we will be doing is adding various elements to that string and restarting the computer. So, make a copy now before we start. If you have none completed my tutorial on building windows packages I’ll suggest you do that now
The next step is to locate and download some sample MODIS data. later we will do this step in an automated fashion from inside R, but to gain some understanding of the external tools we will be calling from within R we will start by doing a few things manually.