From 2bc45e34f87f127fe7c596fbed8fdd0875a33f9c Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 14 Oct 2024 15:07:08 -0400 Subject: [PATCH 1/2] Add `outside_input_range` options to `get_nearest_date_idx` --- src/dolphin/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dolphin/utils.py b/src/dolphin/utils.py index 4505aba1..86098de5 100644 --- a/src/dolphin/utils.py +++ b/src/dolphin/utils.py @@ -11,7 +11,7 @@ from itertools import chain from multiprocessing import cpu_count from pathlib import Path -from typing import Any, Iterable, Optional, Sequence, Union +from typing import Any, Iterable, Literal, Optional, Sequence, Union import numpy as np from numpy.typing import ArrayLike, DTypeLike @@ -695,13 +695,19 @@ def map(self, fn: Callable[P, T], *iterables, **kwargs): # noqa: D102 def get_nearest_date_idx( input_items: Sequence[datetime.datetime], requested: datetime.datetime, + outside_input_range: Literal["allow", "warn", "raise"] = "warn", ) -> int: """Find the index nearest to `requested` within `input_items`.""" sorted_inputs = sorted(input_items) if not sorted_inputs[0] <= requested <= sorted_inputs[-1]: msg = f"Requested {requested} falls outside of input range: " msg += f"{sorted_inputs[0]}, {sorted_inputs[-1]}" - raise ValueError(msg) + if outside_input_range == "raise": + raise ValueError(msg) + elif outside_input_range == "warn": + warnings.warn(msg, stacklevel=2) + else: + pass nearest_idx = min( range(len(input_items)), From 561af42ac3dcb1629821a713f1bd355d191d90ba Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 14 Oct 2024 15:08:10 -0400 Subject: [PATCH 2/2] Skip `spurt` unwrapping steps if they exist --- src/dolphin/unwrap/_unwrap_3d.py | 5 +++++ src/dolphin/utils.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dolphin/unwrap/_unwrap_3d.py b/src/dolphin/unwrap/_unwrap_3d.py index cd7958aa..f721d699 100644 --- a/src/dolphin/unwrap/_unwrap_3d.py +++ b/src/dolphin/unwrap/_unwrap_3d.py @@ -45,6 +45,11 @@ def unwrap_spurt( unwrap_tiles, ) + if existing_unw_files := sorted(Path(output_path).glob(f"*{UNW_SUFFIX}")): + logger.info(f"Found {len(existing_unw_files)} unwrapped files") + existing_ccl_files = sorted(Path(output_path).glob(f"*{CONNCOMP_SUFFIX}")) + return existing_unw_files, existing_ccl_files + if cor_filenames is not None: assert len(ifg_filenames) == len(cor_filenames) if mask_filename is not None: diff --git a/src/dolphin/utils.py b/src/dolphin/utils.py index 86098de5..fc324433 100644 --- a/src/dolphin/utils.py +++ b/src/dolphin/utils.py @@ -695,7 +695,7 @@ def map(self, fn: Callable[P, T], *iterables, **kwargs): # noqa: D102 def get_nearest_date_idx( input_items: Sequence[datetime.datetime], requested: datetime.datetime, - outside_input_range: Literal["allow", "warn", "raise"] = "warn", + outside_input_range: Literal["allow", "warn", "raise"] = "raise", ) -> int: """Find the index nearest to `requested` within `input_items`.""" sorted_inputs = sorted(input_items)