From 2ef8204525a4b19bbacaab55e62cd62d33c461fd Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 21 Oct 2024 17:59:30 -0700 Subject: [PATCH] Only do nearest-3 similarity if were unwrapping short baseline --- src/dolphin/workflows/sequential.py | 5 ++++- src/dolphin/workflows/single.py | 3 ++- src/dolphin/workflows/wrapped_phase.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/dolphin/workflows/sequential.py b/src/dolphin/workflows/sequential.py index 600209b5..8800c766 100644 --- a/src/dolphin/workflows/sequential.py +++ b/src/dolphin/workflows/sequential.py @@ -45,6 +45,7 @@ def run_wrapped_phase_sequential( shp_nslc: Optional[int] = None, use_evd: bool = False, beta: float = 0.00, + similarity_nearest_n: int | None = None, compressed_slc_plan: CompressedSlcPlan = CompressedSlcPlan.ALWAYS_FIRST, max_num_compressed: int = 100, output_reference_idx: int = 0, @@ -129,6 +130,7 @@ def already_processed(d: Path, search_ext: str = ".tif") -> bool: shp_method=shp_method, shp_alpha=shp_alpha, shp_nslc=shp_nslc, + similarity_nearest_n=similarity_nearest_n, block_shape=block_shape, baseline_lag=baseline_lag, **tqdm_kwargs, @@ -169,8 +171,9 @@ def already_processed(d: Path, search_ext: str = ".tif") -> bool: search_radius=11, sim_type="median", block_shape=block_shape, - nearest_n=3, + nearest_n=similarity_nearest_n, num_threads=2, + add_overviews=False, ) else: output_similarity_file = similarity_files[0].rename( diff --git a/src/dolphin/workflows/single.py b/src/dolphin/workflows/single.py index 53979dfa..a319342a 100644 --- a/src/dolphin/workflows/single.py +++ b/src/dolphin/workflows/single.py @@ -52,6 +52,7 @@ def run_wrapped_phase_single( shp_method: ShpMethod = ShpMethod.NONE, shp_alpha: float = 0.05, shp_nslc: Optional[int] = None, + similarity_nearest_n: int | None = None, block_shape: tuple[int, int] = (1024, 1024), baseline_lag: Optional[int] = None, **tqdm_kwargs, @@ -298,7 +299,7 @@ def run_wrapped_phase_single( output_file=output_folder / f"similarity_{start_end}.tif", num_threads=2, add_overviews=False, - nearest_n=3, + nearest_n=similarity_nearest_n, ) written_comp_slc = output_files[0] diff --git a/src/dolphin/workflows/wrapped_phase.py b/src/dolphin/workflows/wrapped_phase.py index 01c89195..3a8b6070 100644 --- a/src/dolphin/workflows/wrapped_phase.py +++ b/src/dolphin/workflows/wrapped_phase.py @@ -159,6 +159,13 @@ def run( logger.info(f"Running sequential EMI step in {pl_path}") kwargs = tqdm_kwargs | {"desc": f"Phase linking ({pl_path})"} + # Figure out if we should compute phase similarity based on single-ref, + # or using nearest-3 interferograms + is_single_ref = _is_single_reference_network( + cfg.interferogram_network, cfg.unwrap_options.unwrap_method + ) + similarity_nearest_n = None if is_single_ref else 3 + # TODO: Need a good way to store the nslc attribute in the PS file... # If we pre-compute it from some big stack, we need to use that for SHP # finding, not use the size of `slc_vrt_file` @@ -186,6 +193,7 @@ def run( shp_method=cfg.phase_linking.shp_method, shp_alpha=cfg.phase_linking.shp_alpha, shp_nslc=shp_nslc, + similarity_nearest_n=similarity_nearest_n, cslc_date_fmt=cfg.input_options.cslc_date_fmt, block_shape=cfg.worker_settings.block_shape, baseline_lag=cfg.phase_linking.baseline_lag, @@ -496,3 +504,13 @@ def _get_mask( mask_filename = nodata_mask_file return mask_filename + + +def _is_single_reference_network( + ifg_network: InterferogramNetwork, unwrap_method: UnwrapMethod +): + return ( + unwrap_method != UnwrapMethod.SPURT + and ifg_network.max_bandwidth is None + and ifg_network.max_temporal_baseline is None + )