Skip to main content

High-performance FITS I/O for PyTorch

Project description

torchfits

PyPI Wheels CI

Fast FITS I/O for PyTorch image and table workflows.

Features

  • Native PyTorch Integration: Read FITS images and tables directly into torch.Tensor with zero-copy efficiency, supporting CPU, CUDA, and MPS.
  • High Performance: Built on a multi-threaded C++ engine that outperforms fitsio and astropy by 2x-30x in typical workloads.
  • Smart Data Handling: Stream large catalogs with predicate pushdown (where="MAG < 20") and load massive images using memory-efficient chunking.
  • Astronomy Ready: Full WCS support, efficient cutout reading, and Rice/HCOMPRESS handling out of the box.

Install

pip install torchfits

Quick Examples

GPU-Accelerated Image Loading

Read science images directly to GPU memory without intermediate copies:

import torchfits

# Load directly to CUDA device (or 'mps' on Mac)
data, header = torchfits.read(
    "science.fits",
    hdu=0,
    device='cuda',
    return_header=True
)
print(data.shape, data.dtype)  # torch.Size([4096, 4096]), torch.float32

Efficient Catalog Filtering and Streaming

Filter million-row tables at the C++ level before loading into Python:

# Read only standard stars brighter than mag 20
table = torchfits.table.read(
    "catalog.fits",
    columns=["RA", "DEC", "MAG_G"],
    where="MAG_G < 20.0 AND CLASS_STAR > 0.9"
)

# Stream massive catalogs in batches
for batch in torchfits.table.scan("survey.fits", batch_size=50_000):
   process(batch)

Performance Snapshot (v0.3.0 Readiness)

torchfits is designed for high-throughput astronomical workflows, delivering 10x-100x speedups over astropy for large arrays and tables. In the 0.3.0 exhaustive suite, it maintains a strong lead in FITS image and table I/O (1.5x-4x median speedups vs fitsio) while achieving parity or better in the HEALPix sphere domain (~89% win rate). While Batch WCS throughput (N > 100k) excels, small-N coordinate transforms and complex spin-harmonic operations (sphere) remain current targets for the 0.3.x optimization roadmap.

Full benchmarks and known deficits: docs/benchmarks.md

Documentation

License

GPL-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchfits-0.3.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torchfits-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

torchfits-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (3.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

torchfits-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

torchfits-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file torchfits-0.3.0.tar.gz.

File metadata

  • Download URL: torchfits-0.3.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torchfits-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e00e8737cfe54d063ff6284a0b921914ec2026cb06b937e38365f095f54afc14
MD5 f64720a3b42ea384a506d94bb9cd72a9
BLAKE2b-256 f6c6be8daec62740b3eff3981a76c0c63b65ab1225a7ea512ee8ce09341ba8ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchfits-0.3.0.tar.gz:

Publisher: build_wheels.yml on sfabbro/torchfits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchfits-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for torchfits-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d300613fed93f6d22835ebc1acd9d28eb46c2c38445f50cbd7da652ef3e4214b
MD5 0d7ffa9b6ed5024fc685c8ae70b0d687
BLAKE2b-256 2577cb9cc1c1add742f1afcbbff35d920b4c915907ad80974a884e807eea636b

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchfits-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on sfabbro/torchfits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchfits-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for torchfits-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6fe102b7f82005deb834767b40f25b2ad33ac787b3aa3ee94303e009863cb9be
MD5 b60808fe00d63f612a7c1d49d7fe76cc
BLAKE2b-256 43d7da764a34e66f3f931145394d24526bee3d5f74023c181491f7f9366f6a82

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchfits-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on sfabbro/torchfits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchfits-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for torchfits-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e1a69a515fb0aab1158d3638a75be6a8078d368a517e29c35332c4eecce28b3
MD5 2b9ddec89d972154dd8666a394aaf1d3
BLAKE2b-256 65f0e8440471c63c568aeee32ec45b51c74f8a899e97ee271d69670831b7bf02

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchfits-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on sfabbro/torchfits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchfits-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for torchfits-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7734f899bbbe16def2c4f5335ce9a67398a09b483f37d4545da0408a01dd9aa
MD5 14e15320f9f2cb252a412d18fad577cc
BLAKE2b-256 5cedb6fd80db2a747f544f66c70fcb9f690e0df14087b80667bb21a875915a8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchfits-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on sfabbro/torchfits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page