Cloud mask provides smaller spatial extent

Hey there,
The below workflow shows applying the cloud mask. However, the final output shows the smaller spatial extent than we have at the beginning. Could you please explain why this is happening?

start_date      = '2022-01-01'
end_date        = '2022-01-31'
bands           = ['B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09',  'B11', 'B12', 'CLP', 'SCL' , 'sunAzimuthAngles', 'sunZenithAngles'] 
spatial_extent  = {'west': -74.06810760, 'east': -73.90597343, 'south': 4.689864510, 'north': 4.724080996, 'crs': 'epsg:4326'}  #colombia

s2_cube = connection.load_collection(
    'SENTINEL2_L2A_SENTINELHUB',
    spatial_extent = spatial_extent,
    temporal_extent = [start_date, end_date],
    bands = bands)

s2_cube.download("s2_cube.nc")

Output:

clp = s2_cube.band("CLP")
clp = clp.resample_spatial(resolution=20, method = "bicubic")
mask_clp = (clp / 255) > 0.3  # 160m resolution s2cloudless so it does not have to use
mask_clp.download("s2_CLP.nc")

Output:

Then the s2 data are masked:

s2_cube_clp = s2_cube.mask(mask_clp) 
s2_cube_clp.download("s2_masked_CLP.nc")

Ouput, here we can see the smaller spatial extent:

Hi Andrea,

Your code works fine if you remove the resample_spatial.
In this case, resample_spatial is not necessary because the entire cube is already resampled to a 10m resolution, so I do get a complete result when running your code without it:

start_date      = '2022-01-01'
end_date        = '2022-01-31'
bands           = ['B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09',  'B11', 'B12', 'CLP', 'SCL' , 'sunAzimuthAngles', 'sunZenithAngles'] 
spatial_extent  = {'west': -74.06810760, 'east': -73.90597343, 'south': 4.689864510, 'north': 4.724080996, 'crs': 'epsg:4326'}  #colombia

s2_cube = connection.load_collection(
    'SENTINEL2_L2A_SENTINELHUB',
    spatial_extent = spatial_extent,
    temporal_extent = [start_date, end_date],
    bands = bands)

clp = s2_cube.band("CLP")
mask_clp = (clp / 255) > 0.3 

s2_cube_clp = s2_cube.mask(mask_clp) 
s2_cube_clp.download("s2_masked_CLP.nc")

1 Like

Thank @bart.driessen for supporting!
It works fine without the resample spatial process. Do you know why that process causes a smaller spatial extent?

Hi Andrea,
the spatial extent is smaller because you resampled the mask from 10m to 20m.
Ideally, the backend should simply not have allowed this combination and thrown an error to inform you that this combination of datacubes was not possible.

best regards,
Jeroen

Thanks Jeroen!