Installing MODIS for R

If you have installed MRT and OsGeow4, and reviewed the Modis data on datapool, then you are ready for the next step: Installing MODIS  package. At the current writing the package is not posted to CRAN, that will happen in due course. If you want to get started, then, you’ll have to install it from source using bits available at R Forge.

Before I show you how to do that,  let me pull up the description file from the package

Package: MODIS
Version: 0.6-22
Date: 16-November-2012
Title: MODIS download and processing package. Processing
functionalities for (multi-temporal) MODIS grid data.
Depends: R (>= 2.10), raster, bitops
Suggests: RCurl, rgeos, XMLSchema, rgdal, mapdata, maptools, plotrix,
SSOAP, XML, snow, ptw
Author: Matteo Mattiuzzi, Jan Verbesselt, Forrest Stevens, Tomislav Hengl, Anja Klisch, Bradley Evans and Agustin Lobo
Maintainer: Matteo Mattiuzzi <matteo.mattiuzzi@boku.ac.at>
Description: MODIS download and processing Package. Downloading, re-projecting, re-sampling, mosaicking, format conversion, SDS-extraction, bit-enconding and filtering/smoothing capabilities. Download data from FTP (local processing) or using SSOAP (online processing) via the MODIS web-service. Pre-processing data with MRT, GDAL, FWT, SSOAP. Starting from version 0.3-14 also SRTMv41 can be downloadad. Manual: https://www.dropbox.com/sh/18t0rgcm6bga7xt/-4k_Xwojxr/MODIS
URL: http://r-forge.r-project.org/projects/modis/
License: GPL (>=3)
LazyLoad: yes
Repository: R-Forge
Repository/R-Forge/Project: modis
Repository/R-Forge/Revision: 341
Repository/R-Forge/DateTimeStamp: 2012-11-16 09:16:33
Date/Publication: 2012-11-16 09:16:33
Packaged: 2012-11-16 11:17:11 UTC; rforge

The package description lets us know what other packages we are going to have to install first to make the MODIS R package work. Using R Studio you need to go get the following packages:  raster, bitops,RCurl,rgeos,XMLSchema, rgdal,mapdata,maptools,plotrix,SSOAP,XML,snow and ptw.

The only packages that might be a bit tricky to install are RCurl, and SSOAP. As I recall RCurl should work right out of the box on a windows system. It makes calls to curlib and your windows system should have that installed.  SSOAP is a different matter.

In my current testing I havent been able to get any of the calls that rely on SSOAP to work, so I’ll be making bug reports. Still there are plenty of functions that dont need SSOAP. You just need it installed.

SSOAP resides here. This package is an “S” implementation of SOAP. To find out about SOAP.. wiki.  I think of SOAP as just another way to get data from a web service.  Instead of downloading from an ftp site, some services are set up to respond to SOAP requests or queries. Also, don’t be confused by the fact that SSOAP is a “S’ package.  R is just an implementation of S.

When you download the package you will note that it is a source distribution, NOT a typical windows binary package which comes in a zip. That means we will have to build the package locally.

If you don’t know how to build a package on R then see my package tutorial.  Specifically, we are going to be doing a windows build.

After you download the SSOAP package to a directory, you will want to “untar” or decompress the  tar.gz file.  If you don’t have winzip installed you can do this from within R using  “untar”  make sure to set the compressed variable to TRUE and it will default to unzipping a “gz” file.

With the file unzipped, you now use your windows console. Change directories until you are in the SSOAP directory and then use the command:

R CMD INSTALL –build SOAP_.09-0.tar.gz

This will create the package you need.  Then using R Studio, install packages from a local zip. select SSOAP and you are good to go. If this is unclear, let me know and I will expand this section.

With all your packages installed you are ready to download the source code for MODIS. You will go through the same process as with SSOAP. get the source bits and use R CMD INSTALL.  If you dont understand how to build packages, please read the tutorial.

The last step here will be getting MODIS  bits. The source for the package is located Here

A few agreements however. Since the package has not hit CRAN yet, if you  have any issues with the windows version you should probably contact me before you contact Matteo.  He is pretty busy working on finalizing things and I don’t think we should interrupt him with too many questions.  I’ll be going through the code and functions and doing windows testing as I write this tutorial, so if your are just learning R or struggling with this pre release code, it will probably help to work with me before we bug the developers. Of course you can ignore that and write to him directly.

Download the  “tar.gz” file to a directory and then “unzip”.  You should have all the source for the package. Next take the same steps as you did with SSOAP.  Open a console window.  > R CMD –build MODIS_0.6-22.tar.gz   That should work to  create a  ‘zip’  binary. Then open R Studio and install packages from a local zip

