-
Notifications
You must be signed in to change notification settings - Fork 29
Support OME-NGFF zarr dataset translation #8311
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
Changes from all commits
9a8871c
5bd3ec4
58620ec
eb7af06
a1c816d
adba7f8
78301d7
bbdde25
a4700cd
52fc186
ba5b24c
851c88a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import com.scalableminds.webknossos.datastore.models.LengthUnit.LengthUnit | |
import com.scalableminds.webknossos.datastore.models.datasource.LayerViewConfiguration.LayerViewConfiguration | ||
import com.scalableminds.webknossos.datastore.models.datasource.{ | ||
AdditionalAxis, | ||
CoordinateTransformation, | ||
CoordinateTransformationType, | ||
DataLayerWithMagLocators, | ||
ElementClass, | ||
LayerViewConfiguration | ||
|
@@ -259,6 +261,46 @@ trait NgffExplorationUtils extends FoxImplicits { | |
layerAndVoxelSizeTuples = layers.map((_, VoxelSize(voxelSizeFactor, unifiedAxisUnit))) | ||
} yield layerAndVoxelSizeTuples | ||
|
||
protected def getTranslation(multiscale: NgffMultiscalesItem): Option[List[CoordinateTransformation]] = { | ||
val is2d = !multiscale.axes.exists(_.name == "z") | ||
val baseTranslation = if (is2d) List(1.0, 1.0) else List(1.0, 1.0, 1.0) | ||
multiscale.datasets.headOption match { | ||
case Some(firstDataset) if firstDataset.coordinateTransformations.exists(_.`type` == "translation") => { | ||
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 | ||
Comment on lines
+272
to
+275
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 chainAdd 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 executedThe 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 |
||
} | ||
case _ => | ||
ct.scale match { | ||
case Some(scaleList) => acc.zipWithIndex.map { case (v, i) => v / scaleList(scaleList.length - 1 - i) } | ||
case _ => acc | ||
} | ||
} | ||
}) | ||
if (is2d) { | ||
translation = translation :+ 0.0 | ||
} | ||
val xTranslation = translation(0) | ||
val yTranslation = translation(1) | ||
val zTranslation = translation(2) | ||
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))) | ||
) | ||
Some(List(coordinateTransformation)) | ||
} | ||
case _ => None | ||
} | ||
} | ||
|
||
protected def layersForLabel(remotePath: VaultPath, | ||
labelPath: String, | ||
credentialId: Option[String]): Fox[List[(DataLayerWithMagLocators, VoxelSize)]] | ||
|
Uh oh!
There was an error while loading. Please reload this page.