Skip to content

Add notebook demonstrating equivalence of equiangular samplings #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
375 changes: 375 additions & 0 deletions notebooks/equivalence_equiangular_sampling.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,375 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "76430a19-e222-4c2c-9e4e-743641a5e12e",
"metadata": {},
"source": [
"# Equivalence of various equiangular samplings\n",
"\n",
"In this demo we show the equivalence between Fejer/Clenshaw-Curtis sampling and other equiangular sampling schemes, including MW, MWSS and DH."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"In this demo we show the equivalence between Fejer/Clenshaw-Curtis sampling and other equiangular sampling schemes, including MW, MWSS and DH."
"In this tutorial we show the equivalence between Fejer / Clenshaw-Curtis sampling and other equiangular sampling schemes, including [McEwen-Wiaux (MW)](https://doi.org/10.1109/TSP.2011.2166394), diametrically symmetric McEwen-Wiaux (MWSS) and [Driscoll-Healy (DH)](https://doi.org/10.1006/aama.1994.1008)."

I think tutorial is better than demo for consistency with terminology we use in documentation and that it's worth expanding the sampling scheme acronyms as it may not be clear what these refer to .

]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "be9189dc-7827-416a-9340-fb66fbc390e1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"JAX is not using 64-bit precision. This will dramatically affect numerical precision at even moderate L.\n"
]
}
],
"source": [
"import s2fft \n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "81b92ac3-36e8-40fc-93f6-45394eb673dd",
"metadata": {},
"source": [
"Set band-limit for tests."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "463a7044-99c3-45e6-bce2-3b3c7dd0e259",
"metadata": {},
"outputs": [],
"source": [
"L = 4"
]
},
{
"cell_type": "markdown",
"id": "f59ae250-b286-4a9a-8a45-32098fa134a1",
"metadata": {},
"source": [
"## Equivalence of MW and Fejer type 1 sampling"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8559d609-67d5-4561-bb43-2de124f49e25",
"metadata": {},
"outputs": [],
"source": [
"thetas_mw = s2fft.sampling.s2_samples.thetas(L, sampling=\"mw\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bed1f19f-d015-4284-ade6-eeb8954d34b9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.44879895, 1.34639685, 2.24399475, 3.14159265])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_mw"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ad22a641-3940-489e-98f5-315f0ca4c5e6",
"metadata": {},
"outputs": [],
"source": [
"n = L - 1/2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear what n represents here particularly given it appears to be set to be a non-integer value but is used as an argument to numpy.arange. I would say a descriptive variable name would be better or at least some explanatory text.

]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "de96933f-6b89-4796-bdcd-1eb4959a1a55",
"metadata": {},
"outputs": [],
"source": [
"thetas_mw_fejer1 = (np.arange(0, n) + 0.5) * np.pi / n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to have a reference for this formula or at least some explanation of how it arises.

]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "974e4e4d-0753-45da-8eab-ecf0cf21f501",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.44879895, 1.34639685, 2.24399475, 3.14159265])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_mw_fejer1"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "01fd0a9d-180d-4275-b4bb-4e269aa1d466",
"metadata": {},
"outputs": [],
"source": [
"assert np.allclose(thetas_mw, thetas_mw_fejer1)"
]
},
{
"cell_type": "markdown",
"id": "0f13b08a-3df9-4999-a1a0-f022b36c7aa8",
"metadata": {},
"source": [
"## Equivalence of MWSS and Clenshaw-Curtis (Fejer type 2 with end-points) sampling "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3df7cacf-90c1-44c5-9d84-4c0164b5df4e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_mwss = s2fft.sampling.s2_samples.thetas(L, sampling=\"mwss\")\n",
"thetas_mwss"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "c7e7af1f-d1dd-4d32-bbaf-3bf61f6026b1",
"metadata": {},
"outputs": [],
"source": [
"n = L"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "5334dba6-f247-45ea-8340-9e13d1321ab9",
"metadata": {},
"outputs": [],
"source": [
"thetas_mwss_fejer2 = np.arange(1, n) * np.pi / n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again without context unclear where this formula comes from / what is being shown here.

]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "c8dbc543-71a7-4b4d-b8d0-3ca1af2fb360",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.78539816, 1.57079633, 2.35619449])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_mwss_fejer2"
]
},
{
"cell_type": "markdown",
"id": "ae69b19f-c6cb-4f94-a591-946ab9c235fa",
"metadata": {},
"source": [
"Note that Fejer tyle 2 sampling does not include end-points."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Note that Fejer tyle 2 sampling does not include end-points."
"Note that Fejer type 2 sampling does not include end-points."

]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6484fd92-7c6c-45dd-87c6-170c2cd94699",
"metadata": {},
"outputs": [],
"source": [
"assert np.allclose(thetas_mwss[1:-1], thetas_mwss_fejer2)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "c80ef1dd-1b41-401c-a506-95da1e842bc1",
"metadata": {},
"outputs": [],
"source": [
"thetas_mwss_cc = np.arange(0, n + 1) * np.pi / n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "2c4b38b9-8e40-4050-8942-77cc9dbc2b52",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_mwss_cc"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "c5818c01-bcb5-4df6-9a94-097af75c504f",
"metadata": {},
"outputs": [],
"source": [
"assert np.allclose(thetas_mwss, thetas_mwss_cc)"
]
},
{
"cell_type": "markdown",
"id": "303b49fa-ceff-4f36-99fd-adc714d93140",
"metadata": {},
"source": [
"## Equivalence of DH and Fejer type 1 sampling"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d412cec5-47e1-4146-955b-3aed62318647",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.19634954, 0.58904862, 0.9817477 , 1.37444679, 1.76714587,\n",
" 2.15984495, 2.55254403, 2.94524311])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_dh = s2fft.sampling.s2_samples.thetas(L, sampling=\"dh\")\n",
"thetas_dh"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "19336652-2ccb-48d5-9bbe-1de0b352d5d7",
"metadata": {},
"outputs": [],
"source": [
"n = 2 * L"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c58e6bbe-4892-46d3-8478-747d282630a0",
"metadata": {},
"outputs": [],
"source": [
"thetas_dh_fejer1 = (np.arange(0, n) + 0.5) * np.pi / n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "383a53ad-0fbe-40e2-8c4f-fdb3d630596c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.19634954, 0.58904862, 0.9817477 , 1.37444679, 1.76714587,\n",
" 2.15984495, 2.55254403, 2.94524311])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"thetas_dh_fejer1"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "ed2f9425-bf04-45b6-bb94-1c5546dd1417",
"metadata": {},
"outputs": [],
"source": [
"assert np.allclose(thetas_dh, thetas_dh_fejer1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading