Skip to content

Commit 109a98f

Browse files
edyoshikunieivanovtayllatheodoropicaq
authored
Merging autotracker (#156)
* initial test of the multiotsu * adding working pcc, template matching and multiotsu. borrowing funcs from dexv2 * adding autotracker shrimpy backbone and tracking methods * this runs on demo mode without updating the events for the stage. Assumes that there are shifts computed and returned. * autotracker with demo mode working * adding autotracker parameters to the mantis config * add notes * add back isort on/off * implement shift limits * fix bug in template matching validator * debug autotracker * change from tuple to list * adding normalization flag * Update autotracker.py small fix on phase cross corr * Update autotracker.py printing positions in the same order * Update autotracker.py Update printing positions and logging * Update acq_engine.py * Update autotracker.py use t=0 as reference * update O3 refocus to use new piezo stage * style * add autotracker stall debugging * move autotracker logs to /logs (#176) * move autotracker logs to /logs * Update author metadata labeling in CITATION.cff (#188) Update author metadata format in CITATION.cff * Add CLI to stir plate before acquisition (#189) * add stir_plate CLI * docs and check for empty pos list * use logging instead of click.echo * style --------- Co-authored-by: Mandy Chen <[email protected]> * Update MM position list when using autotracker (#197) * update MM position list * bugfixes * update positions at last timepoint * from pycromanager import JavaObject * add autotracker stall debugging * abort stalled O3 autofocus * add phase reconstruction * update pcc removing padding * bug fix * clean gpu * keep track of gpu vars * autotracker debug Co-Authored-By: Taylla Milena Theodoro <[email protected]> * clip shift_zyx Co-Authored-By: Taylla Milena Theodoro <[email protected]> * update limits Co-Authored-By: Taylla Milena Theodoro <[email protected]> * remove log transform from PCC and adding max shift Co-Authored-By: Taylla Milena Theodoro <[email protected]> * add vs to autotracker * adding viscy and correcting bugs * correct config indentation Co-Authored-By: Taylla Milena Theodoro <[email protected]> * add vs to pydantic acquisition settings model Co-Authored-By: Taylla Milena Theodoro <[email protected]> * debug * remove device log and tif file writes * Autotracker based on phase reconstruction (#198) * add autotracker stall debugging * abort stalled O3 autofocus * add phase reconstruction * update pcc removing padding * bug fix * clean gpu * keep track of gpu vars * autotracker debug Co-Authored-By: Taylla Milena Theodoro <[email protected]> * clip shift_zyx Co-Authored-By: Taylla Milena Theodoro <[email protected]> * update limits Co-Authored-By: Taylla Milena Theodoro <[email protected]> * remove log transform from PCC and adding max shift Co-Authored-By: Taylla Milena Theodoro <[email protected]> --------- Co-authored-by: Taylla Theodoro <[email protected]> * Revert "Autotracker based on phase reconstruction" (#201) Revert "Autotracker based on phase reconstruction (#198)" This reverts commit d295f36. * abort stalled O3 autofocus * add phase reconstruction * update pcc removing padding * bug fix * clean gpu * keep track of gpu vars * autotracker debug Co-Authored-By: Taylla Milena Theodoro <[email protected]> * clip shift_zyx Co-Authored-By: Taylla Milena Theodoro <[email protected]> * update limits Co-Authored-By: Taylla Milena Theodoro <[email protected]> * remove log transform from PCC and adding max shift Co-Authored-By: Taylla Milena Theodoro <[email protected]> * debug - don't use PM for O3 autofocus * if shift reaches the max value, use max Co-Authored-By: Taylla Milena Theodoro <[email protected]> * working stage with autotracker instanciated once, buffer=100 * limit shifts function * autotracker settings in classs init * adding data preprocessing label free function * Autotracker refactor instantiation and shifit limits (#209) * instanciate autotracker once * refactor shift lim * add logging * debug * tracker in autotracker * arguments from tracker to init * zyx_shape as parameter * tf in autotracker * push last updates from mantis microscope * remove extra print statements --------- Co-authored-by: Ivan Ivanov <[email protected]> * remove python-no-eval hook * style --------- Co-authored-by: Ivan Ivanov <[email protected]> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Mandy Chen <[email protected]>
1 parent 301bb2e commit 109a98f

16 files changed

+3231
-17
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ repos:
2121
- id: python-check-blanket-noqa
2222
- id: python-check-blanket-type-ignore
2323
- id: python-no-log-warn
24-
- id: python-no-eval
2524

2625
- repo: https://github.com/pycqa/isort
2726
rev: 5.12.0

examples/acquisition_settings/demo_acquisition_settings.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ time_settings:
66
time_interval_s: 5
77

88
lf_channel_settings:
9-
default_exposure_times_ms: [10, 10]
9+
default_exposure_times_ms: [5, 5]
1010
channel_group: 'Channel-Multiband'
1111
channels: ['DAPI', 'FITC']
1212
use_sequencing: True
@@ -30,6 +30,8 @@ lf_microscope_settings:
3030
channel_sequencing_settings:
3131
- ['LED', 'Sequence', 'On']
3232
use_autofocus: False
33+
autotracker_config: ['Channel-Multiband', 'DAPI']
34+
3335

3436
ls_channel_settings:
3537
default_exposure_times_ms: [20, 30]
@@ -56,3 +58,14 @@ ls_microscope_settings:
5658
- ['Camera', 'BitDepth', '11']
5759
z_sequencing_settings:
5860
- ['Z', 'UseSequences', 'Yes']
61+
62+
ls_autoexposure_settings:
63+
autoexposure_method: 'manual'
64+
rerun_each_timepoint: True
65+
66+
autotracker_settings:
67+
tracking_method: 'phase_cross_correlation'
68+
tracking_interval: 1
69+
shift_limit: [30,200,200]
70+
device: 'cpu'
71+
scale_yx: 0.075

examples/acquisition_settings/example_acquisition_settings.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ lf_microscope_settings:
120120
use_autofocus: True
121121
autofocus_stage: 'ZDrive'
122122
autofocus_method: 'PFS'
123+
# Autotracker parameters using the label-free channel
124+
autotracker_config: ['Channel - LF', 'BF']
123125

124126
# Microscope settings which will be applied when the light-sheet acquisition is
125127
# initialized
@@ -144,3 +146,52 @@ ls_microscope_settings:
144146
ls_autoexposure_settings:
145147
autoexposure_method: 'manual'
146148
rerun_each_timepoint: True
149+
150+
autotracker_settings:
151+
tracking_method: 'phase_cross_correlation'
152+
reconstruction: ['phase', 'vs'] ##list of reconstruction methods to apply before tracking
153+
tracking_interval: 1
154+
shift_estimation_channel: 'vs_nuclei'
155+
absolute_shift_limits_um:
156+
z: [0.5, 2]
157+
y: [2, 10]
158+
x: [2, 10]
159+
device: 'cpu'
160+
scale_yx: 0.075
161+
phase_config: # apply phase reconstruction before tracking
162+
transfer_function:
163+
wavelength_illumination: 0.450
164+
yx_pixel_size: 0.1494
165+
z_pixel_size: 0.174
166+
z_padding: 5
167+
index_of_refraction_media: 1.4
168+
numerical_aperture_detection: 1.35
169+
numerical_aperture_illumination: 0.52
170+
invert_phase_contrast: false
171+
apply_inverse:
172+
reconstruction_algorithm: Tikhonov
173+
regularization_strength: 0.01
174+
TV_rho_strength: 0.001
175+
TV_iterations: 1
176+
vs_config:
177+
model:
178+
class_path: viscy.translation.engine.VSUNet
179+
init_args:
180+
architecture: fcmae
181+
model_config:
182+
in_channels: 1
183+
out_channels: 2
184+
in_stack_depth: 21
185+
encoder_blocks: [3, 3, 9, 3]
186+
dims: [96, 192, 384, 768]
187+
encoder_drop_path_rate: 0.0
188+
stem_kernel_size: [7, 4, 4]
189+
in_stack_depth: 21
190+
decoder_conv_blocks: 2
191+
pretraining: False
192+
head_conv: True
193+
head_conv_expansion_ratio: 4
194+
head_conv_pool: False
195+
test_time_augmentations: True
196+
tta_type: median
197+
ckpt_path: /hpc/projects/comp.micro/virtual_staining/models/fcmae-3d/fit_v2/pretrain_end2end/lightning_logs/finetune_VS_end2end_v1_test6_prefetch2_nopersistwork_restart_2/checkpoints/epoch=64-step=24960.ckpt

mantis/acquisition/AcquisitionSettings.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import copy
12
import warnings
23

34
from dataclasses import field
4-
from typing import Dict, List, Literal, Optional, Tuple, Union
5+
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
56

67
import numpy as np
78

@@ -36,10 +37,12 @@ class PositionSettings:
3637
position_labels: List[str] = field(default_factory=list)
3738
num_positions: int = field(init=False, default=0)
3839
well_ids: List[str] = field(init=False, default_factory=list)
40+
xyz_positions_shift: list = field(init=False, default_factory=list)
3941

4042
def __post_init__(self):
4143
assert len(self.xyz_positions) == len(self.position_labels)
4244
self.num_positions = len(self.xyz_positions)
45+
self.xyz_positions_shift = copy.deepcopy(self.xyz_positions)
4346

4447
try:
4548
# Look for "'A1-Site_0', 'H12-Site_1', ... " format
@@ -143,6 +146,7 @@ class MicroscopeSettings:
143146
o3_refocus_config: Optional[ConfigSettings] = None
144147
o3_refocus_interval_min: Optional[int] = None
145148
o3_refocus_skip_wells: List[str] = field(default_factory=list)
149+
autotracker_config: Optional[ConfigSettings] = None
146150

147151

148152
@dataclass
@@ -195,3 +199,32 @@ def __post_init__(self):
195199
attr_val = getattr(self, attr)
196200
if attr_val is not None:
197201
setattr(self, attr, round(attr_val, 1))
202+
203+
204+
@dataclass
205+
class AutotrackerSettings:
206+
tracking_method: Literal['phase_cross_correlation', 'template_matching', 'multi_otsu']
207+
tracking_interval: Optional[int] = 1 # TODO: add units
208+
shift_estimation_channel: Literal['phase', 'vs_nuclei', 'vs_membrane', 'bf'] = 'bf'
209+
scale_yx: Optional[float] = 1.0 # in um per pixel
210+
device: Optional[str] = 'cpu'
211+
zyx_dampening_factor: Optional[Union[Tuple[float, float, float], None]] = None
212+
absolute_shift_limits_um: Optional[Dict[str, Tuple[float, float]]] = field(
213+
default_factory=lambda: {'z': (0.5, 2), 'y': (2, 10), 'x': (2, 10)}
214+
) # in um
215+
# TODO: maybe do the ROI like in the ls_microscope_settings
216+
template_roi_zyx: Optional[Tuple[int, int, int]] = None
217+
template_channel: Optional[str] = None
218+
reconstruction: Optional[List[str]] = field(default_factory=list)
219+
phase_config: Optional[Dict[str, Any]] = field(default_factory=dict)
220+
vs_config: Optional[Dict[str, Any]] = field(default_factory=dict)
221+
222+
@validator("tracking_method")
223+
def check_tracking_method_options(cls, v):
224+
# Check if template matching options are provided and are not None
225+
if v == 'template_matching':
226+
if not all([cls.template_roi_zyx, cls.template_channel]):
227+
raise ValueError(
228+
'template_roi_zyx and template_channel must be provided for template matching'
229+
)
230+
return v

0 commit comments

Comments
 (0)