Skip to content

Commit

Permalink
Don't set Plane metadata until we know the final plane counts
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Nov 11, 2024
1 parent 5a00e83 commit 676dfe6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
16 changes: 12 additions & 4 deletions components/formats-gpl/src/loci/formats/in/LeicaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public class LeicaHandler extends BaseHandler {
private MetadataLevel level;
private int laserCount = 0;

private Map<String, Time> exposureTimes = new HashMap<String, Time>();
private Map<String, Time> deltaT = new HashMap<String, Time>();

// -- Constructor --

public LeicaHandler(MetadataStore store, MetadataLevel level) {
Expand All @@ -144,6 +147,10 @@ public LeicaHandler(MetadataStore store, MetadataLevel level) {

public Vector<String> getLutNames() { return lutNames; }

public Map<String, Time> getExposureTimes() { return exposureTimes; }

public Map<String, Time> getDeltaT() { return deltaT; }

// -- DefaultHandler API methods --

@Override
Expand Down Expand Up @@ -549,7 +556,7 @@ else if (id.indexOf("WFC") == 1) {
try {
Double exposureTime = DataTools.parseDouble(value);
if (exposureTime != null) {
store.setPlaneExposureTime(new Time(exposureTime, UNITS.SECOND), numDatasets, c);
exposureTimes.put(numDatasets + "-" + c, new Time(exposureTime, UNITS.SECOND));
}
}
catch (IndexOutOfBoundsException e) { }
Expand Down Expand Up @@ -878,14 +885,14 @@ else if (qName.equals("TimeStamp") && numDatasets >= 0) {
store.setImageAcquisitionDate(new Timestamp(date), numDatasets);
}
firstStamp = ms;
store.setPlaneDeltaT(new Time(0.0, UNITS.SECOND), numDatasets, count);
deltaT.put(numDatasets + "-" + count, new Time(0.0, UNITS.SECOND));
}
else if (level != MetadataLevel.MINIMUM) {
CoreMetadata coreMeta = core.get(numDatasets);
int nImages = coreMeta.sizeZ * coreMeta.sizeT * coreMeta.sizeC;
if (count < nImages) {
ms -= firstStamp;
store.setPlaneDeltaT(new Time(ms / 1000.0, UNITS.SECOND), numDatasets, count);
deltaT.put(numDatasets + "-" + count, new Time(ms / 1000.0, UNITS.SECOND));
}
}

Expand All @@ -897,7 +904,8 @@ else if (qName.equals("RelTimeStamp") && level != MetadataLevel.MINIMUM) {
if (count < nImages) {
Double time = DataTools.parseDouble(attributes.getValue("Time"));
if (time != null) {
store.setPlaneDeltaT(new Time(time, UNITS.SECOND), numDatasets, count++);
deltaT.put(numDatasets + "-" + count, new Time(time, UNITS.SECOND));
count++;
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions components/formats-gpl/src/loci/formats/in/TCSReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import loci.common.DataTools;
import loci.common.DateTools;
Expand All @@ -49,6 +50,7 @@
import loci.formats.tiff.TiffParser;

import ome.units.quantity.Length;
import ome.units.quantity.Time;

/**
* TCSReader is the file format reader for Leica TCS TIFF files and their
Expand Down Expand Up @@ -465,6 +467,8 @@ else if (getSizeT() == 1) {
else ms0.sizeZ *= ifds.size();
}

Map<String, Time> exposureTime = null;
Map<String, Time> deltaT = null;
if (xmlFile != null) {
// parse XML metadata

Expand All @@ -474,6 +478,8 @@ else if (getSizeT() == 1) {
LeicaHandler handler =
new LeicaHandler(store, getMetadataOptions().getMetadataLevel());
XMLTools.parseXML(xml, handler);
exposureTime = handler.getExposureTimes();
deltaT = handler.getDeltaT();

metadata = handler.getGlobalMetadata();
MetadataTools.merge(handler.getGlobalMetadata(), metadata, "");
Expand Down Expand Up @@ -509,6 +515,20 @@ else if (getSizeT() == 1) {
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, 0);
}

for (int s=0; s<getSeriesCount(); s++) {
setSeries(s);
for (int i=0; i<getImageCount(); i++) {
String key = s + "-" + i;
if (exposureTime != null && exposureTime.containsKey(key)) {
store.setPlaneExposureTime(exposureTime.get(key), s, i);
}
if (deltaT != null && deltaT.containsKey(key)) {
store.setPlaneDeltaT(deltaT.get(key), s, i);
}
}
}
setSeries(0);
}

// -- Helper methods --
Expand Down

0 comments on commit 676dfe6

Please sign in to comment.