deltametrics.mask.ElevationMask

class deltametrics.mask.ElevationMask(*args, elevation_threshold, elevation_offset=0, cube_key='eta', **kwargs)

Elevation mask.

This mask implements a binarization of a raster based on elevation values.

Examples

Initialize the ElevationMask from elevation data:

(Source code, png, hires.png)

../_images/deltametrics-mask-ElevationMask-1.png
__init__(*args, elevation_threshold, elevation_offset=0, cube_key='eta', **kwargs)

Initialize the ElevationMask.

Note

Needs docstring!

Methods

__init__(*args, elevation_threshold[, ...])

Initialize the ElevationMask.

from_array(_arr)

Create an ElevationMask from an array.

show([ax, title, ticks, colorbar])

Show the mask.

trim_mask(*args[, value, axis, length])

Replace a part of the mask with a new value.

Attributes

elevation_offset

An optional offset to apply to input threshold.

elevation_threshold

Elevation value used to threshold the elevation data.

integer_mask

Binary mask values as integer

mask

Binary mask values.

mask_type

Type of the mask (string)

shape

threshold

Generic property for ThresholdValueMask threshold.

variables

__getitem__(var)

Implement slicing.

Return values directly from the mask. Supported variables are only ‘mask’ or ‘integer’.

property elevation_offset

An optional offset to apply to input threshold.

property elevation_threshold

Elevation value used to threshold the elevation data.

Determined during instantiation as the sum of input arguments to __init__ elevation_threshold and elevation_offset.

static from_array(_arr)

Create an ElevationMask from an array.

Note

Instantiation with from_array will attempt to any data type (dtype) to boolean. This may have unexpected results. Convert your array to a boolean before using from_array to ensure the mask is created correctly.

Parameters:

_arr (ndarray) – The array with values to set as the mask. Can be any dtype but will be coerced to boolean.

property integer_mask

Binary mask values as integer

Important

integer_mask is a boolean array as 0 and 1 (integers). It is not suitible for multidimensional array indexing; see also mask.

Read-only mask attribute.

Type:

ndarray

property mask

Binary mask values.

Important

mask is a boolean array (not integer). See also integer_mask.

Read-only mask attribute.

Type:

ndarray

property mask_type

Type of the mask (string)

show(ax=None, title=None, ticks=False, colorbar=False, **kwargs)

Show the mask.

The Mask is shown in a matplotlib axis with imshow. The mask values are accessed from integer_mask, so the display will show as 0 for False and 1 for True. Default colormap is black and white.

Hint

Passes **kwargs to matplotlib.imshow.

Parameters:

ax (matplotlib.pyplot.Axes) – Which axes object to plot into.

property threshold

Generic property for ThresholdValueMask threshold.

trim_mask(*args, value=False, axis=1, length=None)

Replace a part of the mask with a new value.

This is sometimes necessary before using a mask in certain computations. Most often, this method is used to manually correct domain edge effects.

Parameters:
  • *args (BaseCube subclass, optional) – Optionally pass a Cube object to the mask, and the dimensions to trim/replace the mask by will be inferred from the cube. In this case, axis and length have no effect.

  • value – Value to replace in the trim region with. Default is False.

  • axis – Which edge to apply the trim of length to. Default is 1, the top domain edge.

  • length – The length of the trim. Note that this is not the array index.

Examples