.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_spherecuts.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_plot_spherecuts.py: ============== Sphere Cuts ============== This example shows some spher(ical) cuts on a set of points in 3D using ``kp.math.spherecut`` and ``kp.math.spherecutmask``. .. GENERATED FROM PYTHON SOURCE LINES 13-18 .. code-block:: Python import km3pipe as kp import matplotlib.pyplot as plt import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 19-20 Generating a few points randomly distributed in a cube .. GENERATED FROM PYTHON SOURCE LINES 20-23 .. code-block:: Python points = np.random.rand(1000, 3) .. GENERATED FROM PYTHON SOURCE LINES 24-26 In this example we create two masks and use them to not only highlight the selected points but also to hide those from the original dataset. .. GENERATED FROM PYTHON SOURCE LINES 26-38 .. code-block:: Python mask1 = kp.math.spherecutmask([0, 0, 0], 0.8, 1.0, points) mask2 = kp.math.spherecutmask([0.8, 0.8, 0.8], 0, 0.2, points) fig = plt.figure() ax = plt.axes(projection="3d") ax.scatter(*points[~(mask1 | mask2)].T, label="unselected points") ax.scatter(*points[mask1].T, label="mask1") ax.scatter(*points[mask2].T, label="mask2") ax.legend() .. image-sg:: /auto_examples/images/sphx_glr_plot_spherecuts_001.png :alt: plot spherecuts :srcset: /auto_examples/images/sphx_glr_plot_spherecuts_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 39-41 This will select all points which are inside a sphere with radius 0.5 and centered at (0.5, 0.5, 0.5): .. GENERATED FROM PYTHON SOURCE LINES 41-51 .. code-block:: Python selected_points = kp.math.spherecut([0.5, 0.5, 0.5], 0.0, 0.5, points) fig = plt.figure() ax = plt.axes(projection="3d") ax.scatter(*selected_points.T) fig.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_spherecuts_002.png :alt: plot spherecuts :srcset: /auto_examples/images/sphx_glr_plot_spherecuts_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.231 seconds) .. _sphx_glr_download_auto_examples_plot_spherecuts.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_spherecuts.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_spherecuts.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_