Skip to content

Commit

Permalink
Merge pull request micro-manager#9 from henrypinkard/main
Browse files Browse the repository at this point in the history
Add MM example and improve packaging
  • Loading branch information
henrypinkard authored Jul 26, 2024
2 parents ac5fc15 + d8c579c commit 4213ae8
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
pip install -e ".[test, all]"
- name: Test with pytest
run: |
Expand Down
83 changes: 83 additions & 0 deletions micro-manager_setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Setup and examples for using the ExEngine with a micro-manager backend

- clone the repository
- install it, specifying which device and data storage backends
`pip install -e ".[micromanager, ndstorage]"`
- install Micro-Manager

```python
from mmpycorex import download_and_install_mm
download_and_install_mm()
```


## Running the ExEngine

```python
from mmpycorex import create_core_instance, download_and_install_mm, terminate_core_instances
from exengine.kernel.executor import ExecutionEngine
from exengine.kernel.data_coords import DataCoordinates
from exengine.kernel.ex_event_base import DataHandler
from exengine.backends.micromanager.mm_device_implementations import MicroManagerCamera, MicroManagerSingleAxisStage
from exengine.storage_backends.NDTiffandRAM import NDRAMStorage
from exengine.events.detector_events import StartCapture, ReadoutData


# Start Micro-Manager core instance with Demo config
create_core_instance()

executor = ExecutionEngine()


# get access to the micro-manager devices
camera = MicroManagerCamera()
z_stage = MicroManagerSingleAxisStage()

```


### Example 1: Use the exengine to acquire a timelapse

```python
# Capture 100 images on the camera
num_images = 100
data_handler = DataHandler(storage=NDRAMStorage())

start_capture_event = StartCapture(num_images=num_images, detector=camera)
readout_images_event = ReadoutData(num_images=num_images, detector=camera,
data_coordinates_iterator=[DataCoordinates(time=t) for t in range(num_images)],
data_handler=data_handler)

_ = executor.submit(start_capture_event)
future = executor.submit(readout_images_event)

# block until all images have been read out
future.await_execution()

# Tell the data handler no more images are expected
data_handler.finish()

```

### Example 2: create series of events with multi-d function
```python
from exengine.events.multi_d_events import multi_d_acquisition_events

data_handler = DataHandler(storage=NDRAMStorage())
events = multi_d_acquisition_events(z_start=0, z_end=10, z_step=2)

futures = executor.submit(events)
# wait until the final event finished
futures[-1].await_execution()

# Tell the data handler no more images are expected
data_handler.finish()
```


```python
# shutdown the engine
executor.shutdown()
# shutdown micro-manager
terminate_core_instances()
```
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ classifiers = [
"Operating System :: OS Independent"
]
dependencies = [
"mmpycorex",
"ndstorage",
"pydantic"
]

dynamic = ["version"]
description = "Microscopy execution engine with support for multiple hardware backends"
readme = "README.md"

[project.optional-dependencies]
test = ["pytest"] # New test dependencies group
test = ["pytest"]

# all backends
all = [
"mmpycorex",
"ndstorage"
]

# device backends
micromanager = ["mmpycorex"]

# storage backends
ndstorage = ["ndstorage"]


[project.urls]
Expand Down
8 changes: 5 additions & 3 deletions src/exengine/examples/micromanager_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
num_images = 100
data_handler = DataHandler(storage=NDRAMStorage())

start_capture_event = StartCapture(num_images=num_images, camera=camera)
readout_images_event = ReadoutData(num_images=num_images, camera=camera,
data_coordinate_iterator=[DataCoordinates(time=t) for t in range(num_images)],
start_capture_event = StartCapture(num_images=num_images, detector=camera)
readout_images_event = ReadoutData(num_images=num_images, detector=camera,
data_coordinates_iterator=[DataCoordinates(time=t) for t in range(num_images)],
data_handler=data_handler)
executor.submit(start_capture_event)
future = executor.submit(readout_images_event)
Expand All @@ -35,6 +35,8 @@

data_handler.finish()



executor.shutdown()
terminate_core_instances()

0 comments on commit 4213ae8

Please sign in to comment.