Skip to content

Commit

Permalink
Move 'axes' logic to ome.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Aug 5, 2021
1 parent 3617cb8 commit 8ed9c89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ export async function createSourceData(config: ImageLayerConfig): Promise<Source

if (node instanceof ZarrGroup) {
const attrs = (await node.attrs.asObject()) as Ome.Attrs;
if ('multiscales' in attrs && attrs.multiscales?.[0]?.axes) {
config.axis_labels = attrs.multiscales?.[0]?.axes;
}

if ('plate' in attrs) {
return loadPlate(config, node, attrs.plate);
Expand Down
16 changes: 10 additions & 6 deletions src/ome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function loadWell(config: ImageLayerConfig, grp: ZarrGroup, wellAtt
// Create loader for every Image.
const promises = imgPaths.map((p) => grp.getItem(join(p, resolution)));
const data = (await Promise.all(promises)) as ZarrArray[];
const axis_labels = getOmeAxisLabels(config.axis_labels);
const axis_labels = getOmeAxisLabels(imgAttrs);
const meta = parseOmeroMeta(imgAttrs.omero, axis_labels);

const tileSize = guessTileSize(data[0]);
Expand Down Expand Up @@ -141,7 +141,7 @@ export async function loadPlate(config: ImageLayerConfig, grp: ZarrGroup, plateA
{ concurrency: 10 }
);
const data = await Promise.all(promises);
const axis_labels = getOmeAxisLabels(imgAttrs.multiscales[0].axes || config.axis_labels);
const axis_labels = getOmeAxisLabels(imgAttrs);
const meta = parseOmeroMeta(imgAttrs.omero, axis_labels);
const tileSize = guessTileSize(data[0][1]);
const loaders = data.map((d) => {
Expand Down Expand Up @@ -200,7 +200,7 @@ export async function loadOmeroMultiscales(
): Promise<SourceData> {
const { name, opacity = 1, colormap = '' } = config;
const data = await loadMultiscales(grp, attrs.multiscales);
const axis_labels = getOmeAxisLabels(config.axis_labels);
const axis_labels = getOmeAxisLabels(attrs);
const meta = parseOmeroMeta(attrs.omero, axis_labels);
const tileSize = guessTileSize(data[0]);

Expand Down Expand Up @@ -247,12 +247,16 @@ function parseOmeroMeta({ rdefs, channels, name }: Ome.Omero, axis_labels: strin
colors,
contrast_limits,
visibilities,
channel_axis: axis_labels.includes('c') ? axis_labels.indexOf('c') : undefined,
channel_axis: axis_labels.includes('c') ? axis_labels.indexOf('c') : null,
defaultSelection,
};
}

function getOmeAxisLabels(axes?: string[]): [...string[], 'y', 'x'] {
function getOmeAxisLabels(attrs: Ome.Attrs): [...string[], 'y', 'x'] {
let axis_labels;
if ('multiscales' in attrs && attrs.multiscales?.[0]?.axes) {
axis_labels = attrs.multiscales[0].axes;
}
const default_axes = ['t', 'c', 'z', 'y', 'x']; // v0.1 & v0.2
return (axes || default_axes) as [...string[], 'y', 'x'];
return (axis_labels || default_axes) as [...string[], 'y', 'x'];
}

0 comments on commit 8ed9c89

Please sign in to comment.