GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Maps, GIS and field navigation / gridatlas / atlas/labs/lightning-grid

Labs — Lightning Grid and 2 more files

A JavaScript module in the atlas folder of GridAtlas that draws UK lightning and uses data from the lightning and PipelineNews repositories. Served with the page at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.

494 lines of JavaScript and HTML from gridatlas, in 3 files. Topic: Maps, GIS and field navigation. Section 520 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Labs — Lightning Grid interaction · gridatlas / atlas/labs/lightning-grid/app.mjs lines 1–277
  2. Feed Contract ingest · gridatlas / atlas/labs/lightning-grid/feed-contract.mjs lines 1–101
  3. Labs — Lightning Grid Page render · gridatlas / atlas/labs/lightning-grid/index.html lines 1–116

Labs — Lightning Grid

A JavaScript module in the atlas folder of GridAtlas that draws UK lightning and uses data from the lightning and PipelineNews repositories. Served with the page at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.

interactiongridatlas / atlas/labs/lightning-grid/app.mjs · lines 1–277 of 277 · Entry point · pattern display (shared by 4 files)

What it does
It draws UK lightning, grid substations and solar. Defines 18 functions or classes, including el, pretty, date, mapStatus, node. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'atlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: solar.
Inputs & outputs
In: data source: lightning data; data source: pipelinenews data; GeoJSON file uk_lightning.geojson; GeoJSON file grid_substations.geojson.
Downstream impact
Used directly by 1 file: Labs — Lightning Grid Page (gridatlas, https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/). It is itself an entry point, published at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.
What it achieves
It maps status (`mapStatus`), downloads JSON (`downloadJSON`) and gets assets (`getAssets`). Standalone Lightning → existing MAP/nearest Grid Engine integration LAB. It responds to change and click events.
Why it matters
Loaded by the page of the same name at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.
Application
gridatlas · atlas/labs/lightning-grid · JavaScript module
Uses
Feed Contract (import), Map View (import), https://cdn.jsdelivr.net/gh/Ventusltd/ventus-grid-engine@69b4e88c8464f0310bd67e47ec83ee8afa9e1921/engine/lightning-click-context.js
Used by
loaded by Labs — Lightning Grid Page (script src)
Produces
el, pretty, date, mapStatus, node, clear, line, status, fail, downloadJSON, features, getAssets
Defines here
el, pretty, date, mapStatus, node, clear, line, status, fail, downloadJSON, features, getAssets, currentFlash, setObservation, display, scenario, inspect, start
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/labs/lightning-grid/app.mjs:1-277 · blob aab11659bdf4f8288e533c31762765c14b919f0b · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
/**
 * Standalone Lightning → existing MAP/nearest Grid Engine integration LAB.
 * Read-only browser sidecar; no mutation of Atlas, archive, original controls.
 *
 * The dependency is pinned to a REVIEWED draft Grid Engine source SHA.
 * This is experimental: verify actual CDN import/CORS in browser before
 * publication. NOT a confirmed ground strike or electrical fault prediction.
 */
import {
  createLightningContextEngine,
  lightningElectricalScenario,
  postEventDiligence,
  caveat
} from 'https://cdn.jsdelivr.net/gh/Ventusltd/ventus-grid-engine@69b4e88c8464f0310bd67e47ec83ee8afa9e1921/engine/lightning-click-context.js';
import {parseOpticalFeed,describeOpticalFeedEvidence} from './feed-contract.mjs';
import {initLightningMap} from './map-view.mjs';

const FEED='https://raw.githubusercontent.com/Ventusltd/lightning/main/data/uk_lightning.geojson';
const SUBSTATIONS='https://raw.githubusercontent.com/Ventusltd/gridatlas/main/atlas/releases/202608300453-atlas-v9/data/grid_substations.geojson';
const SOLAR_PREFIX='https://raw.githubusercontent.com/Ventusltd/pipelinenews/main/data/atlas/202608261927-atlas-solar-partition-v9-1-';
const solarURLs=Array.from({length:8},(_,i)=>SOLAR_PREFIX+String(i+1).padStart(3,'0')+'.geojson');

