-
Notifications
You must be signed in to change notification settings - Fork 5
Warn about Zarr layouts that make viewing awkward #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
krokicki
wants to merge
2
commits into
main
Choose a base branch
from
dataset-warnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
frontend/src/__tests__/unitTests/datasetWarnings.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { getDatasetWarnings } from '@/omezarr-helper'; | ||
| import type { Metadata } from '@/omezarr-helper'; | ||
|
|
||
| // Minimal stand-in for the parts of Metadata the checks read. Codec info is | ||
| // left out by default, which the chunk check treats as compressed. | ||
| const createMetadata = ( | ||
| chunks: number[], | ||
| dtype = 'uint16', | ||
| extra: Partial<Metadata> = {}, | ||
| shape: number[] = [8, 8, 8] | ||
| ): Metadata => | ||
| ({ | ||
| arr: { chunks, dtype, shape }, | ||
| ...extra | ||
| }) as unknown as Metadata; | ||
|
|
||
| const levels = (count: number): Partial<Metadata> => ({ | ||
| multiscales: [ | ||
| { datasets: Array.from({ length: count }, () => ({})) } | ||
| ] as unknown as Metadata['multiscales'] | ||
| }); | ||
|
|
||
| // zstd nested inside a sharding_indexed pipeline, as a sharded v3 array stores it. | ||
| const SHARDED_ZSTD: Partial<Metadata> = { | ||
| codecs: [ | ||
| { | ||
| name: 'sharding_indexed', | ||
| configuration: { codecs: [{ name: 'bytes' }, { name: 'zstd' }] } | ||
| } | ||
| ] | ||
| }; | ||
| const UNCOMPRESSED_V3: Partial<Metadata> = { | ||
| codecs: [{ name: 'bytes' }, { name: 'crc32c' }] | ||
| }; | ||
|
|
||
| describe('getDatasetWarnings: chunk size', () => { | ||
| it('says nothing about reasonable chunks', () => { | ||
| expect(getDatasetWarnings(createMetadata([64, 64, 64]))).toEqual([]); | ||
| }); | ||
|
|
||
| it('does not warn about a compressed 48 MB chunk', () => { | ||
| // 48 MB inner chunks that zstd takes to well under the 32 MB guidance. | ||
| expect( | ||
| getDatasetWarnings( | ||
| createMetadata([24, 128, 128, 128], 'uint8', SHARDED_ZSTD) | ||
| ) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('holds an uncompressed array to the stricter limit', () => { | ||
| // The same 48 MB chunks, but stored raw, so 48 MB is what transfers. | ||
| for (const raw of [UNCOMPRESSED_V3, { compressor: null }]) { | ||
| expect( | ||
| getDatasetWarnings(createMetadata([24, 128, 128, 128], 'uint8', raw)) | ||
| ).toEqual([ | ||
| { | ||
| case: 'zarr-large-chunks', | ||
| size: '48 MB', | ||
| compressed: false, | ||
| sharded: false | ||
| } | ||
| ]); | ||
| } | ||
| }); | ||
|
|
||
| it('finds a compressor nested inside a sharding codec', () => { | ||
| // sharding_indexed is structural, so a flat scan would call this | ||
| // uncompressed and warn at 48 MB. | ||
| expect( | ||
| getDatasetWarnings( | ||
| createMetadata([24, 128, 128, 128], 'uint8', SHARDED_ZSTD) | ||
| ) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('assumes compressed when codec metadata was never fetched', () => { | ||
| // Unknown lands on the permissive limit: a missed warning beats a false one. | ||
| expect( | ||
| getDatasetWarnings(createMetadata([24, 128, 128, 128], 'uint8')) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('warns above the compressed limit', () => { | ||
| // seed151 img: 128 MB chunks. | ||
| expect( | ||
| getDatasetWarnings(createMetadata([256, 256, 256, 8], 'uint8')) | ||
| ).toEqual([ | ||
| { | ||
| case: 'zarr-large-chunks', | ||
| size: '128 MB', | ||
| compressed: true, | ||
| sharded: false | ||
| } | ||
| ]); | ||
| }); | ||
|
|
||
| it('calls out that a sharded array is measured by its inner chunks', () => { | ||
| // zarrita resolves the sharding codec, so arr.chunks is the inner chunk | ||
| // shape - the shard around it is never what we size. | ||
| expect( | ||
| getDatasetWarnings( | ||
| createMetadata([256, 256, 256, 8], 'uint8', SHARDED_ZSTD) | ||
| ) | ||
| ).toEqual([ | ||
| { | ||
| case: 'zarr-large-chunks', | ||
| size: '128 MB', | ||
| compressed: true, | ||
| sharded: true | ||
| } | ||
| ]); | ||
| }); | ||
|
|
||
| it('accounts for the dtype width', () => { | ||
| expect(getDatasetWarnings(createMetadata([256, 256, 256]))).toEqual([]); | ||
| expect( | ||
| getDatasetWarnings(createMetadata([256, 256, 256], 'float64')) | ||
| ).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getDatasetWarnings: resolution levels', () => { | ||
| const BIG = [3000, 3000, 1350, 8]; // 91 GB of uint8, the seed151 img extent | ||
|
|
||
| it('warns when multiscales declares a single level for a large image', () => { | ||
| expect( | ||
| getDatasetWarnings(createMetadata([64, 64, 64], 'uint8', levels(1), BIG)) | ||
| ).toEqual([{ case: 'zarr-single-level', size: '91 GB' }]); | ||
| }); | ||
|
|
||
| it('says nothing when the pyramid has levels', () => { | ||
| expect( | ||
| getDatasetWarnings(createMetadata([64, 64, 64], 'uint8', levels(5), BIG)) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('says nothing about a small single-level image', () => { | ||
| expect( | ||
| getDatasetWarnings( | ||
| createMetadata([64, 64, 64], 'uint8', levels(1), [256, 256, 256]) | ||
| ) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('never fires on a plain array, however large', () => { | ||
| // The bug that made this warn on raw/s2: a plain array also has one shape, | ||
| // but it declares no multiscales and so claims nothing. | ||
| expect( | ||
| getDatasetWarnings(createMetadata([64, 64, 64], 'uint8', {}, BIG)) | ||
| ).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Viewing the dataset when zoomed in to a small field of view is unaffected by the lack of a pyramid.
I usually create such datasets when initially copying data from an instrument computer to shared storage. The copying and pyramid generation as distinct steps.