Files
gods-eye-view/src/tools/queries/imagery.test.mjs
T
Sameh Khamis 9be90fff44 feat: add a recent satellite imagery tool
Add get_recent_imagery. It searches the recent Harmonized Landsat and
Sentinel-2 catalog for an area, picks the image the layer would show
with the layer's own ranking, and returns it with its date, sensor and
cloud cover, falling back to the VIIRS daily overview.
2026-10-01 13:25:00 -07:00

92 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict';
import test from 'node:test';
import { composeCatalog, coreTools } from '../index.js';
const PNG = Uint8Array.from([0x89, 0x50, 0x4e, 0x47]);
const imagery = (latest) => ({
snapshots: [],
boxes: [],
async latest({ box }) {
this.boxes.push(box);
return latest;
},
async getSnapshot(request) {
this.snapshots.push(request);
return { contentType: 'image/png', bytes: PNG };
},
});
const austin = { bbox: [-97.9, 30.1, -97.5, 30.5] };
test('the most recent clear image is returned with its date and sensor', async () => {
const service = imagery({
candidate: {
product: 'S30',
day: '2026-09-28',
cloud: { min: 2, max: 6 },
coverage: 'full',
},
reason: 'clear',
certain: true,
errors: [],
});
const catalog = composeCatalog({
tools: coreTools,
services: { imagery: service },
});
const result = await catalog.call('get_recent_imagery', { area: austin });
assert.equal(
result.summary,
'Most recent image of the requested box: Sentinel-2 (30 m), 2026-09-28, clear, 2–6% cloud.',
);
assert.deepEqual(result.images, [
{ mimeType: 'image/png', data: 'iVBORw==' },
]);
assert.deepEqual(service.snapshots[0], {
product: 'S30',
day: '2026-09-28',
box: { west: -97.9, south: 30.1, east: -97.5, north: 30.5 },
width: 1024,
height: 1024,
signal: undefined,
});
});
test('overview fallback, empty results and invalid areas are reported', async () => {
const overview = composeCatalog({
tools: coreTools,
services: {
imagery: imagery({
candidate: { product: 'VIIRS', day: '2026-10-01', cloud: null },
reason: 'overview',
errors: [{ product: 'S30' }],
}),
},
});
const coarse = await overview.call('get_recent_imagery', { area: austin });
assert.equal(
coarse.summary,
'Most recent image of the requested box: VIIRS daily overview (250 m), 2026-10-01, coarse overview.',
);
assert.deepEqual(coarse.data.search_errors, ['S30']);
const none = composeCatalog({
tools: coreTools,
services: { imagery: imagery({ candidate: null, reason: null }) },
});
assert.equal(
(await none.call('get_recent_imagery', { area: austin })).summary,
'No recent satellite image covers the requested box.',
);
await assert.rejects(
none.call('get_recent_imagery', { area: { bbox: [-120, 20, -60, 50] } }),
/too large for imagery/,
);
await assert.rejects(
none.call('get_recent_imagery', { area: { bbox: [170, 0, -170, 5] } }),
/antimeridian/,
);
await assert.rejects(
none.call('get_recent_imagery', { area: { bbox: [0, 85.5, 1, 86] } }),
/±85° latitude/,
);
});