Skip to content

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Mar 18, 2025

A new format for N5 multiscales metadata has cropped up, it is described in this neuroglancer doc. It has a totally different structure from the multiscales description used for example in this openorganelle dataset.

Example new attributes.json content:

{
   "axes":["x","y","z"],
   "downsamplingFactors":[[1,1,1],[2,2,2],[4,4,4],[8,8,8],[16,16,16]],
   "multiScale":true,
   "resolution":[19.85,19.85,19.85],
   "units":["um","um","um"]
}

This PR adds support for exploring such datasets.

Some caveats: the downsamplingFactors/scales must be described in the toplevel; resolution/units must also be described in the toplevel, otherwise we fall back to 1,1,1nm. Let’s add support for the other cases once we see them.

Steps to test:

  • In the “Add Remote Dataset” tab, explore and add this dataset: n5://gs://ucl-hip-ct-35a68e99feaae8932b1d44da0358940b/LADAF-2021-17/heart/19.85um_complete-organ_bm18/ – should show mags from 1-1-1 to 16-16-16 and load data; show the correct voxel size

Issues:


@fm3 fm3 self-assigned this Mar 18, 2025
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

📝 Walkthrough

Walkthrough

This pull request adds support for N5 datasets using compact-style multiscale metadata. It introduces a new metadata case class with JSON formatting and extends exploration functionality across local, remote, and Neuroglancer interfaces by adding new explorer classes and methods. The changes include utility method additions and inheritance refactoring to centralize N5 data exploration without impacting existing features.

Changes

