Utilities
align_rasters(input_images, output_images, *, resampling_method='bilinear', tap=False, resolution='highest', window_size=None, debug_logs=False, cache=None, image_threads=None, io_threads=None, tile_threads=None)
¶
Aligns multiple rasters to a common resolution and grid using specified resampling.
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 $_Local.tif), ["/input/one.tif", "/input/two.tif"]. |
required |
resampling_method
|
Literal['nearest', 'bilinear', 'cubic']
|
"nearest" | "bilinear" | "cubic". |
'bilinear'
|
tap
|
bool
|
If True, snap output extent to target-aligned pixels (GDAL -tap behavior). |
False
|
resolution
|
Literal['highest', 'average', 'lowest']
|
"highest" (min px size), "average", or "lowest" (max px size). |
'highest'
|
window_size
|
WindowSize
|
Tile size for output blocks; used for GTiff creation options. |
None
|
debug_logs
|
DebugLogs
|
Verbose logging. |
False
|
cache
|
Cache
|
Cache for processing. |
None
|
image_threads
|
Threads
|
Python-level parallelism over images (e.g., ("process", 4)). |
None
|
io_threads
|
Threads
|
Sets GDAL_NUM_THREADS for internal GDAL multithreading (int or str). |
None
|
tile_threads
|
Threads
|
Sets GTiff/COG writer NUM_THREADS and Warp’s NUM_THREADS (int or str). |
None
|
Returns:
| Type | Description |
|---|---|
None
|
List[str]: Paths to the locally adjusted output raster images. |
Source code in spectralmatch/utils.py
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 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 | |
compute_overviews(input_images_paths, *, output_image_paths=None, window_scales=(2, 4, 8, 16, 32), cache=None, image_threads=None, io_threads=None, tile_threads=None, debug_logs=False)
¶
Compute and attach GDAL overviews for one or more raster images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_images_paths
|
(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_image_paths
|
str | List[str] | None
|
Defines output files as None to update input images or from a template path, folder, or list of paths (with the same length as the input). Specify like: "/input/files/$.tif", "/input/folder" (assumes $_Global.tif), ["/input/one.tif", "/input/two.tif"]. |
None
|
window_scales
|
tuple[int] | None
|
Overview decimation factors (default: (2, 4, 8, 16, 32)). |
(2, 4, 8, 16, 32)
|
cache
|
Cache
|
GDAL cache size configuration. |
None
|
image_threads
|
Threads
|
Number of parallel workers for image-level processing. |
None
|
io_threads
|
Threads
|
GDAL IO worker configuration. |
None
|
tile_threads
|
Threads
|
GDAL internal threads for overview computation. |
None
|
debug_logs
|
bool
|
Enable verbose logging. |
False
|
Returns:
| Type | Description |
|---|---|
|
List[str]: Paths of images that received overviews. |
Source code in spectralmatch/utils.py
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 1004 1005 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 | |
create_masked_vrts(input_image_path_pairs, *, vector_mask=None, out_dir=None, debug_logs=False)
¶
For each (name -> image_path), write: - mask_{name}.geojson (cutline: include polys OR exclude complement) - vrt_{name}.vrt (alpha = band1 nodata U cutline-outside) Returns: dict[name, vrt_path]
Source code in spectralmatch/utils.py
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 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 | |
mask_rasters(input_images, output_images, vector_mask=None, window_size=None, debug_logs=False, cache=None, image_threads=None, io_threads=None, tile_threads=None, include_touched_pixels=False, custom_nodata_value=None)
¶
Applies a vector-based mask to one or more rasters using GDAL Warp.
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 $_Local.tif), ["/input/one.tif", "/input/two.tif"]. |
required |
vector_mask
|
VectorMask
|
Tuple ('include'|'exclude', vector_path, optional field name). |
None
|
window_size
|
int | None
|
Tile size for processing tiles. Defaults to None. |
None
|
debug_logs
|
bool
|
If True, prints progress. Defaults to False. |
False
|
cache
|
int | Tuple[int, str] | None
|
Controls GDAL cache size. Examples: 2048 (MB), (2, "GB"). Set None to use GDAL’s default. Applied via GDAL_CACHEMAX. window_parallel_workers (Tuple[Literal["process"], Literal["cpu"] | int] | None = None): Parallelization strategy at the window level within each image. Same format as image_parallel_workers. Threads are not supported. Set to None to disable. |
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
|
include_touched_pixels
|
bool
|
If True, uses all touched pixels for cutline mask. |
False
|
custom_nodata_value
|
float | int | None
|
Overrides detected NoData value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Output image paths after masking. |
Source code in spectralmatch/utils.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
merge_rasters(input_images, output_image_path, *, cache=None, io_threads=None, tile_threads=None, debug_logs=False, output_dtype=None, custom_nodata_value=None, resolution='highest', window_size=None, build_overviews=False)
¶
Merges multiple rasters into a single output.
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_image_path
|
str
|
Path to output mosaic. |
required |
cache
|
int | Tuple[int, str] | None
|
Controls GDAL cache size. Examples: 2048 (MB), (2, "GB"). Set None to use GDAL’s default. Applied via GDAL_CACHEMAX. window_parallel_workers (Tuple[Literal["process"], Literal["cpu"] | int] | None = None): Parallelization strategy at the window level within each image. Same format as image_parallel_workers. Threads are not supported. Set to None to disable. |
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
|
bool
|
If True, prints progress. Defaults to False. |
False
|
output_dtype
|
str | None
|
Data type for output rasters. Defaults to input image dtype. |
None
|
custom_nodata_value
|
float | int | None
|
Overrides detected NoData value. Defaults to None. |
None
|
resolution
|
highest | average | lowest
|
Strategy for computing merge resolution. |
'highest'
|
window_size
|
int | None
|
Tile size for processing tiles. Defaults to None. |
None
|
build_overviews
|
bool
|
If True, computes overviews. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path of the merged raster. |
Source code in spectralmatch/utils.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 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 | |
merge_vectors(input_vectors, merged_vector_path, method, debug_logs=False, create_name_attribute=None)
¶
Merge multiple vector files using the specified geometric method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_vectors
|
str | List[str]
|
Defines input files from a glob path, folder, or list of paths. Specify like: "/input/files/.gpkg", "/input/folder" (assumes .gpkg), ["/input/one.tif", "/input/two.tif"]. |
required |
merged_vector_path
|
str
|
Path to save merged output. |
required |
method
|
Literal['intersection', 'union', 'keep']
|
Merge strategy. |
required |
debug_logs
|
bool
|
If True, print debug information. |
False
|
create_name_attribute
|
Optional[Tuple[str, str]]
|
Tuple of (field_name, separator) to add a combined name field. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in spectralmatch/utils.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 | |