.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/spectral/spectral_detectors.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_spectral_detectors.py: Sweep wavelengths with a fixed sensor geometry ============================================== Assign tabulated spectra to two regions, keep source and detector geometry fixed, and compare collected power at five wavelengths. All coefficients are illustrative. The sweep runs independent monochromatic P1 solves; it is not a broadband source integration or a validated tissue spectrum. .. GENERATED FROM PYTHON SOURCE LINES 10-28 .. code-block:: Python import os import numpy as np import MomentRT from MomentRT import ( P1, CartesianMesh, RobinBoundary, Simulation, SpectralMaterial, StructuredMedium, SurfaceDetector, SurfaceSource, ureg, ) show_figures = os.environ.get("MOMENTRT_SPHINX_GALLERY") != "1" .. GENERATED FROM PYTHON SOURCE LINES 30-35 Define tabulated optical properties ------------------------------------ Tables are linearly interpolated. Out-of-range wavelengths are rejected. The refractive index is constant across the internal interface at every wavelength, as required by the current continuous-fluence solver. .. GENERATED FROM PYTHON SOURCE LINES 35-67 .. code-block:: Python table_wavelengths = np.array([650, 750, 850, 950]) * ureg.nm background = SpectralMaterial( phase_function=MomentRT.phase_function.HenyeyGreenstein(), wavelengths=table_wavelengths, absorption=np.array([0.025, 0.014, 0.018, 0.035]) / ureg.mm, reduced_scattering=np.array([1.5, 1.3, 1.1, 0.9]) / ureg.mm, refractive_index=1.4, ) upper_material = SpectralMaterial( phase_function=MomentRT.phase_function.HenyeyGreenstein(), wavelengths=table_wavelengths, absorption=np.array([0.06, 0.03, 0.025, 0.05]) / ureg.mm, reduced_scattering=np.array([1.8, 1.6, 1.4, 1.2]) / ureg.mm, refractive_index=1.4, ) sample = StructuredMedium( origin=(-4, -3, 0) * ureg.mm, size=(8, 6, 4) * ureg.mm, ) sample.add_background(material=background) sample.add_layer( name="Superficial region", thickness=1 * ureg.mm, material=upper_material, ) .. GENERATED FROM PYTHON SOURCE LINES 68-73 Configure the source, mesh, boundaries, and detectors once ---------------------------------------------------------- Power is already coupled into the sample. The sweep retains that same optical power at every wavelength unless a power vector is supplied. Boundary effective reflectance and detector acceptance also stay fixed. .. GENERATED FROM PYTHON SOURCE LINES 73-127 .. code-block:: Python source = SurfaceSource( face="z_min", position=np.array([-1.5, 0, 0]) * ureg.mm, radius=0.8 * ureg.mm, wavelength=800 * ureg.nm, optical_power=1 * ureg.mW, ) mesh = CartesianMesh.from_sample( sample=sample, shape=(17, 13, 13), ) boundary = RobinBoundary(effective_reflectance=0.4) solver = P1( boundaries={ face: boundary for face in ("x_min", "x_max", "y_min", "y_max", "z_min", "z_max") }, ) reflection_detector = SurfaceDetector( face="z_min", position=np.array([1.5, 0, 0]) * ureg.mm, radius=0.75 * ureg.mm, collection_axis=np.array([0, 0, -1]), acceptance_angle=35 * ureg.degree, ) transmission_detector = SurfaceDetector( face="z_max", position=np.array([0, 0, 4]) * ureg.mm, radius=0.9 * ureg.mm, collection_axis=np.array([0, 0, 1]), acceptance_angle=60 * ureg.degree, ) simulation = Simulation( medium=sample, source=source, mesh=mesh, solver=solver, detectors={ "reflection": reflection_detector, "transmission": transmission_detector, }, ) system_figure = simulation.plot_system( show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 128-132 Run the ordered wavelength sweep ---------------------------------- Each result keeps its own fields, wavelength, and detector measurements. The original sample, source wavelength, and detector geometry are retained. .. GENERATED FROM PYTHON SOURCE LINES 132-154 .. code-block:: Python wavelengths = np.array([700, 750, 800, 850, 900]) * ureg.nm spectrum = simulation.sweep( wavelengths=wavelengths, ) print(f"Geometry preparations: {spectrum.diagnostics['geometry_preparations']}") print(f"Preparation time: {spectrum.diagnostics['preparation_time'].to('s'):~P}") print(f"Per-wavelength run times: {spectrum.diagnostics['solve_times'].to('s'):~P}") spectral_figure = spectrum.plot( wavelength_unit="nm", power_unit="mW", show=show_figures, ) for wavelength, power in zip(wavelengths, spectrum.detector_power["reflection"]): print(f"Reflection at {wavelength:~P}: {power.to('mW'):~P}") .. raw:: html .. rst-class:: sphx-glr-script-out .. code-block:: none Geometry preparations: 1 Preparation time: 0.0901987259999828 s Per-wavelength run times: [0.043688597000027585 0.0417160460000332 0.041540698000005705 0.042602724999994734 0.04193266100003257] s Reflection at 700 nm: 0.0019590985219869353 mW Reflection at 750 nm: 0.002272609112024002 mW Reflection at 800 nm: 0.002367707455554829 mW Reflection at 850 nm: 0.0024643911018476516 mW Reflection at 900 nm: 0.002317102091676802 mW .. GENERATED FROM PYTHON SOURCE LINES 155-162 Inspect one monochromatic fluence volume ----------------------------------------- The third solve corresponds to 800 nm. Its geometry is the same as in the other solves; its optical coefficients are interpolated at this wavelength. Overlays place the instrument on the spatial field; the spectrum above keeps its wavelength and power axes. Named overlays give the two apertures distinct legend entries. .. GENERATED FROM PYTHON SOURCE LINES 162-171 .. code-block:: Python fluence_figure = spectrum.results[2].fluence.plot( view="volume", scale="log", overlays=[source, reflection_detector, transmission_detector], show=show_figures, ) .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 172-175 Inspect the modeled geometry ---------------------------- This view shows the configured geometry and instrument footprints. .. GENERATED FROM PYTHON SOURCE LINES 175-177 .. 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.438 seconds) .. _sphx_glr_download_gallery_spectral_spectral_detectors.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: spectral_detectors.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spectral_detectors.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: spectral_detectors.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_