space

Geometry and variables of the model.

This module contains the objects that are used in Tunax to describe the geometry of the water column in Grid, the variables of the water column at one time-step in State and the time-series of the model computation in Trajectories. These classes can be obtained by the prefix tunax.space. or directly by tunax..

class Grid(zr, zw)[source]

One dimensional spatial geometry of a water column.

This mesh is made up of a number of nz of cells (zr) of potentially varying thickness (hz), separated by interface points (zw) and extending from the ocean surface at a depth of \(0\) to the ocean floor at a depth of hbot.

Parameters:
  • zr (Float[Array, 'nz']) – cf. attribute.

  • zw (Float[Array, 'nz+1']) – cf. attribute.

nz

Number of cells.

Type:

int

hbot

Depth of the water column \([\text m]\).

Type:

float

zr

Depths of cell centers from deepest to shallowest \([\text m]\)

Type:

Float[Array, ‘nz’]

zw

Depths of cell interfaces from deepest to shallowest \([\text m]\).

Type:

Float[Array, ‘nz+1’]

hz

Thickness of cells from deepest to shallowest \([\text m]\).

Type:

Float[Array, ‘nz’]

Note

The constructor __init__ takes only zr and zw as as arguments and construct the other attributes from them. The centers of the cells zr are not necessarly the middle between the interfaces zw.

find_index(h)[source]

Find the index of a depth.

Find the index i so that the depth h is in cell i, which means \(z^w_i \leqslant -h \leqslant z^w_{i+1}\) if \(h \leqslant 0\) and \(i=-1\) if \(h>0\).

Parameters:

h (float, positive) – The depth to search the index \([\text m]\).

Returns:

i – The index corresponding to the depth h.

Return type:

int

classmethod linear(nz, hbot)[source]

Creates a grid with equal thickness cells.

The grid instance will have nz cells of equal thickness for a depth of hbot.

Parameters:
  • nz (int) – Number of cells.

  • hbot (float, positive) – Depth of the water column \([\text m]\).

Return type:

Grid

classmethod analytic(nz, hbot, hc, theta=6.5)[source]

Creates a grid of type analytic.

The grid instance will have a depth of hbot and nz cells of thickness almost equals above hc and wider under, the strecht parameter being defined by theta.

Parameters:
  • nz (int) – Number of cells.

  • hbot (float, positive) – Depth of the water column \([\text m]\).

  • hc (float, positive) – Reference depth \([\text m]\).

  • theta (float, default=6.5) – Stretching parameter toward the surface \([\text{dimensionless}]\).

Return type:

Grid

classmethod orca75(hbot)[source]

Creates the ORCA 75 grid from NEMO.

The whole grid is created then levels between the depth hbot and \(0\) are extracted.

Parameters:

hbot (float, positive) – Depth of the water column \([\text m]\).

Return type:

Grid

classmethod load(ds)[source]

Creates the grid defined by a dataset ds of an observation.

The dataset must be formated to have the variables corresponding to zr and zw.

Parameters:

ds (xarray.Dataset) – Dataset from which to extract the grid.

Return type:

Grid

class State(grid, u, v, t, s)[source]

Water column state at one time-step.

This state is defined on a grid describing the geometry, and is composed of the variables of the water column : the values of the momentum and the tracers on this grid. The call of the constructor build a state on the grid with all the variables set to \(0\).

Parameters:
  • grid (Grid) – cf. attribute.

  • u (Float[Array, 'nz'])

  • v (Float[Array, 'nz'])

  • t (Float[Array, 'nz'])

  • s (Float[Array, 'nz'])

grid

Geometry of the water column.

Type:

Grid

u

Zonal velocity on the center of the cells \(\left[\text m \cdot \text s^{-1}\right]\).

Type:

Float[Array, ‘nz’]

v

Meridional velocity on the center of the cells \(\left[\text m \cdot \text s^{-1}\right]\).

Type:

Float[Array, ‘nz’]

t

Temperature on the center of the cells \([° \text C]\).

Type:

Float[Array, ‘nz’]

s

Salinity on the center of the cells \([\text{psu}]\).

Type:

Float[Array, ‘nz’]

classmethod zeros(grid)[source]

Initialize an instance with all variables equals to zero from a grid.

Parameters:

grid (Grid) – Geometry of the water column.

Returns:

state – An instance defined on the grid with all variables set to 0.

Return type:

State

init_u(hmxl=20.0, u_sfc=0.0)[source]

Initialize zonal velocity with a classical wind stratification.

