PyGeoFetch 2.7.1.0__py3-none-any.whl → 2.7.3__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.1.0.4"
33
+ __version__ = "2.7.3.4"
34
34
  __author__ = "PyGeoFetch Contributors"
35
35
  __license__ = "MIT"
36
36
 
pygeofetch/meta.yaml CHANGED
@@ -1,4 +1,4 @@
1
- {% set version = "2.7.1.0.4" %}
1
+ {% set version = "2.7.3.4" %}
2
2
 
3
3
  package:
4
4
  name: pygeofetch
@@ -291,6 +291,46 @@ def _pick_member(names: List[str], folder: str, prefix: str,
291
291
  return sorted(hits)[0] if hits else None
292
292
 
293
293
 
294
+ # Pixels added around the AOI when cropping a GRD in radar geometry. The AOI
295
+ # corners are located from the product's sparse GCPs, so a generous margin
296
+ # absorbs the interpolation error of that lookup.
297
+ _AOI_MARGIN_PX = 300
298
+ # GCPs kept for georeferencing a cropped product (the nearest ones): a local
299
+ # polynomial fit is far more accurate over a small window than one fitted to
300
+ # GCPs spread over a whole 250 km scene.
301
+ _AOI_KEEP_GCPS = 16
302
+
303
+
304
+ def _aoi_window(gcps, bbox, width: int, height: int):
305
+ """
306
+ Rows/columns of a GRD that cover a lon/lat box, found from its GCPs.
307
+
308
+ Returns ``(r0, r1, c0, c1)`` (half-open, clipped to the image, with
309
+ ``_AOI_MARGIN_PX`` of margin) or None when the box lies outside the
310
+ image. The (lon, lat) -> (row, col) lookup interpolates linearly between
311
+ GCPs, falling back to the nearest GCP outside their hull.
312
+ """
313
+ from scipy.interpolate import griddata
314
+
315
+ pts = np.array([[g.x, g.y] for g in gcps], dtype=np.float64)
316
+ rc = np.array([[g.row, g.col] for g in gcps], dtype=np.float64)
317
+ min_lon, min_lat, max_lon, max_lat = bbox
318
+ lon, lat = np.meshgrid(np.linspace(min_lon, max_lon, 5),
319
+ np.linspace(min_lat, max_lat, 5))
320
+ q = np.column_stack([lon.ravel(), lat.ravel()])
321
+ out = griddata(pts, rc, q, method="linear")
322
+ near = griddata(pts, rc, q, method="nearest")
323
+ out = np.where(np.isnan(out), near, out)
324
+ r0 = int(np.floor(out[:, 0].min())) - _AOI_MARGIN_PX
325
+ r1 = int(np.ceil(out[:, 0].max())) + _AOI_MARGIN_PX + 1
326
+ c0 = int(np.floor(out[:, 1].min())) - _AOI_MARGIN_PX
327
+ c1 = int(np.ceil(out[:, 1].max())) + _AOI_MARGIN_PX + 1
328
+ r0, r1, c0, c1 = max(r0, 0), min(r1, height), max(c0, 0), min(c1, width)
329
+ if r1 <= r0 or c1 <= c0:
330
+ return None
331
+ return r0, r1, c0, c1
332
+
333
+
294
334
  def _extract_member(zf: zipfile.ZipFile, member: str, dest: Path) -> None:
295
335
  """Stream one zip member to disk in chunks (no whole-file RAM copy)."""
296
336
  with zf.open(member) as src, open(dest, "wb") as dst:
@@ -417,6 +457,7 @@ class GRDExtractor:
417
457
  out_db: bool = True,
418
458
  floor_db: Optional[float] = None,
419
459
  block_rows: int = 512,
460
+ aoi_bbox: Optional[Tuple[float, float, float, float]] = None,
420
461
  streaming_cleanup: bool = False,
421
462
  ) -> Optional[Path]:
422
463
  """
@@ -451,6 +492,12 @@ class GRDExtractor:
451
492
  that value instead (non-positive pixels become the
452
493
  floor, so dark areas stay in the time series).
453
494
  block_rows: Rows per processing block.
495
+ aoi_bbox: Optional ``(min_lon, min_lat, max_lon, max_lat)``. When
496
+ given, only the part of the scene around it (plus
497
+ ~3 km margin) is calibrated and written: roughly 10 MB
498
+ instead of the ~0.5-1 GB of a full scene, and much
499
+ faster. Needs the product's GCPs (GRD always has them);
500
+ without them the call fails rather than guessing.
454
501
  streaming_cleanup: Verify-then-delete. When True, the raw
455
502
  .SAFE.zip is deleted ONLY after the output COG has been
456
503
  written and verified. On any failure the zip is kept.
@@ -479,7 +526,8 @@ class GRDExtractor:
479
526
  quantity = {"sigmaNought": "sigma0", "betaNought": "beta0",
480
527
  "gamma": "gamma0", "dn": "dn"}[lut]
481
528
  stem = f"{label}_{self._pol}" if label else self._pol
482
- final = output_dir / self.sigma0_filename(label, lut=lut, out_db=out_db)
529
+ final = output_dir / self.sigma0_filename(
530
+ label, lut=lut, out_db=out_db, aoi_bbox=aoi_bbox)
483
531
  partial = final.with_name(final.name + ".partial")
484
532
  raw = output_dir / f"{stem}_raw.tif" # extracted measurement
485
533
  radar = output_dir / f"{stem}_{quantity}_radar.tif"
@@ -502,7 +550,7 @@ class GRDExtractor:
502
550
  with zipfile.ZipFile(zip_path) as zf:
503
551
  tags, had_gcps = self._calibrate_to_radar_tif(
504
552
  zf, raw, radar, lut, quantity, remove_noise,
505
- out_db, floor_db, block_rows,
553
+ out_db, floor_db, block_rows, aoi_bbox,
506
554
  )
507
555
  if tags is None:
508
556
  return None
@@ -551,19 +599,30 @@ class GRDExtractor:
551
599
  gc.collect()
552
600
 
553
601
  def sigma0_filename(
554
- self, label: str = "", *, lut: str = "sigmaNought", out_db: bool = True
602
+ self, label: str = "", *, lut: str = "sigmaNought", out_db: bool = True,
603
+ aoi_bbox: Optional[Tuple[float, float, float, float]] = None,
555
604
  ) -> str:
556
605
  """Name extract_sigma0() gives its output, so a caller can check whether
557
- a verified product already exists BEFORE downloading the scene again."""
606
+ a verified product already exists BEFORE downloading the scene again.
607
+ A cropped product carries a short hash of its box, so it is never
608
+ mistaken for a full-scene one (or for another box)."""
609
+ import hashlib
610
+
558
611
  quantity = {"sigmaNought": "sigma0", "betaNought": "beta0",
559
612
  "gamma": "gamma0", "dn": "dn"}[lut]
560
613
  stem = f"{label}_{self._pol}" if label else self._pol
561
- return f"{stem}_{quantity}_{'db' if out_db else 'lin'}.tif"
614
+ crop = ""
615
+ if aoi_bbox is not None:
616
+ digest = hashlib.md5(
617
+ ",".join(f"{v:.5f}" for v in aoi_bbox).encode()).hexdigest()[:6]
618
+ crop = f"_aoi{digest}"
619
+ return f"{stem}_{quantity}_{'db' if out_db else 'lin'}{crop}.tif"
562
620
 
563
621
  def _calibrate_to_radar_tif(
564
622
  self, zf: zipfile.ZipFile, raw: Path, radar: Path, lut: str,
565
623
  quantity: str, remove_noise: bool, out_db: bool,
566
624
  floor_db: Optional[float], block_rows: int,
625
+ aoi_bbox: Optional[Tuple[float, float, float, float]] = None,
567
626
  ) -> Tuple[Optional[dict], bool]:
