From 0c16bb4f23f6cb5e550257520a8bcd55aaeaf147 Mon Sep 17 00:00:00 2001 From: Will Moore Date: Tue, 10 Oct 2023 19:36:45 +0100 Subject: [PATCH] feat: Handle no channel axis (#173) --- src/ome.ts | 2 +- src/utils.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ome.ts b/src/ome.ts index 941e678..afa5b07 100644 --- a/src/ome.ts +++ b/src/ome.ts @@ -255,7 +255,7 @@ export async function loadOmeroMultiscales( async function defaultMeta(loader: ZarrPixelSource, axis_labels: string[]) { const channel_axis = axis_labels.indexOf('c'); - const channel_count = loader.shape[channel_axis]; + const channel_count = channel_axis == -1 ? 1 : loader.shape[channel_axis]; const visibilities = getDefaultVisibilities(channel_count); const contrast_limits = await calcConstrastLimits(loader, channel_axis, visibilities); const colors = getDefaultColors(channel_count, visibilities); diff --git a/src/utils.ts b/src/utils.ts index 5fe8025..c755525 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -259,10 +259,11 @@ export async function calcConstrastLimits( visibilities: boolean[], defaultSelection?: number[] ): Promise<([min: number, max: number] | undefined)[]> { + // channelAxis can be -1 if there is no 'c' dimension const def = defaultSelection ?? source.shape.map(() => 0); const csize = source.shape[channelAxis]; - if (csize !== visibilities.length) { + if (csize !== visibilities.length && channelAxis > -1) { throw new Error("provided visibilities don't match number of channels"); } @@ -270,7 +271,9 @@ export async function calcConstrastLimits( visibilities.map(async (isVisible, i) => { if (!isVisible) return undefined; // don't compute non-visible channels const selection = [...def]; - selection[channelAxis] = i; + if (channelAxis > -1) { + selection[channelAxis] = i; + } return calcDataRange(source, selection); }) );