PyGeoFetch 2.7.0.2__py3-none-any.whl → 2.7.0.4__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 CHANGED
@@ -30,7 +30,7 @@ CLI::
30
30
  pygeofetch doctor
31
31
  """
32
32
 
33
- __version__ = "2.7.0.2.4"
33
+ __version__ = "2.7.0.4.4"
34
34
  __author__ = "PyGeoFetch Contributors"
35
35
  __license__ = "MIT"
36
36
 
@@ -615,7 +615,7 @@ class InterferogramGenerator:
615
615
  self._tops_ctx = None
616
616
  # Part of every pair fingerprint: results saved before TOPS deramping (0) or before resampling onto the
617
617
  # reference grid (1) are not reused.
618
- self._tops_deramp_version = 3
618
+ self._tops_deramp_version = 4
619
619
  # Automatic by default (None): on when the inputs exist, explicit
620
620
  # True/False always respected. It used to be opt-in and silent, which
621
621
  # left a full-width range ramp in every interferogram unless the caller
@@ -1437,6 +1437,28 @@ class InterferogramGenerator:
1437
1437
  except Exception as exc: # noqa: BLE001
1438
1438
  metadata["esd_residual_after_correction_px"] = None
1439
1439
  logger.warning("ESD residual re-estimation failed: %s", exc)
1440
+ # Resolve ESD's whole-ambiguity blind spot (TOPS pairs only).
1441
+ if getattr(self, "_tops_ctx", None) is not None:
1442
+ try:
1443
+ _amb = 1.0 / ((_df if _df else 5200.0) * azimuth_time_interval_s)
1444
+ sec_complex, _amb_info = self._resolve_esd_ambiguity(ref_complex, sec_complex, _amb)
1445
+ if _amb_info is not None:
1446
+ _total = esd_shift_px + _amb_info["k"] * _amb
1447
+ if _amb_info["k"] != 0:
1448
+ # ESD again, now within its unambiguous range of the true alignment: the first
1449
+ # estimate was made far from it, where the overlaps decorrelate and bias ESD.
1450
+ _r2, _ = estimate_esd_shift_per_burst_overlap(
1451
+ ref_complex, sec_complex, ref_burst_info, azimuth_time_interval_s,
1452
+ row_offset=int(ref_row_off), **_esd_kwargs,
1453
+ )
1454
+ if _r2 is not None and abs(_r2 / azimuth_time_interval_s) > 1e-4:
1455
+ sec_complex = self._apply_azimuth_shift(sec_complex, _r2 / azimuth_time_interval_s)
1456
+ _total += _r2 / azimuth_time_interval_s
1457
+ _amb_info["esd_refinement_px"] = float(_r2 / azimuth_time_interval_s)
1458
+ metadata["esd_ambiguity"] = _amb_info
1459
+ metadata["esd_total_shift_px"] = _total
1460
+ except Exception as exc: # noqa: BLE001
1461
+ logger.warning("ESD ambiguity scan failed: %s", exc)
1440
1462
  else:
1441
1463
  logger.info(
1442
1464
  "Real per-burst-overlap ESD found no usable burst "
@@ -2588,6 +2610,8 @@ class InterferogramGenerator:
2588
2610
  "burst_timing_steps_px": coreg_metadata.get("burst_timing_steps_px"),
2589
2611
  "coreg_rms_px": coreg_metadata.get("rms_mean_px"),
2590
2612
  "esd_delta_f_ovl_hz": burst_metadata.get("esd_delta_f_ovl_hz"),
2613
+ "esd_ambiguity": burst_metadata.get("esd_ambiguity"),
2614
+ "esd_total_shift_px": burst_metadata.get("esd_total_shift_px"),
2591
2615
  "esd_residual_after_correction_px": burst_metadata.get("esd_residual_after_correction_px"),
2592
2616
  "quality": quality.to_dict(),
2593
2617
  "quality_grade": quality.grade,
@@ -3287,6 +3311,90 @@ class InterferogramGenerator:
3287
3311
  shift_px = diff_phase / (2 * np.pi) * 0.01 # conservative scaling
3288
3312
  return float(np.clip(shift_px, -0.5, 0.5))
3289
3313
 
3314
+ def _tops_content_phase(self, ctx, col_offset: float = 0.0):
3315
+ """Ramp phase carried by the resampled (and possibly already shifted) secondary at local (row, col)."""
3316
+ np = self._np()
3317
+ sec_ramp, row_fn, col_fn = ctx["sec_ramp"], ctx["row_fn"], ctx["col_fn"]
3318
+ r_off, c_off = ctx["ref_row_off"], ctx["ref_col_off"] + col_offset
3319
+ applied = ctx.get("applied_shift_px", 0.0)
3320
+
3321
+ def content_phase(rows, cols):
3322
+ rg = np.asarray(rows, dtype=np.float64) - applied + r_off
3323
+ cg = np.asarray(cols, dtype=np.float64) + c_off
3324
+ return sec_ramp.phase(rg + np.asarray(row_fn(rg, cg), dtype=np.float64),
3325
+ cg + np.asarray(col_fn(rg, cg), dtype=np.float64))
3326
+
3327
+ return content_phase
3328
+
3329
+ def _resolve_esd_ambiguity(self, ref_complex, sec_complex, ambiguity_px: float, k_max: int = 4,
3330
+ max_cols: int = 1536, k_limit: int = 15):
3331
+ """Pick the whole number of ESD ambiguities to add to the azimuth shift, by coherence.
3332
+
3333
+ ESD measures the azimuth misregistration only modulo ``1 / (delta_f_ovl * dt_az)`` (about 0.1 px for IW):
3334
+ a first-stage coregistration error of a few tenths of a pixel leaves an error that ESD cannot see but that
3335
+ ramps the TOPS phase through every burst (about 3 rad/km per pixel) and steps it at burst edges. The
3336
+ interferometric coherence of a TOPS pair peaks at zero misregistration (the burst spectra overlap best),
3337
+ so the secondary is shifted by k ambiguities, k = -k_max..k_max, on a central block of columns, and the
3338
+ k with the highest coherence is kept; when the best k is at an end of the scan the scan is extended (up
3339
+ to +-k_limit, i.e. about 1.5 px). Returns the (possibly shifted) secondary and the scan.
3340
+ """
3341
+ np = self._np()
3342
+ ctx = getattr(self, "_tops_ctx", None)
3343
+ if ctx is None or not (ambiguity_px > 0) or not np.isfinite(ambiguity_px):
3344
+ return sec_complex, None
3345
+ from pygeofetch.insar.tops import shift_azimuth_tops
3346
+
3347
+ h, w = sec_complex.shape
3348
+ c0 = max(0, (w - max_cols) // 2)
3349
+ c1 = min(w, c0 + max_cols)
3350
+ ref_s = np.asarray(ref_complex[:, c0:c1])
3351
+ sec_s = np.asarray(sec_complex[:, c0:c1], dtype=np.complex64)
3352
+ content_phase = self._tops_content_phase(ctx, col_offset=c0)
3353
+ lpb, r_off = ctx["ref_ramp"].lines_per_burst, ctx["ref_row_off"]
3354
+
3355
+ def coherence(a, b, la=4, lr=16):
3356
+ n_r, n_c = (a.shape[0] // la) * la, (a.shape[1] // lr) * lr
3357
+ a, b = a[:n_r, :n_c].astype(np.complex128), b[:n_r, :n_c].astype(np.complex128)
3358
+ shp = (n_r // la, la, n_c // lr, lr)
3359
+ num = np.abs((a * np.conj(b)).reshape(shp).sum(axis=(1, 3)))
3360
+ den = np.sqrt((np.abs(a) ** 2).reshape(shp).sum(axis=(1, 3)) * (np.abs(b) ** 2).reshape(shp).sum(axis=(1, 3)))
3361
+ ok = den > 0
3362
+ return float(np.mean(num[ok] / den[ok])) if ok.any() else float("nan")
3363
+
3364
+ cache = {}
3365
+
3366
+ def score(k):
3367
+ if k not in cache:
3368
+ shifted = sec_s if k == 0 else shift_azimuth_tops(sec_s.copy(), k * ambiguity_px, content_phase, lpb, r_off)
3369
+ cache[k] = coherence(ref_s, shifted)
3370
+ return cache[k]
3371
+
3372
+ for k in range(-k_max, k_max + 1):
3373
+ score(k)
3374
+ # If the peak sits at an end of the scan, keep extending in that direction (up to k_limit ambiguities).
3375
+ while True:
3376
+ ks_now = sorted(cache)
3377
+ k_best = max(ks_now, key=lambda k: cache[k])
3378
+ if k_best == ks_now[-1] and k_best < k_limit:
3379
+ score(k_best + 1)
3380
+ elif k_best == ks_now[0] and k_best > -k_limit:
3381
+ score(k_best - 1)
3382
+ else:
3383
+ break
3384
+ ks = sorted(cache)
3385
+ scores = [cache[k] for k in ks]
3386
+ info = {"ambiguity_px": float(ambiguity_px), "k": int(k_best),
3387
+ "coherence_scan": {int(k): round(float(cache[k]), 5) for k in ks},
3388
+ "at_scan_edge": abs(k_best) >= k_limit}
3389
+ logger.info("ESD ambiguity scan (coherence for k = %d..%d ambiguities of %.4f px): %s -> k = %+d",
3390
+ ks[0], ks[-1], ambiguity_px, ", ".join(f"{v:.4f}" for v in scores), k_best)
3391
+ if info["at_scan_edge"]:
3392
+ logger.warning("ESD ambiguity scan peaks at its limit (k = %+d): the first-stage coregistration is off "
3393
+ "by more than %d ambiguities", k_best, k_limit)
3394
+ if k_best != 0:
3395
+ sec_complex = self._apply_azimuth_shift(sec_complex, k_best * ambiguity_px)
3396
+ return sec_complex, info
3397
+
3290
3398
  def _apply_azimuth_shift(self, data, shift_px: float):
3291
3399
  """Apply a sub-pixel azimuth (row) shift via Fourier phase ramp.
