Mask¶
Geometry-based masks, morphological mask ops, and boolean mask algebra. Convention: True means
"mask this pixel out" (consistent with geoops.qa; see Mask polarity).
- Geometry / DEM masks:
PolygonMask,BBoxMask,DistanceMask,LandMask,OceanMask,CountryMask,AltitudeMask,SlopeMask—keep="inside"(default) keeps the region and masks everything else;keep="outside"drops the region.LandMask/OceanMask/CountryMaskload Natural Earth lazily on their first call (never in the constructor, so building or hydrating a pipeline does no network I/O); the GeoDataFrames are then cached for the process lifetime —mask.clear_natural_earth_cache()releases them.AltitudeMask/SlopeMasktake the DEM as a second positional carrier on the scene's grid:SlopeMask(max_slope_deg=10.0)(scene, dem). - Morphology:
DilateMask,ErodeMask,OpenMask,CloseMask,BufferMask,RemoveSmallObjects,RemoveSmallHoles,CleanMask - Algebra:
CombineMasks(op="or" | "and" | "xor")(m1, m2, ...)(masks on one pixel grid),InvertMask - Apply:
ApplyMask(fill values where mask isTrue):ApplyMask()(gt, mask)with a mask carrier, orApplyMask(mask=BBoxMask(...))(gt)with a mask-producing operator - Tier-A primitives:
apply_mask,dilate_mask,erode_mask,open_mask,close_mask,buffer_mask,clean_mask,remove_small_objects,remove_small_holes,combine_masks,invert_mask,distance_mask,altitude_mask,slope_mask,slope_degrees
geoops.mask
¶
Geometry masks, morphological cleanup, mask algebra, and mask application.
AltitudeMask
¶
Bases: Operator
Build a boolean mask from DEM elevation bounds.
Follows the package polarity (True = drop): with the default
keep="inside" the mask is True where the DEM falls outside the
requested elevation interval. Either bound may be None for an
open-ended interval.
Called as op(scene, dem): the output mask is wrapped like
scene (a GeoArray or plain ndarray), and dem is a single-band
carrier on the scene's pixel grid -- same spatial shape and, when both
are georeferenced, the same transform / CRS (ValueError
otherwise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_elev
|
float | None
|
Inclusive lower bound (units of the DEM). |
None
|
max_elev
|
float | None
|
Inclusive upper bound. |
None
|
keep
|
Keep
|
|
'inside'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
ApplyMask
¶
Bases: Operator
Apply a boolean mask to the carrier, filling True pixels.
Accepts a GeoArray or a plain ndarray and returns the same
carrier kind. This is the canonical mask-application operator.
Delegates the actual masking to
:func:geoops.mask._src.array.apply_mask so the broadcasting +
dtype-preservation rules stay in one place.
Convention: the mask is True where pixels should be masked out —
the polarity every geoops.mask and geoops.qa producer
returns, so geometry masks keep their area of interest by default.
Flip a keep-polarity mask (e.g. valid_mask()) with
:class:InvertMask / :func:~geoops.mask.invert_mask first.
Called as op(gt, mask) with the boolean mask carrier (GeoArray
or ndarray) on gt's pixel grid (ValueError otherwise), so it
wires into a pipekit_ops.Graph as ApplyMask()(Input("x"),
Input("mask")). Alternatively configure a mask operator (e.g. a
geometry mask) that builds the mask from gt and call op(gt).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Operator | None
|
Optional |
None
|
fill_value
|
float | None
|
Value substituted where the mask says "drop". The
default |
None
|
Examples:
>>> import geoops as gz, numpy as np
>>> aoi = gz.mask.BBoxMask(bounds=(1.0, 1.0, 3.0, 3.0))
>>> keep_aoi = gz.mask.ApplyMask(mask=aoi) # fills outside the box
>>> out = keep_aoi(scene)
>>> out = gz.mask.ApplyMask()(scene, cloud_mask)
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 | |
BBoxMask
¶
Bases: PolygonMask
Rasterize an axis-aligned bounding box into a boolean mask.
Geo-dependent: requires a georeferenced GeoArray input (see
:class:PolygonMask).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
tuple[float, float, float, float]
|
|
required |
crs
|
str | None
|
CRS of |
None
|
keep
|
Keep
|
|
'inside'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
BufferMask
¶
Bases: Operator
Radially expand True pixels in a mask by a Euclidean buffer.
Wraps :func:geoops.mask.buffer_mask. With unit="pixels"
(default) the op is metadata-free and accepts a GeoArray or a
plain ndarray, returning the same carrier kind. With
unit="meters" the op is geo-dependent: the input must be a
georeferenced GeoArray whose transform supplies the ground
pixel steps (rotated grids are measured correctly, sheared grids
raise ValueError), and radius is measured in CRS units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Buffer distance, in pixels or CRS units per |
required |
unit
|
str
|
|
'pixels'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
spatial_reach()
¶
Spatial reach in pixels: ⌈radius⌉; None for a radius in map units.
CleanMask
¶
Bases: Operator
Remove small objects, fill small holes, then close the mask.
Convenience composition of :class:RemoveSmallObjects,
:class:RemoveSmallHoles, and :class:CloseMask, in that order.
Accepts a GeoArray or a plain ndarray and returns the same carrier
kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_area_px
|
int
|
Components smaller than this are removed. |
25
|
max_hole_area_px
|
int
|
Enclosed holes up to this size are filled. |
25
|
close_iter
|
int
|
Binary-closing iterations applied last; |
1
|
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
CloseMask
¶
Bases: Operator
Close (dilate then erode) a boolean mask.
Wraps :func:scipy.ndimage.binary_closing. Useful for filling
pin-holes (pepper) inside otherwise solid True regions. Accepts a
GeoArray or a plain ndarray and returns the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterations
|
int
|
Number of closing passes. |
1
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
spatial_reach()
¶
CombineMasks
¶
Bases: Operator
Combine boolean masks on one pixel grid with or, and or xor.
Called with the masks as positional arguments, op(m1, m2, ...)
(GeoArrays or plain ndarrays) -- so it wires straight into a
pipekit_ops.Graph as CombineMasks()(Input("a"), Input("b")) -- or
with one sequence of them, op([m1, m2]), or one (T, C, H, W)
stack whose frames are the masks. Every mask must sit on the first
mask's pixel grid (ValueError otherwise, see
:func:geoops._src.geo.grid_matches). The output takes its carrier
kind -- and, for GeoArrays, its metadata -- from the first mask.
Every input must use the package polarity (True = drop), so
op="or" drops a pixel that any mask drops. Use :class:InvertMask
for the complement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
str
|
|
'or'
|
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
CountryMask
¶
Bases: _NaturalEarthMask
Rasterize Natural Earth country polygons selected by ISO A3 code.
Geo-dependent: requires a georeferenced GeoArray input (see
:class:PolygonMask). The polygons are loaded on the first call,
never in the constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iso_a3
|
str | Sequence[str]
|
One ISO A3 country code or a sequence of them (e.g.
|
required |
source
|
str
|
|
'natural_earth_10m'
|
keep
|
Keep
|
|
'inside'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On the first call, if none of the requested codes are found (codes are checked only once the polygons load). |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
DilateMask
¶
Bases: Operator
Dilate a boolean mask over its trailing spatial axes.
Wraps :func:scipy.ndimage.binary_dilation. The structuring element
defaults to a 3x3 box (8-connectivity). Stacks of masks of shape
(C, H, W) are processed per channel. Accepts a GeoArray or a
plain ndarray and returns the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterations
|
int
|
Number of dilation passes. |
1
|
structure
|
ndarray | None
|
Optional 2-D structuring element. |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
spatial_reach()
¶
Spatial reach in pixels: a structuring half-width per iteration.
DistanceMask
¶
Bases: PolygonMask
Mask pixels by their distance from a geometry (True = drop).
Rasterizes the geometry onto the carrier grid, then buffers it by
distance (CRS units, using the carrier's ground pixel steps
hypot(a, d) / hypot(b, e) so rotated grids measure true
distances; sheared grids raise ValueError; see
:func:geoops.mask.distance_mask). Geo-dependent: requires a
georeferenced GeoArray input. Like :class:PolygonMask, it
returns one boolean (H, W) mask whatever the carrier's rank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
BaseGeometry | GeoDataFrame
|
Shapely geometry or |
required |
distance
|
float
|
Maximum distance from the geometry, in CRS units. |
required |
keep
|
Keep
|
|
'inside'
|
crs
|
str | None
|
CRS of |
None
|
all_touched
|
bool
|
Rasterization rule; see :class: |
True
|
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
ErodeMask
¶
Bases: Operator
Erode a boolean mask over its trailing spatial axes.
Wraps :func:scipy.ndimage.binary_erosion; see :class:DilateMask
for the structuring-element and carrier conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterations
|
int
|
Number of erosion passes. |
1
|
structure
|
ndarray | None
|
Optional 2-D structuring element. |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
spatial_reach()
¶
Spatial reach in pixels: a structuring half-width per iteration.
InvertMask
¶
Bases: Operator
Invert a boolean mask element-wise.
The one complement operator (wraps :func:geoops.mask.invert_mask):
turns a keep-polarity mask (True = keep, e.g. valid_mask()) into
the package's drop polarity, and back. Accepts a GeoArray or a
plain ndarray and returns the same carrier kind. Takes no parameters.
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
LandMask
¶
Bases: _NaturalEarthMask
Rasterize Natural Earth land polygons into a boolean mask.
Geo-dependent: requires a georeferenced GeoArray input (see
:class:PolygonMask). The polygons are loaded on the first call,
never in the constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
|
'natural_earth_10m'
|
keep
|
Keep
|
|
'inside'
|
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
OceanMask
¶
Bases: _NaturalEarthMask
Rasterize Natural Earth ocean polygons into a boolean mask.
Geo-dependent: requires a georeferenced GeoArray input (see
:class:PolygonMask). The polygons are loaded on the first call,
never in the constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
|
'natural_earth_10m'
|
keep
|
Keep
|
|
'inside'
|
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
OpenMask
¶
Bases: Operator
Open (erode then dilate) a boolean mask.
Wraps :func:scipy.ndimage.binary_opening. Useful for removing
isolated True pixels (salt) while preserving large True components.
Accepts a GeoArray or a plain ndarray and returns the same carrier
kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterations
|
int
|
Number of opening passes. |
1
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
spatial_reach()
¶
PolygonMask
¶
Bases: Operator
Rasterize a shapely geometry or GeoDataFrame into a boolean mask.
Follows the package polarity (True = drop): with the default
keep="inside" the mask is True outside the geometry, so
ApplyMask(mask=PolygonMask(...)) keeps the area of interest.
Geo-dependent: rasterization needs the carrier's transform/CRS, so
the input must be a georeferenced GeoArray. The mask matches
the carrier's spatial grid and is returned as a boolean (H, W)
GeoArray with fill_value=False whatever the carrier's
rank: every band and every frame of a (T, C, H, W) stack share
the same grid, so one mask serves them all (it broadcasts in
:class:ApplyMask).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
BaseGeometry | GeoDataFrame
|
Shapely geometry or |
required |
crs
|
str | None
|
CRS of |
None
|
all_touched
|
bool
|
Burn every pixel touched by the geometry instead of only pixels whose center is inside. |
False
|
keep
|
Keep
|
|
'inside'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
RemoveSmallHoles
¶
Bases: Operator
Fill enclosed False components up to max_hole_area_px pixels.
Wraps :func:geoops.mask.remove_small_holes; holes touching the
image border are never filled. Accepts a GeoArray or a plain
ndarray and returns the same carrier kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_hole_area_px
|
int
|
Maximum hole area, in pixels, to fill. |
required |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
RemoveSmallObjects
¶
Bases: Operator
Remove connected True components smaller than min_area_px pixels.
Wraps :func:geoops.mask.remove_small_objects (4-connectivity).
Accepts a GeoArray or a plain ndarray and returns the same carrier
kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_area_px
|
int
|
Minimum component area, in pixels, to keep. |
required |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
SlopeMask
¶
Bases: Operator
Build a boolean mask from DEM slope bounds in degrees.
Slope is computed from the DEM with central differences scaled by
the DEM's ground pixel steps (hypot(a, d) / hypot(b, e), so
rotated grids measure true distances; sheared grids are rejected).
The DEM must be in a projected CRS: a geographic DEM's pixel size is
in degrees and raises ValueError. Follows the package polarity
(True = drop): with the default keep="inside" the mask is True
where the slope (degrees) falls outside the requested interval.
Called as op(scene, dem). Geo-dependent on the DEM side: dem
must be a single-band georeferenced GeoArray (its transform
supplies the pixel size, in the same units as the elevation values)
on the scene's pixel grid. The scene may be a GeoArray or plain
ndarray; when both are georeferenced, their transform / CRS must
match (ValueError otherwise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_slope_deg
|
float | None
|
Inclusive lower bound, degrees. |
None
|
max_slope_deg
|
float | None
|
Inclusive upper bound, degrees. |
None
|
keep
|
Keep
|
|
'inside'
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
altitude_mask(dem, *, min_elev=None, max_elev=None, keep='inside')
¶
Mask DEM cells by an elevation interval (True = drop).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
Float[ndarray, 'h w'] | Float[ndarray, '1 h w']
|
Single-band elevation raster, |
required |
min_elev
|
float | None
|
Inclusive lower elevation bound (DEM units). |
None
|
max_elev
|
float | None
|
Inclusive upper elevation bound. |
None
|
keep
|
Keep
|
|
'inside'
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, 'h w']
|
Boolean |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both bounds are |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
apply_mask(arr, mask, fill_value=np.nan)
¶
Apply a boolean mask to a multi-band array, filling masked pixels.
The mask follows the package polarity: True where pixels should be
masked out (dropped) — see "Mask polarity" in docs/operators/concepts.md.
The result is arr with fill_value substituted wherever
mask is True. Flip a keep-polarity mask with :func:invert_mask
first.
The mask broadcasts against the spatial trailing axes of arr,
so a (H, W) mask applies to every band of a (C, H, W)
raster automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Shaped[ndarray, '*dims']
|
Input array, any shape. |
required |
mask
|
Bool[ndarray, '*mask_dims']
|
Boolean mask. Must broadcast against the spatial
(trailing two) axes of |
required |
fill_value
|
float
|
Value substituted where the mask says "drop".
Default |
nan
|
Returns:
| Type | Description |
|---|---|
Shaped[ndarray, '*dims']
|
Array of the same shape as |
Shaped[ndarray, '*dims']
|
with |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
buffer_mask(mask, radius, *, unit='pixels', pixel_size=(1.0, 1.0))
¶
Radially expand True pixels by a Euclidean-distance buffer.
A pixel is True in the output when its Euclidean distance to the
nearest originally-True pixel is at most radius (so the original
True pixels are always kept). Each leading (batch / band) slice is
buffered independently.
Unit contract:
unit="pixels"(default):radiusis measured in pixels on the unit grid — every pixel is treated as 1 x 1 andpixel_sizeis ignored.unit="meters"(or"meter"):radiusis measured in the same linear units aspixel_size(metres for a projected CRS).pixel_sizemust then be the per-axis pixel extent(row_height, col_width)— i.e.(abs(yres), abs(xres))from the geotransform — and is passed as thesamplingof the distance transform so anisotropic pixels buffer correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
radius
|
float
|
Buffer distance, in the units selected by |
required |
unit
|
str
|
|
'pixels'
|
pixel_size
|
tuple[float, float]
|
|
(1.0, 1.0)
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The buffered boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
clean_mask(mask, *, min_area_px=25, max_hole_area_px=25, close_iter=1)
¶
Remove small objects, fill small holes, then close the mask.
Convenience composition of :func:remove_small_objects,
:func:remove_small_holes, and :func:close_mask, in that order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
min_area_px
|
int
|
Components smaller than this many pixels are removed. |
25
|
max_hole_area_px
|
int
|
Enclosed holes up to this many pixels are filled. |
25
|
close_iter
|
int
|
Binary-closing iterations applied last. |
1
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The cleaned boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any size/iteration argument is negative or
|
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
clear_natural_earth_cache()
¶
Release the in-process Natural Earth GeoDataFrames.
LandMask / OceanMask / CountryMask share one process-lifetime
cache keyed on (kind, source), so each layer is read at most once
per session. Call this to free that memory, or to re-read a local
source file that changed on disk. Mask instances that already
loaded their polygons keep them; the on-disk download cache is
untouched.
Source code in packages/geotoolz-ops/src/geoops/mask/_src/operators.py
close_mask(mask, iterations=1)
¶
Apply binary closing (dilation then erosion) over the spatial axes.
Wraps :func:scipy.ndimage.binary_closing with a 3x3 box structuring
element. Fills pin-holes (pepper) inside otherwise solid True regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
iterations
|
int
|
Number of closing passes. |
1
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The closed boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
combine_masks(masks, op='or')
¶
Combine boolean masks element-wise with an n-ary logical operator.
All masks must have the same shape — they are not broadcast (a
(H, W) mask cannot be combined with a (C, H, W) stack; index
or np.broadcast_to it first). Non-boolean inputs are coerced with
np.asarray(mask, dtype=bool). Use :func:invert_mask for the
unary complement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
Sequence[Bool[ndarray, '*batch h w']]
|
Non-empty sequence of equally shaped boolean masks. |
required |
op
|
str
|
One of |
'or'
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The combined boolean mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
dilate_mask(mask, iterations=1, structure=None)
¶
Dilate a mask over its trailing two (spatial) axes.
Wraps :func:scipy.ndimage.binary_dilation. Leading (batch / band)
axes are processed independently, slice by slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
iterations
|
int
|
Number of dilation passes. |
1
|
structure
|
Bool[ndarray, 'sh sw'] | None
|
2-D structuring element. Defaults to a 3x3 box (8-connectivity). |
None
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The dilated boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
distance_mask(geometry_mask, distance, *, keep='inside', pixel_size=(1.0, 1.0))
¶
Mask pixels by their distance to an already-rasterized geometry.
The zone within distance of the geometry is
:func:buffer_mask of geometry_mask in pixel_size units —
leave the default (1.0, 1.0) for pixel units, or pass
(abs(yres), abs(xres)) for CRS units. The result follows the
package polarity (True = drop).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry_mask
|
Bool[ndarray, 'h w']
|
Boolean |
required |
distance
|
float
|
Maximum distance from the geometry. Pixels on the
geometry itself are at distance |
required |
keep
|
Keep
|
|
'inside'
|
pixel_size
|
tuple[float, float]
|
|
(1.0, 1.0)
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, 'h w']
|
Boolean |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
erode_mask(mask, iterations=1, structure=None)
¶
Erode a mask over its trailing two (spatial) axes.
Wraps :func:scipy.ndimage.binary_erosion; see :func:dilate_mask
for the batching and structuring-element conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
iterations
|
int
|
Number of erosion passes. |
1
|
structure
|
Bool[ndarray, 'sh sw'] | None
|
2-D structuring element. Defaults to a 3x3 box (8-connectivity). |
None
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The eroded boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
invert_mask(mask)
¶
Invert a boolean mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask (non-boolean input is coerced to bool first). |
required |
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The element-wise complement |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
open_mask(mask, iterations=1)
¶
Apply binary opening (erosion then dilation) over the spatial axes.
Wraps :func:scipy.ndimage.binary_opening with a 3x3 box structuring
element. Removes isolated True pixels (salt) while preserving the
extent of large True components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
iterations
|
int
|
Number of opening passes. |
1
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The opened boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
remove_small_holes(mask, max_hole_area_px, *, connectivity=4)
¶
Fill enclosed False components up to max_hole_area_px pixels.
A hole is a False component that does not touch the image border. Each leading (batch / band) slice is processed independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
max_hole_area_px
|
int
|
Maximum hole area, in pixels, to fill. |
required |
connectivity
|
Connectivity
|
|
4
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The filled boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
remove_small_objects(mask, min_area_px, *, connectivity=4)
¶
Remove connected True components smaller than min_area_px pixels.
Delegates to :func:geoops.measure.label_components. Each leading
(batch / band) slice is cleaned independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Bool[ndarray, '*batch h w']
|
Boolean mask, at least 2-D; trailing axes are |
required |
min_area_px
|
int
|
Minimum component area, in pixels, for a component to
be kept. |
required |
connectivity
|
Connectivity
|
|
4
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
The cleaned boolean mask, same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
slope_degrees(dem, pixel_size)
¶
Compute slope in degrees from a single-band DEM.
The gradient is estimated with central differences
(:func:numpy.gradient) scaled by the pixel size; the slope is
degrees(arctan(hypot(dz/dx, dz/dy))). Elevation and pixel size
must be in the same linear units for the angles to be meaningful.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
Float[ndarray, 'h w'] | Float[ndarray, '1 h w']
|
Single-band elevation raster, |
required |
pixel_size
|
tuple[float, float]
|
|
required |
Returns:
| Type | Description |
|---|---|
Float[ndarray, 'h w']
|
Float |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/mask/_src/array.py
slope_mask(dem, pixel_size, *, min_slope_deg=None, max_slope_deg=None, keep='inside')
¶
Mask DEM cells by a slope interval (True = drop).
Slope is computed with :func:slope_degrees; see there for the
pixel-size / unit contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem
|
Float[ndarray, 'h w'] | Float[ndarray, '1 h w']
|
Single-band elevation raster, |
required |
pixel_size
|
tuple[float, float]
|
|
required |
min_slope_deg
|
float | None
|
Inclusive lower slope bound in degrees. |
None
|
max_slope_deg
|
float | None
|
Inclusive upper slope bound in degrees. |
None
|
keep
|
Keep
|
|
'inside'
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, 'h w']
|
Boolean |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both bounds are |