Skip to content

The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.

JavaScript

Find what a sweep kept joining away, ask the size first, add a burned-buildings detector, and check proof points (#93)

OsintMeThate53b25273f88
diff --git a/README.md b/README.md
index 53c2bd8..1b95b20 100644
--- a/README.md
+++ b/README.md
@@ -81,8 +81,8 @@ plain directory holding the whole investigation.
Detect sweeps an area for what appeared, and the map takes layers made elsewhere.
- **Detect**, a tab of its own, sweeps drawn areas of Sentinel-2 for vessels, fires and
- flares, construction, small spots, surface change, burn scars, vegetation loss
- or new water. Candidates come strongest first, and only one you keep becomes a
+ flares, construction, small spots, surface change, burn scars, vegetation loss,
+ new water or burned buildings. Candidates come strongest first, and only one you keep becomes a
case pin.
- Difference and Detect share one Sentinel-2 cloud and shadow mask.
- Radar: five Sentinel-1 analyzers (vessels, any change, razed buildings, new
diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.md
index b015eff..16eb70d 100644
--- a/docs/RELEASE_NOTES.md
+++ b/docs/RELEASE_NOTES.md
@@ -10,7 +10,7 @@ maps made elsewhere on yours.
- **Detect** is a new tab under Map. Draw areas and it sweeps them on Sentinel-2
at full resolution for vessels, fires, construction, burn scars, vegetation
- loss, new water or any change.
+ loss, new water, burned or destroyed buildings, or any change.
- Radar analyzers read Sentinel-1 through cloud and at night: vessels, damaged
buildings, new structures, floods. Settings → Imagery shows how to add the
Sentinel-1 layer they need.
@@ -18,7 +18,10 @@ maps made elsewhere on yours.
or radar. Checks on places you trust turn red when a rule stops holding. Five
examples ship with their checks.
- **Find passes** lists the dates your areas really have, with coverage and
- cloud. The cost in Copernicus requests shows before anything is fetched.
+ cloud, up to a year back or between two days you pick. The cost in Copernicus
+ requests shows before anything is fetched.
+- The When step warns when two passes see the sun at very different heights,
+ since every building's shadow then reads as a change.
- Candidates come strongest first. **Pin** files one in the case with its
evidence crop and a dated claim, or open it in Compare.
- A routine keeps an analyzer, its areas and a date rule, and **Run routine**
@@ -65,6 +68,9 @@ maps made elsewhere on yours.
- A proof can carry one sentence and the date its material was taken, shown on
the Timeline.
- Place a proof's point on a map instead of typing it.
+- A point taken from a capture is only the middle of its frame, so it shows
+ greyed until you check it. Save and To post open the map on each unchecked
+ point first. **Later** saves the proof and keeps those points off the case map.
## Inspect and Collage
diff --git a/docs/SPEC.md b/docs/SPEC.md
index 2424008..3df8ce2 100644
--- a/docs/SPEC.md
+++ b/docs/SPEC.md
@@ -179,10 +179,10 @@ proof for publication.
| ✅ **Imagery Wayback** | Browses every Esri World Imagery release, narrowed on request to the ones that changed the point, and dates the pixels apart from the release. |
| ✅ **Satellite Compare** | Aligns and annotates two dated views, assists matched-product change reading, saves editable sessions and files or exports attributed PNG/GIF outputs. |
| ✅ **Detect sweep** | Native Sentinel-2 detectors, mask footprints, manual candidates and Keep / Dismiss / Pin review with PNG evidence stamped with its dates and point. |
-| ✅ **Passes over an area** | Picks Detect's Copernicus dates from the passes the drawn areas really have, each with the share of them its swath reached, and reports what a finished run actually swept. |
+| ✅ **Passes over an area** | Picks Detect's Copernicus dates from the passes the drawn areas really have, up to a year back or between two days picked in a calendar, each with the share of them its swath reached, and reports what a finished run actually swept. |
| ✅ **Cloud & shadow filter** | One click in Difference and Detect, both on Sentinel-2's scene classification: unsure edges taken, classified "clouds" too small to be one dropped, and shadows cast away from the sun, including the ones the classification read as water. |
| ✅ **Difference over any view** | A switch beside Compare's four views, offered on a matched pair only, laying its highlights on A, B or both (the default). |
-| ✅ **Detect** | Map-first tab, collapsible dock, shared case areas reshaped in place, an A/B When step with per-area dates, one-off and routine runs grouped in Saved, repeat notices and explicit SAT layer snapshots. |
+| ✅ **Detect** | Map-first tab, collapsible dock, shared case areas reshaped in place, an A/B When step with per-area dates that warns when the two passes' shadows differ, one-off and routine runs grouped in Saved, repeat notices and explicit SAT layer snapshots. |
| ✅ **Capture scale & north** | Adds a scale bar and true-north needle to app and extension captures when resolution and heading are known. |
| ✅ **Footprint tracing** | Traces a place's uncertainty as a polygon around its pin, in place of the radius. |
| ✅ **Extension map tools** | Draws measure, the case's points one position at a time, sun and moon, search grids and case media over third-party maps, calibrated per site by a replayable command. |
@@ -202,7 +202,7 @@ proof for publication.
| ✅ **Copernicus where it is needed** | Detect and Compare say in the middle of the tool what Copernicus still lacks, with the free account, the Sentinel-2 configuration and the Sentinel-1 layer form field by field. |
| ✅ **A candidate in Compare** | Opens a Detect candidate in Compare on the passes that found it, or against high-resolution imagery for a thing present on one pass. |
| ✅ **Sizes in Detect** | Right-clicks Detect's map for its own point menu, measures a hull with a ruler, sizes each candidate along its footprint, walks the largest first, and hides the drawing or blinks A against B from the review. |
-| ✅ **Analyzers of your own** | Builds a Detect analyzer from up to six rules on any band, index, ground class or radar polarisation, read on A, B or the change, tried live on the map over any Copernicus layer with a point reading; optional checks (marked places reread as the rules change) and five calibrated examples that ship with theirs; also opened from a built-in or a Difference reading, with a shape filter for every analyzer. |
+| ✅ **Analyzers of your own** | Builds a Detect analyzer from up to six rules on any band, index, ground class or radar polarisation, read on A, B or the change, tried live on the map over any Copernicus layer, painted rule by rule or as the detections alone, with a point reading; optional checks (marked places reread as the rules change) and five calibrated examples that ship with theirs; also opened from a built-in or a Difference reading, with a shape filter for every analyzer. |
| ✅ **Examine: Inspect and Collage** | Keeps one work per file, saved as it is made, with its frames on a strip; lays collages out of frames and images from any file; merges a case's 0.3.0 sessions on open. |
| ✅ **One camera for the map tabs** | Satellite, Compare and Detect show the same ground, and the link carries it to other windows; a Detect review and a saved comparison keep theirs, and Settings turns it off. |
| ✅ **Comparisons in Saved work** | A saved comparison stands on the map with the captures, at its frame's centre with the frame outlined, dated A → B, and reopens in Compare; an export can also be kept in the case under it. |
@@ -210,6 +210,7 @@ proof for publication.
| ✅ **An evolution of one point** | Exports Sentinel-2 passes or Wayback pictures ticked by hand on their previews, back to 2015, as one GIF or one sheet drawn from the tile proxy on the same ground, repeats and empty pictures left out and counted. |
| ✅ **Signed exports, marks in their colours** | Compare exports close their credits line with the Azimut logo and name unless unticked, and a GIF keeps every mark's colour exact. |
| ✅ **One turn on every map** | A middle-drag turns any map or Inspect frame like a wheel about the grabbed point, settling on north, in 15° steps with Ctrl; a middle click or Shift+↑ puts north back, Shift+← / → steps. |
+| ✅ **Checked proof points** | A proof point taken from a capture's centre reads greyed until checked; Save and To post show each one on the map first, and one saved for later stays off the case map. |
---
diff --git a/docs/UI.md b/docs/UI.md
index fc5570b..0c4b0ef 100644
--- a/docs/UI.md
+++ b/docs/UI.md
@@ -1163,7 +1163,7 @@ one pin glyph — coordinates in the tooltip, not in the title — and clicking
flies the map there. **Show N working files** sits on the same independent axis: a
switch rather than another chip, because the chips answer *show me only X* and are
single-select where this one is *put X back*. The library opens on what the case
-collected, the frames, collages and captures it produced itself held back — a capture
+collected, the frames, collages, captures and Compare or Detect renders it produced itself held back — a capture
is a map the app drew out of tiles or the extension grabbed off the screen, where an
upload, a paste and a download came from outside — and the switch says how
many those are rather than leaving them unannounced; the counts and the paging are
@@ -1579,7 +1579,10 @@ which it is (`lib/map/tools.js`) rather than adding a button somewhere.
map's top-left corner with the zoom buttons stacked under it, grouped by a
hairline. An armed seat wears the accent as an edge, not as a filled square.
Adding a reference window is in the rail too, as a seat that runs instead of
- arming.
+ arming. Its picker narrows like the Media Library: past six items it grows a
+ search, one chip per facet that would hide something, a folder button, and
+ **Show N working files**, held back by default since the reference is nearly
+ always collected material. The chip and the switch stay as set for the session.
- **Its settings** open in the rail's one **panel slot**, beside it. One mode is
armed, so one panel is open; a panel cannot cross another or the map's own
controls.
@@ -2139,7 +2142,10 @@ and the reason is written under the Next button. **Passes over the area** lists
what exists right under the question, each row with its A and B buttons, and a
typed day works too. One choice stands for every area; **Set them per area…**
opens the per-area table for areas far enough apart to sit under different swaths,
-and the step then lists each area's days. The last step reads the choice back in
+and the step then lists each area's days. When the two days see the sun at very
+different heights, the step says how long a 10 m building's shadow is on each: past
+half a pixel of difference most buildings read as changed, as a January and a
+September pass over an airbase showed. The last step reads the choice back in
one line. A radar pass is a day and a UTC time,
since Sentinel-1 can see a place twice in a day from opposite directions: the list
shows each pass with its time and direction, and A and B must share
@@ -2148,7 +2154,11 @@ hand is pinned to the pass on the other side's track at launch, and an automatic
pass is looked for on the reference's track.
**Find passes** explicitly asks Copernicus about the areas and counts one request
-against its quota. The picker shows cloud and coverage over all of them. At launch, each area independently resolves its latest usable pass
+against its quota. The picker shows cloud and coverage over all of them. It looks
+30 days, 90 days or a year back, or under **Dates…** between two days picked in a
+calendar that starts at the satellite's launch. The catalogue gives at most 100
+passes, newest first, so a list it cut short offers **Older passes**, one more
+request for the ones before the oldest listed. At launch, each area independently resolves its latest usable pass
under the cloud ceiling. Different tracks can therefore use different days.
An unresolved area fails by name without stopping the rest. Opening Detect reads
local state only; pass lookups happen only on request or during an explicit run.
@@ -2164,10 +2174,10 @@ optical ones approximate, since a hull answers the radar through cloud and glint
alike; two radar passes read damage roughly. An analyzer that cannot run yet
carries a key and *set up*: all of them without a Copernicus key, the radar ones
until Settings has found their layer. It can still be picked and read about, and
-the step says what is missing with a way to Settings. Eight ship built in, for big things and small ones:
+the step says what is missing with a way to Settings. Nine ship built in, for big things and small ones:
vessels, fires and gas flares, construction and earthworks, small spots (impacts,
-burn marks, vehicles), any surface change, burn scars, vegetation loss, and
-flooding or new water. Each reads its own band product, and each was tuned on real
+burn marks, vehicles), any surface change, burn scars, vegetation loss,
+flooding or new water, and burned or destroyed buildings. Each reads its own band product, and each was tuned on real
scenes rather than synthetic ones: rough sea under glint, a dense anchorage under
cumulus, oil fires and wildfires, bright roofs, a construction site across seven
months, dry-season pastures. Vessels stand out from their own patch of sea in near
@@ -2176,9 +2186,15 @@ bulk land is a coast. What counts as sea comes from the water index or from the
classification, either one is enough: under sun glint the index alone read a whole
strait as dry. Fires take the published short-wave ratios on B8A, which
shares B12's grid. Construction is ground that moved the same way in every band
-while its vegetation held; a small spot changed while the ring of ground around it
+while its vegetation held, and burned or destroyed buildings are the same reading
+darkening only, past a 9% drop: soot, char and wreckage, where burn scars need
+vegetation to have burned. On pairs from Planetary Computer it took Hodeidah's
+burned tank farm, an Isfahan depot and Beirut's blasted port warehouses, and gave
+one to three candidates on quiet pairs of the same places; rain-wet ground is its
+look-alike; a small spot changed while the ring of ground around it
did not, that ring read with a hole in its middle so the spot cannot sit in its own
-background and over measured ground only, so a granule edge raises nothing; a burn has to end dark, which a dried pasture does not.
+background and over imaged ground only, past the area's edge too, so neither a
+granule edge nor the area's own edge raises anything; a burn has to end dark, which a dried pasture does not.
Five radar analyzers read Sentinel-1 through the layer Settings → Imagery found,
and see through cloud and at night: vessels, any radar change, damaged or razed
@@ -2194,7 +2210,7 @@ water; the radar decides only where that pass saw cloud. In a large port a
terminal that Sentinel-2 took for water still gives candidates among the ships at
berth, which no mask tried could remove without dropping the ships too. A radar
change is the power of both polarisations averaged over ground, 45 m a step of the
-size's averaging (90 m at Medium), and compared between two passes of one track: a
+size's averaging (90 m at Medium and All), and compared between two passes of one track: a
window counted in pixels held too few radar samples, and ground that did not change
came back as thousands of pieces or one region kilometres wide. *Bright* ground is ground that answered like walls on the
side that had them, and *water* is ground that went as dark as calm water. Two
@@ -2202,13 +2218,16 @@ passes only flag where to look: the razed-buildings analyzer says so, and the
flood one starts at Large, since a flood is fields wide. Without the radar layer
the wizard says where to find it and stops before its dates.
-**Small**, **Medium**, **Large** and **All** under the analyzer set the target
-size as a whole: floor and ceiling area, cleanup and grouping together, since a
-small target needs no cleanup that would erase it. What the chosen one accepts is
-written under the buttons in ground terms — a mark outside that band is found and
-then dropped, which reads as "nothing found" unless it is said. **All** sets no
-floor and no ceiling, for the mark that falls between two bands. Tuning any of
-those by hand leaves no size selected. The **Clouds & shadows** switch reads Sentinel-2's classification, grows a
+**Small**, **Medium**, **Large** and **All** come first in the What step, above
+the analyzers, and set the target size as a whole: floor and ceiling area, cleanup
+and grouping together, since a small target needs no cleanup that would erase it.
+What the chosen one accepts is written under the buttons in ground terms — a mark
+outside that band is found and then dropped, which reads as "nothing found" unless
+it is said. Every analyzer starts at **All**, no floor and no ceiling, because a
+size taken without noticing hid an airbase's change behind Medium's 20 ha ceiling;
+radar flooding alone starts at Large. **All** keeps the radar's 90 m averaging.
+A size pressed holds for the next analyzer picked, and tuning any of those by hand
+leaves no size selected. The **Clouds & shadows** switch reads Sentinel-2's classification, grows a
real cloud into the unsure pixels touching it, ignores classified "clouds" too small
to be one (white hulls and roofs), and casts each cloud away from the sun to find the
shadows the classification missed. The fire detector offers no switch: its band
@@ -2270,7 +2289,11 @@ dot hides or shows them, and pointing at a row shows that rule alone), the
candidates a run would return are outlined with their pins, and each row says what
share of the measured ground it keeps, alone and with the rules above it. The
preview runs the engine's own evaluation, cleanup, sizes, shape and grouping, so
-what it outlines is what a sweep of the same ground returns. A click on the map
+what it outlines is what a sweep of the same ground returns. **Rules** and
+**Detections** beside the count switch the map between that painting and the
+outlined candidates alone, as a run shows them; the dots keep their state for the
+way back, and one pressed from Detections returns to Rules. While a check is open
+the count is the check's own, since the map shows its frame only. A click on the map
reads every rule at that point: the value, before and after for a change, and a
tick or a cross, so a thing that was not kept says which rule let it go. Under
cloud or off the passes the card says so instead.
@@ -2346,7 +2369,9 @@ again returns to the run's order.
A candidate that crosses a tile edge is one candidate with one picture, stitched
from the tiles it touches. New candidates use the detector mask's simplified
outline; merged components retain their parts as a MultiPolygon. The bounding
-box still drives crops and merge tests. Existing results keep their
+box still drives crops. **Group within** measures the gap between the footprints
+themselves, not their boxes, so one join never widens the next: joined by boxes,
+an airbase's 667 marks once became one candidate of 31 km². Existing results keep their
stored rectangle geometry.
Opening a run puts the map on the candidate the panel is about, close enough to
@@ -2429,6 +2454,14 @@ behind a hairline and on a panel of its own, which is how every field here offer
the one act that belongs to it — the map on a coordinate, the eye that says the
camera stood there, the tab a source opens in, the calendar that builds a date. A row added with `+` opens on
the point above it, which is the only thing that says which ground it belongs on.
+**A point the imagery proposed reads greyed**, its pin in amber, until somebody checks
+it. A capture's point is the middle of its frame unless its pin was moved onto the
+target in Satellite, and a wide frame puts that middle far from what the proof is
+about. Typing the row or using the map checks it. **Save and To post walk every
+unchecked point through the map first**, one at a time: *Use this point* keeps or
+moves it and goes on to the next. *Later*, offered by Save only, saves the proof and
+keeps those points off the case map, where they would read as conclusions; a place
+already there stays. To post has no *Later*, since the post publishes the point.
The exported picture prints them only when asked (Advanced → Show coordinates):
unnamed points share one line, a named one takes its own, and the plate grows by
what it prints. **Show text** switches the credit line off beside it, so a plate
diff --git a/frontend/e2e/app.fixture.js b/frontend/e2e/app.fixture.js
index 68d3af4..2e7e8e2 100644
--- a/frontend/e2e/app.fixture.js
+++ b/frontend/e2e/app.fixture.js
@@ -1804,7 +1804,7 @@ export async function installAppFixture(page, options = {}) {
// Two different reads: the capture shelf (pickers list it beside media) and
// the geo index the Map panel groups. Both are needed — a picker whose
// shelf 404s shows no panels at all.
- if (path === `/api/cases/${CASE_ID}/satellite`) return json(route, []);
+ if (path === `/api/cases/${CASE_ID}/satellite`) return json(route, options.satCaptures ?? []);
if (path === `/api/cases/${CASE_ID}/drafts`) {
return json(route, Object.entries(fixtureDrafts).map(([name, draft]) => ({
name,
diff --git a/frontend/e2e/detect.spec.js b/frontend/e2e/detect.spec.js
index e08788a..2a13784 100644
--- a/frontend/e2e/detect.spec.js
+++ b/frontend/e2e/detect.spec.js
@@ -8,6 +8,9 @@ const area = { id: 'aaaaaaaaaaaa', name: 'North site', colour: '#38bdf8',
geometry: { type: 'Polygon', coordinates: [[[2.29, 48.855], [2.3, 48.855], [2.3, 48.862], [2.29, 48.862], [2.29, 48.855]]] } };
const zone = { id: area.id, name: area.name, kind: 'polygon', points: area.geometry.coordinates[0].slice(0, -1) };
const source = (date) => ({ provider: 'sentinel2', date, layer: 'TRUE_COLOR', maxcc: 30 });
+const size = (min_area, max_area, cleanup, smoothing, merge_metres) => ({ min_area, max_area, cleanup, smoothing, merge_metres });
+const SIZES = { small: size(300, 0, 0, 0, 0), medium: size(2000, 0, 1, 0, 30), large: size(20000, 0, 1, 1, 100),
+ all: size(0, 0, 0, 0, 0) };
async function openDetect(page, withRun = false) {
await installAppFixture(page);
@@ -26,7 +29,7 @@ async function openDetect(page, withRun = false) {
area_runs: [{ area_id: area.id, name: area.name, a, b, status: 'ready' }] };
await page.route('**/api/compare/analyzers', (route) => route.fulfill({ json: {
builtins: [recipe, { ...recipe, id: 'boats', name: 'Vessels', method: 'vessels' }], custom: [],
- methods: [{ id: 'surface', single: false, sizes: {} }, { id: 'vessels', single: true, sizes: {} }],
+ methods: [{ id: 'surface', single: false, sizes: SIZES }, { id: 'vessels', single: true, sizes: {} }],
grid: [13, 512], max_tiles: 4096, max_results: 2000,
} }));
await page.route('**/api/settings/prefs', (route) => {
@@ -105,6 +108,32 @@ test('landing, dock rail and the When step fit the existing map workspace', asyn
expect(errors).toEqual([]);
});
+test('the size is asked before the analyzers, and a pair months apart warns about shadows', async ({ page }) => {
+ const { errors, calls } = await openDetect(page);
+ await page.getByRole('button', { name: 'New detection', exact: true }).click();
+ await page.getByRole('button', { name: 'New one pass', exact: true }).click();
+ await page.getByRole('button', { name: 'North site', exact: true }).click();
+ await page.getByRole('button', { name: 'Next: What' }).click();
+ const step = page.getByRole('region', { name: 'What to look for' });
+ const sizes = step.getByRole('group', { name: 'Target size' });
+ await expect(sizes).toHaveCount(1);
+ await expect(sizes.getByRole('button', { name: 'All', exact: true })).toHaveAttribute('aria-pressed', 'true');
+ const [above, list] = [await sizes.boundingBox(), await step.getByRole('radiogroup', { name: 'Analyzer' }).boundingBox()];
+ expect(above.y + above.height).toBeLessThanOrEqual(list.y);
+ await page.screenshot({ path: test.info().outputPath('detect-what.png') });
+ await page.getByRole('button', { name: 'Next: When' }).click();
+ await page.getByLabel('Day of A').fill('21/01/2026');
+ await expect(page.getByRole('note')).toHaveCount(0);
+ await page.getByRole('radio', { name: 'A day I choose' }).click();
+ await page.getByLabel('Day of B').fill('25/09/2026');
+ await expect(page.getByRole('note')).toContainText('most buildings will read as changed');
+ await page.screenshot({ path: test.info().outputPath('detect-shadows.png') });
+ await page.getByLabel('Day of B').fill('02/02/2026');
+ await expect(page.getByRole('note')).toHaveCount(0);
+ expect(calls).toEqual([]);
+ expect(errors).toEqual([]);
+});
+
test('review adds a manual point and uses the standard pin dialog', async ({ page }) => {
const { errors } = await openDetect(page, true);
await page.getByRole('button', { name: 'Saved', exact: true }).click();
@@ -232,6 +261,14 @@ test('an analyzer of your own is built over the map: its rules painted, a point
await expect.poll(tint([250, 204, 21, 110])).toBe(true);
expect(await layers.evaluate((canvas) => canvas.getContext('2d').getImageData(10, 10, 1, 1).data[3])).toBe(0);
+ // the detections alone, as a run would return them: no rule painted, the candidate still outlined
+ const shows = page.getByRole('group', { name: 'What the map shows' });
+ await shows.getByRole('button', { name: 'Detections', exact: true }).click();
+ await expect.poll(tint([0, 0, 0, 0])).toBe(true);
+ await expect(page.locator('svg.analysis-overlay [role="button"]')).toHaveCount(1);
+ await shows.getByRole('button', { name: 'Rules', exact: true }).click();
+ await expect.poll(tint([250, 204, 21, 110])).toBe(true);
+
const map = page.locator('.detect-tool .map');
const box = await map.boundingBox();
await map.click({ position: { x: box.width / 2 - 40, y: box.height / 2 + 40 } });
diff --git a/frontend/e2e/proof-point-check.spec.js b/frontend/e2e/proof-point-check.spec.js
new file mode 100644
index 0000000..c5146cf
--- /dev/null
+++ b/frontend/e2e/proof-point-check.spec.js
@@ -0,0 +1,93 @@
+import { test, expect } from '@playwright/test';
+import { PANEL_PATH, awaitMapReady, installAppFixture, openProofWithPanel } from './app.fixture.js';
+
+/**
+ * A point taken from a capture, checked before it leaves the composer.
+ *
+ * A capture's point is the middle of its frame unless its pin was moved onto the
+ * target, and a save files it on the case map while a post publishes it. So both
+ * walk it through the map first. Driven in a real browser because the question is
+ * whether the save waits for the analyst, which no unit below the page can see.
+ */
+
+// The fixture's one image, filed as a capture framed on its own middle.
+const framed = {
+ path: PANEL_PATH,
+ provider_label: 'Esri',
+ lat: 48.8584,
+ lon: 2.2945,
+ center_lat: 48.8584,
+ center_lon: 2.2945,
+ zoom: 17,
+ fetched_at: '2026-09-01T10:00:00Z',
+};
+const row = (page) => page.locator('.point-row').first();
+
+test('a save stops on the capture point until it is checked', async ({ page }) => {
+ const fixture = await installAppFixture(page, { satCaptures: [framed] });
+ await openProofWithPanel(page);
+
+ await expect(row(page).locator('.meta-input')).toHaveValue('48.858400, 2.294500');
+ await expect(row(page).locator('.coords-field')).toHaveClass(/proposed/);
+
+ await page.getByRole('button', { name: 'Save proof', exact: true }).click();
+ const check = page.getByRole('dialog', { name: 'Check the point' });
+ await expect(check).toBeVisible();
+ await awaitMapReady(page);
+ expect(fixture.proofSaves).toHaveLength(0);
+
+ // right as proposed: kept where it is, and the save goes through
+ await check.getByRole('button', { name: 'Use this point' }).click();
+ await expect(check).toHaveCount(0);
+ await expect.poll(() => fixture.proofSaves.length).toBe(1);
+ const [{ spec }] = fixture.proofSaves;
+ expect(spec.points).toEqual([{ coords: '48.858400, 2.294500' }]);
+ await expect(row(page).locator('.coords-field')).not.toHaveClass(/proposed/);
+
+ // checked once is checked: the next save asks nothing
+ await page.getByRole('button', { name: 'Save proof', exact: true }).click();
+ await expect.poll(() => fixture.proofSaves.length).toBe(2);
+ await expect(page.getByRole('dialog', { name: 'Check the point' })).toHaveCount(0);
+});
+
+test('Later saves the proof and keeps the point unchecked', async ({ page }) => {
+ const fixture = await installAppFixture(page, { satCaptures: [framed] });
+ await openProofWithPanel(page);
+
+ await page.getByRole('button', { name: 'Save proof', exact: true }).click();
+ await page.getByRole('dialog', { name: 'Check the point' }).getByRole('button', { name: 'Later' }).click();
+
+ await expect.poll(() => fixture.proofSaves.length).toBe(1);
+ const [{ spec }] = fixture.proofSaves;
+ expect(spec.coords).toEqual({ lat: 48.8584, lon: 2.2945, proposed: true });
+ await expect(page.getByText('Unchecked points stay off the case map until you check them.')).toBeVisible();
+ await expect(row(page).locator('.coords-field')).toHaveClass(/proposed/);
+});
+
+test('To Post offers no Later, and Cancel sends nothing', async ({ page }) => {
+ // at 1280px the header runs under the case panel, which covers To Post
+ await page.setViewportSize({ width: 1600, height: 900 });
+ const fixture = await installAppFixture(page, { satCaptures: [framed] });
+ await openProofWithPanel(page);
+
+ await page.getByRole('button', { name: 'To Post' }).click();
+ const check = page.getByRole('dialog', { name: 'Check the point' });
+ await expect(check).toBeVisible();
+ await expect(check.getByRole('button', { name: 'Later' })).toHaveCount(0);
+
+ await check.getByRole('button', { name: 'Cancel' }).click();
+ await expect(check).toHaveCount(0);
+ expect(fixture.proofSaves).toHaveLength(0);
+});
+
+test('a capture aimed with the pin is saved without a question', async ({ page }) => {
+ const fixture = await installAppFixture(page, {
+ satCaptures: [{ ...framed, center_lat: 48.8591, center_lon: 2.2931 }],
+ });
+ await openProofWithPanel(page);
+
+ await expect(row(page).locator('.coords-field')).not.toHaveClass(/proposed/);
+ await page.getByRole('button', { name: 'Save proof', exact: true }).click();
+ await expect.poll(() => fixture.proofSaves.length).toBe(1);
+ expect(fixture.proofSaves[0].spec.coords).toEqual({ lat: 48.8584, lon: 2.2945 });
+});
diff --git a/frontend/e2e/satellite-reference.spec.js b/frontend/e2e/satellite-reference.spec.js
new file mode 100644
index 0000000..2d7a158
--- /dev/null
+++ b/frontend/e2e/satellite-reference.spec.js
@@ -0,0 +1,70 @@
+import { test, expect } from '@playwright/test';
+import { awaitMapReady, installAppFixture, PANEL_PATH } from './app.fixture.js';
+
+/**
+ * The Add reference picker over the real map. A case that ran Detect and
+ * Compare holds more renders than shots, and the shot to geolocate has to stay
+ * one or two clicks away: the working files start held back, a chip is one
+ * press, and the narrowing picked is still there the next time.
+ */
+
+const item = (title, kind, source, path) => ({
+ path: path ?? `media/${title}.${kind === 'video' ? 'mp4' : 'png'}`,
+ filename: `${title}.${kind === 'video' ? 'mp4' : 'png'}`,
+ title,
+ kind,
+ source,
+ thumbnail: null,
+ folder: '',
+});
+
+const MEDIA = [
+ // The one picked below is the fixture's served image, so the window can load it.
+ item('Gate', 'image', { type: 'upload' }, PANEL_PATH),
+ item('Roof', 'image', { type: 'upload' }),
+ item('Checkpoint', 'image', { type: 'clipboard' }),
+ item('Crowd', 'image', { type: 'upload' }),
+ item('Strike', 'video', { type: 'download' }),
+ item('Convoy', 'video', { type: 'download' }),
+ item('Launch', 'video', { type: 'download' }),
+ item('Small change', 'image', { type: 'compare' }),
+ item('Comparison 12', 'image', { type: 'compare' }),
+ item('15.73, 45.02', 'image', { type: 'satellite' }),
+ item('Collage 4', 'image', { type: 'inspect', op: 'collage' }),
+];
+
+test('narrows the reference picker to collected media, one type per click', async ({ page }) => {
+ const fixture = await installAppFixture(page, { media: MEDIA });
+ await page.goto('/#satellite');
+ await awaitMapReady(page);
+
+ const rail = page.getByRole('button', { name: 'Add reference' });
+ const dialog = page.getByRole('dialog', { name: 'Add reference' });
+ const tiles = dialog.locator('.ref-pick');
+ const chip = (name) => dialog.getByRole('button', { name });
+
+ await rail.click();
+ await expect(tiles).toHaveCount(7);
+
+ await chip(/^Videos 3/).click();
+ await expect(tiles).toHaveCount(3);
+ await expect(tiles.first()).toHaveAttribute('title', 'Strike');
+
+ await chip(/^All/).click();
+ await chip('Show 4 working files').click();
+ await expect(tiles).toHaveCount(11);
+ await expect(chip(/^Comparisons 2/)).toBeVisible();
+ await chip('Hide working files').click();
+
+ await chip(/^Images 4/).click();
+ await dialog.locator('.ref-pick[title="Gate"]').click();
+ await expect(dialog).toHaveCount(0);
+ await expect(page.locator('.ref-viewer')).toHaveCount(1);
+
+ // The next reference opens on the same narrowing.
+ await rail.click();
+ await expect(chip(/^Images 4/)).toHaveAttribute('aria-pressed', 'true');
+ await expect(tiles).toHaveCount(4);
+
+ fixture.expectNoUnexpectedRequests();
+});
diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.js
index 9e04ea2..2540066 100644
--- a/frontend/src/lib/api.js
+++ b/frontend/src/lib/api.js
@@ -21,9 +21,15 @@ function detailLine(detail) {
.join('; ');
}
+/** What a failure says when its body gave no reason: a crash on the server
+ * answers with a bare "Internal Server Error". */
+function fallback(status) {
+ return status >= 500 ? `Azimut hit an unexpected error (HTTP ${status}). Settings → System → Report an issue has its log.` : `HTTP ${status}`;
+}
+
class ApiError extends Error {
constructor(status, detail) {
- super(detailLine(detail) || `HTTP ${status}`);
+ super(detailLine(detail) || fallback(status));
this.status = status;
}
}
diff --git a/frontend/src/lib/api.test.js b/frontend/src/lib/api.test.js
index 60d80cf..de6a791 100644
--- a/frontend/src/lib/api.test.js
+++ b/frontend/src/lib/api.test.js
@@ -46,8 +46,13 @@ describe('API errors', () => {
});
it('falls back to the status when the body says nothing usable', async () => {
+ answers(404, { detail: [] });
+ await expect(api.get('/api/x')).rejects.toThrow('HTTP 404');
+ });
+
+ it('says a server crash is one, rather than a bare status', async () => {
answers(500, { detail: [] });
- await expect(api.get('/api/x')).rejects.toThrow('HTTP 500');
+ await expect(api.get('/api/x')).rejects.toThrow('Azimut hit an unexpected error (HTTP 500). Settings → System → Report an issue has its log.');
});
it('carries the status for callers that branch on it', async () => {
diff --git a/frontend/src/lib/composer.js b/frontend/src/lib/composer.js
index 93f9290..1758b6b 100644
--- a/frontend/src/lib/composer.js
+++ b/frontend/src/lib/composer.js
@@ -446,6 +446,32 @@ export function autoCoords(panels) {
return null;
}
+/**
+ * True when the panel `autoCoords` reads was aimed: its point is a pin somebody
+ * put on the target, not the middle of whatever the capture framed.
+ */
+export function autoAimed(panels) {
+ for (const p of panels ?? []) {
+ if (p.meta?.lat != null && p.meta?.lon != null) return p.meta.aimed === true;
+ }
+ return false;
+}
+
+/**
+ * True when a capture's point is a pin moved onto the target before it was taken.
+ *
+ * Otherwise the point is the middle of the frame: the screen's centre, or the
+ * rectangle's, which is only where the analyst stood the camera. A wide capture of
+ * an airbase puts that hundreds of metres from the hangar the proof is about. A
+ * map screenshot the extension filed reads its point off the page address, which is
+ * the page's centre, and records no second point, so it is never aimed.
+ */
+export function captureAimed(s) {
+ if (s?.center_lat == null || s?.center_lon == null || s.lat == null || s.lon == null) return false;
+ return Math.abs(Number(s.lat) - Number(s.center_lat)) > 1e-6
+ || Math.abs(Number(s.lon) - Number(s.center_lon)) > 1e-6;
+}
+
/**
* A {lat, lon} rendered in the reader's coordinate format, or '' when null.
* Defaults to decimal degrees so this stays a pure function — components pass
@@ -608,6 +634,7 @@ export function specPoints(p) {
coords: String(one.coords ?? '').trim(),
label: String(one.label ?? '').trim(),
pov: one.pov === true,
+ ...(one.proposed === true ? { proposed: true } : {}),
}))
.filter((one) => one.coords)
: [];
@@ -638,12 +665,14 @@ export function statePoints(spec, points) {
coords: String(one?.coords ?? '').trim(),
label: String(one?.label ?? '').trim(),
pov: one?.pov === true,
+ proposed: one?.proposed === true,
}))
.filter((one) => one.coords)
.map((one) => ({
coords: one.coords,
...(one.label ? { label: one.label } : {}),
...(one.pov ? { pov: true } : {}),
+ ...(one.proposed ? { proposed: true } : {}),
}));
spec.points = stated;
spec.coordsText = stated[0]?.coords ?? '';
@@ -668,12 +697,17 @@ export function statePoints(spec, points) {
* alone: that panel *is* the answer, and the field reads it off the panels as it
* always has.
*
+ * Both rows keep saying whether anyone checked them: the new one is proposed
+ * unless its capture was aimed, and the answer written down stays as proposed as
+ * it was while the field read it.
+ *
* @param {Array} points the rows as edited, at least one
* @param {object} panel the panel that just landed
* @param {string} answered what the proof answered with before it did
* @param {string} format the reader's coordinate format
+ * @param {boolean} answeredProposed whether that answer was the panels' unchecked one
*/
-export function statePanelPoint(points, panel, answered, format = 'dd') {
+export function statePanelPoint(points, panel, answered, format = 'dd', answeredProposed = false) {
const { lat, lon } = panel?.meta ?? {};
if (lat == null || lon == null) return points;
const text = formatCoords({ lat: Number(lat), lon: Number(lon) }, format);
@@ -686,12 +720,35 @@ export function statePanelPoint(points, panel, answered, format = 'dd') {
if ((stated.length ? stated : [answered]).includes(text)) return points;
return [
...rows.map((one, at) =>
- at === 0 && !String(one.coords ?? '').trim() ? { ...one, coords: answered } : one
+ at === 0 && !String(one.coords ?? '').trim()
+ ? { ...one, coords: answered, ...(answeredProposed ? { proposed: true } : {}) }
+ : one
),
- { coords: text, label: '', pov: false },
+ { coords: text, label: '', pov: false, ...(panel.meta.aimed === true ? {} : { proposed: true }) },
];
}
+/**
+ * True when row `i` holds a point nobody checked: one the imagery proposed.
+ *
+ * A first row with no text reads the panels, so it is proposed exactly when there
+ * is a panel answer and its capture was not aimed. Any other row says so itself,
+ * and typing coordinates or placing them on the map is what clears it.
+ */
+export function pointProposed(points, i, panels) {
+ const row = points?.[i];
+ if (!row) return false;
+ if (i === 0 && !String(row.coords ?? '').trim()) {
+ return autoCoords(panels) != null && !autoAimed(panels);
+ }
+ return row.proposed === true && Boolean(String(row.coords ?? '').trim());
+}
+
+/** The rows a save or a post has to have checked first, in the order they show. */
+export function uncheckedPoints(points, panels) {
+ return (points ?? []).map((_, i) => i).filter((i) => pointProposed(points, i, panels));
+}
+
/** Effective coordinates text for a proof/spec: what it concludes on, else auto. */
export function proofCoordsText(p, format = 'dd') {
const stated = specPoints(p)[0]?.coords;
@@ -1117,6 +1174,12 @@ function surfaceGeometry(surface) {
return { ...(crop ? { crop } : {}), ...(rotation ? { rotation } : {}) };
}
+/** What the panels answer with, frozen for the spec, marked when nobody aimed it. */
+function frozenCoords(panels) {
+ const auto = autoCoords(panels);
+ return auto && !autoAimed(panels) ? { ...auto, proposed: true } : auto;
+}
+
/** Serializable spec from runtime state (drops live image objects). */
export function toSpec(proof) {
return {
@@ -1125,7 +1188,10 @@ export function toSpec(proof) {
// A proof keeps the selected house-style identity as well as its copied
// style values, so reopening it can restore the template picker.
templateId: typeof proof.templateId === 'string' ? proof.templateId : null,
- coords: autoCoords(proof.panels), // auto geo (first geo panel), for reference
+ // auto geo (first geo panel), for reference. A first row left empty is stated by
+ // this, so it carries whether anyone checked it, or the save would file the
+ // middle of a capture as the proof's conclusion.
+ coords: frozenCoords(proof.panels),
// The points the proof concludes on, and the mirror of the first for a build
// that predates the list. Whether a point is where the camera stood rather
// than what it filmed rides on the point itself: the proof cannot deduce it —
@@ -1372,7 +1438,7 @@ export function satPanelInput(s, format = 'dd') {
src: s.path,
meta: {
kind: 'satellite', attribution: s.attribution, lat: s.lat, lon: s.lon,
- zoom: s.zoom, provider: s.provider_label,
+ aimed: captureAimed(s), zoom: s.zoom, provider: s.provider_label,
date: s.fetched_at?.slice(0, 10), imagery_date: s.imagery_date ?? null,
},
caption: parts.join(' · '),
diff --git a/frontend/src/lib/composer.test.js b/frontend/src/lib/composer.test.js
index 80f722e..9c046bf 100644
--- a/frontend/src/lib/composer.test.js
+++ b/frontend/src/lib/composer.test.js
@@ -22,6 +22,7 @@ import {
newPaste, pasteBoxes, pasteInsertScale, clampPasteScale, clampPaste,
surfaces, surfaceHitTest, PASTE_SCALE_MAX, PASTE_SHARE,
specPoints, statePoints, statePanelPoint, MAX_POINTS,
+ captureAimed, pointProposed, uncheckedPoints,
proofCoordsLines, coordsPlateLines, coordsPostLines,
footerLines, footerBand,
} from './composer.js';
@@ -818,7 +819,10 @@ describe('toSpec — coordinates + source persistence', () => {
shapes: [],
};
const spec = toSpec(proof);
- expect(spec.coords).toEqual({ lat: 3, lon: 4 });
+ // the middle of a capture nobody aimed: the save must not file it as checked
+ expect(spec.coords).toEqual({ lat: 3, lon: 4, proposed: true });
+ const aimed = { ...proof, panels: [{ ...proof.panels[0], meta: { lat: 3, lon: 4, aimed: true } }] };
+ expect(toSpec(aimed).coords).toEqual({ lat: 3, lon: 4 });
expect(spec.points).toEqual([]); // nothing stated: the panels answer for it
expect(spec.coordsText).toBe('');
expect(spec.sources).toBeNull();
@@ -1917,15 +1921,25 @@ describe('a panel that carries a place', () => {
// the next panel would take its place without saying so
expect(statePanelPoint(blank, panel(48.8738, 2.295), '48.858400, 2.294500')).toEqual([
{ coords: '48.858400, 2.294500', label: '', pov: false },
- { coords: '48.873800, 2.295000', label: '', pov: false },
+ { coords: '48.873800, 2.295000', label: '', pov: false, proposed: true },
]);
});
+ it('keeps both points as checked, or not, as they were', () => {
+ // the answer written down was the panels' unchecked one, and stays so
+ const [first] = statePanelPoint(blank, panel(48.8738, 2.295), '48.858400, 2.294500', 'dd', true);
+ expect(first.proposed).toBe(true);
+ // a capture aimed with the pin is the analyst's own point
+ const aimed = { ...panel(48.8738, 2.295), meta: { ...panel(48.8738, 2.295).meta, aimed: true } };
+ const [, added] = statePanelPoint(blank, aimed, '48.858400, 2.294500');
+ expect(added).toEqual({ coords: '48.873800, 2.295000', label: '', pov: false });
+ });
+
it('leaves a stated conclusion where it is', () => {
const stated = [{ coords: 'the camera', label: 'pov', pov: true }];
expect(statePanelPoint(stated, panel(1, 2), 'the camera')).toEqual([
{ coords: 'the camera', label: 'pov', pov: true },
- { coords: '1.000000, 2.000000', label: '', pov: false },
+ { coords: '1.000000, 2.000000', label: '', pov: false, proposed: true },
]);
});
@@ -1953,6 +1967,51 @@ describe('a panel that carries a place', () => {
});
});
+describe('a point nobody checked', () => {
+ const capture = (meta) => [{ id: 'p1', src: 'a.png', meta: { kind: 'satellite', lat: 1, lon: 2, ...meta } }];
+
+ it('is a capture framed on its middle, not one aimed with the pin', () => {
+ const at = { lat: 48.8584, lon: 2.2945 };
+ expect(captureAimed({ ...at, center_lat: 48.8584, center_lon: 2.2945 })).toBe(false);
+ expect(captureAimed({ ...at, center_lat: 48.8591, center_lon: 2.2945 })).toBe(true);
+ // a map screenshot the extension filed records no second point
+ expect(captureAimed(at)).toBe(false);
+ expect(satPanelInput({ ...at, center_lat: 48.8591, center_lon: 2.2945 }).meta.aimed).toBe(true);
+ expect(satPanelInput({ ...at, center_lat: 48.8584, center_lon: 2.2945 }).meta.aimed).toBe(false);
+ });
+
+ it('is the first row while it reads an unaimed capture', () => {
+ const blank = [{ coords: '', label: '', pov: false }];
+ expect(pointProposed(blank, 0, capture({}))).toBe(true);
+ expect(pointProposed(blank, 0, capture({ aimed: true }))).toBe(false);
+ // no panel answers: there is nothing to check, only a blank to fill
+ expect(pointProposed(blank, 0, [])).toBe(false);
+ expect(pointProposed([{ coords: '1, 2', label: '', pov: false }], 0, capture({}))).toBe(false);
+ });
+
+ it('is any other row that says so, until it is typed or placed', () => {
+ const rows = [
+ { coords: '1, 2', label: '', pov: false },
+ { coords: '3, 4', label: '', pov: false, proposed: true },
+ { coords: '5, 6', label: '', pov: false, proposed: false },
+ ];
+ expect(uncheckedPoints(rows, [])).toEqual([1]);
+ expect(uncheckedPoints([{ coords: '', label: '', pov: false }, rows[1]], capture({}))).toEqual([0, 1]);
+ });
+
+ it('is written down as such, and read back', () => {
+ const spec = statePoints({}, [
+ { coords: '1, 2', label: '', pov: false },
+ { coords: '3, 4', label: '', pov: false, proposed: true },
+ ]);
+ expect(spec.points).toEqual([{ coords: '1, 2' }, { coords: '3, 4', proposed: true }]);
+ expect(specPoints(spec)).toEqual([
+ { coords: '1, 2', label: '', pov: false },
+ { coords: '3, 4', label: '', pov: false, proposed: true },
+ ]);
+ });
+});
+
describe('the coordinates a plate prints', () => {
const lines = [
{ coords: '64.1466, -21.9426', label: '' },
diff --git a/frontend/src/lib/map/acquisitions.js b/frontend/src/lib/map/acquisitions.js
index d43cffd..ae8d213 100644
--- a/frontend/src/lib/map/acquisitions.js
+++ b/frontend/src/lib/map/acquisitions.js
@@ -14,13 +14,56 @@
import { daysBefore, isoDay } from '../sentinel.js';
-/** How far back to look. A month is several passes; a year is a last resort. */
+/**
+ * How far back to look. A month is several passes, a year the most one preset
+ * reaches; anything older is two days picked in the calendar, `{ start, end }`.
+ */
export const LOOKBACK_WINDOWS = Object.freeze([
{ id: 30, label: '30 days' },
{ id: 90, label: '90 days' },
{ id: 365, label: '1 year' },
]);
+/** The day each collection's first satellite was launched: no pass is older. */
+export const MISSION_START = Object.freeze({ sentinel2: '2015-06-23', sentinel1: '2014-04-03' });
+
+/** The days a lookback asks about: a number of days up to today, or two picked days. */
+export function lookupSpan(lookback, now = new Date()) {
+ return typeof lookback === 'number'
+ ? { start: daysBefore(lookback, now), end: isoDay(now) }
+ : { start: lookback?.start ?? '', end: lookback?.end ?? '' };
+}
+
+/** What stops two picked days from being looked up, or '' when nothing does. */
+export function spanProblem(lookback) {
+ if (typeof lookback === 'number') return '';
+ if (!lookback?.start || !lookback?.end) return 'Pick the first and the last day.';
+ return lookback.start > lookback.end ? 'The first day comes after the last.' : '';
+}
+
+/**
+ * Where to look for what a list stopped short of, or null when nothing is left.
+ *
+ * The catalogue answers newest first, so what a cut list lacks is older than its
+ * last row. The same start, then, up to that row's day, which is asked again
+ * because the cut may have fallen among its granules.
+ */
+export function olderSpan(lookback, list, now = new Date()) {
+ const oldest = list?.at(-1)?.date;
+ const { start } = lookupSpan(lookback, now);
+ return oldest && start && oldest > start ? { start, end: oldest } : null;
+}
+
+/**
+ * A list with the older passes found after it, newest first and each pass once.
+ * The older lookup's copy of the day they share wins: it read all of its granules.
+ */
+export function withOlder(list, older) {
+ const passes = new Map((list ?? []).map((entry) => [passKey(entry), entry]));
+ for (const entry of older ?? []) passes.set(passKey(entry), entry);
+ return [...passes.values()].sort((x, y) => passKey(y).localeCompare(passKey(x)));
+}
+
/**
* Coverage at or above this counts as covering the whole area. Not 1.0 because
* the backend measures it by sampling, and a ring's own edge lands a point or
@@ -30,11 +73,10 @@ export const LOOKBACK_WINDOWS = Object.freeze([
export const FULL_COVER = 0.98;
/** The request body for a lookup over the areas currently drawn. */
-export function acquisitionQuery(zones, days, now = new Date(), collection = 'sentinel2') {
+export function acquisitionQuery(zones, lookback, now = new Date(), collection = 'sentinel2') {
return {
zones: zones.map(({ id, name, kind, points }) => ({ id, name, kind, points })),
- start: daysBefore(days, now),
- end: isoDay(now),
+ ...lookupSpan(lookback, now),
collection,
};
}
diff --git a/frontend/src/lib/map/acquisitions.test.js b/frontend/src/lib/map/acquisitions.test.js
index 1cb5ba2..844ad87 100644
--- a/frontend/src/lib/map/acquisitions.test.js
+++ b/frontend/src/lib/map/acquisitions.test.js
@@ -7,7 +7,11 @@ import {
coverClass,
coverLabel,
coverageWarning,
+ lookupSpan,
+ olderSpan,
+ spanProblem,
sweptNote,
+ withOlder,
} from './acquisitions.js';
const zone = (id) => ({
@@ -29,6 +33,39 @@ describe('acquisitions over drawn areas', () => {
expect(Object.keys(query.zones[0]).sort()).toEqual(['id', 'kind', 'name', 'points']);
});
+ it('asks about two days picked in the calendar as they are', () => {
+ const query = acquisitionQuery([zone('a')], { start: '2019-03-01', end: '2019-06-30' }, undefined, 'sentinel1');
+ expect([query.start, query.end, query.collection]).toEqual(['2019-03-01', '2019-06-30', 'sentinel1']);
+ expect(lookupSpan(90, new Date('2026-05-31T09:00:00Z'))).toEqual({ start: '2026-03-02', end: '2026-05-31' });
+ });
+
+ it('needs both days, in order, and nothing of a preset', () => {
+ expect(spanProblem(30)).toBe('');
+ expect(spanProblem({ start: '2019-03-01', end: '' })).toBe('Pick the first and the last day.');
+ expect(spanProblem({ start: '2019-06-30', end: '2019-03-01' })).toBe('The first day comes after the last.');
+ expect(spanProblem({ start: '2019-03-01', end: '2019-03-01' })).toBe('');
+ });
+
+ it('looks for what a cut list lacks before its oldest pass, that day included', () => {
+ const list = [{ date: '2026-05-11' }, { date: '2026-02-03' }];
+ expect(olderSpan({ start: '2025-01-01', end: '2026-05-31' }, list)).toEqual({ start: '2025-01-01', end: '2026-02-03' });
+ expect(olderSpan(365, list, new Date('2026-05-31T09:00:00Z'))).toEqual({ start: '2025-05-31', end: '2026-02-03' });
+ // the list already reaches the first day asked, or there is no list
+ expect(olderSpan({ start: '2026-02-03', end: '2026-05-31' }, list)).toBe(null);
+ expect(olderSpan(365, [])).toBe(null);
+ });
+
+ it('adds the older passes under the list, each pass once and the fuller copy kept', () => {
+ const cut = { date: '2026-02-03', coverage: 0.4 };
+ const whole = { date: '2026-02-03', coverage: 1 };
+ const merged = withOlder([{ date: '2026-05-11' }, cut], [whole, { date: '2026-01-29' }]);
+ expect(merged.map((entry) => entry.date)).toEqual(['2026-05-11', '2026-02-03', '2026-01-29']);
+ expect(merged[1]).toBe(whole);
+ // a radar day holds two passes, told apart by their time
+ const radar = withOlder([{ date: '2026-05-14', time: '17:33:02' }], [{ date: '2026-05-14', time: '05:42:10' }]);
+ expect(radar.map((entry) => entry.time)).toEqual(['17:33:02', '05:42:10']);
+ });
+
it('drops nothing a stray editor field added to a zone', () => {
const query = acquisitionQuery([{ ...zone('a'), selected: true, colour: '#fff' }], 30);
expect(query.zones[0].selected).toBeUndefined();
diff --git a/frontend/src/lib/map/analyzerRules.js b/frontend/src/lib/map/analyzerRules.js
index e81c2ad..bb2fd56 100644
--- a/frontend/src/lib/map/analyzerRules.js
+++ b/frontend/src/lib/map/analyzerRules.js
@@ -351,12 +351,12 @@ export const DEFAULT_PARAMETERS = Object.freeze({
sar_ground: 'any', ignore_clouds: true, ignore_shadows: true, cloud_margin: 5, merge_metres: 0, shape: 'any',
});
-/** A new analyzer of your own: one change rule, at the medium size. */
+/** A new analyzer of your own: one change rule, at All sizes like every built-in. */
export function newRecipe(methods = []) {
const sizes = methods.find((entry) => entry.id === 'rules')?.sizes;
return {
id: 'custom', name: '', description: '', phenomenon: 'Candidate', method: 'rules',
- parameters: { ...DEFAULT_PARAMETERS, ...(sizes?.medium ?? {}) },
+ parameters: { ...DEFAULT_PARAMETERS, ...(sizes?.all ?? {}) },
colour: '#f6a81a', style: 'both', rules: [newRule('index', 'change')], match: 'all', checks: [],
};
}
diff --git a/frontend/src/lib/map/analyzerRules.test.js b/frontend/src/lib/map/analyzerRules.test.js
index 435e11e..f6504f8 100644
--- a/frontend/src/lib/map/analyzerRules.test.js
+++ b/frontend/src/lib/map/analyzerRules.test.js
@@ -10,7 +10,7 @@ import { changeSettings } from './changeAssist.js';
import { toMercator } from './groundFrame.js';
const METHODS = [
- { id: 'rules', single: false, clouds: true, sensor: 'sentinel2', frames: 4, sizes: { medium: { min_area: 2000, cleanup: 1 } }, rules: true },
+ { id: 'rules', single: false, clouds: true, sensor: 'sentinel2', frames: 4, sizes: { medium: { min_area: 2000, cleanup: 1 }, all: { min_area: 0, cleanup: 0 } }, rules: true },
{ id: 'sar-change', single: false, clouds: false, sensor: 'sentinel1', frames: 4, sizes: { medium: { smoothing: 2 } }, smoothing_m: 45 },
{ id: 'vessels', single: true, clouds: true, sensor: 'sentinel2', frames: 2 },
];
diff --git a/frontend/src/lib/map/detectWhen.js b/frontend/src/lib/map/detectWhen.js
index 6db7b2a..69453c4 100644
--- a/frontend/src/lib/map/detectWhen.js
+++ b/frontend/src/lib/map/detectWhen.js
@@ -9,6 +9,12 @@
* A is the picture before, B the one to look in. An empty B date is the
* newest pass, looked up when the run starts; a routine never holds one.
*/
+import { sunPosition } from './changeDetect.js';
+import { zoneRing } from './analyzers.js';
+
+/** How much a 10 m building's shadow may change length between two passes,
+ * in metres, before it reads as a change: half a Sentinel-2 pixel. */
+export const SHADOW_SHIFT_M = 5;
/** A side as a line: its day, and a radar pass's time. */
export function sideLine(source, radar = false) {
@@ -90,3 +96,35 @@ export function whenSummary({ single, routine, against, pairs, radar = false })
if (single) return b.charAt(0).toUpperCase() + b.slice(1);
return `${a || 'A not chosen'} → ${b}`;
}
+
+/** A 10 m building's shadow when Sentinel-2 passes on `day`, in metres. */
+export function shadowLength(day, lat) {
+ const zenith = Math.min(85, sunPosition(day, lat).zenith);
+ return 10 * Math.tan((zenith * Math.PI) / 180);
+}
+
+/**
+ * A pair whose passes see the sun at very different heights, as a warning, or ''.
+ *
+ * Every building's shadow then changes length between A and B and reads as a
+ * change: a January and a September pass over an airbase put a candidate on
+ * most of its buildings. Only a picture has shadows, and only a pair of days
+ * both chosen can be judged.
+ */
+export function shadowWarning(pairs, zones, { single = false, radar = false } = {}) {
+ if (single || radar) return '';
+ let worst = null;
+ for (const pair of pairs ?? []) {
+ const zone = (zones ?? []).find((entry) => entry.id === pair.area_id);
+ if (!zone || !pair.a?.date || !pair.b?.date) continue;
+ const ring = zoneRing(zone);
+ const lat = ring.reduce((sum, point) => sum + point[1], 0) / ring.length;
+ const a = shadowLength(pair.a.date, lat);
+ const b = shadowLength(pair.b.date, lat);
+ if (!worst || Math.abs(a - b) > Math.abs(worst.a - worst.b)) worst = { a, b, pair };
+ }
+ if (!worst || Math.abs(worst.a - worst.b) < SHADOW_SHIFT_M) return '';
+ return `A 10 m building casts ${Math.round(worst.a)} m of shadow on ${worst.pair.a.date} and `
+ + `${Math.round(worst.b)} m on ${worst.pair.b.date}, so most buildings will read as changed. `
+ + 'Passes closer together avoid it.';
+}
diff --git a/frontend/src/lib/map/detectWhen.test.js b/frontend/src/lib/map/detectWhen.test.js
index 171a112..cce27a2 100644
--- a/frontend/src/lib/map/detectWhen.test.js
+++ b/frontend/src/lib/map/detectWhen.test.js
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
- areaLine, setSide, sharedSide, sideLine, uniform, whenNeed, whenSummary, withRule,
+ areaLine, setSide, shadowLength, shadowWarning, sharedSide, sideLine, uniform, whenNeed, whenSummary, withRule,
} from './detectWhen.js';
const pair = (id, a = '', b = '', extra = {}) => ({
@@ -98,3 +98,39 @@ describe('the When step of a detection', () => {
expect(whenSummary({ ...once, radar: true, pairs: radar })).toBe('2026-08-01 16:32 UTC → newest pass');
});
});
+
+describe('the shadow warning', () => {
+ // The Isfahan airbase, where a January and a September pass put a candidate
+ // on most buildings.
+ const airbase = { id: 'base', kind: 'rect', points: [[51.81, 32.72], [51.96, 32.82]] };
+
+ it('works the shadow out from the sun at the pass, as the engine does', () => {
+ expect(shadowLength('2026-01-21', 32.77)).toBeCloseTo(14.7, 0);
+ expect(shadowLength('2026-09-25', 32.77)).toBeCloseTo(7.2, 0);
+ });
+
+ it('warns when the shadows of a pair differ by half a pixel or more', () => {
+ const text = shadowWarning([pair('base', '2026-01-21', '2026-09-25')], [airbase]);
+ expect(text).toBe('A 10 m building casts 15 m of shadow on 2026-01-21 and 7 m on 2026-09-25, '
+ + 'so most buildings will read as changed. Passes closer together avoid it.');
+ expect(shadowWarning([pair('base', '2026-01-16', '2026-01-21')], [airbase])).toBe('');
+ });
+
+ it('names the worst of several areas', () => {
+ const other = { ...airbase, id: 'other' };
+ const text = shadowWarning([pair('base', '2026-01-16', '2026-01-21'), pair('other', '2026-06-21', '2026-12-21')],
+ [airbase, other]);
+ expect(text).toContain('on 2026-06-21');
+ });
+
+ it('says nothing without two chosen days, on one image, or on radar', () => {
+ const far = [pair('base', '2026-01-21', '2026-09-25')];
+ expect(shadowWarning([pair('base', '2026-01-21', '')], [airbase])).toBe('');
+ expect(shadowWarning(far, [airbase], { single: true })).toBe('');
+ expect(shadowWarning(far, [airbase], { radar: true })).toBe('');
+ });
+
+ it('stays finite where the sun barely rises', () => {
+ expect(Number.isFinite(shadowLength('2026-12-21', 68))).toBe(true);
+ });
+});
diff --git a/frontend/src/lib/mediaFilter.js b/frontend/src/lib/mediaFilter.js
index a41f29a..77c1505 100644
--- a/frontend/src/lib/mediaFilter.js
+++ b/frontend/src/lib/mediaFilter.js
@@ -31,9 +31,15 @@ export function isSatelliteMedia(item) {
(source.type === 'screenshot' && source.imagery_mode === 'satellite');
}
-/** Images that are not already classified as satellite captures. */
+/** A Compare render or a kept Detect finding: before/after pictures the app drew. */
+export function isComparison(item) {
+ return item?.source?.type === 'compare';
+}
+
+/** Images that are neither satellite captures nor comparisons, as the server's
+ * `image` facet counts them. */
export function isGenericImage(item) {
- return item?.kind === 'image' && !isSatelliteMedia(item);
+ return item?.kind === 'image' && !isSatelliteMedia(item) && !isComparison(item);
}
/** How material the analyst brought in by hand arrives: dropped or picked off a
@@ -52,11 +58,11 @@ export function isBroughtIn(item) {
* where the two and the reason they differ by a capture are written down. The server
* filters on the same set, and this is the in-memory pass a case small enough for one
* page takes instead. */
-const MADE_HERE = new Set(['inspect', 'satellite', 'screenshot']);
+const MADE_HERE = new Set(['inspect', 'satellite', 'screenshot', 'compare']);
/** Whether the app produced this file rather than the analyst gathering it: an
* extracted frame, an adjustment, a collage, a capture drawn out of tiles, a map
- * the extension grabbed off the screen.
+ * the extension grabbed off the screen, a Compare render or a kept Detect finding.
*
* Reads **how the file entered the case**, not everything true about it. Bytes
* imported first and later found identical to a frame keep `upload`, because that
@@ -66,6 +72,21 @@ export function isMadeHere(item) {
return MADE_HERE.has(item?.source?.type);
}
+/** The type and source facets, shared by the Media Library's filter and the
+ * Satellite reference picker's chips. They overlap on purpose: a downloaded
+ * video is both a Video and a Download. Keys and order are the server's
+ * `_MEDIA_CATEGORIES`, and `_MEDIA_CATEGORY_SQL` counts the same facets. */
+export const MEDIA_CATEGORIES = [
+ { key: 'image', label: 'Images', icon: 'image', match: isGenericImage },
+ { key: 'video', label: 'Videos', icon: 'video', match: (i) => i.kind === 'video' },
+ { key: 'collage', label: 'Collages', icon: 'layers', match: (i) => i.source?.op === 'collage' },
+ { key: 'satellite', label: 'Satellite', icon: 'satellite', match: isSatelliteMedia },
+ { key: 'comparison', label: 'Comparisons', icon: 'compare', match: isComparison },
+ { key: 'upload', label: 'Imports', icon: 'upload', match: isBroughtIn },
+ { key: 'download', label: 'Downloads', icon: 'download', match: (i) => i.source?.type === 'download' },
+ { key: 'other', label: 'Other files', icon: 'file', match: (i) => i.kind !== 'image' && i.kind !== 'video' },
+];
+
/** User-facing kind label for the Media Library card. */
export function mediaDisplayKind(item) {
return isSatelliteMedia(item) ? 'satellite' : item?.kind;
diff --git a/frontend/src/lib/mediaFilter.test.js b/frontend/src/lib/mediaFilter.test.js
index d51eeb6..17eb04c 100644
--- a/frontend/src/lib/mediaFilter.test.js
+++ b/frontend/src/lib/mediaFilter.test.js
@@ -1,9 +1,12 @@
+import { readFileSync } from 'node:fs';
import { describe, it, expect } from 'vitest';
import {
hasMediaForFilters,
+ isComparison,
isGenericImage,
isBroughtIn,
isMadeHere,
+ MEDIA_CATEGORIES,
isSatelliteMedia,
mediaDisplayKind,
matchesQuery,
@@ -87,6 +90,48 @@ describe('media categories', () => {
mediaDisplayKind({ kind: 'image', source: { type: 'screenshot', imagery_mode: 'satellite' } })
).toBe('satellite');
});
+
+ it('files a Compare render or a kept Detect finding under Comparisons, not Images', () => {
+ const render = { kind: 'image', source: { type: 'compare' } };
+ expect(isComparison(render)).toBe(true);
+ expect(isGenericImage(render)).toBe(false);
+ expect(isComparison({ kind: 'image', source: { type: 'upload' } })).toBe(false);
+ });
+});
+
+describe('the shared facet list', () => {
+ // Read off the server's own source: the Media Library asks it for these facets
+ // on a large case and counts them itself on a small one, and the reference
+ // picker counts them again, so a facet added on one side has to exist on both.
+ const read = (rel) => readFileSync(new URL(rel, import.meta.url), 'utf8');
+ const quoted = (text) => [...text.matchAll(/"([a-z_]+)"/g)].map((m) => m[1]);
+
+ it('has the server categories, in the server order', () => {
+ const rows = read('../../../src/azimut/store/rows.py');
+ const tuple = rows.match(/^_MEDIA_CATEGORIES = \(([^)]*)\)/m)[1];
+ expect(MEDIA_CATEGORIES.map((c) => c.key)).toEqual(quoted(tuple));
+ });
+
+ it('holds back every source the server calls produced here', () => {
+ const links = read('../../../src/azimut/engine/links.py');
+ const types = [
+ ...quoted(links.match(/^MADE_HERE: .* = \(([^)]*)\)/m)[1]),
+ ...quoted(links.match(/^PRODUCED_HERE: .* = \(([^)]*)\)/m)[1]),
+ ];
+ expect(types).toContain('compare');
+ for (const type of types) expect(isMadeHere({ source: { type } }), type).toBe(true);
+ });
+
+ it('gives each item every facet it matches, since the facets overlap', () => {
+ const facets = (it) => MEDIA_CATEGORIES.filter((c) => c.match(it)).map((c) => c.key);
+ expect(facets({ kind: 'video', source: { type: 'download' } })).toEqual(['video', 'download']);
+ expect(facets({ kind: 'image', source: { type: 'upload' } })).toEqual(['image', 'upload']);
+ expect(facets({ kind: 'image', source: { type: 'inspect', op: 'collage' } })).toEqual([
+ 'image',
+ 'collage',
+ ]);
+ expect(facets({ kind: 'document', source: { type: 'upload' } })).toEqual(['upload', 'other']);
+ });
});
describe('sortItems', () => {
@@ -240,6 +285,8 @@ describe('what the case made, apart from what it collected', () => {
// extension's window: a map view grabbed on purpose.
expect(isMadeHere(capture)).toBe(true);
expect(isMadeHere(grabbed)).toBe(true);
+ // A Compare render and a kept Detect finding: before/after the app drew.
+ expect(isMadeHere(item({ source: { type: 'compare' } }))).toBe(true);
expect(isMadeHere(upload)).toBe(false);
expect(isMadeHere(item())).toBe(false);
expect(isMadeHere(null)).toBe(false);
diff --git a/frontend/src/tools/MediaLibrary.svelte b/frontend/src/tools/MediaLibrary.svelte
index b1db0e5..0c4e9b2 100644
--- a/frontend/src/tools/MediaLibrary.svelte
+++ b/frontend/src/tools/MediaLibrary.svelte
@@ -8,13 +8,11 @@
import { caseState, uiState, ensureCase, reloadCase, toast } from '../lib/state.svelte.js';
import {
hasMediaForFilters,
- isBroughtIn,
- isGenericImage,
isMadeHere,
- isSatelliteMedia,
mediaDisplayKind,
mediaPoint,
visibleMedia,
+ MEDIA_CATEGORIES as CATEGORIES,
SORTS,
} from '../lib/mediaFilter.js';
import { listenForPaste, pasteImage, resolvePaste } from '../lib/clipboardPaste.js';
@@ -86,16 +84,8 @@
// --- category facets (auto-derived from kind + source) ---
// Overlapping filters (a downloaded video matches both Videos and Downloads);
- // clicking one narrows the grid to that facet. Order matches the sidebar bar.
- const CATEGORIES = [
- { key: 'image', label: 'Images', icon: 'image', match: isGenericImage },
- { key: 'video', label: 'Videos', icon: 'video', match: (i) => i.kind === 'video' },
- { key: 'collage', label: 'Collages', icon: 'layers', match: (i) => i.source?.op === 'collage' },
- { key: 'satellite', label: 'Satellite', icon: 'satellite', match: isSatelliteMedia },
- { key: 'upload', label: 'Imports', icon: 'upload', match: isBroughtIn },
- { key: 'download', label: 'Downloads', icon: 'download', match: (i) => i.source?.type === 'download' },
- { key: 'other', label: 'Other files', icon: 'file', match: (i) => i.kind !== 'image' && i.kind !== 'video' },
- ];
+ // picking one narrows the grid to that facet. The list is shared with the
+ // Satellite reference picker (MEDIA_CATEGORIES), so the two can't drift.
let catFilter = $state(null); // null = All types
diff --git a/frontend/src/tools/MediaLibrary.test.js b/frontend/src/tools/MediaLibrary.test.js
index 25f64d8..dfa0b23 100644
--- a/frontend/src/tools/MediaLibrary.test.js
+++ b/frontend/src/tools/MediaLibrary.test.js
@@ -239,9 +239,10 @@ describe('Media Library search empty state', () => {
});
describe('Media Library browse controls', () => {
- it('separates satellite captures from generic Images', () => {
- expect(source).toContain("match: isGenericImage");
- expect(source).toContain("match: isSatelliteMedia");
+ it('filters on the shared facet list, which separates satellite captures from Images', () => {
+ // The facets themselves are tested in lib/mediaFilter.test.js.
+ expect(source).toContain('MEDIA_CATEGORIES as CATEGORIES');
+ expect(source).not.toContain('const CATEGORIES = [');
expect(source).toContain('mediaDisplayKind(item)');
});
diff --git a/frontend/src/tools/ProofComposer.svelte b/frontend/src/tools/ProofComposer.svelte
index 700b17a..959db59 100644
--- a/frontend/src/tools/ProofComposer.svelte
+++ b/frontend/src/tools/ProofComposer.svelte
@@ -38,7 +38,7 @@
layoutPanels, panelsBottom, panelScale, freeNormalizeDelta, legendLineHeight, footerBand,
attributionLine, docSize, offsetShape, autoLayoutRows,
autoCoords, formatCoords, autoSourceUrls, proofSource, statedSources, openableSource,
- specPoints, statePanelPoint, footerLines, coordsPostLines, proofCoordsLines, MAX_POINTS,
+ specPoints, statePanelPoint, pointProposed, uncheckedPoints, footerLines, coordsPostLines, proofCoordsLines, MAX_POINTS,
normalizeMaterial, resolveSourceUrls,
toSpec, newId, loadImage, orderedFeatureColors, notesFromShapes,
templateFromProof, applyProofStyle, normalizeProofStyle, newSignatureText,
@@ -1071,11 +1071,12 @@
}, img);
// what the proof answers with today, read before the panel can change it
const answered = displayedCoords;
+ const answeredProposed = pointProposed(proof.points, 0, proof.panels);
// grid: append (rightmost / bottom row); free: a new panel lands in front
if (proof.layout === 'free') proof.panels.unshift(panel);
else proof.panels.push(panel);
// a panel that carries a place states it, under the point already there
- proof.points = statePanelPoint(proof.points, panel, answered, prefs.coordFormat);
+ proof.points = statePanelPoint(proof.points, panel, answered, prefs.coordFormat, answeredProposed);
dirty = true;
requestAnimationFrame(fit);
} catch (e) {
@@ -3574,7 +3575,7 @@
if (!proofHasContent || exporting || saving) return;
exporting = true;
try {
- if (dirty || !savedName) await save();
+ if (dirty || !savedName) await save({ then: exportProof });
// A failed save leaves the proof dirty; a title collision opens the
// overwrite prompt without binding a name. In either case there is no
// confirmed PNG to copy yet.
@@ -3732,8 +3733,34 @@
}
}
- async function save({ andPost = false } = {}) {
+ // The points a save or a post has to have looked at first, walked one at a time:
+ // { rows, at, andPost, then } while it runs.
+ let checking = $state(null);
+ // What the dialog is asked about, read once per point. The dialog's props are
+ // read again while it closes, after `checking` is already gone.
+ const checkStep = $derived(
+ checking
+ ? {
+ view: pointMapView(checking.rows[checking.at]),
+ check: {
+ step: checking.rows.length > 1 ? `${checking.at + 1} of ${checking.rows.length}` : '',
+ label: proof.points[checking.rows[checking.at]]?.label ?? '',
+ },
+ later: !checking.andPost,
+ }
+ : null
+ );
+
+ async function save({ andPost = false, checked = false, then = null } = {}) {
if (!proof.panels.length || saving) return;
+ // A point the imagery proposed is the middle of a capture until somebody looks.
+ // A save files it on the case map and a post publishes it, so each one is shown
+ // on the map first. `then` is what asked for the save, resumed once it lands.
+ const rows = checked ? [] : uncheckedPoints(proof.points, proof.panels);
+ if (rows.length) {
+ checking = { rows, at: 0, andPost, then };
+ return;
+ }
// The name in the header is the filename. A bound proof writes back over
// itself, and renaming it moves the file — the backend refuses a rename onto
// a name another proof holds. An unbound proof landing on a saved name is
@@ -3742,7 +3769,24 @@
overwritePrompt = { slug: slugify(proof.title, 'proof'), andPost };
return;
}
- return performSave(andPost);
+ await performSave(andPost);
+ if (then && !dirty) then();
+ }
+
+ /** The point on screen is right, or was moved: on to the next one, or the save. */
+ function checkPick(point) {
+ const { rows, at } = checking;
+ movePoint(rows[at], point);
+ if (at + 1 < rows.length) checking = { ...checking, at: at + 1 };
+ else finishCheck();
+ }
+
+ /** Save now. `later` keeps the points left unchecked off the case map. */
+ async function finishCheck(later = false) {
+ const { andPost, then } = checking;
+ checking = null;
+ await save({ andPost, checked: true, then });
+ if (later && !dirty) toast('Unchecked points stay off the case map until you check them.', 'warn', 5200);
}
async function performSave(andPost = false) {
@@ -4000,7 +4044,7 @@
picker || newProofOpen || importOpen || openList !== null || discardConfirm
|| replaceWithNewConfirm || exportPicker || overwritePrompt !== null
|| placeOffer !== null || orphanOffer !== null || deleteEntry !== null
- || sourcePick !== null || pointMap !== null
+ || sourcePick !== null || pointMap !== null || checking !== null
);
const editableShape = $derived(editableShapes.length === 1 ? editableShapes[0] : null);
const fillableSelection = $derived(editableShapes.some((s) => canFill(s.kind)));
@@ -4061,7 +4105,10 @@
* answer first, which is what adding a second row already did.
*/
function statePoint0() {
- if (!proof.points[0].coords.trim()) proof.points[0].coords = displayedCoords;
+ if (proof.points[0].coords.trim()) return;
+ // naming a point is not checking where it is
+ if (pointProposed(proof.points, 0, proof.panels)) proof.points[0].proposed = true;
+ proof.points[0].coords = displayedCoords;
}
/** Add a row. The first one is materialised first: that answer has to become the
@@ -4122,6 +4169,7 @@
/** The point the map handed back, written where the row reads it. */
function movePoint(i, point) {
proof.points[i].coords = formatCoords(point, prefs.coordFormat);
+ proof.points[i].proposed = false;
dirty = true;
}
@@ -4512,16 +4560,29 @@
of a building by editing digits — so the map is one press from
the field, inside the same box, the way the date beside it
opens its calendar. -->
- <div class="field-with-act coords-field" class:warn={i === 0 && !displayedCoords}>
+ <!-- A point the imagery proposed reads greyed until somebody checks it:
+ typed, or placed on the map. -->
+ <div
+ class="field-with-act coords-field"
+ class:warn={i === 0 && !displayedCoords}
+ class:proposed={pointProposed(proof.points, i, proof.panels)}
+ >
<input
class="input meta-input"
placeholder="lat, lon"
value={i === 0 ? displayedCoords : point.coords}
- oninput={(e) => { proof.points[i].coords = e.target.value; dirty = true; }}
+ oninput={(e) => {
+ proof.points[i].coords = e.target.value;
+ proof.points[i].proposed = false;
+ dirty = true;
+ }}
/>
<button
class="field-act"
- title="Move this point on the map"
+ class:check={pointProposed(proof.points, i, proof.panels)}
+ title={pointProposed(proof.points, i, proof.panels)
+ ? 'Not checked yet. Check it on the map'
+ : 'Move this point on the map'}
onclick={() => (pointMap = { row: i, view: pointMapView(i) })}
>
<Icon name="pin" size={13} />
@@ -4940,6 +5001,19 @@
/>
{/if}
+<!-- One point at a time, each on its own map: the dialog reads where it opens once. -->
+{#if checkStep}
+ {#key checking?.at}
+ <PointMapDialog
+ view={checkStep?.view}
+ check={checkStep?.check}
+ onpick={checkPick}
+ onlater={checkStep?.later ? () => finishCheck(true) : null}
+ onclose={() => (checking = null)}
+ />
+ {/key}
+{/if}
+
{#if importOpen && caseState.current}
<ImportProofDialog
caseId={caseState.current.id}
@@ -5415,6 +5489,8 @@
.point-row + .point-row { margin-top: 4px; }
.point-row .meta-input { flex: 1; min-width: 0; }
.point-row .coords-field { flex: 1; min-width: 0; }
+ .coords-field.proposed .meta-input { color: var(--text-3); font-style: italic; }
+ .coords-field .field-act.check { color: var(--warn, #e8a33d); }
/* The name is as wide as a name needs to be; the coordinate takes the rest. */
.point-row .label-field { width: 110px; flex: none; }
.point-label { width: 100%; min-width: 0; font-size: var(--fs-xs); padding: 5px 8px; }
diff --git a/frontend/src/tools/ProofComposer.test.js b/frontend/src/tools/ProofComposer.test.js
index 5a512f4..3b299e4 100644
--- a/frontend/src/tools/ProofComposer.test.js
+++ b/frontend/src/tools/ProofComposer.test.js
@@ -63,7 +63,8 @@ describe('Proof Composer header', () => {
expect(source).toContain('onchosen={useExportFolder}');
expect(source).toContain('api.post(`/api/cases/${cid}/proofs/${encodeURIComponent(savedName)}/export`)');
expect(source).toContain('/proofs/export/reveal`');
- expect(source).toContain('if (dirty || !savedName) await save();');
+ // a save that stops to check a point resumes the export once it lands
+ expect(source).toContain('if (dirty || !savedName) await save({ then: exportProof });');
expect(source).toContain('if (dirty || !savedName) return;');
});
@@ -643,7 +644,11 @@ describe('the points a proof states', () => {
it('materialises the auto point before a second one sits under it', () => {
// an empty field means "whatever the imagery says", and that answer has to
// become the conclusion in writing before the list can grow
- expect(source).toContain("if (!proof.points[0].coords.trim()) proof.points[0].coords = displayedCoords;");
+ const state = bodyOfFn('statePoint0');
+ expect(state).toContain('if (proof.points[0].coords.trim()) return;');
+ expect(state).toContain('proof.points[0].coords = displayedCoords;');
+ // …and still as unchecked as it was: naming a point is not checking where it is
+ expect(state).toContain('if (pointProposed(proof.points, 0, proof.panels)) proof.points[0].proposed = true;');
expect(bodyOfFn('addPoint')).toContain('statePoint0();');
});
@@ -682,15 +687,17 @@ describe('the points a proof states', () => {
// canvas; in grid layout the second place was simply never heard.
const body = bodyOfFn('addPanel');
expect(body).toContain('const answered = displayedCoords;');
+ expect(body).toContain('const answeredProposed = pointProposed(proof.points, 0, proof.panels);');
expect(body.indexOf('const answered')).toBeLessThan(body.indexOf('proof.panels.unshift(panel)'));
+ expect(body.indexOf('const answeredProposed')).toBeLessThan(body.indexOf('proof.panels.unshift(panel)'));
expect(body).toContain(
- 'proof.points = statePanelPoint(proof.points, panel, answered, prefs.coordFormat);'
+ 'proof.points = statePanelPoint(proof.points, panel, answered, prefs.coordFormat, answeredProposed);'
);
});
it('opens a row on the ground it names, or on the point above it', () => {
// six decimals is a tenth of a metre: the pin is the instrument, not the digits
- expect(source).toContain('title="Move this point on the map"');
+ expect(source).toContain(": 'Move this point on the map'}");
expect(source).toContain('onclick={() => (pointMap = { row: i, view: pointMapView(i) })}');
const view = bodyOfFn('pointMapView');
expect(view).toContain('proof.points.slice(0, i).map((one) => one.coords).reverse()');
@@ -701,6 +708,34 @@ describe('the points a proof states', () => {
);
});
+ it('greys a point the imagery proposed until it is typed or placed', () => {
+ expect(source).toContain('class:proposed={pointProposed(proof.points, i, proof.panels)}');
+ expect(source).toContain('class:check={pointProposed(proof.points, i, proof.panels)}');
+ expect(source).toContain("'Not checked yet. Check it on the map'");
+ const typed = source.slice(source.indexOf('placeholder="lat, lon"'), source.indexOf('class="field-act"'));
+ expect(typed).toContain('proof.points[i].proposed = false;');
+ expect(bodyOfFn('movePoint')).toContain('proof.points[i].proposed = false;');
+ });
+
+ it('shows every unchecked point on the map before a save or a post', () => {
+ const body = bodyOfFn('save');
+ expect(body).toContain('const rows = checked ? [] : uncheckedPoints(proof.points, proof.panels);');
+ expect(body).toContain('checking = { rows, at: 0, andPost, then };');
+ // the check comes before anything is written, the overwrite question included
+ expect(body.indexOf('uncheckedPoints')).toBeLessThan(body.indexOf('overwritePrompt'));
+ expect(body.indexOf('uncheckedPoints')).toBeLessThan(body.indexOf('performSave'));
+ // one point at a time, then the save it was holding
+ const pick = bodyOfFn('checkPick');
+ expect(pick).toContain('movePoint(rows[at], point);');
+ expect(pick).toContain('checking = { ...checking, at: at + 1 };');
+ expect(bodyOfFn('finishCheck')).toContain('await save({ andPost, checked: true, then });');
+ // a post publishes the point, so only a plain save can leave it for later
+ expect(source).toContain('later: !checking.andPost,');
+ expect(source).toContain('onlater={checkStep?.later ? () => finishCheck(true) : null}');
+ expect(source).toContain('{#key checking?.at}');
+ expect(source).toContain('|| checking !== null');
+ });
+
it('redraws the plate when a point or the footer switch changes', () => {
// both feed the footer, and the footer decides the picture's height: a
// rebuild that does not read them leaves the export a line behind
diff --git a/frontend/src/tools/Satellite.svelte b/frontend/src/tools/Satellite.svelte
index f1e7c07..25665af 100644
--- a/frontend/src/tools/Satellite.svelte
+++ b/frontend/src/tools/Satellite.svelte
@@ -2753,6 +2753,8 @@
media={refs.media}
loading={refs.loading}
caseId={caseState.current?.id}
+ bind:category={refs.category}
+ bind:showWorking={refs.showWorking}
onpick={(item) => refs.add(item)}
onclose={() => (refs.picking = false)}
/>
diff --git a/frontend/src/tools/detect/AcquisitionPicker.svelte b/frontend/src/tools/detect/AcquisitionPicker.svelte
index 4d2317c..104e13e 100644
--- a/frontend/src/tools/detect/AcquisitionPicker.svelte
+++ b/frontend/src/tools/detect/AcquisitionPicker.svelte
@@ -9,15 +9,24 @@
* cells in five are dead. So this lists what exists, newest first, with the
* two facts that decide between them: how much of the areas the pass reaches,
* and how much of it was cloud.
+ *
+ * The calendar has its place one step up, for where to look: past the year the
+ * presets reach, two days picked in it bound the lookup. The catalogue gives at
+ * most 100 passes, newest first, so a list it cut short offers the older ones.
*/
import Icon from '../../components/Icon.svelte';
- import { LOOKBACK_WINDOWS, coverClass, coverLabel, passKey } from '../../lib/map/acquisitions.js';
+ import MonthGrid from '../../components/MonthGrid.svelte';
+ import {
+ LOOKBACK_WINDOWS, MISSION_START, coverClass, coverLabel, lookupSpan, olderSpan, passKey, spanProblem,
+ } from '../../lib/map/acquisitions.js';
+ import { isoDay } from '../../lib/sentinel.js';
import { cloudClass, cloudLabel } from '../../lib/sentinel.js';
import { orbitMark, sameTrack } from '../../lib/radar.js';
let {
list = [],
- days,
+ /** Days back from today, or two days picked in the calendar, `{ start, end }`. */
+ lookback,
busy = false,
error = '',
truncated = false,
@@ -31,11 +40,26 @@
/** The chosen sources, `{ date, time }` each, or null. */
a = null,
b = null,
- ondays,
+ onlookback,
onlook,
+ /** Look again before the oldest pass listed, when the catalogue cut the list. */
+ onolder,
onpick,
} = $props();
+ const picked = $derived(typeof lookback === 'object' && lookback !== null);
+ const problem = $derived(spanProblem(lookback));
+ const older = $derived(truncated && onolder ? olderSpan(lookback, list) : null);
+ const first = $derived(MISSION_START[radar ? 'sentinel1' : 'sentinel2']);
+ const today = isoDay(new Date());
+ /** Which picked day has its month open: 'start', 'end' or ''. */
+ let calendar = $state('');
+
+ function pickDay(day) {
+ onlookback({ ...lookback, [calendar]: day });
+ calendar = '';
+ }
+
/** Whether a row is the pass a side names: a typed radar day matches its day. */
function names(source, entry) {
if (!source?.date || source.date !== entry.date) return false;
@@ -49,17 +73,43 @@
{#each LOOKBACK_WINDOWS as option (option.id)}
<button
type="button"
- class:on={days === option.id}
+ class:on={lookback === option.id}
disabled={busy}
- onclick={() => ondays(option.id)}
+ onclick={() => { calendar = ''; onlookback(option.id); }}
>{option.label}</button>
{/each}
+ <button
+ type="button"
+ class:on={picked}
+ disabled={busy}
+ title="Pick the first and the last day in the calendar"
+ onclick={() => { if (!picked) onlookback(lookupSpan(lookback)); }}
+ >Dates…</button>
</div>
- <button class="btn btn-sm" disabled={busy || !areas} onclick={onlook}>
+ <button class="btn btn-sm" disabled={busy || !areas || !!problem} onclick={onlook}>
{busy ? 'Looking…' : searched ? 'Look again' : 'Find passes'}
</button>
</div>
+ {#if picked}
+ <div class="span">
+ <button type="button" class="day cmp-mono" class:open={calendar === 'start'} disabled={busy}
+ aria-label="First day" aria-expanded={calendar === 'start'}
+ onclick={() => (calendar = calendar === 'start' ? '' : 'start')}>{lookback.start || 'First day'}</button>
+ <span aria-hidden="true">→</span>
+ <button type="button" class="day cmp-mono" class:open={calendar === 'end'} disabled={busy}
+ aria-label="Last day" aria-expanded={calendar === 'end'}
+ onclick={() => (calendar = calendar === 'end' ? '' : 'end')}>{lookback.end || 'Last day'}</button>
+ </div>
+ {#if calendar}
+ <MonthGrid value={lookback[calendar]} label={calendar === 'start' ? 'First day' : 'Last day'}
+ min={calendar === 'start' ? first : lookback.start || first}
+ max={calendar === 'start' ? lookback.end || today : today}
+ onpick={pickDay} />
+ {/if}
+ {#if problem}<p class="warn">{problem}</p>{/if}
+ {/if}
+
{#if !areas}
<p class="hint">Draw an area in step 1, then look up the passes it has.</p>
{:else if error}
@@ -72,7 +122,8 @@
<p class="warn">No pass reaches these areas in this window. Try a longer one.</p>
{:else}
{#if truncated}
- <p class="warn">The catalogue stopped at 100 passes, so older ones are missing. Shorten the window for a complete list.</p>
+ <p class="warn">The catalogue stopped at 100 passes, so older ones are missing.
+ {#if older}<button type="button" class="link" disabled={busy} onclick={onolder}>Older passes</button>{/if}</p>
{/if}
<ul class="list">
{#each list as entry (passKey(entry))}
@@ -140,6 +191,28 @@
gap: 8px;
flex-wrap: wrap;
}
+ /* Underlined: it sits in the warning's own orange. */
+ .link { color: var(--accent); font-size: inherit; text-decoration: underline; }
+ .link:disabled { color: var(--text-3); }
+ .span {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ color: var(--text-3);
+ font-size: var(--fs-xs);
+ }
+ .day {
+ padding: 3px 7px;
+ border: 1px solid var(--border);
+ border-radius: var(--r-sm);
+ color: var(--text-1);
+ font-size: var(--fs-xs);
+ }
+ .day:hover:not(:disabled),
+ .day.open {
+ border-color: var(--accent);
+ background: var(--accent-soft);
+ }
.hint {
display: flex;
align-items: center;
diff --git a/frontend/src/tools/detect/AcquisitionPicker.test.js b/frontend/src/tools/detect/AcquisitionPicker.test.js
index 13ac9eb..f494442 100644
--- a/frontend/src/tools/detect/AcquisitionPicker.test.js
+++ b/frontend/src/tools/detect/AcquisitionPicker.test.js
@@ -14,8 +14,8 @@ function render(props = {}) {
const live = mount(AcquisitionPicker, {
target,
props: {
- list: passes, days: 30, searched: true, areas: 1,
- ondays: () => {}, onlook: () => {}, onpick: () => {}, ...props,
+ list: passes, lookback: 30, searched: true, areas: 1,
+ onlookback: () => {}, onlook: () => {}, onpick: () => {}, ...props,
},
});
flushSync();
@@ -90,6 +90,72 @@ describe('the acquisition picker', () => {
done();
});
+ it('opens the calendar on the window the presets were showing', () => {
+ const onlookback = vi.fn();
+ const { target, done } = render({ onlookback });
+ button(target, 'Dates…').click();
+ const [span] = onlookback.mock.calls[0];
+ expect(span.end).toBe(new Date().toISOString().slice(0, 10));
+ expect(span.start < span.end).toBe(true);
+ done();
+ });
+
+ it('bounds a lookup by two days picked in the calendar, however old', () => {
+ const onlookback = vi.fn();
+ const { target, done } = render({ lookback: { start: '2019-03-01', end: '2019-06-30' }, onlookback });
+ expect(button(target, 'Dates…').classList.contains('on')).toBe(true);
+ target.querySelector('[aria-label="First day"]').click(); flushSync();
+ target.querySelector('.cal button[title="2019-03-12"]').click(); flushSync();
+ expect(onlookback).toHaveBeenLastCalledWith({ start: '2019-03-12', end: '2019-06-30' });
+ // the calendar closes on the day it was opened for
+ expect(target.querySelector('.cal')).toBe(null);
+ done();
+ });
+
+ it('keeps each picked day on its side of the other', () => {
+ const { target, done } = render({ lookback: { start: '2019-06-10', end: '2019-06-20' } });
+ const day = (iso) => target.querySelector(`.cal button[title="${iso}"]`);
+ target.querySelector('[aria-label="First day"]').click(); flushSync();
+ expect([day('2019-06-15').disabled, day('2019-06-25').disabled]).toEqual([false, true]);
+ target.querySelector('[aria-label="Last day"]').click(); flushSync();
+ expect([day('2019-06-05').disabled, day('2019-06-15').disabled]).toEqual([true, false]);
+ done();
+ });
+
+ it('starts the calendar at the launch of the satellite the passes come from', () => {
+ const lookback = { start: '2014-04-01', end: '2014-04-30' };
+ const optical = render({ lookback });
+ optical.target.querySelector('[aria-label="First day"]').click(); flushSync();
+ expect(optical.target.querySelector('.cal button[title="2014-04-10"]').disabled).toBe(true);
+ optical.done();
+ const radar = render({ lookback, radar: true, list: [] });
+ radar.target.querySelector('[aria-label="First day"]').click(); flushSync();
+ const day = (iso) => radar.target.querySelector(`.cal button[title="${iso}"]`);
+ expect([day('2014-04-02').disabled, day('2014-04-10').disabled]).toEqual([true, false]);
+ radar.done();
+ });
+
+ it('will not look up two days in the wrong order', () => {
+ const { target, done } = render({ lookback: { start: '2020-06-01', end: '2020-01-01' } });
+ expect(target.textContent).toContain('The first day comes after the last.');
+ expect(button(target, 'Look again').disabled).toBe(true);
+ done();
+ });
+
+ it('offers the older passes a cut list is missing', () => {
+ const onolder = vi.fn();
+ const { target, done } = render({ truncated: true, lookback: { start: '2026-01-01', end: '2026-05-31' }, onolder });
+ button(target, 'Older passes').click();
+ expect(onolder).toHaveBeenCalledOnce();
+ done();
+ });
+
+ it('offers nothing older once the list reaches the first day asked', () => {
+ const { target, done } = render({ truncated: true, lookback: { start: '2026-05-08', end: '2026-05-31' }, onolder: vi.fn() });
+ expect(button(target, 'Older passes')).toBeUndefined();
+ done();
+ });
+
it('suggests a longer window when nothing reaches the areas', () => {
const { target, done } = render({ list: [] });
expect(target.textContent).toContain('No pass reaches these areas');
diff --git a/frontend/src/tools/detect/AnalyzerBuilder.svelte b/frontend/src/tools/detect/AnalyzerBuilder.svelte
index 7e82877..f45f7c4 100644
--- a/frontend/src/tools/detect/AnalyzerBuilder.svelte
+++ b/frontend/src/tools/detect/AnalyzerBuilder.svelte
@@ -18,7 +18,7 @@
*/
import { onDestroy, onMount, untrack } from 'svelte';
import { api } from '../../lib/api.js';
- import { acquisitionQuery } from '../../lib/map/acquisitions.js';
+ import { acquisitionQuery, olderSpan, withOlder } from '../../lib/map/acquisitions.js';
import { clone, viewZone } from '../../lib/map/analyzers.js';
import {
RULE_COLOURS, checksSummary, describeRecipe, formatShare, markOutcomes, newCheck, newRule, readsOneDate,
@@ -86,11 +86,13 @@
let error = $state('');
let saving = $state(false);
let shown = $state([]);
+ /** What the map paints: each rule's pixels, or only what a run would return. */
+ let view = $state('rules');
let hover = $state(null);
let probe = $state(null);
let showing = $state('basemap');
let layer = $state('TRUE_COLOR');
- let passes = $state({ list: [], days: 90, busy: false, error: '', searched: false, truncated: false, open: false });
+ let passes = $state({ list: [], lookback: 90, busy: false, error: '', searched: false, truncated: false, open: false });
/** The check on the bench, and what each check's last read left. */
let active = $state(null);
let readings = $state({});
@@ -101,6 +103,10 @@
const current = $derived(signature(recipe));
const summary = $derived(checksSummary(recipe));
const bench = $derived(recipe.checks.find((check) => check.id === active) ?? null);
+ /** The open check's own count, while its last read matches the rules and passes on the map:
+ * the map then shows its frame only, so the view's count would not be what is seen. */
+ const framed = $derived(bench?.result && bench.result.signature === current && bench.b.date === b.date
+ && (single || (bench.a?.date ?? '') === a.date) ? bench.result : null);
/** The view, held inside the ranges the engine accepts. */
function bounded(bounds) {
@@ -148,8 +154,13 @@
/** A rule's eye; one added since the last toggle starts open. */
const isShown = (i) => shown[i] ?? true;
function toggle(i) {
- shown = recipe.rules.map((_, k) => (k === i ? !isShown(k) : isShown(k)));
+ // With the detections alone on the map every eye reads closed, so one
+ // pressed there opens its rule and brings the others back as they were.
+ const opening = view === 'detections';
+ view = 'rules';
+ shown = recipe.rules.map((_, k) => (k === i ? opening || !isShown(k) : isShown(k)));
}
+ const painted = (i) => view === 'rules' && isShown(i);
/** What a reading depends on; the name, label, colour and checks do not. */
const readingRecipe = $derived({ name: 'Preview', method: 'rules', rules: recipe.rules, match: recipe.match,
@@ -372,8 +383,8 @@
builder = {
preview, probe,
// A hidden rule stays hidden while the pointer is on its row.
- hover: hover !== null && isShown(hover) ? hover : null,
- shown: recipe.rules.map((_, i) => isShown(i)),
+ hover: hover !== null && painted(hover) ? hover : null,
+ shown: recipe.rules.map((_, i) => painted(i)),
rules: clone(recipe.rules),
colour: recipe.colour, style: recipe.style, phenomenon: recipe.phenomenon,
colours: RULE_COLOURS,
@@ -450,13 +461,17 @@
if (source.date) show(letter);
}
- async function lookUp() {
- if (!region) return;
+ const lookUp = () => search(passes.lookback, false);
+ const lookOlder = () => search(olderSpan(passes.lookback, passes.list), true);
+
+ async function search(span, more) {
+ if (!region || !span) return;
passes = { ...passes, busy: true, error: '', open: true };
try {
const found = await api.post('/api/satellite/sentinel/acquisitions',
- acquisitionQuery([viewZone(region, 'Preview')], passes.days, new Date(), radar ? 'sentinel1' : 'sentinel2'));
- passes = { ...passes, list: found.dates ?? [], searched: true, truncated: !!found.truncated };
+ acquisitionQuery([viewZone(region, 'Preview')], span, new Date(), radar ? 'sentinel1' : 'sentinel2'));
+ const list = more ? withOlder(passes.list, found.dates) : found.dates ?? [];
+ passes = { ...passes, list, searched: true, truncated: !!found.truncated };
} catch (e) {
passes = { ...passes, error: e.message };
} finally {
@@ -509,10 +524,10 @@
</button>
</div>
{#if passes.open}
- <AcquisitionPicker list={passes.list} days={passes.days} busy={passes.busy} error={passes.error}
+ <AcquisitionPicker list={passes.list} lookback={passes.lookback} busy={passes.busy} error={passes.error}
searched={passes.searched} truncated={passes.truncated} areas={region ? 1 : 0} {single} {radar}
wantsReference={!single} wantsCompare={true} {a} {b}
- ondays={(days) => (passes = { ...passes, days })} onlook={lookUp}
+ onlookback={(lookback) => (passes = { ...passes, lookback })} onlook={lookUp} onolder={lookOlder}
onpick={(letter, entry) => setDate(letter, entry.date, entry.time ?? '')} />
{/if}
<div class="row under">
@@ -539,8 +554,21 @@
<p class="hint">{needs}</p>
{:else}
{#if preview}
- <p class="result"><strong>{preview.count} candidate{preview.count === 1 ? '' : 's'}</strong> on the map
- · {formatShare(preview.kept)} of the measured ground kept{#if working} · updating…{/if}</p>
+ <div class="row">
+ {#if framed}
+ <p class="result grow"><strong>{framed.count} candidate{framed.count === 1 ? '' : 's'}</strong>
+ in “{bench.name}”{#if working} · updating…{/if}</p>
+ {:else}
+ <p class="result grow"><strong>{preview.count} candidate{preview.count === 1 ? '' : 's'}</strong> on the map
+ · {formatShare(preview.kept)} of the measured ground kept{#if working} · updating…{/if}</p>
+ {/if}
+ <div class="cmp-seg" role="group" aria-label="What the map shows">
+ <button type="button" class:on={view === 'rules'} aria-pressed={view === 'rules'}
+ title="Each rule's pixels in its colour" onclick={() => (view = 'rules')}>Rules</button>
+ <button type="button" class:on={view === 'detections'} aria-pressed={view === 'detections'}
+ title="Only what a detection would return" onclick={() => (view = 'detections')}>Detections</button>
+ </div>
+ </div>
{#if preview.candidates.length && preview.count > preview.candidates.length}<p class="hint">The {preview.candidates.length} strongest are drawn.</p>{/if}
{#if preview.note}<p class="warn">{preview.note}</p>{/if}
{:else if working && !missing}
@@ -583,7 +611,7 @@
</div>
{#each recipe.rules as _, i (i)}
<RuleRow bind:rule={recipe.rules[i]} index={i} colour={RULE_COLOURS[i % RULE_COLOURS.length]}
- signal={i === signal} reading={preview?.rules?.[i] ?? null} match={recipe.match} shown={isShown(i)} ontoggle={() => toggle(i)}
+ signal={i === signal} reading={preview?.rules?.[i] ?? null} match={recipe.match} shown={painted(i)} ontoggle={() => toggle(i)}
bands={limits.bands} classes={limits.classes} maxAround={limits.max_around}
canRemove={recipe.rules.length > 1} onremove={() => remove(i)} onsignal={() => rank(i)}
onhover={(index) => (hover = index)} />
diff --git a/frontend/src/tools/detect/AnalyzerSettings.svelte b/frontend/src/tools/detect/AnalyzerSettings.svelte
index 372261d..b366b28 100644
--- a/frontend/src/tools/detect/AnalyzerSettings.svelte
+++ b/frontend/src/tools/detect/AnalyzerSettings.svelte
@@ -7,9 +7,8 @@
* name.
*/
import CloudFilter from '../compare/CloudFilter.svelte';
- import { sizeBand, sizeOf } from '../../lib/map/analyzers.js';
+ import AnalyzerSize from './AnalyzerSize.svelte';
- const SIZES = [['small', 'Small'], ['medium', 'Medium'], ['large', 'Large'], ['all', 'All']];
const INDICES = [
['ndvi', 'NDVI · vegetation'], ['nbr', 'NBR · burn scars'], ['mndwi', 'MNDWI · open water'],
['ndwi', 'NDWI · open water'], ['bsi', 'BSI · bare soil'], ['ndbi', 'NDBI · built-up'],
@@ -21,6 +20,8 @@
/** Thresholds shown outright rather than behind a link. */
expanded = false,
readonly = false,
+ /** The wizard asks for the size first, above the analyzers, and not here. */
+ showSize = true,
} = $props();
let showThresholds = $state(false);
@@ -30,12 +31,6 @@
* sensitivity or direction here, and it cleans and smooths on one date too. */
const rules = $derived(recipe.method === 'rules');
const SHAPES = [['any', 'Any shape'], ['compact', 'Compact: roofs, craters, vehicles'], ['elongated', 'Long and thin: roads, tracks, trenches']];
- const size = $derived(sizeOf(recipe.parameters, capability.sizes));
-
- function setSize(name) {
- if (readonly || !capability.sizes?.[name]) return;
- recipe.parameters = { ...recipe.parameters, ...capability.sizes[name] };
- }
function setWeather(on) {
if (readonly) return;
@@ -44,17 +39,7 @@
</script>
<fieldset class="settings" disabled={readonly}>
- {#if capability.sizes}
- <div class="cmp-seg fill" role="group" aria-label="Target size">
- {#each SIZES as [name, label] (name)}
- {#if capability.sizes[name]}
- <button type="button" class:on={size === name} aria-pressed={size === name}
- title={sizeBand(capability.sizes[name])} onclick={() => setSize(name)}>{label}</button>
- {/if}
- {/each}
- </div>
- <p class="hint">{size ? sizeBand(capability.sizes[size]) : 'Sizes are set by hand below.'}</p>
- {/if}
+ {#if showSize}<AnalyzerSize bind:recipe {capability} {readonly} />{/if}
{#if capability.clouds}
<CloudFilter clouds={recipe.parameters.ignore_clouds} shadows={recipe.parameters.ignore_shadows}
ontoggle={setWeather} />
diff --git a/frontend/src/tools/detect/AnalyzerSize.svelte b/frontend/src/tools/detect/AnalyzerSize.svelte
new file mode 100644
index 0000000..4fd0b5f
--- /dev/null
+++ b/frontend/src/tools/detect/AnalyzerSize.svelte
@@ -0,0 +1,40 @@
+<script>
+ /**
+ * Small, Medium, Large or All: the floor and ceiling on a candidate's area,
+ * with the cleanup and grouping that go with them. The band a size keeps is
+ * said under the buttons, which read as sensitivity and are not. One
+ * component, so the wizard can ask it first and the library beside the
+ * thresholds, and both apply the same numbers.
+ */
+ import { sizeBand, sizeOf } from '../../lib/map/analyzers.js';
+
+ const SIZES = [['small', 'Small'], ['medium', 'Medium'], ['large', 'Large'], ['all', 'All']];
+
+ let {
+ recipe = $bindable(),
+ capability = {},
+ readonly = false,
+ /** Told which size was pressed, so a caller can carry it to the next analyzer. */
+ onpick = () => {},
+ } = $props();
+
+ const size = $derived(sizeOf(recipe.parameters, capability.sizes));
+
+ function setSize(name) {
+ if (readonly || !capability.sizes?.[name]) return;
+ recipe.parameters = { ...recipe.parameters, ...capability.sizes[name] };
+ onpick(name);
+ }
+</script>
+
+{#if capability.sizes}
+ <div class="cmp-seg fill" role="group" aria-label="Target size">
+ {#each SIZES as [name, label] (name)}
+ {#if capability.sizes[name]}
+ <button type="button" class:on={size === name} aria-pressed={size === name} disabled={readonly}
+ title={sizeBand(capability.sizes[name])} onclick={() => setSize(name)}>{label}</button>
+ {/if}
+ {/each}
+ </div>
+ <p class="hint">{size ? sizeBand(capability.sizes[size]) : 'Sizes are set by hand below.'}</p>
+{/if}
diff --git a/frontend/src/tools/detect/AreaDates.svelte b/frontend/src/tools/detect/AreaDates.svelte
index f48ce1e..aa7fff2 100644
--- a/frontend/src/tools/detect/AreaDates.svelte
+++ b/frontend/src/tools/detect/AreaDates.svelte
@@ -1,6 +1,6 @@
<script>
import { api } from '../../lib/api.js';
- import { acquisitionQuery, coverageWarning, passKey } from '../../lib/map/acquisitions.js';
+ import { acquisitionQuery, coverageWarning, olderSpan, passKey, withOlder } from '../../lib/map/acquisitions.js';
import AcquisitionPicker from './AcquisitionPicker.svelte';
import DateField from '../../components/DateField.svelte';
@@ -13,7 +13,7 @@
const radar = $derived(sensor === 'sentinel1');
let looking = $state(null);
let passes = $state([]);
- let days = $state(90);
+ let lookback = $state(90);
let busy = $state(false);
let error = $state('');
let searched = $state(false);
@@ -21,14 +21,19 @@
let generation = 0;
const pairFor = (id) => pairs.find((p) => p.area_id === id);
- async function lookup(zone) {
- looking = zone.id; busy = true; error = ''; searched = false; passes = [];
+ /** The passes over one area, or with `more` those before the oldest listed. */
+ async function lookup(zone, more = false) {
+ const span = more ? olderSpan(lookback, passes) : lookback;
+ if (!span) return;
+ looking = zone.id; busy = true; error = '';
+ if (!more) { searched = false; passes = []; }
const mine = ++generation;
try {
const found = await api.post('/api/satellite/sentinel/acquisitions',
- acquisitionQuery([zone], days, new Date(), sensor));
+ acquisitionQuery([zone], span, new Date(), sensor));
if (mine !== generation) return;
- passes = found.dates ?? []; searched = true; truncated = !!found.truncated;
+ passes = more ? withOlder(passes, found.dates) : found.dates ?? [];
+ searched = true; truncated = !!found.truncated;
} catch (e) { if (mine === generation) error = e.message; }
finally { if (mine === generation) busy = false; }
}
@@ -74,9 +79,10 @@
{#if looking}
{@const pair = pairFor(looking)}
<p class="hint">{zones.find((zone) => zone.id === looking)?.name}</p>
- <AcquisitionPicker list={passes} {days} {busy} {error} {searched} {truncated} areas={1} {radar}
+ <AcquisitionPicker list={passes} {lookback} {busy} {error} {searched} {truncated} areas={1} {radar}
{single} wantsReference={!single} wantsCompare={!baselineOnly} a={pair?.a ?? null} b={pair?.b ?? null}
- ondays={(value) => (days = value)} onlook={() => lookup(zones.find((zone) => zone.id === looking))}
+ onlookback={(value) => (lookback = value)} onlook={() => lookup(zones.find((zone) => zone.id === looking))}
+ onolder={() => lookup(zones.find((zone) => zone.id === looking), true)}
onpick={(letter, entry) => pick(looking, letter, entry.date, entry.time ?? '')} />
{#each [single ? null : pair?.a, pair?.b].filter((source) => source?.date) as source}
{@const warning = coverageWarning(passes.find((pass) => passKey(pass) === passKey(source)
diff --git a/frontend/src/tools/detect/DetectPanel.svelte b/frontend/src/tools/detect/DetectPanel.svelte
index 39fa115..437901a 100644
--- a/frontend/src/tools/detect/DetectPanel.svelte
+++ b/frontend/src/tools/detect/DetectPanel.svelte
@@ -600,7 +600,7 @@
survives a detour to make the analyzer it needs. -->
<div class="pane" hidden={view !== 'new'}>
{#key draft}
- <DetectWizard {caseId} {catalogue} areaSets={lists.zones} areas={lists.areas} seed={draft} {offer} {busy}
+ <DetectWizard {caseId} {catalogue} areaSets={lists.zones} areas={lists.areas} seed={draft} {offer} {busy} failure={error}
bind:zones bind:drawing bind:selectedZone bind:showZones
{onfocus} {onusecurrentview} {onshow} onlibrary={openLibrary}
onareas={(id) => refresh(id)} onsubmit={(request) => act(() => submit(request))} />
diff --git a/frontend/src/tools/detect/DetectPanel.test.js b/frontend/src/tools/detect/DetectPanel.test.js
index cfdb583..6751344 100644
--- a/frontend/src/tools/detect/DetectPanel.test.js
+++ b/frontend/src/tools/detect/DetectPanel.test.js
@@ -321,6 +321,46 @@ it('walks a single pass through its steps and runs it once', async () => {
}));
});
+it('pages back through a pass list the catalogue cut short', async () => {
+ answer({ '/api/cases/case-a/analysis/zones/aaaaaaaaaaaa': { id: 'aaaaaaaaaaaa', title: 'Port', zones: area } });
+ const ago = (days) => new Date(Date.now() - days * 86400000).toISOString().slice(0, 10);
+ await open({ opening: 'zones-aaaaaaaaaaaa' });
+ button('Next: What').click(); await settle();
+ button('Next: When').click(); await settle();
+ button('1 year').click(); await settle();
+ post.mockResolvedValueOnce({ dates: [{ date: ago(10), cloud: 2, coverage: 1 }, { date: ago(100), cloud: 5, coverage: 0.4 }],
+ truncated: true });
+ post.mockResolvedValueOnce({ dates: [{ date: ago(100), cloud: 5, coverage: 1 }, { date: ago(120), cloud: 9, coverage: 1 }],
+ truncated: false });
+ button('Find passes').click(); await settle();
+ expect(target.textContent).toContain('stopped at 100 passes');
+ button('Older passes').click(); await settle();
+ expect(post).toHaveBeenLastCalledWith('/api/satellite/sentinel/acquisitions',
+ expect.objectContaining({ start: ago(365), end: ago(100) }));
+ const listed = [...target.querySelectorAll('.passes li strong')].map((node) => node.textContent);
+ expect(listed).toEqual([ago(10), ago(100), ago(120)]);
+ expect(target.textContent).not.toContain('stopped at 100 passes');
+ expect(target.textContent).not.toContain('40% of the areas');
+});
+
+it('says why a pass did not start, beside the button that started it', async () => {
+ answer({ '/api/cases/case-a/analysis/zones/aaaaaaaaaaaa': { id: 'aaaaaaaaaaaa', title: 'Port', zones: area } });
+ post.mockRejectedValue(new Error('an area of this detection was deleted; choose its areas again'));
+ await open({ opening: 'zones-aaaaaaaaaaaa' });
+ button('Next: What').click(); await settle();
+ button('Next: When').click(); await settle();
+ button('A day I choose').click(); await settle();
+ for (const [label, day] of [['Day of A', '01/08/2026'], ['Day of B', '06/09/2026']]) {
+ const field = target.querySelector(`[aria-label="${label}"]`);
+ field.value = day; field.dispatchEvent(new Event('input', { bubbles: true })); await settle();
+ }
+ button('Next: Start').click(); await settle();
+ button('Run this pass').click(); await settle();
+ expect(heading()).toBe('Name and start');
+ expect(target.querySelector('.cmp-dock-foot [role="alert"]')?.textContent)
+ .toBe('an area of this detection was deleted; choose its areas again');
+});
+
it('asks a routine what each pass compares against, not which day to read', async () => {
const set = { id: 'aaaaaaaaaaaa', title: 'Port', zones: area, areas: 1 };
let saved = [];
@@ -504,6 +544,22 @@ it('sets a size as a whole set of numbers, and shows when it was tuned by hand',
expect(pressed()).toEqual([]);
});
+it('asks the size above the analyzers, and holds a pressed size for the next one picked', async () => {
+ answer({ '/api/cases/case-a/analysis/zones/aaaaaaaaaaaa': { id: 'aaaaaaaaaaaa', title: 'Port', zones: area } });
+ await open({ opening: 'zones-aaaaaaaaaaaa' });
+ button('Next: What').click(); await settle();
+ const step = target.querySelector('section[aria-label="What to look for"]');
+ const sizes = step.querySelectorAll('[aria-label="Target size"]');
+ const list = step.querySelector('[aria-label="Analyzer"]');
+ expect(sizes.length).toBe(1);
+ expect(sizes[0].compareDocumentPosition(list) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ const pressed = () => [...step.querySelectorAll('[aria-label="Target size"] button')]
+ .filter((b) => b.getAttribute('aria-pressed') === 'true').map((b) => b.textContent.trim());
+ button('Large').click(); await settle();
+ [...list.querySelectorAll('[role="radio"]')].find((b) => b.textContent.includes('Vessels')).click(); await settle();
+ expect(pressed()).toEqual(['Large']);
+});
+
it('offers the cloud switch on by default, and none for a method that rejects cloud itself', async () => {
answer({ '/api/cases/case-a/analysis/zones/aaaaaaaaaaaa': { id: 'aaaaaaaaaaaa', title: 'Port', zones: area } });
await open({ opening: 'zones-aaaaaaaaaaaa' });
@@ -771,6 +827,43 @@ it('marks a point read on the map in a check, which turns red when a rule loses
expect(saved.checks[0].result.signature).toMatch(/^[0-9a-z]+$/);
});
+it('shows the detections alone on the map, keeps each eye for the way back, and counts an open check', async () => {
+ answer({ '/api/compare/analyzers': rulesCatalogue() });
+ copernicus(PREVIEWED, () => ({ ready: true, missing: 0, count: 2, covered: [true] }));
+ await openBuilder();
+ button('Add a rule').click(); await settle();
+ await readTheView();
+ const eye = (n) => target.querySelector(`button.eye[aria-label$="rule ${n} on the map"]`).getAttribute('aria-pressed');
+ const view = (name) => target.querySelector(`[aria-label="What the map shows"]`)
+ .querySelector(`button:nth-child(${name === 'Rules' ? 1 : 2})`);
+ labelled('Hide rule 2 on the map').click(); await settle();
+ expect([eye(1), eye(2)]).toEqual(['true', 'false']);
+
+ // the detections alone: nothing of the rules is painted, so every eye reads closed
+ view('Detections').click(); await settle();
+ expect(view('Detections').getAttribute('aria-pressed')).toBe('true');
+ expect([eye(1), eye(2)]).toEqual(['false', 'false']);
+ // back to the rules, each eye as it was left
+ view('Rules').click(); await settle();
+ expect([eye(1), eye(2)]).toEqual(['true', 'false']);
+
+ // an eye pressed from the detections opens its rule and brings the rules back
+ view('Detections').click(); await settle();
+ labelled('Show rule 2 on the map').click(); await settle();
+ expect(view('Rules').getAttribute('aria-pressed')).toBe('true');
+ expect([eye(1), eye(2)]).toEqual(['true', 'true']);
+
+ // an open check counts its own frame, which is all the map shows, and the choice rides along
+ view('Detections').click(); await settle();
+ await live.probeAt({ lon: 2.01, lat: 48.01 }); await settle();
+ live.markProbe('found'); await settle();
+ await debounce(900); await settle();
+ expect(tab('Checks').getAttribute('aria-selected')).toBe('true');
+ expect(target.textContent).toContain('2 candidates in “Check 1”');
+ expect(target.textContent).not.toContain('candidate on the map');
+ expect(view('Detections').getAttribute('aria-pressed')).toBe('true');
+});
+
it('adds a check where the map is: pick its passes, drop pins with the map, done', async () => {
answer({ '/api/compare/analyzers': rulesCatalogue() });
copernicus();
diff --git a/frontend/src/tools/detect/DetectWizard.svelte b/frontend/src/tools/detect/DetectWizard.svelte
index f6e59fa..9ce9a4d 100644
--- a/frontend/src/tools/detect/DetectWizard.svelte
+++ b/frontend/src/tools/detect/DetectWizard.svelte
@@ -30,6 +30,7 @@
import { openCopernicusSettings } from '../../lib/navigate.js';
import { uniform, whenNeed, whenSummary } from '../../lib/map/detectWhen.js';
import AnalyzerSettings from './AnalyzerSettings.svelte';
+ import AnalyzerSize from './AnalyzerSize.svelte';
import WhenStep from './WhenStep.svelte';
import Icon from '../../components/Icon.svelte';
@@ -44,6 +45,8 @@
/** An analyzer just made in the library, to pick. */
offer = null,
busy = false,
+ /** Why the last launch or save failed, said beside the button that did it. */
+ failure = '',
zones = $bindable([]),
drawing = $bindable('select'),
selectedZone = $bindable(null),
@@ -65,6 +68,8 @@
let kind = $state('once');
let recipe = $state(null);
let chosen = $state('');
+ /** A size pressed in this detection, which holds for the next analyzer picked. */
+ let pickedSize = $state('');
let title = $state('');
let note = $state('');
let a = $state({ ...EMPTY_SOURCE });
@@ -144,7 +149,10 @@
function choose(id) {
const found = [...builtins, ...custom].find((r) => r.id === id);
if (!found) return;
- recipe = clone(found);
+ const next = clone(found);
+ const sizes = recipeCapability(next, catalogue?.methods ?? []).sizes;
+ if (pickedSize && sizes?.[pickedSize]) next.parameters = { ...next.parameters, ...sizes[pickedSize] };
+ recipe = next;
chosen = id;
}
@@ -372,6 +380,12 @@
{:else if step === 2}
<section class="step" aria-label="What to look for">
<h3>What to look for</h3>
+ {#if recipe}
+ <div class="size">
+ <p class="group">Target size</p>
+ <AnalyzerSize bind:recipe {capability} onpick={(name) => (pickedSize = name)} />
+ </div>
+ {/if}
<div class="choices" role="radiogroup" aria-label="Analyzer">
{#each groups as group (group.label)}
<p class="group">{group.label}</p>
@@ -395,7 +409,7 @@
{/if}
</div>
{#if recipe.description}<p class="hint">{recipe.description}</p>{/if}
- <AnalyzerSettings bind:recipe {capability} />
+ <AnalyzerSettings bind:recipe {capability} showSize={false} />
<button class="link" onclick={onlibrary}>Make an analyzer of your own…</button>
</section>
{:else if step === 3}
@@ -457,6 +471,7 @@
</div>
<div class="cmp-dock-foot">
+ {#if failure}<p class="warn" role="alert">{failure}</p>{/if}
<div class="row">
{#if step > 1}<button class="btn btn-sm" onclick={() => step--}>Back</button>{/if}
{#if step < 4}
@@ -541,6 +556,7 @@
.link:disabled { opacity: 0.5; }
.link small { display: block; color: var(--text-3); font-size: 10px; }
.centre { justify-self: center; text-align: center; }
+ .size { display: grid; gap: 5px; }
.choices { display: grid; gap: 2px; }
.group {
margin: 6px 0 2px;
diff --git a/frontend/src/tools/detect/WhenStep.svelte b/frontend/src/tools/detect/WhenStep.svelte
index 3bd65c9..76e7724 100644
--- a/frontend/src/tools/detect/WhenStep.svelte
+++ b/frontend/src/tools/detect/WhenStep.svelte
@@ -14,8 +14,8 @@
*/
import { untrack } from 'svelte';
import { api } from '../../lib/api.js';
- import { acquisitionQuery, areaKey, coverageWarning, passKey } from '../../lib/map/acquisitions.js';
- import { areaLine, setSide, sharedSide, uniform, withRule } from '../../lib/map/detectWhen.js';
+ import { acquisitionQuery, areaKey, coverageWarning, olderSpan, passKey, withOlder } from '../../lib/map/acquisitions.js';
+ import { areaLine, setSide, shadowWarning, sharedSide, uniform, withRule } from '../../lib/map/detectWhen.js';
import AcquisitionPicker from './AcquisitionPicker.svelte';
import AreaDates from './AreaDates.svelte';
import DateField from '../../components/DateField.svelte';
@@ -43,7 +43,7 @@
];
const radar = $derived(sensor === 'sentinel1');
- let days = $state(untrack(() => lookup?.days ?? 90));
+ let lookback = $state(untrack(() => lookup?.lookback ?? 90));
let busy = $state(false);
let error = $state('');
let perArea = $state(false);
@@ -72,15 +72,21 @@
.map((side) => coverageWarning(fresh.list.find((pass) => passKey(pass) === passKey(side)
|| (!side.time && pass.date === side.date))))
.filter(Boolean));
+ const shadows = $derived(shadowWarning(pairs, zones, { single, radar }));
- async function look() {
+ const look = () => search(lookback, false);
+ const lookOlder = () => search(olderSpan(lookback, fresh?.list), true);
+
+ async function search(span, more) {
+ if (!span) return;
busy = true; error = '';
const mine = ++generation;
try {
const found = await api.post('/api/satellite/sentinel/acquisitions',
- acquisitionQuery(zones, days, new Date(), sensor));
+ acquisitionQuery(zones, span, new Date(), sensor));
if (mine !== generation) return;
- lookup = { key, days, list: found.dates ?? [], truncated: !!found.truncated };
+ const list = more ? withOlder(fresh?.list, found.dates) : found.dates ?? [];
+ lookup = { key, lookback, list, truncated: !!found.truncated };
} catch (e) { if (mine === generation) error = e.message; }
finally { if (mine === generation) busy = false; }
}
@@ -163,12 +169,14 @@
{/if}
</div>
+ {#if shadows}<p class="warn" role="note">{shadows}</p>{/if}
+
<p class="passes-title"><strong>Passes over {ground}</strong>
<span>{radar ? 'with their time and track' : 'with their cloud cover'}</span></p>
- <AcquisitionPicker list={fresh?.list ?? []} {days} {busy} {error} searched={!!fresh} truncated={!!fresh?.truncated}
+ <AcquisitionPicker list={fresh?.list ?? []} {lookback} {busy} {error} searched={!!fresh} truncated={!!fresh?.truncated}
areas={zones.length} {radar} {single} wantsReference={!single} wantsCompare={!routine}
a={single ? null : a} b={routine ? null : b}
- ondays={(value) => (days = value)} onlook={look}
+ onlookback={(value) => (lookback = value)} onlook={look} onolder={lookOlder}
onpick={(letter, entry) => pick(letter, entry.date, entry.time ?? '')} />
{#each warnings as warning (warning)}<p class="warn">{warning}</p>{/each}
{/if}
@@ -242,6 +250,7 @@
.passes-title { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; margin: 2px 0 0; font-size: var(--fs-xs); }
.passes-title span { color: var(--text-3); font-size: 10.5px; }
.link { color: var(--accent); font-size: var(--fs-xs); }
+ .warn { margin: 0; color: var(--warn, #e2a03f); font-size: 10.5px; line-height: 1.35; }
.dates { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; }
.dates li { display: flex; gap: 8px; font-size: var(--fs-xs); }
.dates .who { flex: 1; min-width: 0; overflow: hidden; color: var(--text-2); text-overflow: ellipsis; white-space: nowrap; }
diff --git a/frontend/src/tools/proof/PointMapDialog.render.test.js b/frontend/src/tools/proof/PointMapDialog.render.test.js
index cadf3d5..f2db878 100644
--- a/frontend/src/tools/proof/PointMapDialog.render.test.js
+++ b/frontend/src/tools/proof/PointMapDialog.render.test.js
@@ -91,10 +91,10 @@ async function settle() {
flushSync();
}
-async function open(view = VIEW) {
+async function open(view = VIEW, extra = {}) {
const target = document.createElement('div');
document.body.append(target);
- live = mount(PointMapDialog, { target, props: { view, onpick, onclose } });
+ live = mount(PointMapDialog, { target, props: { view, onpick, onclose, ...extra } });
flushSync();
await settle();
}
@@ -183,6 +183,30 @@ describe('moving a proof point on the map', () => {
expect(setOverlay).toHaveBeenCalledWith('railway', true, null);
});
+ it('checks a point before a save, handing it back without closing', async () => {
+ const onlater = vi.fn();
+ await open(VIEW, { check: { step: '1 of 2', label: 'Hangar' }, onlater });
+
+ expect(document.body.textContent).toContain('Check point 1 of 2');
+ expect(document.body.textContent).toContain('Hangar');
+ expect(document.body.textContent).toContain('Taken from the imagery.');
+
+ // kept where it is: the point is right as proposed
+ button('Use this point').click();
+ expect(onpick).toHaveBeenCalledWith({ lat: 48.8584, lon: 2.2945 });
+ // the composer moves on to the next point, so the dialog does not close itself
+ expect(onclose).not.toHaveBeenCalled();
+
+ button('Later').click();
+ expect(onlater).toHaveBeenCalled();
+ });
+
+ it('offers no Later before a post, which publishes the point', async () => {
+ await open(VIEW, { check: { step: '', label: '' } });
+ expect(document.body.textContent).toContain('Check the point');
+ expect(button('Later')).toBeUndefined();
+ });
+
it('writes nothing: the dialog answers one question and files nothing', async () => {
await open();
engines[0].handlers.click({ lat: 1, lon: 2 });
diff --git a/frontend/src/tools/proof/PointMapDialog.svelte b/frontend/src/tools/proof/PointMapDialog.svelte
index 80ece0b..4cfdf42 100644
--- a/frontend/src/tools/proof/PointMapDialog.svelte
+++ b/frontend/src/tools/proof/PointMapDialog.svelte
@@ -13,6 +13,11 @@
* tool. The camera opens where the caller says (the row's own point, else the
* one above it) so a row added with `+` starts beside the point it belongs with
* rather than on the empty Atlantic.
+ *
+ * The same map checks a point before a save or a post (`check`). A point the
+ * imagery proposed is the middle of a capture until somebody looks, so the
+ * composer walks each one through here and the analyst either moves the pin or
+ * says the point is right.
*/
import { onMount, untrack } from 'svelte';
import Modal from '../../components/Modal.svelte';
@@ -34,9 +39,14 @@
let {
/** Where the map opens, `{ lat, lon, zoom }`. The pin starts on it. */
view,
- /** The point chosen, `{ lat, lon }`. The dialog closes itself after. */
+ /** The point chosen, `{ lat, lon }`. The dialog closes itself after, unless it
+ * is checking: then the caller moves on to the next point. */
onpick,
onclose,
+ /** `{ step, label }` when checking a point before a save or a post. */
+ check = null,
+ /** Checking before a save only: save now, leaving the point unchecked. */
+ onlater = null,
} = $props();
const PIN = 'point';
@@ -135,7 +145,13 @@
<svelte:window onkeydown={(event) => turnFromKey(engine, event)} />
-<Modal title="Move the point" {onclose} width="900px">
+<Modal title={check ? (check.step ? `Check point ${check.step}` : 'Check the point') : 'Move the point'} {onclose} width="900px">
+ {#if check}
+ <p class="check">
+ {#if check.label}<strong>{check.label}</strong>{/if}
+ <span>Taken from the imagery. Put the pin on what the proof shows, or keep it if it is right.</span>
+ </p>
+ {/if}
<div class="stage">
<MapSurface
bind:engine
@@ -167,18 +183,31 @@
<div class="foot">
<span class="hint">Click the map to move the pin.</span>
<span class="reading mono">{reading}</span>
+ {#if onlater}
+ <button class="btn btn-ghost btn-sm" title="Save now and keep the point off the case map" onclick={onlater}>Later</button>
+ {/if}
<button class="btn btn-ghost btn-sm" onclick={onclose}>Cancel</button>
<button
class="btn btn-ok btn-sm"
onclick={() => {
onpick(at);
- onclose();
+ if (!check) onclose();
}}>Use this point</button
>
</div>
</Modal>
<style>
+ .check {
+ display: flex;
+ gap: 8px;
+ margin: 0 0 10px;
+ font-size: var(--fs-sm);
+ color: var(--text-2);
+ }
+ .check strong {
+ color: var(--text-1);
+ }
.stage {
position: relative;
display: flex;
diff --git a/frontend/src/tools/satellite/RefPicker.render.test.js b/frontend/src/tools/satellite/RefPicker.render.test.js
new file mode 100644
index 0000000..d528c2c
--- /dev/null
+++ b/frontend/src/tools/satellite/RefPicker.render.test.js
@@ -0,0 +1,201 @@
+// @vitest-environment happy-dom
+/**
+ * The Add reference picker, actually mounted.
+ *
+ * What it is for is one click to the shot being geolocated in a case that also
+ * holds dozens of renders. So what is asserted is what a click narrows to: the
+ * working files start held back, a chip is one press, a chip that would narrow
+ * nothing is left out, and a short case skips all of it.
+ */
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { flushSync, mount, unmount } from 'svelte';
+import RefPicker from './RefPicker.svelte';
+
+const upload = (title, extra = {}) => ({
+ path: `media/${title}.jpg`,
+ filename: `${title}.jpg`,
+ title,
+ kind: 'image',
+ source: { type: 'upload' },
+ ...extra,
+});
+const clip = (title) => ({
+ path: `media/${title}.mp4`,
+ filename: `${title}.mp4`,
+ title,
+ kind: 'video',
+ source: { type: 'download' },
+});
+const made = (title, source) => ({
+ path: `media/${title}.png`,
+ filename: `${title}.png`,
+ title,
+ kind: 'image',
+ source,
+});
+
+const COLLECTED = [
+ upload('Gate', { folder: 'street' }),
+ upload('Roof'),
+ upload('Checkpoint'),
+ upload('Crowd'),
+ clip('Strike'),
+ clip('Convoy'),
+ clip('Launch'),
+];
+const WORKING = [
+ made('Small change', { type: 'compare' }),
+ made('Comparison 12', { type: 'compare' }),
+ made('15.73, 45.02', { type: 'satellite' }),
+ made('Collage 4', { type: 'inspect', op: 'collage' }),
+];
+
+let held = null;
+
+function show(props = {}) {
+ held = mount(RefPicker, {
+ target: document.body,
+ props: { media: [...COLLECTED, ...WORKING], caseId: 'c1', onpick: vi.fn(), onclose: vi.fn(), ...props },
+ });
+ flushSync();
+ return document.body;
+}
+
+afterEach(() => {
+ if (held) unmount(held);
+ held = null;
+ document.body.innerHTML = '';
+});
+
+const shown = () => [...document.body.querySelectorAll('.ref-pick')].map((node) => node.title);
+const chips = () =>
+ [...document.body.querySelectorAll('.ref-chips .ref-chip')].map((node) => node.textContent.replace(/\s+/g, ' ').trim());
+const chip = (label) =>
+ [...document.body.querySelectorAll('.ref-chip')].find((node) => node.textContent.trim().startsWith(label));
+const pressed = () =>
+ [...document.body.querySelectorAll('.ref-chip[aria-pressed="true"]')].map((node) => node.textContent.trim());
+
+function press(node) {
+ node.click();
+ flushSync();
+}
+
+function search(text) {
+ const input = document.body.querySelector('.search-input');
+ input.value = text;
+ input.dispatchEvent(new Event('input', { bubbles: true }));
+ flushSync();
+}
+
+describe('a short case', () => {
+ it('is a plain grid with everything in it, working files included', () => {
+ const media = [COLLECTED[0], COLLECTED[4], WORKING[0]];
+ show({ media });
+
+ expect(shown()).toEqual(['Gate', 'Strike', 'Small change']);
+ expect(document.body.querySelector('.search-input')).toBeNull();
+ expect(chips()).toEqual([]);
+ });
+});
+
+describe('a long case', () => {
+ it('opens on what the case collected, and says how much it holds back', () => {
+ show();
+
+ expect(shown()).toEqual(COLLECTED.map((item) => item.title));
+ expect(document.body.querySelector('.search-count').textContent).toBe('7/7');
+ expect(chip('Show 4 working files')).toBeTruthy();
+ });
+
+ it('brings the working files back with one press, and their facets with them', () => {
+ show();
+ press(chip('Show 4 working files'));
+
+ expect(shown()).toHaveLength(11);
+ expect(chips()).toContain('Comparisons 2');
+ expect(chips()).toContain('Satellite 1');
+ expect(chip('Hide working files')).toBeTruthy();
+ });
+
+ it('narrows to one type in one click, counts included', () => {
+ show();
+ expect(chips()).toEqual([
+ 'All 7',
+ 'Images 4',
+ 'Videos 3',
+ 'Imports 4',
+ 'Downloads 3',
+ ]);
+
+ press(chip('Videos'));
+ expect(shown()).toEqual(['Strike', 'Convoy', 'Launch']);
+ expect(pressed()).toEqual(['Videos 3']);
+
+ press(chip('All'));
+ expect(shown()).toHaveLength(7);
+ });
+
+ it('searches inside the chip, and says when only held-back files match', () => {
+ show();
+ press(chip('Images'));
+ search('roof');
+ expect(shown()).toEqual(['Roof']);
+
+ press(chip('All'));
+ search('comparison');
+ expect(shown()).toEqual([]);
+ expect(document.body.textContent).toContain('Only working files match this search.');
+ });
+
+ it('opens on the chip the session kept', () => {
+ show({ category: 'video' });
+ expect(shown()).toEqual(['Strike', 'Convoy', 'Launch']);
+ });
+
+ it('reads a kept chip the switch hides as All, and gives it back with the switch', () => {
+ show({ category: 'satellite' });
+ expect(shown()).toHaveLength(7);
+ expect(pressed()).toEqual(['All 7']);
+
+ press(chip('Show 4 working files'));
+ expect(shown()).toEqual(['15.73, 45.02']);
+ });
+
+ it('leaves out a chip that would narrow nothing', () => {
+ const media = ['A', 'B', 'C', 'D', 'E', 'F', 'G'].map(clip);
+ show({ media });
+
+ // Every item is a downloaded video: Videos and Downloads would hide nothing,
+ // and there are no working files to hold back.
+ expect(chips()).toEqual([]);
+ expect(shown()).toHaveLength(7);
+ });
+
+ it('shows the working files when the case collected nothing', () => {
+ const media = [...WORKING, ...WORKING.map((item) => ({ ...item, path: `${item.path}-2` }))];
+ show({ media });
+
+ expect(shown()).toHaveLength(8);
+ expect(chip('Show')).toBeUndefined();
+ });
+
+ it('browses folders behind a button that says so, within the chip', () => {
+ show();
+ press(document.body.querySelector('button[title="Browse folders"]'));
+ const rows = () =>
+ [...document.body.querySelectorAll('.browser-row')].map((node) => node.textContent.trim());
+ expect(rows()).toEqual(['Unfiled', 'street']);
+
+ // Only an image is filed under street, so the Videos chip takes the folder away.
+ press(chip('Videos'));
+ expect(rows()).toEqual(['Unfiled']);
+ expect(document.body.querySelector('button[title="Back to the grid"]')).toBeTruthy();
+ });
+
+ it('hands the picked item back', () => {
+ const onpick = vi.fn();
+ show({ onpick });
+ press(document.body.querySelector('.ref-pick[title="Roof"]'));
+ expect(onpick).toHaveBeenCalledWith(COLLECTED[1]);
+ });
+});
diff --git a/frontend/src/tools/satellite/RefPicker.svelte b/frontend/src/tools/satellite/RefPicker.svelte
index 1b8d874..f13b65e 100644
--- a/frontend/src/tools/satellite/RefPicker.svelte
+++ b/frontend/src/tools/satellite/RefPicker.svelte
@@ -3,23 +3,32 @@
* Pick a case image or video to float over the map.
*
* A reference window is a pure scratch aid — never captured, never saved — so
- * this reads the case's media and hands one back. Two ways in, because a case
- * with two hundred images is a different problem from a case with four: the
- * grid, and the folder browser behind "…". The search box only appears once
- * the grid is long enough to need it.
+ * this reads the case's media and hands one back. A short list is a plain
+ * grid. Once it is long enough to need narrowing, the picker grows a search
+ * box, one chip per type or source (the Media Library's facets, one click
+ * each), a switch for the case's working files, and the folder browser.
+ *
+ * The working files start held back. The reference is almost always the shot
+ * being geolocated, which the case collected, and a case that ran Detect or
+ * Compare holds dozens of renders beside it. A case that collected nothing
+ * shows them anyway rather than an empty grid.
*/
import Icon from '../../components/Icon.svelte';
import Modal from '../../components/Modal.svelte';
import SearchInput from '../../components/SearchInput.svelte';
import FolderBrowser from '../../components/FolderBrowser.svelte';
import { fileUrl } from '../../lib/fileUrl.js';
- import { matchesQuery } from '../../lib/mediaFilter.js';
+ import { isMadeHere, matchesQuery, MEDIA_CATEGORIES } from '../../lib/mediaFilter.js';
let {
/** The case's images and videos, already loaded. */
media = [],
loading = false,
caseId,
+ /** The chip picked last; the caller keeps it for the session. */
+ category = $bindable(null),
+ /** Whether the working files are in the grid; kept the same way. */
+ showWorking = $bindable(false),
/** Take this one as a reference window. */
onpick,
onclose,
@@ -28,16 +37,36 @@
const SEARCH_MIN = 6; // below that, the grid is easier to scan than to search
let query = $state('');
- let browsing = $state(false); // "…" swaps the grid for the folder browser
+ let browsing = $state(false); // the folder button swaps the grid for the browser
let path = $state('');
let selection = $state(null);
+ const narrowing = $derived(media.length > SEARCH_MIN);
+ const working = $derived(media.filter(isMadeHere));
+ const collectedCount = $derived(media.length - working.length);
+ // Offered only when it has something to hide and something to leave.
+ const canHold = $derived(narrowing && working.length > 0 && collectedCount > 0);
+ const pool = $derived(canHold && !showWorking ? media.filter((item) => !isMadeHere(item)) : media);
+ // A chip that would hide nothing narrows nothing, so it stays out of the row.
+ const chips = $derived(
+ MEDIA_CATEGORIES.map((c) => ({ ...c, count: pool.filter(c.match).length })).filter(
+ (c) => c.count > 0 && c.count < pool.length
+ )
+ );
+ // A choice the pool no longer offers (the switch hid what it picked) reads as
+ // All, and comes back with the switch.
+ const active = $derived(narrowing ? chips.find((c) => c.key === category) ?? null : null);
+ const narrowed = $derived(active ? pool.filter(active.match) : pool);
// Same free-text match as the Media Library (filename, title, notes, folder,
// download source), so what works there works here.
- const visible = $derived(media.filter((item) => matchesQuery(item, query)));
+ const visible = $derived(narrowed.filter((item) => matchesQuery(item, query)));
+ const heldMatches = $derived(
+ canHold && !showWorking && query.trim() && working.some((item) => matchesQuery(item, query))
+ );
const entries = $derived(
- media.map((item) => ({ ...item, id: item.path, attrs: { folder: item.folder ?? '' } }))
+ narrowed.map((item) => ({ ...item, id: item.path, attrs: { folder: item.folder ?? '' } }))
);
+ const plural = (n) => (n > 1 ? 's' : '');
function resetBrowser() {
path = '';
@@ -53,6 +82,11 @@
resetBrowser();
browsing = true;
}
+
+ function pickCategory(key) {
+ category = key;
+ resetBrowser();
+ }
</script>
<Modal title="Add reference" {onclose} width="560px">
@@ -67,20 +101,69 @@
No images or videos in this case yet. Import one in the Media Library first.
</div>
{:else}
- {#if browsing || media.length > SEARCH_MIN}
+ {#if narrowing}
<div class="ref-search">
<SearchInput
bind:value={query}
placeholder="Search media…"
- count={`${visible.length}/${media.length}`}
+ count={`${visible.length}/${pool.length}`}
width="100%"
/>
+ {#if canHold}
+ <button
+ type="button"
+ class="ref-chip ref-working"
+ class:active={showWorking}
+ aria-pressed={showWorking}
+ title={showWorking
+ ? 'Show only what the case collected'
+ : `Show the ${working.length} file${plural(working.length)} the case produced itself`}
+ onclick={() => {
+ showWorking = !showWorking;
+ resetBrowser();
+ }}
+ >
+ <Icon name="layers" size={12} />
+ {showWorking
+ ? 'Hide working files'
+ : `Show ${working.length} working file${plural(working.length)}`}
+ </button>
+ {/if}
<button
class="btn btn-ghost btn-sm browse-btn"
- title={browsing ? 'Show every image' : 'Browse folders'}
+ class:on={browsing}
+ aria-pressed={browsing}
+ title={browsing ? 'Back to the grid' : 'Browse folders'}
onclick={toggleBrowser}
- >…</button>
+ >
+ <Icon name="folder" size={15} />
+ </button>
</div>
+ {#if chips.length}
+ <div class="ref-chips" role="group" aria-label="Filter by type or source">
+ <button
+ type="button"
+ class="ref-chip"
+ class:active={!active}
+ aria-pressed={!active}
+ onclick={() => pickCategory(null)}
+ >
+ All <span>{pool.length}</span>
+ </button>
+ {#each chips as chip (chip.key)}
+ <button
+ type="button"
+ class="ref-chip"
+ class:active={active?.key === chip.key}
+ aria-pressed={active?.key === chip.key}
+ onclick={() => pickCategory(chip.key)}
+ >
+ <Icon name={chip.icon} size={12} />
+ {chip.label} <span>{chip.count}</span>
+ </button>
+ {/each}
+ </div>
+ {/if}
{/if}
{#if browsing}
<FolderBrowser
@@ -112,7 +195,9 @@
</button>
</div>
{:else if !visible.length}
- <div class="ref-empty">No media matches this search.</div>
+ <div class="ref-empty">
+ {heldMatches ? 'Only working files match this search.' : 'No media matches this search.'}
+ </div>
{:else}
<div class="ref-grid">
{#each visible as item (item.path)}
@@ -145,7 +230,7 @@
display: flex;
align-items: center;
gap: 6px;
- margin-bottom: 10px;
+ margin-bottom: 8px;
}
.ref-search :global(.search-box) {
flex: 1;
@@ -153,8 +238,43 @@
.browse-btn {
flex-shrink: 0;
padding: 0 8px;
- font-size: var(--fs-md);
- line-height: 1;
+ }
+ .browse-btn.on {
+ color: var(--accent);
+ }
+ .ref-chips {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 5px;
+ margin-bottom: 10px;
+ }
+ .ref-chip {
+ display: flex;
+ align-items: center;
+ gap: 5px;
+ padding: 4px 8px;
+ border: 1px solid var(--border);
+ border-radius: var(--r-sm);
+ background: var(--bg-2);
+ color: var(--text-2);
+ font-size: var(--fs-xs);
+ white-space: nowrap;
+ cursor: pointer;
+ }
+ .ref-chip:hover {
+ border-color: var(--border-strong);
+ color: var(--text-1);
+ }
+ .ref-chip.active {
+ border-color: var(--accent);
+ color: var(--text-1);
+ }
+ .ref-chip span {
+ color: var(--text-3);
+ }
+ .ref-working {
+ flex-shrink: 0;
+ align-self: stretch;
}
.ref-actions {
display: flex;
diff --git a/frontend/src/tools/satellite/state/refs.svelte.js b/frontend/src/tools/satellite/state/refs.svelte.js
index e4130df..dc0c725 100644
--- a/frontend/src/tools/satellite/state/refs.svelte.js
+++ b/frontend/src/tools/satellite/state/refs.svelte.js
@@ -39,6 +39,10 @@ export function createRefsState({ api, notify, caseId, viewers, setViewers }) {
let media = $state([]); // what the case has to offer
let loading = $state(false);
let spawned = 0; // id source, so two windows on the same media stay distinct
+ // The picker's chip and working-files switch, kept for the session so the
+ // next reference opens on the same narrowing as the last one.
+ let category = $state(null);
+ let showWorking = $state(false);
return {
get picking() {
@@ -47,6 +51,18 @@ export function createRefsState({ api, notify, caseId, viewers, setViewers }) {
set picking(value) {
picking = value;
},
+ get category() {
+ return category;
+ },
+ set category(value) {
+ category = value;
+ },
+ get showWorking() {
+ return showWorking;
+ },
+ set showWorking(value) {
+ showWorking = value;
+ },
get media() {
return media;
},
diff --git a/frontend/src/tools/satellite/state/refs.svelte.test.js b/frontend/src/tools/satellite/state/refs.svelte.test.js
index cf96f38..7aae489 100644
--- a/frontend/src/tools/satellite/state/refs.svelte.test.js
+++ b/frontend/src/tools/satellite/state/refs.svelte.test.js
@@ -77,6 +77,20 @@ describe('the picker', () => {
await reading;
expect(refs.loading).toBe(false);
});
+
+ it('opens on collected media with every type, then keeps the narrowing picked', async () => {
+ const refs = store();
+ expect(refs.category).toBe(null);
+ expect(refs.showWorking).toBe(false);
+
+ await refs.openPicker();
+ refs.category = 'video';
+ refs.showWorking = true;
+ refs.add(CLIP); // closes the picker
+ await refs.openPicker();
+ expect(refs.category).toBe('video');
+ expect(refs.showWorking).toBe(true);
+ });
});
describe('spawning a window', () => {
diff --git a/src/azimut/api/analyzers.py b/src/azimut/api/analyzers.py
index 88028d6..7339391 100644
--- a/src/azimut/api/analyzers.py
+++ b/src/azimut/api/analyzers.py
@@ -23,7 +23,7 @@ from ..engine import (
from ..engine.analysis_models import (
BUILTINS, GROUPS, MAX_AROUND, MAX_BANDS, MAX_CHECKS, MAX_MARKS, MAX_RULES, METHODS, RELIABILITY, Area, AreaDates,
AreaGeometry, Bounds, Check, Latitude, Longitude, Model, Recipe, RunInput, SceneClass, ShortId, Source, Zone,
- ZoneSet, is_single,
+ ZoneSet, is_single, stored, unreadable,
)
from ..workspace import Case
from .cases import delete_by_path, delete_entities_deep, get_case
@@ -37,7 +37,7 @@ def recipes() -> dict[str, Any]:
custom = []
for raw in settings.get("analyzers", []):
try:
- custom.append(Recipe.model_validate(raw).model_dump())
+ custom.append(stored(Recipe, raw).model_dump())
except ValueError:
continue
return {"builtins": [r.model_dump() for r in BUILTINS], "custom": custom, "methods": METHODS,
@@ -222,7 +222,10 @@ def start(case: Any, body: RunInput) -> dict[str, Any]:
detection twice is refused, since the second would sweep what the first
is already sweeping."""
with engine.LOCK, case._lock:
- body = engine.hydrate(case, body)
+ try:
+ body = engine.hydrate(case, body)
+ except FileNotFoundError as exc:
+ raise HTTPException(404, "an area of this detection was deleted; choose its areas again") from exc
if body.followup_id:
read(case, "followups", body.followup_id)
if any(row.get("status") in engine.ACTIVE and row.get("followup_id") == body.followup_id
@@ -273,7 +276,7 @@ def run_followup(case_id: str, ident: str, body: RunAgain | None = None) -> dict
fields = {key: saved[key] for key in RunInput.model_fields if key in saved}
chosen = body or RunAgain()
try:
- run = RunInput.model_validate({**fields, "followup_id": ident})
+ run = stored(RunInput, {**fields, "followup_id": ident})
if chosen.area_dates is not None:
run = RunInput.model_validate({**run.model_dump(), "area_dates": chosen.area_dates})
if chosen.date:
@@ -288,8 +291,7 @@ def run_followup(case_id: str, ident: str, body: RunAgain | None = None) -> dict
"b": {**pair.b.model_dump(), "date": chosen.date}}
for pair in run.area_dates]})
except ValidationError as exc:
- reason = str(exc.errors()[0].get("msg", "")).removeprefix("Value error, ")
- raise HTTPException(422, reason or "this detection needs editing before it can run") from exc
+ raise HTTPException(422, unreadable(exc) or "this detection needs editing before it can run") from exc
return start(case, run.model_copy(update={"run_anyway": chosen.run_anyway}))
@@ -388,7 +390,7 @@ def add_manual(case_id: str, ident: str, body: ManualCandidate) -> dict[str, Any
raise HTTPException(409, "finish the run before adding a candidate")
if len(saved["results"]) >= engine.MAX_RESULTS:
raise HTTPException(409, "this run has reached the candidate limit")
- zone = next((Zone.model_validate(z) for z in saved["input"]["zones"] if z["id"] == body.area_id), None)
+ zone = next((stored(Zone, z) for z in saved["input"]["zones"] if z["id"] == body.area_id), None)
outcome = next((p for p in saved.get("area_runs", []) if p["area_id"] == body.area_id), None)
if zone is None or (outcome and outcome["status"] != "ready"):
raise HTTPException(422, "choose an area successfully read by this run")
@@ -407,7 +409,7 @@ def add_manual(case_id: str, ident: str, body: ManualCandidate) -> dict[str, Any
parts = []
for ty in range(top // size, (bottom - 1) // size + 1):
for tx in range(left // size, (right - 1) // size + 1):
- keys = [engine._key(Source.model_validate(s), z, tx, ty, None) for s in sources]
+ keys = [engine._key(stored(Source, s), z, tx, ty, None) for s in sources]
if not all(key in saved["frames"] for key in keys):
continue
px, py = max(left, tx * size), max(top, ty * size)
diff --git a/src/azimut/api/proofs.py b/src/azimut/api/proofs.py
index f85d12d..4920e17 100644
--- a/src/azimut/api/proofs.py
+++ b/src/azimut/api/proofs.py
@@ -705,6 +705,12 @@ def _state_points(
to answer a question the Locate pass answers for free: the first point is
resolved because the analyst is about to look at it, and the rest are born
unlocated for that pass to pick up, exactly as an offline save already is.
+
+ **A point nobody checked is never filed** (``proposed``, see
+ ``satellite.spec_points``): it is the middle of a capture, and filing it would
+ put a guess on the case map as a conclusion. It is not asked about either, since
+ the composer just offered to check it and heard "later". A place the case
+ already holds there stays, so an older proof re-saved unchecked keeps its point.
"""
stated: list[dict[str, Any]] = []
filed: list[dict[str, Any]] = []
@@ -714,6 +720,8 @@ def _state_points(
if standing is not None:
stated.append({"id": standing["id"], "pov": point["pov"]})
continue
+ if point.get("proposed"):
+ continue
if not auto:
# the point moved somewhere the case cannot hold yet: the old claim is
# withdrawn either way, and the new one waits on the analyst's yes
diff --git a/src/azimut/api/settings.py b/src/azimut/api/settings.py
index fbbf062..6f5738c 100644
--- a/src/azimut/api/settings.py
+++ b/src/azimut/api/settings.py
@@ -33,7 +33,7 @@ from ..engine import (
workspacemove,
)
from .templates import MAX_PER_KIND as MAX_TEMPLATES_PER_KIND
-from ..engine.analysis_models import DetectPrefs, Recipe
+from ..engine.analysis_models import DetectPrefs, Recipe, stored
# A backup carries the signature logo as base64: 4 characters per 3 bytes, plus
# slack for padding and any line breaks a hand-edited file picked up.
@@ -125,6 +125,14 @@ class PrefsIn(BaseModel):
export_dirs: dict[str, str] | None = None
+def _detect_view(saved: Any) -> dict[str, Any]:
+ """Detect's saved view in the shape the prefs PUT takes back."""
+ try:
+ return stored(DetectPrefs, saved).model_dump()
+ except ValueError:
+ return dict(config.DEFAULT_SETTINGS["detect_view"])
+
+
def _prefs(settings: dict[str, Any]) -> dict[str, Any]:
"""The preference block shared by GET /settings and PUT /settings/prefs."""
return {
@@ -139,7 +147,7 @@ def _prefs(settings: dict[str, Any]) -> dict[str, Any]:
"units": settings.get("units", "metric"),
"home_view": settings.get("home_view", DEFAULT_HOME_VIEW),
"map_sync": bool(settings.get("map_sync", True)),
- "detect_view": settings.get("detect_view", config.DEFAULT_SETTINGS["detect_view"]),
+ "detect_view": _detect_view(settings.get("detect_view")),
"sentinel1_layer": settings.get("sentinel1_layer", ""),
"capture_scale_north": bool(settings.get("capture_scale_north", False)),
"proof_place_auto": bool(settings.get("proof_place_auto", True)),
@@ -655,6 +663,33 @@ class ImportedSettings(BaseModel):
update_dismissed_version: str = Field(default="", max_length=64)
download_cookies: ImportedDownloadCookies = Field(default_factory=ImportedDownloadCookies)
+ @field_validator("analyzers", mode="before")
+ @classmethod
+ def readable_analyzers(cls, value: Any) -> Any:
+ """Analyzers read the way the library reads its own.
+
+ A field a later version dropped is ignored, and one that no longer reads
+ at all is left out, as the library leaves it out, rather than refusing
+ the whole backup over it.
+ """
+ if not isinstance(value, list):
+ return value
+ kept = []
+ for raw in value:
+ try:
+ kept.append(stored(Recipe, raw))
+ except ValueError:
+ continue
+ return kept
+
+ @field_validator("detect_view", mode="before")
+ @classmethod
+ def readable_detect_view(cls, value: Any) -> Any:
+ try:
+ return stored(DetectPrefs, value)
+ except ValueError:
+ return DetectPrefs()
+
@field_validator("api_keys")
@classmethod
def canonical_keys(cls, value: dict[str, str]) -> dict[str, str]:
diff --git a/src/azimut/engine/analysis_geometry.py b/src/azimut/engine/analysis_geometry.py
index 2b2b2f9..da068c5 100644
--- a/src/azimut/engine/analysis_geometry.py
+++ b/src/azimut/engine/analysis_geometry.py
@@ -89,10 +89,10 @@ def footprint(mask: Any, x: int, y: int, z: int, size: int, offset=(0, 0)) -> di
"type": "MultiPolygon", "coordinates": polygons}
-def joined(a: dict[str, Any], b: dict[str, Any]) -> dict[str, Any]:
+def joined_all(shapes: list[dict[str, Any]]) -> dict[str, Any]:
def parts(shape: dict[str, Any]) -> list:
return [shape["coordinates"]] if shape["type"] == "Polygon" else shape["coordinates"]
- return {"type": "MultiPolygon", "coordinates": parts(a) + parts(b)}
+ return {"type": "MultiPolygon", "coordinates": [part for shape in shapes for part in parts(shape)]}
def interior(geometry: dict[str, Any], preferred: tuple[float, float]) -> tuple[float, float]:
diff --git a/src/azimut/engine/analysis_models.py b/src/azimut/engine/analysis_models.py
index 876fc0c..ca34d25 100644
--- a/src/azimut/engine/analysis_models.py
+++ b/src/azimut/engine/analysis_models.py
@@ -11,7 +11,7 @@ from __future__ import annotations
import math
from datetime import date
-from typing import Annotated, Any, Literal
+from typing import Annotated, Any, Literal, TypeVar
from pydantic import (
BaseModel,
@@ -19,6 +19,8 @@ from pydantic import (
Field,
FiniteFloat,
SerializerFunctionWrapHandler,
+ ValidationError,
+ ValidationInfo,
field_validator,
model_serializer,
model_validator,
@@ -73,9 +75,35 @@ def sensor_for(method: str) -> str:
return "sentinel1" if method in RADAR_METHODS else "sentinel2"
+#: Validation context for data Azimut wrote itself and reads back (`stored`).
+STORED = {"stored": True}
+
+
class Model(BaseModel):
model_config = ConfigDict(extra="forbid", allow_inf_nan=False)
+ @model_validator(mode="before")
+ @classmethod
+ def _known_fields(cls, data: Any, info: ValidationInfo) -> Any:
+ """Drop the fields this version does not know, when the data is Azimut's own.
+
+ A request naming an unknown field is a bug in its caller and is refused.
+ A saved run, routine or analyzer is history instead: a field an earlier
+ version wrote and a later one dropped must not make it unreadable, and
+ one such run once turned every launch in its case into a server error.
+ """
+ if isinstance(data, dict) and isinstance(info.context, dict) and info.context.get("stored"):
+ return {key: value for key, value in data.items() if key in cls.model_fields}
+ return data
+
+
+M = TypeVar("M", bound=Model)
+
+
+def stored(model: type[M], data: Any) -> M:
+ """Read back something Azimut saved, ignoring the fields it no longer has."""
+ return model.model_validate(data, context=STORED)
+
#: Map layers that no longer exist. A saved preference or a settings backup that
#: still names one drops it rather than being refused: CARTO's labels went when
@@ -138,14 +166,15 @@ class Parameters(Model):
# pieces grouped. The panel applies these; nothing stores which size was picked.
_SIZE_KEYS = ("min_area", "max_area", "cleanup", "smoothing", "merge_metres")
#: No floor and no ceiling, so nothing is dropped for its size. A mark that
-#: falls between two sizes is the one an analyst hunts for and never sees.
+#: falls between two sizes is the one an analyst hunts for and never sees, so
+#: this is where every built-in starts.
_ALL = dict(zip(_SIZE_KEYS, (0.0, 0.0, 0, 0, 0.0)))
-def _sizes(*rows: tuple[float, float, int, int, float]) -> dict[str, dict[str, float]]:
+def _sizes(*rows: tuple[float, float, int, int, float], averaging: int = 0) -> dict[str, dict[str, float]]:
named = {name: dict(zip(_SIZE_KEYS, row))
for name, row in zip(("small", "medium", "large"), rows)}
- return {**named, "all": dict(_ALL)}
+ return {**named, "all": {**_ALL, "smoothing": averaging}}
_CHANGE_SIZES = _sizes((300, 0, 0, 0, 0), (2000, 0, 1, 0, 30), (20000, 0, 1, 1, 100))
@@ -160,7 +189,10 @@ SIZES: dict[str, dict[str, dict[str, float]]] = {
# works against: for radar change a step of it is 45 m of ground
# (`SAR_WINDOW_M`), and a small target keeps the finest window.
"sar-vessels": _sizes((0, 150_000, 0, 0, 30), (250, 150_000, 0, 0, 50), (2500, 400_000, 0, 0, 100)),
- "sar-change": _sizes((300, 0, 0, 1, 0), (2000, 0, 1, 2, 30), (20000, 0, 1, 3, 100)),
+ # All keeps Medium's 90 m of averaging: it is what took Istanbul's false
+ # "razed" from 111 to 25 (`analyzers.SAR_WINDOW_M`), and All is the size a
+ # detection starts at, so it drops the size limits and not that.
+ "sar-change": _sizes((300, 0, 0, 1, 0), (2000, 0, 1, 2, 30), (20000, 0, 1, 3, 100), averaging=2),
# Your own rules measure change like the index methods do. Radar rules
# take radar change's sizes instead (`METHODS`, the panel picks them).
"rules": _CHANGE_SIZES,
@@ -510,7 +542,16 @@ class RunInput(Model):
def _as_recipe(recipe: Recipe | dict[str, Any]) -> Recipe:
- return recipe if isinstance(recipe, Recipe) else Recipe.model_validate(recipe)
+ # A request's recipe is already a model; a dict is one read off disk.
+ return recipe if isinstance(recipe, Recipe) else stored(Recipe, recipe)
+
+
+def unreadable(exc: ValidationError) -> str:
+ """The first thing a saved detection fails on, in one line an analyst can act on."""
+ error = exc.errors()[0]
+ where = " › ".join(str(part) for part in error.get("loc", ()) if part != "body")
+ reason = str(error.get("msg", "")).removeprefix("Value error, ")
+ return f"{where}: {reason}" if where and error.get("type") != "value_error" else reason
def is_radar(recipe: Recipe | dict[str, Any]) -> bool:
@@ -576,7 +617,7 @@ def frames_for(recipe: Recipe | dict[str, Any]) -> int:
return (1 if is_single(recipe) else 2) * (1 + len(recipe_products(recipe)))
-def _recipe(size: str = "medium", **fields: Any) -> Recipe:
+def _recipe(size: str = "all", **fields: Any) -> Recipe:
parameters = {**SIZES[fields["method"]][size], **fields.pop("parameters", {})}
return Recipe(parameters=Parameters(**parameters), **fields)
@@ -625,6 +666,19 @@ BUILTINS = [
description="Ground that now reads as open water in the modified water index.",
parameters={"sensitivity": 56, "index": "mndwi", "direction": "gain"},
colour="#0ea5e9"),
+ # Construction's reading, darkening only and at a firmer line: a 9% drop in
+ # every band. On pairs from Planetary Computer it took Hodeidah's burned tank
+ # farm (July 2024) whole, an Isfahan depot and its soot with a hangar beside
+ # it (spring 2026), and Beirut's blasted port warehouses (August 2020).
+ # Hodeidah, Saky and Isfahan days apart with nothing happening gave one to
+ # three. A Dubai pair after April 2024's rain gave two hundred, which is why
+ # it says so.
+ _recipe(id="burned-buildings", name="Burned or destroyed buildings", method="structure",
+ phenomenon="Burn or blast mark",
+ description="Ground and roofs that went darker in every band: soot, char and "
+ "wreckage. Rain-wet ground darkens too, and a roof that fell without burning "
+ "rarely shows.",
+ parameters={"sensitivity": 60, "direction": "loss"}, colour="#b45309"),
# Sentinel-1. The radar sees through cloud and at night, and a metal hull
# or a standing wall answers it far louder than water or open ground.
_recipe(id="radar-vessels", name="Vessels by radar", method="sar-vessels",
@@ -649,6 +703,7 @@ BUILTINS = [
"vehicles, containers, moored ships.",
parameters={"sensitivity": 60, "direction": "gain", "sar_ground": "bright"},
colour="#eab308"),
+ # A flood is fields wide: without a floor it comes back in hundreds of pieces.
_recipe("large", id="radar-flood", name="Flooding by radar", method="sar-change",
phenomenon="New open water (radar)",
description="Ground that went as radar-dark as calm water, under the cloud a flood "
@@ -663,7 +718,8 @@ GROUPS: list[tuple[str, str, list[str]]] = [
("vessels", "Vessels", ["radar-vessels", "boats"]),
("fire", "Fires and burns", ["anomaly", "burn-scars"]),
("water", "Water and floods", ["radar-flood", "new-water"]),
- ("built", "Buildings and earthworks", ["structures", "radar-new-objects", "radar-razed"]),
+ ("built", "Buildings and earthworks", ["structures", "radar-new-objects", "radar-razed",
+ "burned-buildings"]),
("ground", "Vegetation and small marks", ["vegetation-loss", "impacts"]),
("any", "Any change", ["radar-change", "large-change"]),
]
@@ -679,6 +735,7 @@ RELIABILITY: dict[str, Literal["reliable", "approximate", "rough"]] = {
"anomaly": "reliable", "burn-scars": "reliable",
"radar-flood": "reliable", "new-water": "approximate",
"structures": "approximate", "radar-new-objects": "approximate", "radar-razed": "rough",
+ "burned-buildings": "rough",
"vegetation-loss": "reliable", "impacts": "rough",
"radar-change": "rough", "large-change": "rough",
}
diff --git a/src/azimut/engine/analyzers.py b/src/azimut/engine/analyzers.py
index 27033db..e3fb7d1 100644
--- a/src/azimut/engine/analyzers.py
+++ b/src/azimut/engine/analyzers.py
@@ -28,6 +28,7 @@ from typing import Any
import httpx
from PIL import Image
+from pydantic import ValidationError
from .. import config, layout
from ..workspace import Case
@@ -40,7 +41,9 @@ from .analysis_models import (
Area,
AreaDates,
AreaGeometry,
+ Model,
Parameters,
+ Recipe,
RunInput,
Source,
Zone,
@@ -48,6 +51,8 @@ from .analysis_models import (
is_single,
recipe_products,
recipe_sensor,
+ stored,
+ unreadable,
)
# What one run may sweep. The ceiling is not memory — tiles are read one at a
@@ -269,9 +274,68 @@ def read(case: Case, kind: str, ident: str) -> dict[str, Any]:
saved["zones"], saved["area_dates"] = zones, kept
if missing:
saved["missing_areas"] = missing
+ return current(saved)
+ if kind == "runs" and isinstance(saved.get("input"), dict):
+ saved["input"] = current(saved["input"])
return saved
+#: The parts of a saved detection that editing it sends back as they were read.
+PARTS: dict[str, type[Model]] = {"recipe": Recipe, "a": Source, "b": Source}
+LISTS: dict[str, type[Model]] = {"zones": Zone, "area_dates": AreaDates}
+
+
+def _today(model: type[Model], part: Any) -> Any:
+ try:
+ model.model_validate(part)
+ return part
+ except ValueError:
+ pass
+ try:
+ return stored(model, part).model_dump()
+ except ValueError:
+ return part
+
+
+def current(body: dict[str, Any]) -> dict[str, Any]:
+ """A saved detection with its parts in the shape this version reads.
+
+ Editing a routine or a run sends its recipe, dates and areas back to a route
+ that refuses any field it does not know, so a field an earlier version wrote
+ has to be gone before they leave. A part that reads as it is stays untouched,
+ and one that no longer reads at all is left for the route to refuse with its
+ reason.
+ """
+ body = dict(body)
+ for key, model in PARTS.items():
+ if isinstance(body.get(key), dict):
+ body[key] = _today(model, body[key])
+ for key, model in LISTS.items():
+ if isinstance(body.get(key), list):
+ body[key] = [_today(model, part) for part in body[key]]
+ return body
+
+
+def ready_runs(case: Case, followup_id: str | None = None) -> list[tuple[dict[str, Any], dict[str, Any]]]:
+ """Every finished run, as its list row and its record, newest first.
+
+ Something reading other runs to decide about this one (a repeat, the pass
+ before, what a routine found) skips a run it cannot read, rather than let
+ that one run fail every launch in the case.
+ """
+ found = []
+ for row in listing(case, "runs"):
+ if row.get("status") != "ready" or (followup_id and row.get("followup_id") != followup_id):
+ continue
+ try:
+ run = read(case, "runs", row["id"])
+ except (OSError, ValueError):
+ continue
+ if isinstance(run.get("input"), dict):
+ found.append((row, run))
+ return found
+
+
def area_zone(area: dict[str, Any]) -> Zone:
return Zone(id=area["id"], name=area["name"], kind="polygon",
points=area["geometry"]["coordinates"][0][:-1])
@@ -284,7 +348,7 @@ def share_areas(case: Case, data: dict[str, Any], ident: str) -> dict[str, Any]:
linked = []
zones = data.get("zones") or data.get("recipe", {}).get("zones") or []
for raw in zones:
- zone = Zone.model_validate(raw)
+ zone = stored(Zone, raw)
try:
read(case, "areas", zone.id)
area_id = zone.id
@@ -378,10 +442,7 @@ def findings(case: Case, followup_id: str) -> list[dict[str, Any]]:
separate sweeps, but what they found is one growing list, and this is it.
"""
rows: list[dict[str, Any]] = []
- for summary in listing(case, "runs"):
- if summary.get("followup_id") != followup_id or summary.get("status") != "ready":
- continue
- run = read(case, "runs", summary["id"])
+ for _, run in ready_runs(case, followup_id):
day = (run["input"].get("b") or {}).get("date", "")
for result in run.get("results", []):
if result.get("review") not in KEPT:
@@ -948,7 +1009,7 @@ def _changes(before: Any, after: Any, valid: Any) -> tuple[Any, Any]:
return stacked, stacked.mean(-1)
-def _spots(before: Any, after: Any, valid: Any, metres: float, threshold: float,
+def _spots(before: Any, after: Any, valid: Any, seen: Any, metres: float, threshold: float,
options: Parameters) -> tuple[Any, Any, Any]:
"""Change against the change around it, and whether the surroundings held.
@@ -957,10 +1018,14 @@ def _spots(before: Any, after: Any, valid: Any, metres: float, threshold: float,
takes the target itself for background, and a 90 m mark in the Yemeni desert
then measured 3.5% where it had really moved 7%.
- Only pixels the sweep can measure feed that ring. Where a granule ends or a
- cloud sits, one date has ground and the other has nothing, and letting that
- difference into the background raised every neighbour it reached: a quiet
- tile cut in half by a granule edge produced a candidate the size of the cut.
+ Only imaged ground feeds that ring, `seen`, which runs past the area and
+ into the tile's padding. Where a granule ends or a cloud sits, one date has
+ ground and the other has nothing, and letting that difference into the
+ background raised every neighbour it reached: a quiet tile cut in half by a
+ granule edge produced a candidate the size of the cut. The ground past the
+ area's edge was imaged all the same, and counting it as ground that held
+ still made the sliver of every field the edge cut look isolated, which
+ lined an airbase's edge with candidates.
"""
import cv2
import numpy as np
@@ -973,15 +1038,16 @@ def _spots(before: Any, after: Any, valid: Any, metres: float, threshold: float,
residual, moved = [], []
for old, new in zip(_reflectance(before), _reflectance(after)):
delta = (new - old).astype(np.float64)
- mean, _, share = ring_statistics(delta, valid, ring, guard)
+ mean, _, share = ring_statistics(delta, seen, ring, guard)
residual.append(np.where(share > 0, delta - mean, 0.0))
# The passes' overall shift in light is not the neighbourhood changing.
shift = float(np.median(delta[valid])) if valid.any() else 0.0
moved.append(delta - max(-MAX_SHIFT, min(MAX_SHIFT, shift)))
spot = np.stack(residual, -1)
changed = ((np.sqrt((np.stack(moved, -1) ** 2).mean(-1)) >= threshold * GROW)
- & valid).astype(np.float32)
- share = cv2.blur(changed, (wide, wide))
+ & seen).astype(np.float32)
+ imaged = cv2.blur(seen.astype(np.float32), (wide, wide))
+ share = cv2.blur(changed, (wide, wide)) / np.maximum(imaged, 1e-6)
return np.sqrt((spot ** 2).mean(-1)), spot.mean(-1), share < SPOT_SHARE
@@ -1076,24 +1142,26 @@ def sar_window(smoothing: int, metres: float) -> int:
return max(3, round(SAR_WINDOW_M * max(1, smoothing) / metres) | 1)
-def _sar_change(before: Any, after: Any, valid: Any, metres: float,
+def _sar_change(before: Any, after: Any, valid: Any, seen: Any, metres: float,
options: Parameters) -> tuple[Any, Any, Any, float, dict[str, tuple[Any, str]]]:
"""Backscatter that moved between two passes of one track, in decibels.
Both passes are averaged as power over the same ground before they are
- compared, so speckle does not read as change. What the recipe's ground
- setting asks for then gates it: bright ground on the side that has it, or
- water coming or going.
+ compared, so speckle does not read as change. That ground is all the radar
+ imaged, `seen`, past the area's edge too, so a pixel by the edge averages
+ as many samples as any other. What the recipe's ground setting asks for
+ then gates it: bright ground on the side that has it, or water coming or
+ going.
"""
import numpy as np
window = sar_window(options.smoothing, metres)
- old = _power_mean(before[:, :, 0], valid, window)
- new = _power_mean(after[:, :, 0], valid, window)
+ old = _power_mean(before[:, :, 0], seen, window)
+ new = _power_mean(after[:, :, 0], seen, window)
# Both polarisations vote: a building that falls or a field that floods
# darkens in each, while speckle in one is not speckle in the other.
- delta = (new - old + _power_mean(after[:, :, 1], valid, window)
- - _power_mean(before[:, :, 1], valid, window)) / 2
+ delta = (new - old + _power_mean(after[:, :, 1], seen, window)
+ - _power_mean(before[:, :, 1], seen, window)) / 2
shift = float(np.median(delta[valid])) if valid.any() else 0.0
delta = delta - max(-MAX_SAR_SHIFT, min(MAX_SAR_SHIFT, shift))
ground = options.sar_ground
@@ -1146,14 +1214,16 @@ def detect(pictures: tuple[Any, Any], products: tuple[Any, Any], mask: Any, body
binary, stat, threshold, measures = _sar_vessels(products[1], water, inside, metres, options)
else:
before, after = products
- valid = inside & ~blocked
+ # Ground both passes imaged, inside the area or past it: what a change is
+ # read against. Only the area can hold a candidate.
+ seen = (before[:, :, 0] > 0) & (after[:, :, 0] > 0) & ~blocked
+ valid = inside & seen
if method == "sar-change":
- valid &= (before[:, :, 0] > 0) & (after[:, :, 0] > 0)
- stat, signed, state, threshold, measures = _sar_change(before, after, valid, metres, options)
+ stat, signed, state, threshold, measures = _sar_change(before, after, valid, seen,
+ metres, options)
elif method == "index":
old = before[:, :, 0].astype(np.float32) / 127.5 - 1
new = after[:, :, 0].astype(np.float32) / 127.5 - 1
- valid &= (before[:, :, 0] > 0) & (after[:, :, 0] > 0)
delta = new - old
absent, present = INDEX_STATES[options.index]
gone, came = new < absent, old < absent
@@ -1167,13 +1237,12 @@ def detect(pictures: tuple[Any, Any], products: tuple[Any, Any], mask: Any, body
signed = delta
measures = {"before": (old, "mean"), "after": (new, "mean")}
else:
- valid &= (before[:, :, 0] > 0) & (after[:, :, 0] > 0)
state = np.ones(valid.shape, bool)
# In reflectance: 2% is noise over bright desert in a week, 20% is
# a new roof on sand.
threshold = _scale(options.sensitivity, 0.02, 0.2)
if method == "spots":
- stat, signed, state = _spots(before, after, valid, metres, threshold, options)
+ stat, signed, state = _spots(before, after, valid, seen, metres, threshold, options)
measures = {"signed": (signed * 100, "mean")}
else:
deltas, signed = _changes(before, after, valid)
@@ -1192,9 +1261,14 @@ def detect(pictures: tuple[Any, Any], products: tuple[Any, Any], mask: Any, body
if options.direction != "both":
valid &= signed > 0 if options.direction == "gain" else signed < 0
stat = np.clip(stat, -10, 10).astype(np.float32)
- # Radar change was already averaged as power over this window.
+ # Radar change was already averaged as power over this window. The blur
+ # only averages imaged ground, so a granule's end does not bleed into
+ # the pixels beside it.
if options.smoothing and method not in RADAR_METHODS:
- stat = cv2.GaussianBlur(stat, (options.smoothing * 2 + 1,) * 2, 0)
+ blur = (options.smoothing * 2 + 1,) * 2
+ total = cv2.GaussianBlur(np.where(seen, stat, 0).astype(np.float32), blur, 0)
+ weight = cv2.GaussianBlur(seen.astype(np.float32), blur, 0)
+ stat = np.where(weight > 1e-3, total / np.maximum(weight, 1e-3), 0).astype(np.float32)
grow = valid & (np.abs(signed if method == "structure" else stat) >= threshold * GROW)
binary = hysteresis(valid & state & (stat >= threshold), grow & state)
if options.cleanup:
@@ -1275,40 +1349,145 @@ def keeps(row: dict[str, Any], options: Parameters) -> bool:
return ratio <= COMPACT_MAX if options.shape == "compact" else ratio >= ELONGATED_MIN
+# Two outlines closer than this, in metres, touch: pieces of one component cut
+# by a tile seam share the seam's edge exactly.
+TOUCH_M = 0.01
+
+
+def _outline(row: dict[str, Any]) -> Any:
+ """Every edge of a candidate's footprint as (x0, y0, x1, y1), in metres of
+ the Mercator plane, or None for a candidate without one."""
+ import numpy as np
+
+ geometry = row.get("geometry")
+ if not geometry or geometry.get("type") not in ("Polygon", "MultiPolygon"):
+ return None
+ polygons = [geometry["coordinates"]] if geometry["type"] == "Polygon" else geometry["coordinates"]
+ edges = []
+ for polygon in polygons:
+ for ring in polygon:
+ points = np.array([mercator(lon, lat) for lon, lat in ring], np.float64) * WORLD
+ if len(points) and (points[0] != points[-1]).any():
+ points = np.vstack([points, points[:1]])
+ if len(points) > 1:
+ edges.append(np.hstack([points[:-1], points[1:]]))
+ return np.vstack(edges) if edges else None
+
+
+def _within(first: Any, second: Any, reach: float) -> bool:
+ """Whether two outlines come within `reach` of each other anywhere.
+
+ Outlines of different components never cross, so the gap between them is
+ always measured from a corner of one to an edge of the other.
+ """
+ import numpy as np
+
+ def bounds(edges: Any) -> Any:
+ return np.array([np.minimum(edges[:, 0], edges[:, 2]).min(), np.minimum(edges[:, 1], edges[:, 3]).min(),
+ np.maximum(edges[:, 0], edges[:, 2]).max(), np.maximum(edges[:, 1], edges[:, 3]).max()])
+
+ def corners_to_edges(corners: Any, edges: Any) -> bool:
+ box = bounds(edges)
+ corners = corners[(corners[:, 0] >= box[0] - reach) & (corners[:, 0] <= box[2] + reach)
+ & (corners[:, 1] >= box[1] - reach) & (corners[:, 1] <= box[3] + reach)]
+ if not len(corners):
+ return False
+ near = bounds(np.hstack([corners, corners]))
+ edges = edges[(np.maximum(edges[:, 0], edges[:, 2]) >= near[0] - reach)
+ & (np.minimum(edges[:, 0], edges[:, 2]) <= near[2] + reach)
+ & (np.maximum(edges[:, 1], edges[:, 3]) >= near[1] - reach)
+ & (np.minimum(edges[:, 1], edges[:, 3]) <= near[3] + reach)]
+ if not len(edges):
+ return False
+ start, step = edges[:, :2], edges[:, 2:] - edges[:, :2]
+ length = np.maximum((step ** 2).sum(-1), 1e-12)
+ # Blocks keep the corner-by-edge table to a few million entries.
+ for block in range(0, len(corners), max(1, 2_000_000 // len(edges))):
+ points = corners[block:block + max(1, 2_000_000 // len(edges)), None, :]
+ t = np.clip(((points - start) * step).sum(-1) / length, 0, 1)
+ gap = points - (start + t[..., None] * step)
+ if ((gap ** 2).sum(-1) <= reach * reach).any():
+ return True
+ return False
+
+ return corners_to_edges(first[:, :2], second) or corners_to_edges(second[:, :2], first)
+
+
def merge(rows: list[dict[str, Any]], distance: float) -> list[dict[str, Any]]:
- """Join touching seam components or explicitly requested nearby candidates.
+ """Join candidates whose footprints come within `distance` metres, and at
+ zero the pieces of one component that a tile seam cut apart.
+
+ The gap is measured between the footprints themselves. Boxes alone once
+ joined everything: two boxes overlap without their shapes touching, and
+ each join grew the box that the next one was tested against, until the
+ 667 marks of an airbase's seasonal pair became one candidate of 31 km²,
+ which its size then dropped.
- A joined candidate keeps the reading of its stronger half: the margin is
+ A joined candidate keeps the reading of its stronger part: the margin is
how far the best of it got past the line, and that is what it is sorted by.
"""
+ count = len(rows)
+ parent = list(range(count))
+
+ def root(i: int) -> int:
+ while parent[i] != i:
+ parent[i] = parent[parent[i]]
+ i = parent[i]
+ return i
+
+ outlines: dict[int, Any] = {}
+
+ def outline(i: int) -> Any:
+ if i not in outlines:
+ outlines[i] = _outline(rows[i])
+ return outlines[i]
+
+ reach = [0.0] * count
+ dx = [0.0] * count
+ dy = distance / 111_320
+ for i, row in enumerate(rows):
+ lat = (row["bbox"][1] + row["bbox"][3]) / 2
+ # Mercator metres run longer than ground metres by 1 / cos(latitude).
+ reach[i] = (distance + TOUCH_M) / max(.08, math.cos(math.radians(lat)))
+ dx[i] = dy / max(.08, math.cos(math.radians(lat)))
+ widest = max(dx, default=0.0)
+ active: list[int] = []
+ for i in sorted(range(count), key=lambda k: rows[k]["bbox"][0]):
+ a = rows[i]["bbox"]
+ active = [j for j in active if rows[j]["bbox"][2] + widest + 1e-10 >= a[0]]
+ for j in active:
+ b = rows[j]["bbox"]
+ if root(i) == root(j):
+ continue
+ if not (a[0] <= b[2] + dx[i] + 1e-10 and b[0] <= a[2] + dx[i] + 1e-10
+ and a[1] <= b[3] + dy + 1e-10 and b[1] <= a[3] + dy + 1e-10):
+ continue
+ first, second = outline(i), outline(j)
+ if first is None or second is None or _within(first, second, max(reach[i], reach[j])):
+ parent[root(i)] = root(j)
+ active.append(i)
+
+ groups: dict[int, list[int]] = {}
+ for i in range(count):
+ groups.setdefault(root(i), []).append(i)
+ if len(groups) > MAX_RESULTS * 2:
+ raise ValueError("too many candidates; reduce the area or pick a larger size")
kept: list[dict[str, Any]] = []
- for row in rows:
- i = 0
- while i < len(kept):
- other = kept[i]
- a, b = row["bbox"], other["bbox"]
- lat = (a[1] + a[3]) / 2
- dy = distance / 111_320
- dx = dy / max(.08, math.cos(math.radians(lat)))
- if a[0] <= b[2] + dx + 1e-10 and b[0] <= a[2] + dx + 1e-10 and \
- a[1] <= b[3] + dy + 1e-10 and b[1] <= a[3] + dy + 1e-10:
- kept.pop(i)
- if other["margin"] > row["margin"]:
- row.update(margin=other["margin"], strength=other["strength"],
- measure=other["measure"])
- row["area"] += other["area"]
- row["bbox"] = [min(a[0], b[0]), min(a[1], b[1]), max(a[2], b[2]), max(a[3], b[3])]
- row["parts"].extend(other["parts"])
- if "geometry" in row and "geometry" in other:
- row["geometry"] = analysis_geometry.joined(row["geometry"], other["geometry"])
- a = row["bbox"]
- row["coordinates"] = [(a[0] + a[2]) / 2, (a[1] + a[3]) / 2]
- i = 0
- else:
- i += 1
+ for members in sorted(groups.values(), key=lambda group: group[0]):
+ row = rows[members[0]]
+ if len(members) > 1:
+ parts = [rows[i] for i in members]
+ best = max(parts, key=lambda part: part["margin"])
+ boxes = [part["bbox"] for part in parts]
+ box = [min(b[0] for b in boxes), min(b[1] for b in boxes),
+ max(b[2] for b in boxes), max(b[3] for b in boxes)]
+ row.update(margin=best["margin"], strength=best["strength"], measure=best["measure"],
+ area=sum(part["area"] for part in parts), bbox=box,
+ coordinates=[(box[0] + box[2]) / 2, (box[1] + box[3]) / 2],
+ parts=[piece for part in parts for piece in part["parts"]])
+ if all("geometry" in part for part in parts):
+ row["geometry"] = analysis_geometry.joined_all([part["geometry"] for part in parts])
kept.append(row)
- if len(kept) > MAX_RESULTS * 2:
- raise ValueError("too many candidates; reduce the area or pick a larger size")
return kept
@@ -1341,23 +1520,23 @@ def previous_pass(case: Case, body: RunInput) -> Source:
if not body.followup_id:
return body.a
best: tuple[tuple[str, str], Source] | None = None
- for summary in listing(case, "runs"):
- if summary.get("followup_id") != body.followup_id or summary.get("status") != "ready":
- continue
- previous = read(case, "runs", summary["id"])
+ for summary, previous in ready_runs(case, body.followup_id):
area_id = body.zones[0].id
- if previous.get("area_runs"):
- area = next((p for p in previous["area_runs"] if p["area_id"] == area_id
- and p["status"] == "ready"), None)
- if not area:
- continue
- candidate = Source.model_validate(area["b"])
- else:
- if not any(z["id"] == area_id or hashlib.sha256(
- f"{body.followup_id}:{z['id']}".encode()).hexdigest()[:12] == area_id
- for z in previous["input"].get("zones", [])):
- continue
- candidate = Source.model_validate(previous["input"]["b"])
+ try:
+ if previous.get("area_runs"):
+ area = next((p for p in previous["area_runs"] if p["area_id"] == area_id
+ and p["status"] == "ready"), None)
+ if not area:
+ continue
+ candidate = stored(Source, area["b"])
+ else:
+ if not any(z["id"] == area_id or hashlib.sha256(
+ f"{body.followup_id}:{z['id']}".encode()).hexdigest()[:12] == area_id
+ for z in previous["input"].get("zones", [])):
+ continue
+ candidate = stored(Source, previous["input"]["b"])
+ except (KeyError, ValueError):
+ continue
if candidate.layer != body.b.layer or not candidate.date:
continue
if body.b.date and candidate.date >= body.b.date:
@@ -1542,14 +1721,22 @@ def prepare_areas(case: Case, body: RunInput) -> tuple[RunInput, list[dict[str,
return body.model_copy(update={"area_dates": pairs}), outcomes
+def _same_pass(saved: Any, asked: dict[str, Any]) -> bool:
+ """Whether a pass a run recorded is the one asked for, read as this version reads it."""
+ try:
+ return stored(Source, saved).model_dump() == asked
+ except ValueError:
+ return False
+
+
def duplicates(case: Case, body: RunInput, outcomes: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Exact geometry, recipe and source pairs only; overlapping dates do not match."""
found = []
- for summary in listing(case, "runs"):
- if summary.get("status") != "ready":
- continue
- run = read(case, "runs", summary["id"])
- old = RunInput.model_validate(run["input"])
+ for _, run in ready_runs(case):
+ try:
+ old = stored(RunInput, run["input"])
+ except ValueError:
+ continue # a run this version cannot read is not the one being launched
if old.recipe.model_dump() != body.recipe.model_dump():
continue
for outcome in outcomes:
@@ -1561,9 +1748,9 @@ def duplicates(case: Case, body: RunInput, outcomes: list[dict[str, Any]]) -> li
continue
records = run.get("area_runs") or [{"area_id": zone.id, "status": "ready",
"a": old.a.model_dump(), "b": old.b.model_dump()}]
- match = next((r for r in records if r["area_id"] == zone.id and r["status"] == "ready"
- and r["b"] == outcome["b"] and
- (is_single(body.recipe) or r["a"] == outcome["a"])), None)
+ match = next((r for r in records if r.get("area_id") == zone.id and r.get("status") == "ready"
+ and _same_pass(r.get("b"), outcome["b"]) and
+ (is_single(body.recipe) or _same_pass(r.get("a"), outcome["a"]))), None)
if match:
found.append({"run_id": run["id"], "title": run["title"], "area_id": zone.id,
"area_name": zone.name, "a": outcome["a"], "b": outcome["b"]})
@@ -1575,7 +1762,11 @@ def execute(case: Case, job: dict[str, Any]) -> None:
check_active(case, ident)
run = read(case, "runs", ident)
try:
- original = hydrate(case, RunInput.model_validate(run["input"]))
+ try:
+ original = hydrate(case, stored(RunInput, run["input"]))
+ except ValidationError as exc:
+ raise ValueError(f"this detection no longer reads ({unreadable(exc)}); "
+ "edit it and run it again") from exc
outcomes = run.get("area_runs")
if outcomes is None:
_, outcomes = prepare_areas(case, original)
@@ -1593,8 +1784,8 @@ def execute(case: Case, job: dict[str, Any]) -> None:
continue
zone = next(zone for zone in original.zones if zone.id == outcome["area_id"])
body = for_area(original, zone).model_copy(update={
- "a": Source.model_validate(outcome["b"] if single else outcome["a"]),
- "b": Source.model_validate(outcome["b"]), "date_rule": "manual"})
+ "a": stored(Source, outcome["b"] if single else outcome["a"]),
+ "b": stored(Source, outcome["b"]), "date_rule": "manual"})
resolved.append(AreaDates(area_id=zone.id, a=body.a, b=body.b, date_rule="manual"))
if not single and body.a == body.b:
outcome.update(status="no_new_imagery", message=f"{zone.name}: No different dated imagery is available")
diff --git a/src/azimut/engine/satellite.py b/src/azimut/engine/satellite.py
index d077bef..50ee237 100644
--- a/src/azimut/engine/satellite.py
+++ b/src/azimut/engine/satellite.py
@@ -697,6 +697,8 @@ def _stated_once(spec: dict[str, Any]) -> list[dict[str, Any]]:
# nothing was typed, so the row carries no text: the composer shows the
# panels' own answer there and the reset arrow stays away, as it always has
point = {**frozen, "coords": ""} if frozen else None
+ if point is not None and isinstance(coords, dict) and coords.get("proposed") is True:
+ point["proposed"] = True
if point is None:
return []
return [{**point, "label": "", "pov": bool(spec.get("pov"))}]
@@ -737,6 +739,12 @@ def spec_points(spec: dict[str, Any]) -> list[dict[str, Any]]:
two entries a metre apart are one place, so the second is dropped rather than
drawn as a second mark on the same roof.
+ **``proposed`` marks a point nobody checked**: the middle of a capture the
+ composer read off the panels, which the analyst chose to save before looking at
+ it on the map. It rides along so the save can keep it off the case map. Absent
+ means checked, so every spec written before it and every road that states its
+ own point (a sheet row, an import) reads as the analyst's answer.
+
A spec holding no list falls back to the single point it was written with
(:func:`_stated_once`), so nothing has to be migrated and nothing that states
one point has to learn the list.
@@ -756,6 +764,8 @@ def spec_points(spec: dict[str, Any]) -> list[dict[str, Any]]:
point = _typed_point(entry.get("coords"))
if point is None:
continue
+ if entry.get("proposed") is True:
+ point["proposed"] = True
points.append(
{
**point,
@@ -937,6 +947,8 @@ def state_points(spec: dict[str, Any], entries: list[dict[str, Any]]) -> dict[st
point["label"] = label
if entry.get("pov"):
point["pov"] = True
+ if entry.get("proposed") is True:
+ point["proposed"] = True
points.append(point)
spec["points"] = points
first = points[0] if points else {}
diff --git a/tests/test_analyzers.py b/tests/test_analyzers.py
index de957bb..956927e 100644
--- a/tests/test_analyzers.py
+++ b/tests/test_analyzers.py
@@ -597,7 +597,10 @@ def test_every_method_publishes_sizes_and_words_for_its_reading():
assert all(entry["sizes"]["small"]["cleanup"] == 0 for entry in METHODS)
-def test_builtins_cover_big_and_small_things_and_start_at_medium():
+def test_builtins_cover_big_and_small_things_and_start_at_all_sizes():
+ """A size picked without noticing drops what falls outside it, so a
+ detection starts with none: Medium's 20 ha ceiling once dropped an
+ airbase's worth of change."""
ids = {recipe.id for recipe in BUILTINS}
assert {"boats", "anomaly", "structures", "impacts", "large-change", "burn-scars",
"vegetation-loss", "new-water"} <= ids
@@ -605,11 +608,19 @@ def test_builtins_cover_big_and_small_things_and_start_at_medium():
# out in some 280 pieces, so the radar flood detector starts at Large.
starts = {"radar-flood": "large"}
for recipe in BUILTINS:
- size = SIZES[recipe.method][starts.get(recipe.id, "medium")]
+ size = SIZES[recipe.method][starts.get(recipe.id, "all")]
assert {key: getattr(recipe.parameters, key) for key in size} == size, recipe.id
assert len(recipe.description) < 200, recipe.id
+def test_all_sizes_drops_the_limits_but_keeps_the_radar_averaging():
+ for method, sizes in SIZES.items():
+ assert sizes["all"]["min_area"] == sizes["all"]["max_area"] == 0, method
+ # the panel tells the sizes apart by their numbers
+ assert len({tuple(size.values()) for size in sizes.values()}) == 4, method
+ assert SIZES["sar-change"]["all"]["smoothing"] == SIZES["sar-change"]["medium"]["smoothing"]
+
+
# -- vessels ---------------------------------------------------------------------------
@@ -801,6 +812,24 @@ def test_construction_is_ground_that_moved_the_same_way_in_every_band(client, co
assert saved["results"][0]["measure"]["signed"] > 5
+def test_burned_buildings_are_ground_that_went_dark_in_every_band(client, copernicus):
+ """Soot, char and wreckage darken every band. A new roof brightens, the
+ desert drifting a few percent stays under the line, and a burned field is
+ Burn scars' to find."""
+ body = sentinel_input("burned-buildings")
+ before, after = surface(0.33, 0.39, 0.45, BARE), surface(0.33, 0.39, 0.45, BARE)
+ after[at(100, 100, 12, 12)] = code(0.20, 0.24, 0.30, BARE) # a burned hangar
+ after[at(300, 100, 12, 12)] = code(0.45, 0.50, 0.55, BARE) # a new bright roof
+ after[at(100, 300, 30, 30)] = code(0.30, 0.36, 0.42, BARE) # the desert drifting
+ before[at(300, 300, 30, 30)] = code(0.05, 0.40, 0.18) # a field...
+ after[at(300, 300, 30, 30)] = code(0.04, 0.12, 0.16, BARE) # ...that burned
+ seed(body, before, after)
+ saved = run(client, copernicus, body)
+ assert saved["status"] == "ready", saved
+ assert saved["count"] == 1, [(r["coordinates"], r["area"]) for r in saved["results"]]
+ assert saved["results"][0]["measure"]["signed"] < -9
+
+
def test_small_spots_are_found_where_everything_around_them_held_still(client, copernicus):
body = sentinel_input("impacts")
before, after = surface(0.20, 0.30, 0.30), surface(0.20, 0.30, 0.30)
@@ -847,18 +876,93 @@ def test_a_cloud_edge_is_not_a_spot(client, copernicus):
assert saved["count"] == 0, [(r["coordinates"], r["area"]) for r in saved["results"]]
+def test_a_field_the_area_edge_cuts_is_not_a_spot(client, copernicus):
+ """Past the area's edge nothing was measured, so it is not ground that held
+ still. Counted as still, it made the sliver of a field left inside the edge
+ look isolated, and lined an airbase's edge with candidates."""
+ before, after = surface(0.20, 0.30, 0.30), surface(0.20, 0.30, 0.30)
+ after[at(458, 150, 60, 120)] = code(0.35, 0.40, 0.45) # a field, 3 px of it inside
+ after[at(100, 100, 2, 2)] = code(0.08, 0.12, 0.10) # a real mark
+ body = sentinel_input("impacts", **SIZES["spots"]["all"])
+ seed(body, before, after)
+ saved = run(client, copernicus, body)
+ assert saved["status"] == "ready", saved
+ assert saved["count"] == 1, [(r["coordinates"], r["area"]) for r in saved["results"]]
+ assert saved["results"][0]["area"] < 500
+
+
+def test_smoothing_does_not_carry_a_granule_edge_into_the_ground_beside_it(client, copernicus):
+ """The blur averages measured ground only; nodata read as a change bled
+ into the pixels next to it and drew a line along the granule's end."""
+ before, after = surface(0.20, 0.28, 0.32), surface(0.20, 0.28, 0.32)
+ after[:, PAD + 300:] = 0
+ body = sentinel_input("structures", min_area=0, max_area=0, cleanup=0, smoothing=3,
+ merge_metres=0)
+ seed(body, before, after)
+ saved = run(client, copernicus, body)
+ assert saved["status"] == "ready", saved
+ assert saved["count"] == 0, [(r["coordinates"], r["area"]) for r in saved["results"]]
+
+
+def candidates_of(mask):
+ """The rows one tile's detection gives for `mask`, as a sweep builds them."""
+ reading = analyzers.Reading(binary=mask.astype(np.uint8), stat=mask.astype(np.float32),
+ threshold=0.5)
+ return analyzers._candidates(reading, "test", SENTINEL_TILE[1], SENTINEL_TILE[2], 0, [])
+
+
+def test_merging_measures_the_gap_between_footprints_not_their_boxes():
+ """A hollow mark's box holds the dots inside it, but its outline is far from
+ them. Joined by boxes, and each join growing the box the next was tested
+ against, an airbase's 667 marks became one candidate of 31 km²."""
+ mask = np.zeros((512, 512), bool)
+ mask[100:200, 100:104] = mask[100:104, 100:200] = mask[196:200, 100:200] = True # a C, 650 m wide
+ for x, y in ((140, 130), (160, 150), (140, 170), (170, 130), (170, 170)):
+ mask[y:y + 3, x:x + 3] = True # dots 200 m inside it
+ rows = candidates_of(mask)
+ assert len(rows) == 6
+ merged = analyzers.merge(rows, 20)
+ assert len(merged) == 6, [row["area"] for row in merged]
+
+
+def test_merging_joins_within_the_distance_and_not_past_it():
+ mask = np.zeros((512, 512), bool)
+ mask[100:104, 100:104] = mask[100:104, 106:110] = True # 2 px apart, about 13 m
+ mask[300:304, 100:104] = mask[300:304, 109:113] = True # 5 px apart, about 33 m
+ merged = analyzers.merge(candidates_of(mask), 20)
+ assert sorted(len(row["parts"]) for row in merged) == [1, 1, 2]
+ joined = next(row for row in merged if len(row["parts"]) == 2)
+ assert joined["bbox"][3] == max(row["bbox"][3] for row in merged) # the northern pair
+ assert joined["geometry"]["type"] == "MultiPolygon" and len(joined["geometry"]["coordinates"]) == 2
+
+
+def test_a_tile_edge_between_two_pieces_joins_them_even_at_zero():
+ left = np.zeros((512, 512), bool)
+ left[200:220, 492:512] = True
+ right = np.zeros((512, 512), bool)
+ right[200:220, 0:20] = True
+ right[400:404, 0:4] = True # touches nothing
+ z, x, y = SENTINEL_TILE
+ rows = candidates_of(left) + analyzers._candidates(
+ analyzers.Reading(binary=right.astype(np.uint8), stat=right.astype(np.float32), threshold=0.5),
+ "test", x + 1, y, 1, [])
+ piece = rows[0]["area"]
+ merged = analyzers.merge(rows, 0)
+ assert sorted(round(row["area"] / piece, 2) for row in merged) == [0.04, 2.0]
+
+
def test_a_mark_wider_than_its_window_still_reads_its_own_contrast(client, copernicus):
"""A median box the size of the target takes the target for its background.
The background is read from a ring with a hole in it instead, so a 90 m mark
- in the desert measures what it really moved. Small then drops it for its
+ in the desert measures what it really moved. Medium then drops it for its
size, with nothing to show for it — which is what All is for.
"""
ground = surface(0.37, 0.40, 0.55)
marked = surface(0.37, 0.40, 0.55)
marked[at(200, 200, 10, 10)] = code(0.29, 0.30, 0.45)
- body = sentinel_input("impacts")
+ body = sentinel_input("impacts", **SIZES["spots"]["medium"])
seed(body, ground, marked)
assert run(client, copernicus, body)["count"] == 0
diff --git a/tests/test_detect_saved_drift.py b/tests/test_detect_saved_drift.py
new file mode 100644
index 0000000..68f4762
--- /dev/null
+++ b/tests/test_detect_saved_drift.py
@@ -0,0 +1,173 @@
+"""Detect keeps working over what an earlier version saved.
+
+A run, a routine or an analyzer is written once and read back by every later
+version. One run that still carried a field the analyzer builder had renamed
+made every launch in its case a server error, because the repeat check read
+all the case's runs strictly. These gates plant such fields at every depth and
+walk each road that reads them back.
+"""
+
+import json
+
+import pytest
+
+from azimut.engine import analyzers, media, workqueue
+from azimut.engine.analysis_models import BUILTINS
+from analyzerfixture import seed_images
+from test_analyzers import run, scenario as analyzer_scenario
+
+
+def scenario(client, monkeypatch):
+ return analyzer_scenario.__wrapped__(client, monkeypatch)
+
+
+def rewrite(case, kind, ident, change):
+ path = case.resolve_inside(analyzers.relpath(kind, ident))
+ saved = json.loads(path.read_text(encoding="utf-8"))
+ change(saved)
+ media.write_json_atomic(path, saved)
+
+
+#: What DetectWizard's submit sends, each part as the saved detection had it.
+WIZARD = ("title", "note", "recipe", "a", "b", "zones", "area_dates", "date_rule", "offline")
+
+
+def drift(body):
+ """Fields no version of today's models knows, at every depth of a detection."""
+ body["recipe"]["tests"] = []
+ body["recipe"]["parameters"]["retired"] = 1
+ body["a"]["retired"] = "x"
+ body["b"]["retired"] = "x"
+ for zone in body.get("zones", []):
+ zone["retired"] = True
+ for pair in body.get("area_dates", []):
+ pair["retired"] = True
+ pair["b"]["retired"] = "x"
+ body["retired"] = True
+
+
+def test_a_run_with_fields_a_later_version_dropped_still_launches_reviews_and_repeats(client, scenario):
+ case, body = scenario
+ first = run(client, case, body)
+ base = f"/api/cases/{case.id}/analysis"
+
+ def old(saved):
+ drift(saved["input"])
+ for outcome in saved["area_runs"]:
+ outcome["b"]["retired"] = "x"
+ rewrite(case, "runs", first["id"], old)
+
+ # The launch that used to fail on the repeat check: the same detection is
+ # still recognised as a repeat, and new dates still start.
+ repeat = client.post(base + "/runs", json=body)
+ assert repeat.status_code == 200, repeat.text
+ assert repeat.json()["duplicates"][0]["run_id"] == first["id"]
+ later = {**body, "b": {**body["b"], "date": "2026-05-18"}}
+ seed_images(later)
+ started = client.post(base + "/runs", json=later)
+ assert started.status_code == 200 and "id" in started.json(), started.text
+
+ loaded = client.get(base + f"/runs/{first['id']}").json()
+ assert "tests" not in loaded["input"]["recipe"] and "retired" not in loaded["input"]["a"]
+ # Edit this run: the wizard sends its parts back as it read them.
+ edited = {key: loaded["input"][key] for key in WIZARD}
+ again = client.post(base + "/runs", json={**edited, "run_anyway": True})
+ assert again.status_code == 200, again.text
+
+ candidate = loaded["results"][0]
+ manual = client.post(base + f"/runs/{first['id']}/results", json={
+ "area_id": candidate["area_id"], "geometry": {"type": "Point", "coordinates": candidate["coordinates"]}})
+ assert manual.status_code == 200, manual.text
+ kept = client.post(base + f"/runs/{first['id']}/results/{candidate['id']}/promote", json={"title": "Pinned"})
+ assert kept.status_code == 200, kept.text
+ assert client.post(base + f"/runs/{first['id']}/export").status_code == 200
+ row = next(row for row in client.get(base + "/runs").json() if row["id"] == first["id"])
+ assert row["analyzer"] == body["recipe"]["name"]
+
+
+def test_a_routine_with_dropped_fields_opens_saves_runs_and_remembers(client, scenario):
+ case, body = scenario
+ base = f"/api/cases/{case.id}/analysis"
+ watch = client.post(base + "/followups", json=body).json()
+ first = run(client, case, {**body, "followup_id": watch["id"]})
+ client.patch(base + f"/runs/{first['id']}/results/{first['results'][0]['id']}", json={"review": "noted"})
+ rewrite(case, "followups", watch["id"], drift)
+ rewrite(case, "runs", first["id"], lambda saved: drift(saved["input"]))
+
+ opened = client.get(base + f"/followups/{watch['id']}").json()
+ saved = client.put(base + f"/followups/{watch['id']}", json={key: opened[key] for key in WIZARD})
+ assert saved.status_code == 200, saved.text
+ assert len(client.get(base + f"/followups/{watch['id']}/findings").json()) == 1
+ later = "2026-05-18"
+ seed_images({**body, "b": {**body["b"], "date": later}})
+ again = client.post(base + f"/followups/{watch['id']}/run", json={"date": later})
+ assert again.status_code == 200 and "id" in again.json(), again.text
+
+
+def unreadable_run(case, body, status):
+ """A run whose recipe no longer reads at all, even with dropped fields ignored."""
+ broken = {**body, "recipe": {**body["recipe"], "colour": "red"}}
+ return analyzers.save(case, "runs", {
+ "title": "Broken", "input": broken, "area_runs": [], "status": status, "progress": 0,
+ "total": 1, "results": [], "frames": {}, "count": 0, "message": ""})
+
+
+def test_a_run_that_no_longer_reads_blocks_nothing_and_fails_with_its_reason(client, scenario):
+ case, body = scenario
+ unreadable_run(case, body, "ready")
+ base = f"/api/cases/{case.id}/analysis"
+ started = client.post(base + "/runs", json=body)
+ assert started.status_code == 200 and "id" in started.json(), started.text
+
+ queued = unreadable_run(case, body, "queued")
+ analyzers.execute(case, {"payload": {"run_id": queued["id"]}})
+ failed = analyzers.read(case, "runs", queued["id"])
+ assert failed["status"] == "failed"
+ assert failed["message"].startswith("this detection no longer reads (recipe › colour: ")
+ assert "pydantic" not in failed["message"]
+ workqueue.drain(case)
+
+
+def test_a_routine_that_no_longer_reads_says_where(client, scenario):
+ case, body = scenario
+ base = f"/api/cases/{case.id}/analysis"
+ watch = client.post(base + "/followups", json=body).json()
+ rewrite(case, "followups", watch["id"], lambda saved: saved["recipe"].update(colour="red"))
+ refused = client.post(base + f"/followups/{watch['id']}/run", json={"date": body["b"]["date"]})
+ assert refused.status_code == 422
+ assert refused.json()["detail"].startswith("recipe › colour: ")
+
+
+def test_a_request_naming_an_unknown_field_is_still_refused(client, scenario):
+ case, body = scenario
+ asked = {**body, "recipe": {**body["recipe"], "tests": []}}
+ assert client.post(f"/api/cases/{case.id}/analysis/runs", json=asked).status_code == 422
+
+
+def own_analyzer(**extra):
+ return {**BUILTINS[0].model_dump(), "id": "custom-0123456789ab", "name": "Harbour boats", **extra}
+
+
+def test_saved_analyzers_and_detect_view_survive_dropped_fields_in_settings_and_backups(client):
+ from azimut import config
+
+ def old(settings):
+ settings["analyzers"] = [own_analyzer(tests=[])]
+ settings["detect_view"] = {"collapsed": True, "basemap": "osm", "overlays": ["roads"],
+ "saved": True, "retired": 1}
+ config.update_settings(old)
+ assert [r["name"] for r in client.get("/api/compare/analyzers").json()["custom"]] == ["Harbour boats"]
+ view = client.get("/api/settings").json()["detect_view"]
+ assert "retired" not in view and view["basemap"] == "osm"
+ assert client.put("/api/settings/prefs", json={"detect_view": view}).status_code == 200
+
+ backup = client.get("/api/settings/export").json()
+ backup["settings"]["analyzers"] = [own_analyzer(tests=[]),
+ own_analyzer(id="custom-ba0000000000", colour="red")]
+ backup["settings"]["detect_view"] = {**view, "retired": 1}
+ config.update_settings(lambda settings: settings.update(analyzers=[]))
+ restored = client.post("/api/settings/import", json=backup)
+ assert restored.status_code == 200, restored.text
+ assert [r["id"] for r in client.get("/api/compare/analyzers").json()["custom"]] == ["custom-0123456789ab"]
+ assert client.get("/api/settings").json()["detect_view"] == view
diff --git a/tests/test_proofs_api.py b/tests/test_proofs_api.py
index e5a148a..7f3105f 100644
--- a/tests/test_proofs_api.py
+++ b/tests/test_proofs_api.py
@@ -1226,6 +1226,101 @@ def test_reopening_a_proof_never_rewrites_what_was_typed(client):
assert [one["coords"] for one in spec["points"]] == [typed]
+# -- a point nobody checked (the composer's "Later") -----------------------------
+#
+# The middle of a capture is a guess until somebody looks at it on the map. The
+# composer walks each one through the map before a save, and a point saved without
+# that check stays off the case map rather than landing there as a conclusion.
+
+
+def test_an_unchecked_point_is_not_filed(client):
+ cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
+ spec = _points(("64.1466, -21.9426", "hangar", False), ("64.1502, -21.9350", "", False))
+ spec["points"][1]["proposed"] = True
+ saved = _save(client, cid, "Airbase", spec)
+
+ assert [p["attrs"]["lat"] for p in _places(cid)] == [64.1466]
+ assert [one["label"] for one in saved["place"]["filed"]] == ["hangar"]
+ # never asked about either: the composer just offered to check it
+ assert saved["place"]["asking"] == []
+
+
+def test_an_unchecked_point_is_not_asked_about_when_filing_asks(client):
+ client.put("/api/settings/prefs", json={"proof_place_auto": False})
+ cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
+ spec = _points(("64.1466, -21.9426", "", False))
+ spec["points"][0]["proposed"] = True
+ saved = _save(client, cid, "Airbase", spec)
+
+ assert saved.get("place") is None
+ # and the yes to an earlier question files nothing unchecked either
+ name = saved["name"]
+ assert client.post(f"/api/cases/{cid}/proofs/{name}/place").json() == []
+ assert _places(cid) == []
+
+
+def test_the_panels_unchecked_answer_is_not_filed(client, sat_tiles):
+ cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
+ cap = _sat(client, cid, 50.4501, 30.5234)
+ _save(client, cid, "Unchecked", _with_coords(None, {"lat": 50.4501, "lon": 30.5234, "proposed": True}, cap["path"]))
+ assert _places(cid) == []
+
+ # once somebody checked it, the same answer is the conclusion
+ _save(client, cid, "Checked", _with_coords(None, {"lat": 50.4501, "lon": 30.5234}, cap["path"]))
+ assert [p["attrs"]["lat"] for p in _places(cid)] == [50.4501]
+
+
+def test_a_point_already_on_the_map_stays_when_saved_unchecked(client):
+ """An older proof reopened reads its capture as unchecked. Saving it for later
+ must not take back the place it filed before the check existed."""
+ cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
+ _save(client, cid, "Airbase", _points(("64.1466, -21.9426", "", False)))
+ [place] = _places(cid)
+
+ spec = _points(("64.1466, -21.9426", "", False))
+ spec["points"][0]["proposed"] = True
+ saved = _save(client, cid, "Airbase", spec)
+
+ assert saved["orphans"] == []
+ assert [lk["to"] for lk in _depicts(cid)] == [place["id"]]
+
+
+def test_an_unchecked_point_reopens_unchecked(client):
+ cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
+ spec = _points(("64.1466, -21.9426", "", False), ("64.1502, -21.9350", "", False))
+ spec["points"][1]["proposed"] = True
+ _save(client, cid, "Airbase", spec)
+
+ reopened = client.get(f"/api/cases/{cid}/proofs/Airbase").json()
+ assert [one.get("proposed") for one in reopened["points"]] == [None, True]
+
+ from azimut.engine import satellite
+
+ assert [one.get("proposed", False) for one in satellite.spec_points(reopened)] == [False, True]
+ written = satellite.state_points({}, satellite.spec_points(reopened))
+ assert written["points"][1] == {"coords": "64.1502, -21.9350", "proposed": True}
+
+
+def test_a_capture_says_where_its_frame_was_centred(client, sat_tiles):
+ """What tells the composer a pin was aimed: the point and the frame's centre
+ differ only when the pin was moved onto the target."""
+ cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
+ client.post(
+ f"/api/cases/{cid}/satellite/capture",
+ json={"lat": 50.45, "lon": 30.52, "zoom": 16, "width": 256, "height": 256,
+ "marker_style": "pin", "marker_x": 40, "marker_y": -20,
+ "marker_lat": 50.4501, "marker_lon": 30.5234},
+ )
+ client.post(
+ f"/api/cases/{cid}/satellite/capture",
+ json={"lat": 48.85, "lon": 2.35, "zoom": 16, "width": 256, "height": 256},
+ )
+ captures = {c["lat"]: c for c in client.get(f"/api/cases/{cid}/satellite").json()}
+
+ assert (captures[50.4501]["center_lat"], captures[50.4501]["center_lon"]) == (50.45, 30.52)
+ assert (captures[48.85]["center_lat"], captures[48.85]["center_lon"]) == (48.85, 2.35)
+
+
def test_a_proof_the_panels_place_opens_with_an_empty_field(client, sat_tiles):
"""Nothing was typed, so nothing is written into the row: the field shows the
panels' own answer and the reset arrow stays away."""