Using the Cloud and QA Masks
Here, we'll explore Hydrosat's cloud and quality assurance masks to better understand the information encoded within them.
1. Accessing Hydrosat's STAC API
1.1 Import dependencies
import json
import pystac
from pystac_client import Client
import base641.2 Connect to the API with your account credentials
To run the next cell, you should have set up a creds.json file containing your username and password in the same directory as this notebook.
with open('creds.json') as f:
creds = json.loads(f.read())
userpass = f"{creds['username']}:{creds['password']}"
b64 = base64.b64encode(userpass.encode()).decode()
headers = {'Authorization':'Basic ' + b64}
cat_url = 'https://stac.hydrosat.com/'
catalog = Client.open(cat_url, headers)Let's search the catalog for data in the vz-l2 collection near Santa Barbara, CA from mid-2025.
2. Explore the cloud mask asset
2.1 Access the cloud mask COG
2.2 Visualize the cloud mask
Here, we'll define and use a function to plot the mask with a discrete colormap.
Let's plot the cloud mask for the item of interest.

The cloud mask includes bit-packed values, so we'll need to unpack them to understand what they represent.
We'll explore this in the next section.
2.3 Interpret the cloud mask pixel values
First, we'll need to write a function to convert a given binary value to a 16-bit binary string.
Next, we'll create a dict with information about each bit's meaning. This information is available on the FAQs page and in our product guide.
Finally, we'll display a lookup table for each unique pixel value from the cloud mask.
This function takes the cloud mask and bit definitions as input and outputs a table of pixel values mapped to their meanings.
0.0
0000000000000000
No
No
No
No
1.0
0000000000000001
Yes
No
No
No
2.0
0000000000000010
No
Yes
No
No
There we go! Each pixel value represents a specific set of conditions. For example, a value of 2 indicates cloudy conditions; a value of 1 represents no data; and a value of 0 represents clear conditions.
Access the QA mask asset
The QA mask provides information about radiometric saturation in the VNIR and LWIR bands. Similar to the cloud mask, it contains bit-packed values.
First, we'll use rioxarray to access the QA mask data.
The following dict contains information about each bit's meaning.
Let's plot the QA mask to understand the variability in pixel values.

Interpret the QA mask pixel values
Now, we'll use the same functions we wrote previously to interpret the pixel values from the QA mask.
0
0000000000000000
No
No
No
No
No
No
No
No
No
1
0000000000000001
Yes
No
No
No
No
No
No
No
No
2
0000000000000010
No
Yes
No
No
No
No
No
No
No
3
0000000000000011
Yes
Yes
No
No
No
No
No
No
No
4
0000000000000100
No
No
Yes
No
No
No
No
No
No
...
...
...
...
...
...
...
...
...
...
...
67
0000000001000011
Yes
Yes
No
No
No
No
Yes
No
No
68
0000000001000100
No
No
Yes
No
No
No
Yes
No
No
69
0000000001000101
Yes
No
Yes
No
No
No
Yes
No
No
70
0000000001000110
No
Yes
Yes
No
No
No
Yes
No
No
71
0000000001000111
Yes
Yes
Yes
No
No
No
Yes
No
No
The bottom line is that a pixel value of 0 means that no bands are saturated, while a nonzero pixel value indicates some saturation.
Last updated
Was this helpful?