Skip to content

Commit e7bf17d

Browse files
committed
Force nodata in stack
1 parent 14261f5 commit e7bf17d

3 files changed

Lines changed: 5 additions & 13 deletions

File tree

ci/on_push/test_others.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def test_custom_resamplings():
495495

496496
@s3_env
497497
def test_write(tmp_path):
498-
"""Test custom resamplings"""
498+
"""Test write with different drivers"""
499499
# Get paths
500500
prod_path = opt_path().joinpath("LT05_L1TP_200030_20111110_20200820_02_T1")
501501
window_path = others_path().joinpath(
@@ -520,7 +520,6 @@ def test_write(tmp_path):
520520
assert_is_cog(cog)
521521

522522
# Don't set it with os.environ otherwise it'll break all the test suite!
523-
524523
with tempenv.TemporaryEnvironment({"EOREADER_DEFAULT_DRIVER": "GTiff"}):
525524
gtiff_env = tmp_path / "gtiff_e.tif"
526525
prod.stack(RED, window=window_path, pixel_size=60, stack_path=gtiff_env)
@@ -536,8 +535,6 @@ def test_write(tmp_path):
536535
driver="Zarr",
537536
compress="NONE",
538537
)
539-
with pytest.raises(AssertionError):
540-
assert_is_cog(gtiff_env)
541538

542539
# Just test to read the zarr array
543540
np.testing.assert_array_equal(zstack.data, utils.read(zarr).data)

eoreader/products/product.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,8 +1959,6 @@ def _collocate_bands(bands: dict, reference: xr.DataArray = None) -> dict:
19591959

19601960
return bands
19611961

1962-
# pylint: disable=R0913
1963-
# Too many arguments (6/5)
19641962
def stack(
19651963
self,
19661964
bands: list,
@@ -1971,7 +1969,7 @@ def stack(
19711969
**kwargs,
19721970
) -> xr.DataArray:
19731971
"""
1974-
Stack bands and index of a products.
1972+
Stack bands and index of a product.
19751973
19761974
.. code-block:: python
19771975

eoreader/utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,9 @@ def stack(band_xds: xr.Dataset, **kwargs) -> (xr.DataArray, type):
546546
.transpose("bands", "y", "x")
547547
)
548548

549-
if dtype == np.float32:
550-
# Set nodata if needed (NaN values are already set)
551-
if stack.rio.encoded_nodata != nodata:
552-
stack = stack.astype(dtype).rio.write_nodata(
553-
nodata, encoded=True, inplace=True
554-
)
549+
# Set nodata if needed (NaN values are already set)
550+
if dtype == np.float32 and stack.rio.encoded_nodata != nodata:
551+
stack = rasters.set_nodata(stack.astype(dtype), nodata)
555552

556553
return stack, dtype
557554

0 commit comments

Comments
 (0)