|
40 | 40 | "import jax\n", |
41 | 41 | "jax.config.update(\"jax_enable_x64\", True)\n", |
42 | 42 | "import torch \n", |
43 | | - "import numpy as np \n", |
44 | | - "from s2fft.precompute_transforms.spherical import inverse, forward\n", |
| 43 | + "import numpy as np\n", |
| 44 | + "from s2fft.transforms.spherical import inverse, forward\n", |
| 45 | + "from s2fft.precompute_transforms.spherical import (\n", |
| 46 | + " inverse as precompute_inverse, forward as precompute_forward\n", |
| 47 | + ")\n", |
45 | 48 | "from s2fft.precompute_transforms.construct import spin_spherical_kernel_torch\n", |
46 | 49 | "from s2fft.utils import signal_generator" |
47 | 50 | ] |
|
68 | 71 | "cell_type": "markdown", |
69 | 72 | "metadata": {}, |
70 | 73 | "source": [ |
71 | | - "For the fully precompute transform we must also generate the precompute kernels which we store as a torch tensors." |
| 74 | + "Now lets calculate the signal on the sphere by applying the inverse spherical harmonic transform" |
72 | 75 | ] |
73 | 76 | }, |
74 | 77 | { |
|
85 | 88 | } |
86 | 89 | ], |
87 | 90 | "source": [ |
88 | | - "inverse_kernel = spin_spherical_kernel_torch(L, forward=False) \n", |
89 | | - "forward_kernel = spin_spherical_kernel_torch(L, forward=True) " |
| 91 | + "f = inverse(flm, L, method=\"torch\")" |
90 | 92 | ] |
91 | 93 | }, |
92 | 94 | { |
93 | 95 | "cell_type": "markdown", |
94 | 96 | "metadata": {}, |
95 | 97 | "source": [ |
96 | | - "Now lets calculate the signal on the sphere by applying the inverse spherical harmonic transform" |
| 98 | + "To calculate the corresponding spherical harmonic representation execute" |
97 | 99 | ] |
98 | 100 | }, |
99 | 101 | { |
|
102 | 104 | "metadata": {}, |
103 | 105 | "outputs": [], |
104 | 106 | "source": [ |
105 | | - "f = inverse(flm, L, 0, inverse_kernel, method=\"torch\")" |
| 107 | + "flm_check = forward(f, L, method=\"torch\")" |
106 | 108 | ] |
107 | 109 | }, |
108 | 110 | { |
109 | 111 | "cell_type": "markdown", |
110 | 112 | "metadata": {}, |
111 | 113 | "source": [ |
112 | | - "To calculate the corresponding spherical harmonic representation execute" |
| 114 | + "Finally, lets check the error on the round trip is as expected for 64 bit machine precision floating point arithmetic" |
113 | 115 | ] |
114 | 116 | }, |
115 | 117 | { |
116 | 118 | "cell_type": "code", |
117 | 119 | "execution_count": 6, |
118 | 120 | "metadata": {}, |
119 | | - "outputs": [], |
| 121 | + "outputs": [ |
| 122 | + { |
| 123 | + "name": "stdout", |
| 124 | + "output_type": "stream", |
| 125 | + "text": [ |
| 126 | + "Mean absolute error = 2.8915048238993476e-14\n" |
| 127 | + ] |
| 128 | + } |
| 129 | + ], |
120 | 130 | "source": [ |
121 | | - "flm_check = forward(f, L, 0, forward_kernel, method=\"torch\")" |
| 131 | + "print(f\"Mean absolute error = {np.nanmean(np.abs(flm_check - flm))}\")" |
122 | 132 | ] |
123 | 133 | }, |
124 | 134 | { |
125 | 135 | "cell_type": "markdown", |
126 | 136 | "metadata": {}, |
127 | 137 | "source": [ |
128 | | - "Finally, lets check the error on the roundtrip is at 64bit machine precision" |
| 138 | + "For the fully precompute transform we must also generate the precompute kernels which we store as a torch tensors." |
129 | 139 | ] |
130 | 140 | }, |
131 | 141 | { |
132 | 142 | "cell_type": "code", |
133 | 143 | "execution_count": 7, |
134 | 144 | "metadata": {}, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "inverse_kernel = spin_spherical_kernel_torch(L, forward=False) \n", |
| 148 | + "forward_kernel = spin_spherical_kernel_torch(L, forward=True) " |
| 149 | + ] |
| 150 | + }, |
| 151 | + { |
| 152 | + "cell_type": "markdown", |
| 153 | + "metadata": {}, |
| 154 | + "source": [ |
| 155 | + "We then pass the kernels as additional arguments to the transform functions" |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "cell_type": "code", |
| 160 | + "execution_count": null, |
| 161 | + "metadata": {}, |
| 162 | + "outputs": [ |
| 163 | + { |
| 164 | + "ename": "NameError", |
| 165 | + "evalue": "name 'orward_kernel' is not defined", |
| 166 | + "output_type": "error", |
| 167 | + "traceback": [ |
| 168 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 169 | + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
| 170 | + "Cell \u001b[0;32mIn[8], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m precompute_f \u001b[38;5;241m=\u001b[39m precompute_inverse(flm, L, kernel\u001b[38;5;241m=\u001b[39minverse_kernel, method\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtorch\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m precompute_flm_check \u001b[38;5;241m=\u001b[39m precompute_forward(f, L, kernel\u001b[38;5;241m=\u001b[39m\u001b[43morward_kernel\u001b[49m, method\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtorch\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", |
| 171 | + "\u001b[0;31mNameError\u001b[0m: name 'orward_kernel' is not defined" |
| 172 | + ] |
| 173 | + } |
| 174 | + ], |
| 175 | + "source": [ |
| 176 | + "precompute_f = precompute_inverse(flm, L, kernel=inverse_kernel, method=\"torch\")\n", |
| 177 | + "precompute_flm_check = precompute_forward(f, L, kernel=forward_kernel, method=\"torch\")" |
| 178 | + ] |
| 179 | + }, |
| 180 | + { |
| 181 | + "cell_type": "markdown", |
| 182 | + "metadata": {}, |
| 183 | + "source": [ |
| 184 | + "Again, we check the error on the round trip is as expected" |
| 185 | + ] |
| 186 | + }, |
| 187 | + { |
| 188 | + "cell_type": "code", |
| 189 | + "execution_count": null, |
| 190 | + "metadata": {}, |
135 | 191 | "outputs": [ |
136 | 192 | { |
137 | 193 | "name": "stdout", |
|
142 | 198 | } |
143 | 199 | ], |
144 | 200 | "source": [ |
145 | | - "print(f\"Mean absolute error = {np.nanmean(np.abs(flm_check - flm))}\")" |
| 201 | + "print(f\"Mean absolute error = {np.nanmean(np.abs(precompute_flm_check - flm))}\")" |
146 | 202 | ] |
147 | 203 | } |
148 | 204 | ], |
|
0 commit comments