3292
3400
 
@@ -3304,17 +3412,12 @@ class InterferogramGenerator:
3304
3412
  # every burst.
3305
3413
  from pygeofetch.insar.tops import shift_azimuth_tops
3306
3414
 
3307
- sec_ramp, row_fn, col_fn = ctx["sec_ramp"], ctx["row_fn"], ctx["col_fn"]
3308
- r_off, c_off = ctx["ref_row_off"], ctx["ref_col_off"]
3309
-
3310
- def content_phase(rows, cols):
3311
- rg = np.asarray(rows, dtype=np.float64) + r_off
3312
- cg = np.asarray(cols, dtype=np.float64) + c_off
3313
- return sec_ramp.phase(rg + np.asarray(row_fn(rg, cg), dtype=np.float64),
3314
- cg + np.asarray(col_fn(rg, cg), dtype=np.float64))
3315
-
3316
- return shift_azimuth_tops(np.asarray(data), float(shift_px), content_phase,
3317
- ctx["ref_ramp"].lines_per_burst, r_off)
3415
+ content_phase = self._tops_content_phase(ctx)
3416
+ out = shift_azimuth_tops(np.asarray(data), float(shift_px), content_phase,
3417
+ ctx["ref_ramp"].lines_per_burst, ctx["ref_row_off"])
3418
+ # The data now carry the ramp of the positions r - shift; a later shift must start from there.
3419
+ ctx["applied_shift_px"] = ctx.get("applied_shift_px", 0.0) + float(shift_px)
3420
+ return out
3318
3421
  h, w = data.shape
