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.2.1)

TorchFits is designed to saturate modern IO subsystems, achieving a 100% win rate against standard baselines across our 88-case exhaustive benchmark suite. It delivers median speedups of ~2.5x over fitsio and >30x over astropy for image I/O, while maintaining strict memory safety for massively large files. For machine learning pipelines, the custom FITSDataset and loader implementations match or exceed the throughput of optimized NumPy-based data loaders.

Full benchmarks: 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.2.1.tar.gz (592.9 kB view details)

Uploaded Source

Built Distributions

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

torchfits-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

torchfits-0.2.1-cp313-cp313-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

torchfits-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

torchfits-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: torchfits-0.2.1.tar.gz
  • Upload date:
  • Size: 592.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for torchfits-0.2.1.tar.gz
Algorithm Hash digest
SHA256 aa78f85c4cdd49f4508c8138ba48961024331803a939a86570335943501d28e3
MD5 0b9c1d9b7e561647d72ff22c9fbfdfe2
BLAKE2b-256 aed12a7af3033853376fe8ebb1277e1f0d7b2ba52e0cdceb3c86b3ca6d5031dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torchfits-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e923f09b7ec908b7c89136a8eeb5d62133eecb75e54743a5c34dd28424f5df2
MD5 fd5fd7de25e6405fc0879afcf259da3e
BLAKE2b-256 1f8bb4db395d81e1e02fdcb292636283624d7080a452ca535e85f90357a2f0d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torchfits-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79324d0482c25ec9d83efaad93987d3706ac08faa08b7ba570238487cb69fe92
MD5 2c817fbd697e13e59709743a2fe0a2a2
BLAKE2b-256 dd6941be4b77bbd04cf002bc3f372ad860e193114f893502f8c64efc1f2e0f96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torchfits-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b696d7c2dee37cbd80041e1bb9804d9404bba32bb6a9596856ca66b164262957
MD5 2cd2cadd6949c4d1a4f7c61457930d30
BLAKE2b-256 de9388ea93dd6e775086f51e9c4850f8303bcf2aaab0b296af8ea645971b0b95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torchfits-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b68736283eb790056c848f5eaf294ece88e1dd916e24299b95cb9be4a715f6e
MD5 b69cc12c9c98470193e6f706eab265c4
BLAKE2b-256 470537b10d5c36f549ff49077d523d9b670bc24e7de38a0440cfe7b678c0a908

See more details on using hashes here.

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