Skip to content

Commit dae10e4

Browse files
authored
Remove RasterMask and PointCloudMask classes in favor of boolean dtype in parent class (#737)
1 parent 9c8fec7 commit dae10e4

34 files changed

+468
-887
lines changed

doc/source/api.md

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ documentation.
7272
.. autosummary::
7373
:toctree: gen_modules/
7474
75+
Raster.is_mask
7576
Raster.count_on_disk
7677
Raster.bands_on_disk
7778
Raster.is_loaded
@@ -198,7 +199,7 @@ documentation.
198199

199200
And reverse operations.
200201

201-
### Logical operator casting to Mask
202+
### Logical operators casting to mask (boolean raster)
202203

203204
```{eval-rst}
204205
.. autosummary::
@@ -222,34 +223,6 @@ And reverse operations.
222223
Raster.__array_function__
223224
```
224225

225-
## Raster mask
226-
227-
```{eval-rst}
228-
.. minigallery:: geoutils.RasterMask
229-
:add-heading:
230-
```
231-
232-
### Opening a file
233-
234-
```{eval-rst}
235-
.. autosummary::
236-
:toctree: gen_modules/
237-
238-
RasterMask
239-
```
240-
241-
### Overloaded Raster methods
242-
243-
```{eval-rst}
244-
.. autosummary::
245-
:toctree: gen_modules/
246-
247-
RasterMask.crop
248-
RasterMask.reproject
249-
RasterMask.polygonize
250-
RasterMask.proximity
251-
```
252-
253226
## Multiple rasters
254227

255228
```{eval-rst}
@@ -655,20 +628,3 @@ documentation](https://shapely.readthedocs.io/en/stable/properties.html).
655628
PointCloud.pointcloud_equal
656629
PointCloud.georeferenced_coords_equal
657630
```
658-
659-
660-
## Point cloud mask
661-
662-
```{eval-rst}
663-
.. minigallery:: geoutils.PointCloudMask
664-
:add-heading:
665-
```
666-
667-
### Opening a file
668-
669-
```{eval-rst}
670-
.. autosummary::
671-
:toctree: gen_modules/
672-
673-
PointCloudMask
674-
```

doc/source/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@
124124
# To avoid long path names in inheritance diagrams
125125
inheritance_alias = {
126126
"geoutils.raster.raster.Raster": "geoutils.Raster",
127-
"geoutils.raster.raster.RasterMask": "geoutils.RasterMask",
128127
"geoutils.pointcloud.pointcloud.PointCloud": "geoutils.PointCloud",
129-
"geoutils.pointcloud.pointcloud.PointCloudMask": "geoutils.PointCloudMask",
130128
"geoutils.vector.Vector": "geoutils.Vector",
131129
"xdem.dem.DEM": "xdem.DEM",
132130
}

doc/source/core_array_funcs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ np.modf(rast)
7575
```
7676

7777
Similar to with Python operators, NumPy's [logical comparison functions](https://numpy.org/doc/stable/reference/ufuncs.html#comparison-functions) cast
78-
{class}`Rasters<geoutils.Raster>` to a {class}`~geoutils.RasterMask`.
78+
{class}`Rasters<geoutils.Raster>` to a boolean {class}`~geoutils.Raster`, a raster mask.
7979

8080
```{code-cell} ipython3
8181
# Universal function with a single input and two outputs

doc/source/core_inheritance.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ implemented in GeoUtils.
2222

2323
Current {class}`~geoutils.Raster` inheritance extends into other packages, such as [xDEM](https://xdem.readthedocs.io/)
2424
for analyzing digital elevation models.
25-
Within GeoUtils, inheritance extends only to {class}`~geoutils.RasterMask` that implements overloaded methods specific to binary raster masks,
26-
as shown in the diagram below.
2725

2826
```{eval-rst}
2927
.. inheritance-diagram:: geoutils.raster.raster

doc/source/core_match_ref.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ at modifying the georeferencing of {class}`Rasters<geoutils.Raster>` or {class}`
6262

6363
The {func}`~geoutils.Vector.rasterize` operation to convert from {class}`~geoutils.Vector` to {class}`~geoutils.Raster` accepts a {class}`~geoutils.Raster` to define the
6464
grid and georeferencing. The behaviour is similar for {func}`~geoutils.Vector.create_mask`, that directly relies on {func}`~geoutils.Vector.rasterize` to
65-
rasterize directly into a boolean {class}`~geoutils.RasterMask`.
65+
rasterize directly into a boolean {class}`~geoutils.Raster`.
6666

6767
In addition, the {func}`~geoutils.Vector.proximity` operation to compute proximity distances from the vector also relies on a
6868
{func}`~geoutils.Vector.rasterize`, and therefore also accepts a {class}`~geoutils.Raster` as reference.

doc/source/core_py_ops.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ If an unmasked {class}`~numpy.ndarray` is passed, it will internally be cast int
6969
{class}`~geoutils.Raster.nodata` values. Additionally, the {attr}`~geoutils.Raster.dtype` are also reconciled as they would for {class}`~numpy.ndarray`,
7070
following [standard NumPy coercion rules](https://numpy.org/doc/stable/reference/generated/numpy.find_common_type.html).
7171

72-
## Logical comparisons cast to {class}`~geoutils.RasterMask`
72+
## Logical comparisons cast to a raster mask
7373

7474
Logical comparison operators ({func}`==<operator.eq>`, {func}` != <operator.ne>`, {func}`>=<operator.ge>`, {func}`><operator.gt>`, {func}`<=<operator.le>`,
7575
{func}`<<operator.lt>`) can be used on a {class}`~geoutils.Raster`, also in combination with any other {class}`~geoutils.Raster`, {class}`~numpy.ndarray` or
7676
number.
7777

78-
Those operation always return a {class}`~geoutils.RasterMask`, a subclass of {class}`~geoutils.Raster` with a boolean {class}`~numpy.ma.MaskedArray`
79-
as {class}`~geoutils.Raster.data`.
78+
Those operation always return a raster mask i.e. a {class}`~geoutils.Raster` with a boolean {class}`~numpy.ma.MaskedArray` as {class}`~geoutils.Raster.data`.
8079

8180
```{code-cell} ipython3
8281
# Logical comparison with a number
@@ -85,14 +84,14 @@ mask
8584
```
8685

8786
```{note}
88-
A {class}`~geoutils.RasterMask`'s {attr}`~geoutils.Raster.data` remains a {class}`~numpy.ma.MaskedArray`. Therefore, it still maps invalid values through its
89-
{attr}`~numpy.ma.MaskedArray.mask`, but has no associated {attr}`~geoutils.Raster.nodata`.
87+
A boolean {class}`~geoutils.Raster`'s {attr}`~geoutils.Raster.data` remains a {class}`~numpy.ma.MaskedArray`. Therefore, it still maps invalid values
88+
through its {attr}`~numpy.ma.MaskedArray.mask`, but has no associated {attr}`~geoutils.Raster.nodata`.
9089
```
9190

92-
## Logical bitwise operations on {class}`~geoutils.RasterMask`
91+
## Logical bitwise operations on raster masks
9392

9493
Logical bitwise operators ({func}`~ <operator.invert>`, {func}`& <operator.and_>`, {func}`| <operator.or_>`, {func}`^ <operator.xor>`) can be used to
95-
combine a {class}`~geoutils.RasterMask` with another {class}`~geoutils.RasterMask`, and always output a {class}`~geoutils.RasterMask`.
94+
combine a boolean {class}`~geoutils.Raster` with another boolean {class}`~geoutils.Raster`, and always output a boolean {class}`~geoutils.Raster`.
9695

9796
```{code-cell} ipython3
9897
# Logical bitwise operation between masks
@@ -102,17 +101,18 @@ mask
102101

103102
(py-ops-indexing)=
104103

105-
## Indexing a {class}`~geoutils.Raster` with a {class}`~geoutils.RasterMask`
104+
## Indexing a {class}`~geoutils.Raster` with a raster mask
106105

107106
Finally, indexing and index assignment operations ({func}`[] <operator.getitem>`, {func}`[]= <operator.setitem>`) are both supported by
108107
{class}`Rasters<geoutils.Raster>`.
109108

110-
For indexing, they can be passed either a {class}`~geoutils.RasterMask` with the same georeferencing, or a boolean {class}`~numpy.ndarray` of the same shape.
109+
For indexing, they can be passed either a boolean {class}`~geoutils.Raster` with the same georeferencing, or a boolean {class}`~numpy.ndarray` of the same
110+
shape.
111111
For assignment, either a {class}`~geoutils.Raster` with the same georeferencing, or any {class}`~numpy.ndarray` of the same shape is expected.
112112

113-
When indexing, a flattened {class}`~numpy.ma.MaskedArray` is returned with the indexed values of the {class}`~geoutils.RasterMask` **excluding those masked in its
114-
{class}`~geoutils.Raster.data`'s {class}`~numpy.ma.MaskedArray` (for instance, nodata values present during a previous logical comparison)**. To bypass this
115-
behaviour, simply index without the mask using {attr}`Mask.data.data`.
113+
When indexing, a flattened {class}`~numpy.ma.MaskedArray` is returned with the indexed values of the boolean {class}`~geoutils.Raster` **excluding those masked
114+
in its {class}`~geoutils.Raster.data`'s {class}`~numpy.ma.MaskedArray` (for instance, nodata values present during a previous logical comparison)**. To bypass this
115+
behaviour, simply index without the mask using {attr}`Raster.data.data`.
116116

117117
```{code-cell} ipython3
118118
# Indexing the raster with the previous mask

doc/source/feature_overview.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,26 @@ import numpy as np
195195
rast = (rast - np.min(rast)) / (np.max(rast) - np.min(rast))
196196
```
197197

198-
## Casting to {class}`~geoutils.RasterMask`, indexing and overload
198+
## Casting to raster mask, indexing and overload
199199

200200
All {class}`~geoutils.Raster` objects also support Python logical comparison operators ({func}`==<operator.eq>`, {func}` != <operator.ne>`, {func}`>=<operator.ge>`, {func}`><operator.gt>`, {func}`<=<operator.le>`,
201-
{func}`<<operator.lt>`), or more complex NumPy logical functions. Those operations automatically casts them into a {class}`~geoutils.RasterMask`, a boolean raster that inherits all methods from {class}`~geoutils.Raster`.
201+
{func}`<<operator.lt>`), or more complex NumPy logical functions. Those operations automatically casts them into a raster mask, i.e. a boolean
202+
{class}`~geoutils.Raster`.
202203

203204
```{code-cell} ipython3
204205
# Get mask of an AOI: infrared index above 0.6, at least 200 m from glaciers
205206
mask_aoi = np.logical_and(rast > 0.6, rast_proximity_to_vec > 200)
206207
```
207208

208-
Masks can then be used for indexing a {class}`~geoutils.Raster`, which returns a {class}`~numpy.ma.MaskedArray` of indexed values.
209+
Raster masks can then be used for indexing a {class}`~geoutils.Raster`, which returns a {class}`~numpy.ma.MaskedArray` of indexed values.
209210

210211
```{code-cell} ipython3
211212
# Index raster with mask to extract a 1-D array
212213
values_aoi = rast[mask_aoi]
213214
```
214215

215-
Masks also have simplified, overloaded {class}`~geoutils.Raster` methods due to their boolean {class}`dtype<numpy.dtype>`. Using {func}`~geoutils.Raster.polygonize` with a
216-
{class}`~geoutils.RasterMask` is straightforward, for instance, to retrieve a {class}`~geoutils.Vector` of the area-of-interest:
216+
Raster masks also have simplified {class}`~geoutils.Raster` methods due to their boolean {class}`dtype<numpy.dtype>` rendering many arguments implicit.
217+
For instance, using {func}`~geoutils.Raster.polygonize` with a raster mask is straightforward, to retrieve a {class}`~geoutils.Vector` of the area-of-interest:
217218

218219
```{code-cell} ipython3
219220
# Polygonize areas where mask is True

doc/source/mask_class.md

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)