|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# __Rotate a signal__\n", |
| 8 | + "\n", |
| 9 | + "---\n", |
| 10 | + "\n" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "attachments": {}, |
| 15 | + "cell_type": "markdown", |
| 16 | + "metadata": {}, |
| 17 | + "source": [ |
| 18 | + "This tutorial demonstrates how to use `S2FFT` to rotate a signal on the sphere. 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:\n", |
| 19 | + "\n", |
| 20 | + "- forward spherical harmonic transform\n", |
| 21 | + "- rotation on the flm coefficients\n", |
| 22 | + "- inverse spherical harmonic transform\n", |
| 23 | + "\n", |
| 24 | + "Specifically, we will adopt the sampling scheme of [McEwen & Wiaux (2012)](https://arxiv.org/abs/1110.6298). For our purposes here we'll just generate a random bandlimited signal." |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 5, |
| 30 | + "metadata": {}, |
| 31 | + "outputs": [], |
| 32 | + "source": [ |
| 33 | + "from jax.config import config\n", |
| 34 | + "config.update(\"jax_enable_x64\", True)\n", |
| 35 | + "\n", |
| 36 | + "import numpy as np\n", |
| 37 | + "import s2fft \n", |
| 38 | + "import plotting_functions\n", |
| 39 | + "\n", |
| 40 | + "L = 128\n", |
| 41 | + "sampling = \"mw\"\n", |
| 42 | + "rng = np.random.default_rng(12346161)\n", |
| 43 | + "flm = s2fft.utils.signal_generator.generate_flm(rng, L)\n", |
| 44 | + "f = s2fft.inverse(flm, L)" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "attachments": {}, |
| 49 | + "cell_type": "markdown", |
| 50 | + "metadata": {}, |
| 51 | + "source": [ |
| 52 | + "### Execute the rotation steps\n", |
| 53 | + "\n", |
| 54 | + "---\n", |
| 55 | + "\n", |
| 56 | + "First, we will run the JAX function to compute the spherical harmonic transform of our signal" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": 7, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "flm = s2fft.forward_jax(f, L, reality=True)" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "markdown", |
| 70 | + "metadata": {}, |
| 71 | + "source": [ |
| 72 | + "Now apply the rotation (here pi/2 in each of alpha, beta, gamma) on the harmonic coefficients flm " |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | + "cell_type": "code", |
| 77 | + "execution_count": 8, |
| 78 | + "metadata": {}, |
| 79 | + "outputs": [], |
| 80 | + "source": [ |
| 81 | + "flm_rotated = s2fft.rotate_flms(flm, L, (np.pi/2, np.pi/2,np.pi/2))" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "attachments": {}, |
| 86 | + "cell_type": "markdown", |
| 87 | + "metadata": {}, |
| 88 | + "source": [ |
| 89 | + "Finally, we will run the JAX function to compute the inverse spherical harmonic transform to get back to pixel space" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": 9, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [], |
| 97 | + "source": [ |
| 98 | + "f_rotated = s2fft.inverse_jax(flm_rotated, L, reality=True)" |
| 99 | + ] |
| 100 | + } |
| 101 | + ], |
| 102 | + "metadata": { |
| 103 | + "kernelspec": { |
| 104 | + "display_name": "Python 3.10.4 ('s2fft')", |
| 105 | + "language": "python", |
| 106 | + "name": "python3" |
| 107 | + }, |
| 108 | + "language_info": { |
| 109 | + "codemirror_mode": { |
| 110 | + "name": "ipython", |
| 111 | + "version": 3 |
| 112 | + }, |
| 113 | + "file_extension": ".py", |
| 114 | + "mimetype": "text/x-python", |
| 115 | + "name": "python", |
| 116 | + "nbconvert_exporter": "python", |
| 117 | + "pygments_lexer": "ipython3", |
| 118 | + "version": "3.10.4" |
| 119 | + }, |
| 120 | + "orig_nbformat": 4, |
| 121 | + "vscode": { |
| 122 | + "interpreter": { |
| 123 | + "hash": "3425e24474cbe920550266ea26b478634978cc419579f9dbcf479231067df6a3" |
| 124 | + } |
| 125 | + } |
| 126 | + }, |
| 127 | + "nbformat": 4, |
| 128 | + "nbformat_minor": 2 |
| 129 | +} |
0 commit comments