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.
__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",
]
Alm ¶
healpy-shaped helpers for packed (ell, m) coefficient indices.
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).
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
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.
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.