Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Aug 25, 2023
1 parent 8f08940 commit 88fab52
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 44 deletions.
22 changes: 13 additions & 9 deletions src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ async function loadMultiChannel(
}

function isOmePlate(attrs: zarr.Attributes): attrs is { plate: Ome.Plate } {
return "plate" in attrs;
return 'plate' in attrs;
}

function isOmeWell(attrs: zarr.Attributes): attrs is { well: Ome.Well } {
return "well" in attrs;
return 'well' in attrs;
}

function isOmeroMultiscales(attrs: zarr.Attributes): attrs is { omero: Ome.Omero; multiscales: Ome.Multiscale[] } {
return "omero" in attrs && "multiscales" in attrs;
return 'omero' in attrs && 'multiscales' in attrs;
}

function isMultiscales(attrs: zarr.Attributes): attrs is { multiscales: Ome.Multiscale[] } {
return "multiscales" in attrs;
return 'multiscales' in attrs;
}

export async function createSourceData(config: ImageLayerConfig): Promise<SourceData> {
Expand All @@ -118,10 +118,14 @@ export async function createSourceData(config: ImageLayerConfig): Promise<Source
}

if (isOmeroMultiscales(attrs)) {
return loadOmeroMultiscales(config, node, attrs as {
omero: Ome.Omero;
multiscales: Ome.Multiscale[];
});
return loadOmeroMultiscales(
config,
node,
attrs as {
omero: Ome.Omero;
multiscales: Ome.Multiscale[];
}
);
}

if (Object.keys(attrs).length === 0 && node.path) {
Expand Down Expand Up @@ -170,7 +174,7 @@ type Labels = [...string[], 'y', 'x'];
function getAxisLabelsAndChannelAxis(
config: ImageLayerConfig,
ngffAxes: Ome.Axis[] | undefined,
arr: zarr.Array<zarr.DataType, Readable>
arr: zarr.Array<zarr.DataType, Readable>
): { labels: Labels; channel_axis: number } {
// type cast string[] to Labels
const maybeAxisLabels = config.axis_labels as undefined | Labels;
Expand Down
6 changes: 3 additions & 3 deletions src/lru-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AsyncReadable } from '@zarrita/storage';
import type { Readable } from '@zarrita/storage';
import QuickLRU from 'quick-lru';

export class LRUCacheStore<S extends AsyncReadable> {
export class LRUCacheStore<S extends Readable> {
cache: QuickLRU<string, Promise<Uint8Array | undefined>>;
constructor(public store: S, maxSize: number = 100) {
this.cache = new QuickLRU({ maxSize });
Expand All @@ -11,7 +11,7 @@ export class LRUCacheStore<S extends AsyncReadable> {
if (this.cache.has(key)) {
return this.cache.get(key)!;
}
const value = this.store.get(key, opts).catch((err) => {
const value = Promise.resolve(this.store.get(key, opts)).catch((err) => {
this.cache.delete(key);
throw err;
});
Expand Down
4 changes: 2 additions & 2 deletions src/ome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ export async function loadPlate(

// Create loader for every Well. Some loaders may be undefined if Wells are missing.
const mapper = async ([key, path]: string[]) => {
let arr = await zarr.open(grp.resolve(path), { kind: "array" });
let arr = await zarr.open(grp.resolve(path), { kind: 'array' });
return [key, arr] as const;
}
};

const promises = await pMap(
wellImagePaths.map((p) => [p, join(p, resolution)]),
Expand Down
2 changes: 1 addition & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PrimitiveAtom, WritableAtom } from 'jotai';
import { atom } from 'jotai';
import { atomFamily, splitAtom, waitForAll } from 'jotai/utils';

import type { Readable } from "@zarrita/storage";
import type { Readable } from '@zarrita/storage';
import type { default as GridLayer, GridLayerProps, GridLoader } from './gridLayer';
import { initLayerStateFromSource } from './io';

Expand Down
58 changes: 29 additions & 29 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LRUCacheStore } from './lru-store';
import type { ViewState } from './state';

import * as zarr from '@zarrita/core';
import { slice, get, type Slice } from "@zarrita/indexing";
import { slice, get, type Slice } from '@zarrita/indexing';
import { FetchStore, Readable } from '@zarrita/storage';

export const MAX_CHANNELS = 6;
Expand Down Expand Up @@ -285,50 +285,50 @@ export async function calcConstrastLimits<S extends string[]>(

function getV2DataType(dtype: string) {
const mapping: Record<string, string> = {
"int8": "|i1",
"uint8": "|u1",
"int16": "<i2",
"uint16": "<u2",
"int32": "<i4",
"uint32": "<u4",
"int64": "<i8",
"uint64": "<u8",
"float32": "<f4",
"float64": "<f8",
int8: '|i1',
uint8: '|u1',
int16: '<i2',
uint16: '<u2',
int32: '<i4',
uint32: '<u4',
int64: '<i8',
uint64: '<u8',
float32: '<f4',
float64: '<f8',
};
if (!(dtype in mapping)) {
throw new Error(`Unsupported dtype ${dtype}`);
}
return mapping[dtype];
}

type Selection = (number | Omit<Slice, "indices"> | null)[];
type Selection = (number | Omit<Slice, 'indices'> | null)[];

export function createZarrArrayAdapter(arr: zarr.Array<zarr.DataType>): any {
return new Proxy(arr, {
get(target, prop) {
if (prop === "getRaw") {
if (prop === 'getRaw') {
return (selection: Selection) => {
return get(target, selection.map(s => {
if (typeof s === "object" && s !== null) {
return slice(s.start, s.stop, s.step);
}
return s;
}));
}
return get(
target,
selection.map((s) => {
if (typeof s === 'object' && s !== null) {
return slice(s.start, s.stop, s.step);
}
return s;
})
);
};
}
if (prop === "getRawChunk") {
return (
selection: number[],
options: { storeOptions: RequestInit }
) => {
if (prop === 'getRawChunk') {
return (selection: number[], options: { storeOptions: RequestInit }) => {
return target.getChunk(selection, options.storeOptions);
}
};
}
if (prop === "dtype") {
if (prop === 'dtype') {
return getV2DataType(target.dtype);
}
return Reflect.get(target, prop);
}
})
},
});
}

0 comments on commit 88fab52

Please sign in to comment.