Energy Flow Observatory
Model documents   /   Download PDF

Software, reproduction, and deployment

The application is a static website. The interface, saved dataset, numerical solver, geographic geometry, and documents are ordinary files. Scenario calculations run in the visitor’s browser. No scenario is submitted to a server-side optimization service. Settings are encoded in the URL, so opening or sharing a scenario link can transmit those query parameters to the static host.

1. Repository layout

Path Role
dist/index.html Application structure and controls
dist/styles.css Layout, typography, responsive behavior, and visual states
dist/app.js UI state, visualizations, historical comparisons, downloads, and worker requests
dist/pairs.js Country-directory classification and direct-pair scenario eligibility
dist/solver.js Capacity construction, flow algorithms, and model outputs
dist/worker.js Asynchronous numerical requests and a bounded result cache
dist/data/energy-data.json Saved analytical inputs, metadata, observations, and reference values
dist/data/world.json Country geometry for the map
docs/ Editable explanations of the model and application
scripts/ Numerical reproduction and document-building programs
review/ Reproducible numerical review and worked-example results
dist/docs/ Published HTML and PDF documents

The application uses relative paths. It can therefore be served at a domain root or a project subdirectory, including a GitHub Pages project site. Opening index.html directly as a local file is not the intended way to run it, because browsers restrict module, worker, and data access from file URLs.

2. Run the site locally

From the repository root:

python3 -m http.server 8000 --directory dist

Open http://localhost:8000. The website needs no package installation, build step, API key, or database. Python provides only the local static file server in this command. The model itself runs in JavaScript.

Use a current browser with ES modules, Web Workers, SVG, and canvas support. The application downloads a saved data file and geographic geometry once during initialization. Its calculations can then use those in-memory inputs without contacting UN Comtrade.

3. From a control change to a result

The user selects a commodity, annual baseline, shock, and capacity assumptions. The interface converts displayed percentage controls into fractions. For example, a displayed 50% cut becomes cut: 0.5.

The selected annual panel and normalized options are passed to a dedicated worker. The worker calls the requested numerical operation and returns its result under a request identifier. The interface also retains a scenario version. A result from an earlier scenario cannot overwrite the current result after the user changes controls.

Pending calculations clear stale scenario metrics and disable result downloads. Unsupported pair scenarios do not send a quantitative corridor calculation. They display a coverage reason instead. Historical exploration remains available on its own eligible observations.

The worker stores at most 60 request results. Its key includes the operation, product, year, options, and operation settings. This avoids repeating an identical scenario during a session. The cache is appropriate for the shipped immutable panel. A future feature that replaces data without reloading the page must also invalidate this cache or include a data-version identifier in its key.

4. The numerical module

The browser’s numerical module exports seven main operations.

Function Returned object
buildProblem(panel, options) Checked capacities, supported arcs, direct loss, and numerical scale
maximumService(problem, withCut) Maximum total service and, when requested, a minimum-cut certificate
solveScenario(panel, options) Ordered allocation, country and source totals, bilateral flows, metrics, and alternative-support benchmark
sensitivityCurve(panel, options, settings) Common-severity loss curves, thresholds, outage loss, and integrated stress
sensitivityGrid(panel, options, settings) Aggregate loss across supply and route headroom combinations
rankSuppliers(panel, options, settings) Separate supplier-shock outcomes at a common severity
countryEnvelopes(panel, options) Separate buyer minima and maxima at maximum aggregate service

buildProblem and maximumService are useful for inspection and reproduction. The worker exposes the other five calculations as solve, curve, grid, ranking, and envelopes operations.

An example call

import {solveScenario} from './dist/solver.js';

const panel = data.products.lng.panels['2025'];
const result = solveScenario(panel, {
  spareSupply: 0.10,
  linkExpansion: 0.25,
  routeMode: 'existing',
  shocks: [{code: 842, cut: 0.50}]
});

For a single corridor, supply cuts are omitted:

const result = solveScenario(panel, {
  spareSupply: 0.10,
  linkExpansion: 0.25,
  routeMode: 'existing',
  shocks: [],
  corridor: {sourceCode: 842, targetCodes: [251], cut: 1.0}
});

The interface checks direct-pair eligibility before submitting such a request. A program calling the numerical module directly must preserve the same distinction between known quantities, unknown observations, and outside-panel roles. The numerical module is not a substitute for the coverage checks in pairs.js.

