Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add outside_input_range options to get_nearest_date_idx #450

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dolphin/unwrap/_unwrap_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions src/dolphin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"] = "raise",
) -> 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)),
Expand Down