# ARCES Climate Explorer

The interactive explorer displays the committed Ontario case study, with 398
selected grid-cell centres and annual records for 1995–2024. It consumes existing
C++ regional exports; it does not recalculate climate statistics in JavaScript.

## Open locally

From the ARCES checkout in PowerShell:

```powershell
Start-Process .\explorer\index.html
```

Keep the entire explorer directory together. Its library, boundary, basemap and
observations are bundled locally, so it also works without an internet connection,
API key, Node installation, Python installation, or C++ build. No external fonts,
map tiles, geocoder, telemetry, or location service are requested. Documentation
and attribution links open only when clicked. The documentation links expect the
repository's `docs/` and `examples/` directories alongside `explorer/`.

For HTTP preview from the repository root, optionally use `python -m http.server
8000 --bind 127.0.0.1` and visit `http://127.0.0.1:8000/explorer/`. A normal static
host can serve the repository files; hosting/publication is a separate step.

## Case study

The **Case study** navigation opens `explorer/case-study.html`: an offline reading
page with the Ontario findings, a trend overview, a chart comparing three selected
centres, methods, validation notes and original export downloads. The page uses the
same packaged dataset and remembers the same OLED preference as the explorer.
Cell links open the matching centre and trend layer in Explorer. The Earth-orbit
mark adapts the chosen logo concept to a crisp, scalable SVG for the header/favicon.

## Publish safely

Use `python tools/build_site.py` and publish **only the generated `dist/`** on an
HTTPS static host. The source checkout is for local development, not public
serving. The generated copy adds CSP and script-integrity attributes while the
source explorer remains compatible with direct local-file opening. The supplied
`_headers` configuration is for compatible static hosts; actual response headers
must be verified after deployment. See `docs/SECURITY_REVIEW.md` before publishing.

## Controls

- **Temperature:** complete, calendar-day-weighted annual means in °C. Scrub the
  slider, use keyboard arrow/Home/End keys, or press Play. Playback stops at the
  final year and pauses when the browser tab is hidden. Speed changes take effect
  during playback. Animation starts only after pressing Play.
- **Trend:** full-period OLS slope in °C per decade. The scale is symmetric about
  zero; dark outlines mark approximate 95% HAC intervals containing zero. Playback
  and year controls are disabled because a full-period trend does not vary by year.
- **Coverage:** complete years per grid centre. Full-period layer; no playback.
- **Select a centre:** click a coloured point, or search a listed place / decimal
  `latitude, longitude`. Search runs locally and chooses the geographically nearest
  *selected* centre, with its distance shown. It never interpolates a city value.
- **Cell details:** annual-temperature chart, exported trend, approximate interval,
  complete-year count, and annual CSV download. Chart gaps remain gaps.
- **Display:** OLED mode, boundary, place labels, uncertainty outlines and point
  opacity. OLED mode switches panel and map backgrounds to true black; switch it
  off to restore the standard dark theme. The preference is saved only in this
  browser when local storage is available. Blue (`#6492FF`) is the interface accent;
  scientific temperature/trend colour scales retain their data meaning.
- **Map controls:** zoom, fit Ontario, and browser fullscreen. Fullscreen retains
  the explorer's timeline and details. Pan/zoom is keyboard and touch
  accessible. Search and slider controls provide keyboard access to cell details.

Annual temperatures use a single fixed scale computed over the entire dataset,
not a new scale for each frame. Missing values use grey dashed points; zero is a
valid value. Only selected centres are drawn, without inventing an interpolated
temperature surface between them. On small screens the map and timeline appear
above the details panel.

## Repackage exports

Python 3.9+ standard library only:

```powershell
python tools/build_explorer.py
# Or package an updated Ontario run:
python tools/build_explorer.py --input .\results\new-ontario-run
```

The exporter reads `regional.json`, `regional.csv`, `annual.csv`,
`boundary.geojson`, and `boundary.source.json`. It validates coordinates, cell IDs,
annual uniqueness, finite numbers, schema/variable, and complete-year counts.
Incomplete or absent annual records become `null`. Values retain the precision of
the parsed source exports; no smoothing, trend fitting, or rounding is applied.
`explorer/data.js` is a generated, tracked asset, including source checksums and
the original run version. CSV/JSON source hashes normalize CRLF to LF across
platforms; the boundary GeoJSON hash is byte-exact. Regeneration is deterministic.
The interface and bundled
city list are designed for Ontario; arbitrary regions require interface changes.

The checked-in package retains the original **0.4.0-dev** source run provenance.
The raw NASA files are not included. This feature does not rerun extraction or
independently validate the original HAC calculation. See the Ontario case study
and `docs/VALIDATION.md` for the earlier validation record.

## Basemap and licenses

- **Leaflet 1.9.4**, BSD-2-Clause, vendored in `explorer/vendor/`. License included.
- **Natural Earth 5.1.2**, public domain: 1:110m country and lake geometries from
  `nvkelso/natural-earth-vector`, pinned tag `v5.1.2`. Included features intersect
  the North America envelope (-130, 25) to (-50, 75); properties are removed.
  Geometry is retained without further simplification. This small-scale context
  map omits roads and local geography; zooming does not increase its detail.
- **Ontario selection boundary:** the existing unmodified Statistics Canada /
  geoBoundaries geometry and attribution are embedded from the source exports.
  CC BY 4.0 and upstream terms are retained in `data/boundaries/README.md` and the
  source sidecar. The display basemap is never used to select climate cells.

`explorer/vendor/manifest.json` records original download URLs/checksums and bundled
asset checksums. The map is independent of The Weather Network and uses ARCES
branding. No live precipitation or forecasts are displayed.

## Verification

```powershell
python -m unittest discover -s tests -p "test_explorer_package.py"
node --test tests/explorer.test.cjs
python tools/verify_ontario_example.py
```

Node 18+ is required for the JavaScript tests. The package tests compare every embedded value and source checksum against a
fresh package from the committed exports, validate vendored asset integrity, and
exercise malformed/missing annual data. Display-helper tests cover fixed scales,
nulls versus zero, interval markers, the Ontario-selected Toronto-nearest cell,
and year-invariant trend/coverage layers. They run in CI without network access.
