.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/spherical_rotation.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_tutorials_spherical_rotation.py: Rotate a signal =============== This tutorial demonstrates how to use ``S2FFT`` to rotate a signal on the sphere. .. image:: https://colab.research.google.com/assets/colab-badge.svg :align: center :alt: Open in Google Colab :target: https://colab.research.google.com/github/astro-informatics/s2fft/tree/gh-pages/_colab_notebooks/spherical_rotation.ipynb If you are working on this notebook in Google Colab, you will need to have Google Colab install ``s2fft``. You can do this by adding a cell to the top of the notebook with the following content: .. code-block:: bash !pip install s2fft &> /dev/null and then running that cell. .. GENERATED FROM PYTHON SOURCE LINES 23-32 A signal can be rotated in pixel space, however this can introduce artifacts. The best way to perform a rotation is through spherical harmonic space using the Wigner d-matrices, that is: * forward spherical harmonic transform, * rotation on the flm coefficients, * inverse spherical harmonic transform. Specifically, we will adopt the sampling scheme of `McEwen & Wiaux (2012) `_. For our purposes here we'll just generate a random bandlimited signal. .. GENERATED FROM PYTHON SOURCE LINES 32-46 .. code-block:: Python import jax import numpy as np import s2fft jax.config.update("jax_enable_x64", True) L = 128 sampling = "mw" rng = np.random.default_rng(12346161) flm = s2fft.utils.signal_generator.generate_flm(rng, L) f = s2fft.inverse(flm, L) .. rst-class:: sphx-glr-script-out .. code-block:: none JAX is not using 64-bit precision. This will dramatically affect numerical precision at even moderate L. .. GENERATED FROM PYTHON SOURCE LINES 47-51 Execute the rotation steps -------------------------- First, we will run the ``JAX`` function to compute the spherical harmonic transform of our signal .. GENERATED FROM PYTHON SOURCE LINES 51-54 .. code-block:: Python flm = s2fft.forward_jax(f, L, reality=True) .. GENERATED FROM PYTHON SOURCE LINES 55-56 Now apply the rotation (here :math:`\pi/2` in each of ``alpha``, ``beta``, ``gamma``) on the harmonic coefficients ``flm``. .. GENERATED FROM PYTHON SOURCE LINES 56-59 .. code-block:: Python flm_rotated = s2fft.rotate_flms(flm, L, (np.pi / 2, np.pi / 2, np.pi / 2)) .. GENERATED FROM PYTHON SOURCE LINES 60-61 Finally, we will run the ``JAX`` function to compute the inverse spherical harmonic transform to get back to pixel space. .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python f_rotated = s2fft.inverse_jax(flm_rotated, L, reality=True) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 33.816 seconds) .. _sphx_glr_download_tutorials_spherical_rotation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: spherical_rotation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spherical_rotation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: spherical_rotation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_