pygetm.density module

class pygetm.density.Density[source]

Bases: object

CP = 3991.86795711963

specific heat (J kg-1 K-1)

static convert_ts(salt: Array, temp: Array, p: Array | None = None, in_situ: bool = False) None[source]

Convert practical salinity and potential temperature to absolute salinity and conservative temperature. The conversion happens in-place: absolute salinity (g kg-1) will replace practical salinity, conservative temperature (°C) will replace potential temperature.

Parameters:
  • salt – practical salinity (PSU)

  • temp – potential temperature or, if in_situ=True, in-situ temperature (°C)

  • p – pressure (dbar). If not provided, the water depth in m will be used as approximate pressure.

  • in_situtemp is in-situ temperature rather than potential temperature

static get_buoyancy_frequency(SA: Array, ct: Array, p: Array | None = None, out: Array | None = None) Array[source]

Calculate the square of the buoyancy frequency at layer interfaces from absolute salinity, conservative temperature and pressure at the layer centers.

Parameters:
  • SA – absolute salinity (g kg-1)

  • ct – conservative temperature (°C)

  • p – pressure (dbar). If not provided, the water depth in m will be used as approximate pressure.

  • out – array to store buoyancy frequency result in. If not provided, a new array will be created.

Returns:

array with values for the square of the buoyancy frequency (s-2)

static get_density(SA: Array, ct: Array, p: Array | None = None, out: Array | None = None) Array[source]

Calculate in-situ density from absolute salinity and conservative temperature. Inputs can be 2D or 3D.

Parameters:
  • SA – absolute salinity (g kg-1)

  • ct – conservative temperature (°C)

  • p – pressure (dbar). If not provided, the water depth in m will be used as approximate pressure.

  • out – array to store density result in. If not provided, a new array will be created.

Returns:

array with density values (kg m-3)

static get_potential_temperature(SA: Array, ct: Array, out: Array | None = None) Array[source]

Calculate potential temperature from absolute salinity and conservative temperature. Inputs can be 2D or 3D.

Parameters:
  • SA – absolute salinity (g kg-1)

  • ct – conservative temperature (°C)

  • out – array to store potential temperature result in. If not provided, a new array will be created.

Returns:

array with potential temperature values (°C)

static lazy_convert_ts(salt: DataArray, temp: DataArray, p: Array | None = None, lon: Array | None = None, lat: Array | None = None, in_situ: bool = False) tuple[DataArray, DataArray][source]

Lazily convert practical salinity and potential temperature to absolute salinity and conservative temperature. The conversion is done only when the returned objects are indexed or cast to a numpy.ndarray.

Parameters:
  • salt – practical salinity (PSU)

  • temp – potential temperature or, if in_situ=True, in-situ temperature (°C)

  • p – pressure (dbar). If not provided, it will be inferred from the depth coordinate of salt or temp.

  • lon – longitude (°East). If not provided, it will be inferred from the coordinates of salt or temp.

  • lat – latitude (°North). If not provided, it will be inferred from the coordinates of salt or temp.

  • in_situ – input is in-situ temperature rather than potential temperature

Returns:

a tuple with lazy arrays for absolute salinity (g kg-1) and conservative temperature (°C)

class pygetm.density.LazyConvert(salt: ndarray | Number | LazyArray | Variable, temp: ndarray | Number | LazyArray | Variable, lon: ndarray | Number | LazyArray | Variable, lat: ndarray | Number | LazyArray | Variable, p: ndarray | Number | LazyArray | Variable, in_situ: bool = False, return_salt: bool = True)[source]

Bases: Operator

apply(salt: ndarray, temp: ndarray, lon: ndarray, lat: ndarray, p: ndarray, dtype=None) ndarray[source]