Skip to content

Cloud cover calculation for subset of a Landsat scene #104

Discussion options

You must be logged in to vote

https://stackstac.readthedocs.io/en/latest/examples/gif.html#Mask-cloudy-pixels-using-the-QA-band has a nice example of this.

I think the key sections are to

  1. Load the qa_pixel as unit16 values
qa = stackstac.stack([items[0].to_dict()], assets=["qa_pixel"], dtype="uint16", fill_value=0).isel(band=0)
qa
  1. Make a cloud mask for the values you care about
mask_bitfields = [1, 2, 3, 4]  # dilated cloud, cirrus, cloud, cloud shadow
bitmask = 0
for field in mask_bitfields:
    bitmask |= 1 << field


bad = qa & bitmask  # just look at those 4 bits
mask = bad == 0
  1. Use that mask on your other bands
rgb = stackstac.stack([items[0].to_dict()], assets=["red", "green", "blue"])
good = rgb.where(good)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cullen-molitor
Comment options

Answer selected by cullen-molitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants