From 4a0d8e4c754b3d004692b0c89e38d89c7e80599b Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 4 Apr 2022 11:20:25 -0500 Subject: [PATCH] Update units to use the enum names instead of symbols --- .../bioformats2raw/Converter.java | 19 ++++++++++++++++++- .../bioformats2raw/test/ZarrTest.java | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index f1703b23..29271318 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -55,11 +55,15 @@ import loci.formats.ome.OMEXMLMetadata; import loci.formats.services.OMEXMLService; import loci.formats.services.OMEXMLServiceImpl; +import ome.units.quantity.Length; import ome.units.quantity.Quantity; +import ome.units.quantity.Time; import ome.xml.meta.OMEXMLMetadataRoot; import ome.xml.model.enums.DimensionOrder; import ome.xml.model.enums.EnumerationException; import ome.xml.model.enums.PixelType; +import ome.xml.model.enums.UnitsLength; +import ome.xml.model.enums.UnitsTime; import ome.xml.model.primitives.PositiveInteger; import org.perf4j.slf4j.Slf4JStopWatch; @@ -1610,7 +1614,20 @@ else if (axis.equals("c")) { thisAxis.put("name", axis); thisAxis.put("type", type); if (scale != null) { - thisAxis.put("unit", scale.unit().getSymbol()); + String symbol = scale.unit().getSymbol(); + String unitName = null; + try { + if (scale instanceof Length) { + unitName = UnitsLength.fromString(symbol).name().toLowerCase(); + } + else if (scale instanceof Time) { + unitName = UnitsTime.fromString(symbol).name().toLowerCase(); + } + } + catch (EnumerationException e) { + LOGGER.warn("Could not identify unit '{}'", symbol); + } + thisAxis.put("unit", unitName); } axes.add(thisAxis); } diff --git a/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java b/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java index a076c2e7..abdf04c8 100644 --- a/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java +++ b/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java @@ -361,7 +361,8 @@ public void testPhysicalSizes() throws Exception { Map multiscale = multiscales.get(0); List> axes = (List>) multiscale.get("axes"); - checkAxes(axes, "TCZYX", new String[] {null, null, "cm", "mm", "mm"}); + checkAxes(axes, "TCZYX", + new String[] {null, null, "centimeter", "millimeter", "millimeter"}); List> datasets = (List>) multiscale.get("datasets");