deltametrics.mask.ChannelMask

class deltametrics.mask.ChannelMask(*args, is_mask=None, **kwargs)

Identify a binary channel mask.

A channel mask object, helps enforce valid masking of channels.

Examples

Initialize the ChannelMask from elevation and flow data:

golfcube = dm.sample_data.golf()
cmsk = dm.mask.ChannelMask(
    golfcube['eta'][-1, :, :],
    golfcube['velocity'][-1, :, :],
    elevation_threshold=0,
    flow_threshold=0.3)

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

(png, hires.png)

../_images/deltametrics-mask-ChannelMask-1.png
__init__(*args, is_mask=None, **kwargs)

Initialize the ChannelMask.

Intializing the channel mask requires a flow velocity field and an array of the delta topography.

Parameters:
  • topo (ndarray) – The model topography to be used for mask creation.

  • velocity (ndarray) – The velocity array to be used for mask creation.

  • velocity_threshold (float) – Threshold velocity above which flow is considered ‘channelized’.

  • contour_threshold (int, optional) –

    Threshold value used for identfying the shoreline.

    In the case of the OAM this threshold is a threshold opening angle. Default is 75 degrees. Threshold could be between 0-1 for the MPM.

  • is_mask (bool, optional) – Whether the data in arr is already a binary mask. Default 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 ChannelMask object.

  • landmask (LandMask, optional) – A LandMask object with a defined binary land mask. If given, it will be used to help define the channel mask.

  • wetmask (WetMask, optional) – A WetMask object with a defined binary wet mask. If given, the landmask attribute it contains will be used to determine the channel mask.

  • kwargs (optional) – Keyword arguments for compute_shoremask.

Methods

__init__(*args[, is_mask])

Initialize the ChannelMask.

from_Planform(*args, **kwargs)

from_Planform_and_FlowMask(_Planform, ...)

Create from a Planform object and a FlowMask.

from_array(_arr)

Create a ChannelMask from an array.

from_mask(*args, **kwargs)

Create a ChannelMask directly from another mask.

from_masks(*args, **kwargs)

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

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’.

static from_Planform_and_FlowMask(_Planform, _FlowMask, **kwargs)

Create from a Planform object and a FlowMask.

static from_array(_arr)

Create a ChannelMask 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(*args, **kwargs)

Create a ChannelMask directly from another mask.

Can take either an ElevationMask or LandMask, and a FlowMask as input.

Examples

Initialize the ChannelMask from an ElevationMask and a FlowMask:

golfcube = dm.sample_data.golf()

# Create the ElevationMask
emsk = dm.mask.ElevationMask(
    golfcube['eta'][-1, :, :],
    elevation_threshold=0)

# Create the FlowMask
fmsk = dm.mask.FlowMask(
    golfcube['velocity'][-1, :, :],
    flow_threshold=0.3)

# Make the ChannelMask from the ElevationMask and FlowMask
cmsk = dm.mask.ChannelMask.from_mask(
    emsk, fmsk)

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

(png, hires.png)

../_images/deltametrics-mask-ChannelMask-2.png
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