Skip to content

Commit

Permalink
this runs on demo mode without updating the events for the stage. Ass…
Browse files Browse the repository at this point in the history
…umes that there are shifts computed and returned.
  • Loading branch information
edyoshikun committed Aug 14, 2024
1 parent 841dccf commit 1b0f208
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 211 deletions.
13 changes: 7 additions & 6 deletions mantis/acquisition/AcquisitionSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class MicroscopeSettings:
use_o3_refocus: bool = False
o3_refocus_config: Optional[ConfigSettings] = None
o3_refocus_interval_min: Optional[int] = None
autotracker_config: Optional[ConfigSettings] = None


@dataclass
Expand Down Expand Up @@ -198,17 +199,17 @@ def __post_init__(self):
@dataclass
class AutotrackerSettings:
tracking_method: Literal['phase_cross_correlation', 'template_matching', 'multi_otsu']
tracking_interval: Optional[int] = 1
scale_yx: Optional[float] = 1.0
shift_limit: Optional[Union[Tuple[float, float, float], 'None']] = None
device: Optional[str] = 'cpu'
tracking_arm: Literal['lf', 'ls'] = 'lf'
channel_to_track: Optional[str] = None
zyx_dampening_factor: Optional[float, float, float] = None
re_run_every_n_timepoints: Optional[int] = None
zyx_dampening_factor: Optional[Union[Tuple[float, float, float], None]] = None
# TODO: maybe do the ROI like in the ls_microscope_settings
template_roi_zyx: Optional[Tuple[int, int, int]] = None
template_channel: Optional[str] = None

@validator("autotracker_method")
def check_autotracker_methods_options(cls, v):
@validator("tracking_method")
def check_tracking_method_options(cls, v):
# Check if template matching options are provided and are not None
if v == 'template_matching':
if not all([cls.template_roi_zyx, cls.template_channel]):
Expand Down
63 changes: 39 additions & 24 deletions mantis/acquisition/acq_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
check_ls_acq_finished,
)

# isort: on
from mantis.acquisition.autotracker import autotracker_hook_fn


# Define constants
Expand Down Expand Up @@ -212,9 +212,12 @@ def autoexposure_settings(self, settings: AutoexposureSettings):

@autotracker_settings.setter
def autotracker_settings(self, settings: AutotrackerSettings):
logger.debug(
f"{self.type.capitalize()} acquisition will have the following settings:{asdict(settings)}"
)
if settings is None:
logger.debug('Autotracker settings are not provided')
else:
logger.debug(
f"{self.type.capitalize()} acquisition will have the following settings:{asdict(settings)}"
)
self._autotracker_settings = settings

def setup(self):
Expand Down Expand Up @@ -350,6 +353,8 @@ def __init__(
self._lf_acq_obj = None
self._ls_acq_obj = None

globals.demo_run = demo_run

if not enable_lf_acq or not enable_ls_acq:
raise Exception('Disabling LF or LS acquisition is not currently supported')

Expand Down Expand Up @@ -686,20 +691,8 @@ def setup_autoexposure(self):
)

def setup_autotracker(self):
if self._demo_run:
# TODO: implement autotracker in demo mode
logger.debug('Autotracker is not supported in demo mode')
return

if self.lf_acq.microscope_settings.use_autotracker:
logger.debug('Setting up autotracker')
microscope_operations.setup_autotracker(
self.lf_acq.mmc,
self.lf_acq.microscope_settings.autotracker_channel,
self.lf_acq.microscope_settings.autotracker_threshold,
)
else:
logger.debug('Autotracker is not enabled in the microscope settings')
logger.info('Setting up autotracker')
# TODO: probably setup the GPU/CPU settings here

def go_to_position(self, position_index: int):
# Move slowly for short distances such that autofocus can stay engaged.
Expand Down Expand Up @@ -1007,7 +1000,7 @@ def setup(self):
logger.debug('Setting up autoexposure')
self.setup_autoexposure()

logger.debug('Setting up auotracker')
logger.debug('Setting up autotracker')
self.setup_autotracker()

def acquire(self):
Expand All @@ -1029,7 +1022,20 @@ def acquire(self):
start_daq_counters, [self._lf_z_ctr_task, self._lf_channel_ctr_task]
)
lf_post_hardware_hook_fn = log_acquisition_start
lf_image_saved_fn = check_lf_acq_finished

# TODO: implement logic for the autotracker_img_saved_hook_fn
if self.lf_acq.microscope_settings.autotracker_config is not None:
lf_image_saved_fn = partial(
autotracker_hook_fn,
'lf',
self.lf_acq.autotracker_settings,
self.lf_acq.microscope_settings.autotracker_config,
self.lf_acq.slice_settings,
self._acq_dir,
)
else:
logger.info('No autotracker config found. Using default image saved hook')
lf_image_saved_fn = check_lf_acq_finished

# define LF acquisition
self._lf_acq_obj = Acquisition(
Expand Down Expand Up @@ -1059,7 +1065,19 @@ def acquire(self):
self.ls_acq.channel_settings.channels,
)
ls_post_camera_hook_fn = partial(start_daq_counters, [self._ls_z_ctr_task])
ls_image_saved_fn = check_ls_acq_finished

# TODO: implement logic for the autotracker_img_saved_hook_fn
if self.ls_acq.microscope_settings.autotracker_config is not None:
ls_image_saved_fn = partial(
autotracker_hook_fn,
'ls',
self.ls_acq.autotracker_settings,
self.ls_acq.slice_settings,
self._acq_dir,
)
else:
logger.info('No autotracker config found. Using default image saved hook')
ls_image_saved_fn = check_ls_acq_finished

# define LS acquisition
self._ls_acq_obj = Acquisition(
Expand Down Expand Up @@ -1134,9 +1152,6 @@ def acquire(self):
well_id=well_id,
method=self.ls_acq.autoexposure_settings.autoexposure_method,
)
# TODO: add logic to handle skipping timepoints
if t_idx < 2:
self.run_autotracker(acq=self.lf_acq, well_id=well_id)
# Acq rate needs to be updated even if autoexposure was not rerun in this well
# Only do that if we are using autoexposure?
self.update_ls_acquisition_rates(
Expand Down
Loading

0 comments on commit 1b0f208

Please sign in to comment.