Skip to content

Commit c1ef8e2

Browse files
scottstanieclaude
andauthored
Fix/propagate cslc date fmt to ministack (#710)
* fix(stack): propagate cslc_date_fmt to ministack output filenames When run_wrapped_phase_sequential is invoked with a non-default cslc_date_fmt (e.g. "%Y%m%d%H%M%S" for non-SSO cadences with same-day repeats), the date format was not forwarded to MiniStackPlanner. As a result, phase-linked SLCs and CRLB rasters were written using the default "%Y%m%d", and create_ifgs in wrapped_phase later raised IndexError trying to extract dates from those filenames with the caller's longer format. Two complementary fixes: 1. sequential.py: pass file_date_fmt=cslc_date_fmt when constructing MiniStackPlanner. 2. stack.py: in MiniStackPlanner.plan(), forward self.file_date_fmt to each MiniStackInfo it creates. The planner already accepted the field but did not propagate it to its children. With both in place, _name_slcs / _name_crlbs produce filenames that preserve the time-of-day component, and create_ifgs can parse them back round-trip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(interferogram): propagate cslc_date_fmt to ifg VRT filenames After the prior commit, phase-linked SLCs were written with the caller's cslc_date_fmt (e.g. "%Y%m%d%H%M%S"), but the interferogram VRT names were still hardcoded to "%Y%m%d" because Network and convert_pl_to_ifg default to that format. The resulting "%Y%m%d_%Y%m%d.int.vrt" filenames then failed downstream stitching: stitching_bursts.run calls merge_by_date with file_date_fmt=cslc_date_fmt, the long-format regex matches no dates in the date-only filenames, and merge_images either groups all ifgs together or builds a clip window with negative dimensions ("Computed -srcwin ... has negative width and/or height"). Forward file_date_fmt into: - interferogram.Network(...) constructions in create_ifgs (3 sites) - interferogram.VRTInterferogram(...) construction for the extra-ref case - interferogram.convert_pl_to_ifg(...) (2 sites) convert_pl_to_ifg now accepts a date_format parameter (default unchanged for backward compatibility) and uses it for both date extraction from the input SLC name and output filename formatting. With this and the prior MiniStack propagation in place, IFG VRT filenames preserve the time-of-day component end-to-end and downstream merge_by_date round-trips correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Tests added, new fix emerged in stitching * fix(unwrap): propagate cslc_date_fmt to spurt --date-fmt flag Spurt's emcf workflow now accepts a --date-fmt CLI flag (default "%Y%m%d") that controls how acquisition dates are extracted from SLC filenames and written into unwrapped output filenames. Without forwarding the caller's cslc_date_fmt, dolphin's spurt subprocess used the default %Y%m%d slice and same-day acquisitions collapsed to a single date in the output (e.g. 20240709_20240709.unw.tif), losing the time-of-day component already preserved in the upstream ifg names. Thread file_date_fmt: str = "%Y%m%d" through: - unwrap_spurt: append "--date-fmt <fmt>" to the spurt subprocess command, and forward to filled_masked_unw_regions for the ambiguity-interpolation gap-fill step (which already accepted the parameter but was being called with the default). - unwrap.run: forward into unwrap_spurt. - workflows.unwrapping.run: forward into unwrap.run. - workflows.displacement.run: pass cfg.input_options.cslc_date_fmt into unwrapping.run. With this in place, e.g. cslc_date_fmt="%Y%m%d%H%M%S" produces spurt outputs like 20240709040329_20240712025153.unw.tif round-trippable end-to-end. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(timeseries): propagate cslc_date_fmt to inverted/residual filenames timeseries.run already accepted file_date_fmt, but it was not being forwarded from displacement.run, and several internal call sites ignored it. As a result, with cslc_date_fmt="%Y%m%d%H%M%S" the upstream stages produced ifg/unw filenames with time-of-day, but the timeseries/ outputs collapsed back to %Y%m%d (e.g. 20251002_20251005.tif), losing the disambiguation that motivated the custom format in the first place. Forward file_date_fmt at five sites: - displacement.run: pass cfg.input_options.cslc_date_fmt into timeseries.run. - timeseries.run -> invert_unw_network: forward file_date_fmt (the callee accepted but the caller did not pass it). - _redo_reference: pass fmt=file_date_fmt into format_dates when building the re-referenced filenames for extra_reference_date. - invert_unw_network: pass fmt=file_date_fmt into both format_dates calls that build out_paths and out_residuals_paths. - create_nonzero_conncomp_counts: replace hardcoded d.strftime('%Y%m%d') with d.strftime(file_date_fmt) (the function already exposed the parameter). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c2f7c24 commit c1ef8e2

11 files changed

Lines changed: 112 additions & 9 deletions

File tree

‎src/dolphin/interferogram.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ def convert_pl_to_ifg(
774774
reference_date: DateOrDatetime,
775775
output_dir: Filename,
776776
dry_run: bool = False,
777+
date_format: str = io.DEFAULT_DATETIME_FORMAT,
777778
) -> Path:
778779
"""Convert a phase-linked SLC to an interferogram by conjugating the phase.
779780
@@ -793,6 +794,11 @@ def convert_pl_to_ifg(
793794
Default = False (the ifgs will be created/written to disk.)
794795
`dry_run=True` is used to plan out which ifgs will be formed
795796
before actually running the workflow.
797+
date_format : str, optional
798+
``strptime``-compatible format used both to parse the date from
799+
``phase_linked_slc`` and to format the output filename. Must match
800+
the format of the input filename so the time-of-day component is
801+
preserved when callers use formats like ``"%Y%m%d%H%M%S"``.
796802
797803
Returns
798804
-------
@@ -802,8 +808,8 @@ def convert_pl_to_ifg(
802808
"""
803809
# The phase_linked_slc will be named with the secondary date.
804810
# Make the output from that, plus the given reference date
805-
secondary_date = get_dates(phase_linked_slc)[-1]
806-
date_str = utils.format_date_pair(reference_date, secondary_date)
811+
secondary_date = get_dates(phase_linked_slc, fmt=date_format)[-1]
812+
date_str = utils.format_date_pair(reference_date, secondary_date, fmt=date_format)
807813
out_name = Path(output_dir) / f"{date_str}.int.vrt"
808814
if dry_run:
809815
return out_name

‎src/dolphin/stack.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def plan(
547547
output_reference_idx=output_reference_idx,
548548
compressed_reference_idx=compressed_reference_idx,
549549
output_folder=cur_output_folder,
550+
file_date_fmt=self.file_date_fmt,
550551
)
551552

552553
output_ministacks.append(cur_ministack)

‎src/dolphin/stitching.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def merge_by_date(
110110

111111
for dates, cur_images in grouped_images.items():
112112
logger.info(f"{dates}: Stitching {len(cur_images)} images.")
113-
date_str = utils.format_dates(*dates)
113+
date_str = utils.format_dates(*dates, fmt=file_date_fmt)
114114
# If we passed files where different dates have different prefixes,
115115
# we need to use the common prefix before the first date token
116116
# e.g. if we have "temporal_coherence_<dates>,...

‎src/dolphin/timeseries.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def run(
215215
wavelength=wavelength,
216216
method=method,
217217
bad_pixel_mask=bad_pixel_mask,
218+
file_date_fmt=file_date_fmt,
218219
)
219220
if extra_reference_date is None:
220221
final_ts_paths = inverted_phase_paths
@@ -309,7 +310,7 @@ def _redo_reference(
309310
# To create the interferogram (r, r+1), we subtract
310311
# (1, r) from (1, r+1)
311312
cur_img = inverted_phase_paths[idx]
312-
new_stem = format_dates(ref_date, secondary_dates[idx])
313+
new_stem = format_dates(ref_date, secondary_dates[idx], fmt=file_date_fmt)
313314
cur_output_name = extra_out_dir / f"{new_stem}.tif"
314315
cur = io.load_gdal(cur_img, masked=True)
315316
new_out = cur - ref
@@ -1046,10 +1047,12 @@ def invert_unw_network(
10461047
suffix = ".tif"
10471048
# Create the `n_sar_dates - 1` output files (skipping the 0 reference raster)
10481049
out_paths = [
1049-
Path(output_dir) / f"{format_dates(ref_date, d)}{suffix}" for d in sar_dates[1:]
1050+
Path(output_dir) / f"{format_dates(ref_date, d, fmt=file_date_fmt)}{suffix}"
1051+
for d in sar_dates[1:]
10501052
]
10511053
out_residuals_paths = [
1052-
Path(output_dir) / f"residuals_{format_dates(ref_date, d)}{suffix}"
1054+
Path(output_dir)
1055+
/ f"residuals_{format_dates(ref_date, d, fmt=file_date_fmt)}{suffix}"
10531056
for d in sar_dates[1:]
10541057
]
10551058
if all(p.exists() for p in out_paths):
@@ -1585,7 +1588,7 @@ def create_nonzero_conncomp_counts(
15851588

15861589
# Create output paths for each date
15871590
suffix = "_valid_count.tif"
1588-
out_paths = [output_dir / f"{d.strftime('%Y%m%d')}{suffix}" for d in sar_dates]
1591+
out_paths = [output_dir / f"{d.strftime(file_date_fmt)}{suffix}" for d in sar_dates]
15891592

15901593
if all(p.exists() for p in out_paths):
15911594
logger.info("All output files exist, skipping counting")

‎src/dolphin/unwrap/_unwrap.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def run(
8686
scratchdir: PathOrStr | None = None,
8787
delete_intermediate: bool = True,
8888
overwrite: bool = False,
89+
file_date_fmt: str = "%Y%m%d",
8990
) -> tuple[list[Path], list[Path]]:
9091
"""Run snaphu on all interferograms in a directory.
9192
@@ -125,6 +126,10 @@ def run(
125126
Must specify `scratchdir` for this option to be used.
126127
overwrite : bool, optional, default = False
127128
Overwrite existing unwrapped files.
129+
file_date_fmt : str, optional
130+
The strftime format used to parse acquisition dates from input
131+
filenames and to write the date portion of output filenames.
132+
Default is "%Y%m%d".
128133
129134
Returns
130135
-------
@@ -160,6 +165,7 @@ def run(
160165
mask_filename=mask_filename,
161166
options=unwrap_options.spurt_options,
162167
scratchdir=scratchdir,
168+
file_date_fmt=file_date_fmt,
163169
)
164170
for f in unw_paths:
165171
io.set_raster_units(f, "radians")

‎src/dolphin/unwrap/_unwrap_3d.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def unwrap_spurt(
3636
options: SpurtOptions = DEFAULT_OPTIONS,
3737
scratchdir: PathOrStr | None = None,
3838
num_retries: int = 3,
39+
file_date_fmt: str = "%Y%m%d",
3940
) -> tuple[list[Path], list[Path]]:
4041
"""Perform 3D unwrapping using `spurt` via subprocess call."""
4142
# NOTE: we are working around spurt currently wanting "temporal_coherence.tif",
@@ -86,6 +87,8 @@ def unwrap_spurt(
8687
str(scratch_path / "emcf_tmp"),
8788
"-c",
8889
str(0.5), # arbitrary, since we are passing a 0/1 file anyway
90+
"--date-fmt",
91+
file_date_fmt,
8992
]
9093
if not options.general_settings.use_tiles:
9194
cmd.append("--singletile")
@@ -157,7 +160,9 @@ def run_with_retry(cmd: list[str], num_retries: int = 3) -> int:
157160
)
158161

159162
if options.run_ambiguity_interpolation:
160-
filled_masked_unw_regions(unw_filenames, ifg_filenames)
163+
filled_masked_unw_regions(
164+
unw_filenames, ifg_filenames, file_date_fmt=file_date_fmt
165+
)
161166
return unw_filenames, conncomp_filenames
162167

163168

‎src/dolphin/workflows/displacement.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ def run(
427427
nlooks=nlooks,
428428
unwrap_options=cfg.unwrap_options,
429429
mask_file=cfg.mask_file,
430+
file_date_fmt=cfg.input_options.cslc_date_fmt,
430431
)
431432

432433
# ##############################################
@@ -459,6 +460,7 @@ def run(
459460
wavelength=cfg.input_options.wavelength,
460461
add_overviews=cfg.output_options.add_overviews,
461462
extra_reference_date=cfg.output_options.extra_reference_date,
463+
file_date_fmt=cfg.input_options.cslc_date_fmt,
462464
)
463465

464466
else:

‎src/dolphin/workflows/sequential.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def run_wrapped_phase_sequential(
7777
max_num_compressed=max_num_compressed,
7878
output_reference_idx=output_reference_idx,
7979
compressed_slc_plan=compressed_slc_plan,
80+
# Propagate the caller's date format so phase-linked SLC and CRLB
81+
# filenames preserve any time-of-day component. Without this, output
82+
# filenames are written with the default ``%Y%m%d`` and ``create_ifgs``
83+
# later fails to extract dates when ``cslc_date_fmt`` includes hours
84+
# (e.g. ``%Y%m%d%H%M%S`` for non-SSO cadences with same-day repeats).
85+
file_date_fmt=cslc_date_fmt,
8086
)
8187
ministacks = ministack_planner.plan(
8288
ministack_size, compressed_idx=new_compressed_reference_idx

‎src/dolphin/workflows/unwrapping.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def run(
2727
similarity_filename: Path | str | None = None,
2828
mask_file: Path | str | None = None,
2929
add_overviews: bool = True,
30+
file_date_fmt: str = "%Y%m%d",
3031
) -> tuple[list[Path], list[Path]]:
3132
"""Run the displacement workflow on a stack of SLCs.
3233
@@ -51,6 +52,10 @@ def run(
5152
add_overviews : bool, default = True
5253
If True, creates overviews of the unwrapped phase and connected component
5354
labels.
55+
file_date_fmt : str, optional
56+
The strftime format used to parse acquisition dates from input
57+
filenames and to write the date portion of output filenames.
58+
Default is "%Y%m%d".
5459
5560
Returns
5661
-------
@@ -92,6 +97,7 @@ def run(
9297
similarity_filename=similarity_filename,
9398
mask_filename=output_mask,
9499
scratchdir=unwrap_scratchdir,
100+
file_date_fmt=file_date_fmt,
95101
)
96102

97103
if add_overviews:

‎src/dolphin/workflows/wrapped_phase.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ def create_ifgs(
407407
outdir=ifg_dir,
408408
write=not dry_run,
409409
verify_slcs=not dry_run,
410+
date_format=file_date_fmt,
410411
)
411412
if len(network.ifg_list) == 0:
412413
msg = "No interferograms were created"
@@ -426,7 +427,11 @@ def create_ifgs(
426427
# a `.conj()` on the phase-linked SLCs (currently `day1.conj() * day2`)
427428
single_ref_ifgs = [
428429
interferogram.convert_pl_to_ifg(
429-
f, reference_date=reference_date, output_dir=ifg_dir, dry_run=dry_run
430+
f,
431+
reference_date=reference_date,
432+
output_dir=ifg_dir,
433+
dry_run=dry_run,
434+
date_format=file_date_fmt,
430435
)
431436
for f in phase_linked_slcs
432437
]
@@ -441,6 +446,7 @@ def create_ifgs(
441446
reference_date=reference_date, # this is the `phase_linking.output_idx`
442447
output_dir=ifg_dir,
443448
dry_run=dry_run,
449+
date_format=file_date_fmt,
444450
)
445451
for f in phase_linked_slcs[: manual_reference_idx + 1]
446452
]
@@ -453,6 +459,7 @@ def create_ifgs(
453459
outdir=ifg_dir,
454460
write=not dry_run,
455461
verify_slcs=not dry_run,
462+
date_format=file_date_fmt,
456463
)
457464
single_ref_ifgs.append(v.path) # type: ignore[arg-type]
458465

@@ -479,6 +486,7 @@ def create_ifgs(
479486
dates=secondary_dates,
480487
write=not dry_run,
481488
verify_slcs=not dry_run,
489+
date_format=file_date_fmt,
482490
)
483491
# Using `cast` to assert that the paths are not None
484492
if len(network.ifg_list) == 0:
@@ -502,6 +510,7 @@ def create_ifgs(
502510
dates=secondary_dates,
503511
write=not dry_run,
504512
verify_slcs=not dry_run,
513+
date_format=file_date_fmt,
505514
)
506515
# Using `cast` to assert that the paths are not None
507516
ifgs_others = cast(list[Path], [ifg.path for ifg in network_rest.ifg_list])

0 commit comments

Comments
 (0)