closed-loop-microscopy 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. closed_loop_microscopy-1.1.0.dist-info/METADATA +118 -0
  2. closed_loop_microscopy-1.1.0.dist-info/RECORD +74 -0
  3. closed_loop_microscopy-1.1.0.dist-info/WHEEL +4 -0
  4. closed_loop_microscopy-1.1.0.dist-info/entry_points.txt +5 -0
  5. closed_loop_microscopy-1.1.0.dist-info/licenses/LICENSE.md +7 -0
  6. pyclm/__init__.py +26 -0
  7. pyclm/__main__.py +8 -0
  8. pyclm/check.py +931 -0
  9. pyclm/cli.py +256 -0
  10. pyclm/commands.py +183 -0
  11. pyclm/controller.py +447 -0
  12. pyclm/convert_hdf5s.py +273 -0
  13. pyclm/core/__init__.py +20 -0
  14. pyclm/core/base_process.py +166 -0
  15. pyclm/core/core_interface.py +47 -0
  16. pyclm/core/datatypes.py +142 -0
  17. pyclm/core/events.py +194 -0
  18. pyclm/core/experiments.py +403 -0
  19. pyclm/core/grid.py +272 -0
  20. pyclm/core/kinds.py +42 -0
  21. pyclm/core/manager.py +861 -0
  22. pyclm/core/measure.py +266 -0
  23. pyclm/core/messages.py +124 -0
  24. pyclm/core/microscope.py +504 -0
  25. pyclm/core/pattern_process.py +282 -0
  26. pyclm/core/patterns/__init__.py +60 -0
  27. pyclm/core/patterns/bar_patterns.py +259 -0
  28. pyclm/core/patterns/cell_intensity_patterns.py +181 -0
  29. pyclm/core/patterns/composite.py +220 -0
  30. pyclm/core/patterns/embryo_patterns.py +90 -0
  31. pyclm/core/patterns/fbc_cell_movement.py +295 -0
  32. pyclm/core/patterns/pattern.py +610 -0
  33. pyclm/core/patterns/pulse_patterns.py +261 -0
  34. pyclm/core/patterns/static_patterns.py +58 -0
  35. pyclm/core/patterns/wave_patterns.py +95 -0
  36. pyclm/core/patterns/zoo.py +231 -0
  37. pyclm/core/plan.py +623 -0
  38. pyclm/core/position_mover.py +185 -0
  39. pyclm/core/queues.py +41 -0
  40. pyclm/core/real_core.py +158 -0
  41. pyclm/core/router.py +422 -0
  42. pyclm/core/segmentation/__init__.py +2 -0
  43. pyclm/core/segmentation/cellpose_segmentation.py +113 -0
  44. pyclm/core/segmentation/segmentation.py +48 -0
  45. pyclm/core/segmentation_process.py +179 -0
  46. pyclm/core/settings.py +120 -0
  47. pyclm/core/storage/__init__.py +37 -0
  48. pyclm/core/storage/base.py +234 -0
  49. pyclm/core/storage/events.py +130 -0
  50. pyclm/core/storage/hdf5_v1.py +337 -0
  51. pyclm/core/storage/ome_zarr.py +861 -0
  52. pyclm/core/tracking/__init__.py +28 -0
  53. pyclm/core/tracking/centroid.py +75 -0
  54. pyclm/core/tracking/tracking.py +124 -0
  55. pyclm/core/tracking_process.py +106 -0
  56. pyclm/core/virtual_microscope/__init__.py +0 -0
  57. pyclm/core/virtual_microscope/simulated_core.py +262 -0
  58. pyclm/core/virtual_microscope/simulated_source.py +206 -0
  59. pyclm/core/writer_process.py +130 -0
  60. pyclm/demo.py +225 -0
  61. pyclm/directories.py +563 -0
  62. pyclm/gui/__init__.py +28 -0
  63. pyclm/gui/debug_viewer.py +41 -0
  64. pyclm/gui/gui_controller.py +551 -0
  65. pyclm/gui/widgets.py +292 -0
  66. pyclm/io/__init__.py +29 -0
  67. pyclm/io/export.py +202 -0
  68. pyclm/io/readers.py +589 -0
  69. pyclm/methods.py +249 -0
  70. pyclm/mmconfig.py +143 -0
  71. pyclm/preview.py +414 -0
  72. pyclm/run_pyclm.py +298 -0
  73. pyclm/schema.py +806 -0
  74. pyclm/templates.py +165 -0
pyclm/templates.py ADDED
@@ -0,0 +1,165 @@
1
+ """
2
+ ``pyclm new``: an experiment directory from a template, ready for
3
+ ``pyclm check``. Two templates, taken from the lab's experiments: an open
4
+ loop (a moving bar, no segmentation) and a closed loop (Cellpose
5
+ segmentation and a per-cell pattern). Nothing is overwritten.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+
12
+ SCHEDULE = """# Timing shared by every experiment in this directory
13
+ [timing]
14
+ steps = 60 # number of timepoints
15
+ interval_seconds = 60 # seconds between timepoints
16
+ setup_time_seconds = 3.0 # seconds before each timepoint at which its events are prepared
17
+ time_between_positions = 3.0 # seconds between successive positions within a timepoint
18
+ """
19
+
20
+ CONFIG = """# Hardware and output configuration (edit config_path and the DMD calibration)
21
+ config_path = "C:\\\\Program Files\\\\Micro-Manager-2.0\\\\MMConfig.cfg"
22
+
23
+ # camera -> DMD affine [[a, b, tx], [c, d, ty]] from the MicroManager Projector calibration
24
+ affine_transform = [[-0.289, -0.001, 938.103], [0.003, -0.58, 1500.888]]
25
+ slm_shape_h = 1140
26
+ slm_shape_w = 912
27
+
28
+ focus_device = "ZDrive" # MicroManager focus (Z) device
29
+ settle_time_seconds = 1.0 # wait after the hardware reports ready, before each snap
30
+
31
+ [output]
32
+ format = "ome-zarr" # or "hdf5"
33
+ pattern_policy = "on_change" # DMD patterns stored: on_change | imaging | none
34
+ export_imagej = true # ImageJ hyperstacks when the run ends
35
+ """
36
+
37
+ OPEN_LOOP = """# {name}.toml: an open-loop experiment (a bar of light moving across the field)
38
+ # Positions named "{name}.<anything>" in the position list use this file.
39
+ format_version = 1
40
+
41
+ [config_groups] # applied to every acquisition
42
+ Objective = "20x"
43
+
44
+ [imaging] # defaults for the imaging channels
45
+ exposure = 200 # ms
46
+ every_t = 5 # image every 5th timepoint
47
+ save = true
48
+ binning = 1
49
+
50
+ [imaging.config_groups]
51
+ LightPath = "Fluor"
52
+
53
+ [channels] # which presets of which config group to image
54
+ group = "Channel"
55
+ presets = ["545"]
56
+
57
+ [stimulation] # the light delivery (DMD) event
58
+ exposure = 500
59
+ every_t = 1
60
+ save = false # keep the camera frame taken during stimulation?
61
+
62
+ [stimulation.config_groups]
63
+ Channel = "DMD"
64
+ LightPath = "DMD"
65
+
66
+ [pattern]
67
+ method = "bar" # see the method zoo in the documentation
68
+ duty_cycle = 0.2
69
+ bar_speed = 1.0 # um per minute
70
+ period = 100 # um
71
+ """
72
+
73
+ CLOSED_LOOP = """# {name}.toml: a closed-loop experiment (segment cells, light the half of each cell facing out)
74
+ # Positions named "{name}.<anything>" in the position list use this file.
75
+ format_version = 1
76
+
77
+ [config_groups] # applied to every acquisition
78
+ Objective = "20x"
79
+
80
+ [imaging] # defaults for the imaging channels
81
+ exposure = 200 # ms
82
+ every_t = 5 # image every 5th timepoint
83
+ save = true
84
+ binning = 1
85
+
86
+ [imaging.config_groups]
87
+ LightPath = "Fluor"
88
+
89
+ [channels] # which presets of which config group to image
90
+ group = "Channel"
91
+ presets = ["545"]
92
+
93
+ [stimulation] # the light delivery (DMD) event
94
+ exposure = 500
95
+ every_t = 1
96
+ save = false
97
+
98
+ [stimulation.config_groups]
99
+ Channel = "DMD"
100
+ LightPath = "DMD"
101
+
102
+ [segmentation] # runs on the frames the pattern method asks for
103
+ method = "cellpose"
104
+ model = "cpsam"
105
+
106
+ # [tracking] # uncomment to give cells lasting identities
107
+ # method = "centroid"
108
+ # max_distance_um = 20
109
+
110
+ [pattern]
111
+ method = "move_out" # per-cell: light the outward-facing half of each cell
112
+ channel = "545"
113
+ # tracks = true # run the per-cell loop on tracked cells (needs [tracking])
114
+ """
115
+
116
+ README = """This directory was created by `pyclm new`.
117
+
118
+ {name}.toml the experiment: channels, stimulation, segmentation, pattern
119
+ schedule.toml timepoints and interval
120
+ pyclm_config.toml the microscope: MicroManager .cfg path, DMD calibration, output format
121
+
122
+ Next steps
123
+ 1. Export a position list from MicroManager as PositionList.pos into this
124
+ directory. Name each position "{name}.<something>" so it uses {name}.toml.
125
+ 2. Edit the three TOML files (presets, exposures, the method and its arguments).
126
+ 3. pyclm check <this directory> reports anything that is wrong
127
+ 4. pyclm preview <this directory> {name} --image some_frame.tif
128
+ shows what the pattern method would do
129
+ 5. pyclm run <this directory> runs it (add --dry to rehearse on the virtual microscope)
130
+ """
131
+
132
+ TEMPLATES = {
133
+ "open-loop": OPEN_LOOP,
134
+ "closed-loop": CLOSED_LOOP,
135
+ }
136
+
137
+
138
+ def create(
139
+ directory: Path, template: str = "closed-loop", name: str = "experiment"
140
+ ) -> list[Path]:
141
+ """Write the template files into ``directory`` (created if needed); existing files are kept."""
142
+ if template not in TEMPLATES:
143
+ raise ValueError(
144
+ f"unknown template {template!r}; choose from {sorted(TEMPLATES)}"
145
+ )
146
+ if not name or "." in name or "/" in name or "\\" in name:
147
+ raise ValueError(
148
+ "the experiment name must be a plain word (no dots or slashes)"
149
+ )
150
+ directory = Path(directory)
151
+ directory.mkdir(parents=True, exist_ok=True)
152
+ files = {
153
+ f"{name}.toml": TEMPLATES[template].format(name=name),
154
+ "schedule.toml": SCHEDULE,
155
+ "pyclm_config.toml": CONFIG,
156
+ "README.txt": README.format(name=name),
157
+ }
158
+ written = []
159
+ for filename, text in files.items():
160
+ path = directory / filename
161
+ if path.exists():
162
+ continue
163
+ path.write_text(text, encoding="utf-8")
164
+ written.append(path)
165
+ return written