ModisDownload | R Documentation |
'ModisDownload' downloads a series of MODIS images in a specific date or a period of times, and for specified tile(s). It can also use MODIS Reproject Tool (MRT) software to mosaic the downloaded images, in case of selecting more than one tile, and reproject them to a specified coordinate system. As the format of the source images in LP DAAC is HDF, this tool can also convert them into other formats (i.e. Geotif, hdr).
setNASAauth(username,password,update,...)
setMRTpath(MRTpath,update,...)
ModisDownload(x,h,v,dates, ...)
getMODIS(x,h,v,dates,version='006',forceReDownload=TRUE,ncore='auto')
mosaicHDF(hdfNames,filename,MRTpath,bands_subset,delete=FALSE)
reprojectHDF(hdfName,crs,subset,resample_method,filename,...)
modisProducts(version=NULL)
getNativePixelSize(product)
getNativeTemporalResolution(product)
username |
character; username for authentication |
password |
character; password for authentication |
update |
logical; specifies whether .nerc file that has been previously created by setNASAauth, should be updated |
x |
product name or a number specifies the product row in the data.frame generated by |
h |
together with |
v |
see the above descriptopn for |
dates |
a character vector with the length of one or two, specifiying an individual date or a range of dates as the form of |
hdfName |
the name of hdf file |
crs |
coordinate reference system definiation (or a SpatRaster defines definition of new Raster for resampling) |
subset |
integer vector specifies the layer number for subsetting bands |
resample_method |
resample method for reprojection based on GDAL, can be one of "near","bilinear","cubic",or "cubicspline" (default: "near") |
hdfNames |
the names of hdf files |
MRTpath |
Path to the bin folder into the installed directory of MRT software. It is needed only if you need to mosaic and/or reproject the images. Example: MRTpath="d:/MRT/bin" |
filename |
the name of new file |
version |
the product version. The default value is '006' |
bands_subset |
HDF-EOS input files contain several layers of data (bands). Through this argument you ca select a subset of bands. You need to know how many bands the product has, and which bands you want to be subset. Example: Suppose your image has 6 bands and you only need the second band. The parameter should be entered as: bands_subset="0 1 0 0 0 0". |
delete |
Logical. If |
forceReDownload |
logical, specify whether the product should be re-downloaded if it had been downloaded before. The downloaded products are cashed using a hash digest of the inputs. If the download is canceled mid-way and the same exact products are downloaded again, it can be useful to avoid re-downloading them. |
ncore |
numerical; specify the number of cores used to speed up the download; 'auto' can be used instead to detect the number of cores and use half of them |
product |
The product name; can be extracted from the |
... |
additional arguments including: - - - - - - - - - - |
To be able to download the data, you need to register on "https://urs.earthdata.nasa.gov/" and get a username and password. To pass the authentication by the website, you need to set the username and password on the machine (only first time) using setNASAauth
function. Just specify the username and password in the function for the first time, and then the ModisDownload function can use it everytime you need to download the data.
To have the functionality for Mosaic and reprojecting of the images, you need to first install MRT software on your machine, and introduce its' path through the MRTpath argument. Otherwise, it can only be used for automating the downloading procedure.
The functions ModisDownload
uses the functions including getMODIS
, mosaicHDF
(if needed), and reprojectHDF
(if needed). The functions getMODIS
, can be used to download HDF files, while mosaicHDF
and reprojectHDF
can mosaic and reproject the HDF files, respectively.
Babak Naimi & Pablo Alfaro
## Not run:
library(raster)
library(RCurl)
# First, you need to register on https://urs.earthdata.nasa.gov/ and get a username and password
# for the first time, set the authentication info:
setNASAauth(username='myusername',password='mypass')
# product list:
modisProducts(version=5)
modisProducts(version=6)
modisProducts(version=NULL) # both versions
#x=3 # or x="MOD14A1"
# download 4 tiles (h14v04, h14v05, h15v04, h15v05) in single date (2011.05.01)
# Following command only downloads the source HDF images, no mosaic and no projection
ModisDownload(x=x,h=c(17,18),v=c(4,5),dates='2011.05.01',mosaic=F,proj=F,version='006')
# alternatively, you can use getMODIS to download only HDF images:
getMODIS(x=x,h=c(17,18),v=c(4,5),dates='2011.05.01',version='006')
# same as the above command, but downloads all available images in 2011:
ModisDownload(x=x,h=c(17,18),v=c(4,5),dates=c('2011.01.01','2011.12.31'),version='006')
#------
# Downloads selected tiles, and mosaic them, but no projections:
ModisDownload(x=x,h=c(17,18),v=c(4,5),dates=c('2011.05.01','2011.05.31'),
MRTpath='d:/MRT/bin',mosaic=T,proj=F,version='006')
#--- alternatively, you can first download the HDF images using getMODIS,
#and then mosaic them using mosaicHDF!
# Downloads selected tiles, and mosaic, reproject them in UTM_WGS84, zone 30 projection and
#convert all bands into Geotif format (the original HDF will be deleted!):
ModisDownload(x=x,h=c(17,18),v=c(4,5),dates=c('2011.05.01','2011.05.31'),MRTpath='d:/MRT/bin',
mosaic=T,proj=T,proj_type="UTM",utm_zone=30,datum="WGS84",
pixel_size=1000,version='006')
# Same as above command, but only second band out of 6 bands will be kept. (You do not need
#to specify proj_params when "UTM" is selected as proj_type and the zone also is specified,
#but for other types of projections you do).
ModisDownload(x=x,h=c(17,18),v=c(4,5),dates=c('2011.05.01','2011.05.31'),MRTpath='d:/MRT/bin',
mosaic=T,proj=T, bands_subset="0 1 0 0 0 0", proj_type="UTM",
proj_params="-3 0 0 0 0 0 0 0 0 0 0 0 0 0 0",utm_zone=30,
datum="WGS84",pixel_size=1000,version='006')
# Same as above command, but it spatially subsets the images into the specified box (UL and LR):
ModisDownload(x=x,h=c(17,18),v=c(4,5),dates=c('2011.05.01','2011.05.31'),MRTpath='d:/MRT/bin',
mosaic=T,proj=T,UL=c(-42841.0,4871530.0),LR=c(1026104,3983860),
bands_subset="0 1 0 0 0 0", proj_type="UTM",
proj_params="-3 0 0 0 0 0 0 0 0 0 0 0 0 0 0",utm_zone=30,datum="WGS84",
pixel_size=1000,version='006')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.