emsarray.operations.depth#

These operations function on datasets with a depth axis, such as the output from ocean models.

emsarray.operations.depth.ocean_floor(dataset, depth_variables, *, non_spatial_variables=None)#

Make a new xarray.Dataset reduced along the given depth coordinates to only contain values along the ocean floor.

Parameters
  • dataset – The dataset to reduce.

  • depth_variables – The names of depth coordinate variables. For supported formats, use Format.get_all_depth_names().

  • non_spatial_variables – Optional. A list of the names of any non-spatial coordinate variables, such as time. The ocean floor is assumed to be static across non-spatial dimensions. For supported formats, use Format.get_time_name().

Returns

xarray.Dataset – A new dataset with values taken from the deepest data.

Examples

>>> dataset
<xarray.Dataset>
Dimensions:  (z: 5, y: 5, x: 5)
Coordinates:
    lon      (x) int64 0 -1 -2 -3 -4
    lat      (y) int64 0 1 2 3 4
    depth    (z) float64 4.25 3.25 2.25 1.25 0.25
Dimensions without coordinates: z, y, x
Data variables:
    temp     (z, y, x) float64 0.0 nan nan nan nan nan ... 4.0 4.0 4.0 4.0 4.0
>>> operations.ocean_floor(dataset, ['depth'])
<xarray.Dataset>
Dimensions:  (y: 5, x: 5)
Coordinates:
    lon      (x) int64 0 -1 -2 -3 -4
    lat      (y) int64 0 1 2 3 4
Dimensions without coordinates: y, x
Data variables:
    temp     (y, x) float64 0.0 1.0 2.0 3.0 4.0 1.0 ... 4.0 4.0 4.0 4.0 4.0

This operation is relatively efficient, but still involves masking every variable that includes a depth axis. Where possible, do any time and space slicing before calling this method, and drop any variables you are not interested in.

>>> operations.ocean_floor(
...     big_dataset['temp'].isel(record=0).to_dataset(),
...     depth_variables=big_dataset.ems.get_all_depth_names())
<xarray.Dataset>
Dimensions:  (y: 5, x: 5)
Coordinates:
    lon      (x) int64 0 -1 -2 -3 -4
    lat      (y) int64 0 1 2 3 4
Dimensions without coordinates: y, x
Data variables:
    temp     (y, x) float64 0.0 1.0 2.0 3.0 4.0 1.0 ... 4.0 4.0 4.0 4.0 4.0
emsarray.operations.depth.normalize_depth_variables(dataset, depth_variables, *, positive_down=True, deep_to_shallow=True)#

Some datasets represent depth as a positive variable, some as negative. Some datasets sort depth layers from deepest to most shallow, others from shallow to deep. normalize_depth_variables() will return a new dataset with the depth variables normalized.

The default behaviour is for positive values to indicate deeper depths (indicated via the variable attribute positive: "down"), and for the layers to be ordered deep to shallow. This behaviour can be modified using the parameters positive_down and deep_to_shallow respectively.

Parameters
  • dataset – The dataset to normalize

  • depth_variables – The names of the depth coordinate variables. This should be the names of the variables, not the dimensions, for datasets where these differ.

  • positive_down – When true (the default), positive values will indicate depth below the surface. When false, negative values indicate depth below the surface.

  • deep_to_shallow – When true (the default), the layers are ordered such that deeper layers have lower indices.