.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/spectral/sp3_spectral_anisotropy.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_spectral_sp3_spectral_anisotropy.py: Sweep wavelength-dependent scattering anisotropy ================================================== Specify different spectral anisotropy tables for two layers and evaluate an SP3 sensor at several wavelengths. The numbers are illustrative. Each result is monochromatic; the sweep is not a broadband integration. .. GENERATED FROM PYTHON SOURCE LINES 9-19 .. code-block:: Python import os import numpy as np import MomentRT ureg = MomentRT.ureg show_figures = os.environ.get("MOMENTRT_SPHINX_GALLERY") != "1" .. GENERATED FROM PYTHON SOURCE LINES 21-26 Give each material its own spectral table ----------------------------------------- Anisotropy can be a plain scalar or a vector matching the wavelength grid. MomentRT linearly interpolates the vector without extrapolation. SP3 uses the interpolated value with a Henyey–Greenstein phase function. .. GENERATED FROM PYTHON SOURCE LINES 26-60 .. code-block:: Python table_wavelengths = np.array([700, 800, 900]) * ureg.nanometer dermis = MomentRT.SpectralMaterial( phase_function=MomentRT.phase_function.HenyeyGreenstein(), wavelengths=table_wavelengths, absorption=np.array([0.035, 0.025, 0.03]) / ureg.millimeter, reduced_scattering=np.array([1.3, 1.1, 0.9]) / ureg.millimeter, refractive_index=1.4, anisotropy=np.array([0.75, 0.80, 0.84]), ) epidermis = MomentRT.SpectralMaterial( phase_function=MomentRT.phase_function.HenyeyGreenstein(), wavelengths=table_wavelengths, absorption=np.array([0.06, 0.045, 0.05]) / ureg.millimeter, reduced_scattering=np.array([1.8, 1.6, 1.4]) / ureg.millimeter, refractive_index=1.4, anisotropy=np.array([0.60, 0.65, 0.70]), ) sample = MomentRT.StructuredMedium( origin=(-4, -4, 0) * ureg.millimeter, size=(8, 8, 4) * ureg.millimeter, ) sample.add_background(material=dermis) sample.add_layer( name="Epidermis", thickness=0.8 * ureg.millimeter, material=epidermis, ) .. GENERATED FROM PYTHON SOURCE LINES 61-65 Keep the instrument geometry fixed ---------------------------------- Every wavelength uses the same source footprint and detector aperture. The zero-reflectance faces select the matched-index SP3 boundary condition. .. GENERATED FROM PYTHON SOURCE LINES 65-101 .. code-block:: Python source = MomentRT.SurfaceSource( face="z_min", position=np.array([-1.5, 0, 0]) * ureg.millimeter, radius=1.0 * ureg.millimeter, wavelength=800 * ureg.nanometer, optical_power=1 * ureg.milliwatt, ) detector = MomentRT.SurfaceDetector( face="z_min", position=np.array([1.5, 0, 0]) * ureg.millimeter, radius=0.8 * ureg.millimeter, collection_axis=[0, 0, -1], acceptance_angle=90 * ureg.degree, ) mesh = MomentRT.CartesianMesh.from_sample( sample=sample, shape=(15, 15, 11), ) boundary = MomentRT.RobinBoundary(effective_reflectance=0) boundaries = {face: boundary for face in MomentRT.boundary.FACES} solver = MomentRT.SP3(boundaries=boundaries) simulation = MomentRT.Simulation( medium=sample, source=source, mesh=mesh, solver=solver, detectors={"contact": detector}, ) .. GENERATED FROM PYTHON SOURCE LINES 102-106 Interpolate anisotropy and solve each wavelength ------------------------------------------------- The 750 nm value lies halfway between the first two tabulated values. Geometry and boundary quadrature are prepared once for the sweep. .. GENERATED FROM PYTHON SOURCE LINES 106-128 .. code-block:: Python wavelengths = np.array([700, 750, 800, 850, 900]) * ureg.nanometer spectrum = simulation.sweep(wavelengths=wavelengths) for wavelength, power in zip(wavelengths, spectrum.detector_power["contact"]): dermis_at_wavelength = dermis.at(wavelength=wavelength) epidermis_at_wavelength = epidermis.at(wavelength=wavelength) print( f"{wavelength:~P}: dermis g={dermis_at_wavelength.anisotropy:.3f}, " f"epidermis g={epidermis_at_wavelength.anisotropy:.3f}, " f"collected power={power.to('mW'):~P}" ) spectral_figure = spectrum.plot( wavelength_unit="nm", power_unit="mW", show=show_figures, ) .. raw:: html .. rst-class:: sphx-glr-script-out .. code-block:: none 700 nm: dermis g=0.750, epidermis g=0.600, collected power=0.004799176663534618 mW 750 nm: dermis g=0.775, epidermis g=0.625, collected power=0.005352912876820783 mW 800 nm: dermis g=0.800, epidermis g=0.650, collected power=0.005952296585705335 mW 850 nm: dermis g=0.820, epidermis g=0.675, collected power=0.00617759009610433 mW 900 nm: dermis g=0.840, epidermis g=0.700, collected power=0.00642484826351474 mW .. GENERATED FROM PYTHON SOURCE LINES 129-134 View a monochromatic fluence volume ------------------------------------ The 800 nm solution uses the third entry in the sweep. The detector uses a separate Lambertian angular-acceptance approximation. Check mesh convergence and compare with a transport reference for the intended application. .. GENERATED FROM PYTHON SOURCE LINES 134-143 .. code-block:: Python fluence_figure = spectrum.results[2].fluence.plot( view="volume", scale="linear", overlays=[source, detector], show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 144-147 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 147-149 .. code-block:: Python gallery_system_figure = simulation.plot_system(show=False) .. raw:: html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.932 seconds) .. _sphx_glr_download_gallery_spectral_sp3_spectral_anisotropy.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sp3_spectral_anisotropy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sp3_spectral_anisotropy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sp3_spectral_anisotropy.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_