Skip to content

Commit

Permalink
Merge pull request micro-manager#99 from henrypinkard/main
Browse files Browse the repository at this point in the history
Clean up behavior related to non core-focus z drives
  • Loading branch information
henrypinkard authored Aug 3, 2023
2 parents 7f72301 + 8743601 commit 4ecfeef
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.micro-manager.acqengj</groupId>
<artifactId>AcqEngJ</artifactId>
<version>0.29.3</version>
<version>0.30.0</version>
<packaging>jar</packaging>
<name>AcqEngJ</name>
<description>Java-based Acquisition engine for Micro-Manager</description>
Expand Down
44 changes: 31 additions & 13 deletions src/main/java/org/micromanager/acqj/main/AcqEngMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class AcqEngMetadata {
public static final String X_UM_INTENDED = "XPosition_um_Intended";
public static final String Y_UM_INTENDED = "YPosition_um_Intended";
public static final String Z_UM_INTENDED = "ZPosition_um_Intended";
public static final String GENERIC_UM_INTENDED_SUFFIX = "Position_um_Intended";

public static final String X_UM = "XPosition_um";
public static final String Y_UM = "YPosition_um";
public static final String Z_UM = "ZPosition_um";
Expand Down Expand Up @@ -114,37 +116,44 @@ public static void addImageMetadata(JSONObject tags, AcquisitionEvent event,
//AcqEngMetadata.setZPositionUm(tags, Engine.getCore().getPosition());


//Axes (i.e. channel. z, t, or arbitray other indices)
//Axes (i.e. channel. z, t, or arbitrary other indices)
AcqEngMetadata.createAxes(tags);
////// Axes positions /////
for (String s : event.getDefinedAxes()) {
AcqEngMetadata.setAxisPosition(tags, s, event.getAxisPosition(s));
}


///////// XY Stage Positions (with optional support for grid layout) ////////
if (event.getXPosition() != null && event.getYPosition() != null) {
//infer Stage position index at acquisition time to support on the fly modification
// AcqEngMetadata.setPositionIndex(tags, event.acquisition_.getPositionIndexFromName(event.getXY()));
AcqEngMetadata.setStageXIntended(tags, event.getXPosition());
AcqEngMetadata.setStageYIntended(tags, event.getYPosition());

}
if (event.getPositionName() != null) {
AcqEngMetadata.setPositionName(tags, event.getPositionName());
}


if (event.getZPosition() != null) {
AcqEngMetadata.setStageZIntended(tags, event.getZPosition());
} else if (event.getStageSingleAxisStagePosition(Engine.getCore().getFocusDevice()) != null) {
AcqEngMetadata.setStageZIntended(tags, event.getStageSingleAxisStagePosition(Engine.getCore().getFocusDevice()));
}
if (event.getPositionName() != null) {
AcqEngMetadata.setPositionName(tags, event.getPositionName());
// Other non-coreFocusZ positions
for (String name : event.getStageDeviceNames()) {
if (!name.equals(Engine.getCore().getFocusDevice())) {
AcqEngMetadata.setStagePositionIntended(tags, name, event.getStageSingleAxisStagePosition(name));
}
}


if (event.getSequence() != null) {
//Dont add the event to image metadata if it is a sequence, because it could potentially be very large
// Could probably pop out the individual event in the squence this corresponds to
// Could probably pop out the individual event in the sequence this corresponds to
AcqEngMetadata.addAcquisitionEvent(tags, event);
}

////// Generic image coordinate axes //////
// Position and channel indices are inferred at acquisition time
//All other axes (including T and Z) must be explicitly defined in the
//acquisition event and get added here
for (String s : event.getDefinedAxes()) {
AcqEngMetadata.setAxisPosition(tags, s, event.getAxisPosition(s));
}

AcqEngMetadata.setExposure(tags, exposure);

Expand Down Expand Up @@ -841,6 +850,15 @@ public static double getStageZIntended(JSONObject smd) {
}
}

public static void setStagePositionIntended(JSONObject tags,
String name, Double stageSingleAxisStagePosition) {
try {
tags.put(name + GENERIC_UM_INTENDED_SUFFIX, stageSingleAxisStagePosition);
} catch (JSONException ex) {
throw new RuntimeException("Couldnt set stage y");
}
}

public static void setStageX(JSONObject smd, double x) {
try {
smd.put(X_UM, x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ public void setStageCoordinate(String deviceName, double v, String axisName) {


public Double getStageSingleAxisStagePosition(String deviceName) {
if (deviceName == null) {
return null;
}
if (!stageCoordinates_.containsKey(deviceName)) {
return null;
}
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/org/micromanager/acqj/util/AcqEventModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,19 @@ public AcquisitionEvent next() {
channelEvent.setChannelName(channelList.get(index).config_);
boolean hasZOffsets = channelList.stream().map(t -> t.offset_).
filter(t -> t != 0).collect(Collectors.toList()).size() > 0;
Double zPos;
if (channelEvent.getZPosition() == null) {
Double zPos = null;
if (channelEvent.getZPosition() != null) {
zPos = channelEvent.getZPosition();
}
if (channelEvent.getStageSingleAxisStagePosition(Engine.getCore().getFocusDevice()) != null) {
if (zPos != null) {
throw new RuntimeException("Can't have both a z position and a named axis focus position");
} else {
zPos = channelEvent.getStageSingleAxisStagePosition(Engine.getCore().getFocusDevice());
}
}

if (zPos == null) {
if (hasZOffsets) {
try {
zPos = Engine.getCore().getPosition() + channelList.get(index).offset_;
Expand All @@ -146,20 +157,17 @@ public AcquisitionEvent next() {
zPos = null;
}
} else {
zPos = channelEvent.getZPosition() + channelList.get(index).offset_;
zPos += hasZOffsets ? channelList.get(index).offset_ : 0;
}
channelEvent.setZ(channelEvent.getZIndex(), zPos);

// try {
// channelEvent.setZ(channelEvent.getZIndex(),
// channelEvent.getZPosition() == null ?
// hasZOffsets ?
// Engine.getCore().getPosition() + channelList.get(index).offset_ : null
// : channelEvent.getZPosition() + channelList.get(index).offset_
// );
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
if (zPos != null) {
// Its either stored as a named stage or as "z", keep it con
if (channelEvent.getStageSingleAxisStagePosition(Engine.getCore().getFocusDevice()) != null) {
channelEvent.setStageCoordinate(Engine.getCore().getFocusDevice(), zPos);
} else {
channelEvent.setZ(channelEvent.getZIndex(), zPos);
}
}

channelEvent.setExposure(channelList.get(index).exposure_);
index++;
return channelEvent;
Expand Down

0 comments on commit 4ecfeef

Please sign in to comment.