deltametrics.mask.LandMask

class deltametrics.mask.LandMask(*args, contour_threshold=75, method='OAM', **kwargs)

Identify a binary mask of the delta topset.

A land mask object, helps enforce valid masking of delta topset.

If a shoreline mask has been computed, it can be used to help compute the land mask, otherwise it will be computed from scratch.

Examples

Initialize the LandMask from elevation data:

(Source code, png, hires.png)

../_images/deltametrics-mask-LandMask-1.png
__init__(*args, contour_threshold=75, method='OAM', **kwargs)

Initialize the LandMask.

Intializing the land mask requires an array of data, should be two-dimensional.

Note

This class currently computes the mask via the Shaw opening angle method (shaw_opening_angle_method). However, it could/should be generalized to support multiple implementations via a method argument. Then, the contour_threshold might not be a property any longer, and should be treated just as any keyword passed to the method for instantiation.

Parameters:
  • arr (ndarray) – 2-D topographic array to make the mask from.

  • contour_threshold (int, float, optional) – Threshold value used to pick shoreline contour. This is a threshold opening angle used in the OAM. Default is 75 degrees.

  • method (str, optional) – Defines the planform method used. Default is the opening angle method (OAM) specified as ‘OAM’. Alternatively the morphological planform method (MPM) can be specified as ‘MPM’.

  • is_mask (bool, optional) – Whether the data in arr is already a binary mask. Default value is False. This should be set to True, if you have already binarized the data yourself, using custom routines, and want to just store the data in the LandMask object.

  • shoremask (ShoreMask, optional) – A ShoreMask object with a defined binary shoreline mask. If given, the ShoreMask object will be checked for the data and contour_threshold attributes.

  • kwargs (optional) – Keyword arguments for compute_shoremask.

Methods

__init__(*args[, contour_threshold, method])

Initialize the LandMask.

from_Planform(_Planform, **kwargs)

Compute LandMask from any BasePlanform.

from_array(_arr)

Create a LandMask from an array.

from_mask(UnknownMask, **kwargs)

Create a LandMask directly from another mask.

from_masks(UnknownMask)

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

contour_threshold

Threshold value used for picking land area.

integer_mask

Binary mask values as integer

mask

Binary mask values.

mask_type

Type of the mask (string)

shape

variables

__getitem__(var)

Implement slicing.

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

property contour_threshold

Threshold value used for picking land area.

static from_Planform(_Planform, **kwargs)

Compute LandMask from any BasePlanform.

Parameters:

Planform

static from_array(_arr)

Create a LandMask 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.

static from_mask(UnknownMask, **kwargs)

Create a LandMask directly from another mask.

Takes an ElevationMask as input and returns a LandMask; note that this method computes an OpeningAnglePlanform internally.

Parameters:
  • ElevationMask (ElevationMask) – Input ElevationMask to compute from.

  • **kwargs – Keyword arguments are passed to instantiation of all intermediate object; use these to control behavior of instantiation of other masks or planforms.

Returns:

LandMask

Return type:

LandMask

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.

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