3319
3422
  freq = np.fft.fftfreq(h).reshape(-1, 1)
3320
3423
  ramp = np.exp(-2j * np.pi * freq * shift_px)
pygeofetch/meta.yaml CHANGED
@@ -1,4 +1,4 @@
1
- {% set version = "2.7.0.2.4" %}
1
+ {% set version = "2.7.0.4.4" %}
2
2
 
3
3
  package:
4
4
  name: pygeofetch
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygeofetch
3
- Version: 2.7.0.2
3
+ Version: 2.7.0.4
4
4
  Summary: Universal satellite data pipeline + geospatial processing platform
5
5
  Author-email: Samuel Appiah Kubi <appiahkubis14@gmail.com>
6
6
  License: MIT License
@@ -371,7 +371,7 @@ If you use PyGeoFetch in your research or operational work, please cite it using
371
371
  title = {PyGeoFetch: A Unified Python Framework for Multi-Provider Satellite Data Acquisition, Pre-download Quality Control, and Geospatial Processing},
372
372
  year = {2026},
373
373
  publisher = {Zenodo},
374
- version = {2.7.0.2.1},
374
+ version = {2.7.0.4.1},
375
375
  doi = {10.5281/zenodo.22087230},
376
376
  url = {https://doi.org/10.5281/zenodo.22087230}
377
377
  }
