Skip to content

torchsky.sphere.compat

Stability: compatibility. This page mirrors a familiar upstream API on top of torchsky kernels. Behavior follows the documented torchsky contract.

healpy-shaped HEALPix compatibility layer built on torchsky kernels. Use it when migrating healpy code; prefer the torchsky.sphere names for new work.

Guides: healpix


This page is generated from the module source. Import these names from torchsky.sphere.compat.

Module

torchsky.sphere.compat

HEALPix / healpy compatibility layer (one slice of torchsky’s broader ecosystem compatibility story). torchsky also documents call mappings from Astropy, spherical_geometry, and other common packages at their respective API layers; see docs/introduction/coming-from.md.

This module implements healpy’s NumPy-oriented HEALPix API with :class:torch.Tensor inputs/outputs and torchsky-native kernels (no optional hpgeom dispatch).

Scope

  • Pixel / geometry — indexing, neighbors, disc/box/polygon queries, reordering, and related helpers are delegated to :mod:torchsky.sphere.healpix (re-exported here under familiar healpy names).
  • Harmonic / map — map2alm, alm2map, synfast, pixwin, spin transforms, smoothing, etc. delegate to :mod:torchsky.sphere.spectral (torch + torchsky C++ only).

Relationship to :mod:torchsky.sphere

Top-level :mod:torchsky.sphere exposes the same spectral helpers as the native API. This module is the healpy-shaped compatibility surface: names and signatures aligned with healpy for porting and tests. Use import torchsky.sphere.compat as hp when porting healpy code. Other ecosystem mirrors (WCS, FITS tables, polygon semantics, etc.) live in their own subpackages.

Completeness

The goal is to cover healpy’s public HEALPix/spherical-harmonic surface over time. Missing routines should be added here (thin wrappers) rather than scattered across the package. Parity tests may compare against optional healpy where installed; geometry kernels remain torchsky-native.

UNSEEN module-attribute

UNSEEN = UNSEEN

__all__ module-attribute

__all__ = [
    "UNSEEN",
    "Alm",
    "Rotator",
    "ang2pix",
    "ang2vec",
    "boundaries",
    "map2alm",
    "map2alm_lsq",
    "almxfl",
    "rotate_alm",
    "alm2cl",
    "alm2map",
    "alm2map_der1",
    "anafast",
    "gaussian_beam",
    "gauss_beam",
    "pixwin",
    "bl2beam",
    "beam2bl",
    "synalm",
    "synfast",
    "fit_dipole",
    "fit_monopole",
    "get_all_neighbors",
    "get_all_neighbours",
    "get_interp_val",
    "get_interp_weights",
    "get_map_size",
    "get_nside",
    "isnpixok",
    "isnsideok",
    "max_pixrad",
    "nest2ring",
    "npix2nside",
    "nside2npix",
    "nside2pixarea",
    "nside2order",
    "nside2resol",
    "new_map",
    "order2nside",
    "pix2ang",
    "pix2vec",
    "degrade_pixels",
    "degrade_pixel_ranges",
    "pixel_ranges_to_pixels",
    "pixels_to_pixel_ranges",
    "query_box",
    "query_circle",
    "query_circle_vec",
    "query_disc",
    "query_ellipse",
    "query_polygon",
    "query_polygon_vec",
    "query_strip",
    "reorder",
    "smoothalm",
    "smoothmap",
    "smoothing",
    "map2alm_spin",
    "alm2map_spin",
    "remove_dipole",
    "remove_monopole",
    "read_map",
    "ring2nest",
    "ud_grade",
    "upgrade_pixels",
    "upgrade_pixel_ranges",
    "vec2ang",
    "vec2pix",
    "write_map",
]

ang2vec module-attribute

ang2vec = ang2vec

boundaries module-attribute

boundaries = boundaries

degrade_pixel_ranges module-attribute

degrade_pixel_ranges = degrade_pixel_ranges

degrade_pixels module-attribute

degrade_pixels = degrade_pixels

get_interp_val module-attribute

get_interp_val = get_interp_val

get_interp_weights module-attribute

get_interp_weights = get_interp_weights

get_map_size module-attribute

get_map_size = get_map_size

get_nside module-attribute

get_nside = get_nside

isnpixok module-attribute

isnpixok = isnpixok

isnsideok module-attribute

isnsideok = isnsideok

max_pixrad module-attribute

max_pixrad = max_pixel_radius

nest2ring module-attribute

nest2ring = nest2ring

npix2nside module-attribute

npix2nside = npix2nside

nside2npix module-attribute

nside2npix = nside2npix

nside2order module-attribute

nside2order = nside2order

nside2pixarea module-attribute

nside2pixarea = nside2pixarea

nside2resol module-attribute

nside2resol = nside2resol

order2nside module-attribute

order2nside = order2nside

