@@ -2,7 +2,14 @@ import { ZarrPixelSource } from '@hms-dbmi/viv';
2
2
import pMap from 'p-map' ;
3
3
import { Group as ZarrGroup , openGroup , ZarrArray } from 'zarr' ;
4
4
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' ;
6
13
7
14
export async function loadWell ( config : ImageLayerConfig , grp : ZarrGroup , wellAttrs : Ome . Well ) : Promise < SourceData > {
8
15
// Can filter Well fields by URL query ?acquisition=ID
@@ -119,7 +126,7 @@ export async function loadPlate(config: ImageLayerConfig, grp: ZarrGroup, plateA
119
126
const wellPaths = plateAttrs . wells . map ( ( well ) => well . path ) ;
120
127
121
128
// 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 ] ) ;
123
130
if ( ! ( 'well' in wellAttrs ) ) {
124
131
throw Error ( 'Path for image is not valid, not a well.' ) ;
125
132
}
@@ -133,10 +140,16 @@ export async function loadPlate(config: ImageLayerConfig, grp: ZarrGroup, plateA
133
140
const { datasets } = imgAttrs . multiscales [ 0 ] ;
134
141
const resolution = datasets [ datasets . length - 1 ] . path ;
135
142
143
+ async function getImgPath ( wellPath :string ) {
144
+ const wellAttrs = await getAttrsOnly < { well : Ome . Well } > ( grp , wellPath ) ;
145
+ return join ( wellPath , wellAttrs . well . images [ 0 ] . path ) ;
146
+ }
147
+ const wellImagePaths = await Promise . all ( wellPaths . map ( getImgPath ) ) ;
148
+
136
149
// Create loader for every Well. Some loaders may be undefined if Wells are missing.
137
150
const mapper = ( [ key , path ] : string [ ] ) => grp . getItem ( path ) . then ( ( arr ) => [ key , arr ] ) as Promise < [ string , ZarrArray ] > ;
138
151
const promises = await pMap (
139
- wellPaths . map ( ( p ) => [ p , join ( p , imgPath , resolution ) ] ) ,
152
+ wellImagePaths . map ( ( p ) => [ p , join ( p , resolution ) ] ) ,
140
153
mapper ,
141
154
{ concurrency : 10 }
142
155
) ;
0 commit comments