@@ -1,5 +1,5 @@
1
- pygeofetch/__init__.py,sha256=yw--nHUD7CZQ7AlYaW8RiOZ3oJNcuFbBvC1uoWWbO60,2107
2
- pygeofetch/meta.yaml,sha256=lwGyebWDOMyzffGLAszbgdavw5h4lUgdjpwAuSrvPbY,1284
1
+ pygeofetch/__init__.py,sha256=PWgaPdphhZB3iQq6he8iWgqrwfK-CizJXSBJzh94xpQ,2107
2
+ pygeofetch/meta.yaml,sha256=UgcwTzv2cO9lxfHHelmZv7gaYQx3ptNyL4w8lGYzEmU,1284
3
3
  pygeofetch/cli/__init__.py,sha256=QZMIIHEgmjGFieucqq9fZ5uephxP9-jdu1s8Q4qqw8o,30
4
4
  pygeofetch/cli/auth_commands.py,sha256=OUYbInPaERvAfNZ_NmAF3azHoJm14cGn_ZTQtxjjcs4,7871
5
5
  pygeofetch/cli/classify_commands.py,sha256=0att8QoTKPa-z24NXLTW-iXbpkBWZTxjoZkV1eNwHeU,4739
@@ -55,7 +55,7 @@ pygeofetch/insar/flatearth.py,sha256=gSUdDcHlxs3P2TrUkKFkIwq7GftKVOit0A47CaBKIvc
55
55
  pygeofetch/insar/geolocation.py,sha256=7T84uNHIXGmuOCvru9CJkFrnet4HX3t-thXXro2peRk,34163
56
56
  pygeofetch/insar/gpu.py,sha256=tMQSurv6EmmQMFU-e9--ssZo0YRUooPRHyU0V8jamIQ,5726
57
57
  pygeofetch/insar/hybrid_unwrap.py,sha256=PT4G9UPTrMqftaMjFd0i9DkwmtRZXAqN504eLYc22ds,18477
58
- pygeofetch/insar/interferogram.py,sha256=NTlledvr-6Jkqr5h3s5VWEveV_S2QeBMoUbrIGVyBZs,173797
58
+ pygeofetch/insar/interferogram.py,sha256=NcqtSp7qu9Gf38wjr9d7qWTrKX1IM1Lz3q9sZQp7hCY,180215
59
59
  pygeofetch/insar/ionosphere.py,sha256=erfzXKGxWLcLvNZznBCx42t6V05oO3M9q-nbrGzrKyc,30987
60
60
  pygeofetch/insar/learned_unwrap.py,sha256=lSX_u-2U5mm8lRKhO0xBMk1dVYcR3wDh6pFWcPdR350,45950
61
61
  pygeofetch/insar/logs.py,sha256=lQliMDJmt15NTz8Xgqg1EzENA3WUFY48u2xRqvSoB1U,2453
@@ -170,9 +170,21 @@ pygeofetch/viz/__init__.py,sha256=bSgK_f_goAHVQOfYu2nbPFVushvsy2hVKBvIBoGonyk,53
170
170
  pygeofetch/viz/insar.py,sha256=SaHBsbmvxAF4dLYptePX3wvKWV8Y2Sxqn8pFDjvyXuk,56742
171
171
  pygeofetch/viz/map.py,sha256=f8whny5mnz7gDsStNdgtVSpqTNHSDhSZoRT2Qs-Lvos,16403
172
172
  pygeofetch/viz/plot.py,sha256=JybD4qElJBOTvWCu7VllL5DqkKFYf5ttJdFfsgApfLE,56601
173
- pygeofetch-2.7.0.2.dist-info/licenses/LICENSE,sha256=zavMyhODD6NvZTmmKFEtATrngwY4CU_NEtY7lhjxGnI,1075
174
- pygeofetch-2.7.0.2.dist-info/METADATA,sha256=COvD4SEQzrmhyKxz5gMhfhF9UQQqePG_obQvujR6bPQ,25014
175
- pygeofetch-2.7.0.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
176
- pygeofetch-2.7.0.2.dist-info/entry_points.txt,sha256=dHiUXLF5xNJ8vgtXZoUQNleEMQUeDPZiKQOE1tW8SDY,55
177
- pygeofetch-2.7.0.2.dist-info/top_level.txt,sha256=rOmnZargIfNk99fwVOqt6OJyJvpSTBBAYO5HU37yhHk,11
178
- pygeofetch-2.7.0.2.dist-info/RECORD,,
173
+ pygeofetch-2.7.0.4.dist-info/licenses/LICENSE,sha256=zavMyhODD6NvZTmmKFEtATrngwY4CU_NEtY7lhjxGnI,1075
174
+ pygeofetch_tops_fix_part4/files/pygeofetch/insar/coregister.py,sha256=bmM4tcAZiMDaqqwiPFyrGUFTJm_u5oDbOni6jOzPa0Q,74225
175
+ pygeofetch_tops_fix_part4/files/pygeofetch/insar/interferogram.py,sha256=UQb_l3oOhxR_Dy-f1Uc3YoqlzFz6SPCTz89EiuKn-U0,178492
176
+ pygeofetch_tops_fix_part4/files/pygeofetch/insar/tops.py,sha256=-yIthiWED20u7t10m8M3AHEBaa8PDS_rvS-oDnYevgM,18459
177
+ pygeofetch_tops_fix_part4/files/tests/insar/_fake_safe.py,sha256=-ntqxg2Ln-8ZHxC3Waq1qTbVNAj5Iwj40Bc49Q9kD_A,3356
178
+ pygeofetch_tops_fix_part4/files/tests/insar/_tops_sim.py,sha256=t6-ahcc9unf2aLqFTmdMWMeN9gGgU7bFG2ddWS5ZVzY,4776
179
+ pygeofetch_tops_fix_part4/files/tests/insar/test_tops_deramp.py,sha256=oqiRB6__-jhcG56D3ATMGiVhoiIpooFQA6UsRGC8A2k,9355
180
+ pygeofetch_tops_fix_part5/files/pygeofetch/insar/coregister.py,sha256=bmM4tcAZiMDaqqwiPFyrGUFTJm_u5oDbOni6jOzPa0Q,74225
181
+ pygeofetch_tops_fix_part5/files/pygeofetch/insar/interferogram.py,sha256=NcqtSp7qu9Gf38wjr9d7qWTrKX1IM1Lz3q9sZQp7hCY,180215
182
+ pygeofetch_tops_fix_part5/files/pygeofetch/insar/tops.py,sha256=-yIthiWED20u7t10m8M3AHEBaa8PDS_rvS-oDnYevgM,18459
183
+ pygeofetch_tops_fix_part5/files/tests/insar/_fake_safe.py,sha256=-ntqxg2Ln-8ZHxC3Waq1qTbVNAj5Iwj40Bc49Q9kD_A,3356
184
+ pygeofetch_tops_fix_part5/files/tests/insar/_tops_sim.py,sha256=t6-ahcc9unf2aLqFTmdMWMeN9gGgU7bFG2ddWS5ZVzY,4776
185
+ pygeofetch_tops_fix_part5/files/tests/insar/test_tops_deramp.py,sha256=o5rv3Zd5cqogO_RZRkmmaKqx7W9PvkIBWBLYcNz3oR8,9358
186
+ pygeofetch-2.7.0.4.dist-info/METADATA,sha256=vN38qz7JsgERW2mDxG9u8Rxs821tFhMDQPXvlLFVM9Q,25014
187
+ pygeofetch-2.7.0.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
188
+ pygeofetch-2.7.0.4.dist-info/entry_points.txt,sha256=dHiUXLF5xNJ8vgtXZoUQNleEMQUeDPZiKQOE1tW8SDY,55
189
+ pygeofetch-2.7.0.4.dist-info/top_level.txt,sha256=S1tdXb-n2dy3gOtW1MRr5ZhE-Cj2BWpddP-tZLZ16kE,63
190
+ pygeofetch-2.7.0.4.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ pygeofetch
2
+ pygeofetch_tops_fix_part4
3
+ pygeofetch_tops_fix_part5