568
627
  """
569
628
  Extract the measurement TIFF and write the calibrated raster, still
@@ -575,6 +634,7 @@ class GRDExtractor:
575
634
  import warnings
576
635
 
577
636
  import rasterio
637
+ import rasterio.control
578
638
  from rasterio.windows import Window
579
639
 
580
640
  names = zf.namelist()
@@ -600,6 +660,28 @@ class GRDExtractor:
600
660
  with rasterio.open(raw) as src:
601
661
  width, height = src.width, src.height
602
662
  gcps, gcp_crs = src.gcps
663
+ # Crop window in the original radar geometry (the whole scene by
664
+ # default). The LUTs are still indexed by full-scene line/pixel.
665
+ r_lo, r_hi, c_lo, c_hi = 0, height, 0, width
666
+ if aoi_bbox is not None:
667
+ win = _aoi_window(gcps, aoi_bbox, width, height) if gcps else None
668
+ if win is None:
669
+ logger.error(
670
+ "Cannot crop to the AOI (no GCPs, or the box lies "
671
+ "outside this scene)")
672
+ return None, False
673
+ r_lo, r_hi, c_lo, c_hi = win
674
+ # keep only the GCPs nearest the window, shifted to the crop
675
+ cr, cc = (r_lo + r_hi) / 2, (c_lo + c_hi) / 2
676
+ gcps = sorted(
677
+ gcps, key=lambda g: (g.row - cr) ** 2 + (g.col - cc) ** 2
678
+ )[:_AOI_KEEP_GCPS]
679
+ gcps = [
680
+ rasterio.control.GroundControlPoint(
681
+ row=g.row - r_lo, col=g.col - c_lo, x=g.x, y=g.y, z=g.z)
682
+ for g in gcps
683
+ ]
684
+ out_w, out_h = c_hi - c_lo, r_hi - r_lo
603
685
  cal = _parse_vector_lut(
604
686
  zf.read(cal_member), ("calibrationVector",), (lut,), width
605
687
  )
@@ -609,7 +691,7 @@ class GRDExtractor:
609
691
 
610
692
  profile = {
611
693
  "driver": "GTiff", "dtype": "float32", "count": 1,
612
- "width": width, "height": height, "nodata": float("nan"),
694
+ "width": out_w, "height": out_h, "nodata": float("nan"),
613
695
  "tiled": True, "blockxsize": 512, "blockysize": 512,
614
696
  "compress": "deflate", "predictor": 3, "BIGTIFF": "IF_SAFER",
615
697
  }
@@ -622,16 +704,16 @@ class GRDExtractor:
622
704
  with rasterio.open(radar, "w", **profile) as dst:
623
705
  if gcps:
624
706
  dst.gcps = (gcps, gcp_crs)
625
- for r0 in range(0, height, block_rows):
626
- r1 = min(height, r0 + block_rows)
627
- win = Window(0, r0, width, r1 - r0)
707
+ for r0 in range(r_lo, r_hi, block_rows):
708
+ r1 = min(r_hi, r0 + block_rows)
709
+ win = Window(c_lo, r0, out_w, r1 - r0)
628
710
  dn = src.read(1, window=win).astype(np.float32)
629
711
 
630
712
  valid = dn > 0 # DN 0 = no data
631
713
  power = dn * dn
632
714
  if noise is not None:
633
- power -= noise.power(r0, r1, width)
634
- a = cal.rows(r0, r1)
715
+ power -= noise.power(r0, r1, width)[:, c_lo:c_hi]
716
+ a = cal.rows(r0, r1)[:, c_lo:c_hi]
635
717
  usable = valid & (a > 0)
636
718
  with np.errstate(divide="ignore", invalid="ignore"):
637
719
  value = power / (a * a)
@@ -647,7 +729,8 @@ class GRDExtractor:
647
729
  if out_db:
648
730
  with np.errstate(divide="ignore", invalid="ignore"):
649
731
  value = 10.0 * np.log10(value)
650
- dst.write(value.astype(np.float32), 1, window=win)
732
+ dst.write(value.astype(np.float32), 1,
733
+ window=Window(0, r0 - r_lo, out_w, r1 - r0))
651
734
 
652
735
  neg_frac = n_neg / n_valid if n_valid else 0.0
653
736
  logger.info(
@@ -663,6 +746,8 @@ class GRDExtractor:
663
746
  "NONPOSITIVE_POLICY": "NaN" if floor_db is None else f"floor {floor_db} dB",
664
747
  "TERRAIN_CORRECTED": "no (ellipsoid, GRD ground range)",
665
748
  }
749
+ if aoi_bbox is not None:
750
+ tags["AOI_BBOX_LONLAT"] = ",".join(f"{v:.5f}" for v in aoi_bbox)
666
751
  return tags, bool(gcps)
667
752
 
668
753
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygeofetch
3
- Version: 2.7.1.0
3
+ Version: 2.7.3
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
@@ -271,21 +271,21 @@ Results carry real footprint geometry and drop straight onto a map via `MapViewe
271
271
 
272
272
  Real orbit state vectors then pre-filter the candidate pair list against Sentinel-1's own mission thresholds, rejecting pairs for excess burst-sync error, temporal baseline, or spatial baseline before any interferogram is attempted.
273
273
 
274
- <p align="center"><img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/pre-filter-for-interferogram.png" width="85%" /></p>
274
+ <!-- <p align="center"><img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/pre-filter-for-interferogram.png" width="85%" /></p> -->
275
275
 
276
276
  **4. Interferogram formation.** Of 2,211 theoretically possible pairs across 67 downloaded scenes, real orbit-based coregistration, per-burst Enhanced Spectral Diversity, deburst, and flat-earth/topographic phase removal reduce that to 78 valid pairs — the dense urban fringe pattern below is raw wrapped phase, before any correction.
277
277
 
278
- <p align="center"><img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/wrapped_phase.png" width="85%" /></p>
278
+ <!-- <p align="center"><img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/wrapped_phase.png" width="85%" /></p> -->
279
279
 
280
280
  **5. Coherence.** Amplitude and coherence are estimated together for every pair; the urban core holds noticeably higher coherence (0.614) than the scene-wide average (0.508) — exactly the contrast expected between stable built structures and vegetated or agricultural surrounds.
281
281
 
282
- <p align="center"><img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/comparism.png" width="85%" /></p>
282
+ <!-- <p align="center"><img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/comparism.png" width="85%" /></p> -->
283
283
 
284
284
  **6. Phase unwrapping.** SNAPHU (Chen & Zebker, 2001) resolves each wrapped interferogram into continuous phase, both as a raw array and reprojected onto the real city footprint. Reliable coverage is intentionally sparse (~0.1–0.2%) — dense vegetation cover means most of the scene decorrelates between 18–24 day passes, so the pipeline marks those pixels NaN rather than interpolating across them.
285
285
 
286
286
  <p align="center">
287
287
  <img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/unwrapped_phase.png" width="48%" />
288
- <img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/unwrap.png" width="48%" />
288
+ <!-- <img src="https://raw.githubusercontent.com/EOCoreINT/mexico-subsidence-project/main/analysis/unwrap.png" width="48%" /> -->
289
289
  </p>
290
290
 
291
291
  **7. SBAS time-series inversion.** The full 58-date descending stack, once low-coherence and unreliable-reference-pixel pairs are excluded, fractures into 17 disconnected network "islands" — a genuine finding about this AOI's data quality, not a bug. The largest connected island (10 dates, 11 pairs) carries the final inversion, referenced near Cerro de la Estrella.
@@ -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.1.0.1},
374
+ version = {2.7.3.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=UvztDDKKSypto0b-WfphtFhqu1UZMvGieppOQQrZh6A,2107
2
- pygeofetch/meta.yaml,sha256=QFn2uzTQiZbeUBpjWtraMHmprRKqmGjl6Cw_SwLT59M,1284
1
+ pygeofetch/__init__.py,sha256=7_H-A3xAo1KYcqPDsSZ7xNJl4A1_YbMzz8RNMLU9N0A,2105
2
+ pygeofetch/meta.yaml,sha256=TspTTCAy3VmiwcmZ-cZnn8-RXtSanees28OyYqmZPyE,1282
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
@@ -143,7 +143,7 @@ pygeofetch/sar/__init__.py,sha256=AgvyED5Hvk-0zt1w2ucIcuepPoRRBME3liEav3ecYvw,16
143
143
  pygeofetch/sar/_native.py,sha256=6tVgoqJcE7QUSuqkxtVbhNUx9C6Ebzd60CBfpFcQKdU,1540
144
144
  pygeofetch/sar/_ost.py,sha256=7VnO39Ok6VNNw_aAbDcQreGdU9q-ILwyDyd_GeXDkTI,3737
145
145
  pygeofetch/sar/_sarxarray.py,sha256=x2O8EjxBmDj9qRvJE6MaoQK9oxrvGBVpczy9eTrDwHE,3076
146
- pygeofetch/sar/extraction.py,sha256=Jh6v8kStdEiXDifBq1wCa6Jlq8Ho_5o2M4KU_zJcMIE,30547
146
+ pygeofetch/sar/extraction.py,sha256=lOaM31RJ9Q19hv1JE7U0C3h2k0vL_kglhLZFxMZxEYA,34797
147
147
  pygeofetch/sar/math.py,sha256=--dMPlqDbUTxgzyOxGFzTmyubgpUI7Gd8mDGZpysmuQ,4070
148
148
  pygeofetch/sar/pipelines.py,sha256=NKsP2Nh8JD8Z6HSJe_xCxajfemSO2P00aRHzj4wGQkI,21091
149
149
  pygeofetch/sar/processor.py,sha256=BA72j4nlqYGPYAxCd5Le6xIJLTMu2IT43ws9-VDM2ak,16625
@@ -170,9 +170,9 @@ 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.1.0.dist-info/licenses/LICENSE,sha256=zavMyhODD6NvZTmmKFEtATrngwY4CU_NEtY7lhjxGnI,1075
174
- pygeofetch-2.7.1.0.dist-info/METADATA,sha256=y_IG7WcLR7xAQJ2ficz_Nya1hCIucZcvSwfRB_PAQNw,25014
175
- pygeofetch-2.7.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
176
- pygeofetch-2.7.1.0.dist-info/entry_points.txt,sha256=dHiUXLF5xNJ8vgtXZoUQNleEMQUeDPZiKQOE1tW8SDY,55
177
- pygeofetch-2.7.1.0.dist-info/top_level.txt,sha256=rOmnZargIfNk99fwVOqt6OJyJvpSTBBAYO5HU37yhHk,11
178
- pygeofetch-2.7.1.0.dist-info/RECORD,,
173
+ pygeofetch-2.7.3.dist-info/licenses/LICENSE,sha256=zavMyhODD6NvZTmmKFEtATrngwY4CU_NEtY7lhjxGnI,1075
174
+ pygeofetch-2.7.3.dist-info/METADATA,sha256=DborNqgn-ILFfHI31UPWsFcIrt6aL3hf3Jof9aOGdsk,25046
175
+ pygeofetch-2.7.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
176
+ pygeofetch-2.7.3.dist-info/entry_points.txt,sha256=dHiUXLF5xNJ8vgtXZoUQNleEMQUeDPZiKQOE1tW8SDY,55
177
+ pygeofetch-2.7.3.dist-info/top_level.txt,sha256=rOmnZargIfNk99fwVOqt6OJyJvpSTBBAYO5HU37yhHk,11
178
+ pygeofetch-2.7.3.dist-info/RECORD,,