omezarr-tilesource 0.3.0 → 0.5.0

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.
package/README.md CHANGED
@@ -22,6 +22,14 @@ Using pnpm:
22
22
  pnpm add omezarr-tilesource
23
23
  ```
24
24
 
25
+ The package is distributed as an ES module for use with a bundler (e.g. Vite).
26
+ [zarrita](https://github.com/manzt/zarrita.js),
27
+ [@zarrita/storage](https://github.com/manzt/zarrita.js) and
28
+ [ome-zarr.js](https://github.com/BioNGFF/ome-zarr.js) are peer dependencies
29
+ (installed automatically by pnpm and npm 7 or newer) and are not bundled, so
30
+ the app and the tile source share a single copy, e.g. for passing `NgffImage`
31
+ instances loaded by the app.
32
+
25
33
  ## Usage
26
34
 
27
35
  ```javascript
@@ -40,8 +48,8 @@ const tileSource2 = {
40
48
  url: url,
41
49
  // zip: undefined, // undefined = OME-Zarr ZIP auto-detection based on .ozx suffix
42
50
  // c: undefined, // undefined = composite of all active channels (requires dataType "context2d")
43
- // z: undefined, // undefined = omero metadata default
44
- // t: undefined, // undefined = omero metadata default
51
+ // z: undefined, // undefined = omero rdefs default (middle z-slice if missing)
52
+ // t: undefined, // undefined = omero rdefs default (middle timepoint if missing)
45
53
  // dataType: undefined, // "context2d" (default, rendered tiles) or "ome-zarr" (raw single-channel chunks)
46
54
  // autoBoost: undefined // boost brightness of dark tiles (default false)
47
55
  };
@@ -54,13 +62,13 @@ const tileSource4 = new OMEZarrTileSource({
54
62
  url: url,
55
63
  // zip: undefined, // undefined = OME-Zarr ZIP auto-detection based on .ozx suffix
56
64
  // c: undefined, // undefined = composite of all active channels (requires dataType "context2d")
57
- // z: undefined, // undefined = omero metadata default
58
- // t: undefined, // undefined = omero metadata default
65
+ // z: undefined, // undefined = omero rdefs default (middle z-slice if missing)
66
+ // t: undefined, // undefined = omero rdefs default (middle timepoint if missing)
59
67
  // dataType: undefined, // "context2d" (default, rendered tiles) or "ome-zarr" (raw single-channel chunks)
60
68
  // autoBoost: undefined // boost brightness of dark tiles (default false)
61
69
  });
62
70
 
