From 7595d7779c50b57a5040dbfacf0a41bce9c68468 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Wed, 2 Feb 2022 14:17:29 -0600 Subject: [PATCH] Fix axes metadata when dimensionOrder is null dimensionOrder is only null if "--dimension-order original" was specified. --- .../bioformats2raw/Converter.java | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index 20b641f6..b05099c9 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -1473,9 +1473,10 @@ private void saveHCSMetadata(IMetadata meta) throws IOException { * @param resolutions Total number of resolutions from which * names will be generated. * @throws IOException + * @throws InterruptedException */ private void setSeriesLevelMetadata(int series, int resolutions) - throws IOException + throws IOException, InterruptedException { LOGGER.debug("setSeriesLevelMetadata({}, {})", series, resolutions); String resolutionString = String.format( @@ -1516,25 +1517,35 @@ private void setSeriesLevelMetadata(int series, int resolutions) } multiscale.put("datasets", datasets); + String axisOrder = null; if (dimensionOrder != null) { - List> axes = new ArrayList>(); - String axisOrder = dimensionOrder.toString(); - for (int i=axisOrder.length()-1; i>=0; i--) { - String axis = axisOrder.substring(i, i + 1).toLowerCase(); - String type = "space"; - if (axis.equals("t")) { - type = "time"; - } - else if (axis.equals("c")) { - type = "channel"; - } - Map thisAxis = new HashMap(); - thisAxis.put("name", axis); - thisAxis.put("type", type); - axes.add(thisAxis); + axisOrder = dimensionOrder.toString(); + } + else { + IFormatReader reader = readers.take(); + try { + axisOrder = reader.getDimensionOrder(); + } + finally { + readers.put(reader); + } + } + List> axes = new ArrayList>(); + for (int i=axisOrder.length()-1; i>=0; i--) { + String axis = axisOrder.substring(i, i + 1).toLowerCase(); + String type = "space"; + if (axis.equals("t")) { + type = "time"; + } + else if (axis.equals("c")) { + type = "channel"; } - multiscale.put("axes", axes); + Map thisAxis = new HashMap(); + thisAxis.put("name", axis); + thisAxis.put("type", type); + axes.add(thisAxis); } + multiscale.put("axes", axes); Path subGroupPath = getRootPath().resolve(seriesString); LOGGER.debug(" creating subgroup {}", subGroupPath); @@ -1783,13 +1794,25 @@ private Class getBaseReaderClass() throws FormatException, IOException { } } - private Map getArrayAttributes() { + private Map getArrayAttributes() throws InterruptedException { Map attrs = new HashMap(); + String order = null; if (dimensionOrder != null) { - String order = dimensionOrder.toString().toLowerCase(); - String[] axes = new StringBuilder(order).reverse().toString().split(""); - attrs.put("_ARRAY_DIMENSIONS", axes); + order = dimensionOrder.toString(); + } + else { + IFormatReader reader = readers.take(); + try { + order = reader.getDimensionOrder(); + } + finally { + readers.put(reader); + } } + + String[] axes = + new StringBuilder(order.toLowerCase()).reverse().toString().split(""); + attrs.put("_ARRAY_DIMENSIONS", axes); return attrs; }