Downloading and processing MODIS with fast and free tools

Here’s a simple way of processing MODIS: downloading, extracting the bands from HDF as GEOTIFF, merging tiles and reprojecting. Area extraction, NDVI calculation, cloud filtering and more can be done in GRASS for example. It’s Linux based, but can easily used in Windows. My way might not be the most elegant, but it’s fast and works fine.

The first step is to select the tiles, the time frame and product at I take MOD09Q1 (250 m, 8 day, collection 6 reflectance) as example. Once orderd, we get a TXT file containing all file names. We download all files using wget. After download i mass rename all files to remove the creation date (using e.g. total commander) so the files are named like: MOD09Q1.A2000065.h21v05.006.

Then I extract Band 1, Band 2 and the Quality flag as GeoTiff. “aus” is the folder were the TIFFS will end up. Find out the name of the bands using gdalinfo.

wget -i modis.txt
for i in *.hdf; do gdal_translate -of GTiff 'HDF4_EOS:EOS_GRID:"'$i'":MOD_Grid_250m_Surface_Reflectance:sur_refl_b01' $aus`basename $i .hdf`_REF_band1.tif; done
for i in *.hdf; do gdal_translate -of GTiff 'HDF4_EOS:EOS_GRID:"'$i'":MOD_Grid_250m_Surface_Reflectance:sur_refl_b02' $aus`basename $i .hdf`_REF_band2.tif; done
for i in *.hdf; do gdal_translate -of GTiff 'HDF4_EOS:EOS_GRID:"'$i'":MOD_Grid_250m_Surface_Reflectance:sur_refl_qc_250m' $aus`basename $i .hdf`_QA.tif; done

I did not find a clean way for merging, so i suggest my “dirty” way, it needs to be repeated for each year and band, this is 5 minutes of copying but you can use it again and again and again for the next years then….here’s an example for band 1 year 2000. If you use a 16 day product every second line will give an error, but that you can ignore.

# 2000 -o 2000001_band1.tif *2000001* -o 2000009_band1.tif *2000009* -o 2000017_band1.tif *2000017* -o 2000025_band1.tif *2000025* -o 2000033_band1.tif *2000033* -o 2000041_band1.tif *2000041* -o 2000049_band1.tif *2000049* -o 2000057_band1.tif *2000057* -o 2000065_band1.tif *2000065* -o 2000073_band1.tif *2000073* -o 2000081_band1.tif *2000081* -o 2000089_band1.tif *2000089* -o 2000097_band1.tif *2000097* -o 2000105_band1.tif *2000105* -o 2000113_band1.tif *2000113* -o 2000121_band1.tif *2000121* -o 2000129_band1.tif *2000129* -o 2000137_band1.tif *2000137* -o 2000145_band1.tif *2000145* -o 2000153_band1.tif *2000153* -o 2000161_band1.tif *2000161* -o 2000169_band1.tif *2000169* -o 2000177_band1.tif *2000177* -o 2000185_band1.tif *2000185* -o 2000193_band1.tif *2000193* -o 2000201_band1.tif *2000201* -o 2000209_band1.tif *2000209* -o 2000217_band1.tif *2000217* -o 2000225_band1.tif *2000225* -o 2000233_band1.tif *2000233* -o 2000241_band1.tif *2000241* -o 2000249_band1.tif *2000249* -o 2000257_band1.tif *2000257* -o 2000265_band1.tif *2000265* -o 2000273_band1.tif *2000273* -o 2000281_band1.tif *2000281* -o 2000289_band1.tif *2000289* -o 2000297_band1.tif *2000297* -o 2000305_band1.tif *2000305* -o 2000313_band1.tif *2000313* -o 2000321_band1.tif *2000321* -o 2000329_band1.tif *2000329* -o 2000337_band1.tif *2000337* -o 2000345_band1.tif *2000345* -o 2000353_band1.tif *2000353* -o 2000361_band1.tif *2000361*

# We can remove the other files now 
rm MOD*
# Then reproject everything to a geographic system, maybe into a new folder:
mkdir lat

for i in *_band1.tif; do gdalwarp -t_srs EPSG:4326 $i $aus`basename $i .tif`.tif; done
for i in *_band2.tif; do gdalwarp -t_srs EPSG:4326 $i $aus`basename $i .tif`.tif; done
for i in ???????_QA.tif; do gdalwarp -t_srs EPSG:4326 $i $aus`basename $i .tif`.tif; done

What we have now can already be used, but you can continue in GRASS to calculate NDVI and filter the data.