-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
While acquiring a multi-D acquisition on only "emit" the last image to napari viewer #202
Comments
Hi @CedricEsp, Yes, handling the the the "you" in that sentence might be The default function in napari-micromanager/micromanager_gui/main_window.py Lines 79 to 80 in e183861
(that connection line is what causes If you look into the source code of napari-micromanager/micromanager_gui/main_window.py Lines 329 to 336 in e183861
so...
yes, this would be possible, one of two ways:
main_window._mmc.mda.events.frameReady.disconnect(main_window._on_mda_frame)
main_window._mmc.mda.events.frameReady.connect(your_own_callback_function)
if you are trying to connect your own callback, and doing something like calling napari-micromanager/micromanager_gui/main_window.py Lines 314 to 315 in e183861
you could use that same decorator to make sure that the function you're connecting to the frameReady event gets called in the main GUI thread. hope that helps. |
Thanks @tlambert03 that is super useful, I did end up finding the But what concern me is that:
Indeed I would expect that it would not be an issue so I wonder if the engine I built as something wrong that would cause the issue? But indeed it slows down pretty dramatically after some frames if I emit them to napari viewer. Here is a simplified version of the engine I use: def run(self, sequence: MDASequence) -> None:
"""
Run the multi-dimensional acquistion defined by `sequence`.
Most users should not use this directly as it will block further
execution. Instead use ``run_mda`` on CMMCorePlus which will run on
a thread.
Parameters
----------
sequence : MDASequence
The sequence of events to run.
"""
self._prepare_to_run(sequence)
cancelled = self._wait_until_event(event, sequence)
# If cancelled break out of the loop (might create a blue screen..)
if cancelled:
break
logger.info(event)
self._prep_hardware(event)
#adding break before first z to allow stage to move to slide
if event.index.get("z") == 0:
time.sleep(2.2)
#Autofocusing every nth tiles
if event.index.get("p") in AF_nth:
if event.index.get("c") == 0:
if event.index.get("z") == 0:
pos = self.autofocus()
event.z_pos += pos
#capture image
self._prep_hardware(event)
self._mmc.snapImage()
self.img = self._mmc.getImage()
# save the images to disk
self.write_data(event)
if self._param["Streaming"]:
self._events.frameReady.emit(self.img, event)
self._finish_run(sequence) |
Note that I run many mdas and I use that function : def run_many_mda(mdas: list[useq.MDASequence], core: CMMCorePlus = None) -> Thread:
"""
run multiple separate MDAs in a loop without blocking the main thread
"""
core = core or CMMCorePlus.instance()
if core.mda.is_running():
raise ValueError("Cannot start an MDA while the previous MDA is still running.")
def f(mdas):
for seq in mdas:
core.mda.run(seq) # this is blocking so don't need to .join()
th = Thread(target=f, args=(mdas,))
th.start()
return th |
Hello,
I am not clear on how emit work in:
Trying to stream all the data during acquisition seriously slows down the acquisition and often end up in failure (the data are quite big). However, the user would like to have an idea on how the acquisition is going I then wonder if it's possible to only
emit
the current image and remove the previous image in napari. Obviously if I tried to directlyadd_image
to the viewer I end up with a thread error.Thank you for your help!
The text was updated successfully, but these errors were encountered: