## Grid-aware spatial operations using xgcm

### ROMS grid

* ROMS variables are staggered according to the Arakawa C-grid

source:myroms.org, Rajpoot et al. (2012)

We open a sample ROMS model output, using xarray, as usual.

```python
import xarray as xr
import xgcm
import numpy as np
import matplotlib.pyplot as plt

file = '/scratch/training/python_geos/data/ROMS/roms_test.nc'
ds = xr.open_dataset(file)
ds
```

<svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewBox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewBox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>

<xarray.Dataset>
Dimensions:      (ocean_time: 2, s_w: 51, eta_rho: 489, xi_rho: 655, tracer: 2, s_rho: 50, boundary: 4, eta_psi: 488, xi_psi: 654, eta_u: 489, xi_u: 654, eta_v: 488, xi_v: 655)
Coordinates:
    lat_psi      (eta_psi, xi_psi) float64 ...
    lat_rho      (eta_rho, xi_rho) float64 ...
    lat_u        (eta_u, xi_u) float64 ...
    lat_v        (eta_v, xi_v) float64 ...
    lon_psi      (eta_psi, xi_psi) float64 ...
    lon_rho      (eta_rho, xi_rho) float64 ...
    lon_u        (eta_u, xi_u) float64 ...
    lon_v        (eta_v, xi_v) float64 ...
  * ocean_time   (ocean_time) datetime64[ns] 2010-01-05T03:00:00 2010-01-05T0...
  * s_rho        (s_rho) float64 -0.99 -0.97 -0.95 -0.93 ... -0.05 -0.03 -0.01
  * s_w          (s_w) float64 -1.0 -0.98 -0.96 -0.94 ... -0.06 -0.04 -0.02 0.0
Dimensions without coordinates: eta_rho, xi_rho, tracer, boundary, eta_psi, xi_psi, eta_u, xi_u, eta_v, xi_v
Data variables: (12/74)
    AKt          (ocean_time, s_w, eta_rho, xi_rho) float32 ...
    AKv          (ocean_time, s_w, eta_rho, xi_rho) float32 ...
    Akt_bak      (tracer) float64 1e-06 1e-06
    Akv_bak      float64 1e-05
    Cs_r         (s_rho) float64 -0.9672 -0.8937 ... -9.523e-06 -1.051e-06
    Cs_w         (s_w) float64 -1.0 -0.9316 -0.8539 ... -4.215e-06 0.0
    ...           ...
    ubar         (ocean_time, eta_u, xi_u) float32 ...
    v            (ocean_time, s_rho, eta_v, xi_v) float32 ...
    vbar         (ocean_time, eta_v, xi_v) float32 ...
    w            (ocean_time, s_w, eta_rho, xi_rho) float32 ...
    xl           float64 1.983e+06
    zeta         (ocean_time, eta_rho, xi_rho) float32 ...
