@vitessce/ome-tiff 3.0.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.
@@ -0,0 +1,11 @@
1
+ import { B as BaseDecoder } from "./index-db8fde1e.js";
2
+ import "react";
3
+ import "@vitessce/vit-s";
4
+ class RawDecoder extends BaseDecoder {
5
+ decodeBlock(buffer) {
6
+ return buffer;
7
+ }
8
+ }
9
+ export {
10
+ RawDecoder as default
11
+ };
@@ -0,0 +1,31 @@
1
+ import { B as BaseDecoder } from "./index-db8fde1e.js";
2
+ import "react";
3
+ import "@vitessce/vit-s";
4
+ class WebImageDecoder extends BaseDecoder {
5
+ constructor() {
6
+ super();
7
+ if (typeof createImageBitmap === "undefined") {
8
+ throw new Error("Cannot decode WebImage as `createImageBitmap` is not available");
9
+ } else if (typeof document === "undefined" && typeof OffscreenCanvas === "undefined") {
10
+ throw new Error("Cannot decode WebImage as neither `document` nor `OffscreenCanvas` is not available");
11
+ }
12
+ }
13
+ async decode(fileDirectory, buffer) {
14
+ const blob = new Blob([buffer]);
15
+ const imageBitmap = await createImageBitmap(blob);
16
+ let canvas;
17
+ if (typeof document !== "undefined") {
18
+ canvas = document.createElement("canvas");
19
+ canvas.width = imageBitmap.width;
20
+ canvas.height = imageBitmap.height;
21
+ } else {
22
+ canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
23
+ }
24
+ const ctx = canvas.getContext("2d");
25
+ ctx.drawImage(imageBitmap, 0, 0);
26
+ return ctx.getImageData(0, 0, imageBitmap.width, imageBitmap.height).data.buffer;
27
+ }
28
+ }
29
+ export {
30
+ WebImageDecoder as default
31
+ };
@@ -0,0 +1,4 @@
1
+ export default class OmeTiffAsObsSegmentationsLoader extends OmeTiffLoader {
2
+ }
3
+ import OmeTiffLoader from "./OmeTiffLoader.js";
4
+ //# sourceMappingURL=OmeTiffAsObsSegmentationsLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OmeTiffAsObsSegmentationsLoader.d.ts","sourceRoot":"","sources":["../src/OmeTiffAsObsSegmentationsLoader.js"],"names":[],"mappings":"AASA;CAwFC"}
@@ -0,0 +1,62 @@
1
+ import { viv } from '@vitessce/gl';
2
+ import { LoaderResult } from '@vitessce/vit-s';
3
+ import { initializeRasterLayersAndChannels, coordinateTransformationsToMatrix, getNgffAxesForTiff, } from '@vitessce/spatial-utils';
4
+ import OmeTiffLoader from './OmeTiffLoader.js';
5
+ export default class OmeTiffAsObsSegmentationsLoader extends OmeTiffLoader {
6
+ async load() {
7
+ const { url, requestInit } = this;
8
+ const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
9
+ const offsets = await this.loadOffsets();
10
+ const loader = await viv.loadOmeTiff(url, { offsets, headers: requestInit?.headers });
11
+ const { Name: imageName, Pixels: { Channels, DimensionOrder, PhysicalSizeX, PhysicalSizeXUnit, PhysicalSizeY, PhysicalSizeYUnit, }, } = loader.metadata;
12
+ // Get image name and URL tuples.
13
+ const urls = [url, 'OME-TIFF'];
14
+ const transformMatrixFromOptions = coordinateTransformationsToMatrix(coordinateTransformationsFromOptions, getNgffAxesForTiff(DimensionOrder));
15
+ const usePhysicalSizeScaling = (PhysicalSizeX
16
+ && PhysicalSizeXUnit
17
+ && PhysicalSizeY
18
+ && PhysicalSizeYUnit);
19
+ const image = {
20
+ name: imageName || 'Image',
21
+ url,
22
+ type: 'ome-tiff',
23
+ // This load() method is the same as in ./OmeTiffLoader except we specify isBitmask here:
24
+ metadata: {
25
+ isBitmask: true,
26
+ ...(transformMatrixFromOptions ? {
27
+ transform: {
28
+ matrix: transformMatrixFromOptions,
29
+ },
30
+ } : {}),
31
+ },
32
+ };
33
+ // Add a loaderCreator function for each image layer.
34
+ const imagesWithLoaderCreators = [
35
+ {
36
+ ...image,
37
+ loaderCreator: async () => {
38
+ const channels = Array.isArray(Channels)
39
+ ? Channels.map((channel, i) => channel.Name || `Channel ${i}`)
40
+ : [Channels.Name || `Channel ${0}`];
41
+ return { ...loader, channels };
42
+ },
43
+ },
44
+ ];
45
+ const renderLayers = null;
46
+ // TODO: use options for initial selection of channels
47
+ // which omit domain/slider ranges.
48
+ if (!this.autoImageCache) {
49
+ this.autoImageCache = initializeRasterLayersAndChannels(imagesWithLoaderCreators, renderLayers, usePhysicalSizeScaling);
50
+ }
51
+ return this.autoImageCache.then((autoImages) => {
52
+ const [autoImageLayers, imageLayerLoaders, imageLayerMeta] = autoImages;
53
+ const coordinationValues = {
54
+ spatialSegmentationLayer: autoImageLayers,
55
+ };
56
+ return new LoaderResult({
57
+ obsSegmentationsType: 'bitmask',
58
+ obsSegmentations: { loaders: imageLayerLoaders, meta: imageLayerMeta },
59
+ }, urls, coordinationValues);
60
+ });
61
+ }
62
+ }
@@ -0,0 +1,6 @@
1
+ export default class OmeTiffLoader {
2
+ loadOffsets(): Promise<any>;
3
+ load(): Promise<any>;
4
+ autoImageCache: any;
5
+ }
6
+ //# sourceMappingURL=OmeTiffLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OmeTiffLoader.d.ts","sourceRoot":"","sources":["../src/OmeTiffLoader.js"],"names":[],"mappings":"AAQA;IACE,4BAWC;IAED,qBAqFC;IAtBG,oBAIC;CAmBN"}
@@ -0,0 +1,71 @@
1
+ import { viv } from '@vitessce/gl';
2
+ import { initializeRasterLayersAndChannels, coordinateTransformationsToMatrix, getNgffAxesForTiff, } from '@vitessce/spatial-utils';
3
+ import { AbstractTwoStepLoader, LoaderResult } from '@vitessce/vit-s';
4
+ export default class OmeTiffLoader extends AbstractTwoStepLoader {
5
+ async loadOffsets() {
6
+ const { offsetsUrl } = this.options || {};
7
+ if (offsetsUrl) {
8
+ const res = await fetch(offsetsUrl, (this.requestInit || {}));
9
+ if (res.ok) {
10
+ const offsets = await res.json();
11
+ return offsets;
12
+ }
13
+ throw new Error(`OME-TIFF offsets JSON file failed to load: ${res.status} from ${res.url}`);
14
+ }
15
+ return null;
16
+ }
17
+ async load() {
18
+ const { url, requestInit } = this;
19
+ const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
20
+ // Get image name and URL tuples.
21
+ const urls = [
22
+ [url, 'image'],
23
+ ];
24
+ const offsets = await this.loadOffsets();
25
+ const loader = await viv.loadOmeTiff(url, { offsets, headers: requestInit?.headers });
26
+ const { Name: imageName, Pixels: { Channels, DimensionOrder, PhysicalSizeX, PhysicalSizeXUnit, PhysicalSizeY, PhysicalSizeYUnit, }, } = loader.metadata;
27
+ const channels = Array.isArray(Channels)
28
+ ? Channels.map((channel, i) => channel.Name || `Channel ${i}`)
29
+ : [Channels.Name || `Channel ${0}`];
30
+ const transformMatrixFromOptions = coordinateTransformationsToMatrix(coordinateTransformationsFromOptions, getNgffAxesForTiff(DimensionOrder));
31
+ const usePhysicalSizeScaling = (PhysicalSizeX
32
+ && PhysicalSizeXUnit
33
+ && PhysicalSizeY
34
+ && PhysicalSizeYUnit);
35
+ const image = {
36
+ name: imageName || 'Image',
37
+ url,
38
+ type: 'ome-tiff',
39
+ ...(transformMatrixFromOptions ? {
40
+ metadata: {
41
+ transform: {
42
+ matrix: transformMatrixFromOptions,
43
+ },
44
+ },
45
+ } : {}),
46
+ };
47
+ // Add a loaderCreator function for each image layer.
48
+ const imagesWithLoaderCreators = [
49
+ {
50
+ ...image,
51
+ loaderCreator: async () => ({ ...loader, channels }),
52
+ },
53
+ ];
54
+ const renderLayers = null;
55
+ // TODO: use options for initial selection of channels
56
+ // which omit domain/slider ranges.
57
+ if (!this.autoImageCache) {
58
+ this.autoImageCache = initializeRasterLayersAndChannels(imagesWithLoaderCreators, renderLayers, usePhysicalSizeScaling);
59
+ }
60
+ return this.autoImageCache.then((autoImages) => {
61
+ const [autoImageLayers, imageLayerLoaders, imageLayerMeta] = autoImages;
62
+ const coordinationValues = {
63
+ spatialImageLayer: autoImageLayers,
64
+ };
65
+ return new LoaderResult({
66
+ image: { loaders: imageLayerLoaders, meta: imageLayerMeta },
67
+ featureIndex: channels,
68
+ }, urls, coordinationValues);
69
+ });
70
+ }
71
+ }
@@ -0,0 +1,9 @@
1
+ export default class OmeTiffSource {
2
+ constructor({ url, requestInit }: {
3
+ url: any;
4
+ requestInit: any;
5
+ });
6
+ url: any;
7
+ requestInit: any;
8
+ }
9
+ //# sourceMappingURL=OmeTiffSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OmeTiffSource.d.ts","sourceRoot":"","sources":["../src/OmeTiffSource.js"],"names":[],"mappings":"AACA;IACE;;;OAGC;IAFC,SAAc;IACd,iBAA8B;CAEjC"}
@@ -0,0 +1,6 @@
1
+ export default class OmeTiffSource {
2
+ constructor({ url, requestInit }) {
3
+ this.url = url;
4
+ this.requestInit = requestInit;
5
+ }
6
+ }
@@ -0,0 +1,4 @@
1
+ export { default as OmeTiffSource } from "./OmeTiffSource.js";
2
+ export { default as OmeTiffLoader } from "./OmeTiffLoader.js";
3
+ export { default as OmeTiffAsObsSegmentationsLoader } from "./OmeTiffAsObsSegmentationsLoader.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export { default as OmeTiffSource } from './OmeTiffSource.js';
2
+ export { default as OmeTiffLoader } from './OmeTiffLoader.js';
3
+ export { default as OmeTiffAsObsSegmentationsLoader } from './OmeTiffAsObsSegmentationsLoader.js';
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vitessce/ome-tiff",
3
+ "version": "3.0.0",
4
+ "author": "Gehlenborg Lab",
5
+ "homepage": "http://vitessce.io",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/vitessce/vitessce.git"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "files": [
14
+ "src",
15
+ "dist",
16
+ "dist-tsc"
17
+ ],
18
+ "dependencies": {
19
+ "ajv": "^6.10.0",
20
+ "d3-array": "^2.4.0",
21
+ "lodash-es": "^4.17.21",
22
+ "@vitessce/constants-internal": "3.0.0",
23
+ "@vitessce/gl": "3.0.0",
24
+ "@vitessce/sets-utils": "3.0.0",
25
+ "@vitessce/spatial-utils": "3.0.0",
26
+ "@vitessce/utils": "3.0.0",
27
+ "@vitessce/vit-s": "3.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "ajv": "^6.10.0"
31
+ },
32
+ "scripts": {
33
+ "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
34
+ "test": "pnpm exec vitest --run -r ../../../ --dir ."
35
+ },
36
+ "module": "dist/index.js",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist-tsc/index.d.ts",
40
+ "import": "./dist/index.js"
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,98 @@
1
+ import { viv } from '@vitessce/gl';
2
+ import { LoaderResult } from '@vitessce/vit-s';
3
+ import {
4
+ initializeRasterLayersAndChannels,
5
+ coordinateTransformationsToMatrix,
6
+ getNgffAxesForTiff,
7
+ } from '@vitessce/spatial-utils';
8
+ import OmeTiffLoader from './OmeTiffLoader.js';
9
+
10
+ export default class OmeTiffAsObsSegmentationsLoader extends OmeTiffLoader {
11
+ async load() {
12
+ const { url, requestInit } = this;
13
+ const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
14
+ const offsets = await this.loadOffsets();
15
+ const loader = await viv.loadOmeTiff(url, { offsets, headers: requestInit?.headers });
16
+ const {
17
+ Name: imageName,
18
+ Pixels: {
19
+ Channels,
20
+ DimensionOrder,
21
+ PhysicalSizeX,
22
+ PhysicalSizeXUnit,
23
+ PhysicalSizeY,
24
+ PhysicalSizeYUnit,
25
+ },
26
+ } = loader.metadata;
27
+
28
+ // Get image name and URL tuples.
29
+ const urls = [url, 'OME-TIFF'];
30
+
31
+ const transformMatrixFromOptions = coordinateTransformationsToMatrix(
32
+ coordinateTransformationsFromOptions, getNgffAxesForTiff(DimensionOrder),
33
+ );
34
+
35
+ const usePhysicalSizeScaling = (
36
+ PhysicalSizeX
37
+ && PhysicalSizeXUnit
38
+ && PhysicalSizeY
39
+ && PhysicalSizeYUnit
40
+ );
41
+
42
+ const image = {
43
+ name: imageName || 'Image',
44
+ url,
45
+ type: 'ome-tiff',
46
+ // This load() method is the same as in ./OmeTiffLoader except we specify isBitmask here:
47
+ metadata: {
48
+ isBitmask: true,
49
+ ...(transformMatrixFromOptions ? {
50
+ transform: {
51
+ matrix: transformMatrixFromOptions,
52
+ },
53
+ } : {}),
54
+ },
55
+ };
56
+
57
+ // Add a loaderCreator function for each image layer.
58
+ const imagesWithLoaderCreators = [
59
+ {
60
+ ...image,
61
+ loaderCreator: async () => {
62
+ const channels = Array.isArray(Channels)
63
+ ? Channels.map((channel, i) => channel.Name || `Channel ${i}`)
64
+ : [Channels.Name || `Channel ${0}`];
65
+ return { ...loader, channels };
66
+ },
67
+ },
68
+ ];
69
+
70
+ const renderLayers = null;
71
+
72
+ // TODO: use options for initial selection of channels
73
+ // which omit domain/slider ranges.
74
+ if (!this.autoImageCache) {
75
+ this.autoImageCache = initializeRasterLayersAndChannels(
76
+ imagesWithLoaderCreators,
77
+ renderLayers,
78
+ usePhysicalSizeScaling,
79
+ );
80
+ }
81
+
82
+ return this.autoImageCache.then((autoImages) => {
83
+ const [autoImageLayers, imageLayerLoaders, imageLayerMeta] = autoImages;
84
+
85
+ const coordinationValues = {
86
+ spatialSegmentationLayer: autoImageLayers,
87
+ };
88
+ return new LoaderResult(
89
+ {
90
+ obsSegmentationsType: 'bitmask',
91
+ obsSegmentations: { loaders: imageLayerLoaders, meta: imageLayerMeta },
92
+ },
93
+ urls,
94
+ coordinationValues,
95
+ );
96
+ });
97
+ }
98
+ }
@@ -0,0 +1,109 @@
1
+ import { viv } from '@vitessce/gl';
2
+ import {
3
+ initializeRasterLayersAndChannels,
4
+ coordinateTransformationsToMatrix,
5
+ getNgffAxesForTiff,
6
+ } from '@vitessce/spatial-utils';
7
+ import { AbstractTwoStepLoader, LoaderResult } from '@vitessce/vit-s';
8
+
9
+ export default class OmeTiffLoader extends AbstractTwoStepLoader {
10
+ async loadOffsets() {
11
+ const { offsetsUrl } = this.options || {};
12
+ if (offsetsUrl) {
13
+ const res = await fetch(offsetsUrl, (this.requestInit || {}));
14
+ if (res.ok) {
15
+ const offsets = await res.json();
16
+ return offsets;
17
+ }
18
+ throw new Error(`OME-TIFF offsets JSON file failed to load: ${res.status} from ${res.url}`);
19
+ }
20
+ return null;
21
+ }
22
+
23
+ async load() {
24
+ const { url, requestInit } = this;
25
+ const { coordinateTransformations: coordinateTransformationsFromOptions } = this.options || {};
26
+
27
+ // Get image name and URL tuples.
28
+ const urls = [
29
+ [url, 'image'],
30
+ ];
31
+
32
+ const offsets = await this.loadOffsets();
33
+ const loader = await viv.loadOmeTiff(url, { offsets, headers: requestInit?.headers });
34
+ const {
35
+ Name: imageName,
36
+ Pixels: {
37
+ Channels,
38
+ DimensionOrder,
39
+ PhysicalSizeX,
40
+ PhysicalSizeXUnit,
41
+ PhysicalSizeY,
42
+ PhysicalSizeYUnit,
43
+ },
44
+ } = loader.metadata;
45
+ const channels = Array.isArray(Channels)
46
+ ? Channels.map((channel, i) => channel.Name || `Channel ${i}`)
47
+ : [Channels.Name || `Channel ${0}`];
48
+
49
+ const transformMatrixFromOptions = coordinateTransformationsToMatrix(
50
+ coordinateTransformationsFromOptions, getNgffAxesForTiff(DimensionOrder),
51
+ );
52
+
53
+ const usePhysicalSizeScaling = (
54
+ PhysicalSizeX
55
+ && PhysicalSizeXUnit
56
+ && PhysicalSizeY
57
+ && PhysicalSizeYUnit
58
+ );
59
+
60
+ const image = {
61
+ name: imageName || 'Image',
62
+ url,
63
+ type: 'ome-tiff',
64
+ ...(transformMatrixFromOptions ? {
65
+ metadata: {
66
+ transform: {
67
+ matrix: transformMatrixFromOptions,
68
+ },
69
+ },
70
+ } : {}),
71
+ };
72
+
73
+ // Add a loaderCreator function for each image layer.
74
+ const imagesWithLoaderCreators = [
75
+ {
76
+ ...image,
77
+ loaderCreator: async () => ({ ...loader, channels }),
78
+ },
79
+ ];
80
+
81
+ const renderLayers = null;
82
+
83
+ // TODO: use options for initial selection of channels
84
+ // which omit domain/slider ranges.
85
+ if (!this.autoImageCache) {
86
+ this.autoImageCache = initializeRasterLayersAndChannels(
87
+ imagesWithLoaderCreators,
88
+ renderLayers,
89
+ usePhysicalSizeScaling,
90
+ );
91
+ }
92
+
93
+ return this.autoImageCache.then((autoImages) => {
94
+ const [autoImageLayers, imageLayerLoaders, imageLayerMeta] = autoImages;
95
+
96
+ const coordinationValues = {
97
+ spatialImageLayer: autoImageLayers,
98
+ };
99
+ return new LoaderResult(
100
+ {
101
+ image: { loaders: imageLayerLoaders, meta: imageLayerMeta },
102
+ featureIndex: channels,
103
+ },
104
+ urls,
105
+ coordinationValues,
106
+ );
107
+ });
108
+ }
109
+ }
@@ -0,0 +1,7 @@
1
+
2
+ export default class OmeTiffSource {
3
+ constructor({ url, requestInit }) {
4
+ this.url = url;
5
+ this.requestInit = requestInit;
6
+ }
7
+ }
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default as OmeTiffSource } from './OmeTiffSource.js';
2
+ export { default as OmeTiffLoader } from './OmeTiffLoader.js';
3
+ export { default as OmeTiffAsObsSegmentationsLoader } from './OmeTiffAsObsSegmentationsLoader.js';