Skip to content

Commit 94c129a

Browse files
committed
test: ngff v0.4 coordinate transform parsing
see #17
1 parent 1706d96 commit 94c129a

File tree

17 files changed

+258
-3
lines changed

17 files changed

+258
-3
lines changed

src/main/java/org/janelia/saalfeldlab/n5/universe/metadata/ome/ngff/v04/NgffSingleScaleMetadataParser.java

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import org.janelia.saalfeldlab.n5.universe.metadata.N5MetadataWriter;
1414
import org.janelia.saalfeldlab.n5.universe.metadata.axes.Axis;
1515
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformation;
16-
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.ScaleCoordinateTransformation;
17-
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.TranslationCoordinateTransformation;
1816

1917
import com.google.gson.Gson;
2018
import com.google.gson.JsonArray;

src/main/java/org/janelia/saalfeldlab/n5/universe/metadata/ome/ngff/v04/OmeNgffMetadataParser.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.janelia.saalfeldlab.n5.universe.metadata.N5MetadataWriter;
1717
import org.janelia.saalfeldlab.n5.universe.metadata.axes.Axis;
1818
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata.OmeNgffDataset;
19-
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.OmeNgffMultiScaleMetadata.OmeNgffDownsamplingMetadata;
2019
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformation;
2120
import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformationAdapter;
2221
import org.janelia.saalfeldlab.n5.zarr.ZarrDatasetAttributes;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import java.net.URI;
7+
import java.nio.file.Paths;
8+
import java.util.Optional;
9+
10+
import org.janelia.saalfeldlab.n5.DataType;
11+
import org.janelia.saalfeldlab.n5.DatasetAttributes;
12+
import org.janelia.saalfeldlab.n5.N5Reader;
13+
import org.janelia.saalfeldlab.n5.RawCompression;
14+
import org.janelia.saalfeldlab.n5.universe.N5Factory;
15+
import org.janelia.saalfeldlab.n5.universe.N5TreeNode;
16+
import org.janelia.saalfeldlab.n5.universe.metadata.N5SingleScaleMetadata;
17+
import org.junit.Test;
18+
19+
import net.imglib2.realtransform.AffineGet;
20+
import net.imglib2.realtransform.AffineTransform3D;
21+
import net.imglib2.realtransform.ScaleAndTranslation;
22+
23+
public class CoordinateTransformParsingTest {
24+
25+
private static final double EPS = 1E-6;
26+
27+
@Test
28+
public void testCoordinateTransformParsing() {
29+
30+
URI rootF = Paths.get("src", "test", "resources", "metadata.zarr").toUri();
31+
final N5Reader zarr = new N5Factory().openReader(rootF.toString());
32+
33+
final OmeNgffMetadataParser grpParser = new OmeNgffMetadataParser();
34+
test(grpParser.parseMetadata(zarr, setupNode("coordTforms/ss", "s0")),
35+
new double[]{4, 4},
36+
new double[]{0, 0});
37+
38+
test(grpParser.parseMetadata(zarr, setupNode("coordTforms/st", "s0")),
39+
new double[]{2, 2},
40+
new double[]{10, 10});
41+
42+
test(grpParser.parseMetadata(zarr, setupNode("coordTforms/ts", "s0")),
43+
new double[]{2, 2},
44+
new double[]{20, 20});
45+
46+
test(grpParser.parseMetadata(zarr, setupNode("coordTforms/tt", "s0")),
47+
new double[]{1, 1},
48+
new double[]{20, 20});
49+
}
50+
51+
private void test(final Optional<OmeNgffMetadata> metaOpt, final double[] expectedScale, final double[] expectedTranslation) {
52+
53+
assertTrue("ss not parsable", metaOpt.isPresent());
54+
55+
final OmeNgffMetadata meta = metaOpt.get();
56+
final AffineGet[] tforms = meta.spatialTransforms();
57+
assertTrue("ss has one transform", tforms.length == 1);
58+
59+
final ScaleAndTranslation tform = (ScaleAndTranslation)tforms[0];
60+
assertArrayEquals(expectedScale, tform.getScaleCopy(), EPS);
61+
assertArrayEquals(expectedTranslation, tform.getTranslationCopy(), EPS);
62+
}
63+
64+
private N5TreeNode setupNode(final String path, final String childPath) {
65+
66+
final N5TreeNode node = new N5TreeNode(path);
67+
final N5TreeNode child = new N5TreeNode(path + "/" + childPath);
68+
final DatasetAttributes attrs = new DatasetAttributes(new long[]{4, 4}, new int[]{4, 4}, DataType.UINT8, new RawCompression());
69+
child.setMetadata(new N5SingleScaleMetadata(path + "/" + childPath, new AffineTransform3D(),
70+
new double[]{1, 1}, new double[]{1, 1}, new double[]{0, 0}, "", attrs, false));
71+
72+
node.add(child);
73+
return node;
74+
}
75+
76+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"zarr_format":2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"zarr_format":2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"multiscales": [
3+
{
4+
"name": "boats",
5+
"type": "Average",
6+
"version": "0.4",
7+
"axes": [
8+
{
9+
"type": "space",
10+
"name": "y",
11+
"unit": "pixel"
12+
},
13+
{
14+
"type": "space",
15+
"name": "x",
16+
"unit": "pixel"
17+
}
18+
],
19+
"datasets": [
20+
{
21+
"path": "s0",
22+
"coordinateTransformations": [
23+
{
24+
"scale": [
25+
2,
26+
2
27+
],
28+
"type": "scale"
29+
},
30+
{
31+
"scale": [
32+
2,
33+
2
34+
],
35+
"type": "scale"
36+
}
37+
]
38+
}
39+
],
40+
"coordinateTransformations": []
41+
}
42+
]
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"zarr_format":2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":"/"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"multiscales": [
3+
{
4+
"name": "boats",
5+
"type": "Average",
6+
"version": "0.4",
7+
"axes": [
8+
{
9+
"type": "space",
10+
"name": "y",
11+
"unit": "pixel"
12+
},
13+
{
14+
"type": "space",
15+
"name": "x",
16+
"unit": "pixel"
17+
}
18+
],
19+
"datasets": [
20+
{
21+
"path": "s0",
22+
"coordinateTransformations": [
23+
{
24+
"scale": [
25+
2,
26+
2
27+
],
28+
"type": "scale"
29+
},
30+
{
31+
"translation": [
32+
10,
33+
10
34+
],
35+
"type": "translation"
36+
}
37+
]
38+
}
39+
],
40+
"coordinateTransformations": []
41+
}
42+
]
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"zarr_format":2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":"/"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"multiscales": [
3+
{
4+
"name": "boats",
5+
"type": "Average",
6+
"version": "0.4",
7+
"axes": [
8+
{
9+
"type": "space",
10+
"name": "y",
11+
"unit": "pixel"
12+
},
13+
{
14+
"type": "space",
15+
"name": "x",
16+
"unit": "pixel"
17+
}
18+
],
19+
"datasets": [
20+
{
21+
"path": "s0",
22+
"coordinateTransformations": [
23+
{
24+
"translation": [
25+
10,
26+
10
27+
],
28+
"type": "translation"
29+
},
30+
{
31+
"scale": [
32+
2,
33+
2
34+
],
35+
"type": "scale"
36+
}
37+
]
38+
}
39+
],
40+
"coordinateTransformations": []
41+
}
42+
]
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"zarr_format":2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":"/"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"multiscales": [
3+
{
4+
"name": "boats",
5+
"type": "Average",
6+
"version": "0.4",
7+
"axes": [
8+
{
9+
"type": "space",
10+
"name": "y",
11+
"unit": "pixel"
12+
},
13+
{
14+
"type": "space",
15+
"name": "x",
16+
"unit": "pixel"
17+
}
18+
],
19+
"datasets": [
20+
{
21+
"path": "s0",
22+
"coordinateTransformations": [
23+
{
24+
"translation": [
25+
10,
26+
10
27+
],
28+
"type": "translation"
29+
},
30+
{
31+
"translation": [
32+
10,
33+
10
34+
],
35+
"type": "translation"
36+
}
37+
]
38+
}
39+
],
40+
"coordinateTransformations": []
41+
}
42+
]
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"zarr_format":2}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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 commit comments

Comments
 (0)