Skip to content
Draft
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ configurations.all {

dependencies {
implementation 'net.java.dev.jna:jna:5.10.0'
implementation 'ome:formats-gpl:8.5.0'
implementation 'ome:formats-gpl:9.0.0-SNAPSHOT'
implementation 'info.picocli:picocli:4.7.5'
implementation 'com.univocity:univocity-parsers:2.8.4'
implementation 'dev.zarr:zarr-java:0.1.3'
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@
import loci.formats.ClassList;
import loci.formats.FormatException;
import loci.formats.FormatTools;
import loci.formats.IAxisOrientationReader;
import loci.formats.IFormatReader;
import loci.formats.ImageReader;
import loci.formats.Memoizer;
import loci.formats.MinMaxCalculator;
import loci.formats.MissingLibraryException;
import loci.formats.Orientation;
import loci.formats.OrientationTerm;
import loci.formats.OrientationType;
import loci.formats.ReaderWrapper;
import loci.formats.in.DynamicMetadataOptions;
import loci.formats.meta.IMetadata;
import loci.formats.ome.OMEXMLMetadata;
Expand Down Expand Up @@ -3060,7 +3065,27 @@ else if (axisChar.equals("y")) {
}
multiscale.put("datasets", datasets);

List<Map<String, String>> axes = new ArrayList<Map<String, String>>();
Orientation[] axisOrientations = null;
String orientationOrder = null;
try {
v = readers.take();
if (v instanceof ReaderWrapper) {
IFormatReader unwrapped = ((ReaderWrapper) v).unwrap();
if (unwrapped instanceof IAxisOrientationReader) {
axisOrientations =
((IAxisOrientationReader) unwrapped).getAxisOrientations();
orientationOrder = unwrapped.getDimensionOrder().toLowerCase();
}
}
}
catch (FormatException e) {
LOGGER.error("Could not get axis orientations", e);
}
finally {
readers.put(v);
}

List<Map<String, Object>> axes = new ArrayList<Map<String, Object>>();
for (int i=0; i<activeAxes.size(); i++) {
String axis = String.valueOf(activeAxes.get(i).getType()).toLowerCase();
String type = "space";
Expand All @@ -3071,7 +3096,7 @@ else if (axisChar.equals("y")) {
else if (axis.equals("c")) {
type = "channel";
}
Map<String, String> thisAxis = new HashMap<String, String>();
Map<String, Object> thisAxis = new HashMap<String, Object>();
thisAxis.put("name", axis);
thisAxis.put("type", type);
if (scale != null) {
Expand All @@ -3094,6 +3119,25 @@ else if (scale instanceof Time) {
thisAxis.put("unit", unitName);
}
}
if (axisOrientations != null && orientationOrder != null) {
int orientationIndex = orientationOrder.indexOf(axis);
if (orientationIndex >= 0) {
Orientation axisOrientation = axisOrientations[orientationIndex];
Map<String, String> orientationMap = null;
if (axisOrientation != null) {
orientationMap = new HashMap<String, String>();
OrientationType orientType = axisOrientation.getOrientationType();
OrientationTerm orientTerm = axisOrientation.getOrientationTerm();
if (orientType != null) {
orientationMap.put("type", orientType.getDefinedType());
}
if (orientTerm != null) {
orientationMap.put("value", orientTerm.getDefinedTerm());
}
}
thisAxis.put("orientation", orientationMap);
}
}
axes.add(thisAxis);
}
multiscale.put("axes", axes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -40,6 +41,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -491,6 +493,70 @@ public void testPixelType(String type, DataType dataType) throws Exception {
assertFalse(ome.getImage(0).getPixels().getBigEndian());
}

/**
* Test anatomical orientation (RFC-4).
*/
@Test
public void testAnatomicalOrientation() throws Exception {
HashMap<String, String> opts = new HashMap<String, String>();
opts.put("sizeZ", "4");
opts.put("sizeC", "3");
opts.put("sizeT", "2");
HashMap<String, String> seriesOpts = new HashMap<String, String>();
seriesOpts.put("AxisCount", "5");
seriesOpts.put("AxisOrientationType_0", "anatomical");
seriesOpts.put("AxisOrientationTerm_0", "left-to-right");
seriesOpts.put("AxisOrientationType_1", "anatomical");
seriesOpts.put("AxisOrientationTerm_1", "posterior-to-anterior");
seriesOpts.put("AxisOrientationType_2", "anatomical");
seriesOpts.put("AxisOrientationTerm_2", "rostral-to-caudal");
Map<Integer, Map<String, String>> allSeries =
new HashMap<Integer, Map<String, String>>();
allSeries.put(0, seriesOpts);
input = fake(opts, allSeries);

assertTool("--ngff-version", getNGFFVersion());

Array array = Array.open(store.resolve("0", "0"));
assertArrayEquals(new long[] {2, 3, 4, 512, 512}, array.metadata().shape);

Group rootGroup = Group.open(store.resolve("0"));
Attributes attrs = rootGroup.metadata().attributes;
Attributes omeAttrs = attrs.getAttributes("ome");

List<Map<String, Object>> multiscales =
(List<Map<String, Object>>) omeAttrs.get("multiscales");
assertEquals(1, multiscales.size());
Map<String, Object> multiscale = multiscales.get(0);
checkMultiscale(multiscale, "image");

List<Map<String, Object>> datasets =
(List<Map<String, Object>>) multiscale.get("datasets");
assertTrue(datasets.size() > 0);
assertEquals("0", datasets.get(0).get("path"));

List<Map<String, Object>> axes =
(List<Map<String, Object>>) multiscale.get("axes");
checkAxes(axes, "TCZYX", null);

for (int i=0; i<axes.size(); i++) {
Map<String, Object> axis = axes.get(i);
int originalAxisIndex = axes.size() - i - 1;
if (axis.get("orientation") == null) {
assertNull(seriesOpts.get("AxisOrientationType_" + originalAxisIndex));
assertNull(seriesOpts.get("AxisOrientationTerm_" + originalAxisIndex));
}
else {
Map<String, Object> orientation =
(Map<String, Object>) axis.get("orientation");
assertEquals(orientation.get("type"),
seriesOpts.get("AxisOrientationType_" + originalAxisIndex));
assertEquals(orientation.get("value"),
seriesOpts.get("AxisOrientationTerm_" + originalAxisIndex));
}
}
}

/**
* @return pairs of pixel type strings and Zarr data types
*/
Expand Down
Loading