@vitessce/zarr 3.1.2 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
2
- import { B as BaseDecoder } from "./index-e14e0548.js";
2
+ import { B as BaseDecoder } from "./index-58807fea.js";
3
3
  import "@vitessce/vit-s";
4
4
  import "react";
5
5
  class DeflateDecoder extends BaseDecoder {
@@ -142153,16 +142153,16 @@ function addDecoder(cases, importFn) {
142153
142153
  }
142154
142154
  cases.forEach((c) => registry.set(c, importFn));
142155
142155
  }
142156
- addDecoder([void 0, 1], () => import("./raw-10e4baac.js").then((m) => m.default));
142157
- addDecoder(5, () => import("./lzw-dc6a7beb.js").then((m) => m.default));
142156
+ addDecoder([void 0, 1], () => import("./raw-bf0fb054.js").then((m) => m.default));
142157
+ addDecoder(5, () => import("./lzw-5712b930.js").then((m) => m.default));
142158
142158
  addDecoder(6, () => {
142159
142159
  throw new Error("old style JPEG compression is not supported.");
142160
142160
  });
142161
- addDecoder(7, () => import("./jpeg-917d48dd.js").then((m) => m.default));
142162
- addDecoder([8, 32946], () => import("./deflate-c5075574.js").then((m) => m.default));
142163
- addDecoder(32773, () => import("./packbits-d627fc76.js").then((m) => m.default));
142164
- addDecoder(34887, () => import("./lerc-c153da1f.js").then((m) => m.default));
142165
- addDecoder(50001, () => import("./webimage-6254ac4a.js").then((m) => m.default));
142161
+ addDecoder(7, () => import("./jpeg-d96062a4.js").then((m) => m.default));
142162
+ addDecoder([8, 32946], () => import("./deflate-7cf024eb.js").then((m) => m.default));
142163
+ addDecoder(32773, () => import("./packbits-ed7b9205.js").then((m) => m.default));
142164
+ addDecoder(34887, () => import("./lerc-6865e403.js").then((m) => m.default));
142165
+ addDecoder(50001, () => import("./webimage-a8d94527.js").then((m) => m.default));
142166
142166
  function decodeRowAcc(row, stride) {
142167
142167
  let length2 = row.length - stride;
142168
142168
  let offset = 0;
@@ -148105,6 +148105,41 @@ function coordinateTransformationsToMatrix(coordinateTransformations, axes) {
148105
148105
  }
148106
148106
  return mat;
148107
148107
  }
148108
+ function normalizeCoordinateTransformations(coordinateTransformations, datasets) {
148109
+ var _a2;
148110
+ let result = [];
148111
+ if (Array.isArray(coordinateTransformations)) {
148112
+ result = coordinateTransformations.map((transform2) => {
148113
+ if (transform2.input && transform2.output) {
148114
+ const { type } = transform2;
148115
+ if (type === "translation") {
148116
+ return {
148117
+ type,
148118
+ translation: transform2.translation
148119
+ };
148120
+ }
148121
+ if (type === "scale") {
148122
+ return {
148123
+ type,
148124
+ scale: transform2.scale
148125
+ };
148126
+ }
148127
+ if (type === "identity") {
148128
+ return { type };
148129
+ }
148130
+ console.warn(`Coordinate transformation type "${type}" is not supported.`);
148131
+ }
148132
+ return transform2;
148133
+ });
148134
+ }
148135
+ if (Array.isArray((_a2 = datasets == null ? void 0 : datasets[0]) == null ? void 0 : _a2.coordinateTransformations)) {
148136
+ result = [
148137
+ ...datasets[0].coordinateTransformations,
148138
+ ...result
148139
+ ];
148140
+ }
148141
+ return result;
148142
+ }
148108
148143
  class ObsSegmentationsAnndataLoader extends AbstractTwoStepLoader {
148109
148144
  /**
148110
148145
  * Class method for loading embedding coordinates, such as those from UMAP or t-SNE.
@@ -148293,28 +148328,34 @@ class OmeZarrLoader extends AbstractTwoStepLoader {
148293
148328
  const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
148294
148329
  const loader = await loadOmeZarr(this.url, { fetchOptions: this.requestInit, type: "multiscales" });
148295
148330
  const { metadata, data } = loader;
148296
- const { omero, multiscales } = metadata;
148297
- if (!omero) {
148298
- console.error("Path for image not valid");
148331
+ const { omero, multiscales, channels_metadata: spatialDataChannels } = metadata;
148332
+ const isSpatialData = !!spatialDataChannels;
148333
+ if (!isSpatialData && !omero) {
148334
+ console.error("image.ome-zarr must have omero metadata in attributes.");
148299
148335
  return Promise.reject(payload);
148300
148336
  }
148301
148337
  if (!Array.isArray(multiscales) || multiscales.length === 0) {
148302
148338
  console.error("Multiscales array must exist and have at least one element");
148303
148339
  }
148304
- const { coordinateTransformations } = multiscales[0];
148340
+ const {
148341
+ datasets,
148342
+ coordinateTransformations: coordinateTransformationsFromFile,
148343
+ name: imageName
148344
+ } = multiscales[0];
148305
148345
  const axes = getNgffAxes(multiscales[0].axes);
148346
+ const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(
148347
+ coordinateTransformationsFromFile,
148348
+ datasets
148349
+ );
148306
148350
  const transformMatrixFromOptions = coordinateTransformationsToMatrix(
148307
148351
  coordinateTransformationsFromOptions,
148308
148352
  axes
148309
148353
  );
148310
148354
  const transformMatrixFromFile = coordinateTransformationsToMatrix(
148311
- coordinateTransformations,
148355
+ normCoordinateTransformationsFromFile,
148312
148356
  axes
148313
148357
  );
148314
148358
  const transformMatrix = transformMatrixFromFile.multiplyLeft(transformMatrixFromOptions);
148315
- const { rdefs, channels: channels2, name: omeroName } = omero;
148316
- const t2 = rdefs.defaultT ?? 0;
148317
- const z2 = rdefs.defaultZ ?? 0;
148318
148359
  const filterSelection = (sel) => {
148319
148360
  if (data.length > 0) {
148320
148361
  const nextSel = {};
@@ -148328,14 +148369,37 @@ class OmeZarrLoader extends AbstractTwoStepLoader {
148328
148369
  }
148329
148370
  return sel;
148330
148371
  };
148372
+ let channelObjects;
148373
+ let channelLabels = [];
148374
+ let initialTargetT = 0;
148375
+ let initialTargetZ = 0;
148376
+ if (isSpatialData) {
148377
+ const { channels: channels2 } = spatialDataChannels;
148378
+ channelObjects = channels2.map((channel, i2) => ({
148379
+ selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i2 }),
148380
+ slider: [0, 255],
148381
+ color: [255, 255, 255]
148382
+ }));
148383
+ channelLabels = channels2.map((c) => c.label);
148384
+ } else {
148385
+ const { rdefs, channels: channels2 } = omero;
148386
+ if (typeof rdefs.defaultT === "number") {
148387
+ initialTargetT = rdefs.defaultT;
148388
+ }
148389
+ if (typeof rdefs.defaultZ === "number") {
148390
+ initialTargetZ = rdefs.defaultZ;
148391
+ }
148392
+ channelObjects = channels2.map((channel, i2) => ({
148393
+ selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i2 }),
148394
+ slider: [channel.window.start, channel.window.end],
148395
+ color: hexToRgb(channel.color)
148396
+ }));
148397
+ channelLabels = channels2.map((c) => c.label);
148398
+ }
148331
148399
  const imagesWithLoaderCreators = [
148332
148400
  {
148333
- name: omeroName || "Image",
148334
- channels: channels2.map((channel, i2) => ({
148335
- selection: filterSelection({ z: z2, t: t2, c: i2 }),
148336
- slider: [channel.window.start, channel.window.end],
148337
- color: hexToRgb(channel.color)
148338
- })),
148401
+ name: imageName || "Image",
148402
+ channels: channelObjects,
148339
148403
  ...transformMatrix ? {
148340
148404
  metadata: {
148341
148405
  transform: {
@@ -148343,7 +148407,7 @@ class OmeZarrLoader extends AbstractTwoStepLoader {
148343
148407
  }
148344
148408
  }
148345
148409
  } : {},
148346
- loaderCreator: async () => ({ ...loader, channels: channels2.map((c) => c.label) })
148410
+ loaderCreator: async () => ({ ...loader, channels: channelLabels })
148347
148411
  }
148348
148412
  ];
148349
148413
  const [
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A, F, G, a, M, b, O, f, c, d, e, h, Z } from "./index-e14e0548.js";
1
+ import { A, F, G, a, M, b, O, f, c, d, e, h, Z } from "./index-58807fea.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  export {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-e14e0548.js";
1
+ import { B as BaseDecoder } from "./index-58807fea.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  const dctZigZag = new Int32Array([
@@ -1,5 +1,5 @@
1
1
  import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
2
- import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-e14e0548.js";
2
+ import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-58807fea.js";
3
3
  import "@vitessce/vit-s";
4
4
  import "react";
5
5
  const LercParameters = {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-e14e0548.js";
1
+ import { B as BaseDecoder } from "./index-58807fea.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  const MIN_BITS = 9;
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-e14e0548.js";
1
+ import { B as BaseDecoder } from "./index-58807fea.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  class PackbitsDecoder extends BaseDecoder {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-e14e0548.js";
1
+ import { B as BaseDecoder } from "./index-58807fea.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  class RawDecoder extends BaseDecoder {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-e14e0548.js";
1
+ import { B as BaseDecoder } from "./index-58807fea.js";
2
2
  import "@vitessce/vit-s";
3
3
  import "react";
4
4
  class WebImageDecoder extends BaseDecoder {
@@ -1 +1 @@
1
- {"version":3,"file":"OmeZarrLoader.d.ts","sourceRoot":"","sources":["../../src/ome-loaders/OmeZarrLoader.js"],"names":[],"mappings":"AAqBA;IACE,qBA2FC;CACF"}
1
+ {"version":3,"file":"OmeZarrLoader.d.ts","sourceRoot":"","sources":["../../src/ome-loaders/OmeZarrLoader.js"],"names":[],"mappings":"AAsBA;IACE,qBAsIC;CACF"}
@@ -1,5 +1,5 @@
1
1
  import { viv } from '@vitessce/gl';
2
- import { initializeRasterLayersAndChannels, coordinateTransformationsToMatrix, getNgffAxes, } from '@vitessce/spatial-utils';
2
+ import { initializeRasterLayersAndChannels, coordinateTransformationsToMatrix, getNgffAxes, normalizeCoordinateTransformations, } from '@vitessce/spatial-utils';
3
3
  import { AbstractLoaderError, LoaderResult, AbstractTwoStepLoader, } from '@vitessce/vit-s';
4
4
  function hexToRgb(hex) {
5
5
  const result = /^#?([A-F\d]{2})([A-F\d]{2})([A-F\d]{2})$/i.exec(hex);
@@ -18,23 +18,26 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
18
18
  const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
19
19
  const loader = await viv.loadOmeZarr(this.url, { fetchOptions: this.requestInit, type: 'multiscales' });
20
20
  const { metadata, data } = loader;
21
- const { omero, multiscales } = metadata;
22
- if (!omero) {
23
- console.error('Path for image not valid');
21
+ const { omero, multiscales, channels_metadata: spatialDataChannels } = metadata;
22
+ // Crude way to check if this is a SpatialData OME-NGFF.
23
+ const isSpatialData = !!spatialDataChannels;
24
+ if (!isSpatialData && !omero) {
25
+ console.error('image.ome-zarr must have omero metadata in attributes.');
24
26
  return Promise.reject(payload);
25
27
  }
26
28
  if (!Array.isArray(multiscales) || multiscales.length === 0) {
27
29
  console.error('Multiscales array must exist and have at least one element');
28
30
  }
29
- const { coordinateTransformations } = multiscales[0];
31
+ const { datasets, coordinateTransformations: coordinateTransformationsFromFile, name: imageName, } = multiscales[0];
30
32
  // Axes in v0.4 format.
31
33
  const axes = getNgffAxes(multiscales[0].axes);
34
+ // SpatialData uses the new coordinateTransformations spec.
35
+ // Reference: https://github.com/ome/ngff/pull/138
36
+ // This new spec is very flexible, so here we will attepmpt to convert it back to the old spec.
37
+ const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(coordinateTransformationsFromFile, datasets);
32
38
  const transformMatrixFromOptions = coordinateTransformationsToMatrix(coordinateTransformationsFromOptions, axes);
33
- const transformMatrixFromFile = coordinateTransformationsToMatrix(coordinateTransformations, axes);
39
+ const transformMatrixFromFile = coordinateTransformationsToMatrix(normCoordinateTransformationsFromFile, axes);
34
40
  const transformMatrix = transformMatrixFromFile.multiplyLeft(transformMatrixFromOptions);
35
- const { rdefs, channels, name: omeroName } = omero;
36
- const t = rdefs.defaultT ?? 0;
37
- const z = rdefs.defaultZ ?? 0;
38
41
  const filterSelection = (sel) => {
39
42
  // Remove selection keys for which there is no dimension.
40
43
  if (data.length > 0) {
@@ -50,14 +53,45 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
50
53
  }
51
54
  return sel;
52
55
  };
56
+ let channelObjects;
57
+ let channelLabels = [];
58
+ let initialTargetT = 0;
59
+ let initialTargetZ = 0;
60
+ if (isSpatialData) {
61
+ // TODO: Consider removing support for `channels_metadata` once OME-NGFF loosens
62
+ // requirements for channel metadata fields such as `window` and `color`.
63
+ // (Unclear if we will need to keep this around for backwards compatibility with
64
+ // those SpatialData objects generated in the meantime though.)
65
+ // References:
66
+ // - https://github.com/ome/ngff/issues/192
67
+ // - https://github.com/ome/ome-zarr-py/pull/261
68
+ const { channels } = spatialDataChannels;
69
+ channelObjects = channels.map((channel, i) => ({
70
+ selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
71
+ slider: [0, 255],
72
+ color: [255, 255, 255],
73
+ }));
74
+ channelLabels = channels.map(c => c.label);
75
+ }
76
+ else {
77
+ const { rdefs, channels } = omero;
78
+ if (typeof rdefs.defaultT === 'number') {
79
+ initialTargetT = rdefs.defaultT;
80
+ }
81
+ if (typeof rdefs.defaultZ === 'number') {
82
+ initialTargetZ = rdefs.defaultZ;
83
+ }
84
+ channelObjects = channels.map((channel, i) => ({
85
+ selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
86
+ slider: [channel.window.start, channel.window.end],
87
+ color: hexToRgb(channel.color),
88
+ }));
89
+ channelLabels = channels.map(c => c.label);
90
+ }
53
91
  const imagesWithLoaderCreators = [
54
92
  {
55
- name: omeroName || 'Image',
56
- channels: channels.map((channel, i) => ({
57
- selection: filterSelection({ z, t, c: i }),
58
- slider: [channel.window.start, channel.window.end],
59
- color: hexToRgb(channel.color),
60
- })),
93
+ name: imageName || 'Image',
94
+ channels: channelObjects,
61
95
  ...(transformMatrix ? {
62
96
  metadata: {
63
97
  transform: {
@@ -65,7 +99,7 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
65
99
  },
66
100
  },
67
101
  } : {}),
68
- loaderCreator: async () => ({ ...loader, channels: channels.map(c => c.label) }),
102
+ loaderCreator: async () => ({ ...loader, channels: channelLabels }),
69
103
  },
70
104
  ];
71
105
  // TODO: use options for initial selection of channels
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/zarr",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -19,12 +19,12 @@
19
19
  "d3-array": "^2.4.0",
20
20
  "lodash-es": "^4.17.21",
21
21
  "zarr": "0.5.1",
22
- "@vitessce/constants-internal": "3.1.2",
23
- "@vitessce/gl": "3.1.2",
24
- "@vitessce/sets-utils": "3.1.2",
25
- "@vitessce/spatial-utils": "3.1.2",
26
- "@vitessce/utils": "3.1.2",
27
- "@vitessce/vit-s": "3.1.2"
22
+ "@vitessce/constants-internal": "3.1.3",
23
+ "@vitessce/gl": "3.1.3",
24
+ "@vitessce/sets-utils": "3.1.3",
25
+ "@vitessce/spatial-utils": "3.1.3",
26
+ "@vitessce/utils": "3.1.3",
27
+ "@vitessce/vit-s": "3.1.3"
28
28
  },
29
29
  "scripts": {
30
30
  "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
@@ -3,6 +3,7 @@ import {
3
3
  initializeRasterLayersAndChannels,
4
4
  coordinateTransformationsToMatrix,
5
5
  getNgffAxes,
6
+ normalizeCoordinateTransformations,
6
7
  } from '@vitessce/spatial-utils';
7
8
  import {
8
9
  AbstractLoaderError,
@@ -31,34 +32,46 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
31
32
  const loader = await viv.loadOmeZarr(this.url, { fetchOptions: this.requestInit, type: 'multiscales' });
32
33
  const { metadata, data } = loader;
33
34
 
34
- const { omero, multiscales } = metadata;
35
+ const { omero, multiscales, channels_metadata: spatialDataChannels } = metadata;
35
36
 
36
- if (!omero) {
37
- console.error('Path for image not valid');
37
+ // Crude way to check if this is a SpatialData OME-NGFF.
38
+ const isSpatialData = !!spatialDataChannels;
39
+
40
+ if (!isSpatialData && !omero) {
41
+ console.error('image.ome-zarr must have omero metadata in attributes.');
38
42
  return Promise.reject(payload);
39
43
  }
40
44
 
41
45
  if (!Array.isArray(multiscales) || multiscales.length === 0) {
42
46
  console.error('Multiscales array must exist and have at least one element');
43
47
  }
44
- const { coordinateTransformations } = multiscales[0];
48
+
49
+ const {
50
+ datasets,
51
+ coordinateTransformations: coordinateTransformationsFromFile,
52
+ name: imageName,
53
+ } = multiscales[0];
45
54
 
46
55
  // Axes in v0.4 format.
47
56
  const axes = getNgffAxes(multiscales[0].axes);
48
57
 
58
+ // SpatialData uses the new coordinateTransformations spec.
59
+ // Reference: https://github.com/ome/ngff/pull/138
60
+
61
+ // This new spec is very flexible, so here we will attepmpt to convert it back to the old spec.
62
+ const normCoordinateTransformationsFromFile = normalizeCoordinateTransformations(
63
+ coordinateTransformationsFromFile, datasets,
64
+ );
65
+
49
66
  const transformMatrixFromOptions = coordinateTransformationsToMatrix(
50
67
  coordinateTransformationsFromOptions, axes,
51
68
  );
52
69
  const transformMatrixFromFile = coordinateTransformationsToMatrix(
53
- coordinateTransformations, axes,
70
+ normCoordinateTransformationsFromFile, axes,
54
71
  );
55
72
 
56
73
  const transformMatrix = transformMatrixFromFile.multiplyLeft(transformMatrixFromOptions);
57
74
 
58
- const { rdefs, channels, name: omeroName } = omero;
59
-
60
- const t = rdefs.defaultT ?? 0;
61
- const z = rdefs.defaultZ ?? 0;
62
75
 
63
76
  const filterSelection = (sel) => {
64
77
  // Remove selection keys for which there is no dimension.
@@ -76,14 +89,45 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
76
89
  return sel;
77
90
  };
78
91
 
92
+ let channelObjects;
93
+ let channelLabels = [];
94
+ let initialTargetT = 0;
95
+ let initialTargetZ = 0;
96
+ if (isSpatialData) {
97
+ // TODO: Consider removing support for `channels_metadata` once OME-NGFF loosens
98
+ // requirements for channel metadata fields such as `window` and `color`.
99
+ // (Unclear if we will need to keep this around for backwards compatibility with
100
+ // those SpatialData objects generated in the meantime though.)
101
+ // References:
102
+ // - https://github.com/ome/ngff/issues/192
103
+ // - https://github.com/ome/ome-zarr-py/pull/261
104
+ const { channels } = spatialDataChannels;
105
+ channelObjects = channels.map((channel, i) => ({
106
+ selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
107
+ slider: [0, 255],
108
+ color: [255, 255, 255],
109
+ }));
110
+ channelLabels = channels.map(c => c.label);
111
+ } else {
112
+ const { rdefs, channels } = omero;
113
+ if (typeof rdefs.defaultT === 'number') {
114
+ initialTargetT = rdefs.defaultT;
115
+ }
116
+ if (typeof rdefs.defaultZ === 'number') {
117
+ initialTargetZ = rdefs.defaultZ;
118
+ }
119
+ channelObjects = channels.map((channel, i) => ({
120
+ selection: filterSelection({ z: initialTargetZ, t: initialTargetT, c: i }),
121
+ slider: [channel.window.start, channel.window.end],
122
+ color: hexToRgb(channel.color),
123
+ }));
124
+ channelLabels = channels.map(c => c.label);
125
+ }
126
+
79
127
  const imagesWithLoaderCreators = [
80
128
  {
81
- name: omeroName || 'Image',
82
- channels: channels.map((channel, i) => ({
83
- selection: filterSelection({ z, t, c: i }),
84
- slider: [channel.window.start, channel.window.end],
85
- color: hexToRgb(channel.color),
86
- })),
129
+ name: imageName || 'Image',
130
+ channels: channelObjects,
87
131
  ...(transformMatrix ? {
88
132
  metadata: {
89
133
  transform: {
@@ -91,7 +135,7 @@ export default class OmeZarrLoader extends AbstractTwoStepLoader {
91
135
  },
92
136
  },
93
137
  } : {}),
94
- loaderCreator: async () => ({ ...loader, channels: channels.map(c => c.label) }),
138
+ loaderCreator: async () => ({ ...loader, channels: channelLabels }),
95
139
  },
96
140
  ];
97
141