Skip to content

Commit

Permalink
do not mix nodata mask (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Jan 22, 2024
1 parent 21c4dce commit aa9ad18
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 6.3.1 (2024-01-22)

* When overriding **nodata**, do not mix mask and only use the provided nodata value

# 6.3.0 (2024-01-16)

* do not use `warpedVRT` when overwriting the dataset nodata value
Expand Down
2 changes: 1 addition & 1 deletion rio_tiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def read(

# if data has Nodata then we simply make sure the mask == the nodata
if nodata is not None:
data.mask |= data == nodata
data.mask = data.data == nodata

stats = []
for ix in indexes:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
COG = os.path.join(os.path.dirname(__file__), "fixtures", "cog.tif")
COG_SCALE = os.path.join(os.path.dirname(__file__), "fixtures", "cog_scale.tif")
COG_CMAP = os.path.join(os.path.dirname(__file__), "fixtures", "cog_cmap.tif")
COG_NODATA = os.path.join(os.path.dirname(__file__), "fixtures", "cog_nodata.tif")


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -836,3 +837,14 @@ def test_part_align_transform(bounds, crs):
# with the bounds greater than UL
assert img.transform.c < bounds[0]
assert img.transform.f > bounds[3]


def test_nodata_orverride():
"""Make sure notata override."""
with rasterio.open(COG_NODATA) as src_dst:
prev = reader.read(src_dst, max_size=100)
assert prev.mask[0, 0] == 0

prev = reader.read(src_dst, max_size=100, nodata=2720)
assert prev.mask[0, 0] == 255
assert not numpy.all(prev.mask)

0 comments on commit aa9ad18

Please sign in to comment.