Return a State object where u is continuous and linear by part \(u(z) = \begin{cases} 0 & \text{if } z < h_{\text{mxl}}\\ u_{\text{sfc}} \left( 1 - \dfrac z {h_{\text{mxl}}}\right) & \text{else} \end{cases}\)

Parameters:
  • hmxl (float, default=20.) – Mixed layer depth \([\text m]\).

  • u_sfc (float, default=0.) – Surface zonal velocity \(\left[\text m \cdot \text s^{-1}\right]\).

Returns:

state – The self object with the the new value of zonal velocity.

Return type:

State

init_v(hmxl=20.0, v_sfc=0.0)[source]

Initialize meridional velocity with a classical wind stratification.

Return a State object where v is continuous and linear by part \(v(z) = \begin{cases} 0 & \text{if } z < h_{\text{mxl}}\\ v_{\text{sfc}} \left( 1 - \dfrac z {h_{\text{mxl}}}\right) & \text{else} \end{cases}\)

Parameters:
  • hmxl (float, default=20.) – Mixed layer depth \([\text m]\).

  • u_sfc (float, default=0.) – Surface meridional velocity \(\left[\text m \cdot \text s^{-1}\right]\).

  • v_sfc (float)

Returns:

state – The self object with the the new value of meridional velocity.

Return type:

State

init_t(hmxl=20.0, t_sfc=21.0, strat_t=0.051)[source]

Initialize temperature with a classical tracer stratification.

Return a State object where t is linear by part and continous \(T(z) = \begin{cases} t_{\text{sfc}} + S_T(z-h_{\text{mxl}}) & \text{if } z < h_{\text{mxl}}\\ t_{\text{sfc}} & \text{else} \end{cases}\)

Parameters:
  • hmxl (float, default=20.) – Mixed layer depth \([\text m]\).

  • t_sfc (float, default=21.) – Surface temperature \([° \text C]\).

  • strat_t (float, default=5.1e-2) – Thermal stratification above the mixed layer noted by \(S_T\) \([\text K \cdot \text m ^{-1}]\).

Returns:

state – The self object with the the new value of temperature.

Return type:

State

init_s(hmxl=20.0, s_sfc=35.0, strat_s=0.013)[source]

Initialize salinity with a classical tracer stratification.

Return a State object where s is linear by part and continous \(S(z) = \begin{cases} s_{\text{sfc}} + S_S(z-h_{\text{mxl}}) & \text{if } z < h_{\text{mxl}}\\ s_{\text{sfc}} & \text{else} \end{cases}\)

Parameters:
  • hmxl (float, default=20.) – Mixed layer depth \([\text m]\).

  • s_sfc (float, default=21.) – Surface salinity \([\text{psu}]\).

  • strat_t (float, default=5.1e-2) – Salinity stratification above the mixed layer noted by \(S_T\) \([\text{psu} \cdot \text m ^{-1}]\).

  • strat_s (float)

Returns:

state – The self object with the the new value of temperature.

Return type:

State

class Trajectory(grid, time, t, s, u, v)[source]

Define the history of a simulation or an observation.

Contains the timeseries of the momentum and the tracers throught the space of the grid and the time.

Parameters:
  • grid (Grid) – cf. attribute.

  • time (Float[Array, 'nt']) – cf. attribute.

  • u (Float[Array, 'nt nz']) – cf. attribute.

  • v (Float[Array, 'nt nz']) – cf. attribute.

  • t (Float[Array, 'nt nz']) – cf. attribute.

  • s (Float[Array, 'nt nz']) – cf. attribute.

grid

Geometry of the water column.

Type:

Grid

time

Time at each steps of observation from the begining of the simulation \([\text s]\).

Type:

Float[Array, ‘nt’]

u

Time-serie of zonal velocity \(\left[\text m \cdot \text s^{-1}\right]\).

Type:

Float[Array, ‘nt nz’]

v

Time-serie of meridional velocity \(\left[\text m \cdot \text s^{-1}\right]\).

Type:

Float[Array, ‘nt nz’]

t

Time-serie of temperature \([\text C°]\).

Type:

Float[Array, ‘nt nz’]

s

Time-serie of salinity \([\text{psu}]\).

Type:

Float[Array, ‘nt nz’]

to_ds()[source]

Exports the trajectory in an xarray.Dataset.

The dimensions of the dataset are time, grid.zr and grid.zw, the variables are u, v, t and s, all defined on the dimensions (time, zr).

Returns:

ds – Dataset of the trajectory.

Return type:

xarray.Dataset

extract_state(i_time)[source]

Extracts the water column state at one time index.

Parameters:

i_time (int) – The time index of the moment to extract the state.

Returns:

state – The state of the trajectory at the time of index i_time.

Return type:

State