Skip to content

Commit

Permalink
rework acq engine (#5)
Browse files Browse the repository at this point in the history
* partial settings implementation

* update microscope settings code

* Update from main (#3)

* add examples

* minor acq engine update

* fix timelapse enum bug

* Update .gitignore

* Create pyproject.toml

* Create setup.py

* Create setup.cfg

* Update pyproject.toml

* Update pyproject.toml

* implement yaml acq settings

* update settings logging

* continue settings refactor

* update setting and setup_daq

* update acquire

* bugfix

* enforce dataset structure

* cleanup

* revamp acq hooks

* register run-mantis-acquisition command

* add project version

* mock autofocus

* add ls ctr task

* add ls_channel_counter_task

* remove LS z counter

* add_acq_finished_check

* improve acq timing

* Update acq_engine.py

* add moving between positions

* add autofocus

* better autofocus function

* clean up

* small fixes

* Update demo_acquisition_settings.yaml

* extend support for demo run

* demo run support

* fix wait for device bug

* modulate xy stage speed

* debug xy speed modulation

* ls channel specific daq config

* edited acquisition cli and updated docstrings

* add simple phase recon

* update autofocus

* increase LS saving_queue_size

* update autofocus

* Revert "edited acquisition cli and updated docstrings"

This reverts commit 6c9fda4.

* Shalin edited acquisition cli and updated docstrings

Co-Authored-By: Shalin Mehta <[email protected]>

* Update mantis_acquisition_settings.yaml

* rename example acq settings

* move run_acquisition to cli module

* better acq cleanup

* add settings documentation

* update documentation

* Create write_pos_csv.py

---------

Co-authored-by: Shalin Mehta <[email protected]>
  • Loading branch information
ieivanov and mattersoflight authored Apr 12, 2023
1 parent ef72dd3 commit 68bc5f7
Show file tree
Hide file tree
Showing 40 changed files with 1,524 additions and 3,906 deletions.
71 changes: 26 additions & 45 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# repo-specific directories
ignore/
output/
cache/

tests/output/
client/.npm/
client/node_modules/
client/dist/

# IDE directories/configs
.idea/
.vscode/
*.code-workspace
.DS_Store
.obsidian

# node-related
*.tgz
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.changelog

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand All @@ -20,12 +44,9 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -40,16 +61,13 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
Expand All @@ -58,8 +76,6 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
Expand All @@ -77,26 +93,11 @@ target/
# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
# celery beat schedule file
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py
Expand All @@ -107,8 +108,6 @@ celerybeat.pid
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
Expand All @@ -122,22 +121,4 @@ venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# JetBrains template
.idea

# VS code
.vscode

# Mac
.DS_Store


# Windows
Thumbs.db
ehthumbs.db
.dmypy.json
2 changes: 1 addition & 1 deletion examples/acquire_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
use_sequence = True,
)

acq = MantisAcquisition(acquisition_directory=r'D:\2023_02_21_mantis_dataset_standard', verbose=False)
acq = MantisAcquisition(acquisition_directory=r'D:\2023_02_17_mantis_dataset_standard', verbose=False)

acq.define_lf_acq_settings(lf_acq_settings)
acq.define_ls_acq_settings(ls_acq_settings)
Expand Down
27 changes: 27 additions & 0 deletions examples/write_pos_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import csv
from mantis.acquisition.BaseSettings import PositionSettings

position_settings = PositionSettings(**{})

pos_list = []
for i in range(position_settings.num_positions):
pos_list.append(
{
'position_ind': i,
'well_id': position_settings.position_labels[i].split('-')[0],
'site_num': position_settings.position_labels[i].split('_')[-1],
'label': position_settings.position_labels[i],
'x_position': position_settings.xyz_positions[i][0],
'y_position': position_settings.xyz_positions[i][1],
'z_position': position_settings.xyz_positions[i][2],
}
)

path = r'Z:\rawdata\mantis\2023_04_05_mantis_HEK\48wells_1timepoint_4'
with open(os.path.join(path, 'positions.csv'), 'w', newline='') as csvfile:
fieldnames = list(pos_list[0].keys())
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

writer.writeheader()
writer.writerows(pos_list)
1 change: 1 addition & 0 deletions mantis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.2"
79 changes: 79 additions & 0 deletions mantis/acquisition/BaseSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import numpy as np
from typing import Optional, List, Tuple, Sequence
from pydantic.dataclasses import dataclass
from dataclasses import field


@dataclass
class ConfigSettings:
config_group: str
config_name: str


@dataclass
class DevicePropertySettings:
device_name: str
property_name: str
property_value: str


@dataclass
class TimeSettings:
num_timepoints: Optional[int] = 0
time_internal_s: Optional[float] = 0 # in seconds


@dataclass
class PositionSettings:
xyz_positions: list = field(default_factory=list)
position_labels: List[str] = field(default_factory=list)
num_positions: int = field(init=False, default=0)

def __post_init__(self):
assert len(self.xyz_positions) == len(self.position_labels)
self.num_positions = len(self.xyz_positions)


@dataclass
class ChannelSettings:
exposure_time_ms: List[float] = field(default_factory=list) # in ms
channel_group: Optional[str] = None
channels: List[str] = field(default_factory=list)
use_sequencing: bool = False
num_channels: int = field(init=False, default=0)
acquisition_rate: float = field(init=False, default=None)

def __post_init__(self):
self.num_channels = len(self.channels)
assert len(self.exposure_time_ms) == len(self.channels), \
'Number of channels must equal number of exposure times'


@dataclass
class SliceSettings:
z_stage_name: Optional[str] = None
z_start: Optional[float] = None
z_end: Optional[float] = None
z_step: Optional[float] = None
use_sequencing: bool = False
num_slices: int = field(init=False, default=0)
acquisition_rate: float = field(init=False, default=None)
z_range: List[float] = field(init=False, repr=False, default_factory=list)

def __post_init__(self):
if self.z_step is not None:
self.z_range = list(np.arange(self.z_start, self.z_end+self.z_step, self.z_step))
self.num_slices = len(self.z_range)


@dataclass
class MicroscopeSettings:
roi: Optional[Tuple[int, int, int, int]] = None
config_group_settings: List[ConfigSettings] = field(default_factory=list)
device_property_settings: List[DevicePropertySettings] = field(default_factory=list)
reset_device_properties: List[DevicePropertySettings] = field(default_factory=list)
z_sequencing_settings: List[DevicePropertySettings] = field(default_factory=list)
channel_sequencing_settings: List[DevicePropertySettings] = field(default_factory=list)
use_autofocus: bool = False
autofocus_stage: Optional[str] = None
autofocus_method: Optional[str] = None
Loading

0 comments on commit 68bc5f7

Please sign in to comment.