Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zarr): Flatten zarr module, remove XML-parsing #1462

Merged
merged 4 commits into from
Jun 24, 2021
Merged

Conversation

manzt
Copy link
Collaborator

@manzt manzt commented Jun 7, 2021

Applies changes from #1446 to master

const tileSize = guessTileSize(data[0]);
const labels = options.labels ?? guessLabels(rootAttrs);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no labels are provided, they are inferred (if possible) from the rootAttrs. For now, guessLabels only infers if OME-Zarr.

const grp = await openGroup(store, path);
const rootAttrs = await grp.attrs.asObject() as RootAttrs;

if (!Array.isArray(rootAttrs.multiscales)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks that multiscales extension is implemented in rootAttrs (generic across Zarr datasets)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is OME the only possible Zarr extension? Otherwise should we in the future make a more general interface for working with Zarr extensions?

Copy link
Collaborator Author

@manzt manzt Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Zarr store is organized into a hierarchy of nodes. Each node can either be a group or an array, and only a group may contain other nodes. The multiscales extension is not OME-Zarr -specific (although it was spearheaded by OME folks working on zarr).

The mutiscales extension adds a "multiscales" key-value to group metadata that ultimately provides the relative paths to other array sub-resolutions saved in the store. OME-Zarr chooses to also store additional metadata in the same group but under a different key (omero). This function reads the multiscales metadata (to initialize the pixel-sources), but simply returns the complete root metadata ({ multiscales, omero } for Ome-Zarr) back to the end-user to choose what to do with it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late addition, but there has been off and on discussion of moving the multiscales to a "super-interface" of OME-Zarr, i.e. a more generalized pyramidal image spec.

cf. pydata/xarray#4118 (comment)

"version": "0.1"
}
],
"omero": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OME metadata in root attrs. Used to distinguish multiscale dataset is OME-Zarr.

@manzt manzt requested a review from ibgreen June 8, 2021 14:05
@manzt
Copy link
Collaborator Author

manzt commented Jun 8, 2021

Should be ready for review. I consolidated the handling of different Zarr formats in loadZarr, and added an OME-Zarr fixture.

@manzt
Copy link
Collaborator Author

manzt commented Jun 8, 2021

The tests are failing in the browser:

fetch-file.js:17 GET http://localhost:5000/modules/zarr/test/data/multiscale.zarr/.zgroup 404 (Not Found)

The issue seems to be with FetchFileStore which wraps fetchFile.

@manzt manzt force-pushed the manzt/zarr-loader branch 2 times, most recently from dd9698d to 21094a6 Compare June 15, 2021 14:05
@manzt
Copy link
Collaborator Author

manzt commented Jun 15, 2021

Rebased again on master. I commented out the browser tests for zarr due to the issue with fetchFile/FetchFileStore. I'm not sure how to resolve. It seems that a zarr store wrapping fetchFile should work in browser and node environments, but I'm not familiar enough with the implementation.

@@ -1,6 +1,6 @@
{
"name": "@loaders.gl/zarr",
"version": "3.0.0-alpha.21",
"version": "3.0.0-alpha.18",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think other modules are up to .21 now?

"version": "3.0.0-alpha.21",

modules/zarr/package.json Show resolved Hide resolved
modules/zarr/src/lib/load-zarr.ts Show resolved Hide resolved
@@ -0,0 +1,38 @@
import {fetchFile} from '@loaders.gl/core';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed @loaders.gl/core from the package.json...


async getItem(key: string, options?: RequestInit): Promise<ArrayBuffer> {
const filepath = joinUrlParts(this.root, key);
const response = await fetchFile(filepath, options);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just use fetch here instead of fetchFile? For Node we expect users to import @loaders.gl/polyfills which polyfills fetch

Copy link
Collaborator Author

@manzt manzt Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zarr.HTTPStore does exactly this ( uses fetch internally and expects a polyfil in node).

I guess the question is if loadZarr is given a string source, we need to pick the correct store to initialize FileFetchStore vs HTTPStore depending on the URL (one for a local store with node and the latter for a remote store), correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still running into issues here. How can do I resolve the alias for a fixture path to either a path or URL? e.g.

const path = '@loaders.gl/zarr/test/data/multiscale.zarr';

// /Users/..../zarr/test/data/multiscale.zarr 
// or
// https://localhost:5001/zarr/test/data/multiscale.zarr

Am I missing something?

Copy link
Collaborator

@kylebarron kylebarron Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alias doesn't work?

'@loaders.gl/zarr/test': path.resolve(basename, '../modules/zarr/test'),

Copy link
Collaborator Author

@manzt manzt Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing something conceptually with how these aliases are resolved. For the following path:

const path = '@loaders.gl/zarr/test/data/multiscale.zarr';

How can I resolve this to the HTTP endpoint the file is served from (http://localhost:5000/modules/zarr/test/multiscale.zarr) for use with the fetch API? Calling resolvePath(path) returns /modules/zarr/test/multiscale.zarr)

Hmm, fetch('/modules/zarr/test/multiscale.zarr/.zgroup') responds with a 404 in the browser. I'm having trouble figuring out why this file isn't served.

const grp = await openGroup(store, path);
const rootAttrs = await grp.attrs.asObject() as RootAttrs;

if (!Array.isArray(rootAttrs.multiscales)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is OME the only possible Zarr extension? Otherwise should we in the future make a more general interface for working with Zarr extensions?

@manzt manzt force-pushed the manzt/zarr-loader branch from 2d5e6e6 to e9d62e7 Compare June 24, 2021 16:08
@manzt manzt force-pushed the manzt/zarr-loader branch from a09aca1 to 67fecb9 Compare June 24, 2021 17:55
@manzt
Copy link
Collaborator Author

manzt commented Jun 24, 2021

There is still an issue with fetch-ing zarr files in the browser that I can't seem get to the bottom of (See comment above). This seems to be specific to fetching assets in the test suite, but the bundled modules do run in the browser.

I have disabled the browser tests, like geotiff, in favor of merging this PR sooner rather than later to avoid having this PR go stale. We can follow up in subsequent PR to fix both issues (geotiff + zarr).

@manzt manzt merged commit 6c5d201 into master Jun 24, 2021
@manzt manzt deleted the manzt/zarr-loader branch June 24, 2021 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants