Skip to content
Draft
Show file tree
Hide file tree
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
400 changes: 154 additions & 246 deletions src/s2fft/base_transforms/spherical.py

Large diffs are not rendered by default.

62 changes: 24 additions & 38 deletions src/s2fft/base_transforms/wigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def inverse(
L_lower: int = 0,
sampling: str = "mw",
reality: bool = False,
nside: int = None,
nside: int | None = None,
) -> np.ndarray:
r"""
Compute the inverse Wigner transform, i.e. inverse Fourier transform on
Expand All @@ -26,29 +26,22 @@ def inverse(
:math:`\alpha` with :math:`\phi`.

Args:
flmn (np.ndarray): Wigner coefficients with shape :math:`[2N-1, L, 2L-1]`.

L (int): Harmonic bandlimit.

N (int): Directional band-limit.

L_lower (int, optional): Harmonic lower bound. Defaults to 0.

sampling (str, optional): Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl"}. Defaults to "mw".

reality (bool, optional): Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs. Defaults to
False.

nside (int, optional): HEALPix Nside resolution parameter. Only required
if sampling="healpix". Defaults to None.
flmn: Wigner coefficients with shape :math:`[2N-1, L, 2L-1]`.
L: Harmonic bandlimit.
N: Directional band-limit.
L_lower: Harmonic lower bound.
sampling: Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl"}.
reality: Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs.
nside: HEALPix Nside resolution parameter. Only required
if sampling="healpix".

Raises:
ValueError: Sampling scheme not currently supported.

Returns:
np.ndarray: Signal on the on :math:`SO(3)` with shape :math:`[n_{\gamma},
Signal on the on :math:`SO(3)` with shape :math:`[n_{\gamma},
n_{\beta}, n_{\alpha}]`, where :math:`n_\xi` denotes the number of samples for
angle :math:`\xi`.

Expand Down Expand Up @@ -91,7 +84,7 @@ def forward(
L_lower: int = 0,
sampling: str = "mw",
reality: bool = False,
nside: int = None,
nside: int | None = None,
) -> np.ndarray:
r"""
Compute the forward Wigner transform, i.e. Fourier transform on
Expand All @@ -106,31 +99,24 @@ def forward(
:math:`\alpha` with :math:`\phi`.

Args:
f (np.ndarray): Signal on the on :math:`SO(3)` with shape
f: Signal on the on :math:`SO(3)` with shape
:math:`[n_{\gamma}, n_{\beta}, n_{\alpha}]`, where :math:`n_\xi` denotes the
number of samples for angle :math:`\xi`.

L (int): Harmonic bandlimit.

N (int): Directional band-limit.

L_lower (int, optional): Harmonic lower bound. Defaults to 0.

sampling (str, optional): Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh"}. Defaults to "mw".

reality (bool, optional): Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs. Defaults to
False.

nside (int, optional): HEALPix Nside resolution parameter. Only required
if sampling="healpix". Defaults to None.
L: Harmonic bandlimit.
N: Directional band-limit.
L_lower: Harmonic lower bound.
sampling: Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh"}.
reality: Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs.
nside: HEALPix Nside resolution parameter. Only required
if sampling="healpix".

Raises:
ValueError: Sampling scheme not currently supported.

Returns:
np.ndarray: Wigner coefficients `flmn` with shape :math:`[2N-1, L, 2L-1]`.
Wigner coefficients `flmn` with shape :math:`[2N-1, L, 2L-1]`.

"""
assert f.shape == samples.f_shape(L, N, sampling, nside)
Expand Down
121 changes: 44 additions & 77 deletions src/s2fft/precompute_transforms/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,22 @@ def spin_spherical_kernel(
bandlimits :math:`L\geq 512`.

Args:
L (int): Harmonic band-limit.

spin (int): Harmonic spin.

reality (bool, optional): Whether the signal on the sphere is real. If so,
L: Harmonic band-limit.
spin: Harmonic spin.
reality: Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs.
Defaults to False.

sampling (str, optional): Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}. Defaults to "mw".

nside (int): HEALPix Nside resolution parameter. Only required
sampling: Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}.
nside: HEALPix Nside resolution parameter. Only required
if sampling="healpix".

forward (bool, optional): Whether to provide forward or inverse shift.
forward: Whether to provide forward or inverse shift.
Defaults to False.

recursion (str, optional): Recursion to adopt. Supported recursion schemes include
recursion: Recursion to adopt. Supported recursion schemes include
{"auto", "price-mcewen", "risbo"}. Defaults to "auto" which will detect the
most appropriate recursion given the parameter configuration.

Returns:
np.ndarray: Transform kernel for spin-spherical harmonic transform.
Transform kernel for spin-spherical harmonic transform.

"""
if reality and spin != 0:
Expand Down Expand Up @@ -188,29 +181,22 @@ def spin_spherical_kernel_jax(
bandlimits :math:`L\geq 512`.

Args:
L (int): Harmonic band-limit.

spin (int): Harmonic spin.

reality (bool, optional): Whether the signal on the sphere is real. If so,
L: Harmonic band-limit.
spin: Harmonic spin.
reality: Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs.
Defaults to False.

sampling (str, optional): Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}. Defaults to "mw".

nside (int): HEALPix Nside resolution parameter. Only required
sampling: Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}.
nside: HEALPix Nside resolution parameter. Only required
if sampling="healpix".

