Skip to content

Commit

Permalink
MarsMicromanager support metadata.txt only reading
Browse files Browse the repository at this point in the history
When populating metadata directly using only the metadata.txt file and images can not be located there is an NPE. This begins to address this issue.
  • Loading branch information
karlduderstadt committed Nov 2, 2023
1 parent 9546589 commit 2688b26
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,11 @@ else if (key.equals("Time")) {
else if (key.equals("Comment")) {
p.comment = value;
}
else if (key.equals("FileName")) {
else if (key.equals("FileName") && metadataFile != null) {
final Location file = metadataFile.sibling(value);
p.locationMap.put(new Index(slice), file);
if (p.baseTiff == null) {
p.baseTiff = file;
System.out.println("p.baseTiff " + p.baseTiff);
}
}
else if (key.equals("Width")) {
Expand Down Expand Up @@ -764,7 +763,7 @@ else if (key.equals(p.cameraRef + "-Exposure")) {
else if (key.startsWith("DAC-") && key.endsWith("-Volts")) {
p.voltage.add(new Double(value));
}
else if (key.equals("FileName")) {
else if (key.equals("FileName") && metadataFile != null) {
final Location file = metadataFile.sibling(value);
p.locationMap.put(new Index(slice), file);
if (p.baseTiff == null) {
Expand All @@ -782,15 +781,15 @@ else if (key.equals("FileName")) {

p.timestamps = stamps.toArray(new Double[stamps.size()]);
Arrays.sort(p.timestamps);
ms.setName(p.metadataFile.parent().parent().getName() + " (Pos" + p.positionIndex + ")");

ms.setName(ms.getName() + " (Pos" + p.positionIndex + ")");

// look for the optional companion XML file

p.xmlFile = p.metadataFile.sibling(XML);
if (dataHandleService.exists(p.xmlFile)) {
parseXMLFile(meta, posIndex);
}
//p.xmlFile = p.metadataFile.sibling(XML);
//if (dataHandleService.exists(p.xmlFile)) {
// parseXMLFile(meta, posIndex);
//}
}

private void parsePositionMV2(final String jsonData, final Metadata meta,
Expand Down Expand Up @@ -882,7 +881,7 @@ else if (key.equals("Time")) {
else if (key.equals("Comment")) {
p.comment = value;
}
else if (key.equals("FileName")) {
else if (key.equals("FileName") && metadataFile != null) {
final Location file = metadataFile.sibling(value);
p.locationMap.put(new Index(slice), file);
if (p.baseTiff == null) {
Expand Down Expand Up @@ -1084,7 +1083,7 @@ else if (key.equals("ElapsedTime-ms")) {
final double t = Double.parseDouble(value);
stamps.add(new Double(t / 1000));
}
else if (key.equals("FileName")) {
else if (key.equals("FileName") && metadataFile != null) {
final Location file = metadataFile.sibling(value);
p.locationMap.put(new Index(slice), file);
if (p.baseTiff == null) {
Expand Down Expand Up @@ -1118,7 +1117,6 @@ else if (key.equals("UUID") && p.UUID == null) {
ms.setName(ms.getName() + " (Pos" + p.positionIndex + ")");

// look for the optional companion XML file

//p.xmlFile = p.metadataFile.sibling(XML);
//if (dataHandleService.exists(p.xmlFile)) {
// parseXMLFile(meta, posIndex);
Expand Down Expand Up @@ -1487,6 +1485,7 @@ public Location getLocation(final Metadata meta, final int imageIndex,
}
}
}
if (tiffs == null) return null;
return locationMap.size() == 0 ? tiffs.get((int) planeIndex) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,36 @@ private void populateMetadata(final Metadata meta,
store.setPlaneExposureTime(new Time(p.exposureTime, UNITS.SECOND), i,
q);

final Location tiff = positions.get(i).getLocation(meta, i, q);

//Check if the tiff file exists. If a sparse collection was performed some planes
//may not have been collected. In that case, add empty placeholder plane data
if (tiff != null && dataHandleService.exists(tiff))
{
boolean fullPlane = true;
if (positions.get(i).tiffs != null) {
//Check if the tiff file exists. If a sparse collection was performed some planes
//may not have been collected. In that case, add empty placeholder plane data
final Location tiff = positions.get(i).getLocation(meta, i, q);
if (tiff != null && dataHandleService.exists(tiff)) fullPlane = true;
else fullPlane = false;
}
//If tiffs is null, there was no access to the original files when processing the metadata.txt
//In this case, full plane information is included for all possible planes.

ArrayList<MapPair> planeParameterList = new ArrayList<MapPair>();
if (fullPlane) {
if (nextStamp < p.timestamps.length)
store.setPlaneDeltaT(new Time(p.timestamps[nextStamp++],
UNITS.SECOND), i, q);

store.setPlaneTheC(p.getTheC(meta, i, q), i, q);
store.setPlaneTheZ(p.getTheZ(meta, i, q), i, q);
store.setPlaneTheT(p.getTheT(meta, i, q), i, q);

Map<String, String> planeMetaTable = p.getPlaneMap(meta, i, q);

ArrayList<MapPair> planeParameterList = new ArrayList<MapPair>();
for (String planeParameterKey : planeMetaTable.keySet())
planeParameterList.add(new MapPair(planeParameterKey, planeMetaTable.get(planeParameterKey)));

store.setMapAnnotationValue(planeParameterList, q);
store.setMapAnnotationID("MPlane-" + i + "-" + q, q);
store.setPlaneAnnotationRef("MPlane-" + i + "-" + q, i, q, 0);
} else {
ArrayList<MapPair> planeParameterList = new ArrayList<MapPair>();

store.setMapAnnotationValue(planeParameterList, q);
store.setMapAnnotationID("MPlane-" + i + "-" + q, q);
store.setPlaneAnnotationRef("MPlane-" + i + "-" + q, i, q, 0);

for (String planeParameterKey : planeMetaTable.keySet())
planeParameterList.add(new MapPair(planeParameterKey, planeMetaTable.get(planeParameterKey)));
}

store.setMapAnnotationValue(planeParameterList, q);
store.setMapAnnotationID("MPlane-" + i + "-" + q, q);
store.setPlaneAnnotationRef("MPlane-" + i + "-" + q, i, q, 0);
}

final String serialNumber = p.detectorID;
Expand Down

0 comments on commit 2688b26

Please sign in to comment.