.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/samples_and_meshes/cartesian_resolution.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_cartesian_resolution.py: Create a Cartesian mesh from physical resolution ================================================ Choose grid spacing in length units instead of selecting node counts. A three-component resolution can make the spacing different along each axis. .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python import MomentRT from MomentRT import CartesianMesh, Material, StructuredMedium, ureg .. GENERATED FROM PYTHON SOURCE LINES 14-16 Define the sample and optical material -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-31 .. code-block:: Python material = Material( absorption=0.02 / ureg.millimeter, reduced_scattering=1.0 / ureg.millimeter, refractive_index=1.4, anisotropy=0.8, phase_function=MomentRT.HenyeyGreenstein(), ) sample = StructuredMedium( origin=(0, 0, 0) * ureg.millimeter, size=(4, 4, 3) * ureg.millimeter, ) sample.add_background(material=material) .. GENERATED FROM PYTHON SOURCE LINES 32-36 Request anisotropic physical spacing ------------------------------------ The z spacing is finer to resolve depth variations. MomentRT adjusts the actual spacing downward as needed so that the grid reaches every sample face. .. GENERATED FROM PYTHON SOURCE LINES 36-50 .. code-block:: Python mesh = CartesianMesh.from_sample( sample=sample, resolution=(0.5, 0.5, 0.25) * ureg.millimeter, ) figure = mesh.plot( length_unit="mm", show=False, ) print(f"Requested resolution: {mesh.resolution.to('mm')}") print(f"Node counts: {mesh.shape}") print(f"Actual spacing: {mesh.spacing.to('mm')}") .. raw:: html .. rst-class:: sphx-glr-script-out .. code-block:: none Requested resolution: [0.5 0.5 0.25] millimeter Node counts: (9, 9, 13) Actual spacing: [0.5 0.5 0.25] millimeter .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.024 seconds) .. _sphx_glr_download_gallery_samples_and_meshes_cartesian_resolution.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cartesian_resolution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cartesian_resolution.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cartesian_resolution.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_