x="MOD13A1" #Creates an object with the selected MODIS of interest, in this case: Vegetation Indices 16-Day L3 Global 500m #More information on vegetation indexes products: https://modis.gsfc.nasa.gov/data/dataprod/mod13.php
#Enter the website: https://search.earthdata.nasa.gov/contact_info and create an account with a particular username and password
#specify username and password for downloading with the R script
setMRTpath("/Users/daniel/Downloads/MRT/bin", update = TRUE) #Specify the path for the NASA MRT software for mosaic images and reprojection. #Even if you are not using mosaic/reprojection, you have to specify any executable software otherwise an error will show up. #If a different software from MRT was defined, to update for the correct path you should clear objects from the dataset and restart the script. #MRT installation guide for MAC can be found here:
#Install last version of rts package from Git-hub, paramount to prevent another error #More details on this error: https://gis.stackexchange.com/questions/260049/downloading-modis-products-with-r-package-rts/263996 #This updated should be installed only the first time using the script
#If you are reprojecting to geographical coordinates (proj_type = 'GEO'), pixel_size should be approximated in degrees. In this example, the 500 m MODIS images in Africa correspond to 0.00416667 degrees. #bands_subset specify which of the 12 spectral layers from the MODIS sensor you are interested to extract from the HDF images, in this case '1 1 0 0 0 0 0 0 0 0 0 0' is obtaining NDVI and EVI layers. #proj_params are different depending on the coordinate projection, for geographic projections all should be specified in 0. You can review any particular specification in the MRT tool manual appendix C: https://lpdaac.usgs.gov/sites/default/files/public/mrt41_usermanual_032811.pdf
#You can directly download and reproject images with the ModisDownload function. As a result, you will have the mosaic and the .tif reprojected images in the same folder with all the raw .hdf files.