Home > Uncategorized > Modis R: Package tutorial

Modis R: Package tutorial

The MODIS package for R

For people who work in GIS in R there has been a bit of challenge in working with data from  Modis. I’ll use an example from my own work on UHI to illustrate. A while back I decided that I wanted to look at albedo data from MODIS.  If you want to get MODIS data there are basically two approaches. You can use  the web services  like REVERB which is basically a web interface that allows you to construct queries for a wide variety of data ( or similar services shown here ) or you can download files directly from the datapool ftp.

For my Albedo project I decided to download directly from ftp because I could write a simple program in R to collect the entries in the ftp directories and then download them over the course of a few hours.  It’s essentially the same process I use in my study of SUHI for small cities. Getting the data locally is not a big problem, except for the storage issue.  You can imagine what it would take to download 90 days of LST data for the US.  with 10-14 tiles of data required that ends up being a nice chunk of data.

The next challenge is getting MODIS data out of its native format into a format that is friend for R GIS packages. In the case of Albedo that data was stored in a format known as “HDF” or HDF-EOS.  I work with  the raster package and raster ( along with rgdal)  have no way of reading HDF directly. This meant I had to find a way to transform HDF into a more common format like “geoTiff”. There was also the issue of tiling multiple hdf files into a single raster. Unlike other datasets that might give you a monolithic file of the whole world, the MODIS collections are distributed as tiles using their tiling system.

To solve this problem there are a couple tools: MRT or the modis reprojection tool. or GDAL, the Geospatial Data abstraction Library. For Albedo I decided to use GDAL and I used the distribution of GDAL provided by FWTools.  With a few hundred albedo files I had to write a script to load every Hdf file and transform it to a ‘geotiff’ file. That worked fine, but now I had a set of R code for doing my statistics and a “bat” file for controlling Gdal.  With my SUHI project I decided to use MRT. In that case I used the GUI they provide to select all the files, mosaic them, crop them, resample and reproject. I quickly learned that duplicating the same steps with a GUI is not always easy. Further, if I am trying to create work that is reproduceable, it makes it hard. Plus I could not see using that tool to create 365 maps for every day in the year.

What’s needed is an R package that allows us to write R code and achieve the same results as we get with GDAL or MRT. We want to write R code that controls these external applications and tools. That’s what  MODIS R does.

The team: The MODIS R team consists of  Matteo Mattiuzzi, Jan Verbesselt, Forrest Stevens, Tomislav Hengl, Anja Klisch, Bradley Evans and Agustin Lobo. Some of the seminal work was done by Tomislav at his wonderful page

My Tutorial.  I had some discussions with Matteo who is the package maintainer and  suggested that I might do a tutorial to help people get started with the package.  At this stage the package is stable, so I decided to start a tutorial. The way I work is pretty simple. As I try  new things I write them up.    For now the tutorial  starts with the basics of R, R studio and preparing your system for MODIS R. That includes downloading a the tools and testing them out and finally downloading and building a WINDOWS version of MODIS R.

Then I will start to go through the API and test and explain all the calls in more depth than the manual and write some sample code.

A note. If you have questions about what I am doing go ahead and leave comments. I can collect up questions and those I cant answer I can pass on to the maintainers.

The tutorial starts here

Categories: Uncategorized
  1. November 25, 2012 at 8:36 PM

    Hi Steve, thanks for writing a tutorial for the MODIS package. If there are questions that you or your readers have specifically regarding the Windows side of things, I’m happy to address them. Feel free to email me and pass any thoughts you have. Any feedback would be greatly appreciated and perhaps we could discuss collaborating to turn your tutorial into a vignette for the package?

    • Steven Mosher
      November 26, 2012 at 3:10 AM

      Sure thing Forrest. There are few things that need some explanation, but I’m beginning to get the hang of it.

  2. November 26, 2012 at 5:53 AM

    Wow, this looks like a really helpful thing Steve, thanks for doing this. Is it possible to throw some more general MODIS questions your way?

    • Steven Mosher
      November 26, 2012 at 6:59 AM

      Sure Jim, If I can’t answer them, then Matteo or Forest or Tomislav can probably chime in.
      What do you need?

      • November 26, 2012 at 7:08 AM

        Nothing urgent. The first thing I have to do is remind myself of all the MODIS basics which I’ve long since forgotten from lack of use, then read through a new paper and see how much I do and do not get.

        Main thing is I’m trying to now do all analyses–including all GIS work–in R, so these kinds of tutorials are potentially really useful, given what a splitting headache R is in general.

      • Steven Mosher
        November 26, 2012 at 7:19 AM

        Ok, no problem,

        The main challenge is getting the MODIS data into R. Once in R the challenge is figuring out which package to use. I use raster. Robert Hijmans is local to you and is super helpful. So, If I need something done in raster and he agrees its a good addition he very good about adding support. I’ve started a little work with landscape stats and a while back there were some guys working on FRAGSTATS for R, so just let me know and I’ll see if I can help or know the right guy for the job

      • November 26, 2012 at 9:12 AM

        Thanks a lot Steve, much appreciated. Looking forward to learning about this.

    • Steven Mosher
      November 26, 2012 at 7:00 AM

      sure fire away

  3. Maria
    November 30, 2012 at 6:26 AM

    thanks for sharing your http://www.sitepoint.com/tag/wordpress/

  4. Emma
    March 12, 2013 at 8:10 PM

    Hi, Is it possible to use this package to get the MODIS ocean colour data?

    • March 12, 2013 at 8:24 PM

      Unfortunately not at this time. The Ocean Color products are created and distributed completely separately and via different systems than the long-term MODIS archives.

  5. Leejiah
    May 14, 2013 at 4:35 AM

    Hi Steve, Iv been struggling to get runMrt() going on my Mac (im pretty new to R so it may be a simple solution but have been searching all evening and drawing blanks), iv got MODIS package installed and MRT installed. When I run runMrt I get ” MRT path not set or MRT not installed on your system!”, I got the impression that MRT automatically set up a path? If not where do I define the path? Thanks

  6. Luan
    July 9, 2013 at 2:11 AM

    Leejiah :
    Hi Steve, Iv been struggling to get runMrt() going on my Mac (im pretty new to R so it may be a simple solution but have been searching all evening and drawing blanks), iv got MODIS package installed and MRT installed. When I run runMrt I get ” MRT path not set or MRT not installed on your system!”, I got the impression that MRT automatically set up a path? If not where do I define the path? Thanks

    I have the same problem. Can someone help me? Thanks.

  7. August 3, 2019 at 10:26 AM

    Very helpful – thanks !!

  8. February 8, 2020 at 2:09 PM

    I just like the helpful info you supply for your articles.
    I will bookmark your blog and take a look at once more here regularly.

    I am rather sure I’ll be informed many new stuff proper
    right here! Best of luck for the next!

  9. February 15, 2020 at 12:21 PM

    Hi there Dear, are you really visiting this web
    site daily, if so afterward you will definitely get pleasant knowledge.

  10. February 21, 2020 at 12:44 PM

    hello!,I really like your writing so a lot! share we keep in touch
    extra about your post on AOL? I need an expert in this space to solve my problem.
    May be that is you! Taking a look forward to peer you.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: