Skip to content

Commit 3f901f5

Browse files
committed
Add absolute errors
Plot absolute errors on another vertical axis on same panel as fractional errors.
1 parent 33ff44e commit 3f901f5

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

landice/output_processing_li/plot_mass_balance.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
dyr[1:] = yr[1:]-yr[:-1]
3131

3232
# ---- Figure: mass change rate ---
33-
fig, ax = plt.subplots(3,3)
34-
33+
fig, ax = plt.subplots(3,3, figsize=(15,12))
3534
#=====================
3635
# 1. Total mass budget
3736
#=====================
@@ -58,7 +57,8 @@
5857

5958
# Grounding line flux and grounding line migration flux
6059
# do not come into the global mass budget
61-
ax[0,0].plot(yr, SMB+BMB+calv+FMF, "--", label="total")
60+
tot = SMB+BMB+calv+FMF
61+
ax[0,0].plot(yr, tot, "--", label="total")
6262

6363
ax[0,0].legend(loc='best', prop={'size': 6})
6464
ax[0,0].set_ylabel('Mass change (Gt)')
@@ -70,14 +70,15 @@
7070

7171
ax[1,0].plot(yr, (calv*dyr).cumsum(), label='calving')
7272
ax[1,0].plot(yr, (FMF*dyr).cumsum(), label='facemelt')
73-
ax[1,0].plot(yr, ( (SMB+BMB+calv+FMF) * dyr).cumsum(), "--", label='total budget')
73+
ax[1,0].plot(yr, (tot * dyr).cumsum(), "--", label='total budget')
7474

7575
ax[1,0].legend(loc='best', prop={'size': 6})
7676
ax[1,0].set_ylabel('Cumulative mass change (Gt)')
7777

78-
ax[2,0].semilogy(yr, np.abs( ( (dvol) - (SMB+BMB+calv+FMF) ) / dvol ) )
79-
ax[2,0].set_ylabel('fractional error')
80-
78+
ax[2,0].semilogy(yr, np.abs( (tot - dvol ) / dvol ) )
79+
ax[2,0].set_ylabel('fractional error', color='tab:blue')
80+
absErrAxTot = ax[2,0].twinx()
81+
absErrAxTot.plot(yr, tot - dvol, color='tab:orange')
8182
#========================
8283
# 2. Grounded mass budget
8384
#========================
@@ -107,11 +108,13 @@
107108
GLMigrationflux = -f.variables['groundingLineMigrationFlux'][:]/1.0e12
108109
ax[0,1].plot(yr, GLMigrationflux, label="GL migration flux")
109110

110-
ax[0,1].plot(yr, SMBg+BMBg+calvg+FMFg+GLflux+GLMigrationflux, "--", label="total")
111+
grndTot = SMBg+calvg+BMBg+FMFg+GLflux+GLMigrationflux
112+
ax[0,1].plot(yr, grndTot, "--", label="total")
111113

112114
ax[0,1].legend(loc='best', prop={'size': 6})
113115

114116
# --- Figure: cumulative mass change ---
117+
115118
ax[1,1].plot(yr, volGround - volGround[0], 'k', linewidth=3, label='total mass change')
116119
ax[1,1].plot(yr, (SMBg*dyr).cumsum(), label="SMB")
117120
ax[1,1].plot(yr, (BMBg*dyr).cumsum(), label="BMB")
@@ -120,13 +123,13 @@
120123
ax[1,1].plot(yr, (FMFg*dyr).cumsum(), label='facemelt')
121124
ax[1,1].plot(yr, (GLflux*dyr).cumsum(), label="GL flux")
122125
ax[1,1].plot(yr, (GLMigrationflux*dyr).cumsum(), label="GL Migration flux")
123-
ax[1,1].plot(yr, ( (SMBg+BMBg+calvg+FMFg+GLflux+GLMigrationflux) * dyr).cumsum(), "--", label='total budget')
126+
ax[1,1].plot(yr, ( (grndTot) * dyr).cumsum(), "--", label='total budget')
124127

125128
ax[1,1].legend(loc='best', prop={'size': 6})
129+
ax[2,1].semilogy(yr, np.abs( (grndTot - dvolGround) / dvolGround ) )
126130

127-
ax[2,1].semilogy(yr, np.abs( ( (dvolGround) - (SMBg+BMBg+calvg+FMFg+GLflux+GLMigrationflux) ) / dvolGround ) )
128-
129-
131+
absErrAxGrnd = ax[2,1].twinx()
132+
absErrAxGrnd.plot(yr, grndTot - dvolGround, color='tab:orange')
130133
#========================
131134
# 3. Floating mass budget
132135
#========================
@@ -150,12 +153,12 @@
150153
FMFf = -f.variables['totalFloatingFaceMeltingFlux'][:] / 1.0e12
151154
ax[0,2].plot(yr, FMFf, label='facemelt')
152155

153-
GLflux = f.variables['groundingLineFlux'][:]/1.0e12
154-
ax[0,2].plot(yr, GLflux, label="GL flux")
156+
ax[0,2].plot(yr, -GLflux, label="GL flux")
157+
158+
ax[0,2].plot(yr, -GLMigrationflux, label="GL migration flux")
155159

156-
GLMigrationflux = f.variables['groundingLineMigrationFlux'][:]/1.0e12
157-
ax[0,2].plot(yr, GLMigrationflux, label="GL migration flux")
158-
ax[0,2].plot(yr, SMBf+BMBf+calvf+FMFf+GLflux+GLMigrationflux, "--", label="total")
160+
fltTot = SMBf+BMBf+FMFf+calvf-GLflux-GLMigrationflux
161+
ax[0,2].plot(yr, fltTot, "--", label="total")
159162

160163
ax[0,2].legend(loc='best', prop={'size': 6})
161164

@@ -166,13 +169,17 @@
166169

167170
ax[1,2].plot(yr, (calvf*dyr).cumsum(), label='calving')
168171
ax[1,2].plot(yr, (FMFf*dyr).cumsum(), label='facemelt')
169-
ax[1,2].plot(yr, (GLflux*dyr).cumsum(), label="GL flux")
170-
ax[1,2].plot(yr, (GLMigrationflux*dyr).cumsum(), label="GL Migration flux")
171-
ax[1,2].plot(yr, ( (SMBf+BMBf+calvf+FMFf+GLflux+GLMigrationflux) * dyr).cumsum(), "--", label='total budget')
172+
ax[1,2].plot(yr, (-GLflux*dyr).cumsum(), label="GL flux")
173+
ax[1,2].plot(yr, (-GLMigrationflux*dyr).cumsum(), label="GL Migration flux")
174+
ax[1,2].plot(yr, (fltTot * dyr).cumsum(), "--", label='total budget')
172175

173176
ax[1,2].legend(loc='best', prop={'size': 6})
174177

175-
ax[2,2].semilogy(yr, np.abs( ( (dvolFloat) - (SMBf+BMBf+calvf+FMFf+GLflux+GLMigrationflux) ) / dvolFloat ) )
178+
ax[2,2].semilogy(yr, np.abs( (fltTot - dvolFloat) / dvolFloat ) )
179+
180+
absErrAxFlt = ax[2,2].twinx()
181+
absErrAxFlt.plot(yr, fltTot - dvolFloat, color='tab:orange')
182+
absErrAxFlt.set_ylabel('Absolute error (Gt; budget - true)', color='tab:orange')
176183

177184
for plotAx in ax.ravel():
178185
plotAx.grid('on')
@@ -183,5 +190,7 @@
183190
ax[0,0].set_title('Total budget')
184191
ax[0,1].set_title('Grounded budget')
185192
ax[0,2].set_title('Floating budget')
193+
194+
fig.subplots_adjust(wspace=0.5)
186195
plt.show()
187196
f.close()

0 commit comments

Comments
 (0)