Skip to content

Commit

Permalink
feat: Handle no channel axis (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore authored Oct 10, 2023
1 parent 6b6c696 commit 0c16bb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export async function loadOmeroMultiscales(

async function defaultMeta(loader: ZarrPixelSource<string[]>, 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);
Expand Down
7 changes: 5 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,21 @@ export async function calcConstrastLimits<S extends string[]>(
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");
}

return Promise.all(
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);
})
);
Expand Down

0 comments on commit 0c16bb4

Please sign in to comment.