Skip to content

Commit

Permalink
Add absolute errors
Browse files Browse the repository at this point in the history
Plot absolute errors on another vertical axis on same panel as
fractional errors.
  • Loading branch information
trhille committed Oct 19, 2023
1 parent 3c716e9 commit 383ed64
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions landice/output_processing_li/plot_mass_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
dyr[1:] = yr[1:]-yr[:-1]

# ---- Figure: mass change rate ---
fig, ax = plt.subplots(3,3)

fig, ax = plt.subplots(3,3, figsize=(15,12))
#=====================
# 1. Total mass budget
#=====================
Expand All @@ -58,7 +57,8 @@

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

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

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

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

ax[2,0].semilogy(yr, np.abs( ( (dvol) - (SMB+BMB+calv+FMF) ) / dvol ) )
ax[2,0].set_ylabel('fractional error')

ax[2,0].semilogy(yr, np.abs( (tot - dvol ) / dvol ) )
ax[2,0].set_ylabel('fractional error', color='tab:blue')
absErrAxTot = ax[2,0].twinx()
absErrAxTot.plot(yr, tot - dvol, color='tab:orange')
#========================
# 2. Grounded mass budget
#========================
Expand Down Expand Up @@ -107,11 +108,13 @@
GLMigrationflux = -f.variables['groundingLineMigrationFlux'][:]/1.0e12
ax[0,1].plot(yr, GLMigrationflux, label="GL migration flux")

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

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

# --- Figure: cumulative mass change ---

ax[1,1].plot(yr, volGround - volGround[0], 'k', linewidth=3, label='total mass change')
ax[1,1].plot(yr, (SMBg*dyr).cumsum(), label="SMB")
ax[1,1].plot(yr, (BMBg*dyr).cumsum(), label="BMB")
Expand All @@ -120,13 +123,13 @@
ax[1,1].plot(yr, (FMFg*dyr).cumsum(), label='facemelt')
ax[1,1].plot(yr, (GLflux*dyr).cumsum(), label="GL flux")
ax[1,1].plot(yr, (GLMigrationflux*dyr).cumsum(), label="GL Migration flux")
ax[1,1].plot(yr, ( (SMBg+BMBg+calvg+FMFg+GLflux+GLMigrationflux) * dyr).cumsum(), "--", label='total budget')
ax[1,1].plot(yr, ( (grndTot) * dyr).cumsum(), "--", label='total budget')

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

ax[2,1].semilogy(yr, np.abs( ( (dvolGround) - (SMBg+BMBg+calvg+FMFg+GLflux+GLMigrationflux) ) / dvolGround ) )


absErrAxGrnd = ax[2,1].twinx()
absErrAxGrnd.plot(yr, grndTot - dvolGround, color='tab:orange')
#========================
# 3. Floating mass budget
#========================
Expand All @@ -150,12 +153,12 @@
FMFf = -f.variables['totalFloatingFaceMeltingFlux'][:] / 1.0e12
ax[0,2].plot(yr, FMFf, label='facemelt')

GLflux = f.variables['groundingLineFlux'][:]/1.0e12
ax[0,2].plot(yr, GLflux, label="GL flux")
ax[0,2].plot(yr, -GLflux, label="GL flux")

ax[0,2].plot(yr, -GLMigrationflux, label="GL migration flux")

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

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

Expand All @@ -166,13 +169,17 @@

ax[1,2].plot(yr, (calvf*dyr).cumsum(), label='calving')
ax[1,2].plot(yr, (FMFf*dyr).cumsum(), label='facemelt')
ax[1,2].plot(yr, (GLflux*dyr).cumsum(), label="GL flux")
ax[1,2].plot(yr, (GLMigrationflux*dyr).cumsum(), label="GL Migration flux")
ax[1,2].plot(yr, ( (SMBf+BMBf+calvf+FMFf+GLflux+GLMigrationflux) * dyr).cumsum(), "--", label='total budget')
ax[1,2].plot(yr, (-GLflux*dyr).cumsum(), label="GL flux")
ax[1,2].plot(yr, (-GLMigrationflux*dyr).cumsum(), label="GL Migration flux")
ax[1,2].plot(yr, (fltTot * dyr).cumsum(), "--", label='total budget')

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

ax[2,2].semilogy(yr, np.abs( ( (dvolFloat) - (SMBf+BMBf+calvf+FMFf+GLflux+GLMigrationflux) ) / dvolFloat ) )
ax[2,2].semilogy(yr, np.abs( (fltTot - dvolFloat) / dvolFloat ) )

absErrAxFlt = ax[2,2].twinx()
absErrAxFlt.plot(yr, fltTot - dvolFloat, color='tab:orange')
absErrAxFlt.set_ylabel('Absolute error (Gt; budget - true)', color='tab:orange')

for plotAx in ax.ravel():
plotAx.grid('on')
Expand All @@ -183,5 +190,7 @@
ax[0,0].set_title('Total budget')
ax[0,1].set_title('Grounded budget')
ax[0,2].set_title('Floating budget')

fig.subplots_adjust(wspace=0.5)
plt.show()
f.close()

0 comments on commit 383ed64

Please sign in to comment.