Making QA masks with unpackqa and xarray

The xarray package allows you to work with labelled arrays. It uses numpy arrays, so unpackqa works with it without any modifications.

Flags values as a new dim

unpack_to_array can be used directly inside the xarray apply_ufunc function. With this setup you can take advantage of a parallel computing environment. Read more in the xarray docs: http://xarray.pydata.org/en/stable/user-guide/dask.html

Here a new dim will be added called flag, with the same length as the number of flags in the Landsat 8 QA_PIXEL band. The flag dim should be set as a core dim.

Flag values as new variables

Another option would be to have each flag as it's own data variable. That can be done with some rearranging.

Loading and viewing flags

When the chunks argument is set for xr.open_rasterio, all files are accessed lazily. The load options executes all underlying functions and loads all data into memory.