36 |
36 |
|
37 |
37 |
## default date and tile to play with (will be overwritten below when running in batch)
|
38 |
38 |
#date="20090129"
|
39 |
|
#tile="h11v08"
|
|
39 |
#tile="h17v00"
|
40 |
40 |
platform="pleiades"
|
41 |
41 |
verbose=T
|
42 |
42 |
|
... | ... | |
54 |
54 |
## path to some executables
|
55 |
55 |
ncopath="/nasa/sles11/nco/4.0.8/gcc/mpt/bin/"
|
56 |
56 |
swtifpath="/nobackupp1/awilso10/software/heg/bin/swtif"
|
|
57 |
swtifpath="/nobackupp4/pvotava/software/heg/bin/swtif"
|
|
58 |
## path to swath database
|
|
59 |
db="/nobackupp4/pvotava/DB/export/swath_geo.sql.sqlite3.db"
|
|
60 |
## specify working directory
|
|
61 |
outdir=paste("/nobackupp1/awilso10/mod35/daily/",tile,"/",sep="") #directory for separate daily files
|
|
62 |
basedir="/nobackupp1/awilso10/mod35/" #directory to hold files temporarily before transferring to lou
|
|
63 |
setwd(tempdir())
|
|
64 |
## grass database
|
|
65 |
gisBase="/u/armichae/pr/grass-6.4.2/"
|
|
66 |
## path to MOD11A1 file for this tile to align grid/extent
|
|
67 |
gridfile=list.files("/nobackupp4/datapool/modis/MOD11A2.005/2009.01.01",pattern=paste(tile,".*[.]hdf$",sep=""),recursive=T,full=T)[1]
|
|
68 |
td=readGDAL(paste("HDF4_EOS:EOS_GRID:\"",gridfile,"\":MODIS_Grid_8Day_1km_LST:LST_Day_1km",sep=""))
|
|
69 |
projection(td)="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs +datum=WGS84 +ellps=WGS84 "
|
|
70 |
}
|
57 |
71 |
## path to swath database
|
58 |
72 |
db="/nobackupp4/pvotava/DB/export/swath_geo.sql.sqlite3.db"
|
59 |
73 |
## specify working directory
|
... | ... | |
104 |
118 |
vars=as.data.frame(matrix(c(
|
105 |
119 |
"Cloud_Mask", "CM",
|
106 |
120 |
"Quality_Assurance", "QA"),
|
|
121 |
# "Solar_Azimuth", "SA",
|
|
122 |
# "Sensor_Zenith", "SZ"),
|
107 |
123 |
byrow=T,ncol=2,dimnames=list(1:2,c("variable","varid"))),stringsAsFactors=F)
|
108 |
124 |
|
109 |
125 |
## vector of variables expected to be in final netcdf file. If these are not present, the file will be deleted at the end.
|
... | ... | |
137 |
153 |
## Function to generate hegtool parameter file for multi-band HDF-EOS file
|
138 |
154 |
print(paste("Starting file",basename(file)))
|
139 |
155 |
outfile=paste(tempdir(),"/",basename(file),sep="")
|
|
156 |
### Get 1km data
|
140 |
157 |
## First write the parameter file (careful, heg is very finicky!)
|
141 |
158 |
hdr=paste("NUM_RUNS = ",length(vars$varid),"|MULTI_BAND_HDFEOS:",length(vars$varid),sep="")
|
142 |
159 |
grp=paste("
|
... | ... | |
169 |
186 |
cat(c(hdr,grp) , file=paste(tempdir(),"/",basename(file),"_MODparms.txt",sep=""))
|
170 |
187 |
## now run the swath2grid tool
|
171 |
188 |
## write the gridded file
|
172 |
|
system(paste("(",swtifpath," -p ",tempdir(),"/",basename(file),"_MODparms.txt -d)",sep=""),intern=F,ignore.stderr=F)
|
|
189 |
system(paste(swtifpath," -p ",tempdir(),"/",basename(file),"_MODparms.txt -d -tmpLatLondir ",tempdir(),sep=""),intern=F,ignore.stderr=F)
|
173 |
190 |
print(paste("Finished gridding ", file," for tile ",tile))
|
174 |
191 |
} #end looping over swaths
|
175 |
192 |
|
... | ... | |
181 |
198 |
q("no",status=0)
|
182 |
199 |
}
|
183 |
200 |
|
|
201 |
plot=F
|
|
202 |
if(plot){
|
|
203 |
i=1
|
|
204 |
GDALinfo(outfiles[i])
|
|
205 |
d=brick(
|
|
206 |
raster(paste("HDF4_EOS:EOS_GRID:\"",outfiles[i],"\":mod35:Cloud_Mask_0",sep="")),
|
|
207 |
raster(paste("HDF4_EOS:EOS_GRID:\"",outfiles[i],"\":mod35:Quality_Assurance_0",sep="")),
|
|
208 |
raster(paste("HDF4_EOS:EOS_GRID:\"",outfiles[i],"\":mod35:Sensor_Zenith",sep="")),
|
|
209 |
raster(paste("HDF4_EOS:EOS_GRID:\"",outfiles[i],"\":mod35:Solar_Azimuth",sep="")))
|
|
210 |
plot(d)
|
|
211 |
}
|
|
212 |
# TODO: import sensor zenith separately and mask out bad pixels
|
|
213 |
system(paste("scp ",outfiles[1]," adamw@acrobates.eeb.yale.edu:/data/personal/adamw/projects/interp/tmp/",sep=""))
|
|
214 |
|
184 |
215 |
#####################################################
|
185 |
216 |
## Process the gridded files to align exactly with MODLAND tile and produce a daily summary of multiple swaths
|
186 |
217 |
|
Started process of adding sensor zenith filter to MOD35 Processing