-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.py
172 lines (124 loc) · 4.19 KB
/
examples.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# --------------------------------------------------------------------------
#
# This file contains several examples on the different operations
# readily availble after load the .tmat files.
#
# --------------------------------------------------------------------------
import sys
import numpy as np
from matplotlib import pyplot as plt
from tools import data
# ===============================================
# Image manipulation
# ===============================================
def show_rgb(image, original=True):
# Check images size
if len(image.shape) != 3:
print "the image it's not af the shape (n, n, n)"
sys.exit(1)
if (image.shape)[2] != 3:
try:
image = np.dstack(image)
except:
print "The image's shape is not of the form (n, n, 3)"
sys.exit(1)
# Get RGB by slicing
red = image[:, :, 0]
green = image[:, :, 1]
blue = image[:, :, 2]
# put the 4 images in a plot that looks like (positions):
# |
# pos 1 | pos 2
# ------------|------------
# pos 4 | pos 4
# |
pos1, pos2, pos3, pos4 = (221, 222, 223, 224)
plt.subplot(pos1)
plt.imshow(red, cmap=plt.cm.Reds_r)
plt.subplot(pos2)
plt.imshow(green, cmap=plt.cm.Greens_r)
plt.subplot(pos3)
plt.imshow(blue, cmap=plt.cm.Blues_r)
if original:
plt.subplot(pos4)
plt.imshow(image)
plt.show()
def find_clouds(images):
"""
While very basic in principle. I found out that by applying a blue
layer to the reflectance instruments images ibands and mbands; I was
able to see the clouds clearly.
Method:
- Get the blue layer out of the 3D images ibands and mbands
- Add the two images to make sure that we are getting the clouds total
reflectance.
"""
pass
def sea_surface_temp(images, lm):
# Sea water freezing temp in kelvin degrees (271.15 aprox 271)
SEA_FREEZE_TEMP = 271
#fill nan pixels with 0 and flatten array for temp
#NaNs = np.isnan(images)
#sst[NaNs] = 400
#flat_sst = images.flatten()
#img = plt.imshow(images)
img = plt.imshow(lm)
plt.colorbar(img)
plt.show(img)
#plt.hist(flat_sst, range(0, SEA_FREEZE_TEMP))
#plt.hist(images, range(0, SEA_FREEZE_TEMP))
#plt.show()
virs = data.file_names(instrument_id=0)
mods = data.file_names(instrument_id=1)
allfiles = data.file_names(instrument_id=2)
# load only first image
mat = data.mat_generator(virs).next()
#mat = mat_generator(mods).next()
# instruments' image
lm = mat['lm']
sst = mat['sst']
#sic = mat['mw_sic']
#ngr = mat['mw_ngr']
#npr = mat['mw_npr']
#fc = np.dstack(mat['fc'])
#ibands = np.dstack(mat['ibands'])
sea_surface_temp(sst, lm)
# ------------------------------------------------------------
# Create plot of RBG blue layer for fc, ibands, mbands
# ------------------------------------------------------------
#blue1 = ibands[:, :, 2]
#blue2 = mbands[:, :, 2]
#blue3 = fc[:, :, 2]
#clouds = np.add(blue1, blue2, blue3)
#blues = plt.figure()
#blues.suptitle("RBG blue layer for fc, ibands, mbands", fontsize=16)
#ibands_plot = plt.subplot(221)
#ibands_plot.set_title("ibands blue")
#ibands_plot.imshow(blue1)
#mbands_plot = plt.subplot(222)
#mbands_plot.set_title("mbands blue")
#mbands_plot.imshow(blue2)
#fc_plot = plt.subplot(223)
#fc_plot.set_title("fc blue")
#fc_plot.imshow(blue3)
#no_clouds_plot = plt.subplot(224)
#no_clouds_plot.set_title("Summation of fc, ibands, mbands blue")
#no_clouds_plot.imshow(clouds)
# Plot colors in picture
# ------------------------------------------------------------
#blue_plot = plt.figure()
#blue_plot.suptitle("RBG blue layer for ibands plot", fontsize=16)
#ibands_plot = plt.subplot(221)
#ibands_plot.set_title("ibands blue plot")
#ibands_plot.plot(blue1)
#ibands_plot = plt.subplot(222)
#ibands_plot.set_title("ibands blue image")
#ibands_plot.imshow(blue1)
#ibands_plot = plt.subplot(223)
#ibands_plot.set_title("ibands blue acordion")
#ibands_plot.hist(blue1[:, 0], bins=50)
#plt.hist(blue1.flatten(), bins=50)
#ibands_plot = plt.subplot(224)
#ibands_plot.set_title("ibands blue acordion")
#ibands_plot.acorr(blue1)
#plt.show()