.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/experiment/cylinder/cylinder_Qabs_vs_diameter.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_experiment_cylinder_cylinder_Qabs_vs_diameter.py: Cylinder: Qabs vs Diameter ========================== This example demonstrates how to compute and visualize the scattering efficiency (Qsca) as a function of diameter for cylindrical scatterers using PyMieSim. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Importing the package dependencies: numpy, PyMieSim .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: Python import numpy as np from PyMieSim.experiment.scatterer import Cylinder from PyMieSim.experiment.source import Gaussian from PyMieSim.experiment import Setup from PyOptik import Material from PyMieSim.units import nanometer, degree, watt, AU, RIU .. GENERATED FROM PYTHON SOURCE LINES 18-19 Defining the source .. GENERATED FROM PYTHON SOURCE LINES 19-26 .. code-block:: Python source = Gaussian( wavelength=400 * nanometer, # 400 nm polarization=0 * degree, # Linear polarization angle in radians optical_power=1e-3 * watt, # 1 milliwatt NA=0.2 * AU # Numerical Aperture ) .. GENERATED FROM PYTHON SOURCE LINES 27-28 Defining the scatterer distribution .. GENERATED FROM PYTHON SOURCE LINES 28-35 .. code-block:: Python scatterer = Cylinder( diameter=np.linspace(1, 800, 300) * nanometer, # Diameters ranging from 1 nm to 800 nm property=[Material.silver, Material.gold, Material.aluminium], # Scatterer materials medium_property=1 * RIU, # Refractive index of the surrounding medium source=source ) .. GENERATED FROM PYTHON SOURCE LINES 36-37 Setting up the experiment .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python experiment = Setup(scatterer=scatterer, source=source) .. GENERATED FROM PYTHON SOURCE LINES 40-43 Measuring the scattering efficiency (Qsca) Note: The original request mentioned Qsca, but the measurement code uses Qabs. If Qsca measurement is intended, ensure to use the correct measure object from PyMieSim. .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: Python dataframe = experiment.get('Qabs') # Assuming Qabs was intended, replace with measure.Qsca if needed .. GENERATED FROM PYTHON SOURCE LINES 46-48 Plotting the results Visualizing how the scattering efficiency varies with the cylinder diameter. .. GENERATED FROM PYTHON SOURCE LINES 48-49 .. code-block:: Python dataframe.plot_data(x='scatterer:diameter') .. image-sg:: /gallery/experiment/cylinder/images/sphx_glr_cylinder_Qabs_vs_diameter_001.png :alt: cylinder Qabs vs diameter :srcset: /gallery/experiment/cylinder/images/sphx_glr_cylinder_Qabs_vs_diameter_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.457 seconds) .. _sphx_glr_download_gallery_experiment_cylinder_cylinder_Qabs_vs_diameter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cylinder_Qabs_vs_diameter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cylinder_Qabs_vs_diameter.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cylinder_Qabs_vs_diameter.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_