Skip to content

Conversation

frcroth
Copy link
Contributor

@frcroth frcroth commented Jan 8, 2025

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

TODOs:

  • Before merging: Reenable label layers

Issues:


(Please delete unneeded items, merge only when none are left open)

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the OME NGFF (Next Generation File Format) coordinate transformation handling in the WebKnossos datastore. The changes primarily focus on adding support for translation parameters in coordinate transformations across multiple Scala files. The modifications enable more flexible spatial representation of datasets by allowing both scaling and translation transformations, which is crucial for accurately positioning and scaling multidimensional scientific imaging data.

Changes

File Change Summary
NgffMetadata.scala, NgffMetadataV0_5.scala Updated fromNameVoxelSizeAndMags method to include translation parameter with default None values
SharedNgffMetadataAttributes.scala Added optional translation field to NgffCoordinateTransformation
ExploreLayerUtils.scala Enhanced coordinate transformation logic with fallback mechanism
NgffExplorationUtils.scala Added getTranslation method for computing coordinate transformations
NgffV0_4Explorer.scala, NgffV0_5Explorer.scala Integrated translation handling in layer creation process

Assessment against linked issues

Objective Addressed Explanation
Support translation in coordinate transformations [#6600]
Handle missing scale attribute in transformations [#6600]
Enable importing OME NGFF datasets with translations [#6600]

Possibly related PRs

  • Wrap antd tree to enable scrolling while dragging #8162: The changes in this PR involve modifications to the fromNameVoxelSizeAndMags method in NgffMetadataV0_5, which also updates the NgffCoordinateTransformation to include a translation parameter, similar to the changes made in the main PR's NgffMetadata.scala.
  • Zarr streaming e2e test #8137: This PR focuses on end-to-end tests for Zarr streaming, which is relevant as it may involve the same data structures and transformations being modified in the main PR, particularly regarding how datasets are handled.
  • Call triggers/reload with fallback layer name #8298: This PR modifies the data reloading logic for segmentation layers, which is directly related to the changes in how data transformations are handled in the main PR.

Suggested labels

documentation

Suggested reviewers

  • daniel-wer

Poem

🐰 Hopping through metadata's maze,
Translations dance in digital haze,
Scales and shifts, a rabbit's delight,
NGFF transforms now shine so bright!
Code leaps forward with spatial grace 🌈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58620ec and a1c816d.

📒 Files selected for processing (1)
  • CHANGELOG.unreleased.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: circleci_build
🔇 Additional comments (1)
CHANGELOG.unreleased.md (1)

Line range hint 67-67: Document potential breaking changes.

Consider adding an entry to the "Breaking Changes" section if the coordinate transformation changes might affect existing datasets or integrations.

Would the changes to coordinate transformations affect existing datasets? If so, please document:

  • Impact on existing datasets
  • Required user actions
  • Migration steps if any

@frcroth frcroth self-assigned this Jan 8, 2025
@frcroth frcroth requested a review from fm3 January 8, 2025 13:02
@frcroth frcroth changed the title Support 'units' key Support OME-NGFF zarr dataset translation Jan 8, 2025
Copy link
Member

@fm3 fm3 left a comment

Choose a reason for hiding this comment

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

Looking pretty good already :) I added a couple of questions

})
layers: List[(DataLayerWithMagLocators, VoxelSize)] = layerLists.flatten
} yield layers ++ labelLayers
} yield layers //++ labelLayers
Copy link
Member

Choose a reason for hiding this comment

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

just a reminder to re-add this before merging

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: 1

🧹 Nitpick comments (2)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffExplorationUtils.scala (2)

269-283: Consider simplifying the nested transformation logic.

The transformation folding logic is complex and could be simplified for better maintainability. Consider extracting the transformation handling into separate functions for each type.

-        var translation = firstDataset.coordinateTransformations.foldLeft(baseTranslation)((acc, ct) => {
-          ct.`type` match {
-            case "translation" =>
-              ct.translation match {
-                case Some(translationList) =>
-                  acc.zipWithIndex.map { case (v, i) => v * translationList(translationList.length - 1 - i) }
-                case _ => acc
-              }
-            case _ =>
-              ct.scale match {
-                case Some(scaleList) => acc.zipWithIndex.map { case (v, i) => v / scaleList(scaleList.length - 1 - i) }
-                case _               => acc
-              }
-          }
-        })
+        def applyTranslation(acc: List[Double], ct: NgffCoordinateTransformation): List[Double] = 
+          ct.translation.map(tl => 
+            acc.zipWithIndex.map { case (v, i) => v * tl(tl.length - 1 - i) }
+          ).getOrElse(acc)
+        
+        def applyScale(acc: List[Double], ct: NgffCoordinateTransformation): List[Double] = 
+          ct.scale.map(sl => 
+            acc.zipWithIndex.map { case (v, i) => v / sl(sl.length - 1 - i) }
+          ).getOrElse(acc)
+        
+        val translation = firstDataset.coordinateTransformations.foldLeft(baseTranslation) { (acc, ct) =>
+          if (ct.`type` == "translation") applyTranslation(acc, ct)
+          else applyScale(acc, ct)
+        }