Input bounds

The interface offers supply headroom from 0% to 50% and existing-route expansion from 0% to 100%. The numerical module accepts nonnegative fractions up to 10 for both parameters. Shock fractions must lie in [0,1][0,1]. Duplicate supplier selections are rejected. Supplier cuts and a corridor cut cannot be combined in one request.

The lower-level range is broader than the interface range to support controlled experiments. It does not imply that a 1,000% increase is an empirically credible capacity assumption.

Returned quantities

The solver’s volumes are in million barrels. A result includes the selected options, aggregate metrics, country service, supplier usage, bilateral capacities and allocations, an aggregate benchmark under the other support, and the first-stage minimum cut. Calculation time is reported for operational inspection. It is not a model outcome.

The numerical edge object includes both a nonnegative optimization baseline and a known flag. For an unknown observed pair, the numeric reference used by the optimization must not be presented as a measured zero. The interface’s export functions apply this distinction.

5. Reproduce the examples and numerical comparison

The examples use the JavaScript implementation directly:

node scripts/worked_examples.mjs

The independent review constructs linear programs in Python:

python3 -m pip install -r requirements-validation.txt
python3 scripts/validate_reference.py

The second command invokes Node.js to obtain browser-model results, then compares them with an independently constructed SciPy/HiGHS formulation. Its output records the snapshot and solver hashes. Keep these hashes when comparing one release with another. Agreement on a model name or a calendar date alone does not establish that two calculations used identical inputs.

These reproduction commands start from the saved analytical snapshot. Reconstructing that snapshot from raw Comtrade responses requires upstream material that is not included in this repository. The data document identifies that boundary explicitly.

6. Rebuild the documents

The Markdown files under docs/ are the editable document sources. The build script produces individual HTML and PDF versions, a combined manual, and a document archive:

python3 scripts/build_docs.py

This command needs Pandoc and either Tectonic or XeLaTeX. It uses Tectonic when available. Set ENERGY_DOCS_PDF_ENGINE=xelatex to select XeLaTeX explicitly. The shipped documents are already rendered, so these programs are not needed to run or host the application. HTML mathematics is rendered as MathML without a remote equation service. The PDF output uses ordinary text, equations, tables, and internal links.

Document builds should follow changes to model equations, input definitions, defaults, output fields, or behavior. Rebuilds alone do not update the numerical snapshot or rerun the independent comparison.

7. Publish the static application

Any static host can serve the contents of dist/. Preserve the directory structure so the worker, model, data, and documents resolve through their relative paths. A host needs to serve JavaScript modules with an appropriate JavaScript content type and permit same-origin worker loading.

For GitHub Pages, one straightforward arrangement is a source repository with the files in this layout and a gh-pages branch containing the contents of dist/ at its root. In the repository’s Pages settings, choose that branch and its root folder as the publishing source. The included .nojekyll file marks the output as a prebuilt static site. GitHub’s publishing-source documentation describes the supported branch and Actions options.

Publishing the repository and publishing the website are separate actions. A public source repository does not, by itself, enable Pages. A successful deployment should be followed by opening the reported website URL and running at least one representative scenario.

8. What updating the data requires

The demo contains no scheduled refresh, Comtrade credential, hidden API proxy, or automatic parameter fit. Its visible snapshot date belongs to the saved input file.

A data update should define the new vintage, preserve the reporting identifiers, reconstruct quantity and eligibility decisions, rebuild matched panels, update observation statuses, and rerun the numerical review. If country roles or commodity definitions change, historical comparisons must be revisited before old and new totals are treated as comparable.

Changing only the timestamp would not constitute a data update. Replacing the data file without revisiting its masks could change missing observations into apparent zeros. Both would compromise interpretation even if the numerical optimizer still found a feasible solution.

9. A practical review sequence

First read the model’s capacities and three objective priorities. Next check the commodity units, reporter cohort, and known-pair masks. Reproduce one worked example, then run the independent linear-programming comparison. Inspect the selected country’s allocation range before drawing a distributional conclusion. Finally, vary supply and route headroom to see whether the substantive conclusion survives reasonable alternatives.

This sequence connects an operational result to its assumptions. It also separates questions that the released demo can resolve from questions that require additional data or a different model.