Thursday, 6 August 2015

remote sensing - Download MODIS/MCD19A2 AOD product with R



I'm looking for a programmatic way to download MODIS/MCD19A2 AOD data in R. So far, I've found a pretty solid R package called MODISTools that works nicely with the MODIS/VIIRS RESTful API. However, this web service does not provide access to the AOD product that I need (MCD19A2). Currently, the only way I know of downloading the AOD product is manually via the Nasa EarthData Search tool, or via the NASA Data Pool.


Is there anyone out there that has found a more convenient and programmatic way to work with the MCD19A2 AOD product?



Answer



This can be easily achieved using the MODIS package, version 1.1.3 or higher (previous versions didn't provide access to this product).


library(MODIS)

# set MODIS options (these can also be passed to '...' in getHdf())
MODISoptions(localArcPath = "OutputDestinationFolder", quiet = FALSE)

# download data

hdf = getHdf("MCD19A2", collection = "006"
, tileH = 9, tileV = 4
, begin = "2018.08.28", end = "2018.08.31")
hdf
# $`MCD19A2.006`
# [1] "OutputDestinationFolder/MODIS/MCD19A2.006/2018.08.28/MCD19A2.A2018240.h09v04.006.2018242043359.hdf"
# [2] "OutputDestinationFolder/MODIS/MCD19A2.006/2018.08.29/MCD19A2.A2018241.h09v04.006.2018250043019.hdf"
# [3] "OutputDestinationFolder/MODIS/MCD19A2.006/2018.08.30/MCD19A2.A2018242.h09v04.006.2018250043020.hdf"
# [4] "OutputDestinationFolder/MODIS/MCD19A2.006/2018.08.31/MCD19A2.A2018243.h09v04.006.2018250043021.hdf"


This downloads all .hdf files found for the specified tile indices and time frame and puts them in the desired target folder. You might also use runGdal() instead to download and extract the data in one go, provided that GDAL is available. This renders unnecessary an explicit call to getHdf().


tfs = runGdal("MCD19A2", collection = "006"
, tileH = 9, tileV = 4
, begin = "2018.08.28", end = "2018.08.31"
, job = "MCD19A2", SDSstring = "1010000000000")
tfs
# $`MCD19A2.006`
# $`MCD19A2.006`$`2018-08-28`
# [1] "OutputDestinationFolder/PROCESSED/MCD19A2/MCD19A2.A2018240.Optical_Depth_047.tif"
# [2] "OutputDestinationFolder/PROCESSED/MCD19A2/MCD19A2.A2018240.AOD_Uncertainty.tif"

#
# $`MCD19A2.006`$`2018-08-29`
# [1] "OutputDestinationFolder/PROCESSED/MCD19A2/MCD19A2.A2018241.Optical_Depth_047.tif"
# [2] "OutputDestinationFolder/PROCESSED/MCD19A2/MCD19A2.A2018241.AOD_Uncertainty.tif"
# ...

For further information, see also



  • ?getProduct() for a list of available products;

  • getProduct("MCD19A2") for details on a paricular product;


  • argument 'outDirPath' in ?MODISoptions() to specify a target folder for extracted layers;

  • and arguments 'dlmethod' and 'dataFormat' in ?MODISoptions() for supported download methods and write formats, respectively.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...