.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/samples_and_meshes/sample_models.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_samples_and_meshes_sample_models.py: Build samples with named models ================================ Construct a two-layer skin sample and a general layered phantom with explicit materials. The models return ordinary ``StructuredMedium`` objects, so they work with the same meshes, sources, and solvers as a manually built sample. Optical values are illustrative and do not represent an individual. .. GENERATED FROM PYTHON SOURCE LINES 10-18 .. code-block:: Python import numpy as np import MomentRT from MomentRT.models.phantom import LayeredPhantom from MomentRT.models.skin import TwoLayerSkin ureg = MomentRT.ureg .. GENERATED FROM PYTHON SOURCE LINES 20-25 Choose materials and geometry ----------------------------- The parameterized epidermis and dermis materials use approximate literature fits at one wavelength. Their refractive indices match because the finite solvers do not currently model refractive-index jumps within the sample. .. GENERATED FROM PYTHON SOURCE LINES 25-39 .. code-block:: Python epidermis = MomentRT.materials.Epidermis( melanin_fraction=0.05, wavelength=850 * ureg.nm, refractive_index=1.4, ) dermis = MomentRT.materials.Dermis( hydration=0.7, wavelength=850 * ureg.nm, refractive_index=1.4, ) origin = (-3, -3, 0) * ureg.mm size = (6, 6, 3) * ureg.mm .. GENERATED FROM PYTHON SOURCE LINES 40-44 Build a two-layer sample ------------------------ The epidermis starts at the sample's upper face. The dermis fills the remaining depth and is also the background. Positive z points into the sample. .. GENERATED FROM PYTHON SOURCE LINES 44-54 .. code-block:: Python sample = TwoLayerSkin( origin=origin, size=size, epidermis=epidermis, dermis=dermis, epidermis_thickness=0.5 * ureg.mm, ) print(f"Skin layers: {[layer.name for layer in sample.structures]}") .. rst-class:: sphx-glr-script-out .. code-block:: none Skin layers: ['Epidermis', 'Dermis'] .. GENERATED FROM PYTHON SOURCE LINES 55-61 Build a general layered phantom ------------------------------- A phantom accepts a sequence of named layers, thicknesses, and materials. The explicit background fills the space below the stack. Materials and thicknesses here are chosen to match the skin geometry above; they do not describe a manufactured phantom. .. GENERATED FROM PYTHON SOURCE LINES 61-70 .. code-block:: Python phantom = LayeredPhantom( origin=origin, size=size, background=dermis, layers=(("Upper layer", 0.5 * ureg.mm, epidermis),), ) print(f"Phantom layers: {[layer.name for layer in phantom.structures]}") .. rst-class:: sphx-glr-script-out .. code-block:: none Phantom layers: ['Upper layer'] .. GENERATED FROM PYTHON SOURCE LINES 71-76 Solve the skin sample --------------------- The source is diffuse power already coupled into the sample. This coarse mesh is illustrative: resolving the layer and source footprint, and the validity of P1 at the relevant distances, require separate checks. .. GENERATED FROM PYTHON SOURCE LINES 76-109 .. code-block:: Python mesh = MomentRT.mesh.CartesianMesh.from_sample( sample=sample, shape=(13, 13, 13), ) source = MomentRT.source.SurfaceSource( face="z_min", position=np.zeros(3) * ureg.mm, radius=1 * ureg.mm, wavelength=850 * ureg.nm, optical_power=1 * ureg.mW, ) solver = MomentRT.transport.P1( boundaries=MomentRT.boundary.Boundaries.uniform( condition=MomentRT.boundary.RobinBoundary(effective_reflectance=0), ), ) simulation = MomentRT.simulation.Simulation( medium=sample, source=source, mesh=mesh, solver=solver, ) result = simulation.run() print(f"Sampled source area: {result.source_sampled_area.to('mm^2'):~P}") print(f"Geometric source area: {result.source_geometric_area.to('mm^2'):~P}") gallery_system_figure = result.fluence.plot( view="volume", scale="linear", overlays=[*sample.structures, source], show=False, ) .. raw:: html .. rst-class:: sphx-glr-script-out .. code-block:: none Sampled source area: 3.083333333333333 mm² Geometric source area: 3.141592653589793 mm² .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.134 seconds) .. _sphx_glr_download_gallery_samples_and_meshes_sample_models.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sample_models.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sample_models.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sample_models.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_