Dear APEx devs,
i try to dilate the S2 SCL cloud layer (on cdse backend) using this code:
scl = con.load_collection(collection_id="SENTINEL2_L2A", [...], bands=['SCL'])
s2_cube = con.load_collection(collection_id="SENTINEL2_L2A", [...], bands=[...])
cond_scl_cloud = ((scl == 3) | (scl == 8) | (scl == 9) | (scl == 10))
# dilation
k = 11
kernel = array_create([[1.0] * k for _ in range(k)])
dilated_mask = cond_scl_cloud.apply_kernel(kernel=kernel).multiply(1.0)
dilated_mask = (dilated_mask > 0).multiply(1.0)
# masking
b02_masked = s2_cube.band("B02").mask(dilated_mask)
return b02_masked
Using the original scl mask, the B02 looks like expected:
However, using the dilated mask, there are weird artifacts appearing:
I tried casting in various places (as suggested by another thread), but so far without success Could you help me here? Thanks in advance
bossie
December 17, 2025, 9:03am
2
Could you provide me with the actual spatial/temporal extent that you’re using @paul.karlshoefer ?
Of course:
"spatial_extent": { "west": 11.60, "south": 48.50, "east": 12.0, "north": 48.9, "crs": "EPSG:4326"},
"temporal_extent": ["2023-02-06", "2023-02-20"],
the image shown is the masked B02 Band from the first item in this collection:
b02_masked.reduce_dimension(dimension='t', reducer="first")
bossie
December 17, 2025, 11:58am
4
Works for kernel sizes 3-9 but goes haywire from 11 on. This looks like a bug.
How urgent is this?
bossie
December 17, 2025, 12:28pm
5
Thank you, I commented in the Github issue, because the behaviour is also strange with k < 11. I put the details there.
Our apply_kernel implementation switches to a more efficient FFT-based convolution for kernel sizes > 10. This FFT-based implementation introduces very small errors (<10E-13) but in this case this results in a tile with a lot of tiny values around 0 (both positive and negative).
Your last step of generating the mask is a filter (>0) and this leaves in about 50% of this noise around the 0 (the tiny positive values). If you change the filter to (>0.0001), the problem goes away.