Skip to content

Commit

Permalink
test: ngff v0.4 coordinate transform parsing
Browse files Browse the repository at this point in the history
see #17
  • Loading branch information
bogovicj committed May 2, 2024
1 parent 1706d96 commit 94c129a
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.janelia.saalfeldlab.n5.universe.metadata.N5MetadataWriter;
import org.janelia.saalfeldlab.n5.universe.metadata.axes.Axis;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformation;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.ScaleCoordinateTransformation;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.TranslationCoordinateTransformation;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.janelia.saalfeldlab.n5.universe.metadata.N5MetadataWriter;
import org.janelia.saalfeldlab.n5.universe.metadata.axes.Axis;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata.OmeNgffDataset;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata.OmeNgffDownsamplingMetadata;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformation;
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformationAdapter;
import org.janelia.saalfeldlab.n5.zarr.ZarrDatasetAttributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;

import java.net.URI;
import java.nio.file.Paths;
import java.util.Optional;

import org.janelia.saalfeldlab.n5.DataType;
import org.janelia.saalfeldlab.n5.DatasetAttributes;
import org.janelia.saalfeldlab.n5.N5Reader;
import org.janelia.saalfeldlab.n5.RawCompression;
import org.janelia.saalfeldlab.n5.universe.N5Factory;
import org.janelia.saalfeldlab.n5.universe.N5TreeNode;
import org.janelia.saalfeldlab.n5.universe.metadata.N5SingleScaleMetadata;
import org.junit.Test;

import net.imglib2.realtransform.AffineGet;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.realtransform.ScaleAndTranslation;

public class CoordinateTransformParsingTest {

private static final double EPS = 1E-6;

@Test
public void testCoordinateTransformParsing() {

URI rootF = Paths.get("src", "test", "resources", "metadata.zarr").toUri();
final N5Reader zarr = new N5Factory().openReader(rootF.toString());

final OmeNgffMetadataParser grpParser = new OmeNgffMetadataParser();
test(grpParser.parseMetadata(zarr, setupNode("coordTforms/ss", "s0")),
new double[]{4, 4},
new double[]{0, 0});

test(grpParser.parseMetadata(zarr, setupNode("coordTforms/st", "s0")),
new double[]{2, 2},
new double[]{10, 10});

test(grpParser.parseMetadata(zarr, setupNode("coordTforms/ts", "s0")),
new double[]{2, 2},
new double[]{20, 20});

test(grpParser.parseMetadata(zarr, setupNode("coordTforms/tt", "s0")),
new double[]{1, 1},
new double[]{20, 20});
}

private void test(final Optional<OmeNgffMetadata> metaOpt, final double[] expectedScale, final double[] expectedTranslation) {

assertTrue("ss not parsable", metaOpt.isPresent());

final OmeNgffMetadata meta = metaOpt.get();
final AffineGet[] tforms = meta.spatialTransforms();
assertTrue("ss has one transform", tforms.length == 1);

final ScaleAndTranslation tform = (ScaleAndTranslation)tforms[0];
assertArrayEquals(expectedScale, tform.getScaleCopy(), EPS);
assertArrayEquals(expectedTranslation, tform.getTranslationCopy(), EPS);
}

private N5TreeNode setupNode(final String path, final String childPath) {

final N5TreeNode node = new N5TreeNode(path);
final N5TreeNode child = new N5TreeNode(path + "/" + childPath);
final DatasetAttributes attrs = new DatasetAttributes(new long[]{4, 4}, new int[]{4, 4}, DataType.UINT8, new RawCompression());
child.setMetadata(new N5SingleScaleMetadata(path + "/" + childPath, new AffineTransform3D(),
new double[]{1, 1}, new double[]{1, 1}, new double[]{0, 0}, "", attrs, false));

node.add(child);
return node;
}

}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2}
43 changes: 43 additions & 0 deletions src/test/resources/metadata.zarr/coordTforms/ss/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"multiscales": [
{
"name": "boats",
"type": "Average",
"version": "0.4",
"axes": [
{
"type": "space",
"name": "y",
"unit": "pixel"
},
{
"type": "space",
"name": "x",
"unit": "pixel"
}
],
"datasets": [
{
"path": "s0",
"coordinateTransformations": [
{
"scale": [
2,
2
],
"type": "scale"
},
{
"scale": [
2,
2
],
"type": "scale"
}
]
}
],
"coordinateTransformations": []
}
]
}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/ss/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/ss/s0/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2,"shape":[576,720],"chunks":[16,16],"dtype":"|u1","compressor":{"id":"gzip","level":-1},"fill_value":"0","filters":[],"order":"C","dimension_separator":"/"}
43 changes: 43 additions & 0 deletions src/test/resources/metadata.zarr/coordTforms/st/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"multiscales": [
{
"name": "boats",
"type": "Average",
"version": "0.4",
"axes": [
{
"type": "space",
"name": "y",
"unit": "pixel"
},
{
"type": "space",
"name": "x",
"unit": "pixel"
}
],
"datasets": [
{
"path": "s0",
"coordinateTransformations": [
{
"scale": [
2,
2
],
"type": "scale"
},
{
"translation": [
10,
10
],
"type": "translation"
}
]
}
],
"coordinateTransformations": []
}
]
}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/st/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/st/s0/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2,"shape":[576,720],"chunks":[16,16],"dtype":"|u1","compressor":{"id":"gzip","level":-1},"fill_value":"0","filters":[],"order":"C","dimension_separator":"/"}
43 changes: 43 additions & 0 deletions src/test/resources/metadata.zarr/coordTforms/ts/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"multiscales": [
{
"name": "boats",
"type": "Average",
"version": "0.4",
"axes": [
{
"type": "space",
"name": "y",
"unit": "pixel"
},
{
"type": "space",
"name": "x",
"unit": "pixel"
}
],
"datasets": [
{
"path": "s0",
"coordinateTransformations": [
{
"translation": [
10,
10
],
"type": "translation"
},
{
"scale": [
2,
2
],
"type": "scale"
}
]
}
],
"coordinateTransformations": []
}
]
}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/ts/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/ts/s0/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2,"shape":[576,720],"chunks":[16,16],"dtype":"|u1","compressor":{"id":"gzip","level":-1},"fill_value":"0","filters":[],"order":"C","dimension_separator":"/"}
43 changes: 43 additions & 0 deletions src/test/resources/metadata.zarr/coordTforms/tt/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"multiscales": [
{
"name": "boats",
"type": "Average",
"version": "0.4",
"axes": [
{
"type": "space",
"name": "y",
"unit": "pixel"
},
{
"type": "space",
"name": "x",
"unit": "pixel"
}
],
"datasets": [
{
"path": "s0",
"coordinateTransformations": [
{
"translation": [
10,
10
],
"type": "translation"
},
{
"translation": [
10,
10
],
"type": "translation"
}
]
}
],
"coordinateTransformations": []
}
]
}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/tt/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2}
1 change: 1 addition & 0 deletions src/test/resources/metadata.zarr/coordTforms/tt/s0/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"zarr_format":2,"shape":[576,720],"chunks":[16,16],"dtype":"|u1","compressor":{"id":"gzip","level":-1},"fill_value":"0","filters":[],"order":"C","dimension_separator":"/"}

0 comments on commit 94c129a

Please sign in to comment.