Skip to content

Commit

Permalink
Only check if OME-Zarr if dimension mismatch in Bioformats loader (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored Sep 4, 2020
1 parent 3df9c36 commit 603e5e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Changed

- Removed greedy matching of dimension order in Bio-Formats Zarr output. Just check if OME-Zarr.

## 0.4.2

### Added
Expand Down
30 changes: 18 additions & 12 deletions src/loaders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,32 @@ export async function createBioformatsZarrLoader({ url }) {
* Specifying different dimension orders form the METADATA.ome.xml is
* possible and necessary for creating an OME-Zarr precursor.
*
* e.g. `bioformats2raw --file_type=zarr --dimension-order='XYZCY'`
* e.g. `bioformats2raw --file_type=zarr --dimension-order='XYZCT'`
*
* Here we check the shape of base of the pyrmaid and compare the shape
* to the shape of the dimensions. If they are different, we reorder the
* dimensions to create the zarr loader. This is fragile code, and will only
* be executed if someone tries to specify different dimension orders.
* This is fragile code, and will only be executed if someone
* tries to specify different dimension orders.
*/
const nonXYShape = shape.slice(0, -2); // XY always last dims and don't need to be compared
const nonXYDims = dimensions.filter(d => d.values); // XY are null
const allSameSize = nonXYShape.every(
(s, i) => s === nonXYDims[i].values.length
);
if (!allSameSize) {
const sortedDims = [];
// Greedily match first matching dimension
nonXYShape.forEach(len => {
const firstMatchedDim = nonXYDims.filter(d => d.values.length === len)[0];
sortedDims.push(firstMatchedDim);
});
const newDimensions = [...sortedDims, ...dimensions.slice(-2)]; // append YX dims
// Assume OME-Zarr, dims === XYZCT
const omeZarrDims = [
nonXYDims.filter(d => d.field === 'time')[0],
nonXYDims.filter(d => d.field === 'channel')[0],
nonXYDims.filter(d => d.field === 'z')[0]
];
// compare sizes of sorted dims
if (
!omeZarrDims.every(({ values }, i) => values.length === nonXYShape[i])
) {
throw Error(
`Dimension order is different from METADATA.ome.xml and isn't OME-Zarr.`
);
}
const newDimensions = [...omeZarrDims, ...dimensions.slice(-2)]; // append YX dims
return new ZarrLoader({ data, dimensions: newDimensions });
}

Expand Down

0 comments on commit 603e5e0

Please sign in to comment.