Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgleith committed Nov 20, 2024
1 parent e90c970 commit c155126
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/test_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
# Top left is cloud, top right is cloud shadow
# Bottom left is both cloud and cloud shadow, bottom right is neither
xx_bits = DataArray(
[[0b00010000, 0b00001000], [0b00011000, 0b00000000]], dims=("y", "x"), attrs={"nodata": 0}
[[0b00010000, 0b00001000], [0b00011000, 0b00000000]],
dims=("y", "x"),
attrs={"nodata": 0},
)

# Set up a 2x2 8 bit integer DataArray with some
# values set to 3 (shadow), 9 (high confidence cloud).
# Test some values, so 3 is cloud, 9 is cloud shadow
xx_values = DataArray([[3, 9], [3, 0]], dims=("y", "x"), attrs={"nodata": 0})

# Array with some zeros
# Array with at least one zero to test nodata
xx_with_nodata = DataArray([[0, 1], [2, 3]], dims=("y", "x"), attrs={"nodata": 0})


Expand Down Expand Up @@ -73,19 +74,27 @@ def test_mask_invalid_data():

# Test landsat masking
def test_mask_landsat():
xx = Dataset({"pixel_qa": xx_bits, "red": scale_and_offset(xx_with_nodata, offset=20000)})
xx = Dataset(
{"pixel_qa": xx_bits, "red": scale_and_offset(xx_with_nodata, offset=20000)}
)
print(xx)

xx = xx.odc.mask_ls()

assert xx["red"].equals(DataArray([[np.nan, np.nan], [np.nan, 0.3500825]], dims=("y", "x")))
assert xx["red"].equals(
DataArray([[np.nan, np.nan], [np.nan, 0.3500825]], dims=("y", "x"))
)


def test_mask_sentinel2():
xx = Dataset({"scl": xx_values, "red": scale_and_offset(xx_with_nodata, offset=8000)})
xx = Dataset(
{"scl": xx_values, "red": scale_and_offset(xx_with_nodata, offset=8000)}
)

xx = xx.odc.mask_s2()

assert xx["red"].equals(DataArray([[np.nan, np.nan], [np.nan, 0.7003]], dims=("y", "x")))
assert xx["red"].equals(
DataArray([[np.nan, np.nan], [np.nan, 0.7003]], dims=("y", "x"))
)

assert xx.red.odc.nodata is not None

0 comments on commit c155126

Please sign in to comment.