const el=id=>document.getElementById(id);
const pretty=n=>Number(n).toLocaleString('en-GB',{maximumFractionDigits:2});
const date=t=>new Date(t).toISOString().replace('T',' ').replace('Z',' UTC');
const state={observations:[],files:null,engine:null,ctx:null,serial:0,loadingAssets:null};
let mapView=null;
function mapStatus(msg){el('map-status').textContent=msg}
function node(tag,value,cls=''){
  const e=document.createElement(tag);
  if(value!=null)e.textContent=String(value);
  if(cls)e.className=cls;
  return e;
}
function clear(id){const e=el(id);e.replaceChildren();return e}
function line(target,what){target.appendChild(node('p',what,'small'))}
function status(msg){el('status').textContent=msg}
function fail(message){
  const e=document.createElement('span');
  e.className='strong';e.textContent=message;
  el('status').replaceChildren(e);
}
async function downloadJSON(url){
  const c=new AbortController(),timeout=setTimeout(()=>c.abort(),20000);
  try {
    const r=await fetch(url,{cache:'no-store',signal:c.signal});
    if(!r.ok)throw Error('HTTP '+r.status);
    return await r.json();
  }finally{clearTimeout(timeout)}
}
function features(data){
  if(data?.type==='FeatureCollection' && Array.isArray(data.features))return data.features;
  if(Array.isArray(data?.features))return data.features;
  throw Error('Not a GeoJSON feature collection');
}
async function getAssets(){
  if(state.loadingAssets)return state.loadingAssets;
  state.loadingAssets=(async()=>{
    // No 35.7 MB register download; reuse eight established, bounded,
    // genuine Pipeline News solar partitions and original Atlas substations.
    const settled=await Promise.allSettled([downloadJSON(SUBSTATIONS),...solarURLs.map(downloadJSON)]);
    let subs=[],solar=[],issues=[];
    if(settled[0].status==='fulfilled'){
      try{subs=features(settled[0].value)}catch(e){issues.push('Substation source shape: '+e.message)}
    } else issues.push('Substation source unavailable: '+settled[0].reason.message);
    for(let i=1;i<settled.length;i++){
      const x=settled[i];
      if(x.status==='fulfilled'){try{solar.push(...features(x.value))}catch(e){issues.push('Solar partition '+i+': '+e.message)}}
      else issues.push('Solar partition '+i+' unavailable: '+x.reason.message);
    }
    state.files={substations:subs,solar,issues};
    state.engine=createLightningContextEngine({substations:subs,solarProjects:solar});
    return state.files;
  })();
  try{
    const result=await state.loadingAssets;
    // A partial source load is not a permanently cached zero. Let the
    // next explicit Inspect attempt retry unavailable source partitions.
    if(result.issues.length)state.loadingAssets=null;
    return result;
  }catch(e){state.loadingAssets=null;throw e}
}
function currentFlash(){
  const id=el('flash').value;
  return state.observations.find(f=>String(f.id)===id)||null;
}
function setObservation(f){
  state.ctx=null;
  mapView?.selectFlash(f);
  el('fit-selection').disabled=!f||!mapView;
  el('scenario').disabled=true;
  el('project').replaceChildren(node('option','No project selected'));
  el('scenario-output').textContent='Select a genuine optical observation and run the proximity search first.';
  const t=clear('observation');
  if(!f){line(t,'No observation selected.');return}
  const p=node('div',null,'record');
  line(p,'Optical detection · '+date(f.properties.time_utc));
  line(p,'Latitude '+f.geometry.coordinates[1]+', longitude '+f.geometry.coordinates[0]+' (source coordinate; not a ground-strike fix)');
  line(p,'Source ID: '+String(f.id));
  t.appendChild(p);
  const u=new URL(location.href);
  u.searchParams.set('flash_id',String(f.id));
  const a=node('a','Link to this optical observation');
  a.href=u.href;a.rel='noopener';t.appendChild(a);
}
function display(ctx,assets){
  const summary=el('provenance');
  const d=ctx.search,n=state.engine.dataset_summary;
  summary.textContent=
    'Scanned '+pretty(d.scanned_geolocated_substations)+' located substation records of '+pretty(n.total_substations)+
    '; '+pretty(d.scanned_repd_solar_projects)+' located, identified solar projects of '+pretty(n.total_solar_records)+
    ' source rows. Distances are straight-line, not electrical paths.'+
    (assets.issues.length?' PARTIAL SOURCE FAILURE: '+assets.issues.join('; '):'');
  mapView?.setContext(ctx);
  const subs=clear('substations');
  if(!ctx.substations.length)line(subs,'No eligible located substation found in the loaded records. Not evidence that none exists.');
  for(const p of ctx.substations){
    const card=node('div',null,'record');
    card.appendChild(node('strong',p.name||'Unnamed substation'));
    line(card,pretty(p.km)+' km · declared '+p.voltages_kv.map(x=>x+' kV').join(', '));
    if(p.source_site_id)line(card,'Source identifier: '+p.source_site_id);
    subs.appendChild(card);
  }
  const solar=clear('solar'),chooser=el('project');
  chooser.replaceChildren(node('option','No project selected'));
  chooser.firstChild.value='';
  if(!ctx.nearby_solar.length)line(solar,'No eligible identified REPD solar project in this radius among the loaded records. This is not a site exposure assessment.');
  for(const p of ctx.nearby_solar){
    const card=node('div',null,'record');
    card.appendChild(node('strong',p.name));
    line(card,pretty(p.km)+' km · '+(p.capacity_mw===null?'MW capacity not declared':pretty(p.capacity_mw)+' MW as recorded')+
      ' · symbol radius '+pretty(p.marker_radius_px)+' px (display only; not land area)');
    line(card,'Observed optical lightning activity '+pretty(p.km)+' km from this mapped project. Consider post-event inspection as diligence, NOT as evidence of a strike, fault or damage.');
    const a=node('a','Open project in existing GridAtlas MAP');
    a.href=p.gridatlas_project_url;a.target='_blank';a.rel='noopener noreferrer';
    card.appendChild(a);solar.appendChild(card);
    const option=node('option',p.name+' · '+pretty(p.km)+' km');option.value=p.repd_ref;
    chooser.appendChild(option);
  }
}
function scenario(){
  const t=clear('scenario-output');
  if(!state.ctx){line(t,'No selected context.');return}
  try{
    const result=lightningElectricalScenario(state.ctx,{
      acEarthing:el('ac').value,dcReference:el('dc').value,
      inverterIsolation:el('inverter').value,
      selectedRepdRef:el('project').value||null
    });
    const diligence=postEventDiligence(state.ctx,{
      selectedRepdRef:el('project').value||null,
      overheadLineProximity:el('overhead').value,
      wetWeather:el('weather').value
    });
    const title=node('p','NOT RUN — no current, voltage, probability or event causality calculated','strong');
    t.appendChild(title);
    line(t,'Selected site: '+(result.site?.name||'None; generic hypothetical study inputs only'));
    line(t,result.disclaimer);
    result.candidate_scenarios.forEach(s=>{
      const detail=node('details');
      const summary=node('summary',s.label+' · '+(s.applicable===false?'not confirmed applicable':'scenario inputs'));
      detail.appendChild(summary);
      const list=node('ul');
      s.needs.forEach(need=>list.appendChild(node('li',need)));
      detail.appendChild(list);t.appendChild(detail);
    });
    t.appendChild(node('h3','Post-event inspection: engineering diligence, not diagnosis'));
    line(t,diligence.disclaimer);
    line(t,diligence.overhead_note);
    line(t,diligence.weather_note);
    const inspection=node('ul');
    diligence.actions.forEach(a=>inspection.appendChild(node('li',a)));
    t.appendChild(inspection);
    line(t,'Other possible causes: '+diligence.other_possible_causes.join('; ')+'.');
    line(t,'Technical background: DEHN WPX051 / EN / 0422 on string-inverter AC-side surge paths; consult manufacturer instructions and applicable standards.');
  }catch(e){line(t,'Scenario setup refused: '+e.message)}
}
async function inspect(){
  const f=currentFlash();if(!f)return;
  const serial=++state.serial;
  // Explicit refresh cannot leave a previous result looking like the current
  // answer while the genuine source is still being fetched or has failed.
  state.ctx=null;
  mapView?.clearContext();
  el('scenario').disabled=true;
  clear('substations').textContent='Refreshing genuine source records; previous results cleared.';
  clear('solar').textContent='Refreshing genuine source records; previous results cleared.';
  el('provenance').textContent='Loading source provenance; no current proximity result.';
  el('project').replaceChildren(node('option','No project selected'));
  el('scenario-output').textContent='Source refresh in progress. No electrical solver has run.';
  el('inspect').disabled=true;
  status('Loading genuine substation and solar source records. No changes to the original Atlas…');
  try{
    const assets=await getAssets();
    if(serial!==state.serial)return;
    const ctx=state.engine.selectFlash(f,{
      radiusKm:Number(el('radius').value),minimumKv:Number(el('kv').value),
      solarLimit:30,substationLimit:6
    });
    state.ctx=ctx;
    display(ctx,assets);
    el('scenario').disabled=false;
    status('Ready · '+pretty(ctx.nearby_solar.length)+' located solar projects and '+pretty(ctx.substations.length)+
      ' nearest substations returned from LOADED datasets. '+caveat+
      (assets.issues.length?' Partial data: see source failures.':'')+
      ' Earlier than the seven-day feed remains UNKNOWN.');
  }catch(e){
    if(serial===state.serial)fail('Unable to compute or load context: '+e.message+'. No results have been inferred.');
  }finally{
    // Changing flash or filters while a request is in flight invalidates
    // that request, but must NEVER strand the Inspect button disabled.
    el('inspect').disabled=false;
  }
}
el('flash').addEventListener('change',()=>{
  state.serial++;setObservation(currentFlash());el('scenario').disabled=true;
  clear('substations').textContent='Awaiting proximity search.';
  clear('solar').textContent='Awaiting proximity search.';
  el('provenance').textContent='New observation selected; previous results cleared.';
  status('Observation changed. Run a new proximity search; earlier results are not retained.');
});
el('inspect').addEventListener('click',inspect);
el('scenario').addEventListener('click',scenario);
for(const k of ['ac','dc','inverter','project','overhead','weather']){
  el(k).addEventListener('change',()=>{
    el('scenario-output').textContent='Assumptions changed; prepare the scenario again. No electrical solver has run.';
  });
}
for(const k of ['radius','kv'])el(k).addEventListener('change',()=>{
  state.serial++;state.ctx=null;mapView?.clearContext();el('scenario').disabled=true;
  clear('substations').textContent='Parameters changed. Run proximity search again.';
  clear('solar').textContent='Parameters changed. Run proximity search again.';
  el('provenance').textContent='Prior proximity results cleared; no new search yet.';
  el('project').replaceChildren(node('option','No project selected'));
  el('scenario-output').textContent='Parameters changed. Run proximity search again.';
  status('Search parameters changed. Earlier results cleared; select Find nearest mapped infrastructure to recalculate.');
});
async function start(){
  try{
    const source=await downloadJSON(FEED);
    const parsed=parseOpticalFeed(source);
    state.observations=parsed.observations;
    const mapped=mapView?.setObservations(state.observations);
    el('fit-flashes').disabled=!mapView||!mapped;
    if(!state.observations.length)
      throw Error('No valid optical observations in available source; coverage UNKNOWN');
    const selector=el('flash');
    selector.replaceChildren();
    state.observations.forEach((f,i)=>{
      const name=date(f.properties.time_utc)+' · '+f.geometry.coordinates.map(x=>Number(x).toFixed(3)).join(', ')+' · #'+(i+1);
      const item=node('option',name);item.value=String(f.id);selector.appendChild(item);
    });
    const requested=new URL(location.href).searchParams.get('flash_id');
    if(requested && state.observations.some(f=>String(f.id)===requested))selector.value=requested;
    selector.disabled=el('inspect').disabled=false;
    setObservation(currentFlash());
    status(describeOpticalFeedEvidence(parsed.evidence)+' '+caveat+
      ' Select an observation, then run the genuine nearest search.');
  }catch(e){fail('Feed unavailable: '+e.message+'. No flash or infrastructure result is inferred.')}
}
try{
  mapView=initLightningMap({
    onPick:id=>{
      const actual=state.observations.find(f=>String(f.id)===String(id));
      if(!actual)return;
      el('flash').value=String(actual.id);
      state.serial++;
      setObservation(actual);
      void inspect(); // actual optical marker selection immediately opens grid context
    },
    onStatus:mapStatus,
    onError:message=>mapStatus('Map rendering warning: '+message+'; the UTC dropdown remains available.')
  });
}catch(e){mapStatus('Map could not start: '+e.message+'. UTC dropdown selection remains available.')}
el('fit-flashes').addEventListener('click',()=>mapView?.fitFlashes());
el('fit-selection').addEventListener('click',()=>mapView?.fitSelection());
start();

