Skip to content

Commit d70768c

Browse files
committed
Derive STAC bbox and temporal extent from zarr metadata
Use statistics_approximate attributes from zarr coordinate arrays instead of hardcoded bbox and temporal start values.
1 parent 30c00c8 commit d70768c

1 file changed

Lines changed: 49 additions & 8 deletions

File tree

.eleventy.js

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,32 @@ module.exports = function (eleventyConfig) {
256256
};
257257
}
258258

259-
const isGlobal =
260-
entry.spatial_domain && entry.spatial_domain.includes("Global");
261-
const bbox = isGlobal ? [-180, -90, 180, 90] : [-125, 24, -66, 50];
259+
// Compute bbox from latitude/longitude coordinate statistics
260+
const allArrays = [...(entry.dimensions || []), ...(entry.variables || [])];
261+
const latArray = allArrays.find((a) => a.standard_name === "latitude");
262+
const lonArray = allArrays.find((a) => a.standard_name === "longitude");
263+
const bbox =
264+
latArray?.statistics_approximate && lonArray?.statistics_approximate
265+
? [
266+
lonArray.statistics_approximate.min,
267+
latArray.statistics_approximate.min,
268+
lonArray.statistics_approximate.max,
269+
latArray.statistics_approximate.max,
270+
]
271+
: [-180, -90, 180, 90];
272+
273+
// Compute temporal start from time dimension statistics
274+
const timeDim = (entry.dimensions || []).find(
275+
(d) =>
276+
d.name === "time" || d.name === "init_time" || d.name === "valid_time"
277+
);
278+
const tMin = timeDim?.statistics_approximate?.min;
279+
const temporalStart =
280+
tMin && tMin !== "Present"
281+
? tMin.endsWith("Z")
282+
? tMin
283+
: `${tMin}Z`
284+
: null;
262285

263286
// Datacube extension: dimensions and variables from zarr metadata
264287
const cubeDimensions = {};
@@ -267,16 +290,34 @@ module.exports = function (eleventyConfig) {
267290
cubeDimensions[dim.name] = {
268291
type: "spatial",
269292
axis: "y",
270-
extent: [bbox[1], bbox[3]],
293+
extent: dim.statistics_approximate
294+
? [dim.statistics_approximate.min, dim.statistics_approximate.max]
295+
: [bbox[1], bbox[3]],
271296
};
272297
} else if (dim.name === "longitude" || dim.name === "x") {
273298
cubeDimensions[dim.name] = {
274299
type: "spatial",
275300
axis: "x",
276-
extent: [bbox[0], bbox[2]],
301+
extent: dim.statistics_approximate
302+
? [dim.statistics_approximate.min, dim.statistics_approximate.max]
303+
: [bbox[0], bbox[2]],
304+
};
305+
} else if (
306+
dim.name === "time" ||
307+
dim.name === "init_time" ||
308+
dim.name === "valid_time"
309+
) {
310+
const dimMin = dim.statistics_approximate?.min;
311+
const dimStart =
312+
dimMin && dimMin !== "Present"
313+
? dimMin.endsWith("Z")
314+
? dimMin
315+
: `${dimMin}Z`
316+
: null;
317+
cubeDimensions[dim.name] = {
318+
type: "temporal",
319+
extent: [dimStart, null],
277320
};
278-
} else if (dim.name === "time" || dim.name === "init_time" || dim.name === "valid_time") {
279-
cubeDimensions[dim.name] = { type: "temporal", extent: [null, null] };
280321
} else {
281322
cubeDimensions[dim.name] = { type: "other", extent: [null, null] };
282323
}
@@ -309,7 +350,7 @@ module.exports = function (eleventyConfig) {
309350
"cube:variables": cubeVariables,
310351
extent: {
311352
spatial: { bbox: [bbox] },
312-
temporal: { interval: [["2000-01-01T00:00:00Z", null]] },
353+
temporal: { interval: [[temporalStart, null]] },
313354
},
314355
assets,
315356
links: [

0 commit comments

Comments
 (0)