Skip to content
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

Fix shape in zarr.json in zarr3 streaming #8116

Merged
merged 9 commits into from
Oct 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class ZarrStreamingController @Inject()(
"dataSource.notFound") ~> NOT_FOUND
magParsed <- Vec3Int.fromMagLiteral(mag, allowScalar = true) ?~> Messages("dataLayer.invalidMag", mag) ~> NOT_FOUND
_ <- bool2Fox(dataLayer.containsResolution(magParsed)) ?~> Messages("dataLayer.wrongMag", dataLayerName, mag) ~> NOT_FOUND
zarrHeader = Zarr3ArrayHeader.fromDataLayer(dataLayer)
zarrHeader = Zarr3ArrayHeader.fromDataLayer(dataLayer, magParsed)
} yield Ok(Json.toJson(zarrHeader))

def zArrayPrivateLink(token: Option[String],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.scalableminds.webknossos.datastore.datareaders.zarr3

import com.scalableminds.util.geometry.Vec3Int
import com.scalableminds.util.tools.{BoxImplicits, JsonHelper}
import com.scalableminds.webknossos.datastore.datareaders.ArrayDataType.ArrayDataType
import com.scalableminds.webknossos.datastore.datareaders.ArrayOrder.ArrayOrder
Expand Down Expand Up @@ -251,13 +252,20 @@ object Zarr3ArrayHeader extends JsonImplicits {
)

}
def fromDataLayer(dataLayer: DataLayer): Zarr3ArrayHeader = {
def fromDataLayer(dataLayer: DataLayer, mag: Vec3Int): Zarr3ArrayHeader = {
val additionalAxes = reorderAdditionalAxes(dataLayer.additionalAxes.getOrElse(Seq.empty))
// TODOM: Make code together with ZarrHeader.scala DRYer
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
val xyzBBounds = Array(
// Zarr can't handle data sets that don't start at 0, so we extend the shape to include "true" coords
(dataLayer.boundingBox.width + dataLayer.boundingBox.topLeft.x) / mag.x,
(dataLayer.boundingBox.height + dataLayer.boundingBox.topLeft.y) / mag.y,
(dataLayer.boundingBox.depth + dataLayer.boundingBox.topLeft.z) / mag.z
)
Zarr3ArrayHeader(
zarr_format = 3,
node_type = "array",
// channel, additional axes, XYZ
shape = Array(1) ++ additionalAxes.map(_.highestValue).toArray ++ dataLayer.boundingBox.bottomRight.toArray,
shape = Array(1) ++ additionalAxes.map(_.highestValue).toArray ++ xyzBBounds,
data_type = Left(dataLayer.elementClass.toString),
chunk_grid = Left(
ChunkGridSpecification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Zarr3BucketStreamSink(val layer: VolumeTracingLayer, tracingHasFallbackLay
def apply(bucketStream: Iterator[(BucketPosition, Array[Byte])], mags: Seq[Vec3Int], voxelSize: Option[VoxelSize])(
implicit ec: ExecutionContext): Iterator[NamedStream] = {

val header = Zarr3ArrayHeader.fromDataLayer(layer)
val header = Zarr3ArrayHeader.fromDataLayer(layer, mags.head)
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
bucketStream.flatMap {
case (bucket, data) =>
val skipBucket = if (tracingHasFallbackLayer) isAllZero(data) else isRevertedBucket(data)
Expand Down