.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_demos/viz_spherical_harmonics.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_auto_examples_04_demos_viz_spherical_harmonics.py: ======================================= Spherical Harmonics Order Visualization ======================================= This example demonstrates how to use the `sph_glyph` actor to visualize spherical harmonics. The `sph_glyph` actor is used to visualize the spherical harmonics coefficients as glyphs on the surface of a sphere. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python import numpy as np from fury import actor, window .. GENERATED FROM PYTHON SOURCE LINES 16-19 We will create a set of spherical harmonics coefficients to visualize the degree and order of the spherical harmonics. We will explore till degree 3 and order 3. .. GENERATED FROM PYTHON SOURCE LINES 19-46 .. code-block:: Python coefficients = np.zeros((7, 4, 1, 16), dtype=np.float32) # Order 0 coefficients[3, 3, 0, 0] = 1.0 # Order 1 coefficients[2, 2, 0, 1] = 1.0 coefficients[3, 2, 0, 2] = 1.0 coefficients[4, 2, 0, 3] = 1.0 # Order 2 coefficients[1, 1, 0, 4] = 1.0 coefficients[2, 1, 0, 5] = 1.0 coefficients[3, 1, 0, 6] = 1.0 coefficients[4, 1, 0, 7] = 1.0 coefficients[5, 1, 0, 8] = 1.0 # Order 3 coefficients[0, 0, 0, 9] = 1.0 coefficients[1, 0, 0, 10] = 1.0 coefficients[2, 0, 0, 11] = 1.0 coefficients[3, 0, 0, 12] = 1.0 coefficients[4, 0, 0, 13] = 1.0 coefficients[5, 0, 0, 14] = 1.0 coefficients[6, 0, 0, 15] = 1.0 .. GENERATED FROM PYTHON SOURCE LINES 47-49 Now we can create a spherical glyph actor to visualize these coefficients. Update the `sphere` parameter to change the resolution of the sph glyphs. .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: Python sph_glyph = actor.sph_glyph(coefficients, sphere=(50, 50)) .. GENERATED FROM PYTHON SOURCE LINES 53-55 Let's create text actors to label the degree and order of the spherical harmonics. .. GENERATED FROM PYTHON SOURCE LINES 55-75 .. code-block:: Python main_text = actor.text( "Spherical Harmonics Visualization", position=(3, 4, 0), font_size=0.5, ) order_0_text = actor.text("l=0", position=(-2, 3, 0), font_size=0.3) order_1_text = actor.text("l=1", position=(-2, 2, 0), font_size=0.3) order_2_text = actor.text("l=2", position=(-2, 1, 0), font_size=0.3) order_3_text = actor.text("l=3", position=(-2, 0, 0), font_size=0.3) degree_0_text = actor.text("m=0", position=(3, -1, 0), font_size=0.3) degree_1_text = actor.text("m=1", position=(4, -1, 0), font_size=0.3) degree_2_text = actor.text("m=2", position=(5, -1, 0), font_size=0.3) degree_3_text = actor.text("m=3", position=(6, -1, 0), font_size=0.3) degree_neg_1_text = actor.text("m=-1", position=(2, -1, 0), font_size=0.3) degree_neg_2_text = actor.text("m=-2", position=(1, -1, 0), font_size=0.3) degree_neg_3_text = actor.text("m=-3", position=(0, -1, 0), font_size=0.3) .. GENERATED FROM PYTHON SOURCE LINES 76-78 Finally, we can create a window to display the spherical glyph and the text actors. .. GENERATED FROM PYTHON SOURCE LINES 78-101 .. code-block:: Python scene = window.Scene() scene.add( sph_glyph, main_text, order_0_text, order_1_text, order_2_text, order_3_text, degree_0_text, degree_1_text, degree_2_text, degree_3_text, degree_neg_1_text, degree_neg_2_text, degree_neg_3_text, ) show_m = window.ShowManager( scene=scene, size=(800, 600), title="FURY Spherical Harmonics Visualization" ) show_m.start() .. _sphx_glr_download_auto_examples_04_demos_viz_spherical_harmonics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_spherical_harmonics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_spherical_harmonics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_spherical_harmonics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_