Skip to content
Open
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
31 changes: 24 additions & 7 deletions src/dolphin/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion src/dolphin/workflows/displacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -278,6 +285,7 @@ def run(
else:
timeseries_paths = None
timeseries_residual_paths = None
nonzero_conncomp_count_paths = None
reference_point = None

# ##############################################
Expand Down Expand Up @@ -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,
Expand Down
Loading