Analysis of Surface Fields

Analysis of Surface Fields#

mom6_tools.MOM6grid returns an object with MOM6 grid data.

mom6_tools.latlon_analysis has a collection of tools used to perform spatial analysis (e.g., time averages and spatial mean).

The goal of this notebook is the following:

  1. server as an example of how to post-process CESM/MOM6 output;

  2. create time averages of surface fields;

  3. create time-series of globally-averaged surface fields;

%load_ext autoreload
%autoreload 2
import xarray as xr
import warnings, os
import intake
from datetime import datetime
from mom6_tools.MOM6grid import MOM6grid
from mom6_tools.surface import get_MLD, get_BLD

warnings.filterwarnings("ignore")
Basemap module not found. Some regional plots may not function properly
CESM_output_dir = "/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing"
Case = "b.e23_alpha16b.BLT1850.ne30_t232.054"
savefigs = False
mom6_tools_config = {}
# Parameters
CESM_output_dir = "/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing"
Case = "b.e23_alpha16b.BLT1850.ne30_t232.054"
savefigs = False
mom6_tools_config = {
    "start_date": "0091-01-01",
    "end_date": "0101-01-01",
    "Fnames": {"native": "mom6.h.native.????-??.nc", "static": "mom6.h.static.nc"},
    "oce_cat": "/glade/u/home/gmarques/libs/oce-catalogs/reference-datasets.yml",
}
subset_kwargs = {}
product = "/glade/u/home/dbailey/CUPiD/examples/coupled_model/computed_notebooks/quick-run/ocean_surface.ipynb"
OUTDIR = f'{CESM_output_dir}/{Case}/ocn/hist/'
print('Output directory is:', OUTDIR)
Output directory is: /glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing/b.e23_alpha16b.BLT1850.ne30_t232.054/ocn/hist/
# The following parameters must be set accordingly
######################################################

# create an empty class object
class args:
  pass

args.start_date = mom6_tools_config['start_date']
args.end_date = mom6_tools_config['end_date']
args.casename = Case
args.native = f"{Case}.{mom6_tools_config['Fnames']['native']}"
args.static = f"{Case}.{mom6_tools_config['Fnames']['static']}"
args.mld_obs = "mld-deboyer-tx2_3v2"
args.savefigs = savefigs
if not os.path.isdir('PNG/BLD'):
  print('Creating a directory to place figures (PNG/BLD)... \n')
  os.system('mkdir -p PNG/BLD')
if not os.path.isdir('PNG/MLD'):
  print('Creating a directory to place figures (PNG/MLD)... \n')
  os.system('mkdir -p PNG/MLD')
if not os.path.isdir('ncfiles'):
  print('Creating a directory to place netcdf files (ncfiles)... \n')
  os.system('mkdir ncfiles')    
Creating a directory to place figures (PNG/BLD)... 

Creating a directory to place figures (PNG/MLD)... 

Creating a directory to place netcdf files (ncfiles)... 
# load mom6 grid
grd = MOM6grid(OUTDIR+args.static)
grd_xr = MOM6grid(OUTDIR+args.static, xrformat=True)
MOM6 grid successfully loaded... 

MOM6 grid successfully loaded... 
print('Reading native dataset...')
startTime = datetime.now()

def preprocess(ds):
  ''' Compute montly averages and return the dataset with variables'''
  variables = ['oml','mlotst','tos','SSH', 'SSU', 'SSV', 'speed', 'time_bnds']
  for v in variables:
    if v not in ds.variables:
      ds[v] = xr.zeros_like(ds.SSH)
  return ds[variables]

ds1 = xr.open_mfdataset(OUTDIR+args.native, parallel=False)
ds = preprocess(ds1)

print('Time elasped: ', datetime.now() - startTime)
Reading native dataset...
Time elasped:  0:03:40.243508
print('Selecting data between {} and {}...'.format(args.start_date, args.end_date))
ds_sel = ds.sel(time=slice(args.start_date, args.end_date))
Selecting data between 0091-01-01 and 0101-01-01...
catalog = intake.open_catalog(mom6_tools_config['oce_cat'])
mld_obs = catalog[args.mld_obs].to_dask()
# uncomment to list all datasets available
#list(catalog)

Mixed layer depth#

%matplotlib inline
# MLD
get_MLD(ds,'mlotst', mld_obs, grd, args)
Computing monthly MLD climatology...
Time elasped:  0:02:20.530319

 Plotting...
_images/776a7849937485278021019d44a30b9a56171c49a4b6884ac650df213a03c24d.png _images/6703e8ceca40116b660daa5d655e278c42e999fa6f6c9b5a0094ba442c5847cb.png _images/1711de277f06cd8db42c24b1a5fe0a5e1080da4f25c51058ea4b379efe70fb66.png _images/2cd2478b44194e53a8322daaf0db943af3bff2afdf0ec4db200496b48dc129ec.png _images/3551ae5990446c9be5f0a0f250c7bd847a6564178194724d2806f8cded09ee2b.png _images/6c3edcde20f2ba5da980038e137fc61db6c8ce969b7069c04711fc754b0ecbf4.png _images/b779916c73d6e4895a58d57a6f6e28d245bdd72313198fc8d57c462d8936f9fd.png _images/5a876693a5d209d22a64c9baa210d57bece637cbbead91391ccff35ec494133c.png _images/2c8a7cb10003fd87034eb2ab5132dfdbd43098ffee2544c895eb277716297253.png _images/32bcba22292cf42a0313ce8a18d586cfaf3bc73542715e79c575067a65e379f0.png

Boundary layer depth#

get_BLD(ds, 'oml', grd, args)
Computing monthly BLD climatology...
Time elasped:  0:02:23.782546

 Plotting...
_images/ebaa222d53590c1c12072cc3b5ab72eafafb5e1dfe43b0a9cc42467843a8d2d6.png _images/b330baffcce1d2a4cd7cac492a305d76a910134e0e2f15fc7e46efe09e6de6d8.png _images/03aa2cb4739ba61da6137d1f5bf12133eec051ed35ec77cee4a07b514f86756c.png
# SSH (not working)
#get_SSH(ds, 'SSH', grd, args)