Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
* Introduced more basic helper functions for reading from ZARR

## [v0.5.0] - 2025-06-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ lazy val compileSettings = Def.settings(
Test / console / scalacOptions := (Compile / console / scalacOptions).value,
)

lazy val versionNumber = "0.5.0"
lazy val versionNumber = "0.6.0-SNAPSHOT"

lazy val metadataSettings = Def.settings(
name := projectName,
Expand Down
25 changes: 25 additions & 0 deletions modules/zarr/src/main/scala/ZarrArrayExtras.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ import at.ac.oeaw.imba.gerlich.gerlib.zarr.OmeZarrIndex.OmeZarrStandardCoordinat

/** Helpers for working with [[com.bc.zarr.ZarrArray]] */
object ZarrArrayExtras:

// TODO: guard against atypical dimension order.
private def getXY(za: ZarrArray): Either[String, Dimensions2D] =
za.getShape.toList match {
case _ :: _ :: _ :: y :: x :: Nil => new Dimensions2D(x = x, y = y).asRight
case dims => s"${dims.length}-D array, not 5-D".asLeft
}

def readFirstFullSize2DFrom5D(za: ZarrArray): Either[String, DataRead2D] = for
dims <- getXY(za)
data <- Try{
JzarrTools.readFrom(za, Array(1, 1, 1, dims.y, dims.x), Array(0, 0, 0, 0, 0))
}.toEither.leftMap(_.getMessage)
yield DataRead2D(data, dims)

extension (za: ZarrArray)
def read(indexMapping: IndexMapping)(
origin: OmeZarrStandardCoordinate,
Expand All @@ -23,4 +38,14 @@ object ZarrArrayExtras:
.leftMap(e =>
s"For index mapping $indexMapping and starting from $origin, failed to read block of size $size: ${e.getMessage}"
)

final class Dimensions2D(val x: Int, val y: Int):
require(x >= 0, s"x dimension must be nonnegative, not $x")
require(y >= 0, s"y dimension must be nonnegative, not $y")

final class DataRead2D(values: Array[Int], dimensions: Dimensions2D):
require(
values.length === dimensions.x * dimensions.y,
s"${dimensions.x} * ${dimensions.y} = ${dimensions.x * dimensions.y}, not ${values.length}"
)
end ZarrArrayExtras
Loading