Skip to content

Commit 12cc8fa

Browse files
authored
Use zarr string fill values (#7017)
1 parent eab96fe commit 12cc8fa

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.unreleased.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
1818

1919
### Fixed
2020
- Fixed that changing a segment color could lead to a crash. [#7000](https://github.com/scalableminds/webknossos/pull/7000)
21+
- The fill_value property of zarr dataset is now used when it is not a number. [#7017](https://github.com/scalableminds/webknossos/pull/7017)
2122
- Fixed rendering issues on some affected systems that led to "black holes". [#7018](https://github.com/scalableminds/webknossos/pull/7018)
2223
- Fixed a bug that made downloads of public annotations fail occasionally. [#7025](https://github.com/scalableminds/webknossos/pull/7025)
2324
- Added a workaround for a WebGL crash which could appear when a dataset contained many segmentation layers. [#6995](https://github.com/scalableminds/webknossos/pull/6995)

webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/ArrayDataType.scala

+28
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,32 @@ object ArrayDataType extends ExtendedEnumeration {
1919
case ArrayDataType.i1 => 1
2020
case ArrayDataType.u1 => 1
2121
}
22+
23+
def maxValue(dataType: ArrayDataType): Number =
24+
dataType match {
25+
case ArrayDataType.f8 => Double.MaxValue
26+
case ArrayDataType.f4 => Float.MaxValue
27+
case ArrayDataType.i8 => Long.MaxValue
28+
case ArrayDataType.u8 => Long.MaxValue // Max value for primitive datatypes
29+
case ArrayDataType.i4 => Int.MaxValue
30+
case ArrayDataType.u4 => Math.pow(2, 4 * 8).toLong - 1
31+
case ArrayDataType.i2 => Char.MaxValue
32+
case ArrayDataType.u2 => Math.pow(2, 2 * 8).toLong - 1
33+
case ArrayDataType.i1 => Byte.MaxValue
34+
case ArrayDataType.u1 => Math.pow(2, 1 * 8).toLong - 1
35+
}
36+
37+
def minValue(dataType: ArrayDataType): Number =
38+
dataType match {
39+
case ArrayDataType.f8 => Double.MinValue
40+
case ArrayDataType.f4 => Float.MinValue
41+
case ArrayDataType.i8 => Long.MinValue
42+
case ArrayDataType.u8 => 0
43+
case ArrayDataType.i4 => Int.MinValue
44+
case ArrayDataType.u4 => 0
45+
case ArrayDataType.i2 => Char.MinValue
46+
case ArrayDataType.u2 => 0
47+
case ArrayDataType.i1 => Byte.MinValue
48+
case ArrayDataType.u1 => 0
49+
}
2250
}

webknossos-datastore/app/com/scalableminds/webknossos/datastore/datareaders/DatasetHeader.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait DatasetHeader {
3333
lazy val fillValueNumber: Number =
3434
fill_value match {
3535
case Right(n) => n
36-
case Left(_) => 0 // parsing fill value from string not currently supported
36+
case Left(s) => parseFillValueFromString(s)
3737
}
3838

3939
def boundingBox(axisOrder: AxisOrder): Option[BoundingBox] =
@@ -48,5 +48,13 @@ trait DatasetHeader {
4848

4949
def isSharded = false
5050

51+
private def parseFillValueFromString(s: String): Number =
52+
s match {
53+
case "NaN" => 0
54+
case "Infinity" => ArrayDataType.maxValue(resolvedDataType)
55+
case "-Infinity" => ArrayDataType.minValue(resolvedDataType)
56+
case _ => 0 // Unsupported fill value does not throw exception
57+
}
58+
5159
def voxelOffset: Array[Int]
5260
}

0 commit comments

Comments
 (0)