Skip to content

Instantly share code, notes, and snippets.

@cbur24
Last active March 2, 2021 02:48
Show Gist options
  • Save cbur24/edebd3e392d53b8e9e76640ebad9ec49 to your computer and use it in GitHub Desktop.
Save cbur24/edebd3e392d53b8e9e76640ebad9ec49 to your computer and use it in GitHub Desktop.
Improve the Sentinel-2 cloud mask using morpholigical operations
import odc.algo
#Extract boolean mask
mask = odc.algo.enum_to_bool(ds.SCL,
categories=['cloud shadows', 'cloud medium probability',
'cloud high probability', 'thin cirrus'])
# Close mask to remove small holes in cloud, open mask to
# remove narrow false positive cloud, then dilate
mask = odc.algo.binary_closing(mask, 2)
mask_cleaned = odc.algo.mask_cleanup(mask, r=(2, 10))
# Add new mask as nodata pixels
ds_clean = odc.algo.erase_bad(ds, mask_cleaned)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment