darts_acquisition.utils.arosics
¶
Re-implementation of the AROSICS algorithm.
MultiOffsetInfo
dataclass
¶
MultiOffsetInfo(
x_offset: float | None,
y_offset: float | None,
avg_reliability: float | None,
avg_ssim_improvement: float | None,
offset_reduce_method: typing.Literal[
"mean", "weighted_mean", "best"
]
| None,
offset_infos: dict[
str, darts_acquisition.utils.arosics.OffsetInfo
],
)
Dataclass to hold offset information of multiple bands.
offset_infos
instance-attribute
¶
offset_infos: dict[
str, darts_acquisition.utils.arosics.OffsetInfo
]
offset_reduce_method
instance-attribute
¶
is_valid
¶
to_dataframe
¶
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
OffsetInfo
dataclass
¶
OffsetInfo(
x_offset: float | None,
y_offset: float | None,
ssim_before: float | None = None,
ssim_after: float | None = None,
shift_reliability: float = 0.0,
)
Dataclass to hold offset information.
is_valid
¶
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_calc_shift_reliability
¶
_calc_shift_reliability(
shifted_cross_power_spectrum: xarray.DataArray,
x_peak: int,
y_peak: int,
) -> float
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_calc_ssim
¶
_calc_ssim(
target: xarray.DataArray,
reference: xarray.DataArray,
subset: dict[typing.Literal["x", "y"], slice]
| typing.Literal[False],
) -> float
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_calculate_offset
¶
_calculate_offset(
reference: xarray.DataArray,
target: xarray.DataArray,
subset: dict[typing.Literal["x", "y"], slice]
| typing.Literal[False] = False,
max_iter: int = 5,
) -> darts_acquisition.utils.arosics.OffsetInfo
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
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 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 | |
_calculate_scps
¶
_calculate_scps(
reference_window: xarray.DataArray,
target_window: xarray.DataArray,
) -> xarray.DataArray
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_find_suitable_subset_slices
¶
_find_suitable_subset_slices(
target: xarray.Dataset | xarray.DataArray,
reference: xarray.Dataset | xarray.DataArray,
window_size: int = 256,
target_mask: xarray.DataArray | None = None,
reference_mask: xarray.DataArray | None = None,
max_invalid_ratio: float = 0.01,
) -> (
dict[typing.Literal["x", "y"], slice]
| typing.Literal[False]
)
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_get_bands
¶
_get_bands(
target: xarray.Dataset,
reference: xarray.Dataset,
bands: list[str]
| typing.Literal["multiband"]
| str = "multiband",
) -> list[str]
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_get_window_subsets
¶
_get_window_subsets(
target: xarray.DataArray,
reference: xarray.DataArray,
subset: dict[typing.Literal["x", "y"], slice]
| typing.Literal[False],
) -> tuple[xarray.DataArray, xarray.DataArray]
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
_validate_subset
¶
_validate_subset(
subset: xarray.DataArray | xarray.Dataset,
mask: xarray.DataArray | None = None,
max_invalid_ratio: float = 0.01,
) -> bool
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
align
¶
align(
target: xarray.Dataset | xarray.DataArray,
reference: xarray.Dataset | xarray.DataArray,
bands: list[str]
| typing.Literal["multiband"]
| str = "multiband",
subset: dict[typing.Literal["x", "y"], slice]
| typing.Literal[False]
| None = None,
window_size: int = 256,
target_mask: xarray.DataArray | None = None,
reference_mask: xarray.DataArray | None = None,
max_invalid_ratio: float = 0.01,
max_iter: int = 5,
min_reliability: float = 30.0,
max_offset: float = 10.0,
resample_to: typing.Literal["reference", "target"]
| None = None,
return_offset: bool = False,
round_axes: int | typing.Literal[False] = 3,
inplace: bool = False,
) -> (
tuple[
xarray.Dataset | xarray.DataArray,
darts_acquisition.utils.arosics.OffsetInfo
| darts_acquisition.utils.arosics.MultiOffsetInfo,
]
| xarray.Dataset
| xarray.DataArray
)
Align a target to an reference using the AROSICS algorithm.
Note
Assumes that the target and reference datasets have the same dimensions.
Parameters:
-
target(xarray.Dataset | xarray.DataArray) –The target image dataset or dataarray to be aligned.
-
reference(xarray.Dataset | xarray.DataArray) –The reference image dataset or dataarray.
-
bands(list[str] | typing.Literal['multiband'] | str, default:'multiband') –The bands to use for alignment. Only used if the target and reference are datasets. If "multiband", all bands are used. This expects the target and reference datasets to have the same band names. If string, the respective band is used for alignment. If a list of strings, only the specified bands are used for alignment. Note: All bands are shifted by the same offset, even when using "multiband". With multiband, the offset is calculated from the average of all common and valid band offsets. This is slower but more robust than using a single band. If a band-specific offset is desired, please use the
get_dataarray_offsetsfunction for each band separately. Defaults to "multiband". -
subset(dict[typing.Literal['x', 'y'], slice] | typing.Literal[False] | None, default:None) –A dictionary of slices to use for alignment. If provided, only the specified subset of the target and reference datasets is used for alignment. The dictionary must contain the keys "x" and "y" with the respective slices. If False, the whole dataset is used for alignment. If None, will try to find a suitable subset automatically.
-
window_size(int, default:256) –The size of the window to use for alignment in case no subset is provided. Defaults to 256.
-
target_mask(xarray.DataArray | None, default:None) –A mask for the target dataset. If provided, searches for a valid subset of the target dataset where the mask is True. If not provided, a mask is automatically inferred from the nodata value of the target dataset. Defaults to None.
-
reference_mask(xarray.DataArray | None, default:None) –A mask for the reference dataset. If provided, searches for a valid subset of the reference dataset where the mask is True. If not provided, a mask is automatically inferred from the nodata value of the reference dataset. Defaults to None.
-
max_invalid_ratio(float, default:0.01) –The maximum ratio of invalid pixels in the target and reference subset masks. Is not used if the masks are not provided. Defaults to 0.01.
-
max_iter(int, default:5) –The maximum number of iterations to find the offset. Defaults to 5.
-
min_reliability(float, default:30.0) –The minimum reliability (in %) of the offset to consider it valid. Defaults to 30.0.
-
max_offset(float, default:10.0) –The maximum offset in pixels to consider the offset valid. Defaults to 10.0.
-
resample_to(typing.Literal['reference', 'target'] | None, default:None) –The dataset to resample the other dataset to. If "reference", the target dataset is resampled to the reference dataset. If "target", the reference dataset is resampled to the target dataset. Defaults to None. If None, no resampling is done. This assumes that the pixel grids of the target and reference datasets are already aligned.
-
round_axes(int | False, default:3) –The number of decimal places to round the x and y coordinates of the target dataset. This may be necessary if the applying of offsets results in very small floating point errors that lead to misalignment when using further processing steps. If False, no rounding is done. Defaults to 3.
-
return_offset(bool, default:False) –If True, returns the offsets instead of aligning the target dataset.
-
inplace(bool, default:False) –If True, modifies the target dataset in place.
Returns:
-
tuple[xarray.Dataset | xarray.DataArray, darts_acquisition.utils.arosics.OffsetInfo | darts_acquisition.utils.arosics.MultiOffsetInfo] | xarray.Dataset | xarray.DataArray–tuple[xr.Dataset | xr.DataArray, OffsetInfo | MultiOffsetInfo] | xr.Dataset | xr.DataArray: The aligned target dataset or dataarray. If return_offset is True, also returns the offsets in x and y direction as a tuple.
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 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 | |
get_offsets
¶
get_offsets(
target: xarray.Dataset | xarray.DataArray,
reference: xarray.Dataset | xarray.DataArray,
bands: list[str]
| typing.Literal["multiband"]
| str = "multiband",
subset: dict[typing.Literal["x", "y"], slice]
| typing.Literal[False]
| None = None,
window_size: int = 256,
target_mask: xarray.DataArray | None = None,
reference_mask: xarray.DataArray | None = None,
max_invalid_ratio: float = 0.01,
max_iter: int = 5,
min_reliability: float = 30.0,
max_offset: float = 10.0,
resample_to: typing.Literal["reference", "target"]
| None = None,
) -> (
darts_acquisition.utils.arosics.OffsetInfo
| darts_acquisition.utils.arosics.MultiOffsetInfo
)
Get the offsets between a target and a reference using the AROSICS algorithm.
Note
Assumes that the target and reference datasets have the same dimensions.
Parameters:
-
target(xarray.Dataset | xarray.DataArray) –The target image dataset or dataarray to be aligned.
-
reference(xarray.Dataset | xarray.DataArray) –The reference image dataset or dataarray.
-
bands(list[str] | typing.Literal['multiband'] | str, default:'multiband') –The bands to use for alignment. Only used if the target and reference are datasets. If "multiband", all bands are used. This expects the target and reference datasets to have the same band names. If string, the respective band is used for alignment. If a list of strings, only the specified bands are used for alignment. Note: All bands are shifted by the same offset, even when using "multiband". With multiband, the offset is calculated from the average of all common and valid band offsets. This is slower but more robust than using a single band. If a band-specific offset is desired, please use the
get_dataarray_offsetsfunction for each band separately. Defaults to "multiband". -
subset(dict[typing.Literal['x', 'y'], slice] | typing.Literal[False] | None, default:None) –A dictionary of slices to use for alignment. If provided, only the specified subset of the target and reference datasets is used for alignment. The dictionary must contain the keys "x" and "y" with the respective slices. If False, the whole dataset is used for alignment. If None, will try to find a suitable subset automatically.
-
window_size(int, default:256) –The size of the window to use for alignment in case no subset is provided. Defaults to 256.
-
target_mask(xarray.DataArray | None, default:None) –A mask for the target dataset. If provided, searches for a valid subset of the target dataset where the mask is True. If not provided, a mask is automatically inferred from the nodata value of the target dataset. Defaults to None.
-
reference_mask(xarray.DataArray | None, default:None) –A mask for the reference dataset. If provided, searches for a valid subset of the reference dataset where the mask is True. If not provided, a mask is automatically inferred from the nodata value of the reference dataset. Defaults to None.
-
max_invalid_ratio(float, default:0.01) –The maximum ratio of invalid pixels in the target and reference subset masks. Is not used if the masks are not provided. Defaults to 0.01.
-
max_iter(int, default:5) –The maximum number of iterations to find the offset. Defaults to 5.
-
min_reliability(float, default:30.0) –The minimum reliability (in %) of the offset to consider it valid. Defaults to 30.0.
-
max_offset(float, default:10.0) –The maximum offset in pixels to consider the offset valid. Defaults to 10.0.
-
resample_to(typing.Literal['reference', 'target'] | None, default:None) –The dataset to resample the other dataset to. If "reference", the target dataset is resampled to the reference dataset. If "target", the reference dataset is resampled to the target dataset. Defaults to None. If None, no resampling is done. This assumes that the pixel grids of the target and reference datasets are already aligned.
Returns:
-
darts_acquisition.utils.arosics.OffsetInfo | darts_acquisition.utils.arosics.MultiOffsetInfo–OffsetInfo | MultiOffsetInfo: The offsets in x and y direction between the target and reference datasets.
Raises:
-
ValueError–If the target and reference are not both datasets or dataarrays.
-
ValueError–If no suitable subset is found for alignment. This can happen if the window_size is too large or if the masks are too restrictive.
Source code in darts-acquisition/src/darts_acquisition/utils/arosics.py
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 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 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 | |