-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTSpointProfiles_reconstructFuture.py
221 lines (200 loc) · 11.2 KB
/
TSpointProfiles_reconstructFuture.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from __future__ import absolute_import, division, print_function, \
unicode_literals
import numpy as np
import xarray as xr
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt
import os
import glob
from mpas_analysis.shared.io.utility import decode_strings
import gsw
seasons = [2, 8]
# Coordinates of point where to plot profiles
# Barents Sea:
#lonPoint = 37.5
#latPoint = 70
#pointTitle = 'Barents Sea South, 70N,37.5E'
#iCell = 466944
#latPoint = 75
#pointTitle = 'Barents Sea Central, 75N,37.5E'
#iCell = 483456
#latPoint = 80
#pointTitle = 'Barents Sea North, 80N,37.5E'
#iCell = 101763
latPoint = 75
#lonPoint = 27
#pointTitle = 'Barents Sea West, 75N,27E'
#iCell = 417880
lonPoint = 48
pointTitle = 'Barents Sea East, 75N,48E'
iCell = 5762
figdir = f'./TSprofiles/E3SM-Arcticv2.1_historical'
if not os.path.isdir(figdir):
os.makedirs(figdir)
outdir = f'./TSprofiles_data/E3SM-Arcticv2.1_historical/0151/reconstructed'
if not os.path.isdir(outdir):
os.makedirs(outdir)
figsize = (10, 15)
figdpi = 150
fontsize_smallLabels = 18
fontsize_labels = 20
fontsize_titles = 22
legend_properties = {'size':fontsize_smallLabels, 'weight':'bold'}
###################################################################
for season in seasons:
# Initialize figure and axis objects
fig_Tprofile = plt.figure(figsize=figsize, dpi=figdpi)
ax_Tprofile = fig_Tprofile.add_subplot()
for tick in ax_Tprofile.xaxis.get_ticklabels():
tick.set_fontsize(fontsize_smallLabels)
tick.set_weight('bold')
for tick in ax_Tprofile.yaxis.get_ticklabels():
tick.set_fontsize(fontsize_smallLabels)
tick.set_weight('bold')
ax_Tprofile.yaxis.get_offset_text().set_fontsize(fontsize_smallLabels)
ax_Tprofile.yaxis.get_offset_text().set_weight('bold')
#
fig_Sprofile = plt.figure(figsize=figsize, dpi=figdpi)
ax_Sprofile = fig_Sprofile.add_subplot()
for tick in ax_Sprofile.xaxis.get_ticklabels():
tick.set_fontsize(fontsize_smallLabels)
tick.set_weight('bold')
for tick in ax_Sprofile.yaxis.get_ticklabels():
tick.set_fontsize(fontsize_smallLabels)
tick.set_weight('bold')
ax_Sprofile.yaxis.get_offset_text().set_fontsize(fontsize_smallLabels)
ax_Sprofile.yaxis.get_offset_text().set_weight('bold')
#
fig_Cprofile = plt.figure(figsize=figsize, dpi=figdpi)
ax_Cprofile = fig_Cprofile.add_subplot()
for tick in ax_Cprofile.xaxis.get_ticklabels():
tick.set_fontsize(fontsize_smallLabels)
tick.set_weight('bold')
for tick in ax_Cprofile.yaxis.get_ticklabels():
tick.set_fontsize(fontsize_smallLabels)
tick.set_weight('bold')
ax_Cprofile.yaxis.get_offset_text().set_fontsize(fontsize_smallLabels)
ax_Cprofile.yaxis.get_offset_text().set_weight('bold')
Tfigtitle = f'Temperature ({pointTitle})\n{season:02d} - years 2031-2050 (reconstructed)'
Tfigfile = f'{figdir}/Tprofile_icell{iCell:d}_E3SM-Arcticv2.1_historical0151_{season:02d}_years2031-2050_reconstructed.png'
Sfigtitle = f'Salinity ({pointTitle})\n{season:02d} - years 2031-2050 (reconstructed)'
Sfigfile = f'{figdir}/Sprofile_icell{iCell:d}_E3SM-Arcticv2.1_historical0151_{season:02d}_years2031-2050_reconstructed.png'
Cfigtitle = f'Sound speed ({pointTitle})\n{season:02d} - years 2031-2050 (reconstructed)'
Cfigfile = f'{figdir}/Cprofile_icell{iCell:d}_E3SM-Arcticv2.1_historical0151_{season:02d}_years2031-2050_reconstructed.png'
ax_Tprofile.set_xlabel('Temperature ($^\circ$C)', fontsize=fontsize_labels, fontweight='bold')
ax_Tprofile.set_ylabel('Depth (m)', fontsize=fontsize_labels, fontweight='bold')
ax_Tprofile.set_title(Tfigtitle, fontsize=fontsize_titles, fontweight='bold')
#ax_Tprofile.set_xlim(-1.85, 1.8)
ax_Tprofile.set_ylim(-500, 0)
#
ax_Sprofile.set_xlabel('Salinity (psu)', fontsize=fontsize_labels, fontweight='bold')
ax_Sprofile.set_ylabel('Depth (m)', fontsize=fontsize_labels, fontweight='bold')
ax_Sprofile.set_title(Sfigtitle, fontsize=fontsize_titles, fontweight='bold')
#ax_Sprofile.set_xlim(27.8, 35)
ax_Sprofile.set_ylim(-500, 0)
#
ax_Cprofile.set_xlabel('C (m/s)', fontsize=fontsize_labels, fontweight='bold')
ax_Cprofile.set_ylabel('Depth (m)', fontsize=fontsize_labels, fontweight='bold')
ax_Cprofile.set_title(Cfigtitle, fontsize=fontsize_titles, fontweight='bold')
#ax_Cprofile.set_xlim(1430., 1470.)
ax_Cprofile.set_ylim(-500, 0)
infileE3SM0 = f'./TSprofiles_data/E3SM-Arcticv2.1_historical/0151/icell{iCell:d}_profiles_E3SM-Arcticv2.1_historical0151_{season:02d}_years1950-1970.nc'
infileE3SM1 = f'./TSprofiles_data/E3SM-Arcticv2.1_historical/0151/icell{iCell:d}_profiles_E3SM-Arcticv2.1_historical0151_{season:02d}_years2000-2014.nc'
infileHighresMIP0 = f'./TSprofiles_data/HighresMIP/hist-1950/icell{iCell:d}_profiles_HighresMIP_hist-1950_{season:02d}_years1950-1970.nc'
infileHighresMIP1 = f'./TSprofiles_data/HighresMIP/hist-1950/icell{iCell:d}_profiles_HighresMIP_hist-1950_{season:02d}_years2000-2014.nc'
infileHighresMIP2 = f'./TSprofiles_data/HighresMIP/highres-future/icell{iCell:d}_profiles_HighresMIP_highres-future_{season:02d}_years2031-2050.nc'
dsE3SM0 = xr.open_dataset(infileE3SM0)
dsE3SM1 = xr.open_dataset(infileE3SM1)
dsHighresMIP0 = xr.open_dataset(infileHighresMIP0)
dsHighresMIP1 = xr.open_dataset(infileHighresMIP1)
dsHighresMIP2 = xr.open_dataset(infileHighresMIP2)
depthE3SM = dsE3SM0['depth'].values
depthHighresMIP = dsHighresMIP0['depth'].values
pres = gsw.conversions.p_from_z(-depthE3SM, latPoint)
presHighresMIP = gsw.conversions.p_from_z(-depthHighresMIP, latPoint)
Thist0 = dsHighresMIP0['Tprofile'].values
Shist0 = dsHighresMIP0['Sprofile'].values
SA = dsHighresMIP0['SAprofile'].values
CT = dsHighresMIP0['CTprofile'].values
soundspeedhist0 = gsw.sound_speed(SA, CT, presHighresMIP)
Thist1 = dsHighresMIP1['Tprofile'].values
Shist1 = dsHighresMIP1['Sprofile'].values
SA = dsHighresMIP1['SAprofile'].values
CT = dsHighresMIP1['CTprofile'].values
soundspeedhist1 = gsw.sound_speed(SA, CT, presHighresMIP)
Tssp = dsHighresMIP2['Tprofile'].values
Sssp = dsHighresMIP2['Sprofile'].values
SA = dsHighresMIP2['SAprofile'].values
CT = dsHighresMIP2['CTprofile'].values
soundspeedssp = gsw.sound_speed(SA, CT, presHighresMIP)
TE3SMhist0 = dsE3SM0['Tprofile'].values
SE3SMhist0 = dsE3SM0['Sprofile'].values
SA = dsE3SM0['SAprofile'].values
CT = dsE3SM0['CTprofile'].values
soundspeedE3SMhist0 = gsw.sound_speed(SA, CT, pres)
TE3SMhist1 = dsE3SM1['Tprofile'].values
SE3SMhist1 = dsE3SM1['Sprofile'].values
SA = dsE3SM1['SAprofile'].values
CT = dsE3SM1['CTprofile'].values
soundspeedE3SMhist1 = gsw.sound_speed(SA, CT, pres)
Tanomaly = Tssp-Thist1
Sanomaly = Sssp-Shist1
TanomalyE3SM = np.interp(depthE3SM, depthHighresMIP, Tanomaly)
SanomalyE3SM = np.interp(depthE3SM, depthHighresMIP, Sanomaly)
TE3SMssp = TE3SMhist1 + TanomalyE3SM
SE3SMssp = SE3SMhist1 + SanomalyE3SM
SA = gsw.conversions.SA_from_SP(SE3SMssp, pres, lonPoint, latPoint)
CT = gsw.conversions.CT_from_pt(SA, TE3SMssp)
soundspeedE3SMssp = gsw.sound_speed(SA, CT, pres)
outfile = f'{outdir}/icell{iCell:d}_profiles_E3SM-Arcticv2.1_historical0151_{season:02d}_years2031-2050_reconstructed.nc'
dsOut = xr.Dataset()
dsOut['Tprofile'] = TE3SMssp
dsOut['Tprofile'].attrs['units'] = 'degC'
dsOut['Tprofile'].attrs['long_name'] = 'Potential temperature'
dsOut['Sprofile'] = SE3SMssp
dsOut['Sprofile'].attrs['units'] = 'psu'
dsOut['Sprofile'].attrs['long_name'] = 'Salinity'
dsOut['CTprofile'] = CT
dsOut['CTprofile'].attrs['units'] = 'degC'
dsOut['CTprofile'].attrs['long_name'] = 'Conservative temperature'
dsOut['SAprofile'] = SA
dsOut['SAprofile'].attrs['units'] = 'psu'
dsOut['SAprofile'].attrs['long_name'] = 'Absolute salinity'
dsOut['Cprofile'] = soundspeedE3SMssp
dsOut['Cprofile'].attrs['units'] = 'm/s'
dsOut['Cprofile'].attrs['long_name'] = 'Sound speed (computed with python gsw package)'
dsOut['depth'] = depthE3SM
dsOut['depth'].attrs['units'] = 'm'
dsOut['depth'].attrs['long_name'] = 'depth levels'
dsOut.to_netcdf(outfile)
ax_Tprofile.plot(Thist0[::-1], -depthHighresMIP[::-1], '-', color='yellow', linewidth=3, label='HighresMIP 1950-1970')
ax_Tprofile.plot(Thist1[::-1], -depthHighresMIP[::-1], '-', color='gold', linewidth=3, label='HighresMIP 2000-2014')
ax_Tprofile.plot(Tssp[::-1], -depthHighresMIP[::-1], '-', color='darkgoldenrod', linewidth=3, label='HighresMIP 2031-2050')
ax_Tprofile.plot(TE3SMhist0[::-1], -depthE3SM[::-1], '-', color='lightblue', linewidth=3, label='E3SM-Arctic-0151 1950-1970')
ax_Tprofile.plot(TE3SMhist1[::-1], -depthE3SM[::-1], '-', color='dodgerblue', linewidth=3, label='E3SM-Arctic-0151 2000-2014')
ax_Tprofile.plot(TE3SMssp[::-1], -depthE3SM[::-1], '-', color='steelblue', linewidth=3, label='E3SM-Arctic-0151 2031-2050 (reconstructed)')
ax_Sprofile.plot(Shist0[::-1], -depthHighresMIP[::-1], '-', color='yellow', linewidth=3, label='HighresMIP 1950-1970')
ax_Sprofile.plot(Shist1[::-1], -depthHighresMIP[::-1], '-', color='gold', linewidth=3, label='HighresMIP 2000-2014')
ax_Sprofile.plot(Sssp[::-1], -depthHighresMIP[::-1], '-', color='darkgoldenrod', linewidth=3, label='HighresMIP 2031-2050')
ax_Sprofile.plot(SE3SMhist0[::-1], -depthE3SM[::-1], '-', color='lightblue', linewidth=3, label='E3SM-Arctic-0151 1950-1970')
ax_Sprofile.plot(SE3SMhist1[::-1], -depthE3SM[::-1], '-', color='dodgerblue', linewidth=3, label='E3SM-Arctic-0151 2000-2014')
ax_Sprofile.plot(SE3SMssp[::-1], -depthE3SM[::-1], '-', color='steelblue', linewidth=3, label='E3SM-Arctic-0151 2031-2050 (reconstructed)')
ax_Cprofile.plot(soundspeedhist0[::-1], -depthHighresMIP[::-1], '-', color='yellow', linewidth=3, label='HighresMIP 1950-1970')
ax_Cprofile.plot(soundspeedhist1[::-1], -depthHighresMIP[::-1], '-', color='gold', linewidth=3, label='HighresMIP 2000-2014')
ax_Cprofile.plot(soundspeedssp[::-1], -depthHighresMIP[::-1], '-', color='darkgoldenrod', linewidth=3, label='HighresMIP 2031-2050')
ax_Cprofile.plot(soundspeedE3SMhist0[::-1], -depthE3SM[::-1], '-', color='lightblue', linewidth=3, label='E3SM-Arctic-0151 1950-1970')
ax_Cprofile.plot(soundspeedE3SMhist1[::-1], -depthE3SM[::-1], '-', color='dodgerblue', linewidth=3, label='E3SM-Arctic-0151 2000-2014')
ax_Cprofile.plot(soundspeedE3SMssp[::-1], -depthE3SM[::-1], '-', color='steelblue', linewidth=3, label='E3SM-Arctic-0151 2031-2050 (reconstructed)')
ax_Tprofile.legend(prop=legend_properties, loc='lower left', bbox_to_anchor=(1, 0.5))
ax_Tprofile.grid(visible=True, which='both')
fig_Tprofile.savefig(Tfigfile, bbox_inches='tight')
plt.close(fig_Tprofile)
ax_Sprofile.legend(prop=legend_properties, loc='lower left', bbox_to_anchor=(1, 0.5))
ax_Sprofile.grid(visible=True, which='both')
fig_Sprofile.savefig(Sfigfile, bbox_inches='tight')
plt.close(fig_Sprofile)
ax_Cprofile.legend(prop=legend_properties, loc='lower left', bbox_to_anchor=(1, 0.5))
ax_Cprofile.grid(visible=True, which='both')
fig_Cprofile.savefig(Cfigfile, bbox_inches='tight')
plt.close(fig_Cprofile)