Skip to content

Commit

Permalink
Save HCS position label in NDTiff dataset axes (#70)
Browse files Browse the repository at this point in the history
* refactor reading current mm position

* use position label instead of position index in events dict

* update hook functions

* pin ndtiff dependency

* bump iohub dependency
  • Loading branch information
ieivanov authored Aug 19, 2023
1 parent 0cf61f4 commit 8d49dd0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
44 changes: 15 additions & 29 deletions mantis/acquisition/acq_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
13 changes: 6 additions & 7 deletions mantis/acquisition/hook_functions/pre_hardware_hook_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
19 changes: 16 additions & 3 deletions mantis/acquisition/microscope_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d49dd0

Please sign in to comment.