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 Trajectory. These classes can be obtained by the
prefix tunax.space. or directly by tunax..
- TRACERS_NAMES: List[str] = ['t', 's', 'b', 'pt']
Names of the tracers, in the order of temperature, salinity, buoyancy and passive tracer.
- VARIABLE_NAMES: List[str] = ['u', 'v', 't', 's', 'b', 'pt']
Names of all the variables, zonal and meridionnal velocities in addition of the tracers.
- VARIABLE_SHAPES: Dict[str, str] = {'b': 'zr', 'pt': 'zr', 's': 'zr', 't': 'zr', 'u': 'zr', 'v': 'zr'}
Shapes of all the variables on the water column.
- class Grid[source]
One dimensional spatial geometry of a water column.
This mesh is made up of a number of
nzof 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 ofhbot.- zw
Depths of cell interfaces from deepest to shallowest \([\text m]\).
- Type:
float
Arrayof shape (nz+1)
Note
The constructor
__init__takes onlyzrandzwas as arguments and construct the other attributes from them. The centers of the cellszrare not necessarly the middle between the interfaceszwbut should be between.- find_index(h)[source]
Find the index of a depth.
Find the index
iso that the depthhis in celli, which means \(z^w_i \leqslant -h \leqslant z^w_{i+1}\) if \(h \leqslant 0\) and \(i=-1\) if \(h>0\).
- classmethod linear(nz, hbot)[source]
Creates a grid with equal thickness cells.
The grid instance will have
nzcells of equal thickness for a depth ofhbot.
- classmethod analytic(nz, hbot, hc, theta=6.5)[source]
Creates a grid of type analytic.
The grid instance will have a depth of
hbotandnzcells of thickness almost equals abovehcand wider under, the strecht parameter being defined bytheta.- Parameters:
- Returns:
grid – The analytic grid.
- Return type:
- class State[source]
Water column state at one time-step.
This state is defined on a
griddescribing the geometry, and is composed of the variables of the water column : the values of the momentum variablesuandv(which are mandatory) and the tracers variablest,s,bandpt(which are optionals). The constructor takes all the attributes as parameters.- u
Zonal velocity on the center of the cells \(\left[\text m \cdot \text s^{-1}\right]\).
- Type:
float
Arrayof shape (nz)
- v
Meridional velocity on the center of the cells \(\left[\text m \cdot \text s^{-1}\right]\).
- Type:
float
Arrayof shape (nz)
- t
Temperature on the center of the cells \([° \text C]\).
- Type:
float
Arrayof shape (nz), optionnal, default=None
- s
Salinity on the center of the cells \([\text{psu}]\).
- Type:
float
Arrayof shape (nz), optionnal, default=None
- b
Buoyancy on the center of the cells \([\text{dimensionless}]\).
- Type:
float
Arrayof shape (nz), optionnal, default=None
- pt
A passive tracer on the center of the cells \([\text{dimensionless}]\).
- Type:
float
Arrayof shape (nz), optionnal, default=None
- classmethod zeros(grid, tracers)[source]
Initialize an instance with all variables equals to zero from a grid.
- init_u(hmxl=20.0, u_sfc=0.0)[source]
Initialize zonal velocity with a classical wind stratification.
Return a State object where
uis 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}\)
- init_v(hmxl=20.0, v_sfc=0.0)[source]
Initialize meridional velocity with a classical wind stratification.
Return a State object where
vis 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}\)
- 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
tis 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:
- Returns:
state – The
selfobject with the the new value of temperature.- Return type:
- 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
sis 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:
- Returns:
state – The
selfobject with the the new value of temperature.- Return type:
- class Trajectory[source]
Define the history of a simulation or an observation.
Contains the timeseries of the momentum (mandatory) variables and the tracers variables (optionals) throught the space of the
gridand thetime. The constructor takes all the attributes as parameters.- time
Time at each steps of observation from the begining of the simulation \([\text s]\).
- Type:
float
Arrayof shape (nt)
- u
Time-serie of zonal velocity \(\left[\text m \cdot \text s^{-1}\right]\).
- Type:
float
Arrayof shape (nz, nt)
- v
Time-serie of meridional velocity \(\left[\text m \cdot \text s^{-1}\right]\).
- Type:
float
Arrayof shape (nz, nt)
- t
Time-serie of temperature \([\text C°]\).
- Type:
float
Arrayof shape (nz, nt), optionnal, default=None
- s
Time-serie of salinity \([\text{psu}]\).
- Type:
float
Arrayof shape (nz, nt), optionnal, default=None
- b
Time-serie of buoyancy \([\text{dimensionless}]\).
- Type:
float
Arrayof shape (nz, nt), optionnal, default=None
- pt
Time-serie a passive tracer \([\text{dimensionless}]\).
- Type:
float
Arrayof shape (nz, nt), optionnal, default=None
- to_ds()[source]
Exports the trajectory in an xarray.Dataset.
The dimensions of the dataset are
time,grid.zrandgrid.zw, the variables areu,vand the tracers that are not set toNone, all defined on the dimensions (time,zr) orzwdepending onVARIABLE_NAMES.- Returns:
ds – Dataset of the trajectory.
- Return type:
- to_nc(nc_path)[source]
Write on a NetCDF file.
The dimensions are
time,grid.zrandgrid.zw, the variables areu,vand the tracers that are not set toNone, all defined on the dimensions (time,zr) orzwdepending onVARIABLE_NAMES.
- cut(out_nt_cut)[source]
Cut the trajectory in sub-trajectories of
out_nt_cutoutput steps.The first and last state of two consecutive trajectories are the same.
out_nt_cutis the number of output steps, it means that the time dimension of the sub-trajectories haveout_nt_cut+1elements.- Parameters:
out_nt_cut (int) – Number of output steps of the sub-trajectories.
- Returns:
traj_list – List of the sub-trajectories in the chronological order.
- Return type:
List[Trajectory]
- Warns:
Lost last trajectory – If
out_nt_cutdoes not divide the number of output step of the initial trajectory. In this case the last part of the trajectory (which is too short) is abandonned.