Making QA masks from a Landsat 8 scene with unpackqa

This is a Landsat 8 Collection 2 Level 2 product for Path 14, Row 41, May 3, 2013. It's from the example datasets here: https://www.usgs.gov/core-science-systems/nli/landsat/landsat-sample-products

First we'll make a mask for a single flag, the "Cloud" flag (bit 4). See the flag details here https://sdtaylor.github.io/unpackqa/Landsat.html

Along with clouds you probably also want to mask cloud shadows. It's possible to pull both those masks at once and combine them for a single mask.

Here the cloud_and_shadow_mask array has an added axis at the end, with length 2, representing the 2 masks. Next those 2 axis are summed, so that any value > 0 represents a pixel with either a cloud or cloud shadow

Most QA bands are binary (either 0 or 1) but some have more values. Here the Cloud Confidence QA flag can take the following values.

These can be plotted as well to show the variation in cloud confidence across the scene.

If you need several masks for different purposes it would be useful to be able to reference them directly.
For example, say you want to mask out cloudy pixels, but you also want the water mask to highlight rivers or lakes.
The unpack_to_dict function allows for easier separation to use flags later.