diff --git a/changelog.d/1748-clouds-feed-detail.md b/changelog.d/1748-clouds-feed-detail.md new file mode 100644 index 000000000..bf4440e7d --- /dev/null +++ b/changelog.d/1748-clouds-feed-detail.md @@ -0,0 +1,5 @@ +- A weather feed that supplies its own tiles can name how deep they go for + each product (`frameMaximumLevel`). Global satellite clouds are then drawn + from those tiles to that level instead of from one 2048 × 1024 image, so + they stay sharp when zoomed in; radar and the other tiled products take the + named level too. Without it, clouds keep the single image and level 3. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index e03fb3d45..194b10ebf 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1020,7 +1020,9 @@ other map content draws over the shells, and shells are not pickable. A map-source change tears down one renderer and restages the shown observation on the other. A map without an imagery host pauses history while metadata refresh continues, then resumes when a host returns. -Globe tiled products use 256 px tiles to maximum level 6. The tile proxy accepts +Globe tiled products use 256 px tiles to maximum level 6, or to the level a +feed that supplies its own tiles names for the product (`frameMaximumLevel`, +0–12; any other answer keeps 6). The tile proxy accepts size=256 (default), 512 or 1024 and keys cached bytes by size, retaining the 24-hour immutable response and eight upstream slots. The image proxy serves every product as one whole-extent PNG at its advertised bounds, up to 4096×2048 for @@ -1062,7 +1064,11 @@ open latest. Global infrared fetches one capped 4 MiB, 2048×1024 mosaic per frame and decodes and processes it before staging. Globe hosts crop that canvas into 256 px tiles to maximum level 3 on a geographic 2×1 root grid bounded to the manifest extent, -avoiding request-dependent contrast seams. +avoiding request-dependent contrast seams. On globe hosts, a feed that supplies +tiles and names a level for global infrared instead has it drawn from its tiles +to that level, +each tile given the same display transfer as regional infrared tiles, and no +mosaic is read. On globe hosts, regional infrared retains network tiles and processes each decoded tile once; shells process each whole frame once. Exact-time tile and image responses are immutable for 24 hours; manifests and diff --git a/src/layers/weather/rendering.js b/src/layers/weather/rendering.js index d7c2527ab..89dcd778d 100644 --- a/src/layers/weather/rendering.js +++ b/src/layers/weather/rendering.js @@ -13,8 +13,13 @@ import { acquireInfraredMosaic, processInfraredImage, } from './infraredImage.js'; -// Bounded display detail for the hourly, approximately 3 km global product. +// Bounded display detail for the hourly, approximately 3 km global product +// when it is drawn from one 2048 × 1024 mosaic. const GLOBAL_TILE_MAXIMUM_LEVEL = 3; +// Detail of the tiled products when the feed does not name its own. +const TILE_MAXIMUM_LEVEL = 6; +// The deepest level a feed may name: about 150 m a pixel. +const SUPPLIED_MAXIMUM_LEVEL_LIMIT = 12; // Six decoded 2048×1024 canvases (8 MiB each) bound the cache below 50 MiB. const MAX_MOSAICS = 6; const MAX_PREFETCH_TILES = 8; @@ -45,10 +50,33 @@ function createGlobeRendering({ let prefetchJob = null; let prefetchedKey = null; + /** The deepest level the feed's own tiles of `product` go to, or null. */ + function suppliedLevel(product) { + if (!frameSource?.getTile) return null; + let level = null; + try { + level = frameSource.maximumLevel?.(product) ?? null; + } catch { + return null; + } + return Number.isInteger(level) && + level >= 0 && + level <= SUPPLIED_MAXIMUM_LEVEL_LIMIT + ? level + : null; + } + + /** Global clouds come from one mosaic unless the feed tiles them itself. */ + function fromMosaic(product) { + return product === 'clouds' && suppliedLevel(product) === null; + } + function profile(product) { return { tileSize: 256, - maximumLevel: product === 'clouds' ? GLOBAL_TILE_MAXIMUM_LEVEL : 6, + maximumLevel: + suppliedLevel(product) ?? + (product === 'clouds' ? GLOBAL_TILE_MAXIMUM_LEVEL : TILE_MAXIMUM_LEVEL), }; } @@ -252,7 +280,7 @@ function createGlobeRendering({ !snapshot.times.includes(time) ) return false; - const global = snapshot.product === 'clouds'; + const global = fromMosaic(snapshot.product); const tiles = global ? [] : prefetchTiles(snapshot); const supplied = !global && Boolean(frameSource?.getTile); const urls = global || supplied ? [] : tileUrls(snapshot, time, tiles); @@ -315,7 +343,7 @@ function createGlobeRendering({ lastError = null; const { west, south, east, north } = snapshot.bounds; const rectangle = cesium.Rectangle.fromDegrees(west, south, east, north); - const global = snapshot.product === 'clouds'; + const global = fromMosaic(snapshot.product); const frame = { snapshot, creditSnapshot, @@ -484,7 +512,14 @@ function createGlobeRendering({ .then((image) => { // Cesium decodes tiles as ImageBitmaps already flipped, since WebGL // ignores UNPACK_FLIP_Y for them; a canvas upload flips again. - if (!frame.closed && snapshot.product === 'clouds-regional') + // Infrared tiles get the display transfer the mosaic already + // carries. + if ( + !frame.closed && + !global && + (snapshot.product === 'clouds-regional' || + snapshot.product === 'clouds') + ) image = processInfraredImage(image, infrared, createCanvas, { flipY: typeof ImageBitmap !== 'undefined' && diff --git a/src/layers/weather/source.js b/src/layers/weather/source.js index 276e9bf2e..465c89312 100644 --- a/src/layers/weather/source.js +++ b/src/layers/weather/source.js @@ -121,6 +121,10 @@ export function weatherTileUrl(product, time, { size } = {}) { * degrees) a detail window of it. `getFrameTile` returns one `size`-pixel tile * of the geographic tiling scheme, or null for a transparent tile. Rows run * top-down (north first), as an image does. Both honour `signal`. + * `frameMaximumLevel` names the deepest level of that scheme the feed's tiles + * of a product hold detail at (0–12), or null for the layer's own: with it, + * global clouds are drawn from the feed's tiles to that level instead of from + * one 2048 × 1024 image. * @typedef {object} WeatherFrameFeed * @property {(request: { product: string, time: string, * size: { width: number, height: number }, @@ -129,19 +133,25 @@ export function weatherTileUrl(product, time, { size } = {}) { * @property {(request: { product: string, time: string, z: number, x: number, * y: number, size: number, signal: AbortSignal }) * => Promise} [getFrameTile] + * @property {(product: string) => number | null} [frameMaximumLevel] */ /** * The frame source a feed provides, or null when it has neither method. A * missing method is left undefined, so that path keeps the routes. * @param {WeatherFrameFeed | undefined} feed - * @returns {{ getImage?: Function, getTile?: Function } | null} + * @returns {{ getImage?: Function, getTile?: Function, + * maximumLevel?: Function } | null} */ export function weatherFrameSource(feed) { const image = typeof feed?.getFrameImage === 'function'; const tile = typeof feed?.getFrameTile === 'function'; if (!image && !tile) return null; + const level = typeof feed?.frameMaximumLevel === 'function'; return { + maximumLevel: level + ? (product) => feed.frameMaximumLevel(product) + : undefined, getImage: image ? ({ product, time, size, bbox = null, signal }) => feed.getFrameImage({ product, time, size, bbox, signal }) diff --git a/src/layers/weather/source.test.mjs b/src/layers/weather/source.test.mjs index ff69fce2f..81b37c6fa 100644 --- a/src/layers/weather/source.test.mjs +++ b/src/layers/weather/source.test.mjs @@ -257,6 +257,13 @@ test('a frame source forwards exactly the documented requests to its feed', asyn assert.equal(imagesOnly.getTile, undefined, 'tiles keep the tile route'); const tilesOnly = weatherFrameSource({ getFrameTile: feed.getFrameTile }); assert.equal(tilesOnly.getImage, undefined, 'images keep the image route'); + assert.equal(tilesOnly.maximumLevel, undefined); + const leveled = weatherFrameSource({ + getFrameTile: feed.getFrameTile, + frameMaximumLevel: (product) => (product === 'clouds' ? 6 : null), + }); + assert.equal(leveled.maximumLevel('clouds'), 6); + assert.equal(leveled.maximumLevel('radar'), null); }); test('supplied pixels report their drawn size, draw at the origin and close once', (t) => { diff --git a/src/layers/weather/weather.test.mjs b/src/layers/weather/weather.test.mjs index 309b51165..2b9dba5d8 100644 --- a/src/layers/weather/weather.test.mjs +++ b/src/layers/weather/weather.test.mjs @@ -2694,6 +2694,99 @@ test('a frame source supplies regional tiles in place of the tile route, through h.rendering.clear(); }); +test('a frame source that names its tile detail draws global clouds from its tiles to that level', async () => { + let now = 0; + const requests = []; + const h = renderingHarness({ + now: () => now, + fetchImpl: () => assert.fail('supplied clouds are not fetched'), + frameSource: { + getImage: () => assert.fail('no mosaic when the feed tiles clouds'), + getTile: async (request) => { + requests.push(request); + return suppliedTile(); + }, + maximumLevel: (product) => (product === 'clouds' ? 6 : 8), + }, + }); + h.viewer.scene.globe.tilesLoaded = false; + const loaded = h.rendering.setFrame(globalSnapshot, times[0]); + assert.equal(h.providers.length, 1); + const [provider] = h.providers; + assert.equal(provider.options, undefined, 'no URL template provider'); + assert.equal(provider.maximumLevel, 6); + await provider.requestImage(5, 3, 4, {}); + assert.deepEqual( + [requests[0].product, requests[0].z, requests[0].x, requests[0].y], + ['clouds', 4, 5, 3], + ); + now = 500; + h.settle(); + assert.equal(await loaded, true); + h.rendering.clear(); + + // Radar takes the level the feed names for it. + const radar = renderingHarness({ + frameSource: { + getTile: async () => suppliedTile(), + maximumLevel: () => 8, + }, + }); + radar.rendering.setFrame(snapshot, times[0]); + assert.equal(radar.providers[0].maximumLevel, 8); + radar.rendering.clear(); +}); + +test("a frame source naming no usable level keeps the layer's own detail", async () => { + for (const maximumLevel of [ + () => null, + () => 13, + () => 2.5, + () => 'deep', + () => { + throw new Error('no level'); + }, + ]) { + const h = renderingHarness({ + frameSource: { getTile: async () => suppliedTile(), maximumLevel }, + }); + h.rendering.setFrame(snapshot, times[0]); + assert.equal(h.providers[0].maximumLevel, 6); + h.rendering.clear(); + // Global clouds stay on the one image, cut to level 3. + let mosaics = 0; + const clouds = renderingHarness({ + frameSource: { + getImage: async () => { + mosaics++; + return { width: 2048, height: 1024, close() {} }; + }, + getTile: () => assert.fail('clouds are not tiled without a level'), + maximumLevel, + }, + }); + await showMosaic(clouds, times[0]); + assert.equal(mosaics, 1); + assert.equal(clouds.providers[0].maximumLevel, 3); + clouds.rendering.clear(); + } + // A level without tiles leaves global clouds on the mosaic. + let images = 0; + const h = renderingHarness({ + frameSource: { + getImage: async () => { + images++; + return suppliedTile(); + }, + maximumLevel: () => 6, + }, + }); + h.rendering.setFrame(globalSnapshot, times[0]); + await flush(); + assert.equal(images, 1); + h.rendering.clear(); +}); + test('a failed supplied tile fails the staged frame through errorEvent', async () => { const h = renderingHarness({ frameSource: { @@ -2748,6 +2841,52 @@ test('supplied regional infrared tiles are canvases, so they get the transfer wi } }); +test('global clouds tiles get the infrared transfer, and prefetch asks for tiles, not the image', async () => { + const hadBitmap = Object.hasOwn(globalThis, 'ImageBitmap'); + const previous = globalThis.ImageBitmap; + globalThis.ImageBitmap = class ImageBitmap { + width = 256; + height = 256; + close() {} + }; + try { + const requests = []; + const h = renderingHarness({ + frameSource: { + getImage: () => assert.fail('no image when the feed tiles clouds'), + getTile: async (request) => { + requests.push(request); + return new globalThis.ImageBitmap(); + }, + maximumLevel: () => 6, + }, + }); + void h.rendering.setFrame(globalSnapshot, times[0]); + const tile = await h.providers[0].requestImage(5, 3, 4, {}); + assert.equal(tile.drawnWith, null, 'drawn upright, not flipped'); + assert.ok(tile.pixels, 'the infrared transfer ran'); + h.rendering.clear(); + requests.length = 0; + const warm = renderingHarness({ + frameSource: { + getImage: () => assert.fail('no image when the feed tiles clouds'), + getTile: async (request) => { + requests.push(request); + return new globalThis.ImageBitmap(); + }, + maximumLevel: () => 6, + }, + }); + assert.equal(await warm.rendering.prefetch(globalSnapshot, times[1]), true); + assert.ok(requests.length > 0, 'prefetch asked for tiles'); + assert.ok(requests.every((request) => request.product === 'clouds')); + warm.rendering.clear(); + } finally { + if (hadBitmap) globalThis.ImageBitmap = previous; + else delete globalThis.ImageBitmap; + } +}); + test('tiled prefetch asks the frame source for the same level 0/1 tiles and releases them', async (t) => { const requests = []; const supplied = [];