1 |
7526fb1c
|
Jim Regetz
|
# Extracts SDS 10 (Clear Day) from MODIS HDF files and exports them to Erdas IMAGINE format so they can be used in subsequent Raster Calculations.
|
2 |
|
|
# ---------------------------------------------------------------------------
|
3 |
|
|
# Developed by John Donoghue II
|
4 |
|
|
# 6 May, 2010
|
5 |
|
|
|
6 |
|
|
import sys
|
7 |
|
|
import string
|
8 |
|
|
import os
|
9 |
|
|
|
10 |
|
|
sourceDir = "/data/project/organisms/MODIS_LST_Oregon" # provide a default value if unspecified
|
11 |
|
|
outputDir = "/data/project/organisms/MODIS_LST_Oregon/ClearDayGDAL" # provide a default value if unspecified
|
12 |
|
|
|
13 |
|
|
# Loop through the folder
|
14 |
|
|
for dirname, dirnames, filenames in os.walk(sourceDir):
|
15 |
|
|
for filename in filenames:
|
16 |
|
|
ext = os.path.splitext(filename)[1]
|
17 |
|
|
if ext == ".hdf":
|
18 |
|
|
print "processing " + filename
|
19 |
|
|
|
20 |
|
|
# process the file
|
21 |
|
|
inFile = sourceDir + "/" + filename
|
22 |
|
|
outFile = outputDir + "/" + filename[0:27] + "_ClearDay.img"
|
23 |
|
|
|
24 |
|
|
# remove outfile if present
|
25 |
|
|
if not os.path.exists(outFile) == True:
|
26 |
|
|
#os.remove(outFile)
|
27 |
|
|
|
28 |
|
|
# Process: Extract Subdataset
|
29 |
|
|
print " saving " + filename[0:27] + "_ClearDay.img"
|
30 |
|
|
myCommand = "gdal_translate -of HFA HDF4_EOS:EOS_GRID:" + filename + ":MODIS_Grid_Daily_1km_LST:Clear_day_cov " + outFile
|
31 |
|
|
output = os.popen(myCommand).read() # shows the ouput data of the command
|
32 |
|
|
|
33 |
|
|
print "Finished"
|