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:
server as an example of how to post-process CESM/MOM6 output;
create time averages of surface fields;
create time-series of globally-averaged surface fields;
%load_ext autoreload
%autoreload 2
from datetime import datetime
import os
import warnings
from dask.distributed import Client, LocalCluster
import intake
from mom6_tools.MOM6grid import MOM6grid
from mom6_tools.surface import get_MLD, get_BLD
import xarray as xr
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 = {}
lc_kwargs = {}
# Parameters
CESM_output_dir = "/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing"
lc_kwargs = {"threads_per_worker": 1}
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')
# Spin up cluster
cluster = LocalCluster(**lc_kwargs)
client = Client(cluster)
client
Client
Client-dd38f88c-dd7d-11ee-9998-ac1f6bab1e6a
Connection method: Cluster object | Cluster type: distributed.LocalCluster |
Dashboard: http://127.0.0.1:8787/status |
Cluster Info
LocalCluster
f144f829
Dashboard: http://127.0.0.1:8787/status | Workers: 12 |
Total threads: 12 | Total memory: 120.00 GiB |
Status: running | Using processes: True |
Scheduler Info
Scheduler
Scheduler-aa98ccda-7658-4506-aef8-5c4e823e0cd1
Comm: tcp://127.0.0.1:34565 | Workers: 12 |
Dashboard: http://127.0.0.1:8787/status | Total threads: 12 |
Started: Just now | Total memory: 120.00 GiB |
Workers
Worker: 0
Comm: tcp://127.0.0.1:39473 | Total threads: 1 |
Dashboard: http://127.0.0.1:37893/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:35511 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-pg2n3ap_ |
Worker: 1
Comm: tcp://127.0.0.1:45225 | Total threads: 1 |
Dashboard: http://127.0.0.1:40291/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:34631 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-ir5o4c3v |
Worker: 2
Comm: tcp://127.0.0.1:33559 | Total threads: 1 |
Dashboard: http://127.0.0.1:34287/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:35497 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-4v44q70c |
Worker: 3
Comm: tcp://127.0.0.1:41153 | Total threads: 1 |
Dashboard: http://127.0.0.1:43357/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:41883 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-0kxoqznn |
Worker: 4
Comm: tcp://127.0.0.1:38481 | Total threads: 1 |
Dashboard: http://127.0.0.1:45077/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:42191 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-ljtsecix |
Worker: 5
Comm: tcp://127.0.0.1:45025 | Total threads: 1 |
Dashboard: http://127.0.0.1:33759/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:46349 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-9x23p9im |
Worker: 6
Comm: tcp://127.0.0.1:36551 | Total threads: 1 |
Dashboard: http://127.0.0.1:37573/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:45493 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-7bnbra2b |
Worker: 7
Comm: tcp://127.0.0.1:44803 | Total threads: 1 |
Dashboard: http://127.0.0.1:38647/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:42481 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-f9wd4nnv |
Worker: 8
Comm: tcp://127.0.0.1:37261 | Total threads: 1 |
Dashboard: http://127.0.0.1:41919/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:36957 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-77drkeve |
Worker: 9
Comm: tcp://127.0.0.1:41301 | Total threads: 1 |
Dashboard: http://127.0.0.1:36485/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:34361 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-n1l_7dmd |
Worker: 10
Comm: tcp://127.0.0.1:46115 | Total threads: 1 |
Dashboard: http://127.0.0.1:40949/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:33227 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-b21uu3ze |
Worker: 11
Comm: tcp://127.0.0.1:40331 | Total threads: 1 |
Dashboard: http://127.0.0.1:39331/status | Memory: 10.00 GiB |
Nanny: tcp://127.0.0.1:39887 | |
Local directory: /glade/derecho/scratch/dbailey/tmp/dask-scratch-space/worker-s2q7ktiv |
# 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:04:16.644257
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:00:26.134248
Plotting...
![_images/776a7849937485278021019d44a30b9a56171c49a4b6884ac650df213a03c24d.png](_images/776a7849937485278021019d44a30b9a56171c49a4b6884ac650df213a03c24d.png)
![_images/6703e8ceca40116b660daa5d655e278c42e999fa6f6c9b5a0094ba442c5847cb.png](_images/6703e8ceca40116b660daa5d655e278c42e999fa6f6c9b5a0094ba442c5847cb.png)
![_images/1711de277f06cd8db42c24b1a5fe0a5e1080da4f25c51058ea4b379efe70fb66.png](_images/1711de277f06cd8db42c24b1a5fe0a5e1080da4f25c51058ea4b379efe70fb66.png)
![_images/2cd2478b44194e53a8322daaf0db943af3bff2afdf0ec4db200496b48dc129ec.png](_images/2cd2478b44194e53a8322daaf0db943af3bff2afdf0ec4db200496b48dc129ec.png)
![_images/3551ae5990446c9be5f0a0f250c7bd847a6564178194724d2806f8cded09ee2b.png](_images/3551ae5990446c9be5f0a0f250c7bd847a6564178194724d2806f8cded09ee2b.png)
![_images/6c3edcde20f2ba5da980038e137fc61db6c8ce969b7069c04711fc754b0ecbf4.png](_images/6c3edcde20f2ba5da980038e137fc61db6c8ce969b7069c04711fc754b0ecbf4.png)
![_images/b779916c73d6e4895a58d57a6f6e28d245bdd72313198fc8d57c462d8936f9fd.png](_images/b779916c73d6e4895a58d57a6f6e28d245bdd72313198fc8d57c462d8936f9fd.png)
![_images/5a876693a5d209d22a64c9baa210d57bece637cbbead91391ccff35ec494133c.png](_images/5a876693a5d209d22a64c9baa210d57bece637cbbead91391ccff35ec494133c.png)
![_images/2c8a7cb10003fd87034eb2ab5132dfdbd43098ffee2544c895eb277716297253.png](_images/2c8a7cb10003fd87034eb2ab5132dfdbd43098ffee2544c895eb277716297253.png)
![_images/32bcba22292cf42a0313ce8a18d586cfaf3bc73542715e79c575067a65e379f0.png](_images/32bcba22292cf42a0313ce8a18d586cfaf3bc73542715e79c575067a65e379f0.png)
Boundary layer depth#
get_BLD(ds, 'oml', grd, args)
Computing monthly BLD climatology...
Time elasped: 0:00:22.422654
Plotting...
![_images/ebaa222d53590c1c12072cc3b5ab72eafafb5e1dfe43b0a9cc42467843a8d2d6.png](_images/ebaa222d53590c1c12072cc3b5ab72eafafb5e1dfe43b0a9cc42467843a8d2d6.png)
![_images/b330baffcce1d2a4cd7cac492a305d76a910134e0e2f15fc7e46efe09e6de6d8.png](_images/b330baffcce1d2a4cd7cac492a305d76a910134e0e2f15fc7e46efe09e6de6d8.png)
![_images/03aa2cb4739ba61da6137d1f5bf12133eec051ed35ec77cee4a07b514f86756c.png](_images/03aa2cb4739ba61da6137d1f5bf12133eec051ed35ec77cee4a07b514f86756c.png)
# SSH (not working)
#get_SSH(ds, 'SSH', grd, args)