PyGeoFetch 2.7.0.7__py3-none-any.whl → 2.7.0.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pygeofetch/__init__.py +1 -1
- pygeofetch/insar/interferogram.py +302 -51
- pygeofetch/insar/workflow.py +213 -7
- pygeofetch/meta.yaml +1 -1
- pygeofetch/sar/extraction.py +531 -4
- {pygeofetch-2.7.0.7.dist-info → pygeofetch-2.7.0.9.dist-info}/METADATA +2 -2
- {pygeofetch-2.7.0.7.dist-info → pygeofetch-2.7.0.9.dist-info}/RECORD +11 -42
- pygeofetch-2.7.0.9.dist-info/top_level.txt +1 -0
- pygeofetch-2.7.0.7.dist-info/top_level.txt +0 -6
- pygeofetch_crop_fix_part8/pygeofetch/insar/coregister.py +0 -1659
- pygeofetch_crop_fix_part8/pygeofetch/insar/esd.py +0 -752
- pygeofetch_crop_fix_part8/pygeofetch/insar/extraction.py +0 -986
- pygeofetch_crop_fix_part8/pygeofetch/insar/interferogram.py +0 -3729
- pygeofetch_crop_fix_part8/pygeofetch/insar/tops.py +0 -416
- pygeofetch_crop_fix_part8/tests/insar/test_crop_offset.py +0 -85
- pygeofetch_crop_fix_part8/tests/insar/test_tops_deramp.py +0 -236
- pygeofetch_tops_fix_part4/files/pygeofetch/insar/coregister.py +0 -1648
- pygeofetch_tops_fix_part4/files/pygeofetch/insar/interferogram.py +0 -3583
- pygeofetch_tops_fix_part4/files/pygeofetch/insar/tops.py +0 -374
- pygeofetch_tops_fix_part4/files/tests/insar/_fake_safe.py +0 -70
- pygeofetch_tops_fix_part4/files/tests/insar/_tops_sim.py +0 -93
- pygeofetch_tops_fix_part4/files/tests/insar/test_tops_deramp.py +0 -177
- pygeofetch_tops_fix_part5/files/pygeofetch/insar/coregister.py +0 -1648
- pygeofetch_tops_fix_part5/files/pygeofetch/insar/interferogram.py +0 -3611
- pygeofetch_tops_fix_part5/files/pygeofetch/insar/tops.py +0 -374
- pygeofetch_tops_fix_part5/files/tests/insar/_fake_safe.py +0 -70
- pygeofetch_tops_fix_part5/files/tests/insar/_tops_sim.py +0 -93
- pygeofetch_tops_fix_part5/files/tests/insar/test_tops_deramp.py +0 -177
- pygeofetch_tops_fix_part6/pygeofetch/insar/esd.py +0 -752
- pygeofetch_tops_fix_part6/pygeofetch/insar/interferogram.py +0 -3684
- pygeofetch_tops_fix_part6/pygeofetch/insar/tops.py +0 -416
- pygeofetch_tops_fix_part6/tests/insar/_fake_safe.py +0 -70
- pygeofetch_tops_fix_part6/tests/insar/_tops_sim.py +0 -93
- pygeofetch_tops_fix_part6/tests/insar/test_tops_deramp.py +0 -218
- pygeofetch_tops_fix_part7/pygeofetch/insar/esd.py +0 -752
- pygeofetch_tops_fix_part7/pygeofetch/insar/interferogram.py +0 -3728
- pygeofetch_tops_fix_part7/pygeofetch/insar/tops.py +0 -416
- pygeofetch_tops_fix_part7/tests/insar/_fake_safe.py +0 -70
- pygeofetch_tops_fix_part7/tests/insar/_tops_sim.py +0 -93
- pygeofetch_tops_fix_part7/tests/insar/test_tops_deramp.py +0 -236
- {pygeofetch-2.7.0.7.dist-info → pygeofetch-2.7.0.9.dist-info}/WHEEL +0 -0
- {pygeofetch-2.7.0.7.dist-info → pygeofetch-2.7.0.9.dist-info}/entry_points.txt +0 -0
- {pygeofetch-2.7.0.7.dist-info → pygeofetch-2.7.0.9.dist-info}/licenses/LICENSE +0 -0
pygeofetch/__init__.py
CHANGED
|
@@ -202,6 +202,138 @@ def make_fingerprint(arguments: Dict[str, Any], settings: Dict[str, Any]) -> Dic
|
|
|
202
202
|
return body
|
|
203
203
|
|
|
204
204
|
|
|
205
|
+
# ──────────────────────────────────────────────────────────────────────────
|
|
206
|
+
# Streaming cleanup (verify-then-delete) support for process_pairs.
|
|
207
|
+
#
|
|
208
|
+
# These helpers never touch the InSAR maths: they only inspect what
|
|
209
|
+
# process_pair() has already saved and decide when an input scene is no
|
|
210
|
+
# longer needed.
|
|
211
|
+
# ──────────────────────────────────────────────────────────────────────────
|
|
212
|
+
|
|
213
|
+
# process_pair() arguments that name scene data which streaming_cleanup may
|
|
214
|
+
# delete once every pair using them has been saved AND verified. Orbit files
|
|
215
|
+
# and the DEM are small / shared and are never deleted.
|
|
216
|
+
_CLEANUP_INPUT_KEYS = ("reference", "secondary", "reference_safe_zip", "secondary_safe_zip")
|
|
217
|
+
|
|
218
|
+
# Written next to result.json after a verified save. It records a fingerprint of
|
|
219
|
+
# everything EXCEPT the scene paths, so a later resume can still recognise the pair
|
|
220
|
+
# as current after those scenes have been deleted (the regular fingerprint hashes
|
|
221
|
+
# the input files themselves, and cannot be rebuilt once they are gone).
|
|
222
|
+
_CLEANUP_MARKER = "streaming_cleanup.json"
|
|
223
|
+
|
|
224
|
+
# A saved pair needs at least this share of valid coherence pixels to verify.
|
|
225
|
+
_MIN_VALID_FRACTION = 0.01
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _verify_saved_pair(folder: Union[str, Path]) -> "tuple[bool, str]":
|
|
229
|
+
"""
|
|
230
|
+
The *verify* step of verify-then-delete, run on what process_pair() saved.
|
|
231
|
+
|
|
232
|
+
Checks result.json parses, wrapped_phase/coherence/amplitude GeoTIFFs open
|
|
233
|
+
as one band with identical non-empty shape, interferogram_complex.npy has
|
|
234
|
+
that same shape, geometry.pkl exists when result.json says it should, the
|
|
235
|
+
coherence holds valid (>= 0) values that are not all zero, and the complex
|
|
236
|
+
interferogram is not empty. Reads are decimated, so it is cheap on large
|
|
237
|
+
pairs. Returns (ok, reason).
|
|
238
|
+
"""
|
|
239
|
+
import json
|
|
240
|
+
|
|
241
|
+
import numpy as np
|
|
242
|
+
|
|
243
|
+
folder = Path(folder)
|
|
244
|
+
try:
|
|
245
|
+
side = json.loads((folder / _RESULT_JSON).read_text())
|
|
246
|
+
except (OSError, ValueError) as exc:
|
|
247
|
+
return False, f"{_RESULT_JSON} unreadable ({exc})"
|
|
248
|
+
|
|
249
|
+
try:
|
|
250
|
+
import rasterio
|
|
251
|
+
|
|
252
|
+
shapes = {}
|
|
253
|
+
coh = None
|
|
254
|
+
for name in ("wrapped_phase", "coherence", "amplitude"):
|
|
255
|
+
with rasterio.open(folder / f"{name}.tif") as ds:
|
|
256
|
+
if ds.count != 1 or ds.height < 1 or ds.width < 1:
|
|
257
|
+
return False, f"{name}.tif has unexpected shape"
|
|
258
|
+
shapes[name] = (ds.height, ds.width)
|
|
259
|
+
if name == "coherence":
|
|
260
|
+
step = max(1, max(ds.height, ds.width) // 1024)
|
|
261
|
+
coh = ds.read(1, out_shape=(max(1, ds.height // step), max(1, ds.width // step)))
|
|
262
|
+
if len(set(shapes.values())) != 1:
|
|
263
|
+
return False, f"product shapes disagree: {shapes}"
|
|
264
|
+
shape = shapes["coherence"]
|
|
265
|
+
cplx = np.load(folder / "interferogram_complex.npy", mmap_mode="r")
|
|
266
|
+
if tuple(cplx.shape) != tuple(shape):
|
|
267
|
+
return False, f"interferogram_complex.npy shape {tuple(cplx.shape)} != {shape}"
|
|
268
|
+
step = max(1, max(shape) // 1024)
|
|
269
|
+
sample = np.asarray(cplx[::step, ::step])
|
|
270
|
+
if side.get("has_geometry") and not (folder / "geometry.pkl").is_file():
|
|
271
|
+
return False, "geometry.pkl is missing"
|
|
272
|
+
except Exception as exc: # noqa: BLE001 - any read failure means "not verified"
|
|
273
|
+
return False, f"could not read saved products ({exc})"
|
|
274
|
+
|
|
275
|
+
valid = np.isfinite(coh) & (coh >= 0)
|
|
276
|
+
if valid.mean() < _MIN_VALID_FRACTION:
|
|
277
|
+
return False, f"only {valid.mean():.2%} valid coherence pixels"
|
|
278
|
+
if not np.any(coh[valid] > 0):
|
|
279
|
+
return False, "coherence is all zero"
|
|
280
|
+
if not np.any(np.isfinite(sample) & (np.abs(sample) > 0)):
|
|
281
|
+
return False, "interferogram is empty"
|
|
282
|
+
return True, "ok"
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _write_cleanup_marker(folder: Union[str, Path], params_hash: str) -> None:
|
|
286
|
+
"""Atomically record the scene-independent fingerprint of a verified pair."""
|
|
287
|
+
import json
|
|
288
|
+
|
|
289
|
+
folder = Path(folder)
|
|
290
|
+
tmp = folder / (_CLEANUP_MARKER + ".tmp")
|
|
291
|
+
tmp.write_text(json.dumps({"params_hash": params_hash, "pipeline_version": PIPELINE_VERSION}))
|
|
292
|
+
tmp.replace(folder / _CLEANUP_MARKER)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _read_cleanup_marker(folder: Union[str, Path]) -> Optional[Dict[str, Any]]:
|
|
296
|
+
import json
|
|
297
|
+
|
|
298
|
+
try:
|
|
299
|
+
return json.loads((Path(folder) / _CLEANUP_MARKER).read_text())
|
|
300
|
+
except (OSError, ValueError):
|
|
301
|
+
return None
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _delete_input(path: str, protect: Path) -> bool:
|
|
305
|
+
"""
|
|
306
|
+
Delete one input scene file, then its parent folder if that is now empty.
|
|
307
|
+
|
|
308
|
+
Directories are never removed recursively (an input given as a folder is
|
|
309
|
+
left alone with a warning), nothing inside ``protect`` (the results
|
|
310
|
+
folder) is touched, and a failure only logs: the pair's results are
|
|
311
|
+
already safe on disk.
|
|
312
|
+
"""
|
|
313
|
+
import os
|
|
314
|
+
|
|
315
|
+
p = Path(path)
|
|
316
|
+
try:
|
|
317
|
+
if not p.exists():
|
|
318
|
+
return False
|
|
319
|
+
if p.is_dir():
|
|
320
|
+
logger.warning("streaming_cleanup: %s is a directory; not deleting it", p)
|
|
321
|
+
return False
|
|
322
|
+
if protect.resolve() in p.resolve().parents:
|
|
323
|
+
logger.warning("streaming_cleanup: %s is inside the results folder; not deleting it", p)
|
|
324
|
+
return False
|
|
325
|
+
p.unlink()
|
|
326
|
+
logger.info("streaming_cleanup: deleted %s", p.name)
|
|
327
|
+
try:
|
|
328
|
+
os.rmdir(p.parent) # succeeds only when the folder is empty
|
|
329
|
+
except OSError:
|
|
330
|
+
pass
|
|
331
|
+
return True
|
|
332
|
+
except OSError as exc:
|
|
333
|
+
logger.warning("streaming_cleanup: could not delete %s (%s)", p, exc)
|
|
334
|
+
return False
|
|
335
|
+
|
|
336
|
+
|
|
205
337
|
@dataclass
|
|
206
338
|
class InterferogramResult:
|
|
207
339
|
"""Result of interferogram formation for one SLC pair."""
|
|
@@ -627,8 +759,10 @@ class InterferogramGenerator:
|
|
|
627
759
|
self._use_real_burst_processing = use_real_burst_processing
|
|
628
760
|
self._tops_ctx = None
|
|
629
761
|
# Part of every pair fingerprint: results saved before TOPS deramping (0) or before resampling onto the
|
|
630
|
-
# reference grid (1) are not reused.
|
|
631
|
-
|
|
762
|
+
# reference grid (1) are not reused. 7: SLC crops start on whole pixels (fractional crop origins left a
|
|
763
|
+
# per-date misregistration of up to half a pixel, seen as along-track fringes after ESD), and orbit/DEM
|
|
764
|
+
# coregistration is geometry-only by default.
|
|
765
|
+
self._tops_deramp_version = 7
|
|
632
766
|
# Automatic by default (None): on when the inputs exist, explicit
|
|
633
767
|
# True/False always respected. It used to be opt-in and silent, which
|
|
634
768
|
# left a full-width range ramp in every interferogram unless the caller
|
|
@@ -1642,6 +1776,40 @@ class InterferogramGenerator:
|
|
|
1642
1776
|
return saved.get("hash") == self.pair_fingerprint(
|
|
1643
1777
|
reference_date=reference_date, secondary_date=secondary_date, **process_pair_kwargs)["hash"]
|
|
1644
1778
|
|
|
1779
|
+
def _pair_params_hash(self, kw: Dict[str, Any]) -> str:
|
|
1780
|
+
"""Fingerprint hash of a pair's dates, settings and non-scene inputs (orbit files, DEM, options),
|
|
1781
|
+
deliberately excluding the scene paths that streaming_cleanup deletes. See _CLEANUP_MARKER."""
|
|
1782
|
+
import inspect
|
|
1783
|
+
|
|
1784
|
+
bound = inspect.signature(self.process_pair).bind(**kw)
|
|
1785
|
+
bound.apply_defaults()
|
|
1786
|
+
args = {k: v for k, v in bound.arguments.items() if k not in _CLEANUP_INPUT_KEYS}
|
|
1787
|
+
return self._pair_fingerprint(args)["hash"]
|
|
1788
|
+
|
|
1789
|
+
def _resume_state(self, out: Path, kw: Dict[str, Any], verify: bool):
|
|
1790
|
+
"""Decide whether one pair can be skipped. Returns (current, reason, via_marker).
|
|
1791
|
+
|
|
1792
|
+
The regular fingerprint check is tried first. If it fails only because streaming_cleanup already
|
|
1793
|
+
deleted the scenes, the marker written at the time of cleanup is accepted instead, provided its
|
|
1794
|
+
scene-independent hash still matches. A pair is only called current when its saved products also
|
|
1795
|
+
verify (always when scenes are gone or verify=True; the plain resume path is unchanged)."""
|
|
1796
|
+
rd, sd = kw["reference_date"], kw["secondary_date"]
|
|
1797
|
+
folder = out / f"{rd}_{sd}"
|
|
1798
|
+
pair_kw = {k: v for k, v in kw.items() if k not in ("reference_date", "secondary_date")}
|
|
1799
|
+
current = self.is_pair_current(out, rd, sd, **pair_kw)
|
|
1800
|
+
via_marker = False
|
|
1801
|
+
if not current:
|
|
1802
|
+
scenes_gone = any(kw.get(k) is not None and not Path(str(kw[k])).exists()
|
|
1803
|
+
for k in _CLEANUP_INPUT_KEYS)
|
|
1804
|
+
marker = _read_cleanup_marker(folder) if scenes_gone else None
|
|
1805
|
+
if marker and marker.get("params_hash") == self._pair_params_hash(kw):
|
|
1806
|
+
current = via_marker = True
|
|
1807
|
+
if current and (verify or via_marker):
|
|
1808
|
+
ok, why = _verify_saved_pair(folder)
|
|
1809
|
+
if not ok:
|
|
1810
|
+
return False, f"saved products failed verification ({why})", via_marker
|
|
1811
|
+
return current, "", via_marker
|
|
1812
|
+
|
|
1645
1813
|
def process_pairs(
|
|
1646
1814
|
self,
|
|
1647
1815
|
pairs,
|
|
@@ -1649,6 +1817,7 @@ class InterferogramGenerator:
|
|
|
1649
1817
|
resume: bool = True,
|
|
1650
1818
|
keep_results: bool = False,
|
|
1651
1819
|
stop_on_error: bool = False,
|
|
1820
|
+
streaming_cleanup: bool = False,
|
|
1652
1821
|
**common_kwargs,
|
|
1653
1822
|
):
|
|
1654
1823
|
"""Process many pairs one after another, saving each under output_dir/<ref>_<sec>.
|
|
@@ -1657,72 +1826,144 @@ class InterferogramGenerator:
|
|
|
1657
1826
|
reference_date, secondary_date, ... ). common_kwargs apply to every pair; a pair's own dict wins.
|
|
1658
1827
|
resume: pairs whose folder already holds a complete save made with the same inputs and settings
|
|
1659
1828
|
are skipped before any SLC is opened (checked with the same fingerprint process_pair stores).
|
|
1829
|
+
With streaming_cleanup the saved products are also verified first, and a pair whose scenes
|
|
1830
|
+
were deleted by an earlier cleanup is still recognised (see _CLEANUP_MARKER).
|
|
1660
1831
|
keep_results: False (default) keeps only a small record per pair, so memory stays flat however many
|
|
1661
1832
|
pairs run; True also returns each InterferogramResult (loaded from disk for skipped pairs).
|
|
1662
1833
|
stop_on_error: False records the failure and carries on with the next pair.
|
|
1834
|
+
streaming_cleanup: False (default) changes nothing. True applies verify-then-delete to the
|
|
1835
|
+
INPUTS of each pair (reference / secondary extracted SLCs and reference_safe_zip /
|
|
1836
|
+
secondary_safe_zip):
|
|
1837
|
+
try process_pair() as before, saving to output_dir/<ref>_<sec>;
|
|
1838
|
+
verify re-open the saved products (shape, validity, not empty);
|
|
1839
|
+
delete an input is deleted only once EVERY pair in this call that uses it has been saved
|
|
1840
|
+
and verified, so a scene shared by several pairs survives until its last pair;
|
|
1841
|
+
except the error is recorded and the inputs of that pair are KEPT (so is any scene the
|
|
1842
|
+
failed pair shares with others);
|
|
1843
|
+
finally gc.collect().
|
|
1844
|
+
Deleted inputs cannot be recomputed from: to redo a pair, re-download its scenes. Pass all the
|
|
1845
|
+
pairs that need a scene in ONE call, because pairs in other calls are not known to this one.
|
|
1846
|
+
Orbit files and the DEM are never deleted.
|
|
1663
1847
|
|
|
1664
1848
|
Returns a list of records: reference_date, secondary_date, status ("skipped: already generated",
|
|
1665
1849
|
"computed", "failed"), folder, metadata (the pair's summary, loaded from result.json when skipped),
|
|
1666
|
-
error,
|
|
1667
|
-
did not skip anything says so.
|
|
1850
|
+
error, deleted (inputs removed after this pair, streaming_cleanup only) and result (only with
|
|
1851
|
+
keep_results). The decision for every pair is printed, so a run that did not skip anything says so.
|
|
1668
1852
|
"""
|
|
1669
1853
|
import gc
|
|
1670
1854
|
import json
|
|
1855
|
+
import os
|
|
1671
1856
|
|
|
1672
1857
|
out = Path(output_dir)
|
|
1673
1858
|
pairs = list(pairs)
|
|
1674
1859
|
records = []
|
|
1675
1860
|
n_skip = n_done = n_fail = 0
|
|
1676
|
-
print(f"process_pairs: {len(pairs)} pairs, output_dir={out}, resume={resume}"
|
|
1677
|
-
|
|
1861
|
+
print(f"process_pairs: {len(pairs)} pairs, output_dir={out}, resume={resume}"
|
|
1862
|
+
+ (", streaming_cleanup=True" if streaming_cleanup else ""))
|
|
1863
|
+
|
|
1864
|
+
specs = []
|
|
1865
|
+
for spec in pairs:
|
|
1678
1866
|
kw = {**common_kwargs, **spec}
|
|
1679
|
-
|
|
1680
|
-
if not (rd and sd):
|
|
1867
|
+
if not (kw.get("reference_date") and kw.get("secondary_date")):
|
|
1681
1868
|
raise InputError("input", "every pair needs reference_date and secondary_date")
|
|
1869
|
+
specs.append(kw)
|
|
1870
|
+
|
|
1871
|
+
# Streaming bookkeeping. pending[input] = indices of pairs that still need that input; an input
|
|
1872
|
+
# becomes deletable when its set is empty. A pair leaves the sets only once its results are
|
|
1873
|
+
# saved and verified, so a failed pair pins every input it uses.
|
|
1874
|
+
pending: Dict[str, set] = {}
|
|
1875
|
+
states: Dict[int, Any] = {}
|
|
1876
|
+
if streaming_cleanup:
|
|
1877
|
+
for i, kw in enumerate(specs):
|
|
1878
|
+
for key in _CLEANUP_INPUT_KEYS:
|
|
1879
|
+
if kw.get(key) is not None:
|
|
1880
|
+
pending.setdefault(os.path.abspath(str(kw[key])), set()).add(i)
|
|
1881
|
+
|
|
1882
|
+
def _finish(i: int) -> list:
|
|
1883
|
+
"""Pair i is saved and verified: release its inputs and delete those nobody else needs."""
|
|
1884
|
+
deleted = []
|
|
1885
|
+
for key in _CLEANUP_INPUT_KEYS:
|
|
1886
|
+
if specs[i].get(key) is None:
|
|
1887
|
+
continue
|
|
1888
|
+
path = os.path.abspath(str(specs[i][key]))
|
|
1889
|
+
pending[path].discard(i)
|
|
1890
|
+
if not pending[path] and _delete_input(path, protect=out):
|
|
1891
|
+
deleted.append(path)
|
|
1892
|
+
return deleted
|
|
1893
|
+
|
|
1894
|
+
if streaming_cleanup and resume:
|
|
1895
|
+
# Decide every pair up front: pairs that are already done release their inputs straight away.
|
|
1896
|
+
for i, kw in enumerate(specs):
|
|
1897
|
+
try:
|
|
1898
|
+
states[i] = self._resume_state(out, kw, verify=True)
|
|
1899
|
+
except Exception as exc: # noqa: BLE001
|
|
1900
|
+
logger.warning("resume check failed for %s_%s (%s); computing it",
|
|
1901
|
+
kw["reference_date"], kw["secondary_date"], exc)
|
|
1902
|
+
for i, st in states.items():
|
|
1903
|
+
if st[0]:
|
|
1904
|
+
_finish(i)
|
|
1905
|
+
|
|
1906
|
+
for i, (kw, spec) in enumerate(zip(specs, pairs), 1):
|
|
1907
|
+
rd, sd = kw["reference_date"], kw["secondary_date"]
|
|
1682
1908
|
folder = out / f"{rd}_{sd}"
|
|
1683
1909
|
rec = {"reference_date": rd, "secondary_date": sd, "folder": folder, "status": None,
|
|
1684
1910
|
"metadata": None, "error": None, "result": None}
|
|
1911
|
+
if streaming_cleanup:
|
|
1912
|
+
rec["deleted"] = []
|
|
1685
1913
|
tag = f"[{i}/{len(pairs)}] {rd} -> {sd}"
|
|
1686
|
-
current = False
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
"
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
rec["
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1914
|
+
current, why_not = False, ""
|
|
1915
|
+
try:
|
|
1916
|
+
if resume:
|
|
1917
|
+
try:
|
|
1918
|
+
# Plain resume keeps its original cost; verification is added only for streaming runs
|
|
1919
|
+
# (or when the scenes are gone and the marker is all there is to go on).
|
|
1920
|
+
current, why_not, _ = states.get(i - 1) or self._resume_state(
|
|
1921
|
+
out, kw, verify=streaming_cleanup)
|
|
1922
|
+
except Exception as exc: # noqa: BLE001
|
|
1923
|
+
logger.warning("resume check failed for %s_%s (%s); computing it", rd, sd, exc)
|
|
1924
|
+
if current:
|
|
1925
|
+
rec["status"] = "skipped: already generated"
|
|
1926
|
+
try:
|
|
1927
|
+
rec["metadata"] = _restore(json.loads((folder / _RESULT_JSON).read_text()).get("metadata") or {})
|
|
1928
|
+
if keep_results:
|
|
1929
|
+
rec["result"] = InterferogramResult.load(folder)
|
|
1930
|
+
except Exception as exc: # noqa: BLE001
|
|
1931
|
+
logger.warning("could not read saved result for %s_%s (%s)", rd, sd, exc)
|
|
1932
|
+
n_skip += 1
|
|
1933
|
+
print(f"{tag}: {rec['status']}")
|
|
1934
|
+
else:
|
|
1935
|
+
why = why_not or ("resume off" if not resume else (
|
|
1936
|
+
"no complete save" if InterferogramResult.saved_fingerprint(folder) is None
|
|
1937
|
+
else "saved with different inputs/settings/version"))
|
|
1938
|
+
print(f"{tag}: computing ({why})")
|
|
1939
|
+
try:
|
|
1940
|
+
res = self.process_pair(output_dir=out, resume=False, **kw)
|
|
1941
|
+
rec["metadata"] = dict(res.metadata)
|
|
1942
|
+
if keep_results:
|
|
1943
|
+
rec["result"] = res
|
|
1944
|
+
del res
|
|
1945
|
+
if streaming_cleanup:
|
|
1946
|
+
ok, bad = _verify_saved_pair(folder)
|
|
1947
|
+
if not ok:
|
|
1948
|
+
raise RuntimeError(f"saved products failed verification ({bad}); "
|
|
1949
|
+
f"input scenes kept")
|
|
1950
|
+
_write_cleanup_marker(folder, self._pair_params_hash(kw))
|
|
1951
|
+
rec["deleted"] = _finish(i - 1)
|
|
1952
|
+
rec["status"] = "computed"
|
|
1953
|
+
n_done += 1
|
|
1954
|
+
except Exception as exc: # noqa: BLE001
|
|
1955
|
+
rec["status"] = "failed"
|
|
1956
|
+
rec["error"] = f"{type(exc).__name__}: {exc}"
|
|
1957
|
+
if streaming_cleanup:
|
|
1958
|
+
logger.error("%s: %s -- inputs of this pair kept", tag, rec["error"])
|
|
1959
|
+
n_fail += 1
|
|
1960
|
+
print(f"{tag}: FAILED {rec['error']}")
|
|
1961
|
+
if stop_on_error:
|
|
1962
|
+
records.append(rec)
|
|
1963
|
+
raise
|
|
1964
|
+
records.append(rec)
|
|
1965
|
+
finally:
|
|
1966
|
+
gc.collect()
|
|
1726
1967
|
print(f"process_pairs: {n_skip} skipped, {n_done} computed, {n_fail} failed")
|
|
1727
1968
|
return records
|
|
1728
1969
|
|
|
@@ -1741,7 +1982,7 @@ class InterferogramGenerator:
|
|
|
1741
1982
|
looks_range: int = 1,
|
|
1742
1983
|
apply_goldstein_filter: bool = False,
|
|
1743
1984
|
goldstein_alpha: float = 0.5,
|
|
1744
|
-
coregistration_refine_by_coherence: bool =
|
|
1985
|
+
coregistration_refine_by_coherence: Optional[bool] = None,
|
|
1745
1986
|
coregistration_degree: int = 1,
|
|
1746
1987
|
coregistration_rms_threshold: Optional[float] = None,
|
|
1747
1988
|
coregistration_method: str = "orbit_dem",
|
|
@@ -1792,11 +2033,19 @@ class InterferogramGenerator:
|
|
|
1792
2033
|
apply_goldstein_filter: Apply adaptive frequency-domain
|
|
1793
2034
|
phase filtering after interferogram formation.
|
|
1794
2035
|
goldstein_alpha: Goldstein filter strength (0-1).
|
|
1795
|
-
coregistration_refine_by_coherence: If True
|
|
2036
|
+
coregistration_refine_by_coherence: If True, the
|
|
1796
2037
|
orbit/DEM (or collocation) offset field is
|
|
1797
2038
|
refined against the actual image content via
|
|
1798
2039
|
cross-correlation + Powell coherence maximization
|
|
1799
|
-
before the warp polynomial is fit.
|
|
2040
|
+
before the warp polynomial is fit. None (default)
|
|
2041
|
+
chooses by method: False for "orbit_dem" (geometry
|
|
2042
|
+
only, as ISCE2 topsApp and ASF HyP3 do: the orbit
|
|
2043
|
+
and DEM give the offsets to a few hundredths of a
|
|
2044
|
+
pixel, and on 36 Mexico City pairs geometry-only
|
|
2045
|
+
registration agreed with HyP3 at median 0.90 with
|
|
2046
|
+
triplet closure 0.07 rad against HyP3's 0.09),
|
|
2047
|
+
True for "raster_collocation", whose geocoding
|
|
2048
|
+
is too coarse to stand alone.
|
|
1800
2049
|
coregistration_degree: Warp polynomial order (1, 2, or 3).
|
|
1801
2050
|
coregistration_rms_threshold: Optional final absolute GCP
|
|
1802
2051
|
RMS cutoff (pixels), applied after iterative
|
|
@@ -2013,6 +2262,8 @@ class InterferogramGenerator:
|
|
|
2013
2262
|
quality.flag("cross_satellite" if pair_platforms["cross_satellite"] else "cross_track")
|
|
2014
2263
|
|
|
2015
2264
|
# ── Step 1: Coregistration ──
|
|
2265
|
+
if coregistration_refine_by_coherence is None:
|
|
2266
|
+
coregistration_refine_by_coherence = coregistration_method != "orbit_dem"
|
|
2016
2267
|
if coregistration_method == "raster_collocation":
|
|
2017
2268
|
logger.warning(
|
|
2018
2269
|
"coregistration_method='raster_collocation' resamples the secondary without TOPS deramping: "
|