diff --git a/mantis/acquisition/acq_engine.py b/mantis/acquisition/acq_engine.py index 9ad8f85c..d00f5577 100644 --- a/mantis/acquisition/acq_engine.py +++ b/mantis/acquisition/acq_engine.py @@ -397,33 +397,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, ) @@ -822,22 +813,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 = check_lf_acq_finished # define LF acquisition @@ -932,13 +918,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 config.lf_last_img_idx = lf_events[-1]['axes'] 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 diff --git a/mantis/acquisition/microscope_operations.py b/mantis/acquisition/microscope_operations.py index ae49bbf1..91887e3e 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): 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