-
Notifications
You must be signed in to change notification settings - Fork 1
/
CM_coastal.py
95 lines (62 loc) · 2.06 KB
/
CM_coastal.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from pyhdf.SD import *
import sys
#np.set_printoptions(threshold='nan')
_filename = 'C:\Users\AKO NA LNG\Desktop\Esquivel Files\School Files 2\Special Problem\MODIS\MOD35\MOD35_L2.A2015348.0215.006.2015348134053.hdf'
mod35 = SD(_filename, SDC.READ)
sds_name_cm = 'Cloud_Mask'
sds_index_cm = mod35.select(sds_name_cm)
cm_sds_data = sds_index_cm.get()
sds_data_0 = cm_sds_data[0, :, :]
sds_data_0_bin = sds_data_0.astype(dtype=np.uint8, order='K', casting='unsafe', subok=False, copy=False)
for x in np.nditer(sds_data_0_bin, op_flags=['readwrite']):
x[...] = np.right_shift(x, 6)
for y in np.nditer(sds_data_0_bin, op_flags=['readwrite']):
if (y[...] == 3 or y[...] == 2):
y[...] = 0
fig = plt.figure()
ax = fig.add_subplot(111)
cmap = plt.cm.gnuplot2
bounds = np.arange(0, 2, 1)
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
img = plt.imshow(np.flipud(sds_data_0_bin), vmin = 0, vmax = 1, cmap = cmap, interpolation = 'nearest',
origin = 'lower')
#cbar = plt.colorbar(img, cmap = cmap, norm = norm, boundaries = bounds, ticks = bounds)
#cbar.ax.set_yticklabels(['Water', 'Coastal'], fontsize=10)
ax.set_xlabel("", fontsize=7)
ax.set_ylabel("", fontsize=1)
plt.title('Cloud Mask - Surface Type (Coastal Area)', fontsize = 10)
plt.show()
#y = np.empty_like(sds_data_0)
#for x in sds_data_0:
# print sds_data_0[x]
# print type(sds_data_0[x])
# break
#print type(sds_data_0[0,0])
#print sds_data_0[0,0]
#sds_data_0_bin = np.binary_repr(sds_data_0, width=8)
#x = np.right_shift(sds_data_0[0,0], 6)
#print x
#x_rs = np.binary_repr(x, width=2)
#print x_rs
#Bit packing
#y = np.empty_like(sds_data_0)
#z = y.astype(np.uint8)
#z[0,0] = x_rs
#z[0,0] = z[0,0] - 8
#print z[0,0]
#i = np.unpackbits(z[0,0])
#print i
#j = np.packbits(i)
#print j
#x = BitArray(int=sds_data_0[2029,1339], length=8)
#xstr = x.bin
#print np.shape(sds_data_0)
#print sds_data_0[0,0]
#for x in sds_data_0:
#print sds_data_0[0]
#sds_data_0_bin[x] = BitArray(int=sds_data_0[x], length=8)
#print x.bin