Create Masks
band_math(input_images, output_images, threshold_math, *, debug_logs=False, custom_nodata_value=None, cache=None, image_threads=None, io_threads=None, tile_threads=None, window_size=None, custom_output_dtype=None, calculation_dtype='float32')
¶
Applies a thresholding operation to input raster images using a mathematical expression string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_images
|
(str | List[str], required)
|
Defines input files from a glob path, folder, or list of paths. Specify like: "/input/files/.tif", "/input/folder" (assumes .tif), ["/input/one.tif", "/input/two.tif"]. |
required |
output_images
|
(str | List[str], required)
|
Defines output files from a template path, folder, or list of paths (with the same length as the input). Specify like: "/input/files/$.tif", "/input/folder" (assumes $_Threshold.tif), ["/input/one.tif", "/input/two.tif"]. |
required |
threshold_math
|
str
|
A muparser‑compatible expression applied to the raster bands, see https://github.com/beltoforion/muparser. Bands are referenced as B1, B2, … and you can use C‑style comparison and logical operators (such as >, <, >=, <=, ==, !=, &&, ||, !) along with parentheses and ternary ? : constructs—for example, ((B1 > 5) && (B2 < 10)) ? 1 : 0. Percentile‑based thresholds are supported: write 5%B1 to substitute the 5th‑percentile value of band 1 into the expression before evaluation. |
required |
debug_logs
|
bool
|
If True, prints debug messages. |
False
|
custom_nodata_value
|
float | int | None
|
Override the dataset's nodata value. |
None
|
cache
|
float | None
|
Controls GDAL cache size in GB. Defaults to preset cache size. Applied via GDAL_CACHEMAX. |
None
|
image_threads
|
Literal[cpu] | int | None
|
Parallelism for per-image operations. "cpu" to get number of cores, int to assign number, and None to disable image level parallelism. |
None
|
io_threads
|
Literal[cpu] | int | None
|
Parallelism for IO operations. "cpu" to get number of cores, int to assign number, and None to disable io level parallelism. |
None
|
tile_threads
|
Literal[cpu] | int | None
|
"cpu" to get number of cores, int to assign number, and None to disable tile level parallelism. |
None
|
window_size
|
WindowSize
|
Window tiling strategy for memory-efficient processing. |
None
|
custom_output_dtype
|
CustomOutputDtype
|
Output data type override. |
None
|
calculation_dtype
|
CalculationDtype
|
Internal computation dtype. |
'float32'
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Paths to the thresholded output images. |
Source code in spectralmatch/mask/mask.py
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 289 290 291 292 293 294 295 296 297 | |
create_cloud_mask_with_omnicloudmask(input_images, output_images, red_band_index, green_band_index, nir_band_index, *, down_sample_m=None, debug_logs=False, image_threads=None, omnicloud_kwargs=None)
¶
Generates cloud masks from input images using OmniCloudMask, with optional downsampling and multiprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_images
|
(str | List[str], required)
|
Defines input files from a glob path, folder, or list of paths. Specify like: "/input/files/.tif", "/input/folder" (assumes .tif), ["/input/one.tif", "/input/two.tif"]. |
required |
output_images
|
(str | List[str], required)
|
Defines output files from a template path, folder, or list of paths (with the same length as the input). Specify like: "/input/files/$.tif", "/input/folder" (assumes $_CloudMask.tif), ["/input/one.tif", "/input/two.tif"]. |
required |
red_band_index
|
int
|
Index of red band in the image. |
required |
green_band_index
|
int
|
Index of green band in the image. |
required |
nir_band_index
|
int
|
Index of NIR band in the image. |
required |
down_sample_m
|
float
|
If set, resamples input to this resolution in meters. Recommended to use a target resolution of 10 m or lower. |
None
|
debug_logs
|
bool
|
If True, prints progress and debug info. |
False
|
image_threads
|
Literal[cpu] | int | None
|
Enables parallel execution. Note: "process" does not work on macOS due to PyTorch MPS limitations. |
None
|
omnicloud_kwargs
|
dict | None
|
Additional arguments forwarded to predict_from_array. |
None
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagates any error from processing individual images. |
Source code in spectralmatch/mask/mask.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
process_raster_values_to_vector_polygons(input_images, output_vectors, *, extraction_expression, custom_nodata_value=None, custom_output_dtype=None, cache=None, image_threads=None, io_threads=None, tile_threads=None, debug_logs=False, filter_by_polygon_size=None, polygon_buffer=0.0, value_mapping=None, estimate_statistics=True)
¶
Converts raster values into vector polygons based on an expression and optional filtering logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_images
|
(str | List[str], required)
|
Defines input files from a glob path, folder, or list of paths. Specify like: "/input/files/.tif", "/input/folder" (assumes .tif), ["/input/one.tif", "/input/two.tif"]. |
required |
output_vectors
|
(str | List[str], required)
|
Defines output files from a template path, folder, or list of paths (with the same length as the input). Specify like: "/input/files/$.gpkg", "/input/folder" (assumes $_Vectorized.gpkg), ["/input/one.gpkg", "/input/two.gpkg"]. |
required |
extraction_expression
|
str
|
A muparser‑compatible expression applied to the raster bands, see https://github.com/beltoforion/muparser. Bands are referenced as B1, B2, … and you can use C‑style comparison and logical operators (such as >, <, >=, <=, ==, !=, &&, ||, !) along with parentheses and ternary ? : constructs—for example, ((B1 > 5) && (B2 < 10)) ? 1 : 0. Percentile‑based thresholds are supported: write 5%B1 to substitute the 5th‑percentile value of band 1 into the expression before evaluation. |
required |
custom_nodata_value
|
CustomNodataValue
|
Custom NoData value to override the default from the raster metadata. |
None
|
custom_output_dtype
|
CustomOutputDtype
|
Desired output data type. If not set, defaults to raster’s dtype. |
None
|
cache
|
float | None
|
Controls GDAL cache size in GB. Defaults to preset cache size. Applied via GDAL_CACHEMAX. |
None
|
image_threads
|
Literal[cpu] | int | None
|
Parallelism for per-image operations. "cpu" to get number of cores, int to assign number, and None to disable image level parallelism. |
None
|
io_threads
|
Literal[cpu] | int | None
|
Parallelism for IO operations. "cpu" to get number of cores, int to assign number, and None to disable io level parallelism. |
None
|
tile_threads
|
Literal[cpu] | int | None
|
"cpu" to get number of cores, int to assign number, and None to disable tile level parallelism. |
None
|
debug_logs
|
DebugLogs
|
Whether to print debug logs to the console. |
False
|
filter_by_polygon_size
|
str
|
Area filter for resulting polygons. Can be a number (e.g., ">100") or percentile (e.g., ">95%"). |
None
|
polygon_buffer
|
float
|
Distance in coordinate units to buffer the resulting polygons. Default is 0. |
0.0
|
value_mapping
|
dict
|
Mapping from original raster values to new values. Use |
None
|
estimate_statistics
|
bool
|
Whether to estimate statistics for percentile thresholds. Defaults to True. |
True
|
Source code in spectralmatch/mask/utils_mask.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |