PyGeoFetch 2.7.0.4__py3-none-any.whl → 2.7.0.6__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.4.4"
33
+ __version__ = "2.7.0.6.4"
34
34
  __author__ = "PyGeoFetch Contributors"
35
35
  __license__ = "MIT"
36
36
 
pygeofetch/insar/esd.py CHANGED
@@ -583,3 +583,170 @@ def estimate_esd_shift_per_burst_overlap(
583
583
  combined / dt,
584
584
  )
585
585
  return combined, per_overlap_shifts
586
+
587
+
588
+ def _overlap_rows(swath_timing, dt: float, row_offset: int, n_rows: int):
589
+ """Yield (i, backward_rows, forward_rows) for each burst overlap i/i+1 inside an array of ``n_rows`` rows.
590
+
591
+ Same row arithmetic as estimate_esd_shift_per_burst_overlap: both images are on the reference's grid, so the
592
+ reference's own overlap windows locate the overlap rows of both.
593
+ """
594
+ import numpy as np
595
+
596
+ L = swath_timing.lines_per_burst
597
+ for i, r_start, r_end in overlap_time_windows(swath_timing, dt):
598
+ n_lines = int(round((r_end - r_start).total_seconds() / dt)) + 1
599
+ if n_lines < 3:
600
+ continue
601
+ bw, fw = [], []
602
+ for k in range(n_lines):
603
+ tt = r_start + timedelta(seconds=k * dt)
604
+ b = i * L + round((tt - swath_timing.bursts[i].azimuth_time).total_seconds() / dt) - row_offset
605
+ f = (i + 1) * L + round((tt - swath_timing.bursts[i + 1].azimuth_time).total_seconds() / dt) - row_offset
606
+ if 0 <= b < n_rows and 0 <= f < n_rows:
607
+ bw.append(b)
608
+ fw.append(f)
609
+ if len(bw) >= 3:
610
+ yield i, np.array(bw), np.array(fw)
611
+
612
+
613
+ def estimate_esd_blocks(
614
+ ref_complex,
615
+ sec_complex,
616
+ swath_timing,
617
+ azimuth_time_interval_s: float,
618
+ row_offset: int = 0,
619
+ delta_f_ovl_hz: float = SENTINEL1_IW_DELTA_F_OVL_HZ,
620
+ n_col_blocks: int = 8,
621
+ coherence_threshold: float = 0.2,
622
+ min_pixels: int = 200,
623
+ ):
624
+ """ESD per burst overlap AND per block of range columns: where in the image the misregistration is measured.
625
+
626
+ estimate_esd_shift_per_burst_overlap gives one number per pair. A residual misregistration that varies across
627
+ the scene (in range, or from one overlap to the next) leaves, after a constant correction, TOPS phase steps at
628
+ the burst seams of up to 2 pi * delta_f_ovl * dt * delta (about 55 rad per pixel for IW) and ramps inside the
629
+ bursts; 0.04 px is already a 2 rad step. Each block gives its own estimate, at the overlap's mean row and the
630
+ block's mean column (local array coordinates). Returns a list of dicts with keys overlap, row, col, shift_px,
631
+ coherence, n, weight (Fisher information of the mean double-difference phase, n * g^2 / (1 - g^2)).
632
+ """
633
+ import numpy as np
634
+ from scipy.ndimage import uniform_filter
635
+
636
+ dt = azimuth_time_interval_s
637
+ h, w = ref_complex.shape
638
+ edges = np.linspace(0, w, max(1, int(n_col_blocks)) + 1).astype(int)
639
+ out = []
640
+ for i, bw, fw in _overlap_rows(swath_timing, dt, int(row_offset), h):
641
+ ref_bw, sec_bw = ref_complex[bw].astype(np.complex64), sec_complex[bw].astype(np.complex64)
642
+ igram_bw = ref_bw * np.conj(sec_bw)
643
+ igram_fw = ref_complex[fw].astype(np.complex64) * np.conj(sec_complex[fw].astype(np.complex64))
644
+ win = min(5, len(bw))
645
+ num = np.abs(uniform_filter(igram_bw.real, size=win) + 1j * uniform_filter(igram_bw.imag, size=win))
646
+ den = np.sqrt(uniform_filter(np.abs(ref_bw) ** 2, size=win) * uniform_filter(np.abs(sec_bw) ** 2, size=win)) + 1e-10
647
+ coh = num / den
648
+ dd = igram_fw * np.conj(igram_bw)
649
+ for c0, c1 in zip(edges[:-1], edges[1:]):
650
+ if c1 - c0 < 2:
651
+ continue
652
+ ok = np.isfinite(coh[:, c0:c1]) & (coh[:, c0:c1] >= coherence_threshold)
653
+ n = int(ok.sum())
654
+ if n < min(min_pixels, ok.size // 2) or ok.mean() < 0.3:
655
+ continue
656
+ z = dd[:, c0:c1][ok]
657
+ g = float(np.clip(np.mean(coh[:, c0:c1][ok]), 0.0, 0.99))
658
+ phase = float(np.angle(np.mean(z)))
659
+ out.append({"overlap": int(i), "row": float(np.mean(bw)), "col": float(0.5 * (c0 + c1 - 1)),
660
+ "shift_px": phase / (2 * np.pi * delta_f_ovl_hz) / dt, "coherence": g, "n": n,
661
+ "weight": n * g * g / (1.0 - g * g)})
662
+ return out
663
+
664
+
665
+ def fit_esd_field(blocks, ambiguity_px: float, shape, min_blocks: int = 3, n_iter: int = 3):
666
+ """Fit a smooth residual misregistration field, delta = a + b col' (+ b2 (col'^2 - 1/12)) (+ c row'), to block ESD.
667
+
668
+ Each block's ESD is known only modulo ``ambiguity_px``; the blocks of one overlap are unwrapped along range
669
+ (the field is smooth) and each overlap is moved by whole ambiguities to the overall weighted median. Terms:
670
+ the constant always; range when the blocks span at least a quarter of the width (and a quadratic range term
671
+ with six or more blocks over half the width); azimuth when at least two overlaps contribute. Weighted least squares with outlier rejection (3 x MAD, at least 0.005 px).
672
+ Coordinates are normalised (col' = col / width - 0.5, row' = row / height - 0.5). Returns None when there are
673
+ too few blocks, else a dict with the terms, coefficients (px), an ``fn(rows, cols)`` evaluating the field in
674
+ local array coordinates, and the weighted RMS of the blocks about their mean (before) and about the field
675
+ (after).
676
+ """
677
+ import numpy as np
678
+
679
+ if len(blocks) < min_blocks or not (ambiguity_px > 0):
680
+ return None
681
+ h, w = shape
682
+ amb = float(ambiguity_px)
683
+ b = sorted(blocks, key=lambda d: (d["overlap"], d["col"]))
684
+ shift = np.array([d["shift_px"] for d in b], dtype=float)
685
+ ov = np.array([d["overlap"] for d in b])
686
+ for o in np.unique(ov):
687
+ m = ov == o
688
+ shift[m] = np.unwrap(shift[m] * 2 * np.pi / amb) * amb / (2 * np.pi)
689
+ wts = np.array([d["weight"] for d in b], dtype=float)
690
+
691
+ def wmedian(x, wt):
692
+ order = np.argsort(x)
693
+ cw = np.cumsum(wt[order])
694
+ return float(x[order][np.searchsorted(cw, 0.5 * cw[-1])])
695
+
696
+ ref_level = wmedian(shift, wts)
697
+ for o in np.unique(ov):
698
+ m = ov == o
699
+ shift[m] -= amb * np.round((wmedian(shift[m], wts[m]) - ref_level) / amb)
700
+ col_n = np.array([d["col"] for d in b], dtype=float) / max(w, 1) - 0.5
701
+ row_n = np.array([d["row"] for d in b], dtype=float) / max(h, 1) - 0.5
702
+ terms = ["const"]
703
+ cols = [np.ones_like(col_n)]
704
+ n_cols_distinct = len(np.unique(np.round(col_n, 3)))
705
+ if np.ptp(col_n) >= 0.25 and n_cols_distinct >= 3:
706
+ terms.append("range")
707
+ cols.append(col_n)
708
+ if np.ptp(col_n) >= 0.5 and n_cols_distinct >= 6:
709
+ terms.append("range2") # gentle curvature across the swath
710
+ cols.append(col_n ** 2 - 1.0 / 12.0)
711
+ if len(np.unique(ov)) >= 2:
712
+ terms.append("azimuth")
713
+ cols.append(row_n)
714
+ A = np.stack(cols, axis=1)
715
+ keep = np.ones(len(shift), bool)
716
+ coef = np.zeros(A.shape[1])
717
+ for _ in range(n_iter):
718
+ if keep.sum() < max(min_blocks, A.shape[1] + 1):
719
+ break
720
+ sw = np.sqrt(wts[keep])
721
+ coef = np.linalg.lstsq(A[keep] * sw[:, None], shift[keep] * sw, rcond=None)[0]
722
+ res = shift - A @ coef
723
+ mad = 1.4826 * np.median(np.abs(res[keep] - np.median(res[keep])))
724
+ new_keep = np.abs(res) <= max(3 * mad, 0.005)
725
+ if np.array_equal(new_keep, keep):
726
+ break
727
+ keep = new_keep
728
+ if keep.sum() < min_blocks:
729
+ return None
730
+ wk = wts[keep]
731
+ mean_k = float(np.sum(wk * shift[keep]) / wk.sum())
732
+ rms_before = float(np.sqrt(np.sum(wk * (shift[keep] - mean_k) ** 2) / wk.sum()))
733
+ res = shift - A @ coef
734
+ rms_after = float(np.sqrt(np.sum(wk * res[keep] ** 2) / wk.sum()))
735
+ coefs = dict(zip(terms, (float(c) for c in coef)))
736
+
737
+ def fn(rows, cols_):
738
+ rows = np.asarray(rows, dtype=np.float64)
739
+ cols_ = np.asarray(cols_, dtype=np.float64)
740
+ out = coefs["const"] + 0.0 * (rows + cols_)
741
+ if "range" in coefs:
742
+ out = out + coefs["range"] * (cols_ / max(w, 1) - 0.5)
743
+ if "range2" in coefs:
744
+ out = out + coefs["range2"] * ((cols_ / max(w, 1) - 0.5) ** 2 - 1.0 / 12.0)
745
+ if "azimuth" in coefs:
746
+ out = out + coefs["azimuth"] * (rows / max(h, 1) - 0.5)
747
+ return out
748
+
749
+ corners = fn(np.array([0.0, 0.0, h - 1.0, h - 1.0]), np.array([0.0, w - 1.0, 0.0, w - 1.0]))
750
+ return {"terms": terms, "coef_px": coefs, "fn": fn, "n_blocks": int(len(b)), "n_used": int(keep.sum()),
751
+ "n_overlaps": int(len(np.unique(ov))), "rms_before_px": rms_before, "rms_after_px": rms_after,
752
+ "ptp_px": float(np.ptp(corners))}
@@ -509,6 +509,13 @@ class InterferogramGenerator:
509
509
  esd_enabled: Apply ESD refinement (default True). Only
510
510
  meaningful for burst-mode (TOPS) SLC pairs;
511
511
  has no effect on already-deburst/stripmap data.
512
+ esd_field: After the constant ESD shift, also measure ESD per burst overlap and range block and
513
+ remove a smoothly varying residual misregistration (constant + range + azimuth terms).
514
+ TOPS pairs only (default True).
515
+ esd_ambiguity_scan: How to pick the whole number of ESD ambiguities (~0.11 px each) that ESD cannot see:
516
+ "auto" (default) keeps k = 0 when cross-correlation pins the first-stage offset to
517
+ better than a quarter ambiguity and runs the coherence scan otherwise; "always" or
518
+ "never" force it.
512
519
  use_gpu: Use CuPy GPU acceleration if available.
513
520
  memory_guard: "warn" (default) | "raise" | "off". Compares the estimated peak memory of a pair with the
514
521
  available memory before the SLCs are read; "raise" stops with MemoryError instead of
@@ -565,6 +572,8 @@ class InterferogramGenerator:
565
572
  on_error: str = "raise",
566
573
  dem_geoid_offset_m: float = 0.0,
567
574
  memory_guard: str = "warn",
575
+ esd_field: bool = True,
576
+ esd_ambiguity_scan: str = "auto",
568
577
  ) -> None:
569
578
  # Added to every DEM height before use. Most DEMs are orthometric (Copernicus DEM: EGM2008) but the geometry
570
579
  # needs ellipsoidal heights; the difference (about +40 m in Silesia) shifts the geocoding by ~N/tan(incidence)
@@ -592,6 +601,10 @@ class InterferogramGenerator:
592
601
  # below). An explicit value here is always respected as-is.
593
602
  self._coh_window_explicit = coherence_window
594
603
  self._esd_enabled = esd_enabled
604
+ self._esd_field_enabled = bool(esd_field)
605
+ if esd_ambiguity_scan not in ("auto", "always", "never"):
606
+ raise ValueError(f"esd_ambiguity_scan must be 'auto', 'always' or 'never', got {esd_ambiguity_scan!r}")
607
+ self._esd_ambiguity_scan = esd_ambiguity_scan
595
608
  self._use_gpu = use_gpu
596
609
  if verbosity is not None:
597
610
  from pygeofetch.insar.logs import set_verbosity
@@ -615,7 +628,7 @@ class InterferogramGenerator:
615
628
  self._tops_ctx = None
616
629
  # Part of every pair fingerprint: results saved before TOPS deramping (0) or before resampling onto the
617
630
  # reference grid (1) are not reused.
618
- self._tops_deramp_version = 4
631
+ self._tops_deramp_version = 6
619
632
  # Automatic by default (None): on when the inputs exist, explicit
620
633
  # True/False always respected. It used to be opt-in and silent, which
621
634
  # left a full-width range ramp in every interferogram unless the caller
@@ -1439,10 +1452,17 @@ class InterferogramGenerator:
1439
1452
  logger.warning("ESD residual re-estimation failed: %s", exc)
1440
1453
  # Resolve ESD's whole-ambiguity blind spot (TOPS pairs only).
1441
1454
  if getattr(self, "_tops_ctx", None) is not None:
1455
+ _amb = 1.0 / ((_df if _df else 5200.0) * azimuth_time_interval_s)
1442
1456
  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)
1457
+ _scan, _why = self._esd_scan_needed(_amb)
1458
+ if _scan:
1459
+ sec_complex, _amb_info = self._resolve_esd_ambiguity(ref_complex, sec_complex, _amb)
1460
+ else:
1461
+ _amb_info = {"ambiguity_px": float(_amb), "k": 0, "scanned": False, "reason": _why}
1462
+ logger.info("ESD ambiguity: k = 0 kept without a coherence scan (%s)", _why)
1445
1463
  if _amb_info is not None:
1464
+ _amb_info.setdefault("scanned", True)
1465
+ _amb_info.setdefault("reason", _why)
1446
1466
  _total = esd_shift_px + _amb_info["k"] * _amb
