-
Notifications
You must be signed in to change notification settings - Fork 1
/
azmp_section_plot_mathilde.py
124 lines (105 loc) · 4.09 KB
/
azmp_section_plot_mathilde.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
'''
Pickled climatologies are generated by azmp_section_clim.py
see also an automatic function in:
azmp_section_tools.seasonal_section_plot(VAR, SECTION, SEASON, YEAR):
'''
import os
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import azmp_sections_tools as azst
import cmocean
## ---- Region parameters ---- ##
VAR = 'temperature'
SECTION = 'SI'
SEASON = 'summer'
YEAR = 1999
STATION_BASED = True
# derived parameters
if VAR == 'temperature':
v = np.arange(-2,11,1)
v_anom = np.linspace(-3.5, 3.5, 15)
v_anom = np.delete(v_anom, np.where(v_anom==0))
CMAP = cmocean.cm.thermal
elif VAR == 'salinity':
v = np.arange(29,36,.5)
v_anom = np.linspace(-1.5, 1.5, 16)
CMAP = cmocean.cm.haline
else:
v = 10
v_anom = 10
SECTION_BATHY = SECTION
## ---- Get this year's section ---- ##
pickled_stn = VAR + '_' + SECTION + '_' + SEASON + '_' + str(YEAR) + '_stn.pkl'
pickled_itp = VAR + '_' + SECTION + '_' + SEASON + '_' + str(YEAR) + '_itp.pkl'
df_section_stn = pd.read_pickle(pickled_stn)
df_section_itp = pd.read_pickle(pickled_itp)
if STATION_BASED:
df_section = df_section_stn
else:
df_section = df_section_itp
# In case df_section only contains NaNs..
df_section.dropna(axis=0,how='all')
if df_section.size == 0:
print(' !!! Empty section [return None] !!!')
else:
## ---- Get climatology ---- ##
clim_name = 'df_' + VAR + '_' + SECTION + '_' + SEASON + '_clim.pkl'
df_clim = pd.read_pickle(clim_name)
# Update index to add distance (in addition to existing station name)
df_clim.index = df_section_itp.loc[df_clim.index].index
## ---- Retrieve bathymetry using function ---- ##
bathymetry = azst.section_bathymetry(SECTION_BATHY)
## --- ---- ##
df_anom = df_section - df_clim
df_anom_stations = df_anom.reset_index(level=0, drop=True)
df_anom = df_anom.reset_index(level=0, drop=True)
## ---- plot Figure ---- ##
XLIM = df_section_itp.index[-1][1]
fig = plt.figure()
# ax1
ax = plt.subplot2grid((3, 1), (0, 0))
c = plt.contourf(df_section.index.droplevel(0), df_section.columns, df_section.T, v, cmap=CMAP, extend='max')
if VAR == 'temperature':
c_cil_itp = plt.contour(df_section.index.droplevel(0), df_section.columns, df_section.T, [0,], colors='k', linewidths=2)
ax.set_ylim([0, 400])
ax.set_xlim([0, XLIM])
ax.set_ylabel('Depth (m)', fontWeight = 'bold')
ax.invert_yaxis()
Bgon = plt.Polygon(bathymetry,color=np.multiply([1,.9333,.6667],.4), alpha=0.8)
ax.add_patch(Bgon)
plt.colorbar(c)
ax.xaxis.label.set_visible(False)
ax.tick_params(labelbottom='off')
ax.set_title(VAR + ' for section ' + SECTION + ' - ' + SEASON + ' ' + str(YEAR))
# ax2
ax2 = plt.subplot2grid((3, 1), (1, 0))
c = plt.contourf(df_clim.index.droplevel(0), df_clim.columns, df_clim.T, v, cmap=CMAP, extend='max')
if VAR == 'temperature':
c_cil_itp = plt.contour(df_clim.index.droplevel(0), df_clim.columns, df_clim.T, [0,], colors='k', linewidths=2)
ax2.set_ylim([0, 400])
ax2.set_xlim([0, XLIM])
ax2.set_ylabel('Depth (m)', fontWeight = 'bold')
ax2.invert_yaxis()
Bgon = plt.Polygon(bathymetry,color=np.multiply([1,.9333,.6667],.4), alpha=0.8)
ax2.add_patch(Bgon)
plt.colorbar(c)
ax2.xaxis.label.set_visible(False)
ax2.tick_params(labelbottom='off')
ax2.set_title('1981-2010 climatology')
# ax3
ax3 = plt.subplot2grid((3, 1), (2, 0))
c = plt.contourf(df_anom.index, df_anom.columns, df_anom.T, v_anom, cmap=cmocean.cm.balance, extend='both')
ax3.set_ylim([0, 400])
ax3.set_xlim([0, XLIM])
ax3.set_ylabel('Depth (m)', fontWeight = 'bold')
ax3.set_xlabel('Distance (km)', fontWeight = 'bold')
ax3.invert_yaxis()
Bgon = plt.Polygon(bathymetry,color=np.multiply([1,.9333,.6667],.4), alpha=0.8)
ax3.add_patch(Bgon)
plt.colorbar(c)
ax3.set_title(r'Anomaly')
fig.set_size_inches(w=8,h=12)
fig_name = VAR + '_' + SECTION + '_' + SEASON + '_' + str(YEAR) + '.png'
fig.savefig(fig_name, dpi=200)
os.system('convert -trim ' + fig_name + ' ' + fig_name)