diff --git a/src/dolphin/timeseries.py b/src/dolphin/timeseries.py index d3bf740e1..16cba0220 100644 --- a/src/dolphin/timeseries.py +++ b/src/dolphin/timeseries.py @@ -56,7 +56,7 @@ def run( wavelength: float | None = None, add_overviews: bool = True, extra_reference_date: datetime | None = None, -) -> tuple[list[Path], list[Path] | None, ReferencePoint]: +) -> tuple[list[Path], list[Path] | None, list[Path] | None, ReferencePoint]: """Invert the unwrapped interferograms, estimate timeseries and phase velocity. Parameters @@ -118,10 +118,13 @@ def run( Returns ------- inverted_phase_paths : list[Path] - list of Paths to inverted interferograms (single reference phase series). + List of Paths to inverted interferograms (single reference phase series). residual_paths : list[Path] | None - list of Paths to timeseries inversion residuals. - If no inversion is performed, this is be None. + List of Paths to timeseries inversion residuals. + If no inversion is performed, this is None. + nonzero_concomp_count_paths : list[Path] | None + List of Paths to counts of nonzero connected component labels after inversion + If no inversion is performed, or `conncomp_paths` is None, this is None. reference_point : ReferencePoint NamedTuple of reference (row, column) selected. If passed as input, simply returned back as output. @@ -184,6 +187,18 @@ def run( wavelength=wavelength, method=method, ) + + if conncomp_paths: + logger.info("Counting non-zero connected components after inversion") + nonzero_concomp_count_paths = create_nonzero_conncomp_counts( + conncomp_file_list=conncomp_paths, + output_dir=output_dir, + block_shape=block_shape, + num_threads=1, + ) + else: + nonzero_concomp_count_paths = None + if extra_reference_date is None: final_ts_paths = inverted_phase_paths final_residual_paths = residual_paths @@ -222,7 +237,7 @@ def run( num_threads=num_threads, ) - return final_ts_paths, final_residual_paths, ref_point + return final_ts_paths, final_residual_paths, nonzero_concomp_count_paths, ref_point def _redo_reference( @@ -1494,8 +1509,10 @@ def create_nonzero_conncomp_counts( ) # Create output paths for each date - suffix = "_valid_count.tif" - out_paths = [output_dir / f"{d.strftime('%Y%m%d')}{suffix}" for d in sar_dates] + out_paths = [ + output_dir / f"nonzero_conncomp_count_{d.strftime('%Y%m%d')}.tif" + for d in sar_dates + ] if all(p.exists() for p in out_paths): logger.info("All output files exist, skipping counting") diff --git a/src/dolphin/workflows/displacement.py b/src/dolphin/workflows/displacement.py index ffd0f733c..abd6c833d 100755 --- a/src/dolphin/workflows/displacement.py +++ b/src/dolphin/workflows/displacement.py @@ -40,6 +40,7 @@ class OutputPaths: conncomp_paths: list[Path] | None timeseries_paths: list[Path] | None timeseries_residual_paths: list[Path] | None + nonzero_conncomp_count_paths: list[Path] | None tropospheric_corrections: list[Path] | None ionospheric_corrections: list[Path] | None reference_point: ReferencePoint | None @@ -225,6 +226,7 @@ def run( conncomp_paths=None, timeseries_paths=None, timeseries_residual_paths=None, + nonzero_conncomp_count_paths=None, tropospheric_corrections=None, ionospheric_corrections=None, reference_point=None, @@ -254,7 +256,12 @@ def run( if ts_opts.run_inversion or ts_opts.run_velocity: # the output of run_timeseries is not currently used so pre-commit removes it # let's add back if we need it - timeseries_paths, timeseries_residual_paths, reference_point = timeseries.run( + ( + timeseries_paths, + timeseries_residual_paths, + nonzero_conncomp_count_paths, + reference_point, + ) = timeseries.run( unwrapped_paths=unwrapped_paths, conncomp_paths=conncomp_paths, corr_paths=stitched_paths.interferometric_corr_paths, @@ -278,6 +285,7 @@ def run( else: timeseries_paths = None timeseries_residual_paths = None + nonzero_conncomp_count_paths = None reference_point = None # ############################################## @@ -379,6 +387,7 @@ def run( conncomp_paths=conncomp_paths, timeseries_paths=timeseries_paths, timeseries_residual_paths=timeseries_residual_paths, + nonzero_conncomp_count_paths=nonzero_conncomp_count_paths, tropospheric_corrections=tropo_paths, ionospheric_corrections=iono_paths, reference_point=reference_point,