maicroscopy-sandbox 0.3.0__tar.gz
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.
- maicroscopy_sandbox-0.3.0/LICENSE.txt +21 -0
- maicroscopy_sandbox-0.3.0/PKG-INFO +519 -0
- maicroscopy_sandbox-0.3.0/README.md +477 -0
- maicroscopy_sandbox-0.3.0/pyproject.toml +88 -0
- maicroscopy_sandbox-0.3.0/setup.cfg +4 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/__init__.py +17 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/fluorescence_sim.py +170 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/maicroscopy_sandbox.py +383 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/samples/__init__.py +0 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/samples/binary.py +43 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/samples/ellipsoid.py +143 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/samples/sample.py +45 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox/samples/staph.py +816 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox.egg-info/PKG-INFO +519 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox.egg-info/SOURCES.txt +17 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox.egg-info/dependency_links.txt +1 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox.egg-info/requires.txt +21 -0
- maicroscopy_sandbox-0.3.0/src/maicroscopy_sandbox.egg-info/top_level.txt +1 -0
- maicroscopy_sandbox-0.3.0/tests/test_maicroscopy_sandbox.py +664 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [Ricardo Henriques <ricardo@henriqueslab.org>]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: maicroscopy_sandbox
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Fluorescence microscopy simulation toolkit for synthetic microscopy experiments.
|
|
5
|
+
Author-email: Bruno Saraiva <bruno.msaraiva2@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/HenriquesLab/mAIcroscopysandbox
|
|
8
|
+
Project-URL: Repository, https://github.com/HenriquesLab/mAIcroscopysandbox
|
|
9
|
+
Project-URL: Issues, https://github.com/HenriquesLab/mAIcroscopysandbox/issues
|
|
10
|
+
Keywords: microscopy,simulation,fluorescence,bioimaging
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE.txt
|
|
22
|
+
Requires-Dist: matplotlib>=3.10.9
|
|
23
|
+
Requires-Dist: numba
|
|
24
|
+
Requires-Dist: numpy<2
|
|
25
|
+
Requires-Dist: scikit-image
|
|
26
|
+
Requires-Dist: scipy
|
|
27
|
+
Requires-Dist: stackview>=0.19.1
|
|
28
|
+
Requires-Dist: tifffile
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build>=1.2.2; extra == "dev"
|
|
31
|
+
Requires-Dist: ipykernel>=6.29.4; extra == "dev"
|
|
32
|
+
Requires-Dist: pdoc>=12.3.1; extra == "dev"
|
|
33
|
+
Requires-Dist: pre-commit>=3.7.0; extra == "dev"
|
|
34
|
+
Requires-Dist: ruff>=0.4.3; extra == "dev"
|
|
35
|
+
Requires-Dist: twine>=5.1.1; extra == "dev"
|
|
36
|
+
Provides-Extra: test
|
|
37
|
+
Requires-Dist: coverage[toml]>=7.6.1; extra == "test"
|
|
38
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
39
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "test"
|
|
40
|
+
Requires-Dist: pytest-xdist>=3.6.1; extra == "test"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# mAIcroscopy Sandbox
|
|
44
|
+
|
|
45
|
+
[](https://opensource.org/licenses/MIT)
|
|
46
|
+
[](https://www.python.org/downloads/)
|
|
47
|
+
|
|
48
|
+
A Python package for simulating realistic fluorescence microscopy experiments with biological samples. Perfect for testing super-resolution algorithms, training AI models, and teaching microscopy concepts.
|
|
49
|
+
|
|
50
|
+
For installation, usage, and contribution instructions, see:
|
|
51
|
+
|
|
52
|
+
- [INSTALL.md](INSTALL.md)
|
|
53
|
+
- [USAGE.md](USAGE.md)
|
|
54
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- ๐ฌ **Realistic Microscopy Simulation**: Accurate modeling of photon noise, bleaching, and detector characteristics
|
|
59
|
+
- ๐ฆ **Bacterial Cell Dynamics**: Simulate *Staphylococcus*-like cells with growth, septum formation, and division
|
|
60
|
+
- ๐ธ **Stage Control**: Move and scan across large samples with precise positioning
|
|
61
|
+
- ๐ **Laser Control**: Adjustable laser power with realistic photobleaching effects
|
|
62
|
+
- ๐งช **Extensible**: Easy to create custom sample types and imaging modalities
|
|
63
|
+
|
|
64
|
+
## Table of Contents
|
|
65
|
+
|
|
66
|
+
- [Installation](#installation)
|
|
67
|
+
- [Quick Start](#quick-start)
|
|
68
|
+
- [Usage Examples](#usage-examples)
|
|
69
|
+
- [Basic Microscopy Simulation](#basic-microscopy-simulation)
|
|
70
|
+
- [Bacterial Cell Simulation](#bacterial-cell-simulation)
|
|
71
|
+
- [Time-Lapse Imaging](#time-lapse-imaging)
|
|
72
|
+
- [API Reference](#api-reference)
|
|
73
|
+
- [Advanced Usage](#advanced-usage)
|
|
74
|
+
- [Contributing](#contributing)
|
|
75
|
+
- [License](#license)
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
### Requirements
|
|
80
|
+
|
|
81
|
+
- Python 3.10 or higher
|
|
82
|
+
- pip package manager
|
|
83
|
+
|
|
84
|
+
### Install from source
|
|
85
|
+
|
|
86
|
+
1. Clone the repository:
|
|
87
|
+
```bash
|
|
88
|
+
git clone https://github.com/HenriquesLab/mAIcroscopysandbox.git
|
|
89
|
+
cd mAIcroscopysandbox
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
2. Install the package:
|
|
93
|
+
```bash
|
|
94
|
+
pip install -e .
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
3. For development (includes testing and linting tools):
|
|
98
|
+
```bash
|
|
99
|
+
pip install -e ".[dev,test]"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Local CI
|
|
103
|
+
|
|
104
|
+
Run the same lint, test, coverage, and build checks used by the automation:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
./scripts/run_ci_locally.sh
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Dependencies
|
|
111
|
+
|
|
112
|
+
The package automatically installs the following dependencies:
|
|
113
|
+
- `numpy<2` - Numerical computing
|
|
114
|
+
- `scikit-image` - Image processing
|
|
115
|
+
- `numba` - JIT compilation for performance
|
|
116
|
+
- `scipy` - Morphology and filtering utilities
|
|
117
|
+
- `tifffile` - Binary sample loading and TIFF export
|
|
118
|
+
|
|
119
|
+
## Quick Start
|
|
120
|
+
|
|
121
|
+
Here's a minimal example to get you started:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import numpy as np
|
|
125
|
+
from matplotlib import pyplot as plt
|
|
126
|
+
from maicroscopy_sandbox import mAIcroscopySandbox
|
|
127
|
+
from maicroscopy_sandbox.samples.staph import StaphMembrane
|
|
128
|
+
|
|
129
|
+
# Create a virtual microscope
|
|
130
|
+
microscope = mAIcroscopySandbox(
|
|
131
|
+
fov_size=[500, 500], # Field of view in pixels
|
|
132
|
+
laser_intensity=1000 # Photons per pixel
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# Create a bacterial cell sample
|
|
136
|
+
sample = StaphMembrane(
|
|
137
|
+
sample_size=microscope.stage_size,
|
|
138
|
+
n_objects=5, # Number of cells
|
|
139
|
+
pixel_size=30 # nm per pixel
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Load sample and acquire image
|
|
143
|
+
microscope.set_laser_power(100)
|
|
144
|
+
frame = microscope.load_sample(sample, acquire=True)
|
|
145
|
+
|
|
146
|
+
# Display the image
|
|
147
|
+
plt.imshow(frame, cmap="gray")
|
|
148
|
+
plt.title("Simulated Fluorescence Microscopy")
|
|
149
|
+
plt.colorbar(label="Intensity (ADU)")
|
|
150
|
+
plt.show()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Usage Examples
|
|
154
|
+
|
|
155
|
+
### Basic Microscopy Simulation
|
|
156
|
+
|
|
157
|
+
Control the microscope stage and laser settings:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from maicroscopy_sandbox import mAIcroscopySandbox
|
|
161
|
+
from maicroscopy_sandbox.samples.ellipsoid import Ellipsoid
|
|
162
|
+
|
|
163
|
+
# Initialize microscope
|
|
164
|
+
microscope = mAIcroscopySandbox(
|
|
165
|
+
stage_size=[5000, 5000],
|
|
166
|
+
fov_size=[300, 300],
|
|
167
|
+
laser_intensity=100000
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Configure detector parameters
|
|
171
|
+
microscope.set_readout_noise(50) # Camera noise
|
|
172
|
+
microscope.set_ADC_offset(100) # Baseline offset
|
|
173
|
+
microscope.set_gaussian_sigma(2.0) # PSF blur
|
|
174
|
+
|
|
175
|
+
# Create and load a simple ellipsoid sample
|
|
176
|
+
sample = Ellipsoid(
|
|
177
|
+
sample_size=microscope.stage_size,
|
|
178
|
+
n_objects=10
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
# Acquire image
|
|
182
|
+
microscope.set_laser_power(50) # 50% laser power
|
|
183
|
+
frame = microscope.load_sample(sample, acquire=True)
|
|
184
|
+
|
|
185
|
+
# Move stage and acquire another image
|
|
186
|
+
new_frame = microscope.move_stage([100, 50], acquire=True)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Bacterial Cell Simulation
|
|
190
|
+
|
|
191
|
+
Simulate realistic bacterial cell growth and division:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from maicroscopy_sandbox import mAIcroscopySandbox
|
|
195
|
+
from maicroscopy_sandbox.samples.staph import StaphMembrane
|
|
196
|
+
import matplotlib.pyplot as plt
|
|
197
|
+
|
|
198
|
+
# Create microscope
|
|
199
|
+
microscope = mAIcroscopySandbox(fov_size=[500, 500], laser_intensity=1000)
|
|
200
|
+
|
|
201
|
+
# Create bacterial sample with specific parameters
|
|
202
|
+
sample = StaphMembrane(
|
|
203
|
+
sample_size=microscope.stage_size,
|
|
204
|
+
n_objects=3, # Initial number of cells
|
|
205
|
+
pixel_size=30, # 30 nm/pixel
|
|
206
|
+
bleaching_rate=0.05, # 5% bleaching per frame
|
|
207
|
+
progression_rate=10, # Cell cycle progression speed
|
|
208
|
+
p1_rate=42, # Growth phase percentage
|
|
209
|
+
p2_rate=29 # Septum formation percentage
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
# Load sample
|
|
213
|
+
microscope.set_laser_power(100)
|
|
214
|
+
frame = microscope.load_sample(sample, acquire=True)
|
|
215
|
+
|
|
216
|
+
# Visualize
|
|
217
|
+
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
|
|
218
|
+
ax.imshow(frame, cmap="gray")
|
|
219
|
+
ax.set_title("Bacterial Membrane Simulation")
|
|
220
|
+
ax.axis('off')
|
|
221
|
+
plt.tight_layout()
|
|
222
|
+
plt.show()
|
|
223
|
+
|
|
224
|
+
# Access cell information
|
|
225
|
+
print(f"Number of cells: {len(sample.cells)}")
|
|
226
|
+
for cell_id, cell in sample.cells.items():
|
|
227
|
+
print(f"Cell {cell_id}: progression={cell.progression}%")
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Time-Lapse Imaging
|
|
231
|
+
|
|
232
|
+
Capture a time series showing cell dynamics:
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from maicroscopy_sandbox import mAIcroscopySandbox
|
|
236
|
+
from maicroscopy_sandbox.samples.staph import StaphMembrane
|
|
237
|
+
import matplotlib.pyplot as plt
|
|
238
|
+
|
|
239
|
+
# Setup
|
|
240
|
+
microscope = mAIcroscopySandbox(fov_size=[500, 500], laser_intensity=1000)
|
|
241
|
+
sample = StaphMembrane(
|
|
242
|
+
sample_size=microscope.stage_size,
|
|
243
|
+
n_objects=1,
|
|
244
|
+
pixel_size=30,
|
|
245
|
+
progression_rate=20 # Faster progression for demo
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
microscope.set_laser_power(100)
|
|
249
|
+
microscope.load_sample(sample)
|
|
250
|
+
|
|
251
|
+
# Acquire time series
|
|
252
|
+
n_frames = 10
|
|
253
|
+
frames = []
|
|
254
|
+
|
|
255
|
+
for i in range(n_frames):
|
|
256
|
+
frame = microscope.acquire_image()
|
|
257
|
+
frames.append(frame)
|
|
258
|
+
print(f"Frame {i+1}/{n_frames}: {len(sample.cells)} cells")
|
|
259
|
+
|
|
260
|
+
# Display montage
|
|
261
|
+
fig, axes = plt.subplots(2, 5, figsize=(15, 6))
|
|
262
|
+
for i, (ax, frame) in enumerate(zip(axes.flat, frames)):
|
|
263
|
+
ax.imshow(frame, cmap="gray")
|
|
264
|
+
ax.set_title(f"t={i}")
|
|
265
|
+
ax.axis('off')
|
|
266
|
+
plt.tight_layout()
|
|
267
|
+
plt.show()
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## API Reference
|
|
271
|
+
|
|
272
|
+
### mAIcroscopySandbox
|
|
273
|
+
|
|
274
|
+
Main microscope simulation class.
|
|
275
|
+
|
|
276
|
+
#### Constructor Parameters
|
|
277
|
+
- `stage_size` (array): Stage size in pixels [height, width]. Default: [5000, 5000]
|
|
278
|
+
- `fov_size` (array): Field of view in pixels [height, width]. Default: [300, 300]
|
|
279
|
+
- `laser_intensity` (float): Maximum laser intensity in photons/pixel. Default: 100000
|
|
280
|
+
- `pixel_size` (float): Physical pixel size in nanometers. Default: 100
|
|
281
|
+
|
|
282
|
+
#### Key Methods
|
|
283
|
+
- `load_sample(sample, acquire=False)`: Load a sample onto the stage
|
|
284
|
+
- `acquire_image()`: Capture an image at the current position
|
|
285
|
+
- `move_stage(movement, acquire=False)`: Move stage by offset [row, col]
|
|
286
|
+
- `set_laser_power(power)`: Set laser power (0-100%)
|
|
287
|
+
- `set_readout_noise(noise)`: Set camera readout noise
|
|
288
|
+
- `set_gaussian_sigma(sigma)`: Set PSF blur amount
|
|
289
|
+
|
|
290
|
+
### StaphMembrane
|
|
291
|
+
|
|
292
|
+
Bacterial cell sample with growth and division.
|
|
293
|
+
|
|
294
|
+
#### Constructor Parameters
|
|
295
|
+
- `sample_size` (array): Sample area in pixels. Default: [1000, 1000]
|
|
296
|
+
- `n_objects` (int): Initial number of cells. Default: 1
|
|
297
|
+
- `pixel_size` (int): Pixel size in nanometers. Default: 100
|
|
298
|
+
- `bleaching_rate` (float): Bleaching rate per frame. Default: 0.001
|
|
299
|
+
- `progression_rate` (int): Cell cycle progression speed. Default: 2
|
|
300
|
+
- `p1_rate` (int): Growth phase percentage. Default: 42
|
|
301
|
+
- `p2_rate` (int): Septum formation percentage. Default: 29
|
|
302
|
+
|
|
303
|
+
#### Cell Attributes
|
|
304
|
+
Each cell in `sample.cells` has:
|
|
305
|
+
- `center_row`, `center_col`: Position
|
|
306
|
+
- `major_axis`, `minor_axis`: Size
|
|
307
|
+
- `orientation`: Angle in radians
|
|
308
|
+
- `progression`: Cell cycle progress (0-100%)
|
|
309
|
+
- `p1`, `p2`, `p3`: Phase boundaries
|
|
310
|
+
|
|
311
|
+
## Advanced Usage
|
|
312
|
+
|
|
313
|
+
### Creating Custom Samples
|
|
314
|
+
|
|
315
|
+
Extend the `Sample` base class to create custom samples:
|
|
316
|
+
|
|
317
|
+
```python
|
|
318
|
+
from maicroscopy_sandbox.samples.sample import Sample
|
|
319
|
+
import numpy as np
|
|
320
|
+
|
|
321
|
+
class CustomSample(Sample):
|
|
322
|
+
def __init__(self, sample_size=[1000, 1000], **kwargs):
|
|
323
|
+
super().__init__(sample_size=sample_size, **kwargs)
|
|
324
|
+
# Your initialization code
|
|
325
|
+
|
|
326
|
+
def generate_mask(self):
|
|
327
|
+
# Return 2D array with fluorophore distribution
|
|
328
|
+
mask = np.zeros(self.sample_size, dtype=np.float32)
|
|
329
|
+
# ... your custom mask generation ...
|
|
330
|
+
return mask
|
|
331
|
+
|
|
332
|
+
def calculate_dynamics(self):
|
|
333
|
+
# Update sample state between frames
|
|
334
|
+
pass
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Adjusting Optical Parameters
|
|
338
|
+
|
|
339
|
+
Fine-tune the microscope optics:
|
|
340
|
+
|
|
341
|
+
```python
|
|
342
|
+
microscope.set_wavelenght(488) # Excitation wavelength (nm)
|
|
343
|
+
microscope.set_NA(1.4) # Numerical aperture
|
|
344
|
+
microscope.set_sigma(0.21) # Fluorophore emission spread
|
|
345
|
+
microscope.set_ADC_per_photon_conversion(1.5) # Detector gain
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Photobleaching Control
|
|
349
|
+
|
|
350
|
+
Monitor and control photobleaching:
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
# Create sample with high bleaching
|
|
354
|
+
sample = StaphMembrane(
|
|
355
|
+
sample_size=microscope.stage_size,
|
|
356
|
+
bleaching_rate=0.1 # 10% per frame
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
microscope.load_sample(sample)
|
|
360
|
+
|
|
361
|
+
# Reduce laser power to minimize bleaching
|
|
362
|
+
microscope.set_laser_power(30) # 30% power
|
|
363
|
+
|
|
364
|
+
# Acquire multiple frames
|
|
365
|
+
for i in range(10):
|
|
366
|
+
frame = microscope.acquire_image()
|
|
367
|
+
# Bleaching is automatically applied
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Saving Time-Lapse Data
|
|
371
|
+
|
|
372
|
+
Export image sequences:
|
|
373
|
+
|
|
374
|
+
```python
|
|
375
|
+
import tifffile
|
|
376
|
+
import numpy as np
|
|
377
|
+
|
|
378
|
+
frames = []
|
|
379
|
+
for i in range(100):
|
|
380
|
+
frame = microscope.acquire_image()
|
|
381
|
+
frames.append(frame)
|
|
382
|
+
|
|
383
|
+
# Save as multi-page TIFF
|
|
384
|
+
stack = np.stack(frames, axis=0)
|
|
385
|
+
tifffile.imwrite("timelapse.tif", stack)
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Project Structure
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
mAIcroscopysandbox/
|
|
392
|
+
โโโ .github/
|
|
393
|
+
โ โโโ workflows/
|
|
394
|
+
โ โโโ ci.yml
|
|
395
|
+
โ โโโ publish.yml
|
|
396
|
+
โโโ src/
|
|
397
|
+
โ โโโ maicroscopy_sandbox/
|
|
398
|
+
โ โโโ __init__.py
|
|
399
|
+
โ โโโ maicroscopy_sandbox.py # Main microscope class
|
|
400
|
+
โ โโโ fluorescence_sim.py # Image generation
|
|
401
|
+
โ โโโ samples/
|
|
402
|
+
โ โโโ __init__.py
|
|
403
|
+
โ โโโ sample.py # Base sample class
|
|
404
|
+
โ โโโ staph.py # Bacterial cells
|
|
405
|
+
โ โโโ ellipsoid.py # Simple ellipsoids
|
|
406
|
+
โ โโโ binary.py # Binary structures
|
|
407
|
+
โโโ scripts/
|
|
408
|
+
โ โโโ run_ci_locally.sh
|
|
409
|
+
โ โโโ release_to_pypi.sh
|
|
410
|
+
โโโ notebooks/
|
|
411
|
+
โ โโโ example_usage.ipynb # Usage examples
|
|
412
|
+
โ โโโ example_from_binary.ipynb # Binary sample demo
|
|
413
|
+
โโโ tests/
|
|
414
|
+
โ โโโ test_maicroscopy_sandbox.py
|
|
415
|
+
โโโ noxfile.py
|
|
416
|
+
โโโ Makefile
|
|
417
|
+
โโโ README.md
|
|
418
|
+
โโโ pyproject.toml
|
|
419
|
+
โโโ LICENSE.txt
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Contributing
|
|
423
|
+
|
|
424
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
|
|
425
|
+
|
|
426
|
+
1. Fork the repository
|
|
427
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
428
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
429
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
430
|
+
5. Open a Pull Request
|
|
431
|
+
|
|
432
|
+
### Development Setup
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
# Clone the repo
|
|
436
|
+
git clone https://github.com/HenriquesLab/mAIcroscopysandbox.git
|
|
437
|
+
cd mAIcroscopysandbox
|
|
438
|
+
|
|
439
|
+
# Install in development mode with all extras
|
|
440
|
+
pip install -e ".[dev,test]"
|
|
441
|
+
|
|
442
|
+
# Run tests
|
|
443
|
+
pytest
|
|
444
|
+
|
|
445
|
+
# Or run the full local CI flow
|
|
446
|
+
./scripts/run_ci_locally.sh
|
|
447
|
+
|
|
448
|
+
# Run linter
|
|
449
|
+
ruff check src/
|
|
450
|
+
|
|
451
|
+
# Format code
|
|
452
|
+
ruff format src/
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Release Automation
|
|
456
|
+
|
|
457
|
+
- GitHub Actions CI lives in `.github/workflows/ci.yml`
|
|
458
|
+
- PyPI publishing lives in `.github/workflows/publish.yml`
|
|
459
|
+
- Local release validation and optional upload lives in:
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
./scripts/release_to_pypi.sh
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
If `PYPI_TOKEN` is unset, the script stops after test, build, and distribution validation.
|
|
466
|
+
|
|
467
|
+
## Citation
|
|
468
|
+
|
|
469
|
+
If you use this software in your research, please cite:
|
|
470
|
+
|
|
471
|
+
```bibtex
|
|
472
|
+
@software{maicroscopy_sandbox,
|
|
473
|
+
author = {Saraiva, Bruno},
|
|
474
|
+
title = {mAIcroscopy Sandbox: Realistic Fluorescence Microscopy Simulation},
|
|
475
|
+
year = {2025},
|
|
476
|
+
publisher = {GitHub},
|
|
477
|
+
url = {https://github.com/HenriquesLab/mAIcroscopysandbox}
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
## License
|
|
482
|
+
|
|
483
|
+
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
|
|
484
|
+
|
|
485
|
+
## Acknowledgments
|
|
486
|
+
|
|
487
|
+
- Developed at the Henriques Lab
|
|
488
|
+
- Built on scikit-image, scipy, and numpy
|
|
489
|
+
- Inspired by real microscopy workflows and challenges
|
|
490
|
+
|
|
491
|
+
## Contact
|
|
492
|
+
|
|
493
|
+
- **Author**: Bruno Saraiva
|
|
494
|
+
- **Email**: bruno.msaraiva2@gmail.com
|
|
495
|
+
- **Lab**: [Henriques Lab](https://henriqueslab.github.io/)
|
|
496
|
+
|
|
497
|
+
## Troubleshooting
|
|
498
|
+
|
|
499
|
+
### Common Issues
|
|
500
|
+
|
|
501
|
+
**ImportError: No module named 'maicroscopy_sandbox'**
|
|
502
|
+
- Make sure you installed the package: `pip install -e .`
|
|
503
|
+
- Check you're in the correct virtual environment
|
|
504
|
+
|
|
505
|
+
**Cells not appearing/disappearing**
|
|
506
|
+
- Restart the Jupyter kernel after code changes
|
|
507
|
+
- The module caches the old version until restart
|
|
508
|
+
|
|
509
|
+
**Slow performance**
|
|
510
|
+
- Reduce `fov_size` for faster rendering
|
|
511
|
+
- Lower `n_objects` to simulate fewer cells
|
|
512
|
+
- Disable plotting during time-lapse acquisition
|
|
513
|
+
|
|
514
|
+
**Images too dark/bright**
|
|
515
|
+
- Adjust `laser_intensity` and `laser_power`
|
|
516
|
+
- Check `ADC_per_photon_conversion` and `ADC_offset`
|
|
517
|
+
- Verify sample mask has appropriate fluorophore density
|
|
518
|
+
|
|
519
|
+
For more help, please [open an issue](https://github.com/HenriquesLab/mAIcroscopysandbox/issues) on GitHub.
|