pix2vec module-attribute

pix2vec = pix2vec

pixel_ranges_to_pixels module-attribute

pixel_ranges_to_pixels = pixel_ranges_to_pixels

pixels_to_pixel_ranges module-attribute

pixels_to_pixel_ranges = pixels_to_pixel_ranges

query_box module-attribute

query_box = query_box

query_disc module-attribute

query_disc = query_disc

query_polygon module-attribute

query_polygon = query_polygon

query_polygon_vec module-attribute

query_polygon_vec = query_polygon_vec

query_strip module-attribute

query_strip = query_strip

reorder module-attribute

reorder = reorder

ring2nest module-attribute

ring2nest = ring2nest

ud_grade module-attribute

ud_grade = ud_grade

upgrade_pixel_ranges module-attribute

upgrade_pixel_ranges = upgrade_pixel_ranges

upgrade_pixels module-attribute

upgrade_pixels = upgrade_pixels

vec2ang module-attribute

vec2ang = vec2ang

vec2pix module-attribute

vec2pix = vec2pix

Alm

healpy-shaped helpers for packed (ell, m) coefficient indices.

getidx staticmethod
getidx(
    lmax: int, ell: int, m: int, mmax: int | None = None
) -> int

Return the packed index of the (l, m) coefficient.

getlm staticmethod
getlm(i: int, lmax: int) -> tuple[int, int]

Return (l, m) for a packed coefficient index.

Rotator

Rotator(
    rot: tuple[float, float, float]
    | list[float]
    | None = None,
    *,
    deg: bool = True,
)

Thin healpy-shaped rotator for zyz Euler angles (psi, theta, phi).

phi instance-attribute
phi = phi
psi instance-attribute
psi = psi
theta instance-attribute
theta = theta
rotate_alm
rotate_alm(
    alm: Tensor,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
) -> Tensor
rotate_map_alms
rotate_map_alms(
    m: Tensor,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
) -> Tensor

alm2cl

alm2cl(
    alms1: Tensor,
    alms2: Tensor | None = None,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
    lmax_out: int | None = None,
    nspec: int | None = None,
) -> Tensor

alm2map

alm2map(
    alm_values: Tensor,
    nside: int,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
    pol: bool = False,
    pixwin: bool = False,
) -> Tensor

alm2map_der1

alm2map_der1(
    alm: Tensor,
    nside: int,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
) -> tuple[Tensor, Tensor, Tensor]

alm2map_spin

alm2map_spin(
    alms: tuple[Tensor, Tensor],
    nside: int,
    spin: int,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
) -> Tensor

almxfl

almxfl(
    alm: Tensor,
    fl: Tensor,
    mmax: int | None = None,
    inplace: bool = False,
) -> Tensor

anafast

anafast(
    map1: Tensor,
    map2: Tensor | None = None,
    *,
    nside: int | None = None,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
    nspec: int | None = None,
    iter: int = 0,
    alm: bool = False,
    pol: bool = True,
    use_weights: bool = False,
    use_pixel_weights: bool = False,
    gal_cut: float = 0.0,
    datapath: str | PathLike[str] | None = None,
) -> (
    Tensor
    | tuple[Tensor, Tensor]
    | tuple[Tensor, Tensor, Tensor]
)

ang2pix

ang2pix(
    nside: int,
    theta: Tensor,
    phi: Tensor,
    nest: bool = False,
    lonlat: bool = False,
) -> Tensor

beam2bl

beam2bl(beam: Tensor, theta: Tensor, lmax: int) -> Tensor

bl2beam

bl2beam(bl: Tensor, theta: Tensor) -> Tensor

fit_dipole

fit_dipole(
    map_values: Tensor,
    *,
    nest: bool = False,
    bad: float = UNSEEN,
    gal_cut: float = 0.0,
    nside: int | None = None,
    valid_mask: Tensor | None = None,
) -> tuple[Tensor, Tensor]

Fit monopole and dipole to a HEALPix map.

Returns (monopole, dipole_xyz).

fit_monopole

fit_monopole(
    map_values: Tensor,
    *,
    nest: bool = False,
    bad: float = UNSEEN,
    gal_cut: float = 0.0,
) -> Tensor

Fit monopole term with healpy-like masking semantics.

gauss_beam

gauss_beam(
    fwhm: float, lmax: int = 512, pol: bool = False
) -> Tensor

gaussian_beam

gaussian_beam(
    fwhm_rad: float, lmax: int, *, pol: bool = False
) -> Tensor

get_all_neighbors

get_all_neighbors(
    nside: int,
    theta: Tensor | float | int,
    phi: Tensor | float | None = None,
    nest: bool = False,
    lonlat: bool = False,
) -> Tensor

get_all_neighbours

get_all_neighbours(
    nside: int,
    theta: Tensor | float | int,
    phi: Tensor | float | None = None,
    nest: bool = False,
    lonlat: bool = False,
) -> Tensor

