forked from matthewhoffman/e3sm-cryo-analysis-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles_T_S_rho_t.py
executable file
·180 lines (150 loc) · 6.08 KB
/
profiles_T_S_rho_t.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
#!/usr/bin/env python
'''
Script to compare some scalar values from different runs of Thwaites melt variability experiment.
'''
import sys
import os
import netCDF4
import datetime
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal
from matplotlib import cm
from math import pi
#run = 'ISMF'
run = 'ISMF-noEAIS'
savepath='/global/homes/c/cbegeman/weddell_output/'
fmesh=netCDF4.Dataset('/project/projectdirs/acme/inputdata/ocn/mpas-o/oEC60to30v3wLI/oEC60to30v3wLI60lev.171031.nc')
runname = ['ISMF',
'ISMF-noEAIS']
runpath = ['/global/cscratch1/sd/dcomeau/acme_scratch/cori-knl/20190225.GMPAS-DIB-IAF-ISMF.T62_oEC60to30v3wLI.cori-knl/archive/ocn/hist',
'/global/cscratch1/sd/hoffman2/acme_scratch/edison/20190423.GMPAS-DIB-IAF-ISMF.T62_oEC60to30v3wLI.edison.restrictedMelt/run']
latCell = fmesh.variables['latCell'][:]
lonCell = fmesh.variables['lonCell'][:]
xCell = fmesh.variables['xCell'][:]
yCell = fmesh.variables['yCell'][:]
depths = fmesh.variables['refBottomDepth'][:]
zmax = fmesh.variables['bottomDepth'][:]
print(zmax.shape)
depths = fmesh.variables['refBottomDepth'][:]
print(depths.shape)
zh = fmesh.variables['layerThickness'][:]
print(zh.shape)
z = np.zeros(depths.shape)
z[0] = -0.5 * depths[0]
z[1:] = -0.5 * (depths[0:-1] + depths[1:])
#nz = len(z)
deg2rad = pi/180.
#latplt = -1.323514
#lonplt = 5.672896
latS = 73
lonW = 32
locname = str(latS) + 'S' + str(lonW) + 'W'
latplt = -1.*latS*deg2rad
lonplt = (360.-lonW)*deg2rad
#idx=67250-1
idx = np.argmin( (latCell-latplt)**2 + (lonCell-lonplt)**2) #122901-1
#idx=198673-1
#idx=210384-1 # filchner sill
maxLevelCell=fmesh.variables['maxLevelCell'][idx]
nz = maxLevelCell
# plot location
#fig = plt.figure(2, facecolor='w')
#plt.plot(yCell[idx], xCell[idx], 'r.')
#idx2 = np.nonzero(latCell<-60.0/180.0*pi)[0]
#plt.plot(yCell[idx2], xCell[idx2], 'k.')
#plt.plot(yCell[idx], xCell[idx], 'r.')
#path='/global/cscratch1/sd/dcomeau/acme_scratch/cori-knl/20190225.GMPAS-DIB-IAF-ISMF.T62_oEC60to30v3wLI.cori-knl/run'
#path='/global/cscratch1/sd/dcomeau/acme_scratch/cori-knl/20190225.GMPAS-DIB-IAF.T62_oEC60to30v3wLI.cori-knl/run'
#path='/global/cscratch1/sd/kehoch/acme_scratch/cori-knl/20190304.GMPAS-IAF-ISMF.T62_oEC60to30v3wLI.cori-knl/run'
#path='/global/cscratch1/sd/kehoch/acme_scratch/cori-knl/20190304.GMPAS-IAF.T62_oEC60to30v3wLI.cori-knl/run'
#path='/global/cscratch1/sd/hoffman2/acme_scratch/edison/20190423.GMPAS-DIB-IAF-ISMF.T62_oEC60to30v3wLI.edison.restrictedMelt/run'
#path='/global/cscratch1/sd/hoffman2/acme_scratch/edison/archive/20190306.A_WCYCL1850-DIB-ISMF_CMIP6.ne30_oECv3wLI.edison/ocn/hist'
#path='/global/cscratch1/sd/hoffman2/acme_scratch/edison/archive/20190306.A_WCYCL1850-DIB_CMIP6.ne30_oECv3wLI.edison/ocn/hist'
startyr = 95
endyr = 101
years = np.arange(startyr,endyr+1,1)
months = np.arange(1,13,1)
nt = len(years)*len(months)
times = np.zeros((nt,))
Tdata = np.zeros((nz, nt))
Sdata = np.zeros((nz, nt))
rhodata = np.zeros((nz, nt))
udata = np.zeros((nz, nt))
vdata = np.zeros((nz, nt))
t=0
for yr in years:
for mo in months:
times[t] = yr+(mo-1.0)/12.0
datestr = '{0:04d}-{1:02d}'.format(yr, mo)
filename = '{0}/mpaso.hist.am.timeSeriesStatsMonthly.'.format(runpath[runname.index(run)]) + datestr + '-01.nc'
f = netCDF4.Dataset(filename, 'r')
#f=netCDF4.Dataset('{0}/mpaso.hist.am.timeSeriesStatsMonthly.{1:04d}-{2:02d}-01.nc'.format(path, yr, mo), 'r')
T=f.variables['timeMonthly_avg_activeTracers_temperature']
S=f.variables['timeMonthly_avg_activeTracers_salinity']
rho = f.variables['timeMonthly_avg_potentialDensity']
u = f.variables['timeMonthly_avg_velocityZonal']
v = f.variables['timeMonthly_avg_velocityMeridional']
# get data
Tdata[:,t] = T[0,idx,:nz]
Sdata[:,t] = S[0,idx,:nz]
rhodata[:,t] = rho[0,idx,:nz]
udata[:,t] = u[0,idx,:nz]
vdata[:,t] = v[0,idx,:nz]
f.close()
t += 1
fig = plt.figure(1, facecolor='w')
nrow=5
ncol=1
maxDepth=-800.0
axT = fig.add_subplot(nrow, ncol, 1)
plt.xlabel('year')
plt.ylabel('temperature\n(deg. C)')
plt.pcolor(times, z[:nz], Tdata, vmin=-2.1, vmax=1.6, cmap='nipy_spectral')#, vmin=-2.0, vmax=0.0)
axT.set_ylim((maxDepth, 0))
plt.colorbar()
#plt.contour(times, z[:nz], Tdata, [-1.8])
plt.title(run + ': ' + locname)
axS = fig.add_subplot(nrow, ncol, 2)
plt.xlabel('year')
plt.ylabel('salinity\n(psu)')
plt.pcolor(times, z[:nz], Sdata, vmin=33.5,vmax=34.6, cmap='nipy_spectral')#, vmin=31.0, vmax=34.7)
axS.set_ylim((maxDepth, 0))
plt.colorbar()
axrho = fig.add_subplot(nrow, ncol, 3)
plt.xlabel('year')
plt.ylabel('pot. dens.\n(kg/m3)')
plt.pcolor(times, z[:nz], rhodata, vmin=1027.2,vmax=1027.7, cmap='nipy_spectral')#, vmin=31.0, vmax=34.7)
axrho.set_ylim((maxDepth, 0))
plt.colorbar()
axu = fig.add_subplot(nrow, ncol, 4)
plt.xlabel('year')
plt.ylabel('east velo\n(m/s)')
plt.pcolor(times, z[:nz], udata, cmap='seismic', vmin=-0.05, vmax=0.05)
axu.set_ylim((maxDepth, 0))
plt.colorbar()
#axv = plt.figure(5, facecolor='w')
axv = fig.add_subplot(nrow, ncol, 5)
plt.xlabel('year')
plt.ylabel('n velo\n(m/s)')
plt.pcolor(times, z[:nz], vdata, cmap='seismic', vmin=-0.05, vmax=0.05)
axv.set_ylim((maxDepth, 0))
plt.colorbar()
#waterMassMask = np.zeros((nz, nt))
#waterMassMask[np.where((Sdata>34.0) * (Tdata>0.0))] = 1 # CDW
#waterMassMask[np.where((Sdata>34.0) * (Tdata<0.0) * (Tdata>-1.5))] = 2 # mCDW
#waterMassMask[np.where( (Tdata>(-0.0575*Sdata+0.0901)) * (Sdata>34.5) * (Tdata<-1.5))] = 3 # HSSW
#waterMassMask[np.where( (Tdata>(-0.0575*Sdata+0.0901)) * (Sdata<34.5) * (Sdata>34.0) * (Tdata<-1.5))] = 4 # LSSW
#waterMassMask[np.where( (Tdata>(-0.0575*Sdata+0.0901)) * (Sdata<34.0))] = 5 # AASW
#waterMassMask[np.where(Tdata<(-0.0575*Sdata+0.0901))] = 6 # ISW
#
##fig = plt.figure(5, facecolor='w')
#axMass = fig.add_subplot(nrow,ncol,5)
#plt.pcolor(times, z[:nz], waterMassMask, vmin=0.5, vmax=6.5, cmap=cm.get_cmap('tab10',6) )
#cbar = plt.colorbar(ticks=[1,2,3,4,5,6])
#cbar.ax.set_yticklabels(['CDW','mCDW','HSSW','LSSW','AASW','ISW'])
#plt.xlabel('year')
#plt.ylabel('depth (m)')
#axMass.set_ylim((maxDepth, 0))
plt.savefig(savepath + run + '_hovmoller_' + locname + '_' + str(startyr) + '-' + str(endyr) + '.png')
plt.close()