Then go to the next step

  1. R
    November 29, 2012 at 8:04 AM

    Say for instance I wanted to download and use a huge number of MODIS Scenes – say for instance a particular region – every day possible (no cloud cover) for multiple years – and using the land surface temperature product – how ridiculously unfeasible is that idea?

    • Steven Mosher
      November 29, 2012 at 9:21 AM

      well, for my current project I will be downloading an entire year for the US. Thats 12 to 14 tiles by 365 days. A lot of data.

      1. How big is your region?
      2. do you need daily or will the 8 day version work?
      3. what resolution do you need.

      We are still debugging some of the download and post processing work. Once that is done
      I will do a benchmark test and post in up when we get the current issues resoved

  2. Michalis Vardakis
    December 3, 2012 at 5:48 PM

    Hi Steven,
    I found easier to install SSOAP through this URL:
    >install.packages(“SSOAP”, repos = “http://www.omegahat.org/R”,
    dependencies = TRUE,
    type = “source”)

    I hope it also works!
    My attempt to download it manualy and install it through cmd failed epically (I have changed the path to lead also to R, but for one reason or the other…. it didn’t work).
    Regards,
    Michalis

    • Steven Mosher
      December 3, 2012 at 10:27 PM

      Thanks Michalis.

      I’ve let me know how SSOAP works as a stand alone package. I’ve been hitting a few bugs, so let me know how it works.

      What epic fail did you get trying to build it?

  3. Michalis Vardakis
    December 12, 2012 at 3:11 PM

    Hi Steven,

    So far so good with SSOAP,

    The failure was while running the : R CMD INSTALL –build SOAP_.09-0.tar.gz

    A message appeared that there was no R function/execution.

    • Steven Mosher
      December 14, 2012 at 6:26 AM

      1. check the instructions in my Building a package. Make sure you have rtools installed and that your PATH has been changed to reflect this.

      Also the command flag is — build TWO dashes

  4. julian.equihua@gmail.com
    May 22, 2013 at 4:37 AM

    The modis package source has been moved to http://ivfl-arc.boku.ac.at/owncloud/public.php?service=files&t=c4481aebe031c26fbbc62722ace11da4 I downloaded this file: MODIS_0.8-14.tar.gz and did the R CMD INSTALL –build MODIS_0.8-14.tar.gz (I guess this is a newer version since the one that existed when you created this entry). I get a whole bunch of errors e.g. No MODIS ‘suer’ nor ‘systemwide’ settings file found, using default settings. … ‘localArcPath’ doest not exist, it will be created. … ETC. I beleive It still manages ti install the package. I do library(MODIS) in R and get:

    Loading required package: raster
    Loading required package: sp
    ‘localArcPath’ does not exist, it will be created in ‘C:/Users/jequihua/Documents/MODIS_ARC’. Consult ‘?MODISoptions’ if you want to change it!
    ‘outDirPath’ does not exist, it will be created in ‘C:/Users/jequihua/Documents/MODIS_ARC/PROCESSED’. Consult ‘?MODISoptions’ if you want to change it!
    MODIS_manual: http://ivfl-arc.boku.ac.at/owncloud/public.php?service=shorty_relay&id=QR5FZSxe0gNULL
    Warning messages:
    1: ‘.path.package’ is deprecated.
    Use ‘path.package’ instead.
    See help(“Deprecated”)
    2: ‘.path.package’ is deprecated.
    Use ‘path.package’ instead.
    See help(“Deprecated”)
    3: In MODISoptions(save = FALSE, checkPackages = FALSE, quiet = TRUE) :
    No MODIS ‘user’ nor ‘systemwide’ settings file found, using default settings. Use ‘?MODISoptions’ to configure the ‘MODIS’ package and make settings permanent!
    4: In normalizePath(path.expand(path), winslash, mustWork) :
    path[1]=”C:/Users/jequihua/Documents/MODIS_ARC”: El sistema no puede encontrar el archivo especificado
    5: In normalizePath(path.expand(path), winslash, mustWork) :
    path[1]=”C:\Users\jequihua\Documents\MODIS_ARC”: El sistema no puede encontrar el archivo especificado
    6: In normalizePath(path.expand(path), winslash, mustWork) :
    path[1]=”C:/Users/jequihua/Documents/MODIS_ARC/PROCESSED”: El sistema no puede encontrar la ruta especificada
    7: In normalizePath(path.expand(path), winslash, mustWork) :
    path[1]=”C:\Users\jequihua\Documents\MODIS_ARC\PROCESSED”: El sistema no puede encontrar la ruta especificada
    8: In normalizePath(path.expand(path), winslash, mustWork) :
    path[1]=”C:/Users/jequihua/Documents/MODIS_ARC/PROCESSED/.auxiliaries”: El sistema no puede encontrar la ruta especificada
    9: In normalizePath(path.expand(path), winslash, mustWork) :
    path[1]=”C:\Users\jequihua\Documents\MODIS_ARC\PROCESSED\.auxiliaries”: El sistema no puede encontrar la ruta especificada
    10: ‘.path.package’ is deprecated.
    Use ‘path.package’ instead.
    See help(“Deprecated”)

    I then do (ok)

    MODIS:::checkDeps()
    [1] “All suggested packages are installed”

    but I do

    MODIS:::checkTools()
    Checking availabillity of MRT:
    ‘MRT_HOME’ not set/found! MRT is NOT enabled! See: ‘https://lpdaac.usgs.gov/tools/modis_reprojection_tool’
    Checking availabillity of ‘FWTools/OSGeo4W’ (GDAL with HDF4 support for Windows):
    ‘FWTools/OSGeo4W’ installation not found or path not set.
    If you don’t have installed one of them you can get it from ‘http://fwtools.maptools.org/’ or ‘http://trac.osgeo.org/osgeo4w/’ (recommanded)
    Trying to autodetect path to ‘FWTools/OSGeo4W’ (this may takes some time, you can interupt this process and set it manually, see ‘gdalPath’ argument in ‘?MODISoptions':

    Found ‘OSgeo4W’ version: ‘1.7.3’ in ‘c:/OSGeo4W/bin’ but without HDF4 support…strange, try to remove and re-install ‘OSgeo4W’!
    No HDF4 supporting GDAL installation found. You may set it manually in MODISoptions(gdalPath=’/Path/to/XXGDAL/bin’)

    I do have OSEGeo4w and MRT installed. Could you help me out with this? I’m not sure what I’m doing wrong. Thank you in advanced.

  5. Jill
    June 17, 2013 at 10:52 PM

    I am also getting errors #4-9 like Julian in the command window, then
    Error: loading failed
    Execution halted
    ERROR: loading failed
    *removing ‘C:/Program Files/R/R-2.14.0/library/MODIS’

    working from the MODIS_0.9-3.tar.gz file

  6. julian.equihua@gmail.com
    June 17, 2013 at 11:01 PM

    Hello Jill. What worked for me was to dowload the .zip here https://r-forge.r-project.org/R/?group_id=1252 and in RStudio install packages select in “Install from:” Package Archive File (.zip; . tar.gz) and use browse to find the .zip file. I get some errors that you correct later after you install MRT and Fwtools correctly.

    ??MODIS #help related to the MODIS package

    ## we got all the dependancies we need? (important ones: MRT and gdal)
    MODISoptions()

    ## automatically detect gdal
    MODIS:::checkTools(‘GDAL’)

    ## if the latter didnt work, set gdal path manually
    MODISoptions(gdalPath=’c:/Program Files (x86)/FWTools2.4.7/bin’) #this has to point to your ftwools installation

    I now have problems reading MODIS images which is very annoying, please let me know if you manage to solve this :)

    # obtain the names of the SDS of a specified MODIS grid file
    sds <- getSds("C:/Julian/63_Change_Detection_TWO_13_05_2013/3_modis_Rene/h09v06/MOD13Q1.A2001001.h09v06.005.2008270004824.hdf")
    names(sds)
    class(sds$SDS4gdal[1])

    ndvi <- raster(sds$SDS4gdal[1])

    Error in .local(.Object, …) :
    `C:\Julian\63_Change_Detection_TWO_13_05_2013\3_modis_Rene\h09v06\HDF4_EOS:EOS_GRID:"C:\Julian\63_CHA~1\3_MODI~1\h09v06\MOEF82~1.HDF":MODIS_Grid_16DAY_250m_500m_VI:250m 16 days NDVI' does not exist in the file system,
    and is not recognised as a supported dataset name.

    Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
    Cannot create a RasterLayer object from this file. (file does not exist)

  7. Jill
    June 18, 2013 at 7:40 AM

    Awesome, thanks. The zip download did the trick. I’ve been able to batch download the hdf files (getHDF), and now I’m working on getting either runGdal or runMrt to process the reprojection, mosaic, and conversion to geoTIFF.

    At first, I was also using FWTools like your code above, but the MODIS package couldn’t locate any drivers, so I installed gdal from OSGeo4W instead and that did the trick (at least it found 53 drivers and runGdal runs now). Must be a version thing.

    I haven’t used getSDS as I’m getting all of the layers right now. But from my understanding the SDS is just an argument to select the layer you want in the functions runGdal and runMrt, both of which create the geoTIFF that the raster package will recognize.

    This worked for me to create the tifs:

    # using gdal, utm 50 wgs84, two tiles to mosaic for two separate dates
    runGdal(product=’MOD15A2′,begin=’2001-01-01′, end=’2001-01-15′, tileH=26,
    tileV=4:5,collection=005, outProj = ‘EPSG:32650′)

    # But for some reason the runMrt option isn’t working
    runMrt(product=’MOD15A2′,begin=’2001-01-01′, end=’2001-01-15′, tileH=26,
    tileV=4:5,collection=005, outProj = ‘UTM’, zone = 50, datum = ‘WGS84′,
    projPara = ‘117.00 42.00′, mosaic = TRUE, job = ‘test’)

    #it reports that it mosaics fine, and reports original and project coordinates, but then I get:
    Error: ReadParameterFile : Reading Input Parameter File
    : Invalid field and
    Fatal Error, Terminating…

    So, who knows.

  8. July 9, 2014 at 9:53 PM

    Hello, a little bit late. But, what about MOD10 products? Any hope for future plans? :)

  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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 39 other followers

%d bloggers like this: