← all branches

feat/atlas-scan

needs attentionviewing older commit
4aa3c02 · incrementalpre-PRreviewed 2026-08-12 02:35 UTC2H · 3M · 3L
The branch
Purpose
Build a distribution-grid atlas by scraping CFE's WFS (SIGDIS) for circuit topology, hosting capacity, and transformer georeferencing
Goal
Enrich circuit records with exact transformer-derived centroids and kVA load capacity, enabling cross with Power Finder
Sub-goals
  • SG-1: Enumerate circuits via propertyName filter (circuit IDs only, no geometry — avoids HTTP 500 on large tiles)
  • SG-2: Fetch exact centroids from banco_trans_dis transformers per circuit
  • SG-3: New dist_trafos.py script — downloads and georeferences all transformers, fills circuit centroids
The changes (whole branch)
What
dist_enumerate.py refactored to use propertyName filter + separate transformer centroid pass; dist_trafos.py added as dedicated transformer downloader; dist_common.py schema gets n_trafos + kva_total columns
Why
Segment-geometry-based centroid was wrong (approximate mean of polyline endpoints); transformer layer gives exact point locations and kVA data needed for Power Finder cross
Areas
scripts/atlas/distribucion/dist_enumerate.py+6736scripts/atlas/distribucion/dist_trafos.py+1020scripts/atlas/distribucion/dist_common.py+20
Blast
3 files, +153/-36 in scripts/atlas/distribucion — scraper-only, no production code touched
geom-field-name-bug centroid-ownership-conflict
CI· no CI for scraper scriptsCodeRabbit· no .coderabbit.yaml

Findings · 8

correctness4

high

Wrong geometry field 'geom' (should be 'coordenada') silently returns 0 centroids

scripts/atlas/distribucion/dist_enumerate.py:102

property_name='circuito,zona,cap_total,geom' — the WFS layer uses 'coordenada'. Silent except swallows the error; all circuits exit with lat=NULL.

medium

Division filter removed — cross-division circuits get wrong division_code

scripts/atlas/distribucion/dist_enumerate.py:86

Old code filtered p.get('division') != div. New code only checks if not cc. Border tiles include foreign segments; upsert stamps them with the current div.

medium

n_trafos and kva_total count different feature sets (geometry-filtered vs all)

scripts/atlas/distribucion/dist_enumerate.py:105

pts filters by geometry presence; kva sums cap_total from all features. n_trafos and kva are inconsistent.

low

zona regression: no longer populated from segment data when transformer data absent

scripts/atlas/distribucion/dist_enumerate.py:89

Old code got zona from segment properties. New property_name='circuito' only — zona only set if transformer WFS returns it.

security2

medium

CQL filter string-interpolated from API-returned circuit IDs

scripts/atlas/distribucion/dist_trafos.py:57

cql=f"circuito='{cc}'" where cc comes from WFS response. Single quotes in circuit IDs produce malformed filters. Fix: cc.replace("'", "''")

low

Non-Point geometry unpack without type guard

scripts/atlas/distribucion/dist_trafos.py:72

lng, lat = f['geometry']['coordinates'] crashes silently on non-Point geometry.

conventions1

low

Bare except in centroid loop provides no diagnostics

scripts/atlas/distribucion/dist_enumerate.py:103

Tile loop prints SALTADO on errors; centroid loop uses silent except Exception: continue.

improvement1

high

Enumerate centroid pass duplicates dist_trafos and blocks it (WHERE lat IS NULL finds nothing)

scripts/atlas/distribucion/dist_enumerate.py:95

Both scripts update circuit.lat/lng/n_trafos/kva_total. Enumerate running first means dist_trafos.py's WHERE lat IS NULL query finds zero rows, skipping transformer table writes.

History · 16 commits

  1. 91aaedfsafeincremental0H · 1M · 1L2026-08-12 17:35
  2. cb8d915needs attentionincremental2H · 5M · 3L2026-08-12 17:29
  3. 4cbbe8aneeds attentionincremental0H · 3M · 8L2026-08-12 14:01
  4. 4aa3c02needs attentionincremental2H · 3M · 3L2026-08-12 02:35current
  5. f5630b2needs attentionincremental0H · 4M · 5L2026-08-12 02:17
  6. 28fde5bneeds attentionincremental1H · 2M · 2L2026-08-12 01:53
  7. 0babe51needs attentionincremental1H · 2M · 5L2026-08-12 01:23
  8. 50e8a8cneeds attentionincremental3H · 5M · 7L2026-08-11 23:58
  9. 3af4686needs attentionincremental3H · 5M · 5L2026-08-03 20:07
  10. f5d3266needs attentionincremental0H · 3M · 8L2026-08-03 19:40
  11. 9f8b61aneeds attentionincremental0H · 2M · 3L2026-08-03 19:15
  12. ea51fa0needs attentionincremental1H · 4M · 4L2026-08-03 19:02
  13. 2b33f2fneeds attentionincremental0H · 1M · 1L2026-07-18 05:09
  14. 2f8cf79needs attentionincremental1H · 3M · 4L2026-07-18 00:59
  15. 1616332safeincremental0H · 0M · 1L2026-07-18 00:22
  16. e997fd8needs attentionfull1H · 4M · 6L2026-07-17 23:53