File(s) Change Summary
CHANGELOG.unreleased.md Documented new feature supporting N5 datasets with compact-style multiscale metadata.
util/.../Vec3Int.scala Added isAllPowersOfTwo method to check if all vector components are powers of two.
webknossos-datastore/.../N5Metadata.scala Introduced N5CompactMultiscalesMetadata case class with an implicit JSON formatter.
webknossos-datastore/.../explore/* Extended N5 exploration support: added exploreLocalN5CompactMultiscales method, new explorer class N5CompactMultiscalesExplorer (with helper methods), updated N5ArrayExplorer to extend N5Explorer, introduced the N5Explorer trait, refactored N5MultiscalesExplorer, and updated NeuroglancerUriExplorer to include the new explorer.

Assessment against linked issues

Objective Addressed Explanation
Recognize multi-scale N5 datasets and extract correct voxel sizes (#8433)

Possibly related PRs

  • Exploring remote datasets: drop neuroglancer prefixes from URIs #8195: The changes in the main PR, which introduce support for N5 datasets with compact-style multiscale metadata, are related to the retrieved PR that enhances the handling of Neuroglancer URLs by removing prefixes, as both involve modifications to the handling of N5 data formats and metadata processing.

Suggested labels

frontend

Suggested reviewers

  • MichaelBuessemeyer

Poem

I'm a little rabbit, hopping through the code,
Where N5 magic makes the pathways glow.
Compact metadata in every line,
Multiscale wonders now clearly shine.
With each new change, I dance with delight,
Debugging and leaping into the night!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b549cc0 and fa46ad5.

📒 Files selected for processing (1)
  • CHANGELOG.unreleased.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.unreleased.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: circleci_build

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/ExploreRemoteLayerService.scala (1)

94-110: Consider adding a comment about explorer ordering

The ordering of explorers is important as it determines priority. While there's a basic comment on line 98, consider adding a more detailed comment explaining why N5CompactMultiscalesExplorer is positioned where it is in the hierarchy.

 // Explorers are ordered to prioritize the explorer reading meta information over raw Zarr, N5, ... data.
+// N5 explorers are ordered from more specific (N5MultiscalesExplorer, N5CompactMultiscalesExplorer) to more general (N5ArrayExplorer)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/ExploreLocalLayerService.scala (1)

91-97: Add expanded diagnostics for incomplete metadata.
The new exploreLocalN5CompactMultiscales method parallels existing local explorers, boosting consistency. Consider more detailed logging to help diagnose partial or malformed compact-style metadata.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5MultiscalesExplorer.scala (2)

34-34: Refactor to use layerFromMagsWithAttributes.
Delegating layer construction to layerFromMagsWithAttributes removes duplication. Double-check that any prior bounding-box or element-class validations still occur as intended.


71-71: Relax or clarify strict power-of-two requirement.
Requiring power-of-two mags may exclude datasets that lack uniform downsampling. Consider either a more descriptive error or a fallback path for non-power-of-two magnifications.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5Explorer.scala (1)

28-44: Consider supporting additional length units.
While this robust mapping covers many SI prefixes, you might consider including the angstrom symbol “Å” (with factor 0.1 nm) if there's a possibility of encountering that unit.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5CompactMultiscalesExplorer.scala (1)

20-37: Refine error messaging for multiScale requirement.
When multiScale is missing or false, the error text “does have multiScale=true” might be confusing for users. Consider rephrasing for clarity, e.g. “Expected multiScale=true but found otherwise.”

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8130a6b and 055ce24.

📒 Files selected for processing (10)
  • CHANGELOG.unreleased.md (1 hunks)
  • util/src/main/scala/com/scalableminds/util/geometry/Vec3Int.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/n5/N5Metadata.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/ExploreLocalLayerService.scala (2 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/ExploreRemoteLayerService.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5ArrayExplorer.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5CompactMultiscalesExplorer.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5Explorer.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5MultiscalesExplorer.scala (3 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NeuroglancerUriExplorer.scala (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: circleci_build
🔇 Additional comments (23)
util/src/main/scala/com/scalableminds/util/geometry/Vec3Int.scala (1)

82-87: Nice implementation of isAllPowersOfTwo method!

The method correctly checks if all components of a Vec3Int are powers of two using an efficient bit manipulation technique. This is an elegant solution that will be useful for validating properties of N5 compact multiscales metadata.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5ArrayExplorer.scala (1)

16-16: Inheritance change looks good

Changing the parent class from RemoteLayerExplorer to N5Explorer follows good object-oriented design by creating a more specific hierarchy for N5-related explorers.

CHANGELOG.unreleased.md (1)

16-16: LGTM - Well-documented changelog entry

The changelog entry properly documents the new feature of supporting N5 datasets with compact-style multiscale metadata, with a reference to the PR number.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/ExploreRemoteLayerService.scala (1)

105-105: Integration of new explorer looks good

The N5CompactMultiscalesExplorer has been appropriately added to the list of explorers, positioned between N5MultiscalesExplorer and N5ArrayExplorer. This ordering follows a logical progression from more specialized to more general explorers.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NeuroglancerUriExplorer.scala (1)

57-61: Add a fallback check for unsuccessful explorers.
Extending the sequence with N5CompactMultiscalesExplorer enhances coverage of N5 dataset variants. Ensure that each explorer gracefully defers to the next if it fails or encounters incompatible metadata.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/ExploreLocalLayerService.scala (1)

39-39: Confirm error handling among the local explorers sequence.
Inserting exploreLocalN5CompactMultiscales alongside other explorers helps maintain uniform exploration logic. Verify that it properly short-circuits or combines results when certain metadata are incomplete.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/n5/N5Metadata.scala (1)

23-36: Revisit default resolution logic.
While the PR objectives mention falling back to a [1,1,1] resolution if not provided, the code requires resolution as a non-optional field. Confirm whether an explicit fallback or an exception is desired here.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5MultiscalesExplorer.scala (3)

7-7: Confirm necessity of this import.
Importing N5Layer is consistent with returning the specialized layer type from this explorer. There are no apparent conflicts.


14-14: Favor composition via N5Explorer.
Switching to extends N5Explorer centralizes common logic, which should increase clarity and facilitate code reuse.


67-67: Scrutinize dimension validation in magFromTransform.
Ensure that the transform’s axes and scale values are fully validated before deriving magnification. Incomplete or mismatched axis data could lead to incorrect magnification vectors.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5Explorer.scala (7)

1-2: No critical concerns.


3-10: No issues with import statements.


13-16: Trait declaration looks good.
The usage of ExecutionContext is cleanly passed as an implicit, aligning well with async/await patterns.


17-26: Validate length of units list.
Currently, the code assumes that the units sequence has entries for x, y, z (and possibly c). Consider verifying that the list is at least as long as the largest axis index to avoid an IndexOutOfBoundsException.


46-57: Logic for extracting axis order is correct.
This ensures x, y, z (and optionally c) are properly matched. No further issues noted.


58-60: Voxel size extraction is straightforward.
The fallback to a failure on out-of-range indexing is acceptable given preceding checks. Looks good.


61-72: Layer creation approach is coherent.
Dynamically picking a segmentation or data layer based on naming and element class is a clear design. Code is well-organized.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/N5CompactMultiscalesExplorer.scala (6)

1-2: No critical concerns.


3-13: Import statements look good.


16-16: Class definition follows expected pattern.
Extending N5Explorer and mixing in FoxImplicits is a logical choice to reuse shared methods and Fox utilities.


18-18: Naming is clear.
The name method concisely denotes the purpose of this explorer.


38-45: Consistent voxel size extraction.
The multiplication of axis unit factors with resolution aligns with the logic in N5Explorer. No issues found.


46-67: Ensure downsampling factors match the axis count.
If downsamplingFactor doesn’t provide enough indices for x, y, or z, a runtime exception could occur. Confirm that minimal length requirements are satisfied or gracefully handle short lists.

@fm3 fm3 requested a review from frcroth March 18, 2025 14:14
metadataPath <- Fox.successful(remotePath / N5Metadata.FILENAME_ATTRIBUTES_JSON)
n5Metadata <- metadataPath
.parseAsJson[N5CompactMultiscalesMetadata] ?~> s"Failed to read N5 header at $metadataPath"
_ <- bool2Fox(n5Metadata.multiScale.contains(true)) ?~> s"N5 header at $metadataPath does have multiScale=true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this line do? It seems like it checks that multiScale has true and fails otherwise, but the error says that the problem is that it has true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s a typo in the error message. I’ll add a not!

@fm3 fm3 requested a review from frcroth March 23, 2025 09:42
@fm3 fm3 enabled auto-merge (squash) March 24, 2025 11:45
@fm3 fm3 merged commit 1d59228 into master Mar 24, 2025
3 checks passed
@fm3 fm3 deleted the n5-compact-multiscales branch March 24, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

N5 remote dataset not recognized as multi-scale

2 participants