UNPKG

@loaders.gl/zarr

Version:

Framework-independent loaders for Zarr

22 lines (21 loc) 908 B
// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import { loadMultiscales, guessTileSize, guessLabels, normalizeStore, validLabels } from "./utils.js"; import ZarrPixelSource from "./zarr-pixel-source.js"; export async function loadZarr(root, options = {}) { const store = normalizeStore(root); const { data, rootAttrs } = await loadMultiscales(store); const tileSize = guessTileSize(data[0]); // If no labels are provided, inspect the root attributes for the store. // For now, we only infer labels for OME-Zarr. const labels = options.labels ?? guessLabels(rootAttrs); if (!validLabels(labels, data[0].shape)) { throw new Error('Invalid labels for Zarr array dimensions.'); } const pyramid = data.map((arr) => new ZarrPixelSource(arr, labels, tileSize)); return { data: pyramid, metadata: rootAttrs }; }