-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_hovmoller.py
209 lines (178 loc) · 6.34 KB
/
plot_hovmoller.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python
import sys,os
import math
import struct
import matplotlib.pyplot as plt
import numpy as np
import copy
import os.path
import matplotlib.dates as mdates
from netCDF4 import Dataset
from scipy.interpolate import Rbf
from datetime import datetime,timedelta
from dateutil.relativedelta import relativedelta
from calendar import monthrange
######################################################
# FUNCTIONS
# ####################################################
years = mdates.YearLocator() # every year
months = mdates.MonthLocator() # every month
yearsFmt = mdates.DateFormatter('%Y')
exp_name='EAS5'
fig_dir ='./'
def diff_month(d1, d2):
return (d1.year - d2.year) * 12 + d1.month - d2.month
# d1 = last year
# d2 = first year
def dateloop(d1, d2,freq):
if freq == 0:
return (d1 + timedelta(days=i) for i in range((d2 - d1).days + 1))
elif freq == 1:
return (d1 + 7*timedelta(days=i) for i in range((d2-d1).days//7 +1))
elif freq == 2:
return (d1 + relativedelta(months=i) for i in range(diff_month(d2, d1) + 1))
############################################################
# END FUNCIONTS
############################################################
# mode = 0 -> hovmoller from SIMULATION
# mode = 1 -> hovmoller from ANALYSIS
mode = 1
# In case of reanalysis choose 0 => we read also XBT
# else choose 1 => we read only ARGO
system = 1
# first and last dates of computation:
sd=datetime(2018,1,1)
ed=datetime(2020,12,30)
# Frequency of computation:
# 0 = daily
# 1 = weekly
# 2 = monthly
freq = 1
# Label maximum values:
max_salinity_label = 0.3 # with OBSSTAT:0.35, with OBSSTAT_SCREEN: 0.8
max_temp_label = 1.8 # with OBSSTAT:1.5, with OBSSTAT_SCREEN:2.5
# Counts the space we need depending on frequency:
if freq == 0:
space = (ed-sd).days
elif freq == 1:
space = (ed-sd).days//7+1
elif freq == 2:
space = diff_month(ed, sd)+1
# Counts the years
years_diff = int(ed.year) - int(sd.year)
years = []
for i in range(years_diff+1):
years.append(int(sd.year)+i)
fh = Dataset('RMS_hovmoller_V1.nc', mode='r')
rmseT_masked = fh.variables["rms_temperature"][:,:]
rmseS_masked = fh.variables["rms_salinity"][:,:]
biasT_masked = fh.variables["bias_temperature"][:,:]
biasS_masked = fh.variables["bias_salinity"][:,:]
dept = fh.variables["depth"][:]
time = fh.variables["time"][:]
fh.close()
x=np.arange(0,np.size(rmseT_masked,1),1)
y=np.arange(0,np.size(rmseT_masked,0),1)
X,Y=np.meshgrid(x,y)
ncycle=np.size(rmseT_masked,0)-2
if not os.path.isdir(fig_dir):
os.mkdir(fig_dir)
if freq == 0:
freq_label_plot = 365
name_plot = 'daily'
elif freq == 1:
freq_label_plot = 52
name_plot = 'weekly'
elif freq == 2:
freq_label_plot = 3
name_plot = 'monthly'
# Temperature:
# ------------
plt.figure(figsize=(10, 5))
cmapT=plt.cm.jet
csT=plt.pcolor(Y,X,rmseT_masked,cmap=cmapT,vmin=0, vmax=max_temp_label)
plt.xlim([0,np.size(rmseT_masked,0)-2])
plt.ylim([1,np.size(rmseT_masked,1)-4])
plt.gca().invert_yaxis()
plt.xticks(np.arange(0,ncycle,13.1),['Jan-18','Apr-18','Jul-18','Oct-18','Jan-19','Apr-19','Jul-19','Oct-19','Jan-20','Apr-20','Jul-20','Oct-20'],
rotation=45,fontsize=14)
plt.yticks(np.arange(1,80,10),dept[0::10],fontsize=14)
t_name="TEMPERATURE RMS misfits [$^\circ$C] "+exp_name
plt.ylabel("Depth [m]",fontsize=15)
cbar=plt.colorbar(csT,orientation="vertical")
cbar.ax.tick_params(labelsize=14)
cbar.set_label('Temp. RMSD [$^\circ$C]',fontsize=15)
plt.text(0,0, '(a)',
color='black', fontsize=16,fontweight='bold')
plt.savefig(fig_dir+'/bis_T_rmse_HOVMOLLER_'+
name_plot+'_'+str(years[0])+'_'+str(years[-1])+'.png',bbox_inches='tight')
plt.clf()
plt.cla()
plt.close()
# BIAS ------------
plt.figure(figsize=(10, 5))
cmapT=plt.cm.bwr
csT=plt.pcolor(Y,X,biasT_masked,cmap=cmapT,vmin=-0.45, vmax=0.45)
plt.xlim([0,np.size(biasT_masked,0)-2])
plt.ylim([1,np.size(biasT_masked,1)-4])
plt.gca().invert_yaxis()
plt.xticks(np.arange(0,ncycle,13.1),['Jan-18','Apr-18','Jul-18','Oct-18','Jan-19','Apr-19','Jul-19','Oct-19','Jan-20','Apr-20','Jul-20','Oct-20'],
rotation=45,fontsize=14)
plt.yticks(np.arange(1,80,10),dept[0::10],fontsize=14)
t_name="TEMPERATURE Bias [$^\circ$C] "+exp_name
plt.ylabel("Depth [m]",fontsize=15)
cbar=plt.colorbar(csT,orientation="vertical")
cbar.ax.tick_params(labelsize=14)
cbar.set_label('Temp. BIAS [$^\circ$C]',fontsize=15)
plt.text(0,0, '(c)',
color='black', fontsize=16,fontweight='bold')
plt.savefig(fig_dir+'/bis_T_bias_HOVMOLLER_'+
name_plot+'_'+str(years[0])+'_'+str(years[-1])+'.png',bbox_inches='tight')
plt.clf()
plt.cla()
plt.close()
# Salinity:
# ---------
plt.figure(figsize=(10, 5))
cmapS=plt.cm.jet
csS=plt.pcolor(Y,X,rmseS_masked,cmap=cmapS,vmin=0, vmax=max_salinity_label)
plt.xlim([0,np.size(rmseT_masked,0)-2])
plt.ylim([1,np.size(rmseT_masked,1)-4])
plt.gca().invert_yaxis()
plt.xticks(np.arange(0,ncycle,13.1),['Jan-18','Apr-18','Jul-18','Oct-18','Jan-19','Apr-19','Jul-19','Oct-19','Jan-20','Apr-20','Jul-20','Oct-20'],
rotation=45,fontsize=14)
plt.yticks(np.arange(1,80,10),dept[0::10],fontsize=14)
s_name="SALINITY RMS misfits [PSU] "+exp_name
plt.ylabel("Depth [m]",fontsize=15)
cbar=plt.colorbar(csS,orientation="vertical")
cbar.ax.tick_params(labelsize=14)
cbar.set_label('Sal. RMSD [PSU]',fontsize=15)
plt.text(0,0, '(b)',
color='black', fontsize=16,fontweight='bold')
plt.savefig(fig_dir+'/bis_S_rmse_HOVMOLLER_'+
name_plot+'_'+str(years[0])+'_'+str(years[-1])+'.png',bbox_inches='tight')
plt.clf()
plt.cla()
plt.close()
# BIAS ---------
plt.figure(figsize=(10, 5))
cmapS=plt.cm.bwr
csS=plt.pcolor(Y,X,biasS_masked,cmap=cmapS,vmin=-0.1, vmax=0.1)
plt.xlim([0,np.size(biasS_masked,0)-2])
plt.ylim([1,np.size(biasS_masked,1)-4])
plt.gca().invert_yaxis()
plt.xticks(np.arange(0,ncycle,13.1),['Jan-18','Apr-18','Jul-18','Oct-18','Jan-19','Apr-19','Jul-19','Oct-19','Jan-20','Apr-20','Jul-20','Oct-20'],
rotation=45,fontsize=14)
plt.yticks(np.arange(1,80,10),dept[0::10],fontsize=14)
s_name="SALINITY BIAS [PSU] "+exp_name
plt.ylabel("Depth [m]",fontsize=15)
cbar=plt.colorbar(csS,orientation="vertical")
cbar.ax.tick_params(labelsize=14)
cbar.set_label('Sal. BIAS [PSU]',fontsize=15)
plt.text(0,0, '(d)',
color='black', fontsize=16,fontweight='bold')
plt.savefig(fig_dir+'/bis_S_bias_HOVMOLLER_'+
name_plot+'_'+str(years[0])+'_'+str(years[-1])+'.png',bbox_inches='tight')
plt.clf()
plt.cla()
plt.close()