Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
software:micro-manager [2019/07/03 03:58]
Jon Daniels [Scripting the plugin]
software:micro-manager [2024/04/15 23:19] (current)
Jon Daniels [Micro-manager diSPIM Plugin]
Line 5: Line 5:
 Details about the plugin operation can be found in the manual section of this website in the [[:docs:mm_dispim_plugin_user_guide|Micro-manager diSPIM Plugin User Guide]].  **Please see that manual for information about using the plugin.**  There is also a brief overview is on [[https://micro-manager.org/wiki/ASIdiSPIM_Plugin|its Micro-manager wiki page]]. Details about the plugin operation can be found in the manual section of this website in the [[:docs:mm_dispim_plugin_user_guide|Micro-manager diSPIM Plugin User Guide]].  **Please see that manual for information about using the plugin.**  There is also a brief overview is on [[https://micro-manager.org/wiki/ASIdiSPIM_Plugin|its Micro-manager wiki page]].
  
-Currently the diSPIM plugin is supported in 1.4.x only, although there have been some efforts to port it to 2.0.  At some point after the official release of Micro-manager 2.0development on the 1.4.x plugin will slow and eventually stop and at that point only 2.0 will be supported.  But that's all in the future as of early 2019 since 2.0 hasn't been released yet.+Currently the diSPIM plugin is supported in 1.4.x only.  In 2023 there have been efforts to create a new plugin in Micro-Manager 2.0 called [[https://github.com/micro-manager/LightSheetManager|LightSheetManager]] that will operate the diSPIM as well as other types of light sheet microscopes.  Contributions to the effort of making this new plugin are appreciated As of August 2023 this is in alpha testing by the first few bleeding edge adopters, and we expect that by end of 2023 it will be ready for more adopters and a full replacement in 2024.
  
-You can download the nightly builds of Micro-manager 1.4 for Windows [[http://valelab4.ucsf.edu/~MM/nightlyBuilds/1.4/Windows/|here]]; the date is encoded in the file name and the latest date is at the top of the page.  Make sure to get the appropriate 32bit or 64bit depending on your computer.+You can download the nightly builds of Micro-manager 1.4 for Windows [[https://download.micro-manager.org/nightly/1.4/Windows/|here]]; the date is encoded in the file name and the latest date is at the top of the page.  Make sure to get the appropriate 32bit or 64bit depending on your computer.
  
  
Line 66: Line 66:
 The first step is to check and see if your problem has already been fixed by using a recent nightly build of Micro-Manager ([[http://valelab.ucsf.edu/~MM/nightlyBuilds/1.4/Windows/|Windows]] and [[http://valelab.ucsf.edu/~MM/nightlyBuilds/1.4/Mac/|Mac]]). If your firmware is very old it wouldn't hurt to update it; instructions and firmware files are on this wiki filed under [[:hardware:controller#firmware | hardware > controller > firmware]]. The first step is to check and see if your problem has already been fixed by using a recent nightly build of Micro-Manager ([[http://valelab.ucsf.edu/~MM/nightlyBuilds/1.4/Windows/|Windows]] and [[http://valelab.ucsf.edu/~MM/nightlyBuilds/1.4/Mac/|Mac]]). If your firmware is very old it wouldn't hurt to update it; instructions and firmware files are on this wiki filed under [[:hardware:controller#firmware | hardware > controller > firmware]].
  
-If the bug still happens, is helpful to generate a problem report using "Help" -> "Report Problem..." in the main Micro-Manager window. It will prompt you to reproduce the problem, for example if you are having a problem during diSPIM acquisition then run an acquisition and verify that the bug is manifest.  After clicking "Done" do not submit the report the usual way, instead click "View Report", save the text as a file, and then email that file directly to the plugin developers.  If you cannot reproduce the problem in order to generate a bug report, then an alternative is to enable debug logging in "Tools" -> "Options..." and then when the problem happens send the developers the core log file being written to at the time (find the logs in the Core Logs directory located inside the Micro-manager install directory, e.g. C:/Program Files/Micro-Manager-1.4/Core Logs and then log files named by the launch time).+If the bug still happens, is helpful to generate a problem report using "Help" -> "Report Problem..." in the main Micro-Manager window. It will prompt you to reproduce the problem, for example if you are having a problem during diSPIM acquisition then run an acquisition and verify that the bug is manifest.  After clicking "Done" do not submit the report the usual way, instead click "View Report", save the text as a file, and then email that file directly to the plugin developers. 
 + 
 +If you cannot reproduce the problem in order to generate a bug report, then an alternative is to enable debug logging in "Tools" -> "Options..." and then when the problem happens send the developers the core log file being written to at the time (find the logs in the Core Logs directory located inside the Micro-manager install directory, e.g. C:/Program Files/Micro-Manager-1.4/Core Logs and then log files named by the launch time), also noting the time that the error occurred.  Because the problem report file contains extra information, if it is possible to replicate the error on demand then it is better to use the problem report method.
  
 You can see recent changes to the plugin code by [[https://valelab.ucsf.edu/trac/micromanager/search?q=asidispim | searching the Micro-manager code timeline for ASIdiSPIM]].  Sometimes changes to the ASI Tiger device adapter also affect the plugin operation ([[https://valelab.ucsf.edu/trac/micromanager/search?q=asitiger | Micro-manager code timeline for ASITiger]]). You can see recent changes to the plugin code by [[https://valelab.ucsf.edu/trac/micromanager/search?q=asidispim | searching the Micro-manager code timeline for ASIdiSPIM]].  Sometimes changes to the ASI Tiger device adapter also affect the plugin operation ([[https://valelab.ucsf.edu/trac/micromanager/search?q=asitiger | Micro-manager code timeline for ASITiger]]).
Line 72: Line 74:
 ==== Launching the plugin on startup ==== ==== Launching the plugin on startup ====
  
-Add the following lines to your MMStartup.bsh script (or create the file if it doesn't exist).  The startup script lives in the root MM folder (e.g. C:\Program Files\Micro-Manager-1.4) and is automatically executed when Micro-Manager launches.+Add the following lines to your MMStartup.bsh script (or create the file if it doesn't exist).  The startup script lives in the root MM folder (e.g. C:\Program Files\Micro-Manager-1.4) and is automatically executed when Micro-Manager launches (unless set otherwise in Tools->Options).
  
-<code>+<code java>
 import org.micromanager.asidispim.ASIdiSPIM; import org.micromanager.asidispim.ASIdiSPIM;
-ASIdiSPIM plugin = new ASIdiSPIM(); +import org.micromanager.asidispim.Utils.MyDialogUtils; 
-plugin.setApp(gui);+ 
 +// the if statement and closing brace can be removed if you want the plugin to always load regardless 
 +if (MyDialogUtils.getConfirmDialogResult("Do you want to load the ASIdiSPIM plugin and initialize?", JOptionPane.YES_NO_OPTION) ) { 
 +  ASIdiSPIM plugin = new ASIdiSPIM(); 
 +  plugin.setApp(gui); 
 +}
 </code> </code>
  
 ==== Scripting the plugin ==== ==== Scripting the plugin ====
  
-The Micro-Manager plugin has an API that allows most of its functionality to be accessed via Beanshell scripts run from within Micro-Manager.  This allows users to orchestrate complex acquisitions and even use the plugin for adaptive microscopy where automated image analysis guides acquisition.  The best way to see what functionality is exposed via the API is to look at the [[https://valelab4.ucsf.edu/trac/micromanager/browser/plugins/ASIdiSPIM/src/org/micromanager/asidispim/api/ASIdiSPIMInterface.java|source code of the Java interface]] which defines the API.  The API includes are methods to get and set the most commonly changed settings within the plugin, launch acquisitions, move the microscope, and more.  The API can be augmented if needed but every effort is made not to change the documented functionality.  Furthermore there is support for Java RMI which allows the plugin API to be access from a completely separate Java VM.+The Micro-Manager plugin has an API that allows most of its functionality to be accessed via Beanshell scripts run from within Micro-Manager.  This allows users to orchestrate complex acquisitions and even use the plugin for adaptive microscopy where automated image analysis guides acquisition.  The best way to see what functionality is exposed via the API is to look at the [[https://github.com/micro-manager/micro-manager/blob/mm1/plugins/ASIdiSPIM/src/org/micromanager/asidispim/api/ASIdiSPIMInterface.java|source code of the Java interface]] which defines the API.  The API includes are methods to get and set the most commonly changed settings within the plugin, launch acquisitions, move the microscope, and more.  The API can be augmented if needed but every effort is made not to change the documented functionality.  Furthermore there is support for Java RMI which allows the plugin API to be access from a completely separate Java VM.
  
 Here is a bare-bones example script: Here is a bare-bones example script:
  
-<code>+<code java>
 // required imports // required imports
 import org.micromanager.asidispim.api.ASIdiSPIMInterface; import org.micromanager.asidispim.api.ASIdiSPIMInterface;
Line 103: Line 110:
 Here are some example scripts: Here are some example scripts:
  
-<code>+<code java>
 // This script changes channels in the middle of a multi-timepoint acquistion.  It actually runs two separate acquisitions and changes the channel between them. // This script changes channels in the middle of a multi-timepoint acquistion.  It actually runs two separate acquisitions and changes the channel between them.
  
Line 148: Line 155:
  
  
-<code>+<code java>
 // This script runs a multi-timepoint acquisition at multiple positions, collecting all time points at a single position // This script runs a multi-timepoint acquisition at multiple positions, collecting all time points at a single position
 // before moving to the next position (reversing the time/position order usual in the plugin). // before moving to the next position (reversing the time/position order usual in the plugin).
Line 191: Line 198:
  
  
 +<code java>
 +// This script runs a "manual" multiple position acquisitions to save each position
 +// in a separate acquisition on disk.
  
-As of July 2019 limited support for runnables has been added to the plugin.  Currently there are times when runnables can be inserted:+// required imports 
 +import org.micromanager.asidispim.api.*; 
 +import org.micromanager.api.PositionList; 
 +import org.micromanager.api.MultiStagePosition; 
 +import org.micromanager.asidispim.utils.MyDialogUtils; 
 +import java.text.DecimalFormat; 
 + 
 +// get reference to plugin (requires plugin to be open) 
 +ASIdiSPIMInterface diSPIM = new ASIdiSPIMImplementation(); 
 + 
 +// get MM's position list (should have positions set there already before running script) 
 +PositionList pl = gui.getPositionList(); 
 +int numPositions = pl.getNumberOfPositions(); 
 + 
 +// make sure plugin is set _not_ to use positions after caching old value 
 +boolean multiXY = diSPIM.getMultiplePositionsEnabled(); 
 +diSPIM.setMultiplePositionsEnabled(false); 
 + 
 +// get value of post-move delay from plugin 
 +double postMoveDelayMs = diSPIM.getMultiplePositionsDelay(); 
 + 
 +// save original name prefix for file saving 
 +String basePrefix = diSPIM.getSavingNamePrefix(); 
 + 
 +// set up formatting with leading 0s 
 +DecimalFormat df = new DecimalFormat("000"); 
 + 
 +// setup for closing finished acquisition windows 
 +// instead of leaving every window open want to close when done 
 +// found that call to closeAcquisitionWindow() can come before writing is finished and cause problems 
 +// so let there be 2 open windows but prevent opening more 
 +String lastAcqName = ""; 
 +String lastLastAcqName = ""; 
 + 
 + 
 +// loop over all positions in position list 
 +try { 
 + for(int i=1; i<=numPositions; ++i) { 
 + MultiStagePosition.goToPosition(pl.getPosition(i-1), mmc);  // move the the next position, this blocks until stage arrives 
 + Thread.sleep(Math.round(postMoveDelayMs));   // pause for the requested amount 
 + diSPIM.setSavingNamePrefix(basePrefix + "_Pos" + df.format(i)); 
 + try { 
 + diSPIM.closeAcquisitionWindow(lastLastAcqName); 
 + } catch (Exception ex) { 
 + // do nothing 
 +
 + diSPIM.runAcquisitionBlocking()  ;  // launch the acquisition with current settings, will block until done 
 + lastLastAcqName = lastAcqName; 
 + lastAcqName = diSPIM.getLastAcquisitionName(); 
 +
 +} catch (Exception ex) { 
 + MyDialogUtils.showError(ex, "error in manual positions"); 
 +} finally { 
 + // restore prefix and multi-XY value 
 + diSPIM.setSavingNamePrefix(basePrefix); 
 + diSPIM.setMultiplePositionsEnabled(multiXY); 
 +
 +</code> 
 + 
 + 
 +<code java> 
 + 
 +// This script runs a "manual" multiple position, multiple channel acquisitions 
 +// to save each position in a separate file on disk. 
 +// Positions are the "outer loop", channels are the "inner loop" 
 +// Channels are not necessarily in the order specified in the plugin but should be the same order every time. 
 +// User should put the plugin "Change channel" setting to "Every volume" (currently no API method for that). 
 + 
 + 
 +// required imports 
 +import org.micromanager.asidispim.api.*; 
 +import org.micromanager.api.PositionList; 
 +import org.micromanager.api.MultiStagePosition; 
 +import org.micromanager.asidispim.utils.MyDialogUtils; 
 +import java.text.DecimalFormat; 
 + 
 +// get reference to plugin (requires plugin to be open) 
 +ASIdiSPIMInterface diSPIM = new ASIdiSPIMImplementation(); 
 + 
 +// get MM's position list (should have positions set there already before running script) 
 +PositionList pl = gui.getPositionList(); 
 +int numPositions = pl.getNumberOfPositions(); 
 + 
 +// make sure plugin is set _not_ to use positions after caching old value 
 +boolean multiXY = diSPIM.getMultiplePositionsEnabled(); 
 +diSPIM.setMultiplePositionsEnabled(false); 
 + 
 +// get value of post-move delay from plugin 
 +double postMoveDelayMs = diSPIM.getMultiplePositionsDelay(); 
 + 
 +// save original name prefix for file saving 
 +String basePrefix = diSPIM.getSavingNamePrefix(); 
 + 
 +// set up formatting with leading 0s 
 +DecimalFormat df = new DecimalFormat("000"); 
 + 
 +// setup for closing finished acquisition windows 
 +// instead of leaving every window open want to close when done 
 +// found that call to closeAcquisitionWindow() can come before writing is finished and cause problems 
 +// so let there be 2 open windows but prevent opening more 
 +String lastAcqName = ""; 
 +String lastLastAcqName = ""; 
 + 
 +// figure out which channels we are using 
 +boolean channelsEnabled = diSPIM.getChannelsEnabled(); 
 +String [] allChannels = diSPIM.getAvailableChannels(); 
 + 
 +try { 
 + // loop over all positions in position list 
 + for( int i=1; i<=numPositions; ++i ) { 
 + MultiStagePosition.goToPosition(pl.getPosition(i-1), mmc);  // move the the next position, this blocks until stage arrives 
 + Thread.sleep(Math.round(postMoveDelayMs));   // pause for the requested amount 
 + 
 + for( s : allChannels) { 
 + if (!diSPIM.getChannelEnabled(s)) 
 + continue; 
 + diSPIM.setSavingNamePrefix(basePrefix + "_Ch" + s + "_Pos" + df.format(i)); 
 + try { 
 + diSPIM.closeAcquisitionWindow(lastLastAcqName); 
 + } catch (Exception ex) { 
 + // do nothing 
 +
 + diSPIM.runAcquisitionBlocking()  ;  // launch the acquisition with current settings, will block until done 
 + lastLastAcqName = lastAcqName; 
 + lastAcqName = diSPIM.getLastAcquisitionName(); 
 +
 +
 +} catch (Exception ex) { 
 + MyDialogUtils.showError(ex, "error in manual positions"); 
 +} finally { 
 + // restore prefix and multi-XY value 
 + diSPIM.setSavingNamePrefix(basePrefix); 
 + diSPIM.setMultiplePositionsEnabled(multiXY); 
 + diSPIM.setChannelsEnabled(channelsEnabled); 
 +
 + 
 +</code> 
 + 
 + 
 +==== Runnables in the plugin ==== 
 + 
 +Support for "runnables" was added to the plugin early July 2019 and extended November 2019.  A runnable is a snippet of user-specified code that is executed at a pre-defined sequence during the overall acquisition.  Runnables generally should not be used when exact timing matters because their exact execution time will be controlled by Micro-Manager and subject to the whims of the host computer and not done with exactly predictable timing (if you need exact timing, you can use the Tiger controller's flexible Programmable Logic Card (PLC) to implement). 
 + 
 +These runnables are normally defined in a Beanshell script executed from Micro-Manager's script window and "attached" to the plugin after the plugin has been invoked.  See the below example. 
 + 
 +Currently there are six times when runnables can be inserted: 
 +  - Start of acquisition 
 +  - End of acquisition
   - Start of timepoint   - Start of timepoint
   - End of timepoint   - End of timepoint
Line 198: Line 355:
   - End of position   - End of position
  
-Note that these would be called only once each for an acquisition without timepoints nor positions selected.  Recall that timepoints is always the "outer loop" relative to positions.+Note that these would be called only once each for an acquisition without timepoints nor positions selected.  Recall that timepoints is always the "outer loop" relative to positions using the plugin (but to interchange the order you can write a script that uses positions as the outer loop).  The start/end acquisition runnables are only executed once even when the "separate viewer / file" option is enabled in the data saving settings.
  
-Here is an example adding a runnable to each of these possible invocation points:+Here is an example adding a runnable to each of these possible invocation points.  Note the use of global variables in the script so that state can be passed between runnables, as well as local variables within a runnable that cannot be changed by another runnable (e.g. reset at the start of the acquisition).
  
-<code>+<code java>
 // required imports // required imports
 import org.micromanager.asidispim.api.*; import org.micromanager.asidispim.api.*;
Line 211: Line 368:
 // note that the plugin must be launched for this to work // note that the plugin must be launched for this to work
 ASIdiSPIMInterface diSPIM = new ASIdiSPIMImplementation(); ASIdiSPIMInterface diSPIM = new ASIdiSPIMImplementation();
 +int runnableTimepointCounter;
 +int runnablePositionCounter;
 +
 +taskStartAcquisition = new Runnable() {
 + public void run() {
 + // test code which will raise dialog; should be replaced
 + gui.showError("started overall acquisition");
 + runnableTimepointCounter = 0;
 + runnablePositionCounter = 0;
 + }
 +};
 +
 +taskEndAcquisition = new Runnable() {
 + public void run() {
 + // test code which will raise dialog; should be replaced
 + gui.showError("ended entire acquisition");
 + }
 +};
 +
  
 taskStartPosition = new Runnable() { taskStartPosition = new Runnable() {
  public void run() {  public void run() {
 + runnablePositionCounter++;
  // test code which will raise dialog; should be replaced  // test code which will raise dialog; should be replaced
- gui.showError("started position");+ gui.showError("started position " + runnablePositionCounter);
  }  }
 }; };
  
 taskEndPosition = new Runnable() { taskEndPosition = new Runnable() {
 + int localCounter = 0;
  public void run() {  public void run() {
 + localCounter++;
  // test code which will raise dialog; should be replaced  // test code which will raise dialog; should be replaced
- gui.showError("ended position");+ gui.showError("ended position, which is call number " + localCounter + " to this runnable");
  }  }
 }; };
Line 228: Line 407:
 taskStartTimepoint = new Runnable() { taskStartTimepoint = new Runnable() {
  public void run() {  public void run() {
 + runnablePositionCounter = 0;
 + runnableTimepointCounter++;
  // test code which will raise dialog; should be replaced  // test code which will raise dialog; should be replaced
- gui.showError("started timepoint");+ gui.showError("started timepoint " + runnableTimepointCounter );
  }  }
 }; };
  
 taskEndTimepoint = new Runnable() { taskEndTimepoint = new Runnable() {
 + int localCounter = 0;
  public void run() {  public void run() {
 + localCounter++;
  // test code which will raise dialog; should be replaced  // test code which will raise dialog; should be replaced
- gui.showError("ended timepoint");+ gui.showError("ended timepoint, which is call number " + localCounter + " to this runnable");
  }  }
 }; };
Line 242: Line 425:
 // add all run // add all run
 diSPIM.clearAllRunnables(); diSPIM.clearAllRunnables();
 +diSPIM.attachRunnable(taskStartAcquisition, RunnableType.ACQUISITION_START);
 +diSPIM.attachRunnable(taskEndAcquisition, RunnableType.ACQUISITION_END);
 diSPIM.attachRunnable(taskStartPosition, RunnableType.POSITION_START); diSPIM.attachRunnable(taskStartPosition, RunnableType.POSITION_START);
 diSPIM.attachRunnable(taskEndPosition, RunnableType.POSITION_END); diSPIM.attachRunnable(taskEndPosition, RunnableType.POSITION_END);
 diSPIM.attachRunnable(taskStartTimepoint, RunnableType.TIMEPOINT_START); diSPIM.attachRunnable(taskStartTimepoint, RunnableType.TIMEPOINT_START);
 diSPIM.attachRunnable(taskEndTimepoint, RunnableType.TIMEPOINT_END); diSPIM.attachRunnable(taskEndTimepoint, RunnableType.TIMEPOINT_END);
- 
-diSPIM.runAcquisition(); 
- 
  
 </code> </code>