Skip to content

Commit

Permalink
fix(loaders): Allow optional TiffData in OME-XML (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored Nov 14, 2023
1 parent b56f4ad commit 2198e50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Changed
- Fix Avivator demo for OME-Zarr with only spatial axes
- Allow OME-XML to omit `TiffData` tags

## 0.14.1

Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/src/omexml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const TiffDataSchema = z
const PixelsSchema = z
.object({
Channel: z.preprocess(ensureArray, ChannelSchema.array()),
TiffData: z.preprocess(ensureArray, TiffDataSchema.array())
TiffData: z.preprocess(ensureArray, TiffDataSchema.array()).optional()
})
.extend({
attr: z.object({
Expand Down
16 changes: 15 additions & 1 deletion sites/avivator/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ async function getTotalImageCount(src, rootMeta, data) {
return numImagesPerResolution * levels;
}

/**
* @param {unknown} e
* @returns {e is Error & { issues: unknown }}
*/
function isZodError(e) {
return e instanceof Error && 'issues' in e;
}

/**
* Given an image source, creates a PixelSource[] and returns XML-meta
*
Expand Down Expand Up @@ -211,7 +219,13 @@ export async function createLoader(
let source;
try {
source = await loadBioformatsZarr(urlOrFile);
} catch {
} catch (e) {
if (isZodError(e)) {
// If the error is a ZodError, it means there was an OME-XML file
// but it was invalid. We shouldn't try to load the file as a OME-Zarr.
throw e;
}

// try ome-zarr
const res = await loadOmeZarr(urlOrFile, { type: 'multiscales' });
// extract metadata into OME-XML-like form
Expand Down

0 comments on commit 2198e50

Please sign in to comment.