Evaporation Fluxes

Created by Ivan Lima on Tue Jul 21 2020 11:46:35 -0400

In [1]:
%matplotlib inline
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import os, datetime, warnings, cmocean
from matplotlib import colors
from cesm_utils import fixtime, spd
from mpl_utils import center_cmap
warnings.filterwarnings('ignore')
plt.rcParams['figure.dpi'] = 110
print('Last updated on {}'.format(datetime.datetime.now().ctime()))
Last updated on Tue Jul 21 13:04:25 2020

Global maps

In [2]:
from cartopy import crs as ccrs
from cartopy import feature as cfeature

def surf_maps(ds, vname, cmap=plt.cm.viridis, log=False):
    tlat, tlon = ds.TLAT, ds.TLONG
    tlat, tlon = np.c_[tlat,tlat[:,0]], np.c_[tlon,tlon[:,0]]
    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.175,wspace=0.025)
    axs = axs.ravel()
    for ax in axs:
        ax.set_global()
        ax.add_feature(cfeature.LAND, facecolor='#b0b0b0')
        ax.coastlines(linewidth=0.5)
    
    cax = fig.add_axes([0.1,0.07,0.8,0.025])
    if 'z_t' in ds[vname].dims:
        data = ds[vname].isel(z_t=0).where(ds.REGION_MASK>0) # mask marginal seas
    else:
        data = ds[vname].where(ds.REGION_MASK>0) # mask marginal seas

    if log:
        norm = norm=colors.LogNorm()
    else:
        norm = None

    # vmin, vmax = data.min().item(), data.max().item()    
    vmin, vmax = -0.000222, 1.419646e-05
    for t in range(ds.dims['time']):
        pm = axs[t].pcolormesh(tlon, tlat, data[t,...], transform=ccrs.PlateCarree(),
                               vmin=vmin, vmax=vmax, norm=norm, cmap=cmap)
        if vname in ['UVEL','VVEL','EVAP_F']:
            center_cmap(pm)
            
        _ = axs[t].set_title('%d-%02d'%(ds.time[t]['time.year'],ds.time[t]['time.month']),fontsize=10)

    label = '{} ({})'.format(vname, ds[vname].units)
    cb = fig.colorbar(pm, cax=cax, orientation='horizontal')
    cb.set_label(label)
    return fig, axs

G-term run

In [3]:
datadir = '/media/ivan/WD/Data/Postproc/1DPOP'

ds_gterms = xr.open_dataset(os.path.join(datadir, 'cesm.1dpop.07.0005.monthly.nc'), decode_times=False)
ds_gterms = fixtime(ds_gterms, 2051)
fig, ax = surf_maps(ds_gterms, 'EVAP_F', cmocean.cm.balance)
_ = fig.suptitle('G-term run', x=0.5, y=1.02)

U & V restoring run

In [4]:
ds_restore = xr.open_dataset(os.path.join(datadir, 'cesm.1dpop.03.0005.monthly.nc'), decode_times=False)
ds_restore = fixtime(ds_restore, 2051)
fig, ax = surf_maps(ds_restore, 'EVAP_F', cmocean.cm.balance)
_ = fig.suptitle('U & V restoring run', x=0.5, y=1.02)

3-D run

In [5]:
ds_3D = xr.open_dataset(os.path.join(datadir, 'cesm.3d.gterms.test.01.0001.monthly.nc'), decode_times=False)
ds_3D = fixtime(ds_3D, 2051)
fig, ax = surf_maps(ds_3D, 'EVAP_F', cmocean.cm.balance)
_ = fig.suptitle('3-D run', x=0.5, y=1.02)