mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
tighten up arg and kwargs handling
This commit is contained in:
parent
90721683d5
commit
b9b4543cfe
@ -1122,14 +1122,14 @@ cdef class RasterReader(_base.DatasetReader):
|
||||
return out
|
||||
|
||||
|
||||
def dataset_mask(self, **kwargs):
|
||||
def dataset_mask(self, *args, window=None, boundless=False):
|
||||
"""Calculate the dataset's 2D mask. Derived from the individual band masks
|
||||
provided by read_masks().
|
||||
|
||||
Parameters
|
||||
----------
|
||||
All kwargs except indexes are passed to read_masks()
|
||||
See read_masks for details
|
||||
position args ignored
|
||||
window and boundless are passed directly to read_masks()
|
||||
|
||||
Returns
|
||||
-------
|
||||
@ -1150,7 +1150,10 @@ cdef class RasterReader(_base.DatasetReader):
|
||||
in that it applies per-dataset, not per-band
|
||||
(see https://trac.osgeo.org/gdal/wiki/rfc15_nodatabitmask)
|
||||
"""
|
||||
del kwargs['indexes'] # this method determines indexes
|
||||
del args
|
||||
kwargs = {
|
||||
'window': window,
|
||||
'boundless': boundless}
|
||||
|
||||
# GDAL found dataset-wide alpha band or mask
|
||||
# All band masks are equal so we can return the first
|
||||
|
||||
@ -42,6 +42,10 @@ alldata = np.array([[1, 1, 1],
|
||||
[1, 1, 1],
|
||||
[1, 1, 1]]).astype('uint8') * 255
|
||||
|
||||
# boundless window ((1, 4, (1, 4))
|
||||
alp_shift_lr = np.array([[1, 1, 0],
|
||||
[0, 1, 0],
|
||||
[0, 0, 0]]).astype('uint8') * 255
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def tiffs(tmpdir):
|
||||
@ -159,3 +163,21 @@ def test_rgba_msk(tiffs):
|
||||
with rasterio.open(str(tiffs.join('rgba_msk.tif'))) as src:
|
||||
# mask takes precendent over alpha
|
||||
assert np.array_equal(src.dataset_mask(), msk)
|
||||
|
||||
def test_args(tiffs):
|
||||
with rasterio.open(str(tiffs.join('rgb_ndv.tif'))) as src:
|
||||
res = src.dataset_mask()
|
||||
assert np.array_equal(res , alp)
|
||||
# positional args ignored
|
||||
other = src.dataset_mask('FOO')
|
||||
assert np.array_equal(res, other)
|
||||
|
||||
def test_kwargs(tiffs):
|
||||
with rasterio.open(str(tiffs.join('rgb_ndv.tif'))) as src:
|
||||
# window and boundless are passes along
|
||||
other = src.dataset_mask(window=((1, 4), (1, 4)), boundless=True)
|
||||
assert np.array_equal(alp_shift_lr, other)
|
||||
|
||||
# band indexes are not supported
|
||||
with pytest.raises(TypeError):
|
||||
src.dataset_mask(indexes=1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user