Use-case demonstration of oocgcm.modelgrids

  • author : Julien Le Sommer
  • date : May 2016
  • purpose : This notebook is used for testing/debugging modelgrids during the development process. It will eventually become a demonstration notebook when occgcm is ready for dissemination.

In [0]:
import sys
sys.path.append("/Users/lesommer/git/oocgcm/")

In [0]:
#- Modules
import modelgrids as mg
import xarray as xr
from matplotlib import pyplot as plt

In [0]:
%matplotlib inline

In [0]:
#- Parameter
coordfile  = '/Users/lesommer/data/NATL60/NATL60-I/NATL60_coordinates_v4.nc'
maskfile = '/Users/lesommer/data/NATL60/NATL60-I/NATL60_v4.1_cdf_byte_mask.nc'
filenatl60 = '/Users/lesommer/data/NATL60/NATL60-MJM155-S/1d/2008/NATL60-MJM155_y2008m01.1d_BUOYANCYFLX.nc'

#chunks = (3454,5422)
chunks = (1727,2711)
#chunks = (500,500)
xr_chunks = {'x': chunks[-1], 'y': chunks[-2]}

In [0]:
#- creating the grid object
grd = mg.nemo_2d_grid(nemo_coordinate_file=coordfile,nemo_byte_mask_file=maskfile,chunks=xr_chunks)

In [0]:
#- defining a 2D xarray
sig0 = xr.open_dataset(filenatl60,chunks=xr_chunks,lock=False).variables['vosigma0'][0]

In [0]:
#- compute the horizontal gradient
gx,gy = grd.horizontal_gradient(sig0)

In [0]:
#- plot the horizontal gradient
plt.figure(figsize=(15,10))
gx.plot.pcolormesh(vmin=-1e-6,vmax=1e-6)

In [0]:
gx.name

In [0]: