A user ran into this issue, where the user is trying to invert the binary mask using ~/ not_ process. However, this is causing unexpected behaviour, with the values being cast to float32 and falling within the range -1, -2.
https://forum.dataspace.copernicus.eu/t/invert-not-of-a-pixel-mask/5323
Reproducible code:
cube_s2 = connection.load_collection(
"SENTINEL2_L2A",
spatial_extent = pellworm,
temporal_extent = t,
bands = ["B02", "B04", "B08", "SCL"]
)
cube_s2_ndvi = cube_s2.ndvi(nir = "B08", red = "B04")
critereon_1 = cube_s2_ndvi > 0.1
critereon_2 = cube_s2_ndvi < 0.3
combined = (critereon_1 & critereon_2)
inverted = ~combined
cube_s2_ndvi_masked = cube_s2.mask(inverted)
also tried applying not_ through lambda that gives same behaviour as above:
combined = (cube_s2_ndvi > 0.1) & (cube_s2_ndvi < 0.3)
inverted = combined.apply(lambda x: not_(x))
A workaround case could be:
inverted = 1-combined
inverted = combined == 0
where 1 gives the mask in float32 but within the range 0, 1 and the second one gives the mask in unit8 in the range of 0,1 as well.
I assume this is a bug and needs fixing or clarification in the documentation since the current documentation suggests that the not_ process: Inverts a single boolean so that true gets false and false gets true.
A user ran into this issue, where the user is trying to invert the binary mask using ~/ not_ process. However, this is causing unexpected behaviour, with the values being cast to float32 and falling within the range -1, -2.
https://forum.dataspace.copernicus.eu/t/invert-not-of-a-pixel-mask/5323
Reproducible code:
also tried applying
not_through lambda that gives same behaviour as above:A workaround case could be:
inverted = 1-combinedinverted = combined == 0where 1 gives the mask in float32 but within the range 0, 1 and the second one gives the mask in unit8 in the range of 0,1 as well.
I assume this is a bug and needs fixing or clarification in the documentation since the current documentation suggests that the not_ process: Inverts a single boolean so that true gets false and false gets true.