Skip to content

Commit 7cc8ba0

Browse files
committed
Use new utils.getAttrsOnly() for loading plate Wells
1 parent 246a49e commit 7cc8ba0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/ome.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { ZarrPixelSource } from '@hms-dbmi/viv';
22
import pMap from 'p-map';
33
import { Group as ZarrGroup, HTTPStore, openGroup, ZarrArray } from 'zarr';
44
import type { ImageLayerConfig, SourceData } from './state';
5-
import { join, loadMultiscales, guessTileSize, range, parseMatrix } from './utils';
5+
import {
6+
getAttrsOnly,
7+
guessTileSize,
8+
join,
9+
loadMultiscales,
10+
parseMatrix,
11+
range
12+
} from './utils';
613

714
export async function loadWell(config: ImageLayerConfig, grp: ZarrGroup, wellAttrs: Ome.Well): Promise<SourceData> {
815
// Can filter Well fields by URL query ?acquisition=ID
@@ -119,7 +126,7 @@ export async function loadPlate(config: ImageLayerConfig, grp: ZarrGroup, plateA
119126
const wellPaths = plateAttrs.wells.map((well) => well.path);
120127

121128
// Use first image as proxy for others.
122-
const wellAttrs = (await grp.getItem(wellPaths[0]).then((g) => g.attrs.asObject())) as Ome.Attrs;
129+
const wellAttrs = await getAttrsOnly<{ well: Ome.Well }>(grp, wellPaths[0]);
123130
if (!('well' in wellAttrs)) {
124131
throw Error('Path for image is not valid, not a well.');
125132
}
@@ -134,8 +141,7 @@ export async function loadPlate(config: ImageLayerConfig, grp: ZarrGroup, plateA
134141
const resolution = datasets[datasets.length - 1].path;
135142

136143
async function getImgPath(wellPath:string) {
137-
// This loads .zattrs for each well but also tries to load .zarray (404) and .zgroup
138-
const wellAttrs = await grp.getItem(wellPath).then((g) => g.attrs.asObject());
144+
const wellAttrs = await getAttrsOnly<{ well: Ome.Well }>(grp, wellPath);
139145
return join(wellPath, wellAttrs.well.images[0].path);
140146
}
141147
const wellImagePaths = await Promise.all(wellPaths.map(getImgPath));

src/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ export async function open(source: string | Store) {
5454
});
5555
}
5656

57+
const decoder = new TextDecoder();
58+
export function getAttrsOnly<T = unknown>(grp: ZarrGroup, path: string) {
59+
return (grp.store as AsyncStore<ArrayBuffer>)
60+
.getItem(join(grp.path, path, ".zattrs"))
61+
.then((b) => decoder.decode(b))
62+
.then((text) => JSON.parse(text) as T);
63+
}
64+
5765
export async function loadMultiscales(grp: ZarrGroup, multiscales: Ome.Multiscale[]) {
5866
const { datasets } = multiscales[0] || [{ path: '0' }];
5967
const nodes = await Promise.all(datasets.map(({ path }) => grp.getItem(path)));

0 commit comments

Comments
 (0)