Skip to content

Commit

Permalink
feat(ngff zarr): prefer _ARRAY_DIMENSIONS over axes. Chrome --no-sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed May 13, 2022
1 parent d3a6ad6 commit 152d4fe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
8 changes: 7 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ module.exports = function init(config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['Chrome_without_sandbox'],
singleRun: true,
customLaunchers: {
Chrome_without_sandbox: {
base: 'Chrome',
flags: ['--no-sandbox'],
},
},
})
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"lint:types": "tsc --noEmit",
"start": "webpack serve --mode development --static ./dist/ --open --port 8082",
"semantic-release": "semantic-release",
"test": "npm run test:downloadData && npm run lint:types && npm run build:test-ui && karma start ./karma.conf.js --browsers Chrome,Firefox",
"test": "npm run test:downloadData && npm run lint:types && npm run build:test-ui && karma start ./karma.conf.js --browsers Chrome_without_sandbox,Firefox",
"test:downloadData": "node test/downloadData.mjs",
"test:headless": "./test/run.sh",
"test:headless-debug": "./test/run.sh -d",
Expand All @@ -154,4 +154,4 @@
"lint-staged": {
"*.js": "prettier --write"
}
}
}
34 changes: 20 additions & 14 deletions src/IO/ZarrMultiscaleSpatialImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ export const computeTransform = (imageMetadata, datasetMetadata, dimCount) => {
}

// lazy creation of voxel/pixel/dimenstion coordinates array
const makeCoords = (dims, shape, imageScale, datasetScale) => {
const coords = new Map(dims.map(dim => [dim, null]))
const makeCoords = ({ shape, multiscaleImage, dataset }) => {
const axes = multiscaleImage.axes?.map(({ name }) => name) ?? TCZYX
const coords = new Map(axes.map(dim => [dim, null]))

const {
scale: spacingDataset,
translation: originDataset,
} = computeTransform(imageScale, datasetScale, dims.length)
} = computeTransform(multiscaleImage, dataset, axes.length)

return {
get(dim) {
if (coords.get(dim) === null) {
// make array
const dimIdx = dims.indexOf(dim)
const dimIdx = axes.indexOf(dim)
const spacing = spacingDataset[dimIdx]
const origin = originDataset[dimIdx]
const coordsPerElement = new Float32Array(shape[dimIdx])
Expand All @@ -94,19 +95,21 @@ const makeCoords = (dims, shape, imageScale, datasetScale) => {
return coords.get(dim)
},
has(dim) {
return dims.includes(dim)
return axes.includes(dim)
},
}
}

const computeScaleSpacing = ({
zattrs,
const createScaledImageInfo = ({
multiscaleImage,
pixelArrayMetadata,
pixelArrayAttrs,
dataset,
}) => {
// "axis" metadata not defined in ngff V0.1 so fallback to TCZYX
const dims = multiscaleImage.axes?.map(({ name }) => name) ?? TCZYX
const dims =
pixelArrayAttrs?._ARRAY_DIMENSIONS ?? // xarray
multiscaleImage.axes?.map(({ name }) => name) ?? // NGFF
TCZYX // NGFF v0.1

const { shape, chunks } = pixelArrayMetadata

Expand All @@ -127,9 +130,9 @@ const computeScaleSpacing = ({
pixelArrayMetadata,
name: multiscaleImage.name,
pixelArrayPath: dataset.path,
coords: makeCoords(dims, shape, multiscaleImage, dataset),
ranges: zattrs.ranges ?? undefined,
direction: zattrs.direction ?? undefined,
coords: makeCoords({ shape, multiscaleImage, dataset }),
ranges: pixelArrayAttrs?.ranges,
direction: pixelArrayAttrs?.direction,
chunkCount: toDimensionMap(
dims,
dims.map(dim => Math.ceil(arrayShape.get(dim) / chunkSize.get(dim)))
Expand All @@ -152,10 +155,13 @@ const extractScaleSpacing = async dataSource => {
const pixelArrayMetadata = await dataSource.getItem(
`${dataset.path}/.zarray`
)
return computeScaleSpacing({
zattrs,
const pixelArrayAttrs = await dataSource
.getItem(`${dataset.path}/.zattrs`)
.catch(() => Promise.resolve(undefined))
return createScaledImageInfo({
multiscaleImage,
pixelArrayMetadata,
pixelArrayAttrs,
dataset,
})
})
Expand Down
6 changes: 4 additions & 2 deletions test/zarrTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ test('Test ZarrStoreParser', async t => {
}

const topZattrs = await zarrStoreParser.getItem('.zattrs')
console.log(topZattrs)
t.deepEqual(topZattrs, topZattrsBaseline, 'getItem top .zattrs')

const arrayBaseline = {
Expand Down Expand Up @@ -147,6 +146,7 @@ test('Test ZarrMultiscaleSpatialImage metadata fetching', async t => {
t.end()
})

const CONCURRENT_TEST_COUNT = 3
test('Test ZarrMultiscaleSpatialImage chunk assembly', async t => {
const imageTests = imageBaselines.map(async ({ path, baseline }) => {
const storeURL = new URL(path, document.location.origin)
Expand All @@ -162,7 +162,9 @@ test('Test ZarrMultiscaleSpatialImage chunk assembly', async t => {
)
})

await Promise.all(imageTests)
for (let i = 0; i < imageTests.length; i += CONCURRENT_TEST_COUNT) {
await Promise.all(imageTests.slice(i, i + CONCURRENT_TEST_COUNT))
}

t.end()
})
Expand Down

0 comments on commit 152d4fe

Please sign in to comment.