# Sesimbra kelp-cover benchmark

A preregistered experiment asking how well satellite imagery predicts measured kelp
percentage cover at Sesimbra, and whether water-column correction improves it. This is the
experiment, not library code: the `oceanstream` coastal library is a dependency, developed
in [sd-data-ingest](../sd-data-ingest).

**Result: Pléiades Neo does not predict cover beyond what depth alone implies, and a
July-fitted model does not transfer to September.** Depth-only is the best candidate in the
development campaign at both spatial scales; every spectral candidate is worse. On the
sealed September holdout every candidate overpredicts by 35 to 50 percentage points as the
kelp declines seasonally. Three of the four registered comparisons could not run at all and
are reported as unavailable with evidence. See [the results report](docs/results.md).

**Exploratory re-analyses r1–r6 (2026-10-02):** across the tested Sesimbra campaign
geometries, neither glint correction, two-date Sentinel-2 averaging, nor removal of fixed
background offsets enabled reliable recovery of the simulated kelp-cover signals. The
experiments identify strong dependence on observation conditions, spatial variation and
model formulation. They provide a quantified limitation of this campaign benchmark, rather
than a general limit on satellite kelp detection. See the revision reports listed below.

## Reports

| Document | What it covers |
|---|---|
| [technical-report.md](docs/technical-report.md) | The whole experiment in one report: design, what could run, registered results, the six re-analyses, synthesis and limits, with maps |
| [plan.md](docs/plan.md) | The registered protocol, its amendments and pre-registration findings |
| [september-inputs.md](docs/september-inputs.md) | Input audit of the September delivery |
| [scene-selection.md](docs/scene-selection.md) | Why Sentinel-2 is unavailable, and which scenes qualified |
| [optics-readiness.md](docs/optics-readiness.md) | Why the water-column-corrected branch is unavailable |
| [results.md](docs/results.md) | Development and held-out results, and what they support |
| [revision-r1.md](docs/revision-r1.md) | Exploratory re-analysis after the 2026-10-02 review: consistent QC, NIR control, position sensitivities, injection test, glint variants, campaign windows across years |
| [revision-r2.json](registration/revision-r2.json) | Draft protocol, 2026-10-02: glint-tolerant Sentinel-2 admission, correction-domain checks and paired radiometric assessment; not executed |
| [revision-r3.md](docs/revision-r3.md) | Glint-tolerant Sentinel-2 mask for the summer scenes: water admitted, no scene accepted under the registered checks (which have known weaknesses), Sentinel-2 injection test |
| [revision-r4.md](docs/revision-r4.md) | Detectability envelope: synthetic cover through the real sampling, four geometries, patch sizes, position errors, a depth-aware model and an oracle |
| [revision-r5.md](docs/revision-r5.md) | What the unexplained variation is: glint texture on PNeo 8 July, a near-shore term on 3 September, a stable seabed-like pattern plus date-specific noise on Sentinel-2; glint-correction scale diagnostics |
| [revision-r6.md](docs/revision-r6.md) | Paired PNeo V0/V1 recovery with an end-to-end correction check, Sentinel-2 dates against their combination, background bias and an offset control, matched windows: neither correction, combination nor offset removal reaches the envelope |

## Layout

```
registration/   the frozen experiment: experiment.json, ACOLITE settings, reference region,
                water levels, glint screen, input locks, the CCMAR query
benchmark/      run_benchmark.py, every stage of the experiment; revision*.py, the
                re-analyses; report_maps.py and habitat_map.py, the report's maps, the
                habitat context and the story-map layers; report_template.html
inputs/         small registered inputs copied from the library's Sesimbra AOIs
docs/           the reports above, with portable JSON exports and figures/
tests/          failure-mode tests for the stages
out/            run artifacts, git-ignored
.cache/         imagery and ACOLITE output, git-ignored, about 20 GB; emodnet-habitats/
                holds the two downloaded habitat layers with their provenance
```

Field data, bathymetry and the Pléiades Neo deliveries stay where they are and are
referenced by absolute path from `registration/experiment.json`.

## Install and run

```bash
python -m venv venv && . venv/bin/activate
pip install -r requirements-dev.txt        # installs the coastal library from ../sd-data-ingest
python benchmark/run_benchmark.py --help
```

Stages are separate commands, in order:

```bash
python benchmark/run_benchmark.py inventory         # reference dataset, depth checks, join classes
python benchmark/run_benchmark.py water-levels --env-file .env
python benchmark/run_benchmark.py glint-screen      # image-quality pre-filter over candidate dates
python benchmark/run_benchmark.py fetch --env-file .env --top 2
python benchmark/run_benchmark.py prepare           # pinned ACOLITE on every scene
python benchmark/run_benchmark.py scene-qc          # registered checks and scene ranking
python benchmark/run_benchmark.py reference-region  # geometry-only PNeo deep-water region
python benchmark/run_benchmark.py optics-reference  # QAA fit over that region
python benchmark/run_benchmark.py cross-sensor      # PNeo against Sentinel-2 on the 10 m grid
python benchmark/run_benchmark.py freeze            # pin every input
python benchmark/run_benchmark.py fit               # leave-one-transect-out, then seal
python benchmark/run_benchmark.py evaluate          # the held-out campaign, once
python benchmark/run_benchmark.py export            # refresh the JSON exports in docs/
```

`.env` needs `CDSE_USERNAME` and `CDSE_PASSWORD` for Sentinel-2 downloads, and
`COPERNICUSMARINE_SERVICE_USERNAME` and `COPERNICUSMARINE_SERVICE_PASSWORD` for sea level.

## How the protocol is kept

- Choices are registered in `registration/experiment.json` before the data that would be
  affected are examined. Every later change is an entry under `amendments`, with its reason,
  its limits, and the original outcome retained.
- Fitting cannot open the held-out targets: the stage refuses, and the inventory writes them
  to their own file.
- Fits are sealed and checksum-verified before evaluation, and evaluation refuses to run a
  second time.
- `freeze` pins sources, processed imagery, the registration and the library's source, and
  both fitting and evaluation verify that lock first.
- Scenes are chosen on image quality, never on how well they predict cover.

## Provenance

The experiment ran inside the library repository and moved here on 2026-09-20. The lock the
published results were produced under is kept as
`registration/input-lock.sd-data-ingest.json`; `registration/input-lock.json` re-pins the
same file contents at their paths here. `out/RELOCATED.json` records the move. Rerunning
any stage against changed inputs needs a new registration, not an edited lock.
