-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize_data.py
More file actions
110 lines (97 loc) · 4.21 KB
/
visualize_data.py
File metadata and controls
110 lines (97 loc) · 4.21 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
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
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.dates import DateFormatter
import pandas as pd
import os
# BUG TESTING
# plt.plot(colza_SAR[:,43,-1])
def main():
# fig1, axs1 = plt.subplots(5, 1, constrained_layout=True)
# fig1.suptitle('Colza', fontsize=16)
years = [2018, 2019, 2020]
titles_SAR = ['VV', 'VV-grid', 'VH', 'VH-grid']
dB = False # Visualize in dB
path = "results/visualize_data"
if not os.path.exists(path):
os.makedirs(path)
for year in years:
dataset=np.load(f'Colza_DB/Colza_data_{year}.npz', allow_pickle=True)
X_SAR, X_NDVI, y_multi, id_p=dataset["X_SAR"], dataset["X_NDVI"], dataset["y"], dataset["id_parcels"]
if dB:
X_SAR = 10*np.log10(X_SAR)
X_NDVI = 10*np.log10(X_NDVI)
dates_SAR = pd.to_datetime(dataset["dates_SAR"]) - pd.DateOffset(years=year-2018)
dates_NDVI = pd.to_datetime(dataset["dates_NDVI"]) - pd.DateOffset(years=year-2018)
# --- Colza profiles ---
# SAR
colza_SAR=X_SAR[y_multi == 'CZH']
n_times=X_SAR.shape[1]
mean=np.mean(colza_SAR, axis=0)
std=np.std(colza_SAR, axis=0)
for k, title in enumerate(titles_SAR):
plt.figure(k)
# X-axis: Index number
plt.subplot(2,1,1)
plt.title('Colza ' + title)
plt.plot(mean[:, k],label=year)
plt.fill_between(np.arange(n_times), mean[:, k] +
std[:, k], mean[:, k]-std[:, k], alpha=0.5)
plt.legend()
# X-axis: Dates
ax = plt.subplot(2,1,2)
plt.plot(dates_SAR, mean[:, k])
plt.fill_between(dates_SAR, mean[:, k] +
std[:, k], mean[:, k]-std[:, k], alpha=0.5)
plt.xticks(rotation = 45) # Rotates X-Axis Ticks by 45-degrees
ax.xaxis.set_major_formatter(DateFormatter("%b"))
plt.savefig(f'{path}/SAR_mean_profile_{title}.pdf')
# NDVI
colza_NDVI=X_NDVI[y_multi == 'CZH']
n_times=X_NDVI.shape[1]
mean=np.mean(colza_NDVI, axis=0)
std=np.std(colza_NDVI, axis=0)
plt.figure(5)
# X-axis: Index number
plt.subplot(2,1,1)
plt.title('NDVI')
plt.plot(mean,label=year)
plt.fill_between(np.arange(n_times), mean+std, mean-std, alpha=0.5)
plt.legend()
# X-axis: Dates
ax = plt.subplot(2,1,2)
plt.plot(dates_NDVI, mean)
plt.fill_between(dates_NDVI, mean+std, mean-std, alpha=0.5)
plt.xticks(rotation = 45) # Rotates X-Axis Ticks by 45-degrees
ax.xaxis.set_major_formatter(DateFormatter("%b"))
plt.savefig(f'{path}/NDVI_mean_profile.pdf')
# colza_np = colza[:,:,0]
# colza_norm = colza_np/np.sqrt((colza_np * colza_np).sum(axis=1))[:,np.newaxis] # normalize rows
# cov_mtx = colza_norm.dot(colza_norm.T)
# Acquisition Dates - NDVI
plt.figure(6, figsize=(6,1))
ax = plt.subplot(1,1,1)
plt.title('Acquisition dates - NDVI')
ax.scatter(dates_NDVI, [0.5*(year-2017)]*len(dates_NDVI), marker='o', s=30, alpha=0.5)
ax.xaxis.set_major_formatter(DateFormatter("%b"))
ax.yaxis.set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.get_yaxis().set_ticklabels([])
plt.savefig(f'{path}/Acquisition_dates_NDVI.pdf', bbox_inches = "tight")
# Acquisition Dates - SAR
plt.figure(7, figsize=(6,1))
ax = plt.subplot(1,1,1)
plt.title('Acquisition dates - SAR')
ax.scatter(dates_SAR, [0.5*(year-2017)]*len(dates_SAR), marker='o', s=30, alpha=0.5)
ax.xaxis.set_major_formatter(DateFormatter("%b"))
ax.yaxis.set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.get_yaxis().set_ticklabels([])
plt.savefig(f'{path}/Acquisition_dates_SAR.pdf', bbox_inches = "tight")
if __name__ == "__main__":
main()