Skip to content

Commit bacd9ba

Browse files
committed
update
1 parent edc8df8 commit bacd9ba

2 files changed

Lines changed: 91 additions & 30 deletions

File tree

README.rst

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ Simulate a simple flow cytometer experiment:
6060

6161
.. code-block:: python
6262
63+
# %%
64+
# Step 0: Global Settings and Imports
65+
# -----------------------------------
66+
import numpy as np
6367
from TypedUnit import ureg
64-
import os
65-
dir_path = os.path.dirname(os.path.realpath(__file__))
6668
6769
# %%
6870
# Step 1: Define Flow Cell and Fluidics
6971
# -------------------------------------
70-
from FlowCyPy.flow_cell import FlowCell
71-
from FlowCyPy.fluidics import Fluidics, ScattererCollection, distribution, population
72+
from FlowCyPy.fluidics import FlowCell
73+
from FlowCyPy.fluidics import Fluidics, ScattererCollection, population
74+
from FlowCyPy.sampling_method import GammaModel, ExplicitModel
75+
from FlowCyPy.fluidics import distributions
7276
7377
flow_cell = FlowCell(
7478
sample_volume_flow=80 * ureg.microliter / ureg.minute,
@@ -77,25 +81,54 @@ Simulate a simple flow cytometer experiment:
7781
height=100 * ureg.micrometer,
7882
)
7983
80-
scatterer_collection = ScattererCollection(medium_refractive_index=1.33 * ureg.RIU)
84+
scatterer_collection = ScattererCollection()
85+
86+
medium_refractive_index = distributions.Delta(1.33 * ureg.RIU)
87+
88+
diameter_dist = distributions.RosinRammler(
89+
shape=150 * ureg.nanometer,
90+
scale=50 * ureg.nanometer,
91+
low_cutoff=50.0 * ureg.nanometer,
92+
)
93+
94+
ri_dist = distributions.Normal(
95+
mean=1.44 * ureg.RIU,
96+
standard_deviation=0.002 * ureg.RIU,
97+
low_cutoff=1.33 * ureg.RIU,
98+
)
8199
82100
population_0 = population.Sphere(
83101
name="Pop 0",
84-
particle_count=5e9 * ureg.particle / ureg.milliliter,
85-
diameter=distribution.RosinRammler(150 * ureg.nanometer, spread=30),
86-
refractive_index=distribution.Normal(1.44 * ureg.RIU, std_dev=0.002 * ureg.RIU),
102+
medium_refractive_index=medium_refractive_index,
103+
concentration=5e10 * ureg.particle / ureg.milliliter,
104+
diameter=diameter_dist,
105+
refractive_index=ri_dist,
106+
)
107+
108+
109+
diameter_dist = distributions.RosinRammler(
110+
shape=50 * ureg.nanometer,
111+
scale=50 * ureg.nanometer,
112+
)
113+
114+
ri_dist = distributions.Normal(
115+
mean=1.44 * ureg.RIU,
116+
standard_deviation=0.002 * ureg.RIU,
117+
low_cutoff=1.33 * ureg.RIU,
87118
)
88119
89120
population_1 = population.Sphere(
90121
name="Pop 1",
91-
particle_count=5e9 * ureg.particle / ureg.milliliter,
92-
diameter=distribution.RosinRammler(200 * ureg.nanometer, spread=30),
93-
refractive_index=distribution.Normal(1.44 * ureg.RIU, std_dev=0.002 * ureg.RIU),
122+
medium_refractive_index=medium_refractive_index,
123+
concentration=5e17 * ureg.particle / ureg.milliliter,
124+
diameter=diameter_dist,
125+
refractive_index=ri_dist,
126+
sampling_method=GammaModel(mc_samples=10_000),
94127
)
95128
96-
scatterer_collection.add_population(population_0, population_1)
129+
scatterer_collection.add_population(population_0)
97130
98-
scatterer_collection.dilute(factor=30)
131+
scatterer_collection.dilute(factor=280)
99132
100133
fluidics = Fluidics(scatterer_collection=scatterer_collection, flow_cell=flow_cell)
101134
@@ -111,21 +144,21 @@ Simulate a simple flow cytometer experiment:
111144
112145
source = source.GaussianBeam(
113146
numerical_aperture=0.1 * ureg.AU,
114-
wavelength=450 * ureg.nanometer,
147+
wavelength=405 * ureg.nanometer,
115148
optical_power=200 * ureg.milliwatt,
116-
RIN=-140,
149+
RIN=-180,
117150
)
118151
119152
detectors = [
120153
Detector(
121-
name="forward",
122-
phi_angle=0 * ureg.degree,
154+
name="side",
155+
phi_angle=90 * ureg.degree,
123156
numerical_aperture=0.3 * ureg.AU,
124157
responsivity=1 * ureg.ampere / ureg.watt,
125158
),
126159
Detector(
127-
name="side",
128-
phi_angle=90 * ureg.degree,
160+
name="forward",
161+
phi_angle=0 * ureg.degree,
129162
numerical_aperture=0.3 * ureg.AU,
130163
responsivity=1 * ureg.ampere / ureg.watt,
131164
),
@@ -165,7 +198,7 @@ Simulate a simple flow cytometer experiment:
165198
166199
triggering = triggering_system.DynamicWindow(
167200
trigger_detector_name="forward",
168-
threshold=10 * ureg.microvolt,
201+
threshold="4sigma",
169202
pre_buffer=20,
170203
post_buffer=20,
171204
max_triggers=-1,
@@ -192,18 +225,50 @@ Simulate a simple flow cytometer experiment:
192225
background_power=0.001 * ureg.milliwatt,
193226
)
194227
195-
run_record = cytometer.run(run_time=1.5 * ureg.millisecond)
228+
run_record = cytometer.run(run_time=3 * ureg.millisecond)
229+
230+
_ = run_record.event_collection.plot(x="Diameter")
196231
197232
# %%
198233
# Step 5: Plot Events and Raw Analog Signals
199234
# ------------------------------------------
200-
_ = run_record.events.plot(
201-
x="Diameter",
202-
y="RefractiveIndex",
203-
show=False,
204-
save_as=f"{dir_path}/../images/readme_events.png",
235+
_ = run_record.event_collection.plot(x="forward")
236+
237+
238+
# %%
239+
# Plot raw analog signals
240+
# -----------------------
241+
_ = run_record.plot_analog(figure_size=(12, 8))
242+
243+
244+
# %%
245+
# Step 6: Plot Triggered Analog Segments
246+
# --------------------------------------
247+
_ = run_record.plot_digital(figure_size=(12, 8))
248+
249+
250+
# %%
251+
# Step 7: Plot Peak Features
252+
# --------------------------
253+
_ = run_record.peaks.plot(x=("forward", "Height"))
254+
255+
256+
# %%
257+
# Step 8: Classify Events from Peak Features
258+
# ------------------------------------------
259+
from FlowCyPy.classifier import KmeansClassifier
260+
261+
classifier = KmeansClassifier(number_of_clusters=2)
262+
263+
classified = classifier.run(
264+
dataframe=run_record.peaks.unstack("Detector"),
265+
features=["Height"],
266+
detectors=["side", "forward"],
205267
)
206268
269+
_ = classified.plot(x=("side", "Height"), y=("forward", "Height"))
270+
271+
207272
|readme_events|
208273

209274

docs/examples/tutorials/workflow.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
SimulationSettings.assume_perfect_hydrodynamic_focusing = True
3333
SimulationSettings.population_cutoff_bypass = False
3434

35-
np.random.seed(3)
36-
37-
from TypedUnit import RefractiveIndex
38-
3935
# %%
4036
# Step 1: Define Flow Cell and Fluidics
4137
# -------------------------------------

0 commit comments

Comments
 (0)