@loaders.gl/scientific 0.0.0-stage → 5.0.0-alpha.13
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 +21 -2
- package/dist/index.cjs +4313 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/netcdf/bundled.cjs +1394 -0
- package/dist/netcdf/bundled.d.ts +2 -0
- package/dist/netcdf/bundled.d.ts.map +1 -0
- package/dist/netcdf/bundled.js +5 -0
- package/dist/netcdf/bundled.js.map +1 -0
- package/dist/netcdf/index.cjs +1394 -0
- package/dist/netcdf/index.cjs.map +6 -0
- package/dist/netcdf/index.d.ts +7 -0
- package/dist/netcdf/index.d.ts.map +1 -0
- package/dist/netcdf/index.js +8 -0
- package/dist/netcdf/index.js.map +1 -0
- package/dist/netcdf/iobuffer/iobuffer.d.ts +253 -0
- package/dist/netcdf/iobuffer/iobuffer.d.ts.map +1 -0
- package/dist/netcdf/iobuffer/iobuffer.js +450 -0
- package/dist/netcdf/iobuffer/iobuffer.js.map +1 -0
- package/dist/netcdf/netcdf-format.cjs +39 -0
- package/dist/netcdf/netcdf-format.d.ts +11 -0
- package/dist/netcdf/netcdf-format.d.ts.map +1 -0
- package/dist/netcdf/netcdf-format.js +14 -0
- package/dist/netcdf/netcdf-format.js.map +1 -0
- package/dist/netcdf/netcdf-loader-with-parser.cjs +995 -0
- package/dist/netcdf/netcdf-loader-with-parser.d.ts +60 -0
- package/dist/netcdf/netcdf-loader-with-parser.d.ts.map +1 -0
- package/dist/netcdf/netcdf-loader-with-parser.js +35 -0
- package/dist/netcdf/netcdf-loader-with-parser.js.map +1 -0
- package/dist/netcdf/netcdf-loader.cjs +84 -0
- package/dist/netcdf/netcdf-loader.d.ts +81 -0
- package/dist/netcdf/netcdf-loader.d.ts.map +1 -0
- package/dist/netcdf/netcdf-loader.js +41 -0
- package/dist/netcdf/netcdf-loader.js.map +1 -0
- package/dist/netcdf/netcdf-source-loader-types.cjs +78 -0
- package/dist/netcdf/netcdf-source-loader-types.d.ts +28 -0
- package/dist/netcdf/netcdf-source-loader-types.d.ts.map +1 -0
- package/dist/netcdf/netcdf-source-loader-types.js +32 -0
- package/dist/netcdf/netcdf-source-loader-types.js.map +1 -0
- package/dist/netcdf/netcdf-source-loader.cjs +1319 -0
- package/dist/netcdf/netcdf-source-loader.d.ts +59 -0
- package/dist/netcdf/netcdf-source-loader.d.ts.map +1 -0
- package/dist/netcdf/netcdf-source-loader.js +421 -0
- package/dist/netcdf/netcdf-source-loader.js.map +1 -0
- package/dist/netcdf/netcdfjs/netcdf-reader.d.ts +68 -0
- package/dist/netcdf/netcdfjs/netcdf-reader.d.ts.map +1 -0
- package/dist/netcdf/netcdfjs/netcdf-reader.js +172 -0
- package/dist/netcdf/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/netcdf/netcdfjs/netcdf-types.d.ts +70 -0
- package/dist/netcdf/netcdfjs/netcdf-types.d.ts.map +1 -0
- package/dist/netcdf/netcdfjs/netcdf-types.js +3 -0
- package/dist/netcdf/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/netcdf/netcdfjs/read-data.d.ts +19 -0
- package/dist/netcdf/netcdfjs/read-data.d.ts.map +1 -0
- package/dist/netcdf/netcdfjs/read-data.js +51 -0
- package/dist/netcdf/netcdfjs/read-data.js.map +1 -0
- package/dist/netcdf/netcdfjs/read-header.d.ts +16 -0
- package/dist/netcdf/netcdfjs/read-header.d.ts.map +1 -0
- package/dist/netcdf/netcdfjs/read-header.js +227 -0
- package/dist/netcdf/netcdfjs/read-header.js.map +1 -0
- package/dist/netcdf/netcdfjs/read-type.d.ts +36 -0
- package/dist/netcdf/netcdfjs/read-type.d.ts.map +1 -0
- package/dist/netcdf/netcdfjs/read-type.js +135 -0
- package/dist/netcdf/netcdfjs/read-type.js.map +1 -0
- package/dist/netcdf/unbundled.cjs +1394 -0
- package/dist/netcdf/unbundled.d.ts +2 -0
- package/dist/netcdf/unbundled.d.ts.map +1 -0
- package/dist/netcdf/unbundled.js +5 -0
- package/dist/netcdf/unbundled.js.map +1 -0
- package/dist/netcdf.dev.js +3153 -0
- package/dist/netcdf.min.js +12 -0
- package/dist/zarr/bundled.d.ts +2 -0
- package/dist/zarr/bundled.d.ts.map +1 -0
- package/dist/zarr/bundled.js +5 -0
- package/dist/zarr/bundled.js.map +1 -0
- package/dist/zarr/geo-zarr-source-loader.d.ts +121 -0
- package/dist/zarr/geo-zarr-source-loader.d.ts.map +1 -0
- package/dist/zarr/geo-zarr-source-loader.js +692 -0
- package/dist/zarr/geo-zarr-source-loader.js.map +1 -0
- package/dist/zarr/index.cjs +14747 -0
- package/dist/zarr/index.cjs.map +6 -0
- package/dist/zarr/index.d.ts +11 -0
- package/dist/zarr/index.d.ts.map +1 -0
- package/dist/zarr/index.js +10 -0
- package/dist/zarr/index.js.map +1 -0
- package/dist/zarr/lib/consolidated-zarr.d.ts +31 -0
- package/dist/zarr/lib/consolidated-zarr.d.ts.map +1 -0
- package/dist/zarr/lib/consolidated-zarr.js +113 -0
- package/dist/zarr/lib/consolidated-zarr.js.map +1 -0
- package/dist/zarr/lib/load-zarr.d.ts +11 -0
- package/dist/zarr/lib/load-zarr.d.ts.map +1 -0
- package/dist/zarr/lib/load-zarr.js +22 -0
- package/dist/zarr/lib/load-zarr.js.map +1 -0
- package/dist/zarr/lib/spatial-multiscales.d.ts +14 -0
- package/dist/zarr/lib/spatial-multiscales.d.ts.map +1 -0
- package/dist/zarr/lib/spatial-multiscales.js +34 -0
- package/dist/zarr/lib/spatial-multiscales.js.map +1 -0
- package/dist/zarr/lib/utils.d.ts +28 -0
- package/dist/zarr/lib/utils.d.ts.map +1 -0
- package/dist/zarr/lib/utils.js +137 -0
- package/dist/zarr/lib/utils.js.map +1 -0
- package/dist/zarr/lib/zarr-data-cache.d.ts +13 -0
- package/dist/zarr/lib/zarr-data-cache.d.ts.map +1 -0
- package/dist/zarr/lib/zarr-data-cache.js +70 -0
- package/dist/zarr/lib/zarr-data-cache.js.map +1 -0
- package/dist/zarr/lib/zarr-pixel-source.d.ts +41 -0
- package/dist/zarr/lib/zarr-pixel-source.d.ts.map +1 -0
- package/dist/zarr/lib/zarr-pixel-source.js +97 -0
- package/dist/zarr/lib/zarr-pixel-source.js.map +1 -0
- package/dist/zarr/lib/zarrita-pixel-source.d.ts +40 -0
- package/dist/zarr/lib/zarrita-pixel-source.d.ts.map +1 -0
- package/dist/zarr/lib/zarrita-pixel-source.js +96 -0
- package/dist/zarr/lib/zarrita-pixel-source.js.map +1 -0
- package/dist/zarr/ome-zarr-source-loader.d.ts +195 -0
- package/dist/zarr/ome-zarr-source-loader.d.ts.map +1 -0
- package/dist/zarr/ome-zarr-source-loader.js +523 -0
- package/dist/zarr/ome-zarr-source-loader.js.map +1 -0
- package/dist/zarr/spatial-data-source.d.ts +95 -0
- package/dist/zarr/spatial-data-source.d.ts.map +1 -0
- package/dist/zarr/spatial-data-source.js +242 -0
- package/dist/zarr/spatial-data-source.js.map +1 -0
- package/dist/zarr/types.d.ts +105 -0
- package/dist/zarr/types.d.ts.map +1 -0
- package/dist/zarr/types.js +5 -0
- package/dist/zarr/types.js.map +1 -0
- package/dist/zarr/unbundled.d.ts +2 -0
- package/dist/zarr/unbundled.d.ts.map +1 -0
- package/dist/zarr/unbundled.js +5 -0
- package/dist/zarr/unbundled.js.map +1 -0
- package/dist/zarr/zarr-array-source.d.ts +102 -0
- package/dist/zarr/zarr-array-source.d.ts.map +1 -0
- package/dist/zarr/zarr-array-source.js +132 -0
- package/dist/zarr/zarr-array-source.js.map +1 -0
- package/dist/zarr/zarr-loader-types.d.ts +236 -0
- package/dist/zarr/zarr-loader-types.d.ts.map +1 -0
- package/dist/zarr/zarr-loader-types.js +128 -0
- package/dist/zarr/zarr-loader-types.js.map +1 -0
- package/dist/zarr.dev.js +16574 -0
- package/dist/zarr.min.js +79 -0
- package/package.json +62 -4
- package/src/index.ts +52 -0
- package/src/netcdf/bundled.ts +5 -0
- package/src/netcdf/index.ts +14 -0
- package/src/netcdf/iobuffer/iobuffer.ts +510 -0
- package/src/netcdf/netcdf-format.ts +16 -0
- package/src/netcdf/netcdf-loader-with-parser.ts +54 -0
- package/src/netcdf/netcdf-loader.ts +62 -0
- package/src/netcdf/netcdf-source-loader-types.ts +45 -0
- package/src/netcdf/netcdf-source-loader.ts +526 -0
- package/src/netcdf/netcdfjs/LICENSE +24 -0
- package/src/netcdf/netcdfjs/netcdf-reader.ts +196 -0
- package/src/netcdf/netcdfjs/netcdf-types.ts +75 -0
- package/src/netcdf/netcdfjs/read-data.ts +71 -0
- package/src/netcdf/netcdfjs/read-header.ts +277 -0
- package/src/netcdf/netcdfjs/read-type.ts +147 -0
- package/src/netcdf/unbundled.ts +5 -0
- package/src/zarr/bundled.ts +5 -0
- package/src/zarr/geo-zarr-source-loader.ts +998 -0
- package/src/zarr/index.ts +60 -0
- package/src/zarr/lib/consolidated-zarr.ts +190 -0
- package/src/zarr/lib/load-zarr.ts +31 -0
- package/src/zarr/lib/spatial-multiscales.ts +47 -0
- package/src/zarr/lib/utils.ts +162 -0
- package/src/zarr/lib/zarr-data-cache.ts +91 -0
- package/src/zarr/lib/zarr-pixel-source.ts +134 -0
- package/src/zarr/lib/zarrita-pixel-source.ts +141 -0
- package/src/zarr/ome-zarr-source-loader.ts +837 -0
- package/src/zarr/spatial-data-source.ts +370 -0
- package/src/zarr/types.ts +129 -0
- package/src/zarr/unbundled.ts +5 -0
- package/src/zarr/zarr-array-source.ts +225 -0
- package/src/zarr/zarr-loader-types.ts +166 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ZarrArray} from 'zarr';
|
|
6
|
+
import type {ZarrRawArray} from '../types';
|
|
7
|
+
import type {
|
|
8
|
+
PixelSource,
|
|
9
|
+
Labels,
|
|
10
|
+
RasterSelection,
|
|
11
|
+
PixelSourceSelection,
|
|
12
|
+
PixelData,
|
|
13
|
+
TileSelection
|
|
14
|
+
} from '../types';
|
|
15
|
+
|
|
16
|
+
import {BoundsCheckError, slice} from 'zarr';
|
|
17
|
+
import {getImageSize, isInterleaved, getIndexer} from './utils';
|
|
18
|
+
|
|
19
|
+
export const DTYPE_LOOKUP = {
|
|
20
|
+
u1: 'Uint8',
|
|
21
|
+
u2: 'Uint16',
|
|
22
|
+
u4: 'Uint32',
|
|
23
|
+
f4: 'Float32',
|
|
24
|
+
f8: 'Float64',
|
|
25
|
+
i1: 'Int8',
|
|
26
|
+
i2: 'Int16',
|
|
27
|
+
i4: 'Int32'
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
type ZarrIndexer<S extends string[]> = (sel: {[K in S[number]]: number} | number[]) => number[];
|
|
31
|
+
|
|
32
|
+
interface ZarrTileSelection {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
selection: number[];
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class ZarrPixelSource<S extends string[]> implements PixelSource<S> {
|
|
40
|
+
public labels: Labels<S>;
|
|
41
|
+
public tileSize: number;
|
|
42
|
+
private _data: ZarrArray;
|
|
43
|
+
private _indexer: ZarrIndexer<S>;
|
|
44
|
+
private _readChunks: boolean;
|
|
45
|
+
|
|
46
|
+
constructor(data: ZarrArray, labels: Labels<S>, tileSize: number) {
|
|
47
|
+
this._indexer = getIndexer(labels);
|
|
48
|
+
this._data = data;
|
|
49
|
+
|
|
50
|
+
const xChunkSize = data.chunks[this._xIndex];
|
|
51
|
+
const yChunkSize = data.chunks[this._xIndex - 1];
|
|
52
|
+
this._readChunks = tileSize === xChunkSize && tileSize === yChunkSize;
|
|
53
|
+
this.labels = labels;
|
|
54
|
+
this.tileSize = tileSize;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get shape() {
|
|
58
|
+
return this._data.shape;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get dtype() {
|
|
62
|
+
const suffix = this._data.dtype.slice(1) as keyof typeof DTYPE_LOOKUP;
|
|
63
|
+
if (!(suffix in DTYPE_LOOKUP)) {
|
|
64
|
+
throw Error(`Zarr dtype not supported, got ${suffix}.`);
|
|
65
|
+
}
|
|
66
|
+
return DTYPE_LOOKUP[suffix];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private get _xIndex() {
|
|
70
|
+
const interleave = isInterleaved(this._data.shape);
|
|
71
|
+
return this._data.shape.length - (interleave ? 2 : 1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private _chunkIndex<T>(selection: PixelSourceSelection<S> | number[], x: T, y: T) {
|
|
75
|
+
const sel: (number | T)[] = this._indexer(selection);
|
|
76
|
+
sel[this._xIndex] = x;
|
|
77
|
+
sel[this._xIndex - 1] = y;
|
|
78
|
+
return sel;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Converts x, y tile indices to zarr dimension Slices within image bounds.
|
|
83
|
+
*/
|
|
84
|
+
private _getSlices(x: number, y: number) {
|
|
85
|
+
const {height, width} = getImageSize(this);
|
|
86
|
+
const [xStart, xStop] = [x * this.tileSize, Math.min((x + 1) * this.tileSize, width)];
|
|
87
|
+
const [yStart, yStop] = [y * this.tileSize, Math.min((y + 1) * this.tileSize, height)];
|
|
88
|
+
// Deck.gl can sometimes request edge tiles that don't exist. We throw
|
|
89
|
+
// a BoundsCheckError which is picked up in `ZarrPixelSource.onTileError`
|
|
90
|
+
// and ignored by deck.gl.
|
|
91
|
+
if (xStart === xStop || yStart === yStop) {
|
|
92
|
+
throw new BoundsCheckError('Tile slice is zero-sized.');
|
|
93
|
+
}
|
|
94
|
+
return [slice(xStart, xStop), slice(yStart, yStop)];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async getRaster({selection}: RasterSelection<S> | {selection: number[]}) {
|
|
98
|
+
const sel = this._chunkIndex(selection, null, null);
|
|
99
|
+
const {data, shape} = (await this._data.getRaw(sel)) as ZarrRawArray;
|
|
100
|
+
const [height, width] = shape;
|
|
101
|
+
return {data, width, height} as PixelData;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async getTile(props: TileSelection<S> | ZarrTileSelection) {
|
|
105
|
+
const {x, y, selection, signal} = props;
|
|
106
|
+
|
|
107
|
+
let res;
|
|
108
|
+
if (this._readChunks) {
|
|
109
|
+
// Can read chunks directly by key since tile size matches chunk shape
|
|
110
|
+
const sel = this._chunkIndex(selection, x, y);
|
|
111
|
+
res = await this._data.getRawChunk(sel, {storeOptions: {signal}});
|
|
112
|
+
} else {
|
|
113
|
+
// Need to use zarr fancy indexing to get desired tile size.
|
|
114
|
+
const [xSlice, ySlice] = this._getSlices(x, y);
|
|
115
|
+
const sel = this._chunkIndex(selection, xSlice, ySlice);
|
|
116
|
+
res = await this._data.getRaw(sel);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const {
|
|
120
|
+
data,
|
|
121
|
+
shape: [height, width]
|
|
122
|
+
} = res as ZarrRawArray;
|
|
123
|
+
return {data, width, height} as PixelData;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
onTileError(err: Error) {
|
|
127
|
+
if (!(err instanceof BoundsCheckError)) {
|
|
128
|
+
// Rethrow error if something other than tile being requested is out of bounds.
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export default ZarrPixelSource;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import * as zarrita from 'zarrita';
|
|
6
|
+
import type {Readable} from 'zarrita';
|
|
7
|
+
import type {
|
|
8
|
+
RasterSelection,
|
|
9
|
+
PixelData,
|
|
10
|
+
PixelSourceSelection,
|
|
11
|
+
TileSelection,
|
|
12
|
+
Labels,
|
|
13
|
+
SupportedTypedArray
|
|
14
|
+
} from '../types';
|
|
15
|
+
import {getIndexer} from './utils';
|
|
16
|
+
import {cloneZarrSelection, getCachedZarrSelection, getZarrSelectionKey} from './zarr-data-cache';
|
|
17
|
+
|
|
18
|
+
type ZarritaIndexer<S extends string[]> = (sel: {[K in S[number]]: number} | number[]) => number[];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pixel source backed by a zarrita array.
|
|
22
|
+
*/
|
|
23
|
+
export default class ZarritaPixelSource<S extends string[]> {
|
|
24
|
+
/** Dimension labels for the backing array. */
|
|
25
|
+
public readonly labels: Labels<S>;
|
|
26
|
+
/** Square power-of-two tile size used by legacy tile consumers. */
|
|
27
|
+
public readonly tileSize: number;
|
|
28
|
+
/** Native chunk width. */
|
|
29
|
+
public readonly tileWidth: number;
|
|
30
|
+
/** Native chunk height. */
|
|
31
|
+
public readonly tileHeight: number;
|
|
32
|
+
/** Backing Zarrita array. */
|
|
33
|
+
private readonly data: zarrita.Array<zarrita.DataType, Readable>;
|
|
34
|
+
/** Converts named selections to positional Zarrita selections. */
|
|
35
|
+
private readonly indexer: ZarritaIndexer<S>;
|
|
36
|
+
|
|
37
|
+
/** Creates a pixel source for one Zarr pyramid level. */
|
|
38
|
+
constructor(
|
|
39
|
+
data: zarrita.Array<zarrita.DataType, Readable>,
|
|
40
|
+
labels: Labels<S>,
|
|
41
|
+
tileSize: number
|
|
42
|
+
) {
|
|
43
|
+
this.indexer = getIndexer(labels);
|
|
44
|
+
this.data = data;
|
|
45
|
+
this.labels = labels;
|
|
46
|
+
this.tileSize = tileSize;
|
|
47
|
+
const interleaved = labels[labels.length - 1] === '_c';
|
|
48
|
+
[this.tileHeight, this.tileWidth] = data.chunks.slice(interleaved ? -3 : -2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Array dimensions. */
|
|
52
|
+
get shape() {
|
|
53
|
+
return this.data.shape;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Chunk dimensions. */
|
|
57
|
+
get chunks() {
|
|
58
|
+
return this.data.chunks;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Zarrita dtype identifier. */
|
|
62
|
+
get dtype() {
|
|
63
|
+
return this.data.dtype;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Positional index of the x dimension. */
|
|
67
|
+
private get xIndex() {
|
|
68
|
+
const interleaved = this.labels[this.labels.length - 1] === '_c';
|
|
69
|
+
return this.data.shape.length - (interleaved ? 2 : 1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Inserts x and y selectors into a named or positional selection. */
|
|
73
|
+
private chunkIndex<T>(selection: PixelSourceSelection<S> | number[], x: T, y: T) {
|
|
74
|
+
const sel: (number | T)[] = this.indexer(selection);
|
|
75
|
+
sel[this.xIndex] = x;
|
|
76
|
+
sel[this.xIndex - 1] = y;
|
|
77
|
+
return sel;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Reads a complete 2D plane from the backing array. */
|
|
81
|
+
async getRaster({
|
|
82
|
+
selection,
|
|
83
|
+
signal
|
|
84
|
+
}: RasterSelection<S> | {selection: number[]; signal?: AbortSignal}) {
|
|
85
|
+
const sel = this.chunkIndex(selection, null, null) as Array<number | null>;
|
|
86
|
+
if (this.labels[this.labels.length - 1] === '_c') {
|
|
87
|
+
sel[sel.length - 1] = null;
|
|
88
|
+
}
|
|
89
|
+
const chunk = await getCachedZarrSelection(
|
|
90
|
+
this.data,
|
|
91
|
+
getZarrSelectionKey(sel),
|
|
92
|
+
() => zarrita.get(this.data, sel) as Promise<{data: SupportedTypedArray; shape: number[]}>,
|
|
93
|
+
signal
|
|
94
|
+
);
|
|
95
|
+
if (!chunk || typeof chunk !== 'object' || !('data' in chunk) || !('shape' in chunk)) {
|
|
96
|
+
throw new Error('Failed to read Zarr raster selection.');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const shape = chunk.shape as number[];
|
|
100
|
+
const interleaved = this.labels[this.labels.length - 1] === '_c';
|
|
101
|
+
const [height, width] = shape.slice(interleaved ? -3 : -2);
|
|
102
|
+
return {data: cloneZarrSelection(chunk).data, width, height} as PixelData;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Reads one square tile from the backing array. */
|
|
106
|
+
async getTile({x, y, selection, signal}: TileSelection<S>) {
|
|
107
|
+
const interleaved = this.labels[this.labels.length - 1] === '_c';
|
|
108
|
+
const [height, width] = this.data.shape.slice(interleaved ? -3 : -2);
|
|
109
|
+
const xStart = x * this.tileSize;
|
|
110
|
+
const xStop = Math.min((x + 1) * this.tileSize, width);
|
|
111
|
+
const yStart = y * this.tileSize;
|
|
112
|
+
const yStop = Math.min((y + 1) * this.tileSize, height);
|
|
113
|
+
|
|
114
|
+
if (xStart === xStop || yStart === yStop) {
|
|
115
|
+
throw new Error('Tile slice is zero-sized.');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const sel = this.chunkIndex(
|
|
119
|
+
selection,
|
|
120
|
+
zarrita.slice(xStart, xStop),
|
|
121
|
+
zarrita.slice(yStart, yStop)
|
|
122
|
+
) as Array<number | zarrita.Slice>;
|
|
123
|
+
const chunk = await getCachedZarrSelection(
|
|
124
|
+
this.data,
|
|
125
|
+
getZarrSelectionKey(sel),
|
|
126
|
+
() => zarrita.get(this.data, sel) as Promise<{data: SupportedTypedArray; shape: number[]}>,
|
|
127
|
+
signal
|
|
128
|
+
);
|
|
129
|
+
if (!chunk || typeof chunk !== 'object' || !('data' in chunk) || !('shape' in chunk)) {
|
|
130
|
+
throw new Error('Failed to read Zarr tile selection.');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const shape = chunk.shape as number[];
|
|
134
|
+
const [tileHeight, tileWidth] = shape.slice(interleaved ? -3 : -2);
|
|
135
|
+
return {
|
|
136
|
+
data: cloneZarrSelection(chunk).data,
|
|
137
|
+
width: tileWidth,
|
|
138
|
+
height: tileHeight
|
|
139
|
+
} as PixelData;
|
|
140
|
+
}
|
|
141
|
+
}
|