63
- const viewer = OpenSeadragon(
71
+ const viewer = OpenSeadragon({
64
72
  ...
65
73
  tileSources: [
66
74
  tileSource1,
@@ -68,7 +76,55 @@ const viewer = OpenSeadragon(
68
76
  tileSource3,
69
77
  tileSource4
70
78
  ]
79
+ });
80
+ ```
81
+
82
+ ### Accessing OME-Zarr metadata
83
+
84
+ Directly instantiated tile sources start loading the OME-Zarr metadata
85
+ immediately. Await `whenReady()` (or use the `OMEZarrTileSource.open` shortcut)
86
+ to access the `NgffImage` instance (ome-zarr.js) and the opened zarrita arrays
87
+ (one per resolution level) before adding the tile source to a viewer:
88
+
89
+ ```javascript
90
+ const tileSource = await OMEZarrTileSource.open({ url: url, c: 0 });
91
+ // equivalent: await new OMEZarrTileSource({ url: url, c: 0 }).whenReady();
92
+
93
+ console.log(tileSource.image.getAxesNames()); // e.g. ["t", "z", "c", "y", "x"]
94
+ console.log(tileSource.image.omero?.channels); // omero channel metadata
95
+ console.log(tileSource.arrays[0].shape); // full-resolution array shape
96
+
97
+ viewer.addTiledImage({ tileSource: tileSource }); // no second metadata request
98
+ ```
99
+
100
+ The metadata is loaded once per tile source instance: OpenSeadragon reuses a
101
+ tile source instance passed to it as-is (waiting for it to become ready if
102
+ necessary), whereas a URL or an inline configuration object makes OpenSeadragon
103
+ create (and load) a new instance. `whenReady()` rejects (and `image`/`arrays`
104
+ throw) if loading fails.
105
+
106
+ ### Sharing OME-Zarr metadata between tile sources
107
+
108
+ A loaded `NgffImage` can be reused by other directly instantiated tile sources
109
+ for the same URL (e.g. one tile source per channel) by passing it as the second
110
+ constructor argument (also supported by `OMEZarrTileSource.open`). This skips
111
+ loading the OME-Zarr metadata (the `zip` option is ignored) and reuses the
112
+ opened zarrita arrays, which ome-zarr.js caches on the `NgffImage` instance.
113
+ The tile source never modifies the `NgffImage`, so sharing is safe:
114
+
115
+ ```javascript
116
+ import { NgffImage } from "ome-zarr.js";
117
+
118
+ // reuse the image loaded by a first tile source
119
+ const tileSource1 = await OMEZarrTileSource.open({ url: url, c: 0 });
120
+ const tileSource2 = new OMEZarrTileSource(
121
+ { url: url, c: 1 },
122
+ tileSource1.image,
71
123
  );
124
+
125
+ // or load the image with the app's own ome-zarr.js import
126
+ const image = await NgffImage.load(url);
127
+ const tileSource3 = new OMEZarrTileSource({ url: url, c: 2 }, image);
72
128
  ```
73
129
 
74
130
  ## Data pipeline
@@ -79,6 +135,11 @@ passed to OpenSeadragon as 2D canvas contexts, using the rendering settings
79
135
  multi-channel images without `c`, all active channels are rendered into a
80
136
  composite image.
81
137
 
138
+ Contrast limits are taken from the omero channel windows (`window.start`,
139
+ `window.end`). Channels without them are rendered using the data type range
140
+ for integer types (e.g. `[0, 65535]` for `uint16`) and `[0, 1]` for floating
141
+ point types.
142
+
82
143
  With `dataType: "ome-zarr"`, tiles are instead downloaded as raw single-channel
83
144
  zarrita chunks and passed to OpenSeadragon with the data type `ome-zarr` (see
84
145
  the `OMEZarrTileData` type). Multi-channel images therefore require the `c`
@@ -1,5 +1,6 @@
1
1
  import { Channel } from 'ome-zarr.js';
2
2
  import { default as default_2 } from 'openseadragon';
3
+ import { NgffImage } from 'ome-zarr.js';
3
4
  import * as zarr from 'zarrita';
4
5
 
5
6
  export declare interface OMEZarrTileData {
@@ -20,8 +21,13 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
20
21
  height: number;
21
22
  private _image?;
22
23
  private _arrays?;
23
- constructor(url: string);
24
- constructor(options: OMEZarrTileSourceOptions);
24
+ private readonly _readyPromise;
25
+ static open(config: string | OMEZarrTileSourceOptions, image?: NgffImage): Promise<OMEZarrTileSource>;
26
+ constructor(url: string, image?: NgffImage);
27
+ constructor(options: OMEZarrTileSourceOptions, image?: NgffImage);
28
+ get image(): NgffImage;
29
+ get arrays(): zarr.Array<zarr.NumberDataType | zarr.BigintDataType>[];
30
+ whenReady(): Promise<this>;
25
31
  supports(data: string | object | object[] | Document): boolean;
26
32
  configure(data: string | object | object[] | Document, _url: string, postData?: string | null): OMEZarrTileSourceOptions;
27
33
  equals(other: default_2.TileSource): boolean;
@@ -37,6 +43,7 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
37
43
  private static _learnConverters;
38
44
  private _getActiveChannelIndices;
39
45
  private static _render;
46
+ private static _getDataTypeRange;
40
47
  }
41
48
 
42
49
  export declare interface OMEZarrTileSourceOptions {