Control the time interval in a grid between different positions

I have two questions.

  1. I need to control time interval between the positions in a grid. I mean that I need to take an image in position 1, and then wait for 2 min and then go to the 2nd position, take data, and then come back to position 1 after 10 min.
    right now, I can just control time interval between first and the second cycle for the whole grid. is it possible to also control the other timing between pos1 and pos2?

  2. my second question is that can I write a MATLAB code and integrate it with Micro Manager as a channel?

thanks a bunch for your help.

Using pycro-manager Acquisitions, you can write a custom sequence of acquisition events that would accomplish this

Not matlab, but if your code can run in python you can do this with image processors. However, you will need to reconvert back into uint16 or uint8 to use with the default image viewer, as it is incompatible with floating point.

thanks Henry,
would you please more specific about the pycro-manager Acquisition? I am a little confused about using it in the micro manager.

I think if you have a look at the documentation it will make more sense. Happy to answer more specific questions after you’ve looked there

Sure thanks. I started reading the documentation. there is a code to “verify that installation worked” that I should run. Should I run it as a script under the tool tab in micromanager?

No you need to run it from a python environment (terminal, IDE, jupyter notebook etc)

As for the first question, there are straight forward ways to do this with small scripts in Micro-Manager. You can “attach a Runnable” to the acquisition, that instructs it wait for a certain amount of time after each position, see: AcquisitionManager.

There is a scripting introduction with an attachRunnable example at the end.

Thanks @henrypinkard .Does it also work with micro manager 1.4? I need to work with a device that works with micro manager 1.4.
I did install jupyter lab and then used “pip install pycromanager”. I got this error:

Exception Traceback (most recent call last)
in
1 from pycromanager import Bridge
2
----> 3 bridge = Bridge()
4 print(bridge.get_core())

~\anaconda3\lib\site-packages\pycromanager\core.py in init(self, port, convert_camel_case, debug, ip_address)
234 self._master_socket.send({“command”: “connect”, “debug”: debug})
235 self._class_factory = _JavaClassFactory()
→ 236 reply_json = self._master_socket.receive(timeout=500)
237 if reply_json is None:
238 raise TimeoutError(

~\anaconda3\lib\site-packages\pycromanager\core.py in receive(self, timeout)
174 if self._debug:
175 print(“DEBUG, recieved: {}”.format(message))
→ 176 self._check_exception(message)
177 return message
178

~\anaconda3\lib\site-packages\pycromanager\core.py in _check_exception(self, response)
179 def _check_exception(self, response):
180 if “type” in response and response[“type”] == “exception”:
→ 181 raise Exception(response[“value”])
182
183 def close(self):

Exception: JSONObject[“server”] not found.

Thanks @nicost . I copied the example at in the scipt section and I got this error:
Line 1: general error : mm .acquisitions ( )
Is it because of the fact that I’m using micro manager1.4?

when I try micro manager 2, the script didn’t work (no error, but didn’t do my desired goal). Would you please take a look at my script?
(My goal is taking data from position 1, wait for 2 sec, move to position 2 wait and so on)
runnable = new Runnable() {
int count = 0;
public void run() {
settings = mm.acquisitions().getAcquisitionSettings();
// poritions = settings.positions;
pl = mm.positions().getPositionList();
msp = pl.getPosition(count);
msp.goToPosition(msp, mmc);
// position = positions.get(count);
mm.logs().showMessage(“wait for " + position.config + " 2 sec”);
mmc.sleep(2000);
++count;
if (count >= positions.size()) {
count = 0;
}
}
};

mm.acquisitions().attachRunnable(-1, -1, 0, 0, runnable);

Unfortunately no it does not. It might be worth making the switch to 2.0 sooner rather than later though, as 1.4 will soon no longer be supported, and there are no limitations to the device API in 2.0 compared to 1.4

In 1.4, mm is called studio (I think, you can look it up on https://mciro-manager/org).

The device interface layer is the same between 1.4 and 2.0. What is your device that keeps you on 1.4?

What did the script do? Did run at all at the times you want it to run? You should not have to tell it to go to a position (the acquisition engine takes care of that part), only to sleep for a given amount of time.

@nicost, I changed the code, and still doesn’t work. Basically the script doesn’t do anything.
I need to take 10 images from each position and I have 3 positions, and time interval for each cycle to be 10 sec.
I expect to get this: take data from position 1, wait for 2 sec, move to position 2 and take data, wait for 2 sec, move to position 3 and take data, wait for 6 sec and return to position 1.

What I get from from this script is:
taking data from position 1, moving to position 2 and taking data, moving to position 3, wait for near 9 sec and returning to position 1. (which means the script didn’t do anything).

I work with the Polscope, which has two plugins and the plugin works with 1.4.

here is my updated code:
Studio.acquisitions().clearRunnables();

runnable = new Runnable() {
int count = 0;
public void run() {
settings = Studio.acquisitions().getAcquisitionSettings();
// poritions = settings.positions;
pl = Studio.positions().getPositionList();
msp = pl.getPosition(count);
// msp.goToPosition(msp, mmc);
// position = positions.get(count);
Studio.logs().showMessage(“wait for " + position.config + " 2 sec”);
mmc.sleep(2000);
++count;
if (count >= positions.size()) {
count = 0;
}
}
};
// Numbers are frames, stage positions, channels, slices
Studio.acquisitions().attachRunnable(0, -1, 0, 0, runnable);

That script had lots of runtime errors. These are hard to find, you would have look into the Corelog file (or run MM from the command line or IDE to give you its output). The following script does what you asked for in your initial post:

mm.acquisitions().clearRunnables();
pl = mm.positions().getPositionList();

runnable = new Runnable() {
	int count = 0;
	boolean firstTime = true;
	public void run() {
		if (firstTime) {
			firstTime = false; 			
			mm.scripter().message("First position, not sleeping.");
		} else {
			if (count == 0)  {// position 1
				Thread.sleep(1000); // or however long your like				
				mm.scripter().message("Position " + count + ". Sleeping 1 s");
			}
			if (count == 1) { // position 2
				Thread.sleep(2000);
				mm.scripter().message("Position " + count + ". Sleeping 2 s");
			}
		}
		++count;
		if (count >= pl.getNumberOfPositions()) {
			count = 0;
		}
	}
};
// Numbers are frames, stage positions, channels, slices
mm.acquisitions().attachRunnable(-1, -1, 0, 0, runnable);

Thanks Nico. with this code I get this error:
Line 1: general error : Studio .acquisitions ( )
(I changed mm to Studio)

Studio is the name of the class that the studio object belongs to. Only static functions can be called in a class. Why do you want to change it to Studio? This script is written for 2.0, it will look quite a bit different for 1.4. The equivalent of mm in 1.4 is gui. Its function list can be found here: ScriptInterface

Thanks Nico. Can I do the same for different channels as well? like having 3different channels and asking to sleep in one of them for 2 min.

Yes, use the appropriate call for attachRunnable.

Ok thanks. I wrote this code to stop in each channel for 10 sec, using the sample in the link you sent before, but seems something is wrong:
mm.acquisitions().clearRunnables();

runnable = new Runnable() {
int count = 0;
public void run() {
settings = mm.acquisitions().getAcquisitionSettings();
channels = settings.channels;
channel = channels.get(count);
Thread.sleep(10000);
// mm.logs().showMessage(“Move filters for channel " + channel.config + " in place”);
++count;
if (count >= channels.size()) {
count = 0;
}
}
};

mm.acquisitions().attachRunnable(-1, 0, -1, 0, runnable);

Do you have any idea what could be the reason?

You wrote “something is wrong”. What was wrong? Did you get an error in the Beanshell script? Did the acquisition run, but not do what you would like it to do? Or did Micro-Manager disappear from the screen? There are many ways things go wrong, and helping figure this out without knowing is a bit difficult…

Can you also try to use those nice little icons in the top of the editor to insert code? The “pre-formatted text” icon works great. It makes the code much easier to read and to spot issues.

Nico, I realized that the code doesn’t have problem. thanks for your suggestions