Skip to content

Commit b60cc3a

Browse files
authored
swap combine kw to collapse (#424)
* swap combine kw to collapse * use collapse in tests
1 parent 0bb132e commit b60cc3a

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/methods/mask.jl

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ const CRS_KEYWORD = """
1515
- `crs`: a `crs` which will be attached to the resulting raster when `to` not passed
1616
or is an `Extent`. Otherwise the crs from `to` is used.
1717
"""
18-
const COMBINE_KEYWORD = """
19-
- `combine`: combine all geometries in tables/iterables into a single layer, or return
20-
a `Raster` with a `:geometry` dimension where each slice is the rasterisation
21-
of a single geometry. This can be useful for reductions. Note the returned object
22-
may be quite large when `combine=false`. `true` by default.
23-
"""
2418

2519
const SHAPE_KEYWORDS = """
2620
- `shape`: Force `data` to be treated as `:polygon`, `:line` or `:point` geometries.
@@ -36,7 +30,6 @@ $RES_KEYWORD
3630
$SIZE_KEYWORD
3731
$CRS_KEYWORD
3832
$SHAPE_KEYWORDS
39-
$COMBINE_KEYWORD
4033
"""
4134

4235

@@ -260,7 +253,7 @@ And specifically for `shape=:polygon`:
260253
261254
For tabular data, feature collections and other iterables
262255
263-
- `combine`: if `true`, combine all objects into a single mask. Otherwise
256+
- `collapse`: if `true`, collapse all geometry masks into a single mask. Otherwise
264257
return a Raster with an additional `geometry` dimension, so that each slice
265258
along this axis is the mask of the `geometry` opbject of each row of the
266259
table, feature in the feature collection, or just each geometry in the iterable.
@@ -327,7 +320,7 @@ end
327320

328321
"""
329322
missingmask(obj::Raster; kw...)
330-
missingmask(obj; [to, res, size, combine])
323+
missingmask(obj; [to, res, size, collapse])
331324
332325
Create a mask array of `missing` and `true` values, from another `Raster`.
333326
`AbstractRasterStack` or `AbstractRasterSeries` are also accepted, but a mask

src/methods/rasterize.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function _rasterize_iterable!(
359359
kw...
360360
)
361361
# We dont need to iterate the fill, so just mask
362-
mask = boolmask(geoms; to=x1, combine=true, allocs=thread_allocs, metadata=metadata(x1), kw...)
362+
mask = boolmask(geoms; to=x1, collapse=true, allocs=thread_allocs, metadata=metadata(x1), kw...)
363363
# And broadcast the fill
364364
broadcast_dims!(x1, x1, mask) do v, m
365365
m ? fill_itr.xs : v
@@ -372,7 +372,7 @@ function _rasterize_iterable!(
372372
kw...
373373
)
374374
# We dont need to iterate the fill, so just mask
375-
mask = boolmask(geoms; to=x1, combine=true, allocs=thread_allocs, metadata=metadata(x1), kw...)
375+
mask = boolmask(geoms; to=x1, collapse=true, allocs=thread_allocs, metadata=metadata(x1), kw...)
376376
foreach(x1, fill_itr) do A, f
377377
# And broadcast the fill
378378
broadcast_dims!(A, A, mask) do v, m
@@ -456,7 +456,7 @@ function _reduce_fill!(f, st::AbstractRasterStack, geoms, fill_itr::NamedTuple;
456456
# Define mask dimensions, the same size as the spatial dims of x
457457
spatialdims = commondims(st, DEFAULT_POINT_ORDER)
458458
# Mask geoms as separate bool layers
459-
masks = boolmask(geoms; to=st, combine=false, metadata=metadata(st), kw...)
459+
masks = boolmask(geoms; to=st, collapse=false, metadata=metadata(st), kw...)
460460
# Use a generator over the array axis in case the iterator has no length
461461
geom_axis = axes(masks, Dim{:geometry}())
462462
fill = map(itr -> [v for (_, v) in zip(geom_axis, itr)], fill_itr)
@@ -467,7 +467,7 @@ function _reduce_fill!(f, A::AbstractRaster, geoms, fill_itr; progress=true, kw.
467467
# Define mask dimensions, the same size as the spatial dims of x
468468
spatialdims = commondims(A, DEFAULT_POINT_ORDER)
469469
# Mask geoms as separate bool layers
470-
masks = boolmask(geoms; to=A, combine=false, metadata=metadata(A), kw...)
470+
masks = boolmask(geoms; to=A, collapse=false, metadata=metadata(A), kw...)
471471
# Use a generator over the array axis in case the iterator has no length
472472
geom_axis = parent(axes(masks, Dim{:geometry}()))
473473
fill = [val for (i, val) in zip(geom_axis, fill_itr)]

src/polygon_ops.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ function _burn_geometry!(B::AbstractRaster, ::GI.AbstractFeatureCollectionTrait,
175175
end
176176
# Where geoms is an iterator
177177
function _burn_geometry!(B::AbstractRaster, trait::Nothing, geoms;
178-
combine::Union{Bool,Nothing}=nothing, lock=SectorLocks(), verbose=true, progress=true, kw...
178+
collapse::Union{Bool,Nothing}=nothing, lock=SectorLocks(), verbose=true, progress=true, kw...
179179
)::Bool
180180
thread_allocs = _burning_allocs(B)
181181
range = _geomindices(geoms)
182182
checklock = Threads.SpinLock()
183183
burnchecks = _alloc_burnchecks(range)
184184
p = progress ? _progress(length(range)) : nothing
185-
if isnothing(combine) || combine
185+
if isnothing(collapse) || collapse
186186
Threads.@threads for i in range
187187
geom = _getgeom(geoms, i)
188188
ismissing(geom) && continue
@@ -746,8 +746,8 @@ function _init_bools(to::Nothing, T::Type, data; kw...)
746746
dims = _extent2dims(ext; kw...)
747747
return _init_bools(to, dims, T, data; kw...)
748748
end
749-
function _init_bools(to, dims::DimTuple, T::Type, data; combine::Union{Bool,Nothing}=nothing, kw...)
750-
if isnothing(data) || isnothing(combine) || combine
749+
function _init_bools(to, dims::DimTuple, T::Type, data; collapse::Union{Bool,Nothing}=nothing, kw...)
750+
if isnothing(data) || isnothing(collapse) || collapse
751751
_alloc_bools(to, dims, T; kw...)
752752
else
753753
n = if Base.IteratorSize(data) isa Base.HasShape

test/methods.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ end
7373
@test x == trues(X(Projected(-20:1.0:-1.0; crs=nothing)), Y(Projected(10.0:1.0:29.0; crs=nothing)))
7474
@test parent(x) isa BitArray{2}
7575
# With a :geometry axis
76-
x = boolmask([polygon, polygon]; combine=false, res=1.0)
76+
x = boolmask([polygon, polygon]; collapse=false, res=1.0)
7777
@test eltype(x) == Bool
7878
@test size(x) == (20, 20, 2)
7979
@test sum(x) == 800
8080
@test parent(x) isa BitArray{3}
81-
x = boolmask([polygon, polygon]; combine=true, res=1.0)
81+
x = boolmask([polygon, polygon]; collapse=true, res=1.0)
8282
@test size(x) == (20, 20)
8383
@test sum(x) == 400
8484
@test parent(x) isa BitArray{2}
@@ -90,12 +90,12 @@ end
9090
@test all(missingmask(gaNaN) .=== [missing true; true missing])
9191
@test dims(missingmask(ga)) == (X(NoLookup(Base.OneTo(2))), Y(NoLookup(Base.OneTo(2))))
9292
@test missingmask(polygon; res=1.0) == fill!(Raster{Union{Missing,Bool}}(undef, X(Projected(-20:1.0:-1.0; crs=nothing)), Y(Projected(10.0:1.0:29.0; crs=nothing))), true)
93-
x = missingmask([polygon, polygon]; combine=false, res=1.0)
93+
x = missingmask([polygon, polygon]; collapse=false, res=1.0)
9494
@test eltype(x) == Union{Bool,Missing}
9595
@test size(x) == (20, 20, 2)
9696
@test sum(x) == 800
9797
@test parent(x) isa Array{Union{Missing,Bool},3}
98-
x = missingmask([polygon, polygon]; combine=true, res=1.0)
98+
x = missingmask([polygon, polygon]; collapse=true, res=1.0)
9999
@test size(x) == (20, 20)
100100
@test sum(x) == 400
101101
end

0 commit comments

Comments
 (0)