.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/experiment/cylinder/cylinder_Qsca_vs_wavelength.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_Qsca_vs_wavelength.py: Cylinder: Qsca vs Wavelength ============================ This example demonstrates how to compute and visualize the scattering efficiency (Qsca) as a function of wavelength for cylindrical scatterers using PyMieSim, considering cylinders with different diameters and refractive indices. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Importing the package dependencies: numpy, PyMieSim .. GENERATED FROM PYTHON SOURCE LINES 10-16 .. 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 PyMieSim.units import nanometer, degree, watt, AU, RIU .. GENERATED FROM PYTHON SOURCE LINES 17-19 Defining the source Studying the scattering efficiency across a range of wavelengths. .. GENERATED FROM PYTHON SOURCE LINES 19-26 .. code-block:: Python source = Gaussian( wavelength=np.linspace(400, 1000, 150) * nanometer, # Wavelengths ranging from 400 nm to 1000 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-29 Defining the scatterer distribution Considering cylinders with specific diameters and refractive indices. .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python scatterer = Cylinder( diameter=[200, 150] * nanometer, # Array of diameters: 200 nm, 150 nm, 100 nm property=[2, 3, 4] * RIU, # Array of refractive indices: 2, 3, 4 medium_property=[1] * RIU, # Refractive index of the surrounding medium source=source ) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Setting up the experiment .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python experiment = Setup(scatterer=scatterer, source=source) .. GENERATED FROM PYTHON SOURCE LINES 41-43 Measuring the scattering efficiency (Qsca) Averaging the data across the different indices to simplify visualization. .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: Python dataframe = experiment.get('Qsca') .. GENERATED FROM PYTHON SOURCE LINES 46-48 Plotting the results Visualizing how the Qsca varies with wavelength for the given cylinder configurations. .. GENERATED FROM PYTHON SOURCE LINES 48-49 .. code-block:: Python dataframe.plot_data(x='source:wavelength', std='scatterer:property') .. image-sg:: /gallery/experiment/cylinder/images/sphx_glr_cylinder_Qsca_vs_wavelength_001.png :alt: cylinder Qsca vs wavelength :srcset: /gallery/experiment/cylinder/images/sphx_glr_cylinder_Qsca_vs_wavelength_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.463 seconds) .. _sphx_glr_download_gallery_experiment_cylinder_cylinder_Qsca_vs_wavelength.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cylinder_Qsca_vs_wavelength.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cylinder_Qsca_vs_wavelength.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cylinder_Qsca_vs_wavelength.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_