Created by Ivan Lima on Thu Jul 20 2017 15:47:57 -0400
%matplotlib notebook
import pandas as pd
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import os
from matplotlib import colors
from cesm_utils import *
from cases import *
from datetime import datetime
_ = plt.rcParams['xtick.minor.bottom'] = False # fix strange minor ticks in time series plots
print('Last updated on %s'%datetime.now().ctime())
case = 'tr3he.GIAF.06'
print(case,':',case_info[case])
datadir = '/home/ivan/Data/Postproc/Tritium-3H'
store = pd.HDFStore(os.path.join(datadir,'%s_tseries.h5'%case))
df_tseries = store['df']
store.close()
df_annual = df_tseries.groupby(df_tseries.index.year).mean() # compute annual means
fig, axs = plt.subplots(nrows=2,ncols=2,sharex=True,figsize=(9.5,7.125))
fig.subplots_adjust(wspace=0.25)
fig.delaxes(axs[1,1])
_ = df_tseries.TRITIUM.plot(ax=axs[0,0],title='$^3\!$H inventory')
_ = df_tseries.TRITIUM_DECAY.plot(ax=axs[0,1],title='$^3\!$H decay')
_ = df_tseries.STF_TRITIUM.plot(ax=axs[1,0],title='$^3\!$H total surface flux')
_ = axs[0,0].set_ylabel(r'mol')
_ = axs[0,1].set_ylabel(r'mol d$^{-1}$')
_ = axs[1,0].set_ylabel(r'mol d$^{-1}$')
fig, axs = plt.subplots(nrows=3,ncols=2,sharex=True,figsize=(9.5,9))
fig.delaxes(axs[2,1])
fig.subplots_adjust(wspace=0.25)
_ = df_tseries.STF_TRITIUM_PREC.plot(ax=axs[0,0],title='$^3\!$H precipitation flux')
_ = df_tseries.STF_TRITIUM_EVAP.plot(ax=axs[0,1],title='$^3\!$H evaporation flux')
_ = df_tseries.STF_TRITIUM_EVAP_UP.plot(ax=axs[1,0],title='upward $^3\!$H vapor flux')
_ = df_tseries.STF_TRITIUM_EVAP_DOWN.plot(ax=axs[1,1],title='downward $^3\!$H vapor flux')
_ = df_tseries.STF_TRITIUM_ROFF.plot(ax=axs[2,0],title='$^3\!$H river flux')
for ax in axs.ravel():
_ = ax.set_ylabel(r'mol d$^{-1}$')
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,3.4))
fig.subplots_adjust(wspace=0.3)
_ = df_tseries.PREC_F.plot(ax=ax1,title='precipitation')
_ = df_tseries.EVAP_F.plot(ax=ax2,title='evaporation')
_ = ax1.set_ylabel(r'm$^{-3}$ d$^{-1}$')
_ = ax2.set_ylabel(r'm$^{-3}$ d$^{-1}$')
dpm2 = np.resize(dpm,len(df_tseries)) # days per month
dtritium_dt = df_tseries.TRITIUM.diff()/dpm2 # mols/day
df_tseries['SMS_TRITIUM'] = df_tseries.STF_TRITIUM - df_tseries.TRITIUM_DECAY
fig, axs = plt.subplots(nrows=2,ncols=2,sharex=True,figsize=(9.5,7.125))
fig.subplots_adjust(wspace=0.25)
_ = dtritium_dt.plot(ax=axs[0,0],title=r'$\frac{\Delta ^3\!H}{\Delta t}$')
_ = df_tseries.STF_TRITIUM.plot(ax=axs[0,1],title='$^3\!H$ surface flux')
_ = df_tseries.TRITIUM_DECAY.plot(ax=axs[1,0],title='$^3\!H$ decay')
_ = df_tseries.SMS_TRITIUM.plot(ax=axs[1,1],title='$^3\!H$ surface flux - $^3\!H$ decay')
for ax in axs.ravel():
_ = ax.set_ylabel(r'mol d$^{-1}$')
# df = pd.DataFrame({'$\Delta$3H/$\Delta$t':dtritium_dt,'flux - decay':df_tseries.SMS_TRITIUM})
# df.tail(12)
mean_flux = df_tseries.STF_TRITIUM.mean()
print('mean tritium flux = %.6f mol/day'%mean_flux)
hlife = 12.31 * 365 # days
lam = -np.log(0.5)/hlife
decay = lam * df_tseries.TRITIUM[-1]
print('decay = %.6f mol/day'%decay)
print('decay = %.6f mol/day'%df_tseries.TRITIUM_DECAY[-1])
CTB = completely trapped bubbles, PTB = partially trapped bubbles, DGE = difusive gas exchange
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,4))
helium = df_tseries.HELIUM3 * 1.e-6 # mol -> 10^6 mol
_ = helium.plot(ax=ax1,title=r'$^3\!$He inventory')
_ = ax1.set_ylabel(r'$10^6$ mol')
_ = df_tseries[['STF_HELIUM3','STF_HELIUM3_CTB','STF_HELIUM3_PTB',
'STF_HELIUM3_DGE']].plot(ax=ax2,title=r'$^3\!$He air-sea flux')
_ = ax2.hlines(0,df_tseries.index[0],df_tseries.index[-1],linestyles='dashed',linewidth=1)
_ = ax2.set_ylabel(r'mol d$^{-1}$')
Global mean fluxes (mol d$^{-1}$)
df_tseries[['STF_HELIUM3','STF_HELIUM3_CTB','STF_HELIUM3_PTB','STF_HELIUM3_DGE']].mean()
CTB = completely trapped bubbles, PTB = partially trapped bubbles, DGE = difusive gas exchange
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,4))
helium_annual = df_annual['HELIUM3'] * 1.e-6 # mol -> 10^6 mol
_ = helium_annual.plot(ax=ax1,title=r'$^3\!$He inventory')
_ = ax1.set_ylabel(r'$10^6$ mol')
_ = df_annual[['STF_HELIUM3','STF_HELIUM3_CTB','STF_HELIUM3_PTB',
'STF_HELIUM3_DGE']].plot(ax=ax2,title=r'$^3\!$He air-sea flux')
_ = ax2.hlines(0,df_annual.index[0],df_annual.index[-1],linestyles='dashed',linewidth=1)
_ = ax2.set_ylabel(r'mol d$^{-1}$')
CTB = completely trapped bubbles, PTB = partially trapped bubbles, DGE = difusive gas exchange
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,4))
helium = df_tseries[['INERT_HELIUM3']] * 1.e-6 # mol -> 10^6 mol
_ = helium.plot(ax=ax1,title=r'inert $^3\!$He inventory')
_ = ax1.set_ylabel(r'$10^6$ mol')
_ = df_tseries[['STF_INERT_HELIUM3','STF_INERT_HELIUM3_CTB','STF_INERT_HELIUM3_PTB',
'STF_INERT_HELIUM3_DGE']].plot(ax=ax2,title=r'inert $^3\!$He air-sea flux')
_ = ax2.hlines(0,df_tseries.index[0],df_tseries.index[-1],linestyles='dashed',linewidth=1)
_ = ax2.set_ylabel(r'mol d$^{-1}$')
Global mean fluxes (mol d$^{-1}$)
df_tseries[['STF_INERT_HELIUM3','STF_INERT_HELIUM3_CTB','STF_INERT_HELIUM3_PTB','STF_INERT_HELIUM3_DGE']].mean()
Data is very noisy, so we're looking at cumulative changes and fluxes.
cum_dhelium3 = (df_tseries.HELIUM3.diff()).cumsum() # mol
cum_flux_plus_decay = ((df_tseries.STF_HELIUM3 + df_tseries.TRITIUM_DECAY) * dpm2).cumsum() # mol
df = pd.DataFrame({r'$\sum$ $\Delta$3He':cum_dhelium3,r'$\sum$ (flux + 3H decay)$\times \Delta$t':cum_flux_plus_decay})
fig, ax = plt.subplots()
_ = df.plot(ax=ax)
_ = ax.set_ylabel(r'mol')
df.tail()
df_tseries['EXCESS_HELIUM3'] = (df_tseries.HELIUM3 - df_tseries.INERT_HELIUM3)
df_tseries['STF_EXCESS_HELIUM3'] = df_tseries.STF_HELIUM3 - df_tseries.STF_INERT_HELIUM3
fig, axs = plt.subplots(ncols=2,nrows=2,sharex=True,figsize=(9.5,7.125))
axs = axs.ravel()
fig.delaxes(axs[-1])
fig.subplots_adjust(wspace=0.25)
_ = df_tseries.EXCESS_HELIUM3.plot(ax=axs[0],title=r'excess $^3\!$He inventory')
_ = axs[0].set_ylabel(r'mol')
_ = df_tseries.STF_EXCESS_HELIUM3.plot(ax=axs[1],title=r'excess $^3\!$He air-sea flux')
_ = axs[1].set_ylabel(r'mol d$^{-1}$')
_ = df_tseries.TRITIUM_DECAY.plot(ax=axs[2],title=r'$^3\!$H decay')
_ = axs[2].set_ylabel(r'mol d$^{-1}$')
CTB = completely trapped bubbles, PTB = partially trapped bubbles, DGE = difusive gas exchange
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,4))
helium4 = df_tseries.HELIUM4 * 1.e-12 # mol -> 10^12 mol
_ = helium4.plot(ax=ax1,title=r'$^4\!$He inventory')
_ = ax1.set_ylabel(r'$10^{12}$ mol')
_ = df_tseries[['STF_HELIUM4','STF_HELIUM4_CTB','STF_HELIUM4_PTB',
'STF_HELIUM4_DGE']].plot(ax=ax2,title=r'$^4\!$He air-sea flux')
_ = ax2.hlines(0,df_tseries.index[0],df_tseries.index[-1],linestyles='dashed',linewidth=1)
_ = ax2.set_ylabel(r'mol d$^{-1}$')
Global mean fluxes (mol d$^{-1}$)
df_tseries[['STF_HELIUM4','STF_HELIUM4_CTB','STF_HELIUM4_PTB','STF_HELIUM4_DGE']].mean()
CTB = completely trapped bubbles, PTB = partially trapped bubbles, DGE = difusive gas exchange
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,4))
fig.subplots_adjust(wspace=0.25)
neon = df_tseries.NEON * 1.e-12 # mol -> 10^12 mol
_ = neon.plot(ax=ax1,title=r'Ne inventory')
_ = ax1.set_ylabel(r'$10^{12}$ mol')
_ = df_tseries[['STF_NEON','STF_NEON_CTB','STF_NEON_PTB','STF_NEON_DGE']].plot(ax=ax2,title=r'Ne air-sea flux')
_ = ax2.hlines(0,df_tseries.index[0],df_tseries.index[-1],linestyles='dashed',linewidth=1)
_ = ax2.set_ylabel(r'mol d$^{-1}$')
Global mean fluxes (mol d$^{-1}$)
df_tseries[['STF_NEON','STF_NEON_CTB','STF_NEON_PTB','STF_NEON_DGE']].mean()
CTB = completely trapped bubbles, PTB = partially trapped bubbles, DGE = difusive gas exchange
fig, (ax1, ax2) = plt.subplots(ncols=2,figsize=(9.5,4))
fig.subplots_adjust(wspace=0.25)
argon = df_tseries.ARGON * 1.e-15 # mol -> 10^15 mol
_ = argon.plot(ax=ax1,title=r'Ar inventory')
_ = ax1.set_ylabel(r'$10^{15}$ mol')
_ = df_tseries[['STF_ARGON','STF_ARGON_CTB','STF_ARGON_PTB','STF_ARGON_DGE']].plot(ax=ax2,title=r'Ne air-sea flux')
_ = ax2.hlines(0,df_tseries.index[0],df_tseries.index[-1],linestyles='dashed',linewidth=1)
_ = ax2.set_ylabel(r'mol d$^{-1}$')
Global mean fluxes (mol d$^{-1}$)
df_tseries[['STF_ARGON','STF_ARGON_CTB','STF_ARGON_PTB','STF_ARGON_DGE']].mean()
infile = os.path.join(datadir,'%s_tritium_prec.nc'%case)
ds = xr.open_dataset(infile,decode_times=False)
ds = fixtime(ds,1824)
ds['time'] = ds.time.to_index().to_datetimeindex()
tlat = ds.TLAT[:-13]
data = da2ma(ds.TRITIUM_PREC[:,:-13])
xt = pd.date_range('1950-01-01','2010-12-31',freq='10A')
fig, ax = plt.subplots()
pm = ax.pcolormesh(ds.time,tlat,data.transpose(),norm=colors.LogNorm(),cmap=plt.cm.YlOrRd)
_ = ax.set(xticks=xt,xlabel='time',ylabel='latitude',title=r'$^3\!$H concentration in precipitation')
cb = fig.colorbar(pm,ax=ax)
cb.set_label(r'pmol m$^{-3}$')
data = da2ma(ds.TRITIUM_RIVER[:,:-13])
fig, ax = plt.subplots()
pm = ax.pcolormesh(ds.time,tlat,data.transpose(),norm=colors.LogNorm(),cmap=plt.cm.YlOrRd)
_ = ax.set(xticks=xt,xlabel='time',ylabel='latitude',title=r'$^3\!$H concentration in rivers')
cb = fig.colorbar(pm,ax=ax)
cb.set_label(r'pmol m$^{-3}$')