Feed Contract

A JavaScript module in the lightning grid folder of GridAtlas that parses optical feed (`parseOpticalFeed`) and describes optical feed evidence (`describeOpticalFeedEvidence`). Served with the page at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.

ingestgridatlas / atlas/labs/lightning-grid/feed-contract.mjs · lines 1–101 of 101 · pattern describeOpticalFeedEvidence (shared by 2 files)

What it does
Defines utc, finite, validCoordinates, parseOpticalFeed, describeOpticalFeedEvidence.
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'atlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
Downstream impact
Used directly by 1 file: Labs — Lightning Grid (gridatlas, https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/). Reached from 1 other entry point, including Labs — Lightning Grid Page (gridatlas, https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/).
What it achieves
It parses optical feed (`parseOpticalFeed`) and describes optical feed evidence (`describeOpticalFeedEvidence`). Read-only source-evidence contract for the standalone Lightning → Grid Lab.
Why it matters
Imported by Labs — Lightning Grid.
Application
gridatlas · atlas/labs/lightning-grid · JavaScript module
Uses
none found
Used by
imported by Labs — Lightning Grid (import), mentioned in Standalone (comment link)
Produces
parseOpticalFeed, describeOpticalFeedEvidence
Defines here
utc, finite, validCoordinates, parseOpticalFeed, describeOpticalFeedEvidence
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/labs/lightning-grid/feed-contract.mjs:1-101 · blob 472ebca61e9b8cd75a4c97cf2f6e793572d2b2c5 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
/**
 * Read-only source-evidence contract for the standalone Lightning → Grid Lab.
 * A recent collector query is NOT proof that seven days were exhaustively
 * searched. A quiet interval is UNKNOWN unless durable coverage says otherwise.
 * No optical event is a verified ground strike or diagnosed site incident.
 */
const hour=3600000;
const utc=t=>typeof t==='string' && /(?:Z|\+00:00)$/i.test(t) && Number.isFinite(Date.parse(t))
  ? Date.parse(t) : NaN;
const finite=n=>typeof n==='number' && Number.isFinite(n);
const validCoordinates=p=>Array.isArray(p) && p.length>=2
  && finite(p[0]) && finite(p[1])
  && p[0]>=-180 && p[0]<=180 && p[1]>=-90 && p[1]<=90;

export function parseOpticalFeed(data,{nowMs=Date.now(),staleAfterHours=6}={}){
  if(!finite(nowMs)||!finite(staleAfterHours)||staleAfterHours<=0)
    throw new TypeError('Invalid clock or freshness threshold');
  if(data?.type!=='FeatureCollection'||!Array.isArray(data.features))
    throw new Error('Source is not a GeoJSON FeatureCollection');
  const meta=data.metadata||{};
  const queryStartMs=utc(meta.query_start_utc);
  const queryEndMs=utc(meta.query_end_utc);
  if(Number.isFinite(queryEndMs)&&queryEndMs>nowMs+5*60000)
    throw new Error('Feed query end is in the future; coverage UNKNOWN');
  if(Number.isFinite(queryStartMs)&&Number.isFinite(queryEndMs)&&queryStartMs>queryEndMs)
    throw new Error('Feed query window is inverted; coverage UNKNOWN');
  const selected=new Map(),conflicting=new Set();
  let rejected=0,duplicate=0;
  for(const f of data.features){
    const id=f?.id==null?'':String(f.id).trim();
    const time=utc(f?.properties?.time_utc);
    const coordinates=f?.geometry?.coordinates;
    if(!id || f?.type!=='Feature' || f?.geometry?.type!=='Point'
      || !validCoordinates(coordinates)
      || f?.properties?.observation_kind!=='optical_lightning_flash'
      || !Number.isFinite(time)||time>nowMs+5*60000
      || (Number.isFinite(queryEndMs)&&time>queryEndMs+5*60000)){
      rejected++;continue;
    }
    if(selected.has(id)){
      duplicate++;
      const old=selected.get(id);
      if(old.properties.time_utc!==f.properties.time_utc
        || old.geometry.coordinates[0]!==coordinates[0]
        || old.geometry.coordinates[1]!==coordinates[1])conflicting.add(id);
      continue;
    }
    selected.set(id,f);
  }
  for(const id of conflicting){selected.delete(id);rejected++}
  const observations=[...selected.values()].sort((a,b)=>
    Date.parse(b.properties.time_utc)-Date.parse(a.properties.time_utc));
  const freshness=Number.isFinite(queryEndMs)
    ?(nowMs-queryEndMs>staleAfterHours*hour?'STALE_QUERY':'RECENT_QUERY')
    :'QUERY_TIME_UNKNOWN';
  const latestMs=observations.length?Date.parse(observations[0].properties.time_utc):NaN;
  const latestDeclaredMs=utc(meta.latest_detection_utc);
  const warnings=[];
  if(rejected||duplicate)warnings.push(rejected+' rejected/ambiguous, '+duplicate+' duplicate source records');
  if(freshness==='STALE_QUERY')warnings.push('Collector query is stale; later optical observations UNKNOWN');
  if(freshness==='QUERY_TIME_UNKNOWN')warnings.push('Last successful query time UNKNOWN');
  if(Number.isFinite(latestDeclaredMs) && Number.isFinite(latestMs)
    && Math.abs(latestMs-latestDeclaredMs)>60000)
    warnings.push('Latest detected timestamp differs from feed metadata');
  if(Number.isFinite(meta.total_before_display_cap)
    && meta.total_before_display_cap<data.features.length)
    warnings.push('Feed source total is inconsistent with displayed rows');
  if(data.features.length && !observations.length)
    throw new Error('All source records invalid or ambiguous; observations UNKNOWN, not zero');
  return Object.freeze({
    observations,
    evidence:Object.freeze({
      raw_records:data.features.length,accepted:observations.length,
      rejected,duplicates:duplicate,conflicting_ids:conflicting.size,
      latest_detection_utc:Number.isFinite(latestMs)?new Date(latestMs).toISOString():null,
      query_start_utc:Number.isFinite(queryStartMs)?new Date(queryStartMs).toISOString():null,
      query_end_utc:Number.isFinite(queryEndMs)?new Date(queryEndMs).toISOString():null,
      query_freshness:freshness,
      query_age_hours:Number.isFinite(queryEndMs)?Math.max(0,(nowMs-queryEndMs)/hour):null,
      retention_days:Number.isFinite(meta.retention_days)?meta.retention_days:null,
      cumulative_coverage:'UNKNOWN',
      unobserved_interval:'UNKNOWN',
      warnings
    })
  });
}

export function describeOpticalFeedEvidence(e){
  const last=e.latest_detection_utc?e.latest_detection_utc.replace('T',' ').replace('Z',' UTC')
    :'not recorded';
  const query=e.query_end_utc?e.query_end_utc.replace('T',' ').replace('Z',' UTC')
    :'UNKNOWN';
  const freshness=e.query_freshness==='STALE_QUERY'?'STALE COLLECTOR QUERY'
    :e.query_freshness==='QUERY_TIME_UNKNOWN'?'QUERY FRESHNESS UNKNOWN'
    :'recent collector query (not complete coverage)';
  return 'Authentic optical observations: '+e.accepted+' accepted of '+e.raw_records+
    ' source records. Latest optical detection: '+last+'. Latest collector query ended: '+
    query+' ('+freshness+'). Seven-day retention is not a verified seven-day search: '+
    'unsearched hours and older history UNKNOWN, not zero.'+
    (e.warnings.length?' SOURCE WARNINGS: '+e.warnings.join('; ')+'.':'');
}

Labs — Lightning Grid Page

A web page in the atlas folder of GridAtlas that reads inputs for flash, radius and kV, covering solar and substations. Published at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.

rendergridatlas / atlas/labs/lightning-grid/index.html · lines 1–116 of 116 · Entry point

What it does
It draws solar, substations and the REPD register. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'atlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: solar, substations, the REPD register, 400kV, 275kV, 132kV. README: "`atlas/index.html` is the stable composer."
Inputs & outputs
In: form fields (user input). Out: web page. Voltage levels named: 400kV, 275kV, 132kV.
Downstream impact
It is itself an entry point, published at https://gridatlas.globalgrid2050.com/atlas/labs/lightning-grid/.
What it achieves
Lightning → Grid Scenario Lab. Its code works with 132 kV, 275 kV and 400 kV.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
gridatlas · atlas/labs/lightning-grid · page
Uses
GridAtlas — Atlas Page (link), Labs — Lightning Grid (script src), https://cdn.jsdelivr.net/npm/maplibre-gl@3.6.2/dist/maplibre-gl.css, https://cdn.jsdelivr.net/npm/maplibre-gl@3.6.2/dist/maplibre-gl.js
Used by
none found
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/labs/lightning-grid/index.html:1-116 · blob c09365a18f0cbe834d25a058eebd1d7112498e64 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
<!doctype html>
<html lang="en-GB">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="theme-color" content="#10151c">
  <title>Lightning → Grid Scenario Lab · GlobalGrid2050</title>
  <style>
    :root{color-scheme:dark;font-family:system-ui,-apple-system,Segoe UI,Arial,sans-serif;background:#10151c;color:#e6edf4}
    *{box-sizing:border-box}
    body{margin:0;line-height:1.55}
    header{background:#141f2a;border-bottom:1px solid #45566a;padding:14px max(16px,4vw)}
    header h1{margin:0;font-size:clamp(1.3rem,4vw,2rem);letter-spacing:-.03em}
    a{color:#83d9ff}
    main{max-width:1150px;margin:auto;padding:18px}
    .intro{max-width:900px;color:#c5d5e1}
    .status{border-left:4px solid #f7c66d;background:#192534;padding:12px 14px;white-space:pre-wrap;margin:12px 0}
    .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,335px),1fr));gap:14px}
    #flash-map{height:min(58vh,560px);min-height:335px;width:100%;border-radius:8px;overflow:hidden;border:1px solid #4e697f}
    .map-tools{display:flex;gap:9px;flex-wrap:wrap;margin:10px 0}
    .map-tools button{width:auto;min-width:156px;flex:1}
    .map-legend{display:flex;gap:15px;flex-wrap:wrap;margin-top:6px;color:#d9e5f1;font-size:.9rem}
    .map-legend span{display:inline-flex;align-items:center;gap:7px}
    .map-dot{display:inline-block;border-radius:50%;width:13px;height:13px;border:1px solid #202c38;background:#ffe890}
    .map-dot.solar{background:#43e3ab}
    .map-dot.sub{background:#81a6ff}
    .maplibregl-popup-content{background:#152735;color:#ecf6ff;border-radius:7px;max-width:290px}
    .maplibregl-popup-content a{color:#83d9ff}
    .maplibregl-popup-close-button{color:white;font-size:20px}
    @media(max-width:520px){#flash-map{height:43vh;min-height:300px}.maplibregl-ctrl-top-right{top:2px}}
    section{min-width:0;background:#16212b;border:1px solid #3b5065;border-radius:10px;padding:16px}
    section h2{font-size:1.06rem;margin:0 0 12px}
    label{display:block;font-weight:600;margin:10px 0 4px}
    select,button,input{font:inherit;color:#f5f7f8;min-height:44px;border:1px solid #648199;border-radius:6px;background:#182b38;padding:8px;width:100%}
    button{background:#115d7a;border-color:#8dd5ef;cursor:pointer;font-weight:700}
    button:hover,button:focus-visible,a:focus-visible{outline:2px solid #f7c66d;outline-offset:2px}
    button:disabled{cursor:not-allowed;opacity:.5}
    .small{font-size:.86rem;color:#b9c7d4}
    .muted{color:#b9c7d4}
    .strong{color:#ffe3a1;font-weight:700}
    ul{padding-left:22px}
    li{margin:9px 0}
    .record{padding:12px 0;border-bottom:1px solid #35495d;overflow-wrap:anywhere}
    .record:last-child{border:0}
    .tag{display:inline-block;background:#243849;border-radius:4px;padding:2px 6px;margin-right:5px;color:#c8edf9}
    .scenario{max-width:100%;white-space:pre-wrap;overflow-wrap:anywhere;font-size:.9rem}
    footer{padding:20px;font-size:.87rem;color:#b7c9d8;border-top:1px solid #35495d}
    [hidden]{display:none!important}
  </style>
</head>
<body>
<header>
 <h1>GlobalGrid2050 · Lightning → Grid Scenario Lab</h1>
 <div class="small">Experimental, read-only | Existing Ventus Grid Engine + Pipeline News MAP contract | No production changes</div>
</header>
<main>
 <p class="intro">Select a <strong>genuine EUMETSAT optical lightning flash</strong>, inspect nearby mapped substations and REPD solar farms, then prepare a clearly hypothetical inverter/earthing scenario. An optical flash is <strong>not</strong> necessarily a ground strike and is <strong>not evidence that any asset was hit</strong>.</p>
 <p class="status" id="safety-boundary"><strong>Evidence boundary:</strong> fault currents, surges and insulation damage can also arise from grid switching transients, equipment failure, insulation degradation, moisture ingress or a second IT-network fault. This map attributes <strong>no fault</strong> to lightning. <strong>Post-event inspection is a diligence recommendation, not a diagnosis.</str  … [line shortened here: 408 characters; full line on GitHub]
 <div class="status" id="status" role="status" aria-live="polite">Loading the genuine seven-day lightning feed…</div>
 <section aria-label="Map of genuine optical flashes and nearby infrastructure">
   <h2>Optical flashes on the map — tap a larger yellow point</h2>
   <p class="small">The bright dots mark real satellite optical-flash positions, not confirmed ground strikes. Each dot has an invisible 44 CSS px touch target. Tapping one selects it and measures nearby mapped solar farms and substations. Larger amber circles group multiple optical flashes; tap to expand.</p>
   <div id="flash-map" role="region" aria-label="Interactive map of optical lightning flashes and, after selection, nearby solar farms and substations"></div>
   <div class="map-tools">
     <button type="button" id="fit-flashes" disabled>Fit available flashes</button>
     <button type="button" id="fit-selection" disabled>Fit selected observation</button>
   </div>
   <div id="map-status" role="status" aria-live="polite" class="small">Preparing the map. You can always select a flash by UTC time using the dropdown below.</div>
   <div class="map-legend"><span><i class="map-dot"></i> Optical observation</span><span><i class="map-dot solar"></i> Mapped REPD solar project (radius shows declared MW)</span><span><i class="map-dot sub"></i> Mapped substation</span></div>
 </section>
 <div class="grid">
  <section>
   <h2>1. Select optical observation</h2>
   <label for="flash">Observed optical flash (UTC)</label>
   <select id="flash" disabled><option>Loading…</option></select>
   <label for="radius">Nearby solar search radius</label>
   <select id="radius"><option value="5">5 km</option><option value="10">10 km</option><option value="20" selected>20 km</option><option value="50">50 km</option></select>
   <label for="kv">Minimum declared substation voltage</label>
   <select id="kv"><option value="0">All declared voltage classes</option><option value="132" selected>≥132 kV</option><option value="275">≥275 kV</option><option value="400">≥400 kV</option></select>
   <button id="inspect" disabled>Find nearest mapped infrastructure</button>
   <div id="observation" class="small" role="region" aria-label="Selected optical observation"></div>
  </section>
  <section>
   <h2>2. Nearby mapped infrastructure</h2>
   <p class="small">Actual distances in kilometres, using existing Ventus Grid Engine geodesy. Nearest does <strong>not</strong> imply connected, hit, exposed, or damaged.</p>
   <div id="provenance" class="small">No search run.</div>
   <h3>Substations</h3><div id="substations">Not evaluated.</div>
   <h3>Solar projects</h3><div id="solar">Not evaluated.</div>
  </section>
  <section>
   <h2>3. Hypothetical electrical scenario</h2>
   <p class="small">No numerical result is produced. Declare installation earthing and inverter characteristics; do not infer them from the optical flash.</p>
   <label for="ac">AC earthing</label>
   <select id="ac"><option value="unspecified">Not known</option><option value="IT">IT / unearthed</option><option value="TN">TN</option><option value="TT">TT</option></select>
   <label for="dc">PV DC reference</label>
   <select id="dc"><option value="unspecified">Not known</option><option value="floating">Floating</option><option value="functional_earthed">Functional earthing declared</option></select>
   <label for="inverter">Inverter isolation</label>
   <select id="inverter"><option value="unspecified">Not known</option><option value="transformerless">Transformerless</option><option value="isolated">Galvanically isolated</option></select>
   <label for="project">Scenario site</label>
   <select id="project"><option value="">No project selected</option></select>
   <label for="overhead">Overhead lines / pylons nearby (user-provided)</label>
   <select id="overhead"><option value="unknown">Unknown / not assessed</option><option value="nearby">Yes, verified nearby</option><option value="not_reported_nearby">Not reported nearby</option></select>
   <label for="weather">Weather / moisture (user-provided)</label>
   <select id="weather"><option value="unknown">Unknown / not assessed</option><option value="wet">Wet, verified</option><option value="dry">Dry, verified</option></select>
   <button id="scenario" disabled>Prepare scenario &amp; inspection checklist</button>
   <div id="scenario-output" class="scenario" aria-live="polite">Select an observation and find actual nearby infrastructure first.</div>
  </section>
 </div>
 <p class="status">Coverage: this experimental page currently reads the <strong>seven-day live feed only</strong>. It does not load historical archive shards, even if they are published separately. Earlier dates and unsearched hours are <strong>UNKNOWN, not zero</strong> in this view. Source: EUMETSAT MTG Lightning Imager L2-LFL. No optical observation is interpreted as a ground attachment.</p>
</main>
<footer>Ventus Ltd · GlobalGrid2050 · Experimental next-generation preview branch, not a safety study, forensic diagnosis or connection assessment. Code: Apache 2.0 where declared; EUMETSAT, NESO and OSM datasets retain their own source terms. Technical background: <a href="https://www.dehn-international.com/sites/default/files/media/files/string-inverters-wpx051-en.pdf">DEHN WPX051: AC-side surge  … [line shortened here: 662 characters; full line on GitHub]
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@3.6.2/dist/maplibre-gl.css">
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@3.6.2/dist/maplibre-gl.js"></script>
<script type="module" src="./app.mjs"></script>
</body>
</html>