QA¶
geoops.qa is the home of QA / cloud-mask extraction: generic decoders, sensor presets, and the decoding primitives they share:
mask_from_qa_bits— single-bit-flag decoding (OR of bits).mask_from_scl— categorical class membership (Sentinel-2 SCL).mask_from_bit_field— contiguous multi-bit field decoding (needed for MODIS).flagged_band_countandmask_from_band_count— EMIT's packed per-band mask: the bands flagged per pixel, and the dilated saturation mask above each detector column's baseline.
One vocabulary throughout: qa_band selects the QA band from a stack (None, the default for the generic decoders, means the carrier is the QA band), bits lists independent flag bits, values lists categorical class / field values, and the sensor presets take targets — registry names to mask out.
Pick the generic decoders (MaskClouds, MaskCloudShadow, MaskCirrus, MaskSnow, MaskWater, MaskNoData — one implementation under several semantic names) when you have an explicit list of bits / values; invert=True turns the list into a keep-list. MaskInvalid marks nodata pixels (the carrier fill, NaN fills included, or non-finite values); MaskSaturated flags pixels at or above a saturation value (reduce_bands=False for per-band flags). Pick LandsatQA_PIXEL / S2QA60 / S2SCL / MODISStateQA / EMITL2AMask when you want the published-spec defaults, EMITBandMask for the saturation mask of an EMIT scene, and DecodeBitmask to unpack a QA bitmask into named boolean layers. SCL holds the Sentinel-2 SCL class IDs and SCL_CLOUDS, SCL_CLOUDS_AND_INVALID, SCL_INVALID, SCL_LAND, SCL_WATER the common class sets; SENSOR_QA_REGISTRY maps each sensor preset's targets names to bits / values. S2Cloudless, CloudSEN12 and OmniCloudMask are placeholders reserved for optional ML-based detectors: they configure and serialise today but raise ImportError when called. To apply a mask, use geoops.mask.ApplyMask.
geoops.qa
¶
QA bit decoding, SCL classes, and sensor mask presets.
The operators in this module return boolean masks where True means
"mask this pixel out". Use them with geoops.mask.ApplyMask or
downstream mask-combination operators.
Two operator families:
- Generic extraction (
MaskClouds,MaskCloudShadow,MaskCirrus,MaskSnow,MaskWater,MaskNoData,MaskInvalid,MaskSaturated,DecodeBitmask) — pass explicitbits/valueswith an optionalqa_band(None= the carrier is the QA band). - Sensor presets (
S2QA60,S2SCL,LandsatQA_PIXEL,MODISStateQA,EMITL2AMask, andEMITBandMaskfor EMIT's packed band mask) — published bit/class layouts baked in; picktargetsby name.
CloudSEN12
¶
Bases: Operator
Placeholder for the optional ML-based CloudSEN12 detector.
Raises ImportError on call.
Examples:
>>> from geoops.qa import CloudSEN12
>>> CloudSEN12(checkpoint="default").get_config()
{'checkpoint': 'default'}
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
DecodeBitmask
¶
Bases: Operator
Unpack a QA bitmask into named boolean mask layers.
A more general sibling of MaskClouds (bits= mode): instead
of returning a single OR-ed mask, this operator returns a stacked
multi-band boolean carrier with one layer per named entry in
bits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bits
|
Mapping[str, Sequence[int]] | Sequence[Sequence[Any]]
|
Mapping from output-layer name to bit positions, or the
equivalent |
required |
mode
|
str
|
|
'any'
|
qa_band
|
BandSelector
|
Optional integer or named band selector. When omitted, the input carrier itself is treated as the QA band. |
None
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Returns:
| Type | Description |
|---|---|
GeoArray | ndarray
|
A multi-band boolean carrier with
shape |
Examples:
>>> from geoops.qa import DecodeBitmask
>>> # Landsat-8 QA_PIXEL — one band per flag.
>>> op = DecodeBitmask(
... bits={"cloud": [3], "cirrus": [2], "shadow": [4]},
... qa_band="QA_PIXEL",
... )
>>> layers = op(landsat_stack) # (3, H, W) bool GeoArray
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
EMITBandMask
¶
Bases: Operator
Saturation mask from EMIT's packed band mask; True = mask out.
satᵢⱼ = [nᵢⱼ - minᵢ nᵢⱼ > 0], grown by dilation pixels in city-block
distance, with nᵢⱼ the bands flagged at pixel (i, j).
The carrier is EMIT's band_mask in swath geometry: uint8, one
bit per spectral band packed into 36 bytes along dim (EMIT L2A User
Guide V1.0, Table 3-3; the L1B band mask has the same layout). A set
bit marks a band interpolated over a bad detector element or
saturation. See geoops.qa.flagged_band_count and
geoops.qa.mask_from_band_count for the maths: the column minimum
removes the static detector defects, and what is left is saturation.
Compute it before orthorectifying, since the columns must be detector
elements. Nodata pixels of the carrier (its fill value) neither set a
column's baseline nor are flagged, and the output declares
fill_value=False. Every byte value can be data, and a pixel with any
byte equal to the fill is nodata, so declare a fill only for a value
the product reserves for missing pixels. A (Y, H, W) carrier gives
an (H, W) mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dilation
|
int
|
Growth of the mask in pixels (city-block distance). Default 10, SPIIRE's. |
10
|
dim
|
str
|
Name of the packed-byte dim (default |
'band'
|
Examples:
>>> import numpy as np
>>> from geoops.qa import EMITBandMask
>>> bandmask = np.zeros((36, 5, 5), dtype=np.uint8)
>>> bandmask[0] = 0b0000_0111 # three bad bands in every pixel
>>> bandmask[4, 2, 2] = 0b1100_0000 # two more at one pixel
>>> EMITBandMask(dilation=0)(bandmask).astype(int).sum()
np.int64(1)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
EMITL2AMask
¶
Bases: Operator
Named flags of the EMIT L2A mask product, OR-combined; True = mask out.
maskᵢⱼ = OR over t in targets of [flag_{ij, band(t)} > 0].
The carrier is the mask variable of an EMIT L2A MASK file, one band
per flag, in the order of the EMIT L2A User Guide V1.0, Table 3-4
(SENSOR_QA_REGISTRY["emit_l2a_mask"]): cloud, cirrus,
water, spacecraft and dilated_cloud are bands 0 to 4 and
aggregate (the OR of the first five) is band 7. Bands 5 and 6 hold
the aerosol optical depth and the water vapour, which are not flags.
The default, cloud, cirrus and water, is SPIIRE's mask of clouds and
surface water.
Nodata pixels of the carrier are never flagged, and the output declares
fill_value=False. A (B, H, W) carrier gives an (H, W) mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
Sequence[str]
|
Flag names from |
('cloud', 'cirrus', 'water')
|
dim
|
str
|
Name of the band dim (default |
'band'
|
Examples:
>>> import numpy as np
>>> from geoops.qa import EMITL2AMask
>>> flags = np.zeros((8, 2, 2), dtype=np.float32)
>>> flags[2, 0, 1] = 1.0 # water
>>> flags[3, 1, 1] = 1.0 # spacecraft, not a default target
>>> EMITL2AMask()(flags).tolist()
[[False, True], [False, False]]
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 | |
LandsatQA_PIXEL
¶
Bases: Operator
Landsat Collection-2 QA_PIXEL mask preset.
Returns True where any requested targets flag is set in
QA_PIXEL. Defaults to cloud, cloud shadow, and cirrus targets
(the standard "drop cloudy" mask for L8/L9).
Sensor selection: pass sensor="l7" for Landsat 4-7
Collection-2 — same bit layout as L8/L9 except bit 2 ("cirrus") is
unused on TM/ETM+. For sensor="l89" (default) the full L8/L9
layout is used.
Accepts a GeoArray or a plain np.ndarray and returns the
same carrier kind; plain arrays need an integer qa_band.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa_band
|
int | str
|
Band selector for QA_PIXEL. |
'QA_PIXEL'
|
targets
|
Sequence[str] | None
|
Target flag names to OR together. See
|
None
|
sensor
|
str
|
|
'l89'
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> from geoops.qa import LandsatQA_PIXEL
>>> # L8/L9 default "drop everything not clear".
>>> mask = LandsatQA_PIXEL()(landsat8_stack)
>>> # L7 — same but no cirrus bit.
>>> mask = LandsatQA_PIXEL(
... sensor="l7", targets=["cloud", "cloud_shadow"]
... )(landsat7_stack)
References
USGS, "Landsat 8-9 Collection 2 Level-2 Science Product Guide", LSDS-1619, 2022. USGS, "Landsat 4-7 Collection 2 Level-2 Science Product Guide", LSDS-1618, 2022.
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 | |
MODISStateQA
¶
Bases: Operator
MODIS state_1km (or state_500m) QA mask preset.
Returns True where any requested targets is set in the MODIS
State QA band. Defaults to cloud and cloud-shadow targets.
The cloud and cirrus targets are decoded as 2-bit fields, not
independent bit flags: bits [0, 1] are the cloud state
(0=clear, 1=cloudy, 2=mixed, 3=not-set) and bits [8, 9] are
cirrus level (0=none, 1=small, 2=average, 3=high). The default
"cloud" target matches cloudy + mixed; "cirrus" matches
small/average/high.
Accepts a GeoArray or a plain np.ndarray and returns the
same carrier kind; plain arrays need an integer qa_band.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa_band
|
int | str
|
Band selector for the state QA band. |
'state_1km'
|
targets
|
Sequence[str]
|
Target flag names to OR together. See
|
('cloud', 'cloud_shadow')
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> from geoops.qa import MODISStateQA
>>> # Default cloud + cloud-shadow mask.
>>> mask = MODISStateQA()(modis_state_band)
>>> # Include cirrus too.
>>> mask = MODISStateQA(targets=["cloud", "cloud_shadow", "cirrus"])(state)
References
Vermote, E. F., "MODIS Surface Reflectance User's Guide", 2015, Table 12.
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | |
MaskCirrus
¶
MaskCloudShadow
¶
Bases: _QAMask
Return True where a QA band marks cloud-shadow pixels.
Examples:
>>> from geoops.qa import MaskCloudShadow
>>> # Landsat-8 QA_PIXEL: bit 4 is "cloud shadow".
>>> mask = MaskCloudShadow(qa_band="QA_PIXEL", bits=[4])(landsat_stack)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
MaskClouds
¶
Bases: _QAMask
Return True where a QA band marks cloud-contaminated pixels.
Examples:
>>> from geoops.qa import MaskClouds
>>> # Sentinel-2 QA60: bit 10 is "opaque clouds".
>>> mask = MaskClouds(qa_band="QA60", bits=[10])(s2_geoarray)
>>> # Sentinel-2 SCL: the cloud-like classes.
>>> from geoops.qa import SCL_CLOUDS
>>> mask = MaskClouds(qa_band="SCL", values=sorted(SCL_CLOUDS))(s2_l2a)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
MaskInvalid
¶
Bases: Operator
Mark invalid (nodata) pixels: True = invalid, drop it.
The package-polarity counterpart of georeader's
GeoTensor.invalidmask() reduced over bands: a pixel is invalid
when any band equals the fill value or is non-finite. Unlike
georeader's comparison, a NaN fill (fill_value=nan)
matches NaN pixels (see :mod:geoops._src.valid).
Uses the carrier's fill_value by default; pass
invalid_value explicitly to mark a different sentinel (required
for plain-ndarray carriers, which have no fill value).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invalid_value
|
float | int | None
|
Sentinel value treated as "invalid". |
None
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> from geoops.mask import ApplyMask
>>> from geoops.qa import MaskInvalid
>>> mask = MaskInvalid()(geoarray) # True = invalid
>>> clean = ApplyMask(mask=MaskInvalid(), fill_value=np.nan)(geoarray)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
MaskNoData
¶
Bases: _QAMask
Return True where pixels are no-data by QA value or carrier fill value.
Two operating modes:
- QA-driven: pass
bits/values(plusqa_bandwhen the QA band is part of a stack) to decode no-data from a dedicated QA band, exactly like the other_QAMaskshortcuts. - Fill-driven (default): without
bits/valuesit isMaskInvalid— pixels invalid in any band (equal to the carrier'sfill_value, aNaNfill matchingNaN, or non-finite) are marked (see :mod:geoops._src.valid).
The QA-driven mode accepts a GeoArray or a plain np.ndarray
and returns the same carrier kind; the fill-driven mode reads
carrier metadata, so it requires a GeoArray with a
fill_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa_band
|
BandSelector
|
Optional QA band selector (QA-driven mode only). |
None
|
bits
|
Sequence[int] | None
|
Bit positions that mark no-data. |
None
|
values
|
Sequence[int] | None
|
Categorical values that mark no-data (e.g. SCL=0). |
None
|
mode
|
str
|
|
'any'
|
axis
|
int | None
|
Position of the band axis. Default |
None
|
invert
|
bool
|
Flip the QA-driven mask (see |
False
|
Returns:
| Type | Description |
|---|---|
GeoArray
|
Boolean no-data mask. |
Examples:
>>> from geoops.qa import MaskNoData
>>> # Sentinel-2 SCL: class 0 is NO_DATA.
>>> nodata = MaskNoData(qa_band="SCL", values=[0])(s2_l2a)
>>> # Fill-value fallback when no QA band is available.
>>> nodata = MaskNoData()(carrier_with_fill_value)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
MaskSaturated
¶
Bases: Operator
Return True where pixels are at or above a saturation value.
The one saturation mask in the package. Nodata pixels (fill value or
non-finite, see :mod:geoops._src.valid) are never reported as
saturated — so a uint16 fill at the dtype maximum is not flagged
— and the output declares fill_value=False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa_band
|
BandSelector
|
Optional band selector. When omitted, every band is tested. |
None
|
saturation_value
|
float | int | None
|
Saturation threshold; pixels |
None
|
reduce_bands
|
bool
|
When True (default) and |
True
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Returns:
| Type | Description |
|---|---|
GeoArray | ndarray
|
Boolean mask with saturated pixels
marked True, matching the input carrier kind ( |
Examples:
>>> from geoops.qa import MaskSaturated
>>> # uint16 Sentinel-2 — saturation_value defaults to 65535.
>>> sat = MaskSaturated()(s2_uint16_stack)
>>> # Per-band flags at a reflectance ceiling.
>>> sat = MaskSaturated(saturation_value=1.0, reduce_bands=False)(refl)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
MaskSnow
¶
MaskWater
¶
OmniCloudMask
¶
Bases: Operator
Placeholder for the optional ML-based OmniCloudMask detector.
Raises ImportError on call.
Examples:
>>> from geoops.qa import OmniCloudMask
>>> OmniCloudMask(checkpoint="default").get_config()
{'checkpoint': 'default'}
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
S2Cloudless
¶
Bases: Operator
Placeholder for the optional ML-based s2cloudless mask.
Raises ImportError on call. Reserved for the future
[cloud-ml] extra so that pipelines can be configured today and
light up once the dependency is installed.
Examples:
>>> from geoops.qa import S2Cloudless
>>> S2Cloudless(threshold=0.4).get_config()
{'threshold': 0.4}
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
S2QA60
¶
Bases: Operator
Sentinel-2 L1C QA60 cloud + cirrus mask preset.
QA60 (per ESA's S2 L1C product specification) encodes opaque clouds
in bit 10 and cirrus in bit 11 (SENSOR_QA_REGISTRY["s2_qa60"]).
Returns True where any requested targets bit is set.
Note: QA60 is unreliable / zeroed-out on newer processing baselines
(≥ 04.00). Prefer the L2A SCL band (S2SCL) or an ML-based
detector when available.
Accepts a GeoArray or a plain np.ndarray and returns the
same carrier kind; plain arrays need an integer qa_band (the
default is a band name, which requires GeoArray attrs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa_band
|
int | str
|
Band selector for QA60 within the input stack. |
'QA60'
|
targets
|
Sequence[str]
|
Target names to OR together ( |
('cloud', 'cirrus')
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
S2SCL
¶
Bases: Operator
Sentinel-2 L2A SCL preset that masks the requested targets classes.
Returns True for pixels whose SCL class belongs to any of the named
targets (see SENSOR_QA_REGISTRY["s2_scl"], derived from
geoops.qa.SCL). The default targets are every class except
vegetation, soil and water — i.e. vegetation, soil, and water are
kept.
Accepts a GeoArray or a plain np.ndarray and returns the
same carrier kind; plain arrays need an integer qa_band.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa_band
|
int | str
|
Band selector for the SCL band. |
'SCL'
|
targets
|
Sequence[str]
|
Class names to mask out. See
|
_DEFAULT_TARGETS
|
dim
|
str
|
Name of the band dim (default |
'band'
|
axis
|
int | None
|
Deprecated: the band axis position. |
None
|
Examples:
>>> from geoops.qa import S2SCL
>>> # Default: mask everything that isn't vegetation/soil/water.
>>> mask = S2SCL()(s2_l2a_with_scl)
>>> # Custom: mask clouds, cirrus and cloud shadow only.
>>> mask = S2SCL(targets=["cloud", "cirrus", "cloud_shadow"])(s2_l2a)
Source code in packages/geotoolz-ops/src/geoops/qa/_src/operators.py
SCL
¶
Bases: IntEnum
Sentinel-2 L2A Scene Classification Layer class IDs.
Source code in packages/geotoolz-ops/src/geoops/qa/_src/scl.py
flagged_band_count(bandmask)
¶
Number of bands flagged in each pixel's packed band mask.
nᵢⱼ = ∑_k b_ijk, the bits set across the pixel's bytes.
EMIT's band_mask packs one bit per spectral band into 36 bytes for
its 285 bands (EMIT L2A User Guide, Table 3-3); a set bit marks a band
interpolated over a bad detector element or saturation. The count does
not depend on the bit order within a byte.
Algorithm
- Look up the bits set in every byte value in a 256-entry table.
- Gather it for each byte and sum over the bytes.
The table avoids np.unpackbits, which would allocate eight times
the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandmask
|
UInt8[ndarray, 'row col byte']
|
Packed band mask, the bytes on the last axis. |
required |
Returns:
| Type | Description |
|---|---|
Int[ndarray, 'row col']
|
The count nᵢⱼ, |
Examples:
>>> bandmask = np.array([[[0b1010_0000, 0b0000_0001]]], dtype=np.uint8)
>>> flagged_band_count(bandmask).tolist()
[[3]]
Source code in packages/geotoolz-ops/src/geoops/qa/_src/array.py
mask_from_band_count(count, *, valid=None, dilation=10)
¶
Pixels with more flagged bands than their column's baseline, dilated.
satᵢⱼ = [nᵢⱼ - m_j > 0] with m_j = minᵢ nᵢⱼ over valid rows, grown by
dilation pixels in city-block distance.
Algorithm
- Take each column's minimum count over its valid rows.
- Flag valid pixels above their column's minimum.
- Threshold the city-block distance to the flagged pixels.
EMIT is a push-broom instrument, so column j is one cross-track detector
element in every row. A dead or hot element flags the same bands down
its whole column, so the column minimum is the static part and what a
pixel has above it is transient, in practice saturation. Compute the
mask in swath geometry, before any orthorectification: on a map grid
the columns no longer follow the detector. dilation=10 is SPIIRE's
default, 600 m on EMIT's 60 m pixels.
Invalid pixels never set a baseline and are never flagged, not even by
the dilation, and a column with no valid row is all False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
Int[ndarray, 'row col']
|
Flagged-band count nᵢⱼ, from :func: |
required |
valid
|
Bool[ndarray, 'row col'] | None
|
Pixels to use; |
None
|
dilation
|
int
|
Growth radius r in pixels. |
10
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, 'row col']
|
The mask; True means mask out. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
A column with three bands flagged in every row, and one pixel with two more:
>>> count = np.full((5, 5), 3)
>>> count[2, 2] = 5
>>> mask = mask_from_band_count(count, dilation=1)
>>> mask.astype(int).tolist()[1:4]
[[0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0]]
Source code in packages/geotoolz-ops/src/geoops/qa/_src/array.py
mask_from_bit_field(qa, bits, values, *, invert=False)
¶
Decode a contiguous multi-bit QA field by value membership.
Several sensor QA layers pack a small categorical field into two or
more adjacent bits — e.g. MODIS state_1km bits [0, 1] are a
2-bit "cloud state" field (00 clear, 01 cloudy, 10
mixed, 11 not-set/assumed-clear). OR-ing the bits independently
(the standard Landsat semantics) is wrong here: a "mixed" pixel has
bit 1 set but is not cloudy.
This helper extracts the bit field as an integer and returns True
where its value is in values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa
|
Int[ndarray, '*batch h w']
|
Integer QA array. |
required |
bits
|
Sequence[int]
|
Bit positions, ordered LSB → MSB. The field width is
|
required |
values
|
Sequence[int]
|
Integer field-values to match. For MODIS |
required |
invert
|
bool
|
When True, flip the result. |
False
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*batch h w']
|
Boolean array of the same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/geotoolz-ops/src/geoops/qa/_src/array.py
mask_from_qa_bits(qa, bits, *, invert=False)
¶
Decode a Landsat-style bitmask QA band.
Returns a boolean array where any of the supplied bits is set
in the QA value. For Landsat-8 QA_PIXEL the bit assignments
(Collection-2 Level-2) are:
===== ========================== Bit Meaning ===== ========================== 0 Fill / no-data 1 Dilated Cloud 2 Cirrus (high confidence) 3 Cloud 4 Cloud Shadow 5 Snow 6 Clear 7 Water ===== ==========================
So mask_from_qa_bits(qa, bits=[3, 4]) returns True where the
pixel is either cloudy or in cloud shadow.
The math is a single (qa & bitmask) != 0 per bit, OR-ed
together — vectorised over the whole array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qa
|
Int[ndarray, '*dims']
|
Integer QA array (any integer dtype). Typically
|
required |
bits
|
Sequence[int]
|
Sequence of bit positions to test. The function returns True where ANY of these is set. |
required |
invert
|
bool
|
When True, flip the result. Useful for "clear" masks
( |
False
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*dims']
|
Boolean array of the same shape as |
References
USGS, "Landsat 8-9 Collection 2 Level-2 Science Product Guide", LSDS-1619, 2022.
Source code in packages/geotoolz-ops/src/geoops/qa/_src/array.py
mask_from_scl(scl, classes, *, invert=False)
¶
Decode a Sentinel-2 SCL band by class membership.
Returns True where the SCL value equals any of the listed
classes. With invert=True, returns True where the SCL value
is not in the list — handy for "keep only these classes" masks.
SCL class IDs come from geoops.qa.SCL (an IntEnum). Mixing raw
ints and enum members is fine — they're cast to int here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scl
|
Int[ndarray, '*dims']
|
SCL band, integer dtype, typically |
required |
classes
|
Sequence[int]
|
SCL class IDs to match (raw ints or |
required |
invert
|
bool
|
When True, return True where SCL value is NOT in
|
False
|
Returns:
| Type | Description |
|---|---|
Bool[ndarray, '*dims']
|
Boolean array of the same shape as |
Source code in packages/geotoolz-ops/src/geoops/qa/_src/array.py
Sensor registry¶
| Preset | QA source | Default mask targets | Reference |
|---|---|---|---|
S2QA60 |
Sentinel-2 L1C QA60 bitmask (bit 10 cloud, 11 cirrus) |
cloud + cirrus | ESA S2 L1C product spec |
S2SCL |
Sentinel-2 L2A SCL classes (registry derived from SCL_TARGETS) |
every target except vegetation (4), soil (5), water (6) | Sen2Cor product spec |
LandsatQA_PIXEL (sensor=l89) |
Landsat 8/9 C2 QA_PIXEL |
cloud (bit 3), cloud shadow (bit 4), cirrus (bit 2) | USGS LSDS-1619 |
LandsatQA_PIXEL (sensor=l7) |
Landsat 4-7 C2 QA_PIXEL (no cirrus bit) |
cloud (bit 3), cloud shadow (bit 4) | USGS LSDS-1618 |
MODISStateQA |
MODIS state_1km / state_500m |
cloud (bits [0,1] field, values 1,2) + cloud shadow (bit 2) | MOD09 User's Guide, Table 12 |
EMITL2AMask |
EMIT L2A mask, one flag per band (0 cloud, 1 cirrus, 2 water, 3 spacecraft, 4 dilated cloud, 7 aggregate; 5 and 6 are AOD and water vapour) |
cloud + cirrus + water | EMIT L2A User Guide V1.0 (JPL D-107863), Table 3-4 |
EMITBandMask |
EMIT band_mask, one bit per spectral band in 36 bytes |
flagged bands above the column baseline, dilated by 10 pixels | EMIT L2A User Guide V1.0, Table 3-3 |
All QA mask operators return boolean masks matching the input carrier: GeoArray in (CRS/transform preserved, fill_value=False), plain np.ndarray in, plain boolean array out. The convention is True means "mask this pixel out" (see Mask polarity).
MODIS bit-field semantics¶
MODIS state_1km packs categorical fields into multi-bit slots:
- Bits
[0, 1](2 bits): cloud state —0=clear,1=cloudy,2=mixed,3=not-set. - Bit
2: cloud shadow. - Bits
[8, 9](2 bits): cirrus level —0=none,1=small,2=average,3=high.
OR-ing the bits individually (the standard Landsat semantics) would flag value 3 (not-set) as cloudy, which is wrong. MODISStateQA therefore decodes these as field values via mask_from_bit_field.
EMIT saturation¶
EMIT is a push-broom instrument, so each column of a swath is one cross-track detector element. A dead or hot element flags the same bands in every row of its column, so EMITBandMask takes each column's smallest flagged-band count as its static baseline and flags what a pixel has above it, which in practice is saturation (flares, glint, bright roofs). It then grows the mask by dilation pixels in city-block distance. Compute it in swath geometry, before orthorectifying, while the columns still follow the detector.