- Home
- Documentation
- API reference
- Core
- hyperproc.quality
hyperproc.quality¶
Source-derived reference
Generated from the current hyperproc 0.1.2 checkout.
Implementation: hyperproc/quality.py. Signatures, defaults, docstrings, and expandable source are extracted statically; the module is not imported or executed. Names beginning with _ are implementation details, not a stable public API.
Use the function signature as the authority for individual parameter defaults and return annotations. Original docstrings sometimes group parameter names or wrap return descriptions across lines; these descriptions are preserved rather than inferred or rewritten.
Exported entry points¶
| Importable name | Definition |
|---|---|
hyperproc.quality.FLAGS |
hyperproc.quality.FLAGS |
hyperproc.quality.FLAG_DESCRIPTIONS |
hyperproc.quality.FLAG_DESCRIPTIONS |
hyperproc.quality.BOOLEAN_SOURCES |
hyperproc.quality.BOOLEAN_SOURCES |
hyperproc.quality.CODED_SOURCES |
hyperproc.quality.CODED_SOURCES |
hyperproc.quality.DEFAULT_DROP |
hyperproc.quality.DEFAULT_DROP |
hyperproc.quality.build |
hyperproc.quality.build |
hyperproc.quality.decode |
hyperproc.quality.decode |
hyperproc.quality.summary |
hyperproc.quality.summary |
hyperproc.quality.apply |
hyperproc.quality.apply |
hyperproc.quality.set_flag |
hyperproc.quality.set_flag |
hyperproc.quality.describe |
hyperproc.quality.describe |
One quality layer for every sensor, as documented bit flags.
Each provider ships its own masks under its own names and its own polarity.
Nine spellings mean "cloud" across the readers in this package
(cloud, dilated_cloud, cloud_land, cloud_water, cldice,
and the cirrus variants); shadow is shadow on DESIS and cloudshadow on
EnMAP; valid is true when a pixel is good while nodata is true when it
is not; and the AVIRIS family ships nothing at all. Anyone who did not build
the pipeline has to learn all of that before they can mask a cube.
This module reduces it to one uint16 layer with one bit per condition,
the way Landsat's QA_PIXEL does::
import hyperproc as hp
q = hp.quality_flags(ds) # uint16 (y, x)
hp.quality_summary(q) # {'cloud': 0.11, 'water': 0.38, ...}
clear = hp.quality_apply(ds, q) # cube set to NaN where cloudy or fill
print(hp.quality_table(q)) # the bit table with per-flag shares
The per-sensor layers are left exactly as the readers produce them, so nothing
that already reads ds["cloud"] breaks; this is an additional view of them.
The bits¶
===== ==================== =============================================== Bit Flag Set when ===== ==================== =============================================== 0 fill no observation (off-swath, nodata, nav failure) 1 saturated a band is at the detector rail 2 cloud opaque cloud 3 cloud_shadow shadow cast by cloud 4 cirrus thin or high cloud 5 snow_ice snow or ice 6 water inland or ocean water 7 haze aerosol haze flagged by the provider 8 sun_glint specular reflection geometry 9 terrain_shadow not illuminated by the direct beam (cos i <= 0) 10 steep_terrain slope beyond what a topographic correction holds 11 ac_failed atmospheric correction did not converge 12 brdf_filled BRDF c-factor not taken from MODIS 13 negative_reflectance many good bands below zero after correction ===== ==================== ===============================================
Bits 14 and 15 are reserved. Stages add their own bits as they run:
:func:hyperproc.correct.nbar records brdf_filled through brdf_valid,
and :func:hyperproc.atmos.process writes the layer beside every product.
FLAGS: dict[str, int] = {'fill': 0, 'saturated': 1, 'cloud': 2, 'cloud_shadow': 3, 'cirrus': 4, 'snow_ice': 5, 'water': 6, 'haze': 7, 'sun_glint': 8, 'terrain_shadow': 9, 'steep_terrain': 10, 'ac_failed': 11, 'brdf_filled': 12, 'negative_reflectance': 13}
module-attribute
¶
FLAG_DESCRIPTIONS: dict[str, str] = {'fill': 'no observation (off-swath, nodata, navigation failure)', 'saturated': 'a band is at the detector rail', 'cloud': 'opaque cloud', 'cloud_shadow': 'shadow cast by cloud', 'cirrus': 'thin or high cloud', 'snow_ice': 'snow or ice', 'water': 'inland or ocean water', 'haze': 'aerosol haze flagged by the provider', 'sun_glint': 'specular reflection geometry', 'terrain_shadow': 'not illuminated by the direct beam (cos i <= 0)', 'steep_terrain': 'slope beyond what a topographic correction holds', 'ac_failed': 'atmospheric correction did not converge', 'brdf_filled': 'BRDF c-factor not taken from MODIS at this pixel', 'negative_reflectance': 'many good bands below zero after correction'}
module-attribute
¶
BOOLEAN_SOURCES: dict[str, tuple[str, bool]] = {'cloud': ('cloud', True), 'dilated_cloud': ('cloud', True), 'cloud_land': ('cloud', True), 'cloud_water': ('cloud', True), 'cldice': ('cloud', True), 'cirrus': ('cirrus', True), 'shadow': ('cloud_shadow', True), 'cloudshadow': ('cloud_shadow', True), 'snow': ('snow_ice', True), 'water': ('water', True), 'haze': ('haze', True), 'haze_land': ('haze', True), 'haze_water': ('haze', True), 'sunglint': ('sun_glint', True), 'higlint': ('sun_glint', True), 'hilt': ('saturated', True), 'l1_sat_err': ('saturated', True), 'atmfail': ('ac_failed', True), 'navfail': ('fill', True), 'spacecraft': ('fill', True), 'nodata': ('fill', True), 'valid': ('fill', False)}
module-attribute
¶
CODED_SOURCES: dict[str, dict[str, tuple]] = {'landcover': {'water': (0,), 'snow_ice': (1,)}, 'brdf_valid': {'brdf_filled': (0,), 'fill': (2,)}, 'hcw_class': {'fill': (0,), 'cloud_shadow': (1, 22), 'cirrus': (2, 3, 4, 8, 9, 10, 18, 19), 'saturated': (6,), 'snow_ice': (7,), 'haze': (11, 12, 13, 14), 'sun_glint': (13, 14), 'cloud': (15, 16), 'water': (17,), 'terrain_shadow': (21,)}, 'ddv_class': {'fill': (0,), 'water': (1,), 'terrain_shadow': (4,)}}
module-attribute
¶
DEFAULT_DROP = ('fill', 'cloud', 'cloud_shadow', 'cirrus')
module-attribute
¶
_DTYPE = 'uint16'
module-attribute
¶
_DTYPE_ONE = np.uint16(1)
module-attribute
¶
_bit(name: str) -> int
¶
_as_2d(ds: xr.Dataset, name: str) -> np.ndarray | None
¶
_band_nearest(ds: xr.Dataset, var: str, wl: float, tol: float = 30.0)
¶
The band nearest wl nm, or None when nothing is within tol.
Source code in hyperproc/quality.py
build(ds: xr.Dataset, *, var: str | None = None, derive: tuple[str, ...] = ('fill', 'terrain_shadow'), negative_fraction: float = 0.1, slope_max: float = 45.0, zhai: bool = False, sources: bool = True, verbose: bool = False) -> xr.DataArray
¶
Fold every mask a dataset carries into one uint16 flag layer.
| PARAMETER | DESCRIPTION |
|---|---|
ds
|
any hyperproc dataset. Whatever mask layers it has are used; what it lacks is simply absent from the result, never guessed.
TYPE:
|
var
|
the cube to read for the derived flags; the main one by default.
TYPE:
|
derive
|
flags to compute rather than read.
TYPE:
|
negative_fraction
|
fraction of usable bands that must be below zero
before
TYPE:
|
slope_max
|
degrees above which
TYPE:
|
zhai
|
also run the Zhai cloud index from
:mod:
TYPE:
|
sources
|
read the provider's own layers. False derives only.
TYPE:
|
verbose
|
print which layers were folded in.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataArray
|
|
DataArray
|
|
DataArray
|
the data. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
the dataset has no |
Source code in hyperproc/quality.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
decode(quality, *names: str) -> xr.DataArray | np.ndarray
¶
True where any of the named flags is set.
With no names, true where any flag is set.
Source code in hyperproc/quality.py
set_flag(quality: xr.DataArray, name: str, mask) -> xr.DataArray
¶
Return a copy of quality with name set wherever mask is true.
Source code in hyperproc/quality.py
summary(quality) -> dict
¶
Fraction of pixels carrying each flag, plus clear for none of them.
Source code in hyperproc/quality.py
apply(ds: xr.Dataset, quality: xr.DataArray | None = None, drop: tuple[str, ...] = DEFAULT_DROP, var: str | None = None, keep: bool = True, derive: tuple[str, ...] = ('fill',)) -> xr.Dataset
¶
Set the cube to NaN wherever a dropped flag is set.
| PARAMETER | DESCRIPTION |
|---|---|
ds
|
the dataset to mask.
TYPE:
|
quality
|
a layer from :func:
TYPE:
|
drop
|
the flags to mask on. The default is the set almost no analysis wants: fill, cloud, cloud shadow and cirrus.
TYPE:
|
var
|
the cube to mask; the main one by default.
TYPE:
|
keep
|
attach the quality layer to the result as
TYPE:
|
derive
|
passed to :func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dataset
|
A copy of |
Source code in hyperproc/quality.py
describe(quality=None) -> str
¶
The bit table, with the share of pixels per flag when a layer is given.