Skip to content

Commit a60599e

Browse files
committed
Add notebook demonstrating equivalence of equiangular samplings
1 parent 2d240ad commit a60599e

File tree

1 file changed

+375
-0
lines changed

1 file changed

+375
-0
lines changed
Lines changed: 375 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,375 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "76430a19-e222-4c2c-9e4e-743641a5e12e",
6+
"metadata": {},
7+
"source": [
8+
"# Equivalence of various equiangular samplings\n",
9+
"\n",
10+
"In this demo we show the equivalence between Fejer/Clenshaw-Curtis sampling and other equiangular sampling schemes, including MW, MWSS and DH."
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"id": "be9189dc-7827-416a-9340-fb66fbc390e1",
17+
"metadata": {},
18+
"outputs": [
19+
{
20+
"name": "stderr",
21+
"output_type": "stream",
22+
"text": [
23+
"JAX is not using 64-bit precision. This will dramatically affect numerical precision at even moderate L.\n"
24+
]
25+
}
26+
],
27+
"source": [
28+
"import s2fft \n",
29+
"import numpy as np"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"id": "81b92ac3-36e8-40fc-93f6-45394eb673dd",
35+
"metadata": {},
36+
"source": [
37+
"Set band-limit for tests."
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 2,
43+
"id": "463a7044-99c3-45e6-bce2-3b3c7dd0e259",
44+
"metadata": {},
45+
"outputs": [],
46+
"source": [
47+
"L = 4"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"id": "f59ae250-b286-4a9a-8a45-32098fa134a1",
53+
"metadata": {},
54+
"source": [
55+
"## Equivalence of MW and Fejer type 1 sampling"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 3,
61+
"id": "8559d609-67d5-4561-bb43-2de124f49e25",
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"thetas_mw = s2fft.sampling.s2_samples.thetas(L, sampling=\"mw\")"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 4,
71+
"id": "bed1f19f-d015-4284-ade6-eeb8954d34b9",
72+
"metadata": {},
73+
"outputs": [
74+
{
75+
"data": {
76+
"text/plain": [
77+
"array([0.44879895, 1.34639685, 2.24399475, 3.14159265])"
78+
]
79+
},
80+
"execution_count": 4,
81+
"metadata": {},
82+
"output_type": "execute_result"
83+
}
84+
],
85+
"source": [
86+
"thetas_mw"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 5,
92+
"id": "ad22a641-3940-489e-98f5-315f0ca4c5e6",
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"n = L - 1/2"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 6,
102+
"id": "de96933f-6b89-4796-bdcd-1eb4959a1a55",
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"thetas_mw_fejer1 = (np.arange(0, n) + 0.5) * np.pi / n"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": 7,
112+
"id": "974e4e4d-0753-45da-8eab-ecf0cf21f501",
113+
"metadata": {},
114+
"outputs": [
115+
{
116+
"data": {
117+
"text/plain": [
118+
"array([0.44879895, 1.34639685, 2.24399475, 3.14159265])"
119+
]
120+
},
121+
"execution_count": 7,
122+
"metadata": {},
123+
"output_type": "execute_result"
124+
}
125+
],
126+
"source": [
127+
"thetas_mw_fejer1"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": 8,
133+
"id": "01fd0a9d-180d-4275-b4bb-4e269aa1d466",
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"assert np.allclose(thetas_mw, thetas_mw_fejer1)"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"id": "0f13b08a-3df9-4999-a1a0-f022b36c7aa8",
143+
"metadata": {},
144+
"source": [
145+
"## Equivalence of MWSS and Clenshaw-Curtis (Fejer type 2 with end-points) sampling "
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 9,
151+
"id": "3df7cacf-90c1-44c5-9d84-4c0164b5df4e",
152+
"metadata": {},
153+
"outputs": [
154+
{
155+
"data": {
156+
"text/plain": [
157+
"array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])"
158+
]
159+
},
160+
"execution_count": 9,
161+
"metadata": {},
162+
"output_type": "execute_result"
163+
}
164+
],
165+
"source": [
166+
"thetas_mwss = s2fft.sampling.s2_samples.thetas(L, sampling=\"mwss\")\n",
167+
"thetas_mwss"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 10,
173+
"id": "c7e7af1f-d1dd-4d32-bbaf-3bf61f6026b1",
174+
"metadata": {},
175+
"outputs": [],
176+
"source": [
177+
"n = L"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": 11,
183+
"id": "5334dba6-f247-45ea-8340-9e13d1321ab9",
184+
"metadata": {},
185+
"outputs": [],
186+
"source": [
187+
"thetas_mwss_fejer2 = np.arange(1, n) * np.pi / n"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": 12,
193+
"id": "c8dbc543-71a7-4b4d-b8d0-3ca1af2fb360",
194+
"metadata": {},
195+
"outputs": [
196+
{
197+
"data": {
198+
"text/plain": [
199+
"array([0.78539816, 1.57079633, 2.35619449])"
200+
]
201+
},
202+
"execution_count": 12,
203+
"metadata": {},
204+
"output_type": "execute_result"
205+
}
206+
],
207+
"source": [
208+
"thetas_mwss_fejer2"
209+
]
210+
},
211+
{
212+
"cell_type": "markdown",
213+
"id": "ae69b19f-c6cb-4f94-a591-946ab9c235fa",
214+
"metadata": {},
215+
"source": [
216+
"Note that Fejer tyle 2 sampling does not include end-points."
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": 13,
222+
"id": "6484fd92-7c6c-45dd-87c6-170c2cd94699",
223+
"metadata": {},
224+
"outputs": [],
225+
"source": [
226+
"assert np.allclose(thetas_mwss[1:-1], thetas_mwss_fejer2)"
227+
]
228+
},
229+
{
230+
"cell_type": "code",
231+
"execution_count": 14,
232+
"id": "c80ef1dd-1b41-401c-a506-95da1e842bc1",
233+
"metadata": {},
234+
"outputs": [],
235+
"source": [
236+
"thetas_mwss_cc = np.arange(0, n + 1) * np.pi / n"
237+
]
238+
},
239+
{
240+
"cell_type": "code",
241+
"execution_count": 15,
242+
"id": "2c4b38b9-8e40-4050-8942-77cc9dbc2b52",
243+
"metadata": {},
244+
"outputs": [
245+
{
246+
"data": {
247+
"text/plain": [
248+
"array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])"
249+
]
250+
},
251+
"execution_count": 15,
252+
"metadata": {},
253+
"output_type": "execute_result"
254+
}
255+
],
256+
"source": [
257+
"thetas_mwss_cc"
258+
]
259+
},
260+
{
261+
"cell_type": "code",
262+
"execution_count": 16,
263+
"id": "c5818c01-bcb5-4df6-9a94-097af75c504f",
264+
"metadata": {},
265+
"outputs": [],
266+
"source": [
267+
"assert np.allclose(thetas_mwss, thetas_mwss_cc)"
268+
]
269+
},
270+
{
271+
"cell_type": "markdown",
272+
"id": "303b49fa-ceff-4f36-99fd-adc714d93140",
273+
"metadata": {},
274+
"source": [
275+
"## Equivalence of DH and Fejer type 1 sampling"
276+
]
277+
},
278+
{
279+
"cell_type": "code",
280+
"execution_count": 17,
281+
"id": "d412cec5-47e1-4146-955b-3aed62318647",
282+
"metadata": {},
283+
"outputs": [
284+
{
285+
"data": {
286+
"text/plain": [
287+
"array([0.19634954, 0.58904862, 0.9817477 , 1.37444679, 1.76714587,\n",
288+
" 2.15984495, 2.55254403, 2.94524311])"
289+
]
290+
},
291+
"execution_count": 17,
292+
"metadata": {},
293+
"output_type": "execute_result"
294+
}
295+
],
296+
"source": [
297+
"thetas_dh = s2fft.sampling.s2_samples.thetas(L, sampling=\"dh\")\n",
298+
"thetas_dh"
299+
]
300+
},
301+
{
302+
"cell_type": "code",
303+
"execution_count": 18,
304+
"id": "19336652-2ccb-48d5-9bbe-1de0b352d5d7",
305+
"metadata": {},
306+
"outputs": [],
307+
"source": [
308+
"n = 2 * L"
309+
]
310+
},
311+
{
312+
"cell_type": "code",
313+
"execution_count": 19,
314+
"id": "c58e6bbe-4892-46d3-8478-747d282630a0",
315+
"metadata": {},
316+
"outputs": [],
317+
"source": [
318+
"thetas_dh_fejer1 = (np.arange(0, n) + 0.5) * np.pi / n"
319+
]
320+
},
321+
{
322+
"cell_type": "code",
323+
"execution_count": 20,
324+
"id": "383a53ad-0fbe-40e2-8c4f-fdb3d630596c",
325+
"metadata": {},
326+
"outputs": [
327+
{
328+
"data": {
329+
"text/plain": [
330+
"array([0.19634954, 0.58904862, 0.9817477 , 1.37444679, 1.76714587,\n",
331+
" 2.15984495, 2.55254403, 2.94524311])"
332+
]
333+
},
334+
"execution_count": 20,
335+
"metadata": {},
336+
"output_type": "execute_result"
337+
}
338+
],
339+
"source": [
340+
"thetas_dh_fejer1"
341+
]
342+
},
343+
{
344+
"cell_type": "code",
345+
"execution_count": 21,
346+
"id": "ed2f9425-bf04-45b6-bb94-1c5546dd1417",
347+
"metadata": {},
348+
"outputs": [],
349+
"source": [
350+
"assert np.allclose(thetas_dh, thetas_dh_fejer1)"
351+
]
352+
}
353+
],
354+
"metadata": {
355+
"kernelspec": {
356+
"display_name": "Python 3 (ipykernel)",
357+
"language": "python",
358+
"name": "python3"
359+
},
360+
"language_info": {
361+
"codemirror_mode": {
362+
"name": "ipython",
363+
"version": 3
364+
},
365+
"file_extension": ".py",
366+
"mimetype": "text/x-python",
367+
"name": "python",
368+
"nbconvert_exporter": "python",
369+
"pygments_lexer": "ipython3",
370+
"version": "3.11.11"
371+
}
372+
},
373+
"nbformat": 4,
374+
"nbformat_minor": 5
375+
}

0 commit comments

Comments
 (0)