Skip to content

Commit

Permalink
xarray - add nodata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Sep 6, 2024
1 parent 3fb5616 commit 5e1fb61
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_io_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def test_xarray_reader_external_nodata():
data.attrs.update({"valid_min": arr.min(), "valid_max": arr.max()})

data.rio.write_crs("epsg:4326", inplace=True)
assert data.rio.nodata is None

with XarrayReader(data) as dst:
info = dst.info()
assert info.height == 180
Expand All @@ -141,18 +143,21 @@ def test_xarray_reader_external_nodata():
assert img.mask.all()
assert img.data[0, 0, 0] == 0
assert img.data[0, 100, 100]
assert dst.input.rio.nodata is None

# overwrite the nodata value to 0
img = dst.tile(0, 0, 1, nodata=0)
assert not img.mask.all() # not all the mask value are set to 255
assert img.array.mask[0, 0, 0] # the top left pixel should be masked
assert not img.array.mask[0, 100, 100] # pixel 100,100 shouldn't be masked
assert dst.input.rio.nodata is None

# PART
img = dst.part((-160, -80, 160, 80))
assert img.mask.all()
assert img.data[0, 0, 0] == 0
assert img.data[0, 100, 100]
assert dst.input.rio.nodata is None

# overwrite the nodata value to 0
img = dst.part((-160, -80, 160, 80), nodata=0)
Expand All @@ -163,11 +168,13 @@ def test_xarray_reader_external_nodata():
# POINT
pt = dst.point(-179, 89)
assert pt.mask[0] == 255
assert dst.input.rio.nodata is None

# overwrite the nodata value to 0
pt = dst.point(-179, 89, nodata=0)
assert pt.count == 1
assert pt.mask[0] == 0
assert dst.input.rio.nodata is None

feat = {
"type": "Feature",
Expand All @@ -191,12 +198,14 @@ def test_xarray_reader_external_nodata():
assert img.mask.all()
assert img.data[0, 0, 0] == 0
assert img.data[0, 50, 100]
assert dst.input.rio.nodata is None

# overwrite the nodata value to 0
img = dst.feature(feat, nodata=0)
assert not img.mask.all() # not all the mask value are set to 255
assert img.array.mask[0, 0, 0] # the top left pixel should be masked
assert not img.array.mask[0, 50, 100] # pixel 50,100 shouldn't be masked
assert dst.input.rio.nodata is None


def test_xarray_reader_internal_nodata():
Expand All @@ -219,6 +228,7 @@ def test_xarray_reader_internal_nodata():
)

data.rio.write_crs("epsg:4326", inplace=True)
assert data.rio.nodata is not None

with XarrayReader(data) as dst:
# TILE
Expand Down

0 comments on commit 5e1fb61

Please sign in to comment.