From 68b8e170817f45d3dcdc10c85c51e845cee51ad3 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Tue, 10 Dec 2024 15:46:51 -0600 Subject: [PATCH 1/2] OIR: parse time step from TIMELAPSE axis when possible --- .../src/loci/formats/in/OIRReader.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/components/formats-gpl/src/loci/formats/in/OIRReader.java b/components/formats-gpl/src/loci/formats/in/OIRReader.java index 447ae76aa70..cf175479402 100644 --- a/components/formats-gpl/src/loci/formats/in/OIRReader.java +++ b/components/formats-gpl/src/loci/formats/in/OIRReader.java @@ -92,6 +92,7 @@ public class OIRReader extends FormatReader { private transient Double zStart; private transient Double zStep; + private transient Double tStart; private transient Double tStep; private transient HashMap timestampAdjustments = new HashMap(); @@ -277,6 +278,7 @@ public void close(boolean fileOnly) throws IOException { minT = Integer.MAX_VALUE; zStart = null; zStep = null; + tStart = null; tStep = null; } } @@ -603,6 +605,9 @@ else if (!checkSuffix(id, "oir")) { for (int i=0; i= frame) { deltaT += (timestampAdjustments.get(frame) - tStep); @@ -1189,8 +1194,12 @@ private void parseImageProperties(Element root) throws FormatException { Element speed = getFirstChild(getFirstChild(scanner, "lsmimage:param"), "lsmparam:speed"); speed = getFirstChild(speed, "commonparam:speedInformation"); Element seriesInterval = getFirstChild(speed, "commonparam:seriesInterval"); - if (seriesInterval != null) { - tStep = DataTools.parseDouble(seriesInterval.getTextContent()); + + // prefer setting tStep from the TIMELAPSE axis, + // but fall back to this if needed + if (seriesInterval != null && tStep == null) { + // units are seconds, so multiply to get milliseconds + tStep = DataTools.parseDouble(seriesInterval.getTextContent()) * 1000; } } } @@ -1358,6 +1367,8 @@ private void parseAxis(Element dimensionAxis) { else if (name.equals("TIMELAPSE")) { if (m.sizeT <= 1) { m.sizeT = Integer.parseInt(size.getTextContent()); + tStart = DataTools.parseDouble(start.getTextContent()); + tStep = DataTools.parseDouble(step.getTextContent()); } } else if (name.equals("LAMBDA")) { From a0b60c99672bf67b85cb1bfa718166b54e07149d Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Wed, 11 Dec 2024 14:15:20 -0600 Subject: [PATCH 2/2] Fix time step units, and ignore 0 values --- .../formats-gpl/src/loci/formats/in/OIRReader.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/formats-gpl/src/loci/formats/in/OIRReader.java b/components/formats-gpl/src/loci/formats/in/OIRReader.java index cf175479402..cda84e60ab0 100644 --- a/components/formats-gpl/src/loci/formats/in/OIRReader.java +++ b/components/formats-gpl/src/loci/formats/in/OIRReader.java @@ -36,6 +36,7 @@ import java.util.Objects; import javax.xml.parsers.ParserConfigurationException; +import loci.common.Constants; import loci.common.DataTools; import loci.common.DateTools; import loci.common.Location; @@ -1198,8 +1199,8 @@ private void parseImageProperties(Element root) throws FormatException { // prefer setting tStep from the TIMELAPSE axis, // but fall back to this if needed if (seriesInterval != null && tStep == null) { - // units are seconds, so multiply to get milliseconds - tStep = DataTools.parseDouble(seriesInterval.getTextContent()) * 1000; + // units are expected to be milliseconds + tStep = DataTools.parseDouble(seriesInterval.getTextContent()); } } } @@ -1367,8 +1368,12 @@ private void parseAxis(Element dimensionAxis) { else if (name.equals("TIMELAPSE")) { if (m.sizeT <= 1) { m.sizeT = Integer.parseInt(size.getTextContent()); - tStart = DataTools.parseDouble(start.getTextContent()); - tStep = DataTools.parseDouble(step.getTextContent()); + // units are expected to be seconds, multiply to get milliseconds + tStart = DataTools.parseDouble(start.getTextContent()) * 1000; + double stepValue = DataTools.parseDouble(step.getTextContent()); + if (stepValue > Constants.EPSILON) { + tStep = stepValue * 1000; + } } } else if (name.equals("LAMBDA")) {