.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/noise_sources/shot_noise.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_noise_sources_shot_noise.py: Shot noise ========== This example demonstrates the effect of different optical power levels on a flow cytometer detector. We initialize the detector, apply varying optical power levels, and visualize the resulting signals and their distributions. .. GENERATED FROM PYTHON SOURCE LINES 10-66 .. image-sg:: /gallery/noise_sources/images/sphx_glr_shot_noise_001.png :alt: Raw Signals at Different Optical Powers, Histogram of Raw Signals :srcset: /gallery/noise_sources/images/sphx_glr_shot_noise_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from FlowCyPy.detector import Detector from FlowCyPy import units import numpy from FlowCyPy import NoiseSetting NoiseSetting.include_noises = True NoiseSetting.include_shot_noise = True NoiseSetting.include_dark_current_noise = False NoiseSetting.include_source_noise = False # Define optical power levels optical_powers = [1e-9 * units.watt, 2e-9 * units.watt, 4e-9 * units.watt] # Powers in watts sequence_length = 300 # Create a figure for signal visualization fig, (ax_signal, ax_hist) = plt.subplots(2, 1, figsize=(10, 6), sharex=False) # Loop over the optical power levels for optical_power in optical_powers: optical_power_array = numpy.ones(sequence_length) * optical_power # Initialize the detector detector = Detector( name=f"{optical_power.magnitude:.1e} W", responsivity=1 * units.ampere / units.watt, numerical_aperture=0.2 * units.AU, phi_angle=0 * units.degree ) noise_current = detector.get_shot_noise( optical_power=optical_power_array, wavelength=1550 * units.nanometer, bandwidth=10 * units.megahertz ).to(units.ampere) # Plot the raw signal on the first axis ax_signal.step(numpy.arange(sequence_length), noise_current, label=detector.name) # Plot the histogram of the raw signal ax_hist.hist(noise_current, bins=50, alpha=0.6, label=detector.name) # Customize the axes ax_signal.set_title("Raw Signals at Different Optical Powers") ax_signal.set_ylabel("Signal Voltage (V)") ax_signal.legend() ax_hist.set_title("Histogram of Raw Signals") ax_hist.set_xlabel("Signal Voltage (V)") ax_hist.set_ylabel("Frequency") ax_hist.legend() # Show the plots plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.631 seconds) .. _sphx_glr_download_gallery_noise_sources_shot_noise.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: shot_noise.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: shot_noise.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: shot_noise.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_