1447
1467
  if _amb_info["k"] != 0:
1448
1468
  # ESD again, now within its unambiguous range of the true alignment: the first
@@ -1459,6 +1479,15 @@ class InterferogramGenerator:
1459
1479
  metadata["esd_total_shift_px"] = _total
1460
1480
  except Exception as exc: # noqa: BLE001
1461
1481
  logger.warning("ESD ambiguity scan failed: %s", exc)
1482
+ # What a single constant cannot remove: misregistration varying in range and between
1483
+ # overlaps (steps at burst seams, ramps inside bursts).
1484
+ if getattr(self, "_esd_field_enabled", True):
1485
+ try:
1486
+ sec_complex, metadata["esd_field"] = self._esd_field_refinement(
1487
+ ref_complex, sec_complex, ref_burst_info, azimuth_time_interval_s,
1488
+ int(ref_row_off), _amb, _esd_kwargs)
1489
+ except Exception as exc: # noqa: BLE001
1490
+ logger.warning("ESD field refinement failed: %s", exc)
1462
1491
  else:
1463
1492
  logger.info(
1464
1493
  "Real per-burst-overlap ESD found no usable burst "
@@ -2612,6 +2641,7 @@ class InterferogramGenerator:
2612
2641
  "esd_delta_f_ovl_hz": burst_metadata.get("esd_delta_f_ovl_hz"),
2613
2642
  "esd_ambiguity": burst_metadata.get("esd_ambiguity"),
2614
2643
  "esd_total_shift_px": burst_metadata.get("esd_total_shift_px"),
2644
+ "esd_field": burst_metadata.get("esd_field"),
2615
2645
  "esd_residual_after_correction_px": burst_metadata.get("esd_residual_after_correction_px"),
2616
2646
  "quality": quality.to_dict(),
2617
2647
  "quality_grade": quality.grade,
@@ -3081,6 +3111,9 @@ class InterferogramGenerator:
3081
3111
  self._tops_ctx = {
3082
3112
  "ref_ramp": ref_ramp, "sec_ramp": sec_ramp, "row_fn": row_fn, "col_fn": col_fn,
3083
3113
  "ref_row_off": float(ref_row_off), "ref_col_off": float(ref_col_off),
3114
+ # how well the first stage pins the constant azimuth offset (decides the ESD ambiguity scan)
3115
+ "coreg_mode": coreg_quality.mode, "coreg_n": coreg_quality.n_gcps_final,
3116
+ "coreg_rms_px": coreg_quality.rms_mean,
3084
3117
  }
3085
3118
  return resampled, coreg_metadata
3086
3119
 
@@ -3317,15 +3350,99 @@ class InterferogramGenerator:
3317
3350
  sec_ramp, row_fn, col_fn = ctx["sec_ramp"], ctx["row_fn"], ctx["col_fn"]
3318
3351
  r_off, c_off = ctx["ref_row_off"], ctx["ref_col_off"] + col_offset
3319
3352
  applied = ctx.get("applied_shift_px", 0.0)
3353
+ fields = list(ctx.get("applied_shift_fields", ())) # spatially varying shifts, local coordinates
3320
3354
 
3321
3355
  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
3356
+ rows = np.asarray(rows, dtype=np.float64)
3357
+ cols = np.asarray(cols, dtype=np.float64)
3358
+ rl = rows - applied
3359
+ for f in fields:
3360
+ rl = rl - np.asarray(f(rows, cols + col_offset), dtype=np.float64)
3361
+ rg = rl + r_off
3362
+ cg = cols + c_off
3324
3363
  return sec_ramp.phase(rg + np.asarray(row_fn(rg, cg), dtype=np.float64),
3325
3364
  cg + np.asarray(col_fn(rg, cg), dtype=np.float64))
3326
3365
 
3327
3366
  return content_phase
3328
3367
 
3368
+ def _apply_azimuth_shift_field(self, data, shift_fn):
3369
+ """TOPS-aware azimuth shift by a smoothly varying field ``shift_fn(rows, cols)`` (local coordinates, px)."""
3370
+ np = self._np()
3371
+ ctx = getattr(self, "_tops_ctx", None)
3372
+ if ctx is None:
3373
+ raise ValueError("a spatially varying azimuth shift needs the TOPS context")
3374
+ from pygeofetch.insar.tops import shift_azimuth_tops_field
3375
+
3376
+ content_phase = self._tops_content_phase(ctx)
3377
+ out = shift_azimuth_tops_field(np.asarray(data), shift_fn, content_phase, ctx["ref_ramp"].lines_per_burst,
3378
+ ctx["ref_row_off"])
3379
+ ctx.setdefault("applied_shift_fields", []).append(shift_fn)
3380
+ return out
3381
+
3382
+ def _esd_field_refinement(self, ref_complex, sec_complex, swath_timing, dt: float, row_offset: int,
3383
+ ambiguity_px: float, esd_kwargs: dict, n_col_blocks: int = 10,
3384
+ min_ptp_px: float = 0.002):
3385
+ """Measure ESD per overlap and range block, fit a smooth residual misregistration field and remove it.
3386
+
3387
+ After the constant ESD shift (and its ambiguity), the misregistration can still vary across the scene: in
3388
+ range (the cross-correlation fit's range term) and from one burst overlap to the next. In TOPS data that
3389
+ leaves phase steps at the burst seams (about 55 rad per pixel of misregistration for IW) and ramps inside
3390
+ the bursts, which phase closure exposes but coherence and the constant ESD residual do not. Returns the
3391
+ (possibly shifted) secondary and a metadata dict.
3392
+ """
3393
+ from pygeofetch.insar.esd import estimate_esd_blocks, fit_esd_field
3394
+
3395
+ blocks = estimate_esd_blocks(ref_complex, sec_complex, swath_timing, dt, row_offset=row_offset,
3396
+ n_col_blocks=n_col_blocks, **esd_kwargs)
3397
+ fit = fit_esd_field(blocks, ambiguity_px, ref_complex.shape)
3398
+ if fit is None:
3399
+ logger.info("ESD field: too few usable overlap blocks (%d) for a spatially varying correction", len(blocks))
3400
+ return sec_complex, {"applied": False, "n_blocks": len(blocks)}
3401
+ info = {k: v for k, v in fit.items() if k != "fn"}
3402
+ info["applied"] = False
3403
+ if fit["ptp_px"] >= min_ptp_px or abs(fit["coef_px"]["const"]) >= 1e-4:
3404
+ sec_complex = self._apply_azimuth_shift_field(sec_complex, fit["fn"])
3405
+ info["applied"] = True
3406
+ after = estimate_esd_blocks(ref_complex, sec_complex, swath_timing, dt, row_offset=row_offset,
3407
+ n_col_blocks=n_col_blocks, **esd_kwargs)
3408
+ refit = fit_esd_field(after, ambiguity_px, ref_complex.shape)
3409
+ if refit is not None:
3410
+ info["residual_rms_px"] = refit["rms_before_px"]
3411
+ info["residual_coef_px"] = refit["coef_px"]
3412
+ logger.info("ESD field (%d blocks in %d overlap(s), terms %s): %s px, spread %.4f px across the image; "
3413
+ "block scatter %.4f px before, %.4f px about the field%s",
3414
+ fit["n_used"], fit["n_overlaps"], "+".join(fit["terms"]),
3415
+ ", ".join(f"{k} {v:+.4f}" for k, v in fit["coef_px"].items()), fit["ptp_px"],
3416
+ fit["rms_before_px"], fit["rms_after_px"],
3417
+ f"; after correction {info['residual_rms_px']:.4f} px" if "residual_rms_px" in info else "")
3418
+ return sec_complex, info
3419
+
3420
+ def _esd_scan_needed(self, ambiguity_px: float):
3421
+ """Whether to choose the ESD ambiguity k by the coherence scan, and why.
3422
+
3423
+ ``esd_ambiguity_scan``: "always", "never" or "auto" (default). The coherence scan is a weak criterion: the
3424
+ coherence changes by about 0.1 % per ambiguity near the optimum, and on Mexico City Sentinel-1 triplets it
3425
+ picked k = -2 and k = -1 where phase closure showed k = 0 was right (a wrong k leaves exactly k fringes per
3426
+ burst along track, invisible at the seams). "auto" therefore keeps k = 0 when the first-stage
3427
+ coregistration already pins the constant azimuth offset to well within half an ambiguity, i.e. when
3428
+ cross-correlation supports the fit and RMS / sqrt(n) < ambiguity / 4, and scans only otherwise
3429
+ (geometry-only first stage, or too few / too noisy cross-correlation points).
3430
+ """
3431
+ policy = getattr(self, "_esd_ambiguity_scan", "auto")
3432
+ if policy == "always":
3433
+ return True, "esd_ambiguity_scan='always'"
3434
+ if policy == "never":
3435
+ return False, "esd_ambiguity_scan='never'"
3436
+ ctx = getattr(self, "_tops_ctx", None) or {}
3437
+ mode, n, rms = ctx.get("coreg_mode"), ctx.get("coreg_n"), ctx.get("coreg_rms_px")
3438
+ if mode in (None, "geometry_only") or not n or rms is None:
3439
+ return True, f"first stage without cross-correlation support (mode {mode})"
3440
+ sigma = float(rms) / max(float(n), 1.0) ** 0.5
3441
+ if sigma < ambiguity_px / 4:
3442
+ return False, (f"first stage {mode} from {n} cross-correlation points pins the offset to "
3443
+ f"{sigma:.3f} px (< ambiguity/4 = {ambiguity_px / 4:.3f} px)")
3444
+ return True, f"first stage offset uncertain ({sigma:.3f} px >= ambiguity/4 = {ambiguity_px / 4:.3f} px)"
3445
+
3329
3446
  def _resolve_esd_ambiguity(self, ref_complex, sec_complex, ambiguity_px: float, k_max: int = 4,
3330
3447
  max_cols: int = 1536, k_limit: int = 15):
3331
3448
  """Pick the whole number of ESD ambiguities to add to the azimuth shift, by coherence.
pygeofetch/insar/tops.py CHANGED
@@ -372,3 +372,45 @@ def shift_azimuth_tops(data: np.ndarray, shift_px: float, content_phase, lines_p
372
372
  block *= np.exp(1j * content_phase(rows - shift_px, cols))
373
373
  out[r0:r1, c0:c1] = block.astype(np.complex64)
374
374
  return out
375
+
376
+
377
+ def shift_azimuth_tops_field(data: np.ndarray, shift_fn, content_phase, lines_per_burst: int, row_offset: float,
378
+ col_block: int = 256) -> np.ndarray:
379
+ """Like shift_azimuth_tops, but by a smoothly varying shift ``shift_fn(rows, cols)`` (local coordinates, px).
380
+
381
+ Within each burst segment the data are deramped; the field's mean over the array is applied with an exact
382
+ Fourier shift, the small remainder d(r, c) with a second-order Taylor step, s(r - m - d) ~ g - d g' + d^2/2 g''
383
+ with g the Fourier-shifted segment and g', g'' its Fourier derivatives (error O(d^3), negligible for the
384
+ hundredths of a pixel ESD fields carry). The data are reramped with the phase at the positions they came from.
385
+ """
386
+ h, w = data.shape
387
+ out = data if (data.dtype == np.complex64 and data.flags.writeable) else data.astype(np.complex64)
388
+ rr = np.linspace(0, h - 1, 9)[:, None]
389
+ cc = np.linspace(0, w - 1, 9)[None, :]
390
+ mean = float(np.mean(shift_fn(rr + 0 * cc, cc + 0 * rr)))
391
+ starts = sorted({0, h} | {int(math.ceil(b * lines_per_burst - row_offset))
392
+ for b in range(int(row_offset // lines_per_burst) + 1,
393
+ int((row_offset + h) // lines_per_burst) + 1)})
394
+ starts = [s for s in starts if 0 <= s <= h]
395
+ for r0, r1 in zip(starts[:-1], starts[1:]):
396
+ n = r1 - r0
397
+ if n < 2:
398
+ continue
399
+ freq = np.fft.fftfreq(n).reshape(-1, 1)
400
+ ramp = np.exp(-2j * np.pi * freq * mean)
401
+ d1 = 2j * np.pi * freq
402
+ rows = np.arange(r0, r1, dtype=np.float64)[:, None]
403
+ for c0 in range(0, w, col_block):
404
+ c1 = min(w, c0 + col_block)
405
+ cols = np.arange(c0, c1, dtype=np.float64)[None, :]
406
+ shift = np.asarray(shift_fn(rows + 0 * cols, cols + 0 * rows), dtype=np.float64)
407
+ d = shift - mean
408
+ spec = np.fft.fft(out[r0:r1, c0:c1].astype(np.complex128) * np.exp(-1j * content_phase(rows, cols)),
409
+ axis=0) * ramp
410
+ g = np.fft.ifft(spec, axis=0)
411
+ g1 = np.fft.ifft(spec * d1, axis=0)
412
+ g2 = np.fft.ifft(spec * d1 * d1, axis=0)
413
+ block = g - d * g1 + 0.5 * d * d * g2
414
+ block *= np.exp(1j * content_phase(rows - shift, cols))
415
+ out[r0:r1, c0:c1] = block.astype(np.complex64)
416
+ return out
pygeofetch/meta.yaml CHANGED
@@ -1,4 +1,4 @@
1
- {% set version = "2.7.0.4.4" %}
1
+ {% set version = "2.7.0.6.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.4
3
+ Version: 2.7.0.6
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.4.1},
374
+ version = {2.7.0.6.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=PWgaPdphhZB3iQq6he8iWgqrwfK-CizJXSBJzh94xpQ,2107
2
- pygeofetch/meta.yaml,sha256=UgcwTzv2cO9lxfHHelmZv7gaYQx3ptNyL4w8lGYzEmU,1284
1
+ pygeofetch/__init__.py,sha256=O18_DPgWq5U5jEMmXFnCK8Bfp2Rrs6uOQ93W07Fmkhg,2107
2
+ pygeofetch/meta.yaml,sha256=sc3OupnE1gfT0Ns2pyT3QT8NJalX_h5heL4-8Um8AYI,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
@@ -48,14 +48,14 @@ pygeofetch/insar/auto_fallback.py,sha256=zBZuFpfn4FCHmW9GZ_D5YbVEvA-yjFLCT4gizuS
48
48
  pygeofetch/insar/coregister.py,sha256=bmM4tcAZiMDaqqwiPFyrGUFTJm_u5oDbOni6jOzPa0Q,74225
49
49
  pygeofetch/insar/deburst.py,sha256=dzdB-jMupkalvUXoNxalLD31HNkMqyyXagpE5XSXT1g,8017
50
50
  pygeofetch/insar/errors.py,sha256=KTgmnGS05kgjZJdFAB3frPZC_eGrOE3xqZq-ORwOsd0,6625
51
- pygeofetch/insar/esd.py,sha256=FR0k7TwIUGInDA1u9cW4zrrX0HGTY5MuclfeDcShL9k,26177
51
+ pygeofetch/insar/esd.py,sha256=PvvEUFPx1kvy6AI4pntowzUxssSeDK8FZfqw9nQhD2s,34392
52
52
  pygeofetch/insar/extraction.py,sha256=J6YjszYvHi6lizX5vGq71KuMLHmYqtdG-oDUUb60adg,41417
53
53
  pygeofetch/insar/feasibility.py,sha256=4301EIaqy4jtME1NaNvIwSyqJY7ZH39Hto6Uk0c_M5Q,13371
54
54
  pygeofetch/insar/flatearth.py,sha256=gSUdDcHlxs3P2TrUkKFkIwq7GftKVOit0A47CaBKIvc,13566
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=NcqtSp7qu9Gf38wjr9d7qWTrKX1IM1Lz3q9sZQp7hCY,180215
58
+ pygeofetch/insar/interferogram.py,sha256=ib8bCmSLxQwqaX-rTlCXLWOsxYY86JtnNflhOFA2SU8,188375
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
@@ -76,7 +76,7 @@ pygeofetch/insar/stack_selection.py,sha256=T0QQsiw7TZcc2PZMZXYliAv50UkLUALKUeC0V
76
76
  pygeofetch/insar/synthetic.py,sha256=QBHDPp3c8HFvYw4Tt1usGhMZ7D9VD3MT4USbQ7rZ5Sk,16595
77
77
  pygeofetch/insar/timeseries.py,sha256=ArKDu5nYHQmue-n-YUweAU_MPIUoNF26TCitFCjC5MQ,75898
78
78
  pygeofetch/insar/topo.py,sha256=LyfUVRyrUEgjoRJPripinyhudz3R0Mg1NMBrNn6a4qs,14349
79
- pygeofetch/insar/tops.py,sha256=-yIthiWED20u7t10m8M3AHEBaa8PDS_rvS-oDnYevgM,18459
79
+ pygeofetch/insar/tops.py,sha256=ozA8SjgqO6bN8cwwQzKlJS7sQqZmrabISBhRV8H_0hg,20847
80
80
  pygeofetch/insar/unwrap.py,sha256=kQWASRas74vFgj4HPX9Yoq6DXPFLJMLifJFkMDatMpk,36241
81
81
  pygeofetch/insar/validate.py,sha256=guIt70yzOGGmNGFRZwzg7t0usu2zqc6xIAq4fPvM9JY,15096
82
82
  pygeofetch/insar/visualize.py,sha256=47V22sbLwhinFSPPMs2wdACyAurSO12vlYwXi7zCGv4,8422
@@ -170,7 +170,7 @@ 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.4.dist-info/licenses/LICENSE,sha256=zavMyhODD6NvZTmmKFEtATrngwY4CU_NEtY7lhjxGnI,1075
173
+ pygeofetch-2.7.0.6.dist-info/licenses/LICENSE,sha256=zavMyhODD6NvZTmmKFEtATrngwY4CU_NEtY7lhjxGnI,1075
174
174
  pygeofetch_tops_fix_part4/files/pygeofetch/insar/coregister.py,sha256=bmM4tcAZiMDaqqwiPFyrGUFTJm_u5oDbOni6jOzPa0Q,74225
175
175
  pygeofetch_tops_fix_part4/files/pygeofetch/insar/interferogram.py,sha256=UQb_l3oOhxR_Dy-f1Uc3YoqlzFz6SPCTz89EiuKn-U0,178492
176
176
  pygeofetch_tops_fix_part4/files/pygeofetch/insar/tops.py,sha256=-yIthiWED20u7t10m8M3AHEBaa8PDS_rvS-oDnYevgM,18459
@@ -183,8 +183,20 @@ pygeofetch_tops_fix_part5/files/pygeofetch/insar/tops.py,sha256=-yIthiWED20u7t10
183
183
  pygeofetch_tops_fix_part5/files/tests/insar/_fake_safe.py,sha256=-ntqxg2Ln-8ZHxC3Waq1qTbVNAj5Iwj40Bc49Q9kD_A,3356
184
184
  pygeofetch_tops_fix_part5/files/tests/insar/_tops_sim.py,sha256=t6-ahcc9unf2aLqFTmdMWMeN9gGgU7bFG2ddWS5ZVzY,4776
185
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,,
186
+ pygeofetch_tops_fix_part6/pygeofetch/insar/esd.py,sha256=PvvEUFPx1kvy6AI4pntowzUxssSeDK8FZfqw9nQhD2s,34392
187
+ pygeofetch_tops_fix_part6/pygeofetch/insar/interferogram.py,sha256=Y7ThJTUX5jbVQPNZwbSKXDhiHzjhb3fIDJCOvtzT6to,185120
188
+ pygeofetch_tops_fix_part6/pygeofetch/insar/tops.py,sha256=ozA8SjgqO6bN8cwwQzKlJS7sQqZmrabISBhRV8H_0hg,20847
189
+ pygeofetch_tops_fix_part6/tests/insar/_fake_safe.py,sha256=-ntqxg2Ln-8ZHxC3Waq1qTbVNAj5Iwj40Bc49Q9kD_A,3356
190
+ pygeofetch_tops_fix_part6/tests/insar/_tops_sim.py,sha256=t6-ahcc9unf2aLqFTmdMWMeN9gGgU7bFG2ddWS5ZVzY,4776
191
+ pygeofetch_tops_fix_part6/tests/insar/test_tops_deramp.py,sha256=qGYYoPsS09xEAry2s4jp0zeTxJVv5dDtnq6QNPce-rc,11571
192
+ pygeofetch_tops_fix_part7/pygeofetch/insar/esd.py,sha256=PvvEUFPx1kvy6AI4pntowzUxssSeDK8FZfqw9nQhD2s,34392
193
+ pygeofetch_tops_fix_part7/pygeofetch/insar/interferogram.py,sha256=ib8bCmSLxQwqaX-rTlCXLWOsxYY86JtnNflhOFA2SU8,188375
194
+ pygeofetch_tops_fix_part7/pygeofetch/insar/tops.py,sha256=ozA8SjgqO6bN8cwwQzKlJS7sQqZmrabISBhRV8H_0hg,20847
195
+ pygeofetch_tops_fix_part7/tests/insar/_fake_safe.py,sha256=-ntqxg2Ln-8ZHxC3Waq1qTbVNAj5Iwj40Bc49Q9kD_A,3356
196
+ pygeofetch_tops_fix_part7/tests/insar/_tops_sim.py,sha256=t6-ahcc9unf2aLqFTmdMWMeN9gGgU7bFG2ddWS5ZVzY,4776
197
+ pygeofetch_tops_fix_part7/tests/insar/test_tops_deramp.py,sha256=vWorPj79Y0Zwd0_seEV-t8WYeXOH_5oCgW1zUfnnC3s,12633
198
+ pygeofetch-2.7.0.6.dist-info/METADATA,sha256=2dbyK0bAoDxCdoJkO10aVF5nxU6SK5nSCypefqgG_X4,25014
199
+ pygeofetch-2.7.0.6.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
200
+ pygeofetch-2.7.0.6.dist-info/entry_points.txt,sha256=dHiUXLF5xNJ8vgtXZoUQNleEMQUeDPZiKQOE1tW8SDY,55
201
+ pygeofetch-2.7.0.6.dist-info/top_level.txt,sha256=9eHek70wg-Vt21GG0ulmDtyOF9Aov2JqpGwmXvMUs9I,115
202
+ pygeofetch-2.7.0.6.dist-info/RECORD,,
@@ -1,3 +1,5 @@
1
1
  pygeofetch
2
2
  pygeofetch_tops_fix_part4
3
3
  pygeofetch_tops_fix_part5
4
+ pygeofetch_tops_fix_part6
5
+ pygeofetch_tops_fix_part7