1 |
7526fb1c
|
Jim Regetz
|
import sys
|
2 |
|
|
import string
|
3 |
|
|
import os
|
4 |
|
|
import osgeo
|
5 |
|
|
from osgeo import gdal, gdalconst
|
6 |
|
|
import re
|
7 |
|
|
import subprocess
|
8 |
|
|
from osgeo.gdalconst import *
|
9 |
|
|
|
10 |
|
|
driver = gdal.GetDriverByName('Ehdr')
|
11 |
|
|
driver2=gdal.GetDriverByName('HFA')
|
12 |
|
|
driver.Register()
|
13 |
|
|
driver2.Register()
|
14 |
|
|
|
15 |
|
|
# Convert Monthly averages to .bil
|
16 |
|
|
sourceDir = "/data/project/organisms/MODIS_LST_Oregon/ClearDayGDAL/NewClearDay_MonthlyAvgs_Mosaics"
|
17 |
|
|
outputDir = "/data/project/organisms/MODIS_LST_Oregon/ClearDayGDAL/NewClearDay_MonthlyAvgs_Mosaics"
|
18 |
|
|
|
19 |
|
|
# Loop through the folder
|
20 |
|
|
for dirname, dirnames, filenames in os.walk(sourceDir):
|
21 |
|
|
for filename in filenames:
|
22 |
|
|
ext = os.path.splitext(filename)[1]
|
23 |
|
|
if ext == ".img":
|
24 |
|
|
infile= sourceDir + "/" + filename
|
25 |
|
|
outfile= re.sub(".img",".bil",infile)
|
26 |
|
|
subprocess.call(["gdalwarp","-s_srs", "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs","-t_srs", "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs", "-ot", "int16", "-srcnodata", "3.39999999999999996e+38", "-dstnodata", "3.39999999999999996e+38", "-of", "EHdr", "-overwrite", infile, outfile])
|
27 |
|
|
|
28 |
|
|
#subprocess.call(["gdal_translate", "-ot", "int16", "-of", "EHdr", infile, outfile])
|
29 |
|
|
|
30 |
|
|
# Convert Daily averages to .bil
|
31 |
|
|
sourceDir2 = "/data/project/organisms/MODIS_LST_Oregon/ClearDayGDAL/NewClearDay_DailyAvgs_Mosaics"
|
32 |
|
|
outputDir2 = "/data/project/organisms/MODIS_LST_Oregon/ClearDayGDAL/NewClearDay_DailyAvgs_Mosaics"
|
33 |
|
|
|
34 |
|
|
# Loop through the folder
|
35 |
|
|
for dirname, dirnames, filenames in os.walk(sourceDir2):
|
36 |
|
|
for filename in filenames:
|
37 |
|
|
ext = os.path.splitext(filename)[1]
|
38 |
|
|
if ext == ".img":
|
39 |
|
|
infile2= sourceDir2 + "/" + filename
|
40 |
|
|
outfile2= re.sub(".img",".bil",infile2)
|
41 |
|
|
subprocess.call(["gdalwarp","-ot", "int16", "-srcnodata", "3.39999999999999996e+38", "-dstnodata", "3.39999999999999996e+38", "-of", "EHdr", "-overwrite", infile2, outfile2])
|
42 |
|
|
|
43 |
|
|
#subprocess.call(["gdal_translate", "-ot", "int16", "-of", "EHdr", infile2, outfile2])
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
gdalwarp -ot int16 -srcnodata "3.39999999999999996e+38" -dstnodata "3.39999999999999996e+38" -of EHdr infile2 outfile2
|