Skip to content

Commit

Permalink
Update units to use the enum names instead of symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Apr 4, 2022
1 parent 6551d32 commit 4a0d8e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ public void testPhysicalSizes() throws Exception {
Map<String, Object> multiscale = multiscales.get(0);
List<Map<String, Object>> axes =
(List<Map<String, Object>>) multiscale.get("axes");
checkAxes(axes, "TCZYX", new String[] {null, null, "cm", "mm", "mm"});
checkAxes(axes, "TCZYX",
new String[] {null, null, "centimeter", "millimeter", "millimeter"});

List<Map<String, Object>> datasets =
(List<Map<String, Object>>) multiscale.get("datasets");
Expand Down

0 comments on commit 4a0d8e4

Please sign in to comment.