Skip to content
torchsky

Sky computing for PyTorch

Sky geometry, catalogs, maps, spectra, and differentiable models as PyTorch tensor code, at survey scale, on CPU, CUDA, and Apple Silicon.

import torch
from torchsky.wcs import WCS
import torchsky.sphere as sphere

wcs = WCS(header)  # header: a plain dict, e.g. from torchfits
x = y = torch.arange(0.0, 512.0, 64.0)
ra, dec = wcs.pixel_to_world(x, y)
pix = sphere.ang2pix(1024, ra, dec, lonlat=True, nest=True)

Home

These docs have not yet been verified by a human

The guides, examples and reference text for this first release were drafted with AI assistance. Automated tests run every code snippet and example, but no person has yet reviewed the prose, the numbers or the recommendations. Treat them as a draft, check results that matter, and report anything wrong.

torchsky does astronomy's sky-domain computations as PyTorch tensor code: coordinates and WCS, HEALPix and spherical geometry, catalog crossmatches, image coadds and HEALPix maps, spectra and synthetic photometry, and differentiable sky models. Inputs are tensors and header dicts, outputs are tensors on the same device (CPU, CUDA, or Apple MPS), and the autograd graph stays intact. The kernels batch, index, and stream, so the call that handles a hundred rows also handles a survey.

torchfits reads and writes the FITS files; torchsky starts from the tensors it returns.


Real Data

Each example fetches a small public sample once, runs in seconds on a CPU, and prints quantitative checks of its result. Select a figure to open the example.


Areas

  • Coordinates and WCS


    Pixels to sky and back with FITS WCS, SIP and TPV distortions, celestial frames, proper motion, and observed place.

    Coordinates

  • Celestial sphere


    HEALPix indexing and queries, exact spherical regions, MOC coverage, sparse maps, and spherical harmonic transforms.

    Celestial sphere

  • Catalogs


    Catalogs as tensors with frame and epoch; cone and footprint selection; exact crossmatches from a few rows to billions.

    Catalogs

  • Images and maps


    Plan a target grid, resample with declared kernels or drizzle, and coadd images, spectral cubes, and HEALPix maps.

    Images and maps

  • Spectra and photometry


    Spectral axes, redshift and Doppler shifts, dust laws, passbands, synthetic magnitudes, and cosmological distances.

    Spectra and photometry

  • Models (experimental)


    Forward models of the sky through each exposure's WCS, PSF, and bandpass, fitted by gradient descent with exact adjoints.

    Models


Start Here


Stable releases are on PyPI (pip install torchsky); release candidates are GitHub pre-releases and are never uploaded to PyPI. Install covers wheels and source builds.