Attributes: (12/26)
    file:              GOM_hurr_wrf_19950930-06.ocn_0002.hi.1995-10-04_09:00:...
    format:            netCDF-3 classic file
    Conventions:       CF-1.4
    type:              ROMS/TOMS history file
    title:             BP_2010 Coupled Hindcast Run
    rst_file:          gom03_rst.nc
    ...                ...
    compiler_flags:    -fp-model precise -ip -O2 -debug minimal -free -free
    tiling:            020x018
    history:           Thu Nov  4 09:41:12 2021: ncks -d ocean_time,0,1 roms_...
    ana_file:          ROMS/Functionals/ana_btflux.h, ROMS/Functionals/ana_hm...
    CPP_options:       TXGLO, ATM_PRESS, ANA_BSFLUX, ANA_BTFLUX, ASSUMED_SHAP...
    NCO:               netCDF Operators version 4.9.7 (Homepage = http://nco....

xarray.Dataset

<input id='section-388b2f95-30b9-4930-b9b2-a3697fedda8b' class='xr-section-summary-in' type='checkbox' disabled >Dimensions:

ocean_time: 2

s_w: 51

eta_rho: 489

xi_rho: 655

tracer: 2

s_rho: 50

boundary: 4

eta_psi: 488

xi_psi: 654

eta_u: 489

xi_u: 654

eta_v: 488

xi_v: 655

<input id='section-a130e3ea-e7e5-45f8-bc2a-657d0f4118bb' class='xr-section-summary-in' type='checkbox'  checked>Coordinates: (11)

lat_psi

(eta_psi, xi_psi)

float64

...
<input id='attrs-fa5f1319-257c-4d1b-9b29-67022720ec91' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-12732cd3-2fd8-4304-b5df-2c5ed96c4ddc' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

latitude of PSI-points

units :

degree_north

standard_name :

latitude

field :

lat_psi, scalar

[319152 values with dtype=float64]

lat_rho

(eta_rho, xi_rho)

float64

...
<input id='attrs-87937d67-34e2-402b-a8c6-a40772962528' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-807513e4-cc7a-4e35-b827-4c46bc16d721' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

latitude of RHO-points

units :

degree_north

standard_name :

latitude

field :

lat_rho, scalar

[320295 values with dtype=float64]

lat_u

(eta_u, xi_u)

float64

...
<input id='attrs-83bcf353-9c38-481e-be6f-56855877df8c' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-825aa146-9d80-43db-81ca-9404c1f4bb50' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

latitude of U-points

units :

degree_north

standard_name :

latitude

field :

lat_u, scalar

[319806 values with dtype=float64]

lat_v

(eta_v, xi_v)

float64

...
<input id='attrs-0b9a71f5-e66e-43aa-82f1-c139b09d402f' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-e5cc02f6-575f-4adf-96a7-b6c664314af3' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

latitude of V-points

units :

degree_north

standard_name :

latitude

field :

lat_v, scalar

[319640 values with dtype=float64]

lon_psi

(eta_psi, xi_psi)

float64

...
<input id='attrs-c7cfbb90-97b1-4b79-947b-09edc97acc1b' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-4a3aabf0-0a12-425c-8feb-098e6d71e317' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

longitude of PSI-points

units :

degree_east

standard_name :

longitude

field :

lon_psi, scalar

[319152 values with dtype=float64]

lon_rho

(eta_rho, xi_rho)

float64

...
<input id='attrs-3e8b01e7-4ee4-4d15-877b-80c072c63548' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-c0e597fd-eb09-47e5-ac77-756e047eccc8' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

longitude of RHO-points

units :

degree_east

standard_name :

longitude

field :

lon_rho, scalar

[320295 values with dtype=float64]

lon_u

(eta_u, xi_u)

float64

...
<input id='attrs-fa40f7b7-d7f6-4a00-ab78-5268283cb75b' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-c4f52386-38cd-45f8-b276-f472ad7eab52' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

longitude of U-points

units :

degree_east

standard_name :

longitude

field :

lon_u, scalar

[319806 values with dtype=float64]

lon_v

(eta_v, xi_v)

float64

...
<input id='attrs-2270c2f3-7561-48b6-a26c-fbc46cbf1fe3' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-b62ac2eb-3535-451b-95e0-2cd26ebb9351' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

longitude of V-points

units :

degree_east

standard_name :

longitude

field :

lon_v, scalar

[319640 values with dtype=float64]

ocean_time

(ocean_time)

datetime64[ns]

2010-01-05T03:00:00 2010-01-05T0...
<input id='attrs-98d9cc97-5c62-42a8-b43e-87e87c8a851e' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-bda4797e-757f-4eb7-ba32-4335a6c2ad21' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

time since initialization

field :

time, scalar, series

array(['2010-01-05T03:00:00.000000000', '2010-01-05T06:00:00.000000000'],
      dtype='datetime64[ns]')

s_rho

(s_rho)

float64

-0.99 -0.97 -0.95 ... -0.03 -0.01
<input id='attrs-8748750b-22ff-436e-a9d7-604538d167c0' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-da8a78a6-c27d-4f33-bca1-271d14a4f838' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate at RHO-points

valid_min :

-1.0

valid_max :

0.0

positive :

up

standard_name :

ocean_s_coordinate_g2

formula_terms :

s: s_rho C: Cs_r eta: zeta depth: h depth_c: hc

field :

s_rho, scalar

array([-0.99, -0.97, -0.95, -0.93, -0.91, -0.89, -0.87, -0.85, -0.83, -0.81,
       -0.79, -0.77, -0.75, -0.73, -0.71, -0.69, -0.67, -0.65, -0.63, -0.61,
       -0.59, -0.57, -0.55, -0.53, -0.51, -0.49, -0.47, -0.45, -0.43, -0.41,
       -0.39, -0.37, -0.35, -0.33, -0.31, -0.29, -0.27, -0.25, -0.23, -0.21,
       -0.19, -0.17, -0.15, -0.13, -0.11, -0.09, -0.07, -0.05, -0.03, -0.01])

s_w

(s_w)

float64

-1.0 -0.98 -0.96 ... -0.02 0.0
<input id='attrs-9ba86cd9-0dc7-406c-b8de-e475ba7a65e0' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-64db504e-c62a-4f1a-98ea-f1b4bc22b21c' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate at W-points

valid_min :

-1.0

valid_max :

0.0

positive :

up

standard_name :

ocean_s_coordinate_g2

formula_terms :

s: s_w C: Cs_w eta: zeta depth: h depth_c: hc

field :

s_w, scalar

array([-1.  , -0.98, -0.96, -0.94, -0.92, -0.9 , -0.88, -0.86, -0.84, -0.82,
       -0.8 , -0.78, -0.76, -0.74, -0.72, -0.7 , -0.68, -0.66, -0.64, -0.62,
       -0.6 , -0.58, -0.56, -0.54, -0.52, -0.5 , -0.48, -0.46, -0.44, -0.42,
       -0.4 , -0.38, -0.36, -0.34, -0.32, -0.3 , -0.28, -0.26, -0.24, -0.22,
       -0.2 , -0.18, -0.16, -0.14, -0.12, -0.1 , -0.08, -0.06, -0.04, -0.02,
        0.  ])

<input id='section-0921821d-5053-4eae-bc5c-581b72f8029a' class='xr-section-summary-in' type='checkbox'  >Data variables: (74)

AKt

(ocean_time, s_w, eta_rho, xi_rho)

float32

...
<input id='attrs-f5f64926-791d-4832-b07d-498e69fc55ab' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-86507d55-914c-45ca-b9c7-03f063026335' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

temperature vertical diffusion coefficient

units :

meter2 second-1

time :

ocean_time

field :

AKt, scalar, series

[32670090 values with dtype=float32]

AKv

(ocean_time, s_w, eta_rho, xi_rho)

float32

...
<input id='attrs-309d6734-abca-4c44-bd1a-5189359fadb9' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-751f202c-5ccd-4d24-abea-f535135f73ac' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

vertical viscosity coefficient

units :

meter2 second-1

time :

ocean_time

field :

AKv, scalar, series

[32670090 values with dtype=float32]

Akt_bak

(tracer)

float64

...
<input id='attrs-300f671c-de56-4ac4-b47e-10199e8f3f11' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-caa6afbb-3032-4aa0-9b0b-88f534cab5f5' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

background vertical mixing coefficient for tracers

units :

meter2 second-1

array([1.e-06, 1.e-06])

Akv_bak

()

float64

...
<input id='attrs-394c12ff-0057-49f2-8d2c-680d5ce846ba' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-d0e1b901-7a50-483c-87a5-acc803e3e52f' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

background vertical mixing coefficient for momentum

units :

meter2 second-1

array(1.e-05)

Cs_r

(s_rho)

float64

...
<input id='attrs-221fedf4-61c2-4593-9eee-0e0f3e60e54e' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-73cdfb9d-f742-46d9-b243-47db8b84555f' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate stretching curves at RHO-points

valid_min :

-1.0

valid_max :

0.0

field :

Cs_r, scalar

array([-9.671839e-01, -8.936687e-01, -8.126768e-01, -7.281038e-01,
       -6.435888e-01, -5.621205e-01, -4.858744e-01, -4.162221e-01,
       -3.538425e-01, -2.988764e-01, -2.510829e-01, -2.099765e-01,
       -1.749358e-01, -1.452832e-01, -1.203400e-01, -9.946089e-02,
       -8.205365e-02, -6.758860e-02, -5.560076e-02, -4.568777e-02,
       -3.750529e-02, -3.076122e-02, -2.520941e-02, -2.064362e-02,
       -1.689180e-02, -1.381088e-02, -1.128230e-02, -9.207977e-03,
       -7.506952e-03, -6.112496e-03, -4.969678e-03, -4.033328e-03,
       -3.266331e-03, -2.638219e-03, -2.123991e-03, -1.703151e-03,
       -1.358904e-03, -1.077496e-03, -8.476765e-04, -6.602504e-04,
       -5.077145e-04, -3.839599e-04, -2.840284e-04, -2.039151e-04,
       -1.404087e-04, -9.096290e-05, -5.359506e-05, -2.680655e-05,
       -9.522969e-06, -1.051087e-06])

Cs_w

(s_w)

float64

...
<input id='attrs-7cb187cf-f99b-4740-8bd6-3874889a26fb' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-87df8354-4287-4a1c-9511-3774e27df477' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate stretching curves at W-points

valid_min :

-1.0

valid_max :

0.0

field :

Cs_w, scalar

array([-1.000000e+00, -9.315987e-01, -8.538642e-01, -7.705987e-01,
       -6.856341e-01, -6.023182e-01, -5.232411e-01, -4.501671e-01,
       -3.841037e-01, -3.254406e-01, -2.741091e-01, -2.297305e-01,
       -1.917397e-01, -1.594789e-01, -1.322644e-01, -1.094309e-01,
       -9.035791e-02, -7.448392e-02, -6.131160e-02, -5.040772e-02,
       -4.139962e-02, -3.396984e-02, -2.785004e-02, -2.281476e-02,
       -1.867553e-02, -1.527541e-02, -1.248412e-02, -1.019378e-02,
       -8.315276e-03, -6.775087e-03, -5.512663e-03, -4.478185e-03,
       -3.630706e-03, -2.936593e-03, -2.368246e-03, -1.903026e-03,
       -1.522377e-03, -1.211101e-03, -9.567559e-04, -7.491691e-04,
       -5.800326e-04, -4.425739e-04, -3.312869e-04, -2.417122e-04,
       -1.702595e-04, -1.140643e-04, -7.087346e-05, -3.895489e-05,
       -1.702851e-05, -4.214861e-06,  0.000000e+00])

EminusP

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-4c28307a-1211-4b8e-bcf1-6b0672cd1f4a' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-72720bf9-613b-4b98-851f-a0258a968c2a' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

bulk_flux surface net freswater flux, (E-P)

units :

meter second-1

negative_value :

upward flux, freshening (net precipitation)

positive_value :

downward flux, salting (net evaporation)

time :

ocean_time

field :

EminusP, scalar, series

[640590 values with dtype=float32]

FSobc_in

(boundary)

float64

...
<input id='attrs-829a9851-5bbe-43a0-92dc-ea374f35135c' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-f23d0781-a034-4644-af3b-1d020253647c' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

free-surface inflow, nudging inverse time scale

units :

second-1

array([0., 0., 0., 0.])

FSobc_out

(boundary)

float64

...
<input id='attrs-7f89b45e-d87a-46ab-895b-c9692268e78a' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-f6b9c3b4-e2c7-4b00-b8e9-9547ec6429e5' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

free-surface outflow, nudging inverse time scale

units :

second-1

array([0., 0., 0., 0.])

Falpha

()

float64

...
<input id='attrs-bcbdd477-983a-4060-b3d1-ab313657a866' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-8a910131-0934-43b3-8396-38db11091cc6' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

Power-law shape barotropic filter parameter

array(2.)

Fbeta

()

float64

...
<input id='attrs-5234e84a-2e1b-44e9-8eb3-cec1fa27ec1b' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-fcc53498-bd9f-415d-9303-c54eda37e015' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

Power-law shape barotropic filter parameter

array(4.)

Fgamma

()

float64

...
<input id='attrs-8202db99-8a5f-4e96-9032-cf4c44674d65' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-742ef194-21ea-4d15-bdb0-9ad17d0f34d8' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

Power-law shape barotropic filter parameter

array(0.284)

Hsbl

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-e28279ab-95f4-4415-af56-79a7bb58e00d' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-b4fbfc2c-3bd8-4930-abe6-b28e7b9d3085' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

depth of oceanic surface boundary layer

units :

meter

time :

ocean_time

field :

Hsbl, scalar, series

[640590 values with dtype=float32]

M2nudg

()

float64

...
<input id='attrs-ea198445-99d1-4e3d-95e8-69e9b66f2a59' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-b162c3fd-5f7f-4b2b-b232-4c5729a69b7a' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

2D momentum nudging/relaxation inverse time scale

units :

day-1

array(0.1)

M2obc_in

(boundary)

float64

...
<input id='attrs-29a0475a-75c1-4990-9c2b-154bb7d78777' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-24bfe21c-881f-49c7-8df9-607241eca34f' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

2D momentum inflow, nudging inverse time scale

units :

second-1

array([0., 0., 0., 0.])

M2obc_out

(boundary)

float64

...
<input id='attrs-434c4e19-e714-4d27-a1f4-3d223e9e3326' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-5112f96c-1321-489b-b06b-3189df650bbb' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

2D momentum outflow, nudging inverse time scale

units :

second-1

array([0., 0., 0., 0.])

M3nudg

()

float64

...
<input id='attrs-04e7e62b-bb86-46e3-bbae-57721ffed517' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-82d427a7-ab1c-4928-8971-f01ae279669f' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

3D momentum nudging/relaxation inverse time scale

units :

day-1

array(0.1)

M3obc_in

(boundary)

float64

...
<input id='attrs-ee96e8b6-353a-4f08-966c-5e0534d25b30' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-097e8d9b-e720-4959-bc28-2141a92468ba' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

3D momentum inflow, nudging inverse time scale

units :

second-1

array([0.000000e+00, 1.157407e-05, 1.157407e-05, 1.157407e-05])

M3obc_out

(boundary)

float64

...
<input id='attrs-dea52688-a02c-4d1f-a7e2-d88a33b8fb98' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-e07c753f-33e4-4699-b17c-9784038b9142' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

3D momentum outflow, nudging inverse time scale

units :

second-1

array([0.000000e+00, 1.157407e-06, 1.157407e-06, 1.157407e-06])

Tcline

()

float64

...
<input id='attrs-618668d8-79c1-4de9-bfa9-9b1346d4c8bd' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-0d2f25d9-89d6-414e-8776-527af1e9c9b0' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate surface/bottom layer width

units :

meter

array(400.)

Tnudg

(tracer)

float64

...
<input id='attrs-2b62513f-8eef-4121-b325-9d49d97280a1' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-9c4e2e65-75b2-4815-a498-8e5a1633fb79' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

Tracers nudging/relaxation inverse time scale

units :

day-1

array([0.5, 0.5])

Tobc_in

(boundary, tracer)

float64

...
<input id='attrs-a0f7b862-2208-4ed1-98a1-7c210855d07a' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-92bf0043-99e3-4867-b8ef-ac47c9c30468' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

tracers inflow, nudging inverse time scale

units :

second-1

array([[0.000000e+00, 0.000000e+00],
       [5.787037e-05, 5.787037e-05],
       [5.787037e-05, 5.787037e-05],
       [5.787037e-05, 5.787037e-05]])

Tobc_out

(boundary, tracer)

float64

...
<input id='attrs-0fc95028-c61c-467e-af9f-a4f4d4644d81' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-b5fd607c-b4e1-42cb-8d1e-46c93e18da1e' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

tracers outflow, nudging inverse time scale

units :

second-1

array([[0.000000e+00, 0.000000e+00],
       [5.787037e-06, 5.787037e-06],
       [5.787037e-06, 5.787037e-06],
       [5.787037e-06, 5.787037e-06]])

Vstretching

()

int32

...
<input id='attrs-071a29db-b104-495d-8426-b686683a2a2d' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-a9bb53c9-22a8-4cb0-a7bd-177d3383d676' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

vertical terrain-following stretching function

array(4, dtype=int32)

Vtransform

()

int32

...
<input id='attrs-e79e7ce0-45d1-4161-85b6-c3acfab6ee8f' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-db65cb97-4420-424b-9106-2c7d272a71ec' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

vertical terrain-following transformation equation

array(2, dtype=int32)

Znudg

()

float64

...
<input id='attrs-069e1be2-1806-4cff-b907-ee972d1641c9' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-20542375-e49e-433b-a694-8a640d232888' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

free-surface nudging/relaxation inverse time scale

units :

day-1

array(0.5)

Zob

()

float64

...
<input id='attrs-9cee4000-aaba-4b22-8add-d563c62a1d9d' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-abf83d66-4053-4a0c-922a-c42f103a901e' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

bottom roughness

units :

meter

array(0.02)

Zos

()

float64

...
<input id='attrs-e61429aa-ea88-4baa-a78e-ff49da068bd9' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-945266a0-33e9-449b-9406-dceda2ee5232' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

surface roughness

units :

meter

array(0.02)

angle

(eta_rho, xi_rho)

float64

...
<input id='attrs-17f65c95-05fe-4297-bde9-b0984dcbca83' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-4606611b-afd8-4d0d-8883-5eafb9b13cea' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

angle between XI-axis and EAST

units :

radians

field :

angle, scalar

[320295 values with dtype=float64]

dstart

()

datetime64[ns]

...
<input id='attrs-3373a331-aca0-49e7-835b-10d4246b5c95' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-a229140a-3cd2-4ca1-86b7-ef044d40f908' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

time stamp assigned to model initilization

array('2010-01-01T00:00:00.000000000', dtype='datetime64[ns]')

dt

()

float64

...
<input id='attrs-c5805941-ce10-4e7c-972e-f26030b9c98e' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-9be2caa6-5de8-49c1-b91f-2e204d135433' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

size of long time-steps

units :

second

array(30.)

dtfast

()

float64

...
<input id='attrs-e79a675b-818c-4577-8076-0e7a1164cf5e' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-0425e4f8-e107-4a7b-8809-c3a6cc82376a' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

size of short time-steps

units :

second

array(1.)

el

()

float64

...
<input id='attrs-d7bb83d5-dbda-4cfb-a750-d5ea3f9e6987' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-1fd0054b-83bd-44fe-95b0-2acea97efa1c' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

domain length in the ETA-direction

units :

meter

array(1413082.867518)

f

(eta_rho, xi_rho)

float64

...
<input id='attrs-ba208e30-47cd-43ea-a52e-79d6d0066207' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-e86ab3cd-621b-4323-a6f6-9d91e2452a34' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

Coriolis parameter at RHO-points

units :

second-1

field :

coriolis, scalar

[320295 values with dtype=float64]

gamma2

()

float64

...
<input id='attrs-f700b594-7b33-403c-ac8a-a5c4243bd311' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-55ab73d1-69db-4651-bd84-b5ae3cb2d355' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

slipperiness parameter

array(1.)

h

(eta_rho, xi_rho)

float64

...
<input id='attrs-17270b35-5eae-4289-9f91-92d708442c59' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-76119543-ab24-4606-923d-4c99eb1c1aff' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

bathymetry at RHO-points

units :

meter

field :

bath, scalar

[320295 values with dtype=float64]

hc

()

float64

...
<input id='attrs-44a92555-5762-4040-8639-7b8aa7198bb4' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-2066fcd0-13d5-4350-926c-9333c7354ecf' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate parameter, critical depth

units :

meter

array(400.)

latent

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-ea267d31-eb5c-48cd-a896-2671f68e44d8' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-7343abb0-8b2a-4040-bc8e-5132bb1d8f5b' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

net latent heat flux

units :

watt meter-2

negative_value :

upward flux, cooling

positive_value :

downward flux, heating

time :

ocean_time

field :

latent heat flux, scalar, series

[640590 values with dtype=float32]

lwrad

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-d0072bfa-ac17-4b69-80b0-818c5487e536' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-d6c1e07a-6111-4123-aceb-d2c3defc54ab' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

net longwave radiation flux

units :

watt meter-2

negative_value :

upward flux, cooling

positive_value :

downward flux, heating

time :

ocean_time

field :

longwave radiation, scalar, series

[640590 values with dtype=float32]

mask_psi

(eta_psi, xi_psi)

float64

...
<input id='attrs-401570a4-d746-4931-8887-21d31d15004a' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-eb5e2fa5-d313-4d78-82f3-9df62ed08274' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

mask on psi-points

flag_values :

[0. 1.]

flag_meanings :

land water

[319152 values with dtype=float64]

mask_rho

(eta_rho, xi_rho)

float64

...
<input id='attrs-de968da4-c6fc-4549-91a0-8106d3c77255' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-7b684323-796c-4774-b32d-af8e78831746' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

mask on RHO-points

flag_values :

[0. 1.]

flag_meanings :

land water

[320295 values with dtype=float64]

mask_u

(eta_u, xi_u)

float64

...
<input id='attrs-073382a4-25ed-418a-86ec-3d1703c28dc9' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-59eb69f9-b9c4-4ea0-b48f-ca10ea65e61d' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

mask on U-points

flag_values :

[0. 1.]

flag_meanings :

land water

[319806 values with dtype=float64]

mask_v

(eta_v, xi_v)

float64

...
<input id='attrs-f818b039-ea49-4f1b-a9ac-b11003f82201' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-1fcb9c0c-728e-41d7-b1a9-0cf9030f76ef' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

mask on V-points

flag_values :

[0. 1.]

flag_meanings :

land water

[319640 values with dtype=float64]

nHIS

()

int32

...
<input id='attrs-945040ec-b8da-4658-81f5-f37a4f467b92' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-06f9ec12-388c-46fb-ae1a-7fb5fea45567' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

number of time-steps between history records

array(360, dtype=int32)

nRST

()

int32

...
<input id='attrs-203b2733-e163-43a4-83a1-6bf6db4335ba' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-dbfb5ab4-07fa-4e40-b3d5-58f3f94d6af1' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

number of time-steps between restart records

array(8640, dtype=int32)

ndefHIS

()

int32

...
<input id='attrs-21daa8ac-2309-451a-805a-f0ddbfe05962' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-333f7b06-ca2c-4502-8d6b-a7096c00eb4d' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

number of time-steps between the creation of history files

array(2880, dtype=int32)

ndtfast

()

int32

...
<input id='attrs-27121f73-59f2-4ddc-bbbc-289de1406666' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-4d91d9e0-0642-40a2-8eea-58cdc3c2e0c2' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

number of short time-steps

array(30, dtype=int32)

nl_tnu2

(tracer)

float64

...
<input id='attrs-df48da19-85f6-496b-882d-a2ed4ff9cf90' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-83849f81-504f-4858-8ce5-82d8e627bb06' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

nonlinear model Laplacian mixing coefficient for tracers

units :

meter2 second-1

array([15., 15.])

nl_visc2

()

float64

...
<input id='attrs-cffb2e22-f874-41e1-9b03-b97746ee2041' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-de98294d-4008-40c7-9c6a-794251d181c0' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

nonlinear model Laplacian mixing coefficient for momentum

units :

meter2 second-1

array(15.)

ntimes

()

int32

...
<input id='attrs-250eb537-824a-4cea-9ff1-e3dd5e84d158' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-74c69a5b-ec43-4071-86e9-4afb48ca148f' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

number of long time-steps

array(8640, dtype=int32)

pm

(eta_rho, xi_rho)

float64

...
<input id='attrs-36b11915-6228-4db0-b5cd-6ccaf31477a4' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-7e9fbbd2-7bb9-486d-a0a6-4b2efbeb248c' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

curvilinear coordinate metric in XI

units :

meter-1

field :

pm, scalar

[320295 values with dtype=float64]

pn

(eta_rho, xi_rho)

float64

...
<input id='attrs-430a50dc-04d0-4a96-81cd-c30411dbe159' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-9a938cc7-50c9-4a5c-bebd-91f5e2f797fa' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

curvilinear coordinate metric in ETA

units :

meter-1

field :

pn, scalar

[320295 values with dtype=float64]

rdrg

()

float64

...
<input id='attrs-3f92dbd2-b4fd-4a08-9890-f4e5f0e43b20' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-f012add3-0456-4cde-b785-2188e6a6ed3b' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

linear drag coefficient

units :

meter second-1

array(0.0003)

rdrg2

()

float64

...
<input id='attrs-4b4e3bad-d002-4ad3-b13e-0d4623e4e19f' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-c29ee9da-e007-419a-b109-527cea26da32' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

quadratic drag coefficient

array(0.003)

rho

(ocean_time, s_rho, eta_rho, xi_rho)

float32

...
<input id='attrs-38eeae9a-7f53-4d9b-84de-b77ae49bba03' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-e697c13e-42a2-49e6-9a19-ccfdeec8f678' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

density anomaly

units :

kilogram meter-3

time :

ocean_time

field :

density, scalar, series

[32029500 values with dtype=float32]

rho0

()

float64

...
<input id='attrs-a3898af2-75ea-4133-a240-55be25c8dabe' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-f7708c8e-a64f-4ba6-9ec2-649c4ac93874' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

mean density used in Boussinesq approximation

units :

kilogram meter-3

array(1025.)

salt

(ocean_time, s_rho, eta_rho, xi_rho)

float32

...
<input id='attrs-5fe2e0cc-9e55-4d03-94a4-12d62469044b' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-ff26dd31-5410-4e4e-af76-5de6fda84153' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

salinity

time :

ocean_time

field :

salinity, scalar, series

[32029500 values with dtype=float32]

sensible

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-b2c4246a-4100-4d57-b0e2-629c8186d303' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-0f8c77c4-57cc-40cd-bd01-85e9123d5841' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

net sensible heat flux

units :

watt meter-2

negative_value :

upward flux, cooling

positive_value :

downward flux, heating

time :

ocean_time

field :

sensible heat flux, scalar, series

[640590 values with dtype=float32]

shflux

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-d6aaaa87-4efe-485d-a0e0-7f3fc95f2aa2' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-cde99dbd-ef28-4a4d-b2fc-4142b0fcb8b6' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

surface net heat flux

units :

watt meter-2

negative_value :

upward flux, cooling

positive_value :

downward flux, heating

time :

ocean_time

field :

surface heat flux, scalar, series

[640590 values with dtype=float32]

spherical

()

int32

...
<input id='attrs-d4cc9663-cf81-4b9b-a18e-555f9aae6dc1' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-ad54e42e-e258-4a22-bb28-3754141ee7ea' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

grid type logical switch

flag_values :

[0 1]

flag_meanings :

Cartesian spherical

array(1, dtype=int32)

ssflux

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-ec9f93b5-8a9b-4257-8fd1-e015441f0310' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-6036d788-87f8-450e-aadc-e9ddf261edd4' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

surface net salt flux, (E-P)*SALT

units :

meter second-1

negative_value :

upward flux, freshening (net precipitation)

positive_value :

downward flux, salting (net evaporation)

time :

ocean_time

field :

surface net salt flux, scalar, series

[640590 values with dtype=float32]

sustr

(ocean_time, eta_u, xi_u)

float32

...
<input id='attrs-80e7dc75-cbf3-4ee8-bd43-0963dc3d0241' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-29a6536c-01eb-4e95-9731-e6c31df790b2' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

surface u-momentum stress

units :

newton meter-2

time :

ocean_time

field :

surface u-momentum stress, scalar, series

[639612 values with dtype=float32]

svstr

(ocean_time, eta_v, xi_v)

float32

...
<input id='attrs-ad06582c-846f-48a2-b617-7236d7b57688' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-f9ac6ce1-4ac5-474d-b43b-f238569e00cd' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

surface v-momentum stress

units :

newton meter-2

time :

ocean_time

field :

surface v-momentum stress, scalar, series

[639280 values with dtype=float32]

swrad

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-e395893b-557f-45c5-a867-9354d7d891cf' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-719558ec-22c9-4531-bc70-d472b57263ae' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

solar shortwave radiation flux

units :

watt meter-2

negative_value :

upward flux, cooling

positive_value :

downward flux, heating

time :

ocean_time

field :

shortwave radiation, scalar, series

[640590 values with dtype=float32]

temp

(ocean_time, s_rho, eta_rho, xi_rho)

float32

...
<input id='attrs-1597fd26-b01f-491b-86df-adb18f47afc0' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-7a5a73b9-8855-469a-a7db-183f9ac6d5db' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

potential temperature

units :

Celsius

time :

ocean_time

field :

temperature, scalar, series

[32029500 values with dtype=float32]

theta_b

()

float64

...
<input id='attrs-200854d2-604b-4347-bbd0-fe98a845f033' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-d9043da8-3f21-44ce-8188-5cd18df82d83' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate bottom control parameter

array(2.)

theta_s

()

float64

...
<input id='attrs-64018952-0b95-4f4a-be07-46923d5dfe0d' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-dcefb53c-8c67-430f-bb59-bf9ad46db8a6' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

S-coordinate surface control parameter

array(10.)

u

(ocean_time, s_rho, eta_u, xi_u)

float32

...
<input id='attrs-02105b3b-c9e9-4b95-b1fe-67176b899a7b' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-c72ec1ba-f811-4ad4-96bb-82d3b3814e9b' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

u-momentum component

units :

meter second-1

time :

ocean_time

field :

u-velocity, scalar, series

[31980600 values with dtype=float32]

ubar

(ocean_time, eta_u, xi_u)

float32

...
<input id='attrs-6d2e06fb-d66f-445f-b208-31a71936ea61' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-c344a98b-6807-4491-a1c8-d07574c6f374' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

vertically integrated u-momentum component

units :

meter second-1

time :

ocean_time

field :

ubar-velocity, scalar, series

[639612 values with dtype=float32]

v

(ocean_time, s_rho, eta_v, xi_v)

float32

...
<input id='attrs-187d7b6e-e44e-4d5b-981d-a332bf2cfae7' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-73a6021d-3f6c-4f77-bb2b-5d46b0959cf0' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

v-momentum component

units :

meter second-1

time :

ocean_time

field :

v-velocity, scalar, series

[31964000 values with dtype=float32]

vbar

(ocean_time, eta_v, xi_v)

float32

...
<input id='attrs-312e2d7d-9e7d-4b3d-867a-61ec9ee32540' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-5541cc41-86f6-43a0-b024-2cb816012259' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

vertically integrated v-momentum component

units :

meter second-1

time :

ocean_time

field :

vbar-velocity, scalar, series

[639280 values with dtype=float32]

w

(ocean_time, s_w, eta_rho, xi_rho)

float32

...
<input id='attrs-a4ef8e61-95cd-4264-ba54-0d2429b26e42' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-95d98fea-7939-47eb-9acf-9ac4d6024f57' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

vertical momentum component

units :

meter second-1

time :

ocean_time

field :

w-velocity, scalar, series

[32670090 values with dtype=float32]

xl

()

float64

...
<input id='attrs-8dd5be79-c215-4ab3-a6e2-9b78c2d6cf52' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-8f743a57-2e59-45db-985a-b106dee9c91c' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

domain length in the XI-direction

units :

meter

array(1983206.706833)

zeta

(ocean_time, eta_rho, xi_rho)

float32

...
<input id='attrs-e7bc1e04-2751-438b-9888-1a911501f75e' class='xr-var-attrs-in' type='checkbox' ><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg><input id='data-ad7b3d74-1523-4732-8fc7-fc6d149bec6c' class='xr-var-data-in' type='checkbox'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg>

long_name :

free-surface

units :

meter

time :

ocean_time

field :

free-surface, scalar, series

[640590 values with dtype=float32]

<input id='section-a6a0fcfa-725b-490e-98a7-0018fc0e882c' class='xr-section-summary-in' type='checkbox'  >Attributes: (26)

file :

GOM_hurr_wrf_19950930-06.ocn_0002.hi.1995-10-04_09:00:00.nc

format :

netCDF-3 classic file

Conventions :

CF-1.4

type :

ROMS/TOMS history file

title :

BP_2010 Coupled Hindcast Run

rst_file :

gom03_rst.nc

his_base :

GOM_hurr_wrf_19950930-06.ocn_0002.hi

grd_file :

./gom03_grd_N050_coast.nc

ini_file :

./gom03_N050_coast_ini_COPERNICUS_RA025_1995_Opal.nc

bry_file :

./gom03_N050_coast_bry_COPERNICUS_RA025_1995_Opal.nc

script_file :

ocean.in

svn_url :

https://www.myroms.org/svn/src/trunk

svn_rev :

Unversioned directory

code_dir :

/scratch/06667/liu6/GOM_hurr_wrf_19950930-06/bld/ocn/src

header_dir :

/scratch/06667/liu6/GOM_hurr_wrf_19950930-06/bld/ocn/obj/../src/Apps/gom3x

header_file :

gom3x.h

os :

Linux

cpu :

x86_64

compiler_system :

ifort

compiler_command :

/opt/apps/intel18/cray_mpich/7.7.3/bin/mpif90

compiler_flags :

-fp-model precise -ip -O2 -debug minimal -free -free

tiling :

020x018

history :

Thu Nov  4 09:41:12 2021: ncks -d ocean_time,0,1 roms_test.nc ROMS/roms_test.nc
ROMS/TOMS, Version 3.5, Tuesday - September 22, 2020 -  6:42:05 PM

ana_file :

ROMS/Functionals/ana_btflux.h, ROMS/Functionals/ana_hmixcoef.h, ROMS/Functionals/ana_nudgcoef.h

CPP_options :

TXGLO, ATM_PRESS, ANA_BSFLUX, ANA_BTFLUX, ASSUMED_SHAPE, CCSMCOUPLED, CURVGRID, DIFF_GRID, DJ_GRADPS, DOUBLE_PRECISION, EAST_FSCHAPMAN, EAST_M2FLATHER, EAST_M3NUDGING, EAST_M3RADIATION, EAST_TNUDGING, EAST_TRADIATION, EAST_VOLCONS, EMINUSP, LMD_BKPP, LMD_CONVEC, LMD_MIXING, LMD_NONLOCAL, LMD_RIMIX, LMD_SKPP, MASKING, MIX_GEO_TS, MIX_S_UV, MPI, NONLINEAR, NONLIN_EOS, NORTH_VOLCONS, NORTH_FSCHAPMAN, NORTH_M2FLATHER, NORTH_M3NUDGING, NORTH_M3RADIATION, NORTH_TNUDGING, NORTH_TRADIATION, POWER_LAW, PROFILE, RADIATION_2D, RI_HORAVG, RI_VERAVG, !RST_SINGLE, SALINITY, SOLAR_SOURCE, SOLVE3D, SOUTH_FSCHAPMAN, SOUTH_M2FLATHER, SOUTH_M3NUDGING, SOUTH_M3RADIATION, SOUTH_TNUDGING, SOUTH_TRADIATION, SOUTH_VOLCONS, TS_A4HADVECTION, TS_A4VADVECTION, TS_DIF2, UV_ADV, UV_COR, UV_U3HADVECTION, UV_C4VADVECTION, UV_QDRAG, UV_VIS2, VAR_RHO_2D, VISC_GRID, WESTERN_WALL

NCO :

netCDF Operators version 4.9.7 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)

### Creating the grid object

Next we create the xgcm `Grid` object from the xarray dataset. The axes will be assumed to be non-periodic, unless specified otherwise.

```python
ds = ds.rename({'eta_u': 'eta_rho','xi_v': 'xi_rho'})

coords = {
        "X": {"center": "xi_rho", "inner": "xi_u"},
        "Y": {"center": "eta_rho", "inner": "eta_v"},
        "Z": {"center": "s_rho", "outer": "s_w"},
    }

grid = xgcm.Grid(ds, coords=coords, periodic=[])
grid
```

    <xgcm.Grid>
    X Axis (not periodic, boundary=None):
      * center   xi_rho --> inner
      * inner    xi_u --> center
    Y Axis (not periodic, boundary=None):
      * center   eta_rho --> inner
      * inner    eta_v --> center
    Z Axis (not periodic, boundary=None):
      * center   s_rho --> outer
      * outer    s_w --> center

We see that xgcm identified three different axes: X (longitude), Y (latitude), Z (depth).

## Horizontal Interpolation

### Flow speed

$$ \large Speed = \sqrt{U_{rho}^2 + V_{rho}^2} \ . $$

Below we use xgcm to compute the horizontal speed, at the surface, on the RHO-grid.

```python
U = ds.u.isel(ocean_time=0,s_rho=-1)
V = ds.v.isel(ocean_time=0,s_rho=-1)

U_rho = grid.interp(U, "X", to="center", boundary="extend")
V_rho = grid.interp(V, "Y", to="center", boundary="extend")

speed = np.sqrt(U_rho ** 2 + V_rho ** 2)
speed.plot()
```

