-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMOD11.py
More file actions
68 lines (54 loc) · 2.27 KB
/
MOD11.py
File metadata and controls
68 lines (54 loc) · 2.27 KB
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
60
61
62
63
64
65
66
67
68
from GlobalModis import *
indir = '/Users/hg1/data/MOD11'
class MOD11(GlobalMODIS):
# ns = 1320
# nl = 700
# starts = 1080
# startl = 700
# TODO : Populate years list with list in years.txt in the data directories.
def __init__(self, fname=None):
super(MOD11,self).__init__()
self.filename = fname
self.read_data()
#self.stacked_day = np.zeros((1,1))
#self.stacked_night = np.zeros((1,1))
def read_data(self):
file = SD(self.filename, SDC.READ)
print(file.info())
sds_obj = file.select('LST_Day_CMG')
data = sds_obj.get()
attrs = sds_obj.attributes()
# for idx,sds in enumerate(attrs.keys()) :
# print(idx,sds)
for key, val in attrs.items():
if (key == 'scale_factor'):
print('SCALE_FACTOR : ', key, ':', val)
self.scale_factor = val
self.data_day = data[self.startl:self.startl+self.nl, self.starts:self.starts+self.ns]
sds_obj = file.select('LST_Night_CMG')
data = sds_obj.get()
self.data_night = data[self.startl:self.startl + self.nl, self.starts:self.starts + self.ns]
SD.end(file)
print ("Number of samples is ", self.ns)
super().parse_filename ()
self.read_stacked()
def read_stacked (self) :
## read in the nighttime stacked file
self.stackyears.clear()
sfile = os.path.join(self.pathname,'outarr')
yfile = os.path.join(self.pathname,'years.txt')
nbytes = os.path.getsize(sfile)
self.nyears = int(nbytes / (self.ns * self.nl * 2))
print("number of years in outarr is ", self.nyears)
self.stacked_night = np.fromfile (sfile, dtype=np.uint16).reshape(self.nyears, self.nl, self.ns)
sfile = os.path.join(self.pathname, 'outarr_day')
self.stacked_day = np.fromfile(sfile, dtype=np.uint16).reshape(self.nyears, self.nl, self.ns)
f = open (yfile,'r')
allyears = f.readlines()
for l in allyears :
self.stackyears.append(int(l))
def get_time_series (self, x, y) :
myprof0 = self.stacked_night[:,y,x]*self.scale_factor
myprof1 = self.stacked_day[:,y,x]*self.scale_factor
newarr=[myprof0 , myprof1]
return newarr