Skip to content

Commit

Permalink
feat(zarr): Flatten zarr module, remove XML-parsing (#1462)
Browse files Browse the repository at this point in the history
* wip

* Use DTYPE_LOOKUP for supported dtype types

* Use store built on fetch API

* bump zarr
  • Loading branch information
manzt authored Jun 24, 2021
1 parent e5daf5b commit 6c5d201
Show file tree
Hide file tree
Showing 44 changed files with 387 additions and 852 deletions.
2 changes: 0 additions & 2 deletions modules/zarr/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<<<<<<< HEAD:modules/textures/README.md

# @loaders.gl/zarr

[loaders.gl](https://loaders.gl/docs) is a collection of framework-independent 3D and geospatial parsers and encoders.
Expand Down
7 changes: 2 additions & 5 deletions modules/zarr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"loader",
"zarr"
],
"types": "src/index.ts",
"types": "src/index.d.ts",
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"sideEffects": false,
Expand All @@ -30,11 +30,8 @@
"build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js"
},
"dependencies": {
"@loaders.gl/core": "3.0.0-alpha.18",
"@loaders.gl/worker-utils": "3.0.0-alpha.18",
"@luma.gl/constants": "^8.3.0",
"fast-xml-parser": "^3.16.0",
"zarr": "^0.4.0"
"zarr": "^0.5.0"
},
"devDependencies": {
"@loaders.gl/core": "3.0.0-alpha.18"
Expand Down
74 changes: 0 additions & 74 deletions modules/zarr/src/constants.ts

This file was deleted.

2 changes: 0 additions & 2 deletions modules/zarr/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export {loadZarr} from './lib/load-zarr';
export {loadBioformatsZarr} from './lib/load-bioformats-zarr';

export {default as ZarrPixelSource} from './lib/zarr-pixel-source';
28 changes: 0 additions & 28 deletions modules/zarr/src/lib/load-bioformats-zarr-helper.ts

This file was deleted.

79 changes: 0 additions & 79 deletions modules/zarr/src/lib/load-bioformats-zarr.ts

This file was deleted.

48 changes: 14 additions & 34 deletions modules/zarr/src/lib/load-zarr.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
import type {ZarrArray} from 'zarr';
import {loadMultiscales, guessTileSize} from './utils/zarr-utils';
import type {Store} from 'zarr/types/storage/types';
import {loadMultiscales, guessTileSize, guessLabels, normalizeStore, validLabels} from './utils';
import ZarrPixelSource from './zarr-pixel-source';
import type {Labels} from '../types';

interface Channel {
active: boolean;
color: string;
label: string;
window: {
min?: number;
max?: number;
start: number;
end: number;
};
interface ZarrOptions {
labels?: string[];
}

interface Omero {
channels: Channel[];
rdefs: {
defaultT?: number;
defaultZ?: number;
model: string;
};
name?: string;
}
export async function loadZarr(root: string | Store, options: ZarrOptions = {}) {
const store = normalizeStore(root);
const {data, rootAttrs} = await loadMultiscales(store);
const tileSize = guessTileSize(data[0]);

interface Multiscale {
datasets: {path: string}[];
version?: string;
}
// 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);

export interface RootAttrs {
omero: Omero;
multiscales: Multiscale[];
}
if (!validLabels(labels, data[0].shape)) {
throw new Error('Invalid labels for Zarr array dimensions.');
}

export async function loadZarr(store: ZarrArray['store']) {
const {data, rootAttrs} = await loadMultiscales(store);
const labels = ['t', 'c', 'z', 'y', 'x'] as Labels<['t', 'c', 'z']>;
const tileSize = guessTileSize(data[0]);
const pyramid = data.map((arr) => new ZarrPixelSource(arr, labels, tileSize));
return {
data: pyramid,
Expand Down
Loading

0 comments on commit 6c5d201

Please sign in to comment.