## What about the curvilinear grid?

source:https://doi.org/10.1111/1365-2478.12844

#### Grid metrics

$$ \large \frac{\partial x}{\partial \xi} = dx = \frac{1}{pm}\ . $$
$$ \large\frac{\partial y}{\partial \eta} = dy = \frac{1}{pn}\ . $$

### Relative Vorticity

The relative vorticity is a fundamental quantity of interest in ocean circulation theory. It is defined as

$$ \large \zeta = - \frac{\partial u}{\partial y} + \frac{\partial v}{\partial x} \ . $$

$$ \large \zeta = - \frac{\partial u}{\partial \eta}\frac{\partial \eta}{\partial y} + \frac{\partial v}{\partial \xi}\frac{\partial \xi}{\partial x} \ . $$

On the c-grid, including the ROMS metrics, we get the expression:

$$ \large \zeta =  (- \delta_j u * pn + \delta_i v * pm ) \ . $$

In xgcm, we calculate this quanity as

```python
U = ds.u.isel(ocean_time=0,s_rho=-1)
V = ds.v.isel(ocean_time=0,s_rho=-1)

dUdy = grid.diff(U, axis="Y", boundary="extend")
pn = grid.interp(grid.interp(ds.pn, "X"), "Y")

dVdx = grid.diff(V, axis="X", boundary="extend")
pm=grid.interp(grid.interp(ds.pm, "X"), "Y")

```