293-296: Consider using named constants for the affine transformation matrix.

The matrix construction uses magic numbers. Consider extracting these into named constants for better readability and maintainability.

+        val IDENTITY_MATRIX = List(
+          List(1, 0, 0),
+          List(0, 1, 0),
+          List(0, 0, 1)
+        )
+
         val coordinateTransformation = CoordinateTransformation(
           `type` = CoordinateTransformationType.affine,
           matrix = Some(
-            List(List(1, 0, 0, xTranslation),
-                 List(0, 1, 0, yTranslation),
-                 List(0, 0, 1, zTranslation),
-                 List(0, 0, 0, 1)))
+            IDENTITY_MATRIX.zipWithIndex.map { case (row, i) =>
+              row :+ (if (i < 3) translation(i) else 0)
+            } :+ List(0, 0, 0, 1))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a1c816d and bbdde25.

📒 Files selected for processing (3)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/zarr/NgffMetadata.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/zarr/SharedNgffMetadataAttributes.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffExplorationUtils.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/zarr/SharedNgffMetadataAttributes.scala
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/zarr/NgffMetadata.scala
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: circleci_build
🔇 Additional comments (2)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffExplorationUtils.scala (2)

24-25: LGTM!

The new imports are properly organized and necessary for the coordinate transformation functionality.


264-302: Add unit tests for the translation handling.

The new translation handling logic is complex and handles multiple cases (2D/3D, different transformation types). Consider adding comprehensive unit tests to verify the behavior.

Would you like me to help generate unit test cases covering various scenarios including:

  • 2D and 3D datasets
  • Different transformation combinations
  • Edge cases (empty translations, invalid lengths)

Comment on lines +272 to +275
ct.translation match {
case Some(translationList) =>
acc.zipWithIndex.map { case (v, i) => v * translationList(translationList.length - 1 - i) }
case _ => acc
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

The review comment is valid and the suggested fix is necessary. The code assumes the translation list has sufficient elements without validation, which could lead to IndexOutOfBoundsException. The same unsafe pattern is also present in scale list handling. The suggested fix appropriately handles cases where the translation list is shorter than expected.

🔗 Analysis chain

Add validation for translation list length.

The code assumes the translation list has sufficient elements but doesn't validate this assumption. Consider adding length validation to prevent potential index out of bounds exceptions.

             case "translation" =>
               ct.translation match {
                 case Some(translationList) =>
+                  if (translationList.length < acc.length) acc
+                  else
                   acc.zipWithIndex.map { case (v, i) => v * translationList(translationList.length - 1 - i) }
                 case _ => acc
               }
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Get the full context of the file
cat webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffExplorationUtils.scala

# Look for test files related to NgffExplorationUtils
fd "NgffExplorationUtils.*Test.*scala" 

# Search for other usages of translation in the codebase
rg "translation" --type scala -A 2 -B 2

Length of output: 25250


Script:

#!/bin/bash
# Look for test files that might contain translation-related tests
rg -B 3 -A 3 "translation.*Test" --type scala

# Look for any GitHub issues mentioning translation and index
gh issue list -s all -S "translation index bounds"

# Search for potential error logs or exception handling related to translation
rg -B 2 -A 2 "IndexOutOfBoundsException.*translation" --type scala

Length of output: 169


Script:

#!/bin/bash
# Look for NgffCoordinateTransformation construction
rg "new NgffCoordinateTransformation|NgffCoordinateTransformation\(" --type scala -B 2 -A 2

# Look for similar array access patterns with length checks
rg "length.*\- 1.*\-.*i" --type scala -B 2 -A 2

# Look for validation patterns in NGFF code
rg "validate|check" --type scala --glob "*Ngff*.scala" -B 2 -A 2

Length of output: 4063

@frcroth frcroth requested a review from fm3 January 13, 2025 15:59
Copy link
Member

@fm3 fm3 left a comment

Choose a reason for hiding this comment

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

🎉 (don’t forget to re-add label exploring)

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 (1)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffV0_4Explorer.scala (1)

71-71: LGTM! Consider adding documentation.

The coordinate transformations are correctly applied to both layer types. Consider adding documentation to describe:

  1. The expected format of coordinate transformations
  2. How translations affect the layer positioning
  3. Any limitations or constraints on transformation values

Also applies to: 83-83

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 52fc186 and 851c88a.

📒 Files selected for processing (1)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffV0_4Explorer.scala (3 hunks)
🔇 Additional comments (2)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/explore/NgffV0_4Explorer.scala (2)

61-61: LGTM! Verify translation extraction for edge cases.

The addition of translation support aligns with the PR objectives. Consider verifying the behavior when:

  1. Translation data is missing
  2. Translation data is malformed
  3. Translation is present but contains invalid values

Line range hint 39-42: Critical: Re-enable label layers before merging.

As mentioned in the PR objectives and past review comments, label layers need to be re-enabled before merging. Currently, the label layers functionality appears to be commented out.

Run this script to verify the commented-out label layer code:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OME NGFF coordinateTransformations translate

2 participants