forward (bool, optional): Whether to provide forward or inverse shift.
forward: Whether to provide forward or inverse shift.
Defaults to False.

recursion (str, optional): Recursion to adopt. Supported recursion schemes include
recursion: Recursion to adopt. Supported recursion schemes include
{"auto", "price-mcewen", "risbo"}. Defaults to "auto" which will detect the
most appropriate recursion given the parameter configuration.

Returns:
jnp.ndarray: Transform kernel for spin-spherical harmonic transform.
Transform kernel for spin-spherical harmonic transform.

"""
if reality and spin != 0:
Expand Down Expand Up @@ -343,29 +329,21 @@ def wigner_kernel(
bandlimits :math:`L\geq 512`.

Args:
L (int): Harmonic band-limit.

N (int): Directional band-limit.

reality (bool, optional): Whether the signal on the sphere is real. If so,
L: Harmonic band-limit.
N: Directional band-limit.
reality: Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs.
Defaults to False.

sampling (str, optional): Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}. Defaults to "mw".

nside (int): HEALPix Nside resolution parameter. Only required
sampling: Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}.
nside: HEALPix Nside resolution parameter. Only required
if sampling="healpix".

forward (bool, optional): Whether to provide forward or inverse shift.
Defaults to False.

mode (str, optional): Whether to use FFT approach or manually compute each element.
forward: Whether to provide forward or inverse shift.
mode: Whether to use FFT approach or manually compute each element.
{"auto", "direct", "fft"}. Defaults to "auto" which will detect the
most appropriate recursion given the parameter configuration.

Returns:
np.ndarray: Transform kernel for Wigner transform.
Transform kernel for Wigner transform.

"""
if mode.lower() == "fft" and not samples.is_equiangular_in_theta(sampling):
Expand Down Expand Up @@ -476,29 +454,21 @@ def wigner_kernel_jax(
bandlimits :math:`L\geq 512`.

Args:
L (int): Harmonic band-limit.

N (int): Directional band-limit.

reality (bool, optional): Whether the signal on the sphere is real. If so,
L: Harmonic band-limit.
N: Directional band-limit.
reality: Whether the signal on the sphere is real. If so,
conjugate symmetry is exploited to reduce computational costs.
Defaults to False.

sampling (str, optional): Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}. Defaults to "mw".

nside (int): HEALPix Nside resolution parameter. Only required
sampling: Sampling scheme. Supported sampling schemes include
{"mw", "mwss", "dh", "gl", "healpix", "cc", "f2"}.
nside: HEALPix Nside resolution parameter. Only required
if sampling="healpix".

forward (bool, optional): Whether to provide forward or inverse shift.
Defaults to False.

mode (str, optional): Whether to use FFT approach or manually compute each element.
forward: Whether to provide forward or inverse shift.
mode: Whether to use FFT approach or manually compute each element.
{"auto", "direct", "fft"}. Defaults to "auto" which will detect the
most appropriate recursion given the parameter configuration.

Returns:
jnp.ndarray: Transform kernel for Wigner transform.
Transform kernel for Wigner transform.

"""
if mode.lower() == "fft" and not samples.is_equiangular_in_theta(sampling):
Expand Down Expand Up @@ -602,10 +572,10 @@ def fourier_wigner_kernel(L: int) -> tuple[np.ndarray, np.ndarray]:
weights upsampled for the forward Fourier-Wigner transform.

Args:
L (int): Harmonic band-limit.
L: Harmonic band-limit.

Returns:
Tuple[np.ndarray, np.ndarray]: Tuple of delta Fourier coefficients and weights.
Tuple of delta Fourier coefficients and weights.

"""
# Calculate deltas (np.pi/2 Fourier coefficients of Wigner matrices)
Expand All @@ -630,10 +600,10 @@ def fourier_wigner_kernel_jax(L: int) -> tuple[jnp.ndarray, jnp.ndarray]:
weights upsampled for the forward Fourier-Wigner transform (JAX implementation).

Args:
L (int): Harmonic band-limit.
L: Harmonic band-limit.

Returns:
Tuple[jnp.ndarray, jnp.ndarray]: Tuple of delta Fourier coefficients and weights.
Tuple of delta Fourier coefficients and weights.

"""
# Calculate deltas (np.pi/2 Fourier coefficients of Wigner matrices)
Expand Down Expand Up @@ -662,15 +632,12 @@ def healpix_phase_shifts(L: int, nside: int, forward: bool = False) -> np.ndarra
Generates a phase shift vector for HEALPix for all :math:`\theta` rings.

Args:
L (int, optional): Harmonic band-limit.

nside (int): HEALPix Nside resolution parameter.

forward (bool, optional): Whether to provide forward or inverse shift.
Defaults to False.
L: Harmonic band-limit.
nside: HEALPix Nside resolution parameter.
forward: Whether to provide forward or inverse shift.

Returns:
np.ndarray: Vector of phase shifts with shape :math:`[thetas, 2L-1]`.
Vector of phase shifts with shape :math:`[thetas, 2L-1]`.

"""
thetas = samples.thetas(L, "healpix", nside)
Expand Down
Loading
Loading