From 21b7673bfa83eeb6e50f1b6c9137ee1d7d9633c9 Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Tue, 13 Sep 2022 22:05:54 +0200 Subject: [PATCH 1/6] Remove unused functions from ZarrAxes --- .../java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java index ea7ff28c..074f5d6f 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java @@ -95,14 +95,6 @@ public boolean isSpatial3D() { return this.axes.equals(CZYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(ZYX.axes); } - public boolean is4D() { - return this.axes.equals(CZYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(TCYX.axes); - } - - public boolean is3DWithTimepoints() { - return this.axes.equals(TYX.axes); - } - public boolean is4DWithTimepoints() { return this.axes.equals(TZYX.axes); } From 60fc3d48258be543befc456383bfd4291782290d Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Tue, 13 Sep 2022 22:38:15 +0200 Subject: [PATCH 2/6] Simplify getXYZScale, remove isSpatial3D --- .../zarr/loaders/N5OMEZarrImageLoader.java | 33 +++---------------- .../embl/mobie/io/ome/zarr/util/ZarrAxes.java | 17 +++++++--- src/test/java/projects/remote/BaseTest.java | 6 ++++ 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java index 0905fc79..4a95cf82 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java @@ -370,34 +370,11 @@ private double[] getXYZScale(OmeZarrMultiscales.CoordinateTransformations coordi double[] scale = coordinateTransformations.scale; double[] xyzScale = null; if (scale != null && zarrAxesList != null) { - int scalesFirstIndexBackward = scale.length - 1; - if (zarrAxes.hasChannels()) { - if (zarrAxes.is2D()) { - xyzScale = new double[]{ - scale[scalesFirstIndexBackward], - scale[scalesFirstIndexBackward - 1], - 1.0 - }; - } else { - xyzScale = new double[]{ - scale[scalesFirstIndexBackward], - scale[scalesFirstIndexBackward - 1], - scale[scalesFirstIndexBackward - 2]}; - } - } else { - if (zarrAxes.isSpatial3D()) { - xyzScale = new double[]{ - scale[scalesFirstIndexBackward], - scale[scalesFirstIndexBackward - 1], - scale[scalesFirstIndexBackward - 2]}; - } else { - xyzScale = new double[]{ - scale[scalesFirstIndexBackward], - scale[scalesFirstIndexBackward - 1], - 1.0 - }; - } - } + xyzScale = new double[]{ + zarrAxes.axisIndex("x", false), + scale[zarrAxes.axisIndex("y", false)], + zarrAxes.hasZAxis() ? scale[zarrAxes.axisIndex("z", false)] : 1.0 + }; } return xyzScale; } diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java index 074f5d6f..b3995544 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java @@ -118,14 +118,23 @@ public boolean hasChannels() { this.axes.equals(TCZYX.axes); } + // the flag reverseAxes determines whether the index will be given w.r.t. + // reversedAxes=true corresponds to the java/bdv axis convention + // reversedAxes=false corresponds to the zarr axis convention + public int axisIndex(String axisName, boolean reverseAxes) { + if(reverseAxes) { + List reverseAxesList = Lists.reverse(getAxesList()); + return reverseAxesList.indexOf(axisName); + } + return getAxesList().indexOf(axisName); + } + public int timeIndex() { - List reverseAxesList = Lists.reverse(getAxesList()); - return reverseAxesList.indexOf("t"); + return axisIndex("t", true); } public int channelIndex() { - List reverseAxesList = Lists.reverse(getAxesList()); - return reverseAxesList.indexOf("c"); + return axisIndex("c", true); } // spatial: 0,1,2 (x,y,z) diff --git a/src/test/java/projects/remote/BaseTest.java b/src/test/java/projects/remote/BaseTest.java index d2dec728..bf9a34a0 100644 --- a/src/test/java/projects/remote/BaseTest.java +++ b/src/test/java/projects/remote/BaseTest.java @@ -17,6 +17,9 @@ public abstract class BaseTest extends BaseSpimDataChecker { protected int expectedChannelsNumber = 1; protected Dimensions expectedShape; protected String expectedDType; + // TODO refactor the base test into a zarr base test so that we can also check for zarr specific attributes + // like the expected scale + //protected int [] expectedScale = null; protected BaseTest(String path, ImageDataFormat format) throws SpimDataException { super(new SpimDataOpener().openSpimData(path, format)); @@ -32,6 +35,9 @@ public void baseTest() { Assertions.assertEquals(expectedChannelsNumber, getAllChannelsSize()); Assertions.assertEquals(expectedShape, getShape()); Assertions.assertEquals(expectedDType, getDType()); + // if(expectedScale != null) { + // Assertions.assertEquals(expectedScale, getScale()); + //} } public int getExpectedTimePoints() { From 02638c473c35ac1ea19b394feff1bb5c26347177 Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Tue, 13 Sep 2022 22:56:46 +0200 Subject: [PATCH 3/6] Fix typo --- .../embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java index 4a95cf82..d0f4b757 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java @@ -371,7 +371,7 @@ private double[] getXYZScale(OmeZarrMultiscales.CoordinateTransformations coordi double[] xyzScale = null; if (scale != null && zarrAxesList != null) { xyzScale = new double[]{ - zarrAxes.axisIndex("x", false), + scale[zarrAxes.axisIndex("x", false)], scale[zarrAxes.axisIndex("y", false)], zarrAxes.hasZAxis() ? scale[zarrAxes.axisIndex("z", false)] : 1.0 }; From bfe7b68e65c9d6de44bba750d49d2c4a3e9ffc70 Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Tue, 13 Sep 2022 22:59:48 +0200 Subject: [PATCH 4/6] Remove zarr.Axes.is2D --- .../ome/zarr/loaders/N5OMEZarrImageLoader.java | 18 ++++++------------ .../embl/mobie/io/ome/zarr/util/ZarrAxes.java | 8 -------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java index d0f4b757..49c4f310 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java @@ -406,10 +406,10 @@ private VoxelDimensions getVoxelDimensions3D(int setupId, int datasetId) { String unit = zarrAxesList.get(zarrAxesList.size() - 1).getUnit(); if (scale != null && unit != null) { - if (zarrAxes.is2D()) { - return new FinalVoxelDimensions(unit, new double[]{scale[0], scale[1], 1.0}); - } else { + if (zarrAxes.hasZAxis()) { return new FinalVoxelDimensions(unit, scale); + } else { + return new FinalVoxelDimensions(unit, new double[]{scale[0], scale[1], 1.0}); } } } @@ -568,16 +568,10 @@ private double[][] readMipmapResolutions() throws IOException { for (int level = 1; level < mipmapResolutions.length; level++) { long[] dimensions = getDatasetAttributes(getPathName(setupId, level)).getDimensions(); mipmapResolutions[level] = new double[3]; - if (multiscale.axes.is2D()) { - for (int d = 0; d < 2; d++) { - mipmapResolutions[level][d] = Math.round(1.0 * dimensionsOfLevel0[d] / dimensions[d]); - } - mipmapResolutions[level][2] = 1.0; - } else { - for (int d = 0; d < 3; d++) { - mipmapResolutions[level][d] = 1.0 * dimensionsOfLevel0[d] / dimensions[d]; - } + for (int d = 0; d < 2; d++) { + mipmapResolutions[level][d] = Math.round(1.0 * dimensionsOfLevel0[d] / dimensions[d]); } + mipmapResolutions[level][2] = multiscale.axes.hasZAxis() ? Math.round(1.0 * dimensionsOfLevel0[2] / dimensions[2]) : 1.0; } return mipmapResolutions; diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java index b3995544..a598cc1f 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java @@ -83,18 +83,10 @@ public List toAxesList(String spaceUnit, String timeUnit) { return zarrAxesList; } - public boolean is2D() { - return this.axes.equals(YX.axes) || this.axes.equals(CYX.axes); // XYT XYC - } - public boolean is5D() { return this.axes.equals(TCZYX.axes); } - public boolean isSpatial3D() { - return this.axes.equals(CZYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(ZYX.axes); - } - public boolean is4DWithTimepoints() { return this.axes.equals(TZYX.axes); } From 2ba8c2565d59e4c328fb6d5ff543c82bf2d05bca Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Wed, 14 Sep 2022 10:06:57 +0200 Subject: [PATCH 5/6] Update ZarrArrayCreator.getCellDims, remove more unused ZarrAxes functions --- .../io/ome/zarr/util/ZarrArrayCreator.java | 26 +++++-------------- .../embl/mobie/io/ome/zarr/util/ZarrAxes.java | 13 ---------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java index b43535b8..deaea22e 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java @@ -29,28 +29,14 @@ public A createArray(DataBlock dataBlock, long[] gridPosition) { @Override public long[] getCellDims(long[] gridPosition) { - long[] cellMin = new long[3]; - int[] cellDims = new int[3]; - - // TODO: do something like in: private long[] toZarrChunkIndices( long[] gridPosition ) - if (zarrAxes.is4DWithChannels() || zarrAxes.is4DWithTimepoints()) { - cellMin = new long[4]; - cellDims = new int[4]; - cellDims[3] = 1; // channel - } + long[] cellMin = new long[Math.max(zarrAxes.getNumDimension(), 3)]; + int[] cellDims = new int[Math.max(zarrAxes.getNumDimension(), 3)]; - if (zarrAxes.is4DWithTimepointsAndChannels()) { - cellMin = new long[4]; - cellDims = new int[4]; - cellDims[2] = 1; // channel - cellDims[3] = 1; // timepoint + if(zarrAxes.hasChannels()) { + cellDims[zarrAxes.channelIndex()] = 1; } - - if (zarrAxes.is5D()) { - cellMin = new long[5]; - cellDims = new int[5]; - cellDims[3] = 1; // channel - cellDims[4] = 1; // timepoint + if(zarrAxes.hasTimepoints()) { + cellDims[zarrAxes.timeIndex()] = 1; } cellGrid.getCellDimensions(gridPosition, cellMin, cellDims); diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java index a598cc1f..a8f3dbff 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java @@ -87,19 +87,6 @@ public boolean is5D() { return this.axes.equals(TCZYX.axes); } - public boolean is4DWithTimepoints() { - return this.axes.equals(TZYX.axes); - } - - public boolean is4DWithChannels() { - return this.axes.equals(CZYX.axes); - } - - // not used anymore - public boolean is4DWithTimepointsAndChannels() { - return this.axes.equals(TCYX.axes); - } - public boolean hasTimepoints() { return this.axes.equals(TCYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(TYX.axes) || this.axes.equals(TCZYX.axes); From f094a8192c3f7f73459a59f795592870f16ce34d Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Wed, 14 Sep 2022 10:09:41 +0200 Subject: [PATCH 6/6] Remove zarrAxes.is5D --- src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java index a8f3dbff..115e212c 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java @@ -83,10 +83,6 @@ public List toAxesList(String spaceUnit, String timeUnit) { return zarrAxesList; } - public boolean is5D() { - return this.axes.equals(TCZYX.axes); - } - public boolean hasTimepoints() { return this.axes.equals(TCYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(TYX.axes) || this.axes.equals(TCZYX.axes);