deltametrics.mask.ShorelineMask

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

Identify the shoreline as a binary mask.

A shoreline mask object, provides a binary identification of shoreline pixels.

Examples

Initialize the ShorelineMask from elevation data:

golfcube = dm.sample_data.golf()
smsk = dm.mask.ShorelineMask(
    golfcube['eta'][-1, :, :],
    elevation_threshold=0)

fig, ax = plt.subplots(1, 2, figsize=(8, 4))
golfcube.quick_show('eta', idx=-1, ax=ax[0])
smsk.show(ax=ax[1])
plt.show()

(png, hires.png)

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

Initialize the ShorelineMask.

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. For example, a sobel edge detection and morphological thinning on a LandMask (already made from the OAM, or not) may also return a good approximation of the shoreline.

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

  • contour_threshold (float, optional) – Threshold value used when identifying the shoreline contour. For the opening angle method, this is a threshold opening angle value used to determine shoreline contour based on the sea_angles from the OpeningAnglePlanform. For the morphological method this is a threshold value between 0 and 1, for extracting the contour from the mean_image array.

  • method (str, optional) – Specifies the method to use for shoreline mask computation. Currently supports ‘OAM’ for the opening angle method (default) and ‘MPM’ for the morpholigcal planform method.

  • elevation_threshold – Passed to the initialization of an ElevationMask to discern the ocean area binary mask input to the opening angle method.

  • kwargs (optional) – Keyword arguments for shaw_opening_angle_method.

Methods

__init__(*args[, contour_threshold, method])

Initialize the ShorelineMask.

from_Planform(_Planform, **kwargs)

from_array(_arr)

Create a ShorelineMask from an array.

from_mask(UnknownMask, **kwargs)

Create a ShorelineMask directly from an ElevationMask.

from_masks(UnknownMask, **kwargs)

grab_contour(arr, shoremap)

Method to grab contour from some input array using a threshold.

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 shoreline contour.

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 shoreline contour.

static from_array(_arr)

Create a ShorelineMask 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 ShorelineMask directly from an ElevationMask.

Hint

Optionally, use the method flag to control how the mask is created.

grab_contour(arr, shoremap)

Method to grab contour from some input array using a threshold.

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