-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannels_correlation.py
140 lines (122 loc) · 4.22 KB
/
channels_correlation.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
from time import time
from scipy.stats import pearsonr
from get_data import get_features
from utils import *
from visualize import get_bbox, visualize_map
if __name__ == "__main__":
beginning = 13517
nb_days = 10
ending = beginning + nb_days - 1
latitude_beginning = 35.0 + 15
latitude_end = 40.0 + 15
longitude_beginning = 125.0
longitude_end = 130.0
latitudes, longitudes = get_latitudes_longitudes(
latitude_beginning, latitude_end, longitude_beginning, longitude_end
)
date_begin, date_end = print_date_from_dfb(beginning, ending)
type_channels = 0 # 0: infrared, 1: visible
if type_channels == 0:
infra = get_features(
"infrared",
latitudes,
longitudes,
beginning,
ending,
output_level=True,
slot_step=1,
gray_scale=False,
)
cli = infra[:, :, :, 0]
unbiased = infra[:, :, :, 1]
infrared_features = get_features(
"infrared",
latitudes,
longitudes,
beginning,
ending,
output_level=False,
slot_step=1,
gray_scale=False,
)
elif type_channels == 1:
visible_features = get_features(
"visible",
latitudes,
longitudes,
beginning,
ending,
output_level=False,
slot_step=1,
gray_scale=False,
)
features = get_features(
"visible",
latitudes,
longitudes,
beginning,
ending,
output_level=True,
slot_step=1,
gray_scale=False,
)
ndsi = features[:, :, :, 0]
nb_latitudes = len(latitudes)
nb_longitudes = len(longitudes)
if type_channels == 0:
infrared_means = np.empty((nb_latitudes, nb_longitudes))
infrared_correlations = np.empty((nb_latitudes, nb_longitudes))
cli_means = np.empty((nb_latitudes, nb_longitudes))
var_means = np.empty((nb_latitudes, nb_longitudes))
elif type_channels == 1:
visible_correlations = np.empty((nb_latitudes, nb_longitudes))
visible_means = np.empty((nb_latitudes, nb_longitudes))
t_corrs = time()
for lat in range(nb_latitudes):
for lon in range(nb_longitudes):
if type_channels == 0:
mask = infra[:, lat, lon, 0] == -10
infrared_means[lat, lon] = np.mean(
infrared_features[:, lat, lon, 1][~mask]
- infrared_features[:, lat, lon, 0][~mask]
)
infrared_correlations[lat, lon] = pearsonr(
infrared_features[:, lat, lon, 0][~mask],
infrared_features[:, lat, lon, 1][~mask],
)[0]
cli_means[lat, lon] = np.mean(cli[:, lat, lon][~mask])
var_means[lat, lon] = np.mean(unbiased[:, lat, lon][~mask])
elif type_channels == 1:
mask_mu = (
(mu[:, lat, lon] < 0.05)
| (visible_features[:, lat, lon, 0] == -1)
| (visible_features[:, lat, lon, 1] == -1)
)
visible_means[lat, lon] = np.mean(ndsi[:, lat, lon][~mask_mu])
visible_correlations[lat, lon] = pearsonr(
visible_features[:, lat, lon, 0][~mask_mu],
visible_features[:, lat, lon, 1][~mask_mu],
)[0]
print(
"total time corr:",
time() - t_corrs,
"; nb pixels:",
nb_latitudes * nb_longitudes,
"; nb slots:",
144 * nb_days,
)
bbox = get_bbox(
latitude_beginning, latitude_end, longitude_beginning, longitude_end
)
if type_channels == 0:
visualize_map(infrared_correlations)
visualize_map(infrared_means)
visualize_map(cli_means)
visualize_map(var_means)
bias = normalize(infrared_means, normalization="standard") - normalize(
var_means, normalization="standard"
)
visualize_map(bias)
elif type_channels == 1:
visualize_map(visible_correlations)
visualize_map(visible_means)