Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not mix nodata mask #672

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading