/
0.4.LST_ViewAngle_data.processing.R
59 lines (39 loc) · 1.59 KB
/
0.4.LST_ViewAngle_data.processing.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
rm(list=ls())
setwd('C:/Local Data/')
X = read.csv('C:/Local Data/Code/CB_Date_Range.csv')
Date = strptime(X[,1],'%Y-%m-%d')
CURRENT = as.POSIXlt(Date)
CURRENT.YMD = format(CURRENT,'%Y%m%d')
#---------------------------------
#--- Define Area of Interest -----
#---------------------------------
### 250 m grid coordinates of interst
ROI_latlongs = read.csv('C:/Local Data/Code/ROI_BAWAP_CentreCoords_250m.csv')
lats = ROI_latlongs$latitude
lons = ROI_latlongs$longitude
### MODIS 1 km dataset coords
MODIS.NROWS = 3726
MODIS.NCOLS = 4790
### boundary latitude and longitudes of the MODIS region
# see http://remote-sensing.nci.org.au/u39/public/html/modis/lpdaac-mosaics-cmar/templates/
MODIS.LLATS = seq(-10.,by=-0.009394,length.out=MODIS.NROWS+1)
MODIS.LLONS = seq(110.,by= 0.009394,length.out=MODIS.NCOLS+1)
### pixels of interest from MODIS data
MODIS.ppp = (findInterval(-lats,-MODIS.LLATS) - 1)*MODIS.NCOLS + findInterval(lons,MODIS.LLONS)
fl = list.files('M:/PhD/ViewAngle',pattern='.envi',full.names=T)
seq = seq(1,length(fl),by=2)
fl = fl[seq]
#---------------------------------
### loop [temporal/date] function:
for (k in 1:length(fl)) {
#for (k in 21:31) {
#k = 21
###open file
phi = readBin(fl[k],'integer',size=1,n=3726*4790)[MODIS.ppp]
phi[phi<0] = NA # convert no data values to nulls
phi = phi-65 # apply offset
print(range(phi))
### write files
ofn = paste('C:/Local Data/F95/LST/MODIS_LST_1km_ViewAngle/',substr(fl[k],26,33),'_MODIS_LST_1km_ViewAngle.flt',sep='')
writeBin(as.vector(phi),ofn,size=4)
}