Created by Ivan Lima on Thu Jul 20 2017 14:33:34 -0400
%matplotlib notebook
import xarray as xr
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import os
from matplotlib import ticker, colors
from mpl_utils import spd, center_cmap
from cesm_utils import *
from cases import *
from datetime import datetime
print('Last updated on %s'%datetime.now().ctime())
case = 'tr3he.GIAF.06'
print(case,':',case_info[case])
datadir = '/home/ivan/Data/Postproc/Tritium-3H'
ds = xr.open_dataset(os.path.join(datadir,'%s_surf.nc'%case),decode_times=False)
ds = fixtime(ds,1824)
ds = ds.where(ds.REGION_MASK>0) # mask marginal seas for plotting
ds = ds.drop('dz')
ds = ds.squeeze(dim='z_t',drop=True) # remove dimensions of length 1
lon = ds.TLONG.values
loncp = np.where(np.greater_equal(lon,lon[:,0].min()),lon-360,lon) # monotonic lon for contour plots
def createmaps():
fig, axs = plt.subplots(nrows=4,ncols=3,subplot_kw={'projection':ccrs.Robinson(central_longitude=210)},
figsize=(9.5,7.75))
fig.subplots_adjust(top=0.95,left=0.05,right=0.95,hspace=0.1,wspace=0.025)
axs = axs.ravel()
return fig, axs
def mapfig_mon():
fig, axs = createmaps()
for n in range(data.shape[0]):
axs[n].set_global()
axs[n].add_feature(cfeature.LAND, facecolor='#b0b0b0')
axs[n].set_title('%d-%02d'%(dates[n]['time.year'],dates[n]['time.month']),fontsize=9)
cax = fig.add_axes([0.1,0.07,0.8,0.025])
return fig, axs, cax
varinfo_3He = {
'HELIUM3' : {
'label' : 'surface $^3\!$He (pmol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
},
'STF_HELIUM3' :{
'label' : '$^3\!$He total gas flux (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_HELIUM3_DGE' :{
'label' : '$^3\!$He diffusive gas exchange (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_HELIUM3_CTB' :{
'label' : '$^3\!$He flux due to completely dissolved bubbles (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_HELIUM3_PTB' :{
'label' : '$^3\!$He flux due to partially dissolved bubbles (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'HELIUM3_KS' : {
'label' : '$^3\!$He transfer velocity for diffusive gas exchange (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
'HELIUM3_KB' : {
'label' : '$^3\!$He transfer velocity for large bubbles (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
}
varinfo = varinfo_3He
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['HELIUM3_KB','STF_HELIUM3_CTB']:
norm = colors.LogNorm()
else:
norm = None
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree())
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=data.min(),vmax=data.max(),cmap=varinfo[vname]['cmap'])
if 'STF' in vname:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
varinfo_i3He = {
'INERT_HELIUM3' : {
'label' : 'surface inert $^3\!$He (pmol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
},
'STF_INERT_HELIUM3' :{
'label' : 'inert $^3\!$He total gas flux (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_INERT_HELIUM3_DGE' :{
'label' : 'inert $^3\!$He diffusive gas exchange (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_INERT_HELIUM3_CTB' :{
'label' : 'inert $^3\!$He flux due to completely dissolved bubbles (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_INERT_HELIUM3_PTB' :{
'label' : 'inert $^3\!$He flux due to partially dissolved bubbles (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'INERT_HELIUM3_KS' : {
'label' : 'inert $^3\!$He transfer velocity for diffusive gas exchange (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
'INERT_HELIUM3_KB' : {
'label' : 'inert $^3\!$He transfer velocity for large bubbles (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
}
varinfo = varinfo_i3He
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['INERT_HELIUM3_KB','STF_INERT_HELIUM3_CTB']:
norm = colors.LogNorm()
else:
norm = None
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=data.min(),vmax=data.max(),cmap=varinfo[vname]['cmap'])
if 'STF' in vname:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
ds['EXCESS_HELIUM3'] = (ds.HELIUM3 - ds.INERT_HELIUM3)
ds['EXCESS_HELIUM3'] = ds.EXCESS_HELIUM3.where(ds.EXCESS_HELIUM3>0)
ds['STF_EXCESS_HELIUM3'] = ds.STF_HELIUM3 - ds.STF_INERT_HELIUM3
varinfo = {
'EXCESS_HELIUM3' : {
'label' : 'surface excess $^3\!$He (pmol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
},
'STF_EXCESS_HELIUM3' :{
'label' : 'excess $^3\!$He total gas flux (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
}
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['EXCESS_HELIUM3']:
norm = colors.LogNorm()
else:
norm = None
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=data.min(),vmax=data.max(),cmap=varinfo[vname]['cmap'])
if 'STF' in vname:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
varinfo_4He = {
'HELIUM4' : {
'label' : 'surface $^4\!$He ($\mu$mol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
},
'STF_HELIUM4' :{
'label' : '$^4\!$He total gas flux ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_HELIUM4_DGE' :{
'label' : '$^4\!$He diffusive gas exchange ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_HELIUM4_CTB' :{
'label' : '$^4\!$He flux due to completely dissolved bubbles ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_HELIUM4_PTB' :{
'label' : '$^4\!$He flux due to partially dissolved bubbles ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'HELIUM4_KS' : {
'label' : '$^4\!$He transfer velocity for diffusive gas exchange (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
'HELIUM4_KB' : {
'label' : '$^4\!$He transfer velocity for large bubbles (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
}
varinfo = varinfo_4He
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['HELIUM4_KB','STF_HELIUM4_CTB']:
norm = colors.LogNorm()
else:
norm = None
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=data.min(),vmax=data.max(),cmap=varinfo[vname]['cmap'])
if 'STF' in vname:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
varinfo_Ne = {
'NEON' : {
'label' : 'surface Ne ($\mu$mol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
},
'STF_NEON' :{
'label' : 'Ne total gas flux ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_NEON_DGE' :{
'label' : 'Ne diffusive gas exchange ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_NEON_CTB' :{
'label' : 'Ne flux due to completely dissolved bubbles ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_NEON_PTB' :{
'label' : 'Ne flux due to partially dissolved bubbles ($\mu$mol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'NEON_KS' : {
'label' : 'Ne transfer velocity for diffusive gas exchange (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
'NEON_KB' : {
'label' : 'Ne transfer velocity for large bubbles (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
}
varinfo = varinfo_Ne
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['NEON_KB','STF_NEON_CTB']:
norm = colors.LogNorm()
else:
norm = None
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=data.min(),vmax=data.max(),cmap=varinfo[vname]['cmap'])
if 'STF' in vname:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
varinfo_Ar = {
'ARGON' : {
'label' : 'surface Ar (mmol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
},
'STF_ARGON' :{
'label' : 'Ar total gas flux (mmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_ARGON_DGE' :{
'label' : 'Ar diffusive gas exchange (mmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_ARGON_CTB' :{
'label' : 'Ar flux due to completely dissolved bubbles (mmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_ARGON_PTB' :{
'label' : 'Ar flux due to partially dissolved bubbles (mmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'ARGON_KS' : {
'label' : 'Ar transfer velocity for diffusive gas exchange (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
'ARGON_KB' : {
'label' : 'Ar transfer velocity for large bubbles (m d$^{-1}$)',
'cmap' : plt.cm.viridis,
'cfac' : spd,
},
}
varinfo = varinfo_Ar
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['ARGON_KB','STF_ARGON_CTB']:
norm = colors.LogNorm()
else:
norm = None
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=data.min(),vmax=data.max(),cmap=varinfo[vname]['cmap'])
if 'STF' in vname:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
varinfo_3H = {
'TRITIUM' : {
'label' : 'surface $^3\!$H (pmol m$^{-3}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
# 'vlim' : (0.0015, 0.1)
},
'STF_TRITIUM' :{
'label' : '$^3\!$H total surface flux (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
# 'vlim' : (-1.6e-9,0.002)
'vlim' : (-0.005,0.02)
},
'STF_TRITIUM_EVAP' :{
'label' : '$^3\!$H flux due to evaporation (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
# 'vlim' : (-1.e-4,0.0006)
'vlim' : (-0.01,0.01)
},
'STF_TRITIUM_EVAP_UP' :{
'label' : 'upward $^3\!$H vapor flux (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
# 'vlim' : (-0.0004,8.8e-6)
'vlim' : (-0.007,0.008)
},
'STF_TRITIUM_EVAP_DOWN' :{
'label' : 'downward $^3\!$H vapor flux (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
# 'vlim' : (-0.00014,0.0008)
'vlim' : (-0.015,0.015)
},
'STF_TRITIUM_PREC' :{
'label' : '$^3\!$H flux due to precipitation (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'STF_TRITIUM_ROFF' :{
'label' : '$^3\!$H surface flux due to river runoff (pmol m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
'vlim' : (1.e-5,0.059)
},
}
ds['TRITIUM'].values = ds.TRITIUM.where(ds.TRITIUM>=0)
varinfo = varinfo_3H
for vname in sorted(varinfo):
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname].get('cfac',1), ds.time[-12:]
if vname in ['TRITIUM','TRITIUM_KB','STF_TRITIUM_ROFF']:
norm = colors.LogNorm()
else:
norm = None
vmin, vmax = varinfo[vname].get('vlim',(data.min(),data.max()))
cmap = varinfo[vname].get('cmap',plt.cm.plasma)
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=vmin,vmax=vmax,cmap=cmap)
if 'STF' in vname or vname in ['EVAP_F','PREC_F']:
# cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
# print(pm.get_clim())
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])
varinfo = {
'EVAP_F' : {
'label' : 'evaporation (kg m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'PREC_F' : {
'label' : 'precipitation (kg m$^{-2}$ d$^{-1}$)',
'cmap' : plt.cm.RdBu_r,
'cfac' : spd,
},
'HQ' :{
'label' : r'$h$ ($\frac{q_{atm}}{q_{sat}}$)',
'cmap' : plt.cm.plasma,
'cfac' : 1,
'vlim' : (0.00275,0.9),
},
}
# for vname in sorted(varinfo):
for vname in ['PREC_F','EVAP_F','HQ']:
print(vname)
data, dates, = da2ma(ds[vname][-12:,...]) * varinfo[vname]['cfac'], ds.time[-12:]
if vname in ['TRITIUM_KB']:
norm = colors.LogNorm()
else:
norm = None
vmin, vmax = varinfo[vname].get('vlim',(data.min(),data.max()))
fig, axs, cax = mapfig_mon()
for n in range(data.shape[0]):
pm = axs[n].pcolormesh(ds.TLONG, ds.TLAT, data[n,...],transform=ccrs.PlateCarree(),
norm=norm,vmin=vmin,vmax=vmax,cmap=varinfo[vname]['cmap'])
if 'STF' in vname or vname in ['EVAP_F','PREC_F']:
cl = axs[n].contour(loncp,ds.TLAT,data[n,...],[0],colors='k',transform=ccrs.PlateCarree(),linewidths=0.5)
center_cmap(pm)
cb = fig.colorbar(pm,cax=cax,orientation='horizontal')
cb.set_label(varinfo[vname]['label'])