stitching
stitching.py: utilities for combining interferograms into larger images.
get_combined_bounds_nodata(*filenames, target_aligned_pixels=False, out_bounds=None, out_bounds_epsg=None, strides=None)
Get the bounds and nodata of the combined image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filenames
|
list[Filename]
|
list of filenames to combine |
()
|
target_aligned_pixels
|
bool
|
if True, adjust output image bounds so that pixel coordinates
are integer multiples of pixel size, matching the |
False
|
out_bounds
|
Optional[Bbox]
|
if provided, forces the output image bounds to (left, bottom, right, top). Otherwise, computes from the outside of all input images. |
None
|
out_bounds_epsg
|
Optional[int]
|
The EPSG of |
None
|
strides
|
dict[str, int]
|
subsample factor: {"x": x strides, "y": y strides} |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bounds |
Bbox
|
(min_x, min_y, max_x, max_y) |
nodata |
float | None
|
Nodata value of the input files |
Raises:
| Type | Description |
|---|---|
ValueError:
|
If the inputs files have different resolutions/projections/nodata values |
Source code in src/dolphin/stitching.py
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 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
get_downsampled_vrts(filenames, strides, dirname)
Create downsampled VRTs from a list of files.
Does not reproject, only uses gdal_translate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filenames
|
Sequence[Filename]
|
list of filenames to warp. |
required |
strides
|
dict[str, int]
|
subsample factor: {"x": x strides, "y": y strides} |
required |
dirname
|
Filename
|
The directory to write the warped files to. |
required |
Returns:
| Type | Description |
|---|---|
list[Filename]
|
The warped filenames. |
Source code in src/dolphin/stitching.py
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 | |
merge_by_date(image_file_list, file_date_fmt=DEFAULT_DATETIME_FORMAT, output_dir='.', driver='GTiff', output_suffix='.tif', output_prefix='', out_nodata=0, in_nodata=None, out_bounds=None, out_bounds_epsg=None, resample_alg='lanczos', dest_epsg=None, options=io.DEFAULT_TIFF_OPTIONS, num_workers=1, overwrite=False)
Group images from the same datetime and merge into one image per datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_file_list
|
Iterable[Filename]
|
list of paths to images. |
required |
file_date_fmt
|
Optional[str]
|
Format of the datetime in the filename. Default is %Y%m%d |
DEFAULT_DATETIME_FORMAT
|
output_dir
|
Filename
|
Path to output directory |
'.'
|
driver
|
str
|
GDAL driver to use for output. Default is "GTiff" |
'GTiff'
|
output_suffix
|
str
|
Suffix to use to output stitched filenames. Default is ".tif" |
'.tif'
|
output_prefix
|
str
|
Prefix to use to output stitched filenames before the date. Default is "" |
''
|
out_nodata
|
Optional[float | str]
|
Nodata value to use for output file. Default is 0. |
0
|
in_nodata
|
Optional[float | str]
|
Override the files' |
None
|
out_bounds
|
Optional[Bbox]
|
if provided, forces the output image bounds to (left, bottom, right, top). Otherwise, computes from the outside of all input images. |
None
|
out_bounds_epsg
|
Optional[int]
|
EPSG code for the |
None
|
resample_alg
|
str
|
Resampling algorithm to use. Default is "lanczos". |
'lanczos'
|
dest_epsg
|
Optional[int]
|
EPSG code for the output projection. If None, finds the most common projection among the input files. |
None
|
options
|
Optional[Sequence[str]]
|
Driver-specific creation options passed to GDAL. Default is [dolphin.io.DEFAULT_TIFF_OPTIONS][]. |
DEFAULT_TIFF_OPTIONS
|
num_workers
|
int
|
Number of dates to stitch in separate threads in parallel. Default is 1. |
1
|
overwrite
|
bool
|
Overwrite existing files. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
key: the datetime of the SLC acquisitions/datetime pair of the interferogram. value: the path to the stitched image |
Notes
This function is intended to be used with filenames that contain datetime pairs (from interferograms).
Source code in src/dolphin/stitching.py
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 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 | |
merge_images(file_list, outfile, target_aligned_pixels=True, out_bounds=None, out_bounds_epsg=None, dest_epsg=None, strides=None, driver='GTiff', out_nodata=0, out_dtype=None, in_nodata=None, resample_alg='lanczos', overwrite=False, options=io.DEFAULT_TIFF_OPTIONS, create_only=False)
Combine multiple SLC images on the same date into one image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_list
|
list[Filename]
|
list of raster filenames |
required |
outfile
|
Filename
|
Path to output file |
required |
target_aligned_pixels
|
bool
|
If True, adjust output image bounds so that pixel coordinates
are integer multiples of pixel size, matching the |
True
|
out_bounds
|
Optional[Bbox]
|
if provided, forces the output image bounds to
(left, bottom, right, top).
Otherwise, computes from the outside of all input images.
Note that using |
None
|
out_bounds_epsg
|
Optional[int]
|
EPSG code for the |
None
|
dest_epsg
|
Optional[int]
|
EPSG code for the output projection. If None, finds the most common projection among the input files. |
None
|
strides
|
dict[str, int]
|
subsample factor: {"x": x strides, "y": y strides} |
None
|
driver
|
str
|
GDAL driver to use for output file. Default is GTiff. |
'GTiff'
|
out_nodata
|
Optional[float | str]
|
Nodata value to use for output file. Default is 0. |
0
|
out_dtype
|
Optional[DTypeLike]
|
Output data type. Default is None, which will use the data type of the first image in the list. |
None
|
in_nodata
|
Optional[float | str]
|
Override the files' |
None
|
resample_alg
|
str
|
Method for gdal to use for reprojection. Default is lanczos (sinc-kernel) |
"lanczos"
|
overwrite
|
bool
|
Overwrite existing files. Default is False. |
False
|
options
|
Optional[Sequence[str]]
|
Driver-specific creation options passed to GDAL. Default is [dolphin.io.DEFAULT_TIFF_OPTIONS][]. |
DEFAULT_TIFF_OPTIONS
|
create_only
|
bool
|
If True, creates an empty output file, does not write data. Default is False. |
False
|
Source code in src/dolphin/stitching.py
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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
warp_to_match(input_file, match_file, output_file=None, resample_alg='near', output_format=None)
Reproject input_file to align with the match_file.
Uses the bounds, resolution, and CRS of match_file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Filename
|
Path to the image to be reprojected. |
required |
match_file
|
Filename
|
Path to the input image to serve as a reference for the reprojected image. Uses the bounds, resolution, and CRS of this image. |
required |
output_file
|
Optional[Filename]
|
Path to the output, reprojected image.
If None, creates an in-memory warped VRT using the |
None
|
resample_alg
|
str
|
Resampling algorithm to be used during reprojection. See https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-r for choices. |
'near'
|
output_format
|
Optional[str]
|
Output format to be used for the output image.
If None, gdal will try to infer the format from the output file extension, or
(if the extension of |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the output image.
Same as |
Source code in src/dolphin/stitching.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 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 | |
warp_to_projection(filenames, dirname, projection, res=None, resample_alg='lanczos')
Warp a list of files to projection.
If the input file's projection matches projection, the same file is returned.
Otherwise, a new file is created in dirname with the same name as the input file,
but with '_warped' appended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filenames
|
Sequence[Filename]
|
list of filenames to warp. |
required |
dirname
|
Filename
|
The directory to write the warped files to. |
required |
projection
|
str
|
The desired projection, as a WKT string or 'EPSG:XXXX' string. |
required |
res
|
tuple[float, float]
|
The desired [x, y] resolution. |
None
|
resample_alg
|
str
|
Method for gdal to use for reprojection. Default is lanczos (sinc-kernel) |
"lanczos"
|
Returns:
| Type | Description |
|---|---|
list[Filename]
|
The warped filenames. |
Source code in src/dolphin/stitching.py
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 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |