.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tutorials/tuto_plot_solid_angles.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_tutorials_tuto_plot_solid_angles.py: Computing the integrated solid angle of a particle ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This tutorial show how to crete a configuration and computing the integrated solid angle subtended by a particle's trajectory along phi with certain discretization, and plotting it. :math:`\int_\Phi \Omega R d \Phi` Useful for reconstructing emissivity. .. GENERATED FROM PYTHON SOURCE LINES 13-14 We start by loading ITER's configuration (built-in in `tofu`) .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: default import matplotlib.pyplot as plt import numpy as np import tofu as tf config = tf.load_config("ITER") .. GENERATED FROM PYTHON SOURCE LINES 23-28 We define the particles properties and trajectory. Let's suppose we have the data for three points of the trajectory, the particle moves along X from point (5, 0, 0) in cartesian coordinates, to (6, 0, 0) and finally to (7, 0, 0). At the end point the particle radius seems to be a bit bigger (:math:`2 \mu m` instead of :math:`1 \mu m`) .. GENERATED FROM PYTHON SOURCE LINES 28-35 .. code-block:: default part_rad = np.r_[.0001, .0001, .0002]*2 part_traj = np.array([[5.0, 0.0, 0.0], [6.0, 0.0, 0.0], [7.0, 0.0, 0.0]], order="F").T .. GENERATED FROM PYTHON SOURCE LINES 36-39 Let's set some parameters for the discretization for computing the integral: resolutions in (R, Z, Phi) directions and the values to only compute the integral on the core of the plasma. .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: default r_step = z_step = phi_step = 0.02 # 1 cm resolution along all directions Rminmax = np.r_[4.0, 8.0] Zminmax = np.r_[-5., 5.0] .. GENERATED FROM PYTHON SOURCE LINES 45-49 Let's compute the integrated solid angle: the function returns the points in (R,Z) of the discretization, the integrated solid angle on those points, the indices to reconstruct the discretization in all domain and a the volume unit :math:`dR * dZ`. .. GENERATED FROM PYTHON SOURCE LINES 49-58 .. code-block:: default pts, sa_map, ind, vol = tf.geom._GG.compute_solid_angle_map(part_traj, part_rad, r_step, z_step, phi_step, Rminmax, Zminmax) .. GENERATED FROM PYTHON SOURCE LINES 59-60 Now we can plot the results the first point on the trajectory .. GENERATED FROM PYTHON SOURCE LINES 60-71 .. code-block:: default fig1, ax = plt.subplots() ax.scatter(pts[0, :], pts[1, :], # R and Z coordinates marker="s", # each point is a squared pixel edgecolors=None, # no boundary for smooth plot s=10, # size of pixel c=sa_map[:, 0].flatten(), # pixel color is value of int solid angle ) ax.set_aspect("equal") plt.show() .. image-sg:: /auto_examples/tutorials/images/sphx_glr_tuto_plot_solid_angles_001.png :alt: tuto plot solid angles :srcset: /auto_examples/tutorials/images/sphx_glr_tuto_plot_solid_angles_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 72-73 or the three points in the trajectory .. GENERATED FROM PYTHON SOURCE LINES 73-88 .. code-block:: default fig2, list_axes = plt.subplots(ncols=3, sharey=True) # Now we can plot the results for all points on the trajectory for (ind, ax) in enumerate(list_axes): ax.scatter(pts[0, :], pts[1, :], marker="s", edgecolors=None, s=10, c=sa_map[:, ind].flatten(), # we change particle number ) ax.set_aspect("equal") plt.show() .. image-sg:: /auto_examples/tutorials/images/sphx_glr_tuto_plot_solid_angles_002.png :alt: tuto plot solid angles :srcset: /auto_examples/tutorials/images/sphx_glr_tuto_plot_solid_angles_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-90 Now let's see the 1D profile of all particles for z = 0. .. GENERATED FROM PYTHON SOURCE LINES 90-98 .. code-block:: default izero = np.abs(pts[1, :]) < z_step fig3, list_axes = plt.subplots(ncols=3, sharey=False) for (ind, ax) in enumerate(list_axes): ax.plot(pts[0, izero], sa_map[izero, ind]) plt.show() .. image-sg:: /auto_examples/tutorials/images/sphx_glr_tuto_plot_solid_angles_003.png :alt: tuto plot solid angles :srcset: /auto_examples/tutorials/images/sphx_glr_tuto_plot_solid_angles_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 20.896 seconds) .. _sphx_glr_download_auto_examples_tutorials_tuto_plot_solid_angles.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tuto_plot_solid_angles.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tuto_plot_solid_angles.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_