xwmt.wm module#

class xwmt.wm.WaterMass(grid, t_name='thetao', s_name='so', h_name='thkcello', teos10=True, cp=3992.0, rho_ref=1035.0, t_var='conservative', s_var='absolute')#

Bases: object

Stores water mass characteristics and supports methods for analyzing water masses on a numerical grid.

expand_surface_array_vertically(da_surf, target_position='outer')#

Expand surface xr.DataArray (with no “Z”-dimension coordinate) in the vertical, filling with zeros in all layers except the one that outcrops.

Parameters:
  • da_surf (xarray.DataArray) – Variable that is to be expanded in the vertical.

  • position (str) – Position of the desired vertical coordinate in the self.grid instance of xgcm.Grid. Default: “outer”. Other supported option is “center”.

get_density(density_name='rho')#

Derive density variables from layer temperature, salinity, and thickness, and add them to the dataset (if not already present). Uses the TEOS10 algorithm from the gsw package by default, unless “alpha” and “beta” variables are already provided in self.grid._ds.

Parameters:

density_name (str (default: "rho")) – Name of density variable. Supported density variables are: “rho” (in-situ), “sigma0”, “sigma1”, “sigma2”, “sigma3”, “sigma4” (corresponding to functions of the same name in the gsw package).

Return type:

xr.DataArray

get_outcrop_lev(position='center', incrop=False, min_thickness=1e-06)#

Return the first vertical level (starting from the relevant boundary) whose thickness exceeds min_thickness.

Assumes the native Z index increases downward (surface -> bottom).

Parameters:
  • position ({"center", "outer"}) – Vertical grid position for the coordinate/metric.

  • incrop (bool) – False (default): search from sea surface downward (“outcrop”). True: search from seafloor upward (“incrop”).

  • min_thickness (float) – Default: 1e-6. Minimum layer thickness required to count as the first “real” cell.

Returns:

Vertical coordinate value, broadcast across other dims, masked where no layer exceeds min_thickness.

Return type:

xr.DataArray

infer_bins(da, percentiles=[0.0, 1.0], nbins=100, surface=False)#

Specify bins based on the distribution of da, excluding outliers.

Parameters:
  • da (xarray.DataArray) – Variable used to determine bins.

  • percentiles (list) – List of length 2 containing the upper and lower percentiles to bound the array of bins. Default: [0., 1.], i.e. min and max.

  • nbins (int) – Number of bins. Default: 100.

  • surface (bool) – Default: False. If True, compute percentiles only from the outcropping layer of da.

sel_outcrop_lev(da, incrop=False, min_thickness=1e-06, position='center', **kwargs)#

Select da at the first vertical level (starting from the relevant boundary) whose thickness exceeds min_thickness.

Assumes the native Z index increases downward (surface -> bottom).

Parameters:
  • da (xr.DataArray) – DataArray to select from. Must have the same dims as the thickness metric after applying **kwargs.

  • incrop (bool) – Default: False. If True, selects the first thick level from the bottom upward.

  • min_thickness (float) – Minimum layer thickness required to count as the first “real” cell.

  • position ({"center", "outer"}) – Vertical grid position for the coordinate/metric.

  • **kwargs (dict) – Passed to .sel(**kwargs) on the thickness metric (and used to validate dims).

Returns:

da selected at the diagnosed level, masked where no level exceeds min_thickness.

Return type:

xr.DataArray

zonal_mean(da, oceanmask_name='wet')#

Compute area-weighted zonal mean (along X grid axis).

Parameters:
  • da (xarray.DataArray) – Data array to be averaged.

  • oceanmask_name (str) – Name of ocean mask xr.DataArray in self.grid._ds. Default: “wet”.

xwmt.wm.add_gridcoords(grid, coords, boundary)#