FITS I/O for PyTorch
Browse¶
- Install Wheels, source builds, GPU / accelerator notes.
-
Quick start
read_tensor, table filters, DataLoader. -
CLI
info,header,verify,cutout, … - API Core I/O, tables, datasets, transforms.
- Examples Runnable scripts and transform galleries.
- Benchmarks Methodology and scorecards.
- Migration From Astropy / fitsio.
- Parity What torchfits covers today.
At a glance¶
import torchfits
tensor = torchfits.read_tensor("image.fits", hdu=0, device="cuda")
table = torchfits.table.read("catalog.fits", hdu=1, where="MAG_G < 20")
from torchfits.data import FitsImageDataset, make_loader
loader = make_loader(FitsImageDataset("images/*.fits"), batch_size=32)
torchfits info image.fits
torchfits header image.fits -k OBJECT -f json
Why torchfits?¶
torchfits is a 1.0.0rc4 prerelease — see Changelog and Benchmarks for scope and known lags.
| astropy / fitsio | torchfits | |
|---|---|---|
| Image read (16 MB, MPS) | 8.16 ms / 3.67 ms | 3.85 ms (~2× vs astropy; ~parity vs fitsio) |
| Table read (100k rows, mixed) | 31.85 ms / 10.44 ms | 2.20 ms (~15× / ~5×) |
| Repeated cutouts (50×) | 86.01 ms / 5.37 ms | 0.79 ms (~116× / ~7×) |
| GPU placement | manual .to(device) |
device="cuda" / "mps" |
| Table filtering | Python mask | C++ pushdown (where=) |
| Training loop | hand-rolled Dataset | FitsImageDataset + make_loader |
| Shell tooling | fitsinfo / fitsheader / … | torchfits CLI |
Representative medians from Round-3 exhaustive_mps_20260719_143706
(methodology and deficits in Benchmarks).