deltametrics.mask.WetMask¶
- class deltametrics.mask.WetMask(*args, **kwargs)¶
Compute the wet mask.
A wet mask object, identifies all wet pixels on the delta topset. Starts with the land mask and then uses the topo_threshold defined for the shoreline computation to add the wet pixels on the topset back to the mask.
If a land mask has already been computed, then it can be used to define the wet mask. Otherwise the wet mask can be computed from scratch.
Examples
Initialize the WetMask from elevation data:
(
Source code
,png
,hires.png
)- __init__(*args, **kwargs)¶
Initialize the WetMask.
Intializing the wet mask requires either a 2-D array of data, or it can be computed if a
LandMask
has been previously computed.Hint
Pass keyword arguments to control the behavior of creating intermediate Mask or OpeningAnglePlanform objects.
- Parameters:
arr (ndarray) – The data array to make the mask from.
contour_threshold (int, optional) – Threshold value to use when identifying the contour which defines the shoreline. For the OAM this is a threshold opening angle. Default is 75 degrees.
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 WetMask object.landmask (
LandMask
, optional) – ALandMask
object with a defined binary shoreline mask. If given, theLandMask
object will be checked for the data and contour_threshold attributes.kwargs (optional) – Keyword arguments are passed to LandMask and ElevationMask, as appropriate.
Methods
__init__
(*args, **kwargs)Initialize the WetMask.
from_Planform
(_Planform, **kwargs)Create from a Planform.
from_array
(_arr)Create a WetMask from an array.
from_mask
(*args, **kwargs)Create a WetMask 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
Binary mask values as integer
Binary mask values.
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(_Planform, **kwargs)¶
Create from a Planform.
- static from_array(_arr)¶
Create a WetMask 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 WetMask directly from another mask.
Needs both an ElevationMask and a LandMask, or just an ElevationMask and will make a LandMask internally (creates a ~dm.plan.OpeningAnglePlanform); consider alternative static method
from_OAP_and_ElevationMask
if you are computing many masks.Examples
- property integer_mask¶
Binary mask values as integer
Important
integer_mask is a boolean array as
0
and1
(integers). It is not suitible for multidimensional array indexing; see alsomask
.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 as0
forFalse
and1
forTrue
. 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
andlength
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