From f2e48038748c1684dc56e0c37ed432a8fcad0e7d Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 27 Jul 2023 19:14:07 -0700 Subject: [PATCH 1/5] refactor reading current mm position --- mantis/acquisition/acq_engine.py | 31 ++++++++------------- mantis/acquisition/microscope_operations.py | 19 +++++++++++-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/mantis/acquisition/acq_engine.py b/mantis/acquisition/acq_engine.py index cb403cf6..8bc2d2ba 100644 --- a/mantis/acquisition/acq_engine.py +++ b/mantis/acquisition/acq_engine.py @@ -382,33 +382,24 @@ def update_position_settings(self): """ Fetch positions defined in the Micro-manager Position List Manager """ - mm_pos_list = self.lf_acq.mmStudio.get_position_list_manager().get_position_list() - mm_number_of_positions = mm_pos_list.get_number_of_positions() autofocus_stage = self.lf_acq.microscope_settings.autofocus_stage if self.position_settings.num_positions == 0: - if mm_number_of_positions > 0: - logger.debug('Fetching position list from Micro-manager') + logger.debug('Fetching position list from Micro-manager') - xyz_position_list, position_labels = microscope_operations.get_position_list( - self.lf_acq.mmStudio, autofocus_stage + xyz_positions, position_labels = microscope_operations.get_position_list( + self.lf_acq.mmStudio, autofocus_stage + ) + + if not xyz_positions: + logger.debug('Micro-manager position list is empty. Fetching current position') + + xyz_positions, position_labels = microscope_operations.get_current_position( + self.lf_acq.mmc, autofocus_stage ) - else: - logger.debug('Fetching current position from Micro-manager') - - xyz_position_list = [ - ( - self.lf_acq.mmc.get_x_position(), - self.lf_acq.mmc.get_y_position(), - self.lf_acq.mmc.get_position(autofocus_stage) - if autofocus_stage - else None, - ) - ] - position_labels = ['Current'] self.position_settings = PositionSettings( - xyz_positions=xyz_position_list, + xyz_positions=xyz_positions, position_labels=position_labels, ) diff --git a/mantis/acquisition/microscope_operations.py b/mantis/acquisition/microscope_operations.py index 63da24e6..727d4905 100644 --- a/mantis/acquisition/microscope_operations.py +++ b/mantis/acquisition/microscope_operations.py @@ -74,11 +74,11 @@ def get_position_list(mmStudio, z_stage_name): mm_pos_list = mmStudio.get_position_list_manager().get_position_list() number_of_positions = mm_pos_list.get_number_of_positions() - xyz_position_list = [] + xyz_positions = [] position_labels = [] for i in range(number_of_positions): _pos = mm_pos_list.get_position(i) - xyz_position_list.append( + xyz_positions.append( [ _pos.get_x(), _pos.get_y(), @@ -87,7 +87,20 @@ def get_position_list(mmStudio, z_stage_name): ) position_labels.append(_pos.get_label()) - return xyz_position_list, position_labels + return xyz_positions, position_labels + + +def get_current_position(mmc, z_stage_name): + xyz_position = [ + ( + mmc.get_x_position(), + mmc.get_y_position(), + mmc.get_position(z_stage_name) if z_stage_name else None, + ) + ] + position_label = ['Current'] + + return xyz_position, position_label def set_z_position(mmc, z_stage_name: str, z_position: float): From cf7af913865844737997c3ba8177737940340197 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 27 Jul 2023 20:00:43 -0700 Subject: [PATCH 2/5] use position label instead of position index in events dict --- mantis/acquisition/acq_engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mantis/acquisition/acq_engine.py b/mantis/acquisition/acq_engine.py index 8bc2d2ba..35e0ce86 100644 --- a/mantis/acquisition/acq_engine.py +++ b/mantis/acquisition/acq_engine.py @@ -910,13 +910,13 @@ def acquire(self): lf_events = deepcopy(lf_cz_events) for _event in lf_events: _event['axes']['time'] = t_idx - _event['axes']['position'] = p_idx + _event['axes']['position'] = p_label _event['min_start_time'] = 0 ls_events = deepcopy(ls_cz_events) for _event in ls_events: _event['axes']['time'] = t_idx - _event['axes']['position'] = p_idx + _event['axes']['position'] = p_label _event['min_start_time'] = 0 ls_acq.acquire(ls_events) From a935fd59a34a32d9c7121f3fe30b25d5bbaae0a7 Mon Sep 17 00:00:00 2001 From: talonchandler Date: Fri, 28 Jul 2023 10:15:18 -0700 Subject: [PATCH 3/5] update hook functions --- mantis/acquisition/acq_engine.py | 9 ++------- .../hook_functions/post_hardware_hook_functions.py | 13 ++++++------- .../hook_functions/pre_hardware_hook_functions.py | 13 ++++++------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/mantis/acquisition/acq_engine.py b/mantis/acquisition/acq_engine.py index 35e0ce86..a76efa66 100644 --- a/mantis/acquisition/acq_engine.py +++ b/mantis/acquisition/acq_engine.py @@ -800,22 +800,17 @@ def acquire(self): # define LF hook functions if self._demo_run: - lf_pre_hardware_hook_fn = partial( - log_preparing_acquisition, self.position_settings.position_labels - ) + lf_pre_hardware_hook_fn = log_preparing_acquisition lf_post_camera_hook_fn = None else: lf_pre_hardware_hook_fn = partial( log_preparing_acquisition_check_counter, - self.position_settings.position_labels, [self._lf_z_ctr_task, self._lf_channel_ctr_task], ) lf_post_camera_hook_fn = partial( start_daq_counters, [self._lf_z_ctr_task, self._lf_channel_ctr_task] ) - lf_post_hardware_hook_fn = partial( - log_acquisition_start, self.position_settings.position_labels - ) + lf_post_hardware_hook_fn = log_acquisition_start lf_image_saved_fn = None # define LF acquisition diff --git a/mantis/acquisition/hook_functions/post_hardware_hook_functions.py b/mantis/acquisition/hook_functions/post_hardware_hook_functions.py index a84b6266..bbd49aae 100644 --- a/mantis/acquisition/hook_functions/post_hardware_hook_functions.py +++ b/mantis/acquisition/hook_functions/post_hardware_hook_functions.py @@ -3,17 +3,16 @@ logger = logging.getLogger(__name__) -def log_acquisition_start(position_labels: list, events): +def log_acquisition_start(events): if isinstance(events, list): _event = events[0] else: _event = events # events is a dict t_idx = _event['axes']['time'] - p_idx = _event['axes']['position'] - logger.info( - f'Starting acquisition of timepoint {t_idx} at position {position_labels[p_idx]}' - ) + p_label = _event['axes']['position'] + + logger.info(f'Starting acquisition of timepoint {t_idx} at position {p_label}') return events @@ -35,8 +34,8 @@ def update_daq_freq(z_ctr_task, channels: list, acq_rates: list, events): return events -def update_daq_freq_log_start_acq(z_ctr_task, channels, acq_rates, position_labels, events): +def update_daq_freq_log_start_acq(z_ctr_task, channels, acq_rates, events): events = update_daq_freq(z_ctr_task, channels, acq_rates, events) - events = log_acquisition_start(position_labels, events) + events = log_acquisition_start(events) return events diff --git a/mantis/acquisition/hook_functions/pre_hardware_hook_functions.py b/mantis/acquisition/hook_functions/pre_hardware_hook_functions.py index 40a6edbd..fbe434ea 100644 --- a/mantis/acquisition/hook_functions/pre_hardware_hook_functions.py +++ b/mantis/acquisition/hook_functions/pre_hardware_hook_functions.py @@ -10,17 +10,16 @@ logger = logging.getLogger(__name__) -def log_preparing_acquisition(position_labels, events): +def log_preparing_acquisition(events): if isinstance(events, list): _event = events[0] else: _event = events # events is a dict t_idx = _event['axes']['time'] - p_idx = _event['axes']['position'] - logger.debug( - f'Preparing to acquire timepoint {t_idx} at position {position_labels[p_idx]}' - ) + p_label = _event['axes']['position'] + + logger.debug(f'Preparing to acquire timepoint {t_idx} at position {p_label}') return events @@ -44,8 +43,8 @@ def check_num_counter_samples(ctr_tasks, events): return events -def log_preparing_acquisition_check_counter(position_labels, ctr_tasks, events): - events = log_preparing_acquisition(position_labels, events) +def log_preparing_acquisition_check_counter(ctr_tasks, events): + events = log_preparing_acquisition(events) events = check_num_counter_samples(ctr_tasks, events) return events From c07ad1563723136d365f3109c96a0d1ac1acaab1 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 4 Aug 2023 17:11:34 -0700 Subject: [PATCH 4/5] pin ndtiff dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 611ef7d9..45cf54b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dependencies = [ "napari[all]; 'arm64' not in platform_machine", # with Qt5 and skimage "PyQt6; 'arm64' in platform_machine", "natsort", + "ndtiff<2.0", "nidaqmx", "numpy", "pycromanager==0.25.40", From 5c6aa9471ce66898f74c4128ee42bfef63fcb61b Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 18 Aug 2023 09:10:41 -0700 Subject: [PATCH 5/5] bump iohub dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 13338cf7..0b8e62e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ # list package dependencies here dependencies = [ - "iohub==0.1.0.dev4", + "iohub==0.1.0.dev5", "matplotlib", "napari; 'arm64' in platform_machine", # without Qt5 and skimage "napari[all]; 'arm64' not in platform_machine", # with Qt5 and skimage