feat/atlas-scan
needs attentionviewing older commit4aa3c02 · incrementalpre-PRreviewed 2026-08-12 02:35 UTC2H · 3M · 3L- 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
- 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+67−36scripts/atlas/distribucion/dist_trafos.py+102−0scripts/atlas/distribucion/dist_common.py+2−0
- Blast
- 3 files, +153/-36 in scripts/atlas/distribucion — scraper-only, no production code touched
Findings · 8
correctness4
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.
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.
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.
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
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("'", "''")
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
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
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
- 91aaedfsafeincremental0H · 1M · 1L2026-08-12 17:35
- cb8d915needs attentionincremental2H · 5M · 3L2026-08-12 17:29
- 4cbbe8aneeds attentionincremental0H · 3M · 8L2026-08-12 14:01
- 4aa3c02needs attentionincremental2H · 3M · 3L2026-08-12 02:35current
- f5630b2needs attentionincremental0H · 4M · 5L2026-08-12 02:17
- 28fde5bneeds attentionincremental1H · 2M · 2L2026-08-12 01:53
- 0babe51needs attentionincremental1H · 2M · 5L2026-08-12 01:23
- 50e8a8cneeds attentionincremental3H · 5M · 7L2026-08-11 23:58
- 3af4686needs attentionincremental3H · 5M · 5L2026-08-03 20:07
- f5d3266needs attentionincremental0H · 3M · 8L2026-08-03 19:40
- 9f8b61aneeds attentionincremental0H · 2M · 3L2026-08-03 19:15
- ea51fa0needs attentionincremental1H · 4M · 4L2026-08-03 19:02
- 2b33f2fneeds attentionincremental0H · 1M · 1L2026-07-18 05:09
- 2f8cf79needs attentionincremental1H · 3M · 4L2026-07-18 00:59
- 1616332safeincremental0H · 0M · 1L2026-07-18 00:22
- e997fd8needs attentionfull1H · 4M · 6L2026-07-17 23:53