map2alm

map2alm(
    map_values: Tensor,
    *,
    nside: int | None = None,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
    iter: int = 0,
    pol: bool = False,
    use_weights: bool = False,
    use_pixel_weights: bool = False,
    gal_cut: float = 0.0,
    datapath: str | PathLike[str] | None = None,
) -> Tensor

map2alm_lsq

map2alm_lsq(
    maps: Tensor,
    lmax: int,
    mmax: int | None = None,
    pol: bool = True,
    tol: float = 1e-10,
    maxiter: int = 20,
    *,
    nside: int | None = None,
    nest: bool = False,
    use_pixel_weights: bool = False,
    gal_cut: float = 0.0,
    datapath: str | PathLike[str] | None = None,
) -> tuple[Tensor, float, int]

map2alm_spin

map2alm_spin(
    maps: Tensor,
    spin: int,
    *,
    nside: int | None = None,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
    iter: int = 0,
    use_weights: bool = False,
    use_pixel_weights: bool = False,
    gal_cut: float = 0.0,
    datapath: str | PathLike[str] | None = None,
) -> tuple[Tensor, Tensor]

new_map

new_map(nside: int, dtype: dtype = float64) -> Tensor

Return a zero-valued RING-ordered HEALPix map.

pix2ang

pix2ang(
    nside: int,
    ipix: Tensor,
    nest: bool = False,
    lonlat: bool = False,
) -> tuple[Tensor, Tensor]

pixwin

pixwin(
    nside: int, pol: bool = False, lmax: int | None = None
) -> Tensor | tuple[Tensor, Tensor]

query_circle

query_circle(
    nside: int,
    lon: Tensor | float,
    lat: Tensor | float,
    radius: float,
    *,
    degrees: bool = True,
    inclusive: bool = False,
    nest: bool = False,
    chunk_size: int = 1000000,
    fact: int = 4,
    return_pixel_ranges: bool = False,
) -> Tensor

query_circle_vec

query_circle_vec(
    nside: int,
    vec: Tensor,
    radius: float,
    *,
    inclusive: bool = False,
    fact: int = 4,
    nest: bool = False,
    chunk_size: int = 1000000,
    return_pixel_ranges: bool = False,
) -> Tensor

query_ellipse

query_ellipse(
    nside: int,
    a: float | Tensor,
    b: float | Tensor,
    semi_major: float,
    semi_minor: float,
    alpha: float | None = None,
    *,
    pa_deg: float | None = None,
    nest: bool = False,
    inclusive: bool = False,
    fact: int = 4,
    lonlat: bool = True,
    degrees: bool = True,
    return_pixel_ranges: bool = False,
) -> Tensor

read_map

read_map(filename: str | PathLike[str]) -> Tensor

Read the first image HDU as a flat HEALPix map tensor.

remove_dipole

remove_dipole(
    map_values: Tensor,
    *,
    nest: bool = False,
    bad: float = UNSEEN,
    gal_cut: float = 0.0,
    fitval: bool = False,
    copy: bool = True,
    nside: int | None = None,
    valid_mask: Tensor | None = None,
) -> Tensor | tuple[Tensor, Tensor, Tensor]

Remove fitted monopole+dipole from a HEALPix map.

remove_monopole

remove_monopole(
    map_values: Tensor,
    *,
    nest: bool = False,
    bad: float = UNSEEN,
    gal_cut: float = 0.0,
    fitval: bool = False,
    copy: bool = True,
) -> Tensor | tuple[Tensor, Tensor]

Remove fitted monopole with healpy-like masking semantics.

rotate_alm

rotate_alm(
    alm: Tensor,
    psi: float,
    theta: float,
    phi: float,
    lmax: int | None = None,
    mmax: int | None = None,
) -> Tensor

smoothalm

smoothalm(
    alm_values: Tensor,
    *,
    lmax: int | None = None,
    mmax: int | None = None,
    fwhm_rad: float | None = None,
    beam: Tensor | None = None,
    pol: bool = False,
) -> Tensor

smoothing

smoothing(
    map_in: Tensor,
    fwhm: float = 0.0,
    sigma: float | None = None,
    beam_window: Tensor | None = None,
    pol: bool = True,
    iter: int = 3,
    lmax: int | None = None,
    mmax: int | None = None,
    use_weights: bool = False,
    use_pixel_weights: bool = False,
    nest: bool = False,
    datapath: str | PathLike[str] | None = None,
) -> Tensor

smoothmap

