A package for light scattering computation.
Project description
FlowCyPy: Flow Cytometer Simulation Tool
Meta |
|||
Testing |
|||
PyPi |
|||
Anaconda |
Overview
FlowCyPy is a cutting-edge Python library designed to simulate flow cytometer experiments. By generating realistic Forward Scatter (FSC) and Side Scatter (SSC) signals, FlowCyPy enables detailed modeling of flow cytometry setups, making it ideal for researchers and engineers working with extracellular vesicles (EVs) or other scatterers.
Key Features
Particle Event Simulation: Create detailed FSC/SSC signals with customizable particle size and refractive index distributions.
Noise and Signal Modeling: Incorporate realistic noise sources (thermal, shot, dark current) and baseline shifts.
Detector Configurations: Simulate real-world detector behaviors, including saturation and responsivity.
Fluorescence Modeling: Simulate fluorescence signals for labeled particles (e.g., EV surface markers).
Visualization Tools: Generate advanced plots, including density maps and signal traces.
For full documentation and examples, visit the FlowCyPy Documentation.
Installation
Install FlowCyPy via pip or conda`:
pip install FlowCyPy
conda install FlowCyPy --channels MartinPdeS
Requirements: Python 3.11 or higher with dependencies: numpy, pint, tabulate, seaborn, MPSPlots, PyMieSim, pydantic>=2.6.3
Quick Start
Simulate a simple flow cytometer experiment:
from FlowCyPy.units import ureg
from FlowCyPy.fluidics import (
Fluidics,
FlowCell,
ScattererCollection,
populations,
SampleFlowRate,
SheathFlowRate,
)
# from FlowCyPy.sampling_method import GammaModel, ExplicitModel
from FlowCyPy.fluidics import distributions
flow_cell = FlowCell(
sample_volume_flow=SampleFlowRate.MEDIUM.value,
sheath_volume_flow=SheathFlowRate.MEDIUM.value,
width=400 * ureg.micrometer,
height=150 * ureg.micrometer,
)
scatterer_collection = ScattererCollection()
medium_refractive_index = distributions.Delta(1.33)
diameter_dist = distributions.RosinRammler(
scale=200 * ureg.nanometer,
shape=10,
)
ri_dist = distributions.Normal(
mean=1.44,
standard_deviation=0.002,
low_cutoff=1.33,
)
sampling_method = populations.ExplicitModel()
population_0 = populations.SpherePopulation(
name="Pop 0",
medium_refractive_index=medium_refractive_index,
concentration=1e10 * ureg.particle / ureg.milliliter,
diameter=diameter_dist,
refractive_index=ri_dist,
sampling_method=sampling_method,
)
diameter_dist = distributions.RosinRammler(
scale=30 * ureg.nanometer,
shape=50,
)
ri_dist = distributions.Normal(
mean=1.44,
standard_deviation=0.002,
low_cutoff=1.33,
)
population_1 = populations.SpherePopulation(
name="Pop 1",
medium_refractive_index=medium_refractive_index,
concentration=5e11 * ureg.particle / ureg.milliliter,
diameter=diameter_dist,
refractive_index=ri_dist,
sampling_method=populations.GammaModel(number_of_samples=5_000),
)
scatterer_collection.add_population(population_0, population_1)
scatterer_collection.dilute(factor=80)
fluidics = Fluidics(scatterer_collection=scatterer_collection, flow_cell=flow_cell)
# %%
# Step 2: Define Optical Subsystem
# --------------------------------
from FlowCyPy.opto_electronics import (
Detector,
Digitizer,
OptoElectronics,
Amplifier,
source,
circuits,
)
analog_processing = [
circuits.BaselineRestorationServo(time_constant=100 * ureg.microsecond),
circuits.BesselLowPass(cutoff_frequency=2 * ureg.megahertz, order=4, gain=2),
]
source = source.Gaussian(
waist_z=10e-6 * ureg.meter, # Beam waist along flow direction (z-axis)
waist_y=60e-6 * ureg.meter,
wavelength=405 * ureg.nanometer,
optical_power=200 * ureg.milliwatt,
rin=-140 * ureg.dB_per_Hz,
bandwidth=10 * ureg.megahertz,
)
detectors = [
Detector(
name="side",
phi_angle=90 * ureg.degree,
numerical_aperture=1.1,
responsivity=1 * ureg.ampere / ureg.watt,
),
Detector(
name="forward",
phi_angle=0 * ureg.degree,
numerical_aperture=0.3,
cache_numerical_aperture=0.1,
responsivity=1 * ureg.ampere / ureg.watt,
),
]
digitizer = Digitizer(
sampling_rate=60 * ureg.megahertz,
bit_depth=14,
use_auto_range=True,
channel_range_mode="shared",
)
amplifier = Amplifier(
gain=10 * ureg.volt / ureg.ampere,
bandwidth=10 * ureg.megahertz,
voltage_noise_density=0.0 * ureg.nanovolt / ureg.sqrt_hertz,
current_noise_density=0.0 * ureg.femtoampere / ureg.sqrt_hertz,
)
opto_electronics = OptoElectronics(
digitizer=digitizer,
detectors=detectors,
source=source,
amplifier=amplifier,
analog_processing=analog_processing,
)
# %%
# Step 3: Signal Processing Configuration
# ---------------------------------------
from FlowCyPy.digital_processing import (
DigitalProcessing,
peak_locator,
discriminator,
)
triggering = discriminator.FixedWindow(
trigger_channel="side",
threshold="4sigma",
pre_buffer=40,
post_buffer=40,
max_triggers=-1,
)
peak_algo = peak_locator.GlobalPeakLocator()
digital_processing = DigitalProcessing(
discriminator=triggering,
peak_algorithm=peak_algo,
)
# %%
# Step 4: Run Simulation
# ----------------------
from FlowCyPy import FlowCytometer
cytometer = FlowCytometer(
fluidics=fluidics,
background_power=0.001 * ureg.milliwatt,
)
run_record = cytometer.run(
opto_electronics=opto_electronics,
digital_processing=digital_processing,
run_time=1 * ureg.millisecond,
)
run_record.event_collection.plot(x="Diameter")
run_record.event_collection.plot(x="forward")
run_record.plot_analog()
run_record.plot_digital()
run_record.peaks.plot(x=("forward", "Height"))
_ = run_record.plot_analog(
figure_size=(12, 8),
show=False,
save_as=f"{dir_path}/../images/readme_analog.png",
)
_ = run_record.plot_digital(
figure_size=(12, 8),
show=False,
save_as=f"{dir_path}/../images/readme_digital.png",
)
Explore more examples in the FlowCyPy Examples.
Code structure
Here is the architecture for a standard workflow using FlowCyPy:
Development and Contribution
Clone the Repository
git clone https://github.com/MartinPdeS/FlowCyPy.git
cd FlowCyPy
Install Locally
Install in editable mode with testing and documentation dependencies:
pip install -e .[testing,documentation] (on linux system)
pip install -e ".[testing,documentation]" (on macOS system)
Run Tests
Use pytest to validate functionality:
pytest
Build Documentation
Build the documentation locally:
cd docs
make html
Find the documentation in docs/_build/html.
Additional Resources
Documentation: Full guide and API reference at FlowCyPy Documentation
Examples: Explore use cases in the Examples Section
GitHub Repository: Access the source code and contribute at FlowCyPy GitHub
Contributions
Contributions are welcome! If you have suggestions, issues, or would like to collaborate, visit the GitHub repository.
Contact
For inquiries or collaboration, contact Martin Poinsinet de Sivry-Houle.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flowcypy-1.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: flowcypy-1.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca2f39ecb63749e2b7046caf7dab121d618e8a81a4a25bf60b6bd2d12356209a
|
|
| MD5 |
bffa525ae3264958c5b1471cc2f4959a
|
|
| BLAKE2b-256 |
dda5df42533a15eb58c8e47302e29b15440640fca63f7a3ee6a871abf540a3d8
|
File details
Details for the file flowcypy-1.0.2-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: flowcypy-1.0.2-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2bc93cfdc386fd2d3521b134876cd1f995d207c7e974dff835068a6d5e1cbfb
|
|
| MD5 |
af779ce99826bf56891541b0d169cdd9
|
|
| BLAKE2b-256 |
6a5b172819ca20d02bb52abc52c61978d36db342ee168571561b191eb9cb2b8d
|
File details
Details for the file flowcypy-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: flowcypy-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a409f2bfbdce5dcdfaf6bc5c2d0d5b6adad1de46f994ea9fc595392d1a5909
|
|
| MD5 |
41dabef1307a47255063d14b655124e6
|
|
| BLAKE2b-256 |
cb315b337476fcb3504e442a7d16231ed8860cdf765561c4aae2947c0e866d00
|
File details
Details for the file flowcypy-1.0.2-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: flowcypy-1.0.2-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7a9e58134d8cb45dd5ac5778439083f349f1bcd6692ff078abdacf7ca8f0ef7
|
|
| MD5 |
ef0d9a045b0bd374f18f8a8007e26473
|
|
| BLAKE2b-256 |
11d7f7fde35bbb90a8d6f4b6c1ba6b13141f67d15f32d10782186cc2414a86af
|
File details
Details for the file flowcypy-1.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: flowcypy-1.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e262e9eee76bb7619a4f03821971acc30dd7cc26fa73f40f465a32728fad4a
|
|
| MD5 |
1a64a01a78351c92931fc728784f1031
|
|
| BLAKE2b-256 |
0b5fc2357300874e655914d9c2ef44e5bfa60eb42ca0689f5ff5213075d8c4a9
|
File details
Details for the file flowcypy-1.0.2-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: flowcypy-1.0.2-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f68c1d2f7c3280369def267b968ed5aa27d2df46431d0bb56592fa11fd641eff
|
|
| MD5 |
b3c0e74191c8df23659b5b50af42b937
|
|
| BLAKE2b-256 |
ef038b644df95e80d523c086c5f9bbaa8bda115981e7922254bd29fb55896d1b
|