source:myroms.org

```python
zeta = dVdx*pm - dUdy*pn
zeta.plot(vmin=-1e-4, vmax=1e-4,cmap='bwr')
```

## Exercise

### Calculate the divergence of velocity

The divergence of the horizontal flow is is expressed as

$$ \large \frac{\partial u}{\partial x} + \frac{\partial v}{\partial y} $$

Compute the divergence on the C-grid, using xgcm, and plot like previous example.

```python
U = ds.u.isel(ocean_time=0,s_rho=0)
V = ds.v.isel(ocean_time=0,s_rho=0)

```

-------------------------------
# Vertical interpolation

source:myroms.org

## ROMS Sigma coordinate transformation

$$ \large \begin{align}z(x,y,\sigma,t) &= \zeta(x,y,t) + \left[\zeta(x,y,t) + h(x,y)\right] \, S(x,y,\sigma), \\
        S(x,y,\sigma) &= \frac{h_c \, \sigma + h(x,y)\, C(\sigma)}{h_c + h(x,y)} \end{align} $$

```python
Zo_rho = (ds.hc * ds.s_rho + ds.Cs_r * ds.h) / (ds.hc + ds.h)
z_rho = ds.zeta + (ds.zeta + ds.h) * Zo_rho

z_rho.attrs = {
            "long_name": "Depth at RHO-points",
            "time": "ocean_time",
            "field": "z_rho, scalar, series",
            "units": "m",
        }

ds.coords["z_rho"] = z_rho
```

```python
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=[15,5])
fig.subplots_adjust(wspace=1.)

temp_s = ds.temp.isel(ocean_time=0,eta_rho=200,xi_rho=300)
temp_s.plot(ax=ax1, y='s_rho', yincrease=True, marker='.')

z_s = ds.z_rho.isel(ocean_time=0,eta_rho=200,xi_rho=300)
z_s.plot(ax=ax2, y='s_rho', yincrease=True, marker='.')

ax1.set_title('Temp profile (T vs s_rho)')
ax2.set_title('Depth profile (z_rho vs s_rho)')

```

```python
import numpy as np
Z_target = np.linspace(0, -250, 30)

temp_transformed = grid.transform(ds.temp, 'Z', Z_target, target_data=ds.z_rho)
```

    /scratch/training/python_geos/conda/envs/training/lib/python3.7/site-packages/numba/np/ufunc/gufunc.py:151: RuntimeWarning: invalid value encountered in _interp_1d_linear
      return self.ufunc(*args, **kwargs)

```python
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=[15,5])
fig.subplots_adjust(wspace=0.5)

temp_s.plot(ax=ax1, y='s_rho', yincrease=True, marker='.')
z_s.plot(ax=ax2, y='s_rho', yincrease=True, marker='.')
temp_transformed.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax3,y='z_rho',yincrease=True, marker='.')

ax1.set_title('Temp profile (T vs s_rho)')
ax2.set_title('Depth profile (z_rho vs s_rho)')
ax3.set_title('Interpolated Temp (T vs z_rho)')
```

## Exercise

The depth profile of Salinity is shown below. Now try to plot Salinity as a profile of Temperature linearly interpolated between 16 and 28 C.

```python
salt_s = ds.salt.isel(ocean_time=0,eta_rho=200,xi_rho=300)
salt_s.plot( y='s_rho', yincrease=True, marker='.')
```

```python
T_target = np.linspace(16, 28, 20)

salt_transformed = # Enter your expression here

fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=[15,5])
fig.subplots_adjust(wspace=0.5)

ds.salt.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax1, y='s_rho', yincrease=True, marker='.')
ds.temp.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax2, y='s_rho', yincrease=True, marker='.')
salt_transformed.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax3, y='temp',yincrease=True, marker='.')

ax1.set_title('Salt profile (T vs s_rho)')
ax2.set_title('Temp profile (S vs s_rho)')
ax3.set_title('Interpolated Salt (S vs T)')
```

```python
T_target = np.linspace(16, 28, 20)

salt_transformed = grid.transform(ds.salt, 'Z', T_target, target_data=ds.temp)

fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=[15,5])
fig.subplots_adjust(wspace=0.5)

ds.salt.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax1, y='s_rho', yincrease=True, marker='.')
ds.temp.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax2, y='s_rho', yincrease=True, marker='.')
salt_transformed.isel(ocean_time=0,eta_rho=200,xi_rho=300).plot(ax=ax3, y='temp',yincrease=True, marker='.')

ax1.set_title('Salt profile (T vs s_rho)')
ax2.set_title('Temp profile (S vs s_rho)')
ax3.set_title('Interpolated Salt (S vs T)')
```

```python

```


Data Science
====
### Introduction and Overview

Alessandro Gagliardi
Sr. Data Scientist, [Glassdoor.com](Glassdoor.com)

# Welcome!

Welcome to General Assembly's Data Science course.

Instructor:Alessandro Gagliardi

	[ADFGagliardi+GA@Gmail.com](mailto:adfgagliardi+ga@gmail.com)

TA:Kevin Perko

	[KevinJPerko+GA@Gmail.com](mailto:kevinjperko+ga@gmail.com)

Classes:6:00pm-9:00pm, Mondays and Wednesdays

	January 20 – April 7, 2014 (no class February 17)

Office Hours:9:00pm-10:00pm Wednesdays after class

	or by appointment

The class will meet every Monday and Wednesday until April 7 except for February 17 which is Presidents' Day.

Kevin, your TA, will hold office hours will be held immediately following class on Wednesdays and either of us will be available by appointment.

## Who am I?

- 1997 - 2001 - Studied Computer Science at UC Santa Cruz
- 2001 - 2002 - Developed web-based educational CRM at TMP.Worldwide in New York
- 2002 - 2003 - Took some time off
- 2003 - 2005 - Worked as a independent consultant for startups in New York
- 2005 - 2010 - Studient Integrative Neuroscience at Rutgers
- 2010 - 2011 - Taught Psychology and Neuroscience at USF, NDNU, CIIS
- 2011 - 2014 - Returned to industry as a Data Scientist at Socialize (R.I.P.), Path, and Glassdoor

## Who are you?

- Your name
- Where you work and what you do there
- What you hope to get out of this course (in 1 sentence, please)

1. Lecture
    A. What is Data Science?
    B. Goals of the Course
2. Lab
    A. Git setup
    B. IPython Notebook setup
    C. Working in Python

But first...

Since today's my birthday, I thought I might have us warm up our brains with...

# The Birthday Paradox!
(credit to [Balthazar Rouberol](https://gist.github.com/brouberol/6524605) for preparing what follows)

Given a sample of _n_ people, we would like to calculate the probability _p_ that _at least_ one person has the same birthday as _any_ other person in the group.

First: how many know this paradox? Keep the answer to yourselves.

The rest of you: how big do you think this class would have to be in order for there to be >50% chance that two people have the same birthday?

Alternatively, what are the chances that two people in this class have the same birthday (including the TA and me).

### Assumptions:

* the probability distribution is uniform
* all events are independant from each other

P(A) is the probability of at least two people sharing the same birthday.
P(A') is the probability that all birthdays are different.

\begin{equation}
    P(A') = 1 - P(A)
\end{equation}

## Calculating the probability

From [Wikipedia](http://en.wikipedia.org/wiki/Birthday_problem)

P(A') could be calculated as P(1) × P(2) × P(3) × ... × P(20).

The 20 independent events correspond to the 20 people, and can be defined in order. Each event can be defined as the corresponding person not sharing his/her birthday with any of the previously analyzed people. For Event 1, there are no previously analyzed people. Therefore, the probability, P(1), that person number 1 does not share his/her birthday with previously analyzed people is 1, or 100%. Ignoring leap years for this analysis, the probability of 1 can also be written as 365/365, for reasons that will become clear below.

For Event 2, the only previously analyzed people is Person 1. Assuming that birthdays are equally likely to happen on each of the 365 days of the year, the probability, P(2), that Person 2 has a different birthday than Person 1 is 364/365. This is because, if Person 2 was born on any of the other 364 days of the year, Persons 1 and 2 will not share the same birthday.

Similarly, if Person 3 is born on any of the 363 days of the year other than the birthdays of Persons 1 and 2, Person 3 will not share their birthday. This makes the probability P(3) = 363/365.

This analysis continues until Person 20 is reached, whose probability of not sharing his/her birthday with people analyzed before, P(20), is 346/365.

P(A') is equal to the product of these individual probabilities:

        (1) P(A') = 365/365 × 364/365 × 363/365 × 362/365 × ... × 346/365

The terms of equation (1) can be collected to arrive at:

        (2) P(A') = (1/365)^23 × (365 × 364 × 363 × ... × 346)
                  = 0.588

        (3) P(A) = 1 - P(A') = 0.411 = 41.1%

## Generalization

\begin{eqnarray}
P(n') &=& 1 \times (1 - \dfrac{1}{365}) \times (1 - \dfrac{2}{365}) \times ... \times (1 - \dfrac{n+1}{365}) \\
      &=& \dfrac{365 \times 364 \times ... \times (365 - n + 1)}{365^{n}} \\
      &=& \dfrac{365!}{365^{n} . (365 - n)!}\\
\end{eqnarray}

\begin{equation}
P(n) = 1 - P(n') = 1 - \dfrac{365!}{365^{n} . (365 - n)!}
             \end{equation}

```
from __future__ import division

import math

def pn_dash(n):
    """Returns probability that no birthday occur the same day in a group of n people."""
    return math.factorial(365) / (365**n * math.factorial(365 - n))

def pn(n):
    """Returns probability that birthday of at least 2 people occur same day in group of n people."""
    return 1 - pn_dash(n)
```

```
# Let's calculate it for 20 people
print '{:0.2f}%' . format(pn(20) * 100)
```

    41.14%

```
nb_people = range(0, 85, 5)
p_birthday = [pn(n) for n in nb_people]

for n, p in zip(nb_people, p_birthday):
    print 'n = {:2} -> p = {:.2f}%'.format(n, p * 100)
```

    n =  0 -> p = 0.00%
    n =  5 -> p = 2.71%
    n = 10 -> p = 11.69%
    n = 15 -> p = 25.29%
    n = 20 -> p = 41.14%
    n = 25 -> p = 56.87%
    n = 30 -> p = 70.63%
    n = 35 -> p = 81.44%
    n = 40 -> p = 89.12%
    n = 45 -> p = 94.10%
    n = 50 -> p = 97.04%
    n = 55 -> p = 98.63%
    n = 60 -> p = 99.41%
    n = 65 -> p = 99.77%
    n = 70 -> p = 99.92%
    n = 75 -> p = 99.97%
    n = 80 -> p = 99.99%

```
%pylab inline
```

    Populating the interactive namespace from numpy and matplotlib

```
# Main plot layout
f, ax = plt.subplots()
ax.set_yticks(np.arange(0, 1.1, 0.1))
plt.ylabel('probability')
f.text(x=0.5, y=0.975, s='Probability distribution of birthday collision for a sample of n people', horizontalalignment='center', verticalalignment='top')

plt.plot(nb_people, p_birthday, label='$p(n)$', color='r')
plt.plot(nb_people, [pn_dash(n) for n in nb_people],label='$p(\overline{n})$',color='b')

n_p50, p50 = [(n, pn(n)) for n in xrange(0, 100) if round(pn(n), 2) in [0.5, 0.51]][0]
plt.axhline(y=p50, xmax=n_p50/80., linestyle='--', color='grey')
plt.axvline(x=n_p50, ymax=p50, linestyle='--', color="grey")

plt.legend(loc='center right')
plt.text(n_p50 - 1, -0.055, '23')
```

## Conclusion

In a group of 23 people, there is a probability of approximately 50% of finding at least two people with the same birthday, contrary to what your intuition could tell you!

A. What is Data Science?
====
(And what does the birthday paradox have to do with it?)

List examples:

- Recommendation Engines
    - Collaborative Filtering (Amazon, Netflix)
    - PYMK (LinkedIn, etc.)
    - Other (Pandora, etc.)
- Data Viz (NYT, etc.)
- Fraud detection
- Business Intelligence (Obama 2012, etc.)

## Data Science = Data + Science

## Data can be:

1. Most data does not conform to any predetermined schema. Must ETL it first. Will cover next class.
2. Machine-readable but unpredictable. Good for communication. Bad for analysis. Mongo, XML, JSON, etc. Will cover Monday.
3. Must be structured prior to analysis. Fields always there, always same type. SQL, R, Pandas. Next week and beyond.
    - Excel is semi-structured but has some structured capabilities. Special case.

### Unstructured (e.g. Email, Photos, Books, etc.)

### Semi-Structured (e.g. XML, JSON, NoSQL, APIs, etc.)

### Structured (e.g. SQL, Data Frames, etc.)

1. Most data in the world is unstructured. That is, it does not conform to any predetermined computer-readable form. Before we can work with this sort of data, we need to extract it, transform it into something usable, and load it into our system, whatever that system may be. Extract, transform, load is ETL and its one of the less glamorous and more time consuming parts of the job, so it is important to know how to do it efficiently. We will cover this in the next class.
2. Semi-structured data is a relatively new thing and has a lot to do with the web. Semi-structured data is machine readable but does not conform to a rigid structure. This is both a blessing and a curse. The flexibility it provides makes it a lot easier for different systems to talk to one another. But that same flexibility makes working with the data in aggregate more difficult. Many "NoSQL" databases use a semi-structured schema. Those of you who are over 30 probably remember XML which was a popular standard for semi-structured in the late 90's and early 2000's. Fortunately, XML has largely been replaced by JSON which is easier to read by both humans (because it doesn't have so many angle brackets) and computers (because it is less flexible and therefore less ambiguous). We will be covering how to work with this sort of data next Monday.
3. Ultimately, Data Scientists need our data to be structured before we can do anything with it. Relational databases are structured. And once we get into Pandas and R, we will learn about data frames which are also structured. Structured data are consistent throughout. For example, a given field will have the same data type no matter what. This is extremely important because it makes it possible to work across all of the data in aggregate. This opens up the possibility to do everything from calculate sums so measuring relationships and predicting outcomes. We will cover the basics of how to work with this kind of data next week and for the most part, the rest of this course will deal with data in this form.
    1. As an aside, you might be wondering where Excel spreadsheets would fit in this list. I would place it somewhere between Structured and Semi-structured. We might call it "mostly structured". Unlike fully structured data, an Excel spreadsheet can accept different datatypes in a column. But unlike semi-structured data, it will complain when you do this (at least, as soon as you try to do an operation on that column). It probably belongs in the semi-structured category but because of the ability to do structured operations in a spreadsheet, I'm reluctant to put it there.

## Science can be:

1. Once we've got data in a form we can use, first we look at it. Sometimes that is enough to derive valuable insights. Time permitting, we will begin this week 3.
2. Then we might try to model the data which can be useful for making inferences and predictions

### Explorations / Explanations
- Data Visualization (e.g. ggplot2, Tableau, d3.js, etc.)
- Unsupervised Machine Learning (e.g. clustering, etc.)
- etc....

### Inferences / Predictions
- Regression Models (e.g. Linear Models, Logistic Regression)
- Supervised Machine Learning (e.g. Neural Nets, Genetic Algorithms)
- etc....

Data Science Workflow
=====================
From [a Taxonomy of Data Science](http://www.dataists.com/2010/09/a-taxonomy-of-data-science/) (by Dataists)

A. Obtain

B. Scrub

C. Explore

D. Model

E. Interpret

## Workflow Example:
### Problem: what are the leading indicators that a user will make a new purchase?

A. Collect data around user retention, user actions within the product, potentially find data outside of company

B. Extract aggregated values from raw data

1. How many times did a user share through Facebook within a week? A month?
2. How often did they open up our emails?

C. Examine data to find common distributions and correlations

D. Extract new meaning to predict if user would purchase again

E. Share results (and probably also go back to the drawing board)

# B. Goals of the Course

At the completion of this course, you will be able to:

- Employ the Map/Reduce paradigm to transform big unstructured data
- Access data from web-based application programming interfaces (APIs)
- Use Structured Query Language (SQL) functions like JOIN and GROUP
- Explore and present data through visualizations
- Apply generalized linear models (GLMs)
- Detect clusters in multivariate data
- Predict categories using supervised machine learning techniques

### At the completion of this course, you will be able to:

- Employ the Map/Reduce paradigm to transform big unstructured data

- Access data from web-based application programming interfaces (APIs)

- Use Structured Query Language (SQL) functions like JOIN and GROUP

- Explore and present data through visualizations

- Apply generalized linear models (GLMs)

- Detect clusters in multivariate data

- Predict categories using supervised machine learning techniques

### Tentative Course outline:

1. Intro and Overview
2. Big Data I: Hadoop
3. Big Data II: IPython.parallel
4. APIs and semi-structured data - First Project Proposals Due 1/27
5. SQL and Data Frames
6. Data Exploration & Visualization (feedback on proposals returned)
7. Linear Regression
8. Logistic Regression - Formal Project Proposals Due 2/3 (including data and methods chosen)
9. Dimensionality Reduction
10. Unsupervised Machine Learning: K-Means Clustering (feedback on proposals returned)
11. Network Analysis
12. Supervised Machine Learning: K-Nearest Neighbors - Project live on Github 2/19 (no class 2/17)
13. Supervised Machine Learning: Naive Bayes
14. Machine Learning in Python: Scikit-Learn
15. Supervised Machine Learning: Decision Trees & Random Forests - Peer Feedback Due 3/3
16. Ensemble Techniques
17. Recommendation Systems
18. Final Project Working Session
19. Final Project Working Session
20. Where to Go Next
21. Final Project Presentations (10 min. each)
22. Final Project Presentations (10 min. each)

# C. Lab

### Checklist

- Install Anaconda
- Setup Git

The following was put together by [Jake Vanderplas](http://www.vanderplas.com)

# Getting Started: Four Ways to Use Python

### 1. The Python command-line interpreter

### 2. Editing Python (.py) files

### 3. The IPython command-line interpreter

### 4. The IPython notebook

## 1. The Python command-line Interpreter

If you have never used the command-line, you're in for a treat

- Mac OSX: in Finder/Applications, search for "Terminal"

- Linux/Unix: ``Ctrl-Alt-t``

- Windows: run "cmd"

## 1. The Python command-line Interpreter

Type ``python`` at the command-line to start the interpreter

## 1. The Python Command-line Interpreter

Execute a command: Type ``print "hello world"``

## 1. The Python Command-line Interpreter

Closing the terminal:

- Either type ``exit()`` or type ``Ctrl-d``

## 2. Editing Python (.py) files

### This requires a text editor.

The best option is one which includes code highlighting

- Linux: gedit, emacs, nano, vim...
-  Mac OSX: textmate, emacs, nano, vim...
-  Windows: NotePad...

### GUI-based editors with bells & whistles

-  Linux: KWrite, Scribes, eggy
-  Mac OSX: TextWrangler, SublimeText
-  Windows: NotePad++, SublimeText

## 2. Editing Python (.py) files

Use your editor to open ``hello_world.py`` (here we use OSX's ``mate`` though any text editor will do)

Edit the file to say ``print "hello world"``

In the terminal, run ``python hello_world.py``

## 3. The IPython command-line Interpreter

IPython provides an enhanced command-line interface

It can be started by typing ``ipython``:

Useful features include tab completion, help (``?``), etc.

## 3. The IPython command-line Interpreter

Basic use is just like the standard interpreter:

## 4. The IPython Notebook

The IPython notebook can be started by typing ``ipython notebook``:

## 4. The IPython Notebook

Your web browser should open to an interactive notebook page

Notice that this slideshow is written as an IPython notebook!

The most basic data structure is the `None` type. This is the equivalent of `NULL` in other languages.
There are four numeric types: **`int, float, bool, complex`**.

```
type(1)
```

    int

```
type(2.5)
```

    float

```
type(True)
```

    bool

```
type(2+3j)
```

    complex

The next basic data type is the Python list.
**A list is an ordered collection of elements, and these elements can be of arbitrary type. Lists are mutable, meaning they can be changed in-place.**

```
k = [1, 'b', True]
```

```
k[2]
```

    True

```
k[1] = 'a'
```

```
k
```

    [1, 'a', True]

Likewise, **tuples are immutable arrays of arbitrary elements.**

```
x = (1, 'a', 2.5)
```

```
x
```

    (1, 'a', 2.5)

```
x[0]
```

    1

```
x[0] = 'b'
```

The string type in Python represents an immutable ordered array of characters (note there is no char type).

**Strings support slicing and indexing operations like arrays, and have many other string-specific functions as well.**

String processing is one area where Python excels.

Associative arrays (or hash tables) are implemented in Python as the dictionary type.

```
this_class = {'subject': 'Data Science', 'instructor': 'Alessandro', 'time': 1800, 'is_cool': True}
```

```
this_class['subject']
```

    'Data Science'

```
this_class['is_cool']
```

    True

**Dictionaries are unordered collections of key-value pairs, and dictionary keys must be immutable.**

Another basic Python data type is the set. Sets are unordered mutable collections of distinct elements.

```
y = set([1, 1, 2, 3, 5, 8])
```

```
y
```

    {1, 2, 3, 5, 8}

These are particularly useful for checking membership of an element and for ensuring element uniqueness.

### More:

- [Basic Training](http://nbviewer.ipython.org/url/www.astro.washington.edu/users/vanderplas/Astr599/notebooks/01_basic_training.ipynb)
- [Advanced Data Structures](http://nbviewer.ipython.org/url/www.astro.washington.edu/users/vanderplas/Astr599/notebooks/02_advanced_data_structures.ipynb)

# Discussion