smoothmap(
    map_values: Tensor,
    *,
    nside: int | None = None,
    lmax: int | None = None,
    mmax: int | None = None,
    nest: bool = False,
    fwhm_rad: float | None = None,
    sigma: float | None = None,
    beam: Tensor | None = None,
    beam_window: Tensor | None = None,
    pol: bool = False,
    iter: int = 0,
    use_weights: bool = False,
    use_pixel_weights: bool = False,
    gal_cut: float = 0.0,
    datapath: str | PathLike[str] | None = None,
) -> Tensor

synalm

synalm(
    cls: Tensor
    | list[Tensor | list[float] | None]
    | tuple[Tensor | list[float] | None, ...],
    lmax: int | None = None,
    mmax: int | None = None,
    *,
    new: bool = False,
) -> Tensor

synfast

synfast(
    cls: Tensor
    | list[Tensor | list[float] | None]
    | tuple[Tensor | list[float] | None, ...],
    nside: int,
    lmax: int | None = None,
    mmax: int | None = None,
    *,
    alm: bool = False,
    pol: bool = True,
    pixwin: bool = False,
    fwhm: float = 0.0,
    sigma: float | None = None,
    new: bool = False,
) -> Tensor | tuple[Tensor, Tensor]

write_map

write_map(
    filename: str | PathLike[str],
    m: Tensor,
    *,
    overwrite: bool = False,
) -> None

Write a one-dimensional RING-ordered HEALPix image through torchfits.

HEALPix indexing

HEALPix / healpy compatibility layer (one slice of torchsky’s broader ecosystem compatibility story). torchsky also documents call mappings from Astropy, spherical_geometry, and other common packages at their respective API layers; see docs/introduction/coming-from.md.

This module implements healpy’s NumPy-oriented HEALPix API with :class:torch.Tensor inputs/outputs and torchsky-native kernels (no optional hpgeom dispatch).

Scope

  • Pixel / geometry — indexing, neighbors, disc/box/polygon queries, reordering, and related helpers are delegated to :mod:torchsky.sphere.healpix (re-exported here under familiar healpy names).
  • Harmonic / map — map2alm, alm2map, synfast, pixwin, spin transforms, smoothing, etc. delegate to :mod:torchsky.sphere.spectral (torch + torchsky C++ only).

Relationship to :mod:torchsky.sphere

Top-level :mod:torchsky.sphere exposes the same spectral helpers as the native API. This module is the healpy-shaped compatibility surface: names and signatures aligned with healpy for porting and tests. Use import torchsky.sphere.compat as hp when porting healpy code. Other ecosystem mirrors (WCS, FITS tables, polygon semantics, etc.) live in their own subpackages.

Completeness

The goal is to cover healpy’s public HEALPix/spherical-harmonic surface over time. Missing routines should be added here (thin wrappers) rather than scattered across the package. Parity tests may compare against optional healpy where installed; geometry kernels remain torchsky-native.

ang2vec module-attribute

ang2vec = ang2vec

boundaries module-attribute

boundaries = boundaries

get_interp_val module-attribute

get_interp_val = get_interp_val

get_interp_weights module-attribute

get_interp_weights = get_interp_weights

get_map_size module-attribute

get_map_size = get_map_size

get_nside module-attribute

get_nside = get_nside

isnpixok module-attribute

isnpixok = isnpixok

isnsideok module-attribute

isnsideok = isnsideok

max_pixrad module-attribute

max_pixrad = max_pixel_radius

nest2ring module-attribute

nest2ring = nest2ring

npix2nside module-attribute

npix2nside = npix2nside

nside2npix module-attribute

nside2npix = nside2npix

nside2pixarea module-attribute

nside2pixarea = nside2pixarea

nside2order module-attribute

nside2order = nside2order

nside2resol module-attribute

nside2resol = nside2resol

order2nside module-attribute

order2nside = order2nside

pix2vec module-attribute

pix2vec = pix2vec

degrade_pixels module-attribute

degrade_pixels = degrade_pixels

degrade_pixel_ranges module-attribute

degrade_pixel_ranges = degrade_pixel_ranges

pixel_ranges_to_pixels module-attribute

pixel_ranges_to_pixels = pixel_ranges_to_pixels

pixels_to_pixel_ranges module-attribute

pixels_to_pixel_ranges = pixels_to_pixel_ranges

query_box module-attribute

query_box = query_box

query_disc module-attribute

query_disc = query_disc

query_polygon module-attribute

query_polygon = query_polygon

query_polygon_vec module-attribute

query_polygon_vec = query_polygon_vec

query_strip module-attribute

query_strip = query_strip

reorder module-attribute

reorder = reorder

ring2nest module-attribute

ring2nest = ring2nest

ud_grade module-attribute

ud_grade = ud_grade

upgrade_pixels module-attribute

upgrade_pixels = upgrade_pixels

upgrade_pixel_ranges module-attribute

upgrade_pixel_ranges = upgrade_pixel_ranges

vec2ang module-attribute

vec2ang = vec2ang

vec2pix module-attribute

vec2pix = vec2pix