High-performance FITS I/O for PyTorch
Project description
torchfits
torchfits is a focused FITS I/O library for PyTorch. It reads and writes FITS images, headers, HDUs, compressed images, and FITS tables through a multi-threaded C++ engine with vendored CFITSIO, returning tensor-native data without requiring users to build NumPy-to-torch glue code.
It is not a full replacement for Astropy, fitsio, or CFITSIO. The supported surface is documented explicitly in docs/parity.md, with source-backed tests for each claimed parity area. WCS, sky-coordinate models, HEALPix, sphere geometry, and sky-domain simulation workflows are out of scope for torchfits.
At a Glance
| Task | Traditional stack | torchfits equivalent |
|---|---|---|
| Read image to GPU | astropy/fitsio → numpy → torch → .to(device) |
torchfits.read("img.fits", device="cuda") |
| Write tensor to FITS | tensor → numpy → astropy HDU → writeto | torchfits.write("out.fits", tensor) |
| Filter large table | load all rows → mask in Python | where="MAG < 20" pushdown in C++ |
| Read multi-extension files | manual HDU dispatch | with torchfits.open("mef.fits") as hdul: ... |
| Verify FITS checksums | comparator-specific helpers | torchfits.verify_checksums(path) |
Features
FITS I/O — Multi-threaded C++ core with SIMD-optimized type conversion, memory-mapped image reads, intelligent chunking, and adaptive buffering. Reads and writes images, binary/ASCII tables, compressed images, and multi-extension FITS files with header round-trip coverage.
Table Engine — Arrow-native table API with predicate pushdown (where=), column projection, row slicing, streaming scan(), and in-place mutations (append, insert, update, delete rows and columns). Interop with Pandas, Polars, DuckDB, and PyArrow.
Compatibility Contract — Parity is tracked by tier: truthful public docs, fitsio core workflow parity, Astropy common workflow parity, selected CFITSIO backend behavior, and explicit non-goals. See docs/parity.md.
Install
pip install torchfits
Pre-built wheels are available for Linux and macOS (x86_64, arm64). No system CFITSIO needed—it's vendored and compiled automatically.
From source:
git clone https://github.com/astroai/torchfits.git
cd torchfits
pip install -e .
Requires Python 3.10+, a C++17 compiler, CMake 3.21+, and PyTorch 2.0+.
Quick Start
Read an image to GPU
import torchfits
data, header = torchfits.read("science.fits", device="cuda", return_header=True)
# data: torch.Tensor on CUDA, shape e.g. (4096, 4096), dtype torch.float32
Filter and stream a catalog
# Predicate pushdown — only matching rows leave C++
table = torchfits.table.read(
"catalog.fits",
columns=["RA", "DEC", "MAG_G"],
where="MAG_G < 20.0 AND CLASS_STAR > 0.9",
)
# table: pyarrow.Table
# Stream 100M rows in constant memory
for batch in torchfits.table.scan("survey.fits", batch_size=50_000):
process(batch) # batch: pyarrow.RecordBatch
Multi-HDU access
with torchfits.open("multi_ext.fits") as hdul:
print(hdul) # pretty-printed summary
img = hdul[0].data # image tensor
tbl = hdul[1].data # dict-like table accessor
tbl_filtered = hdul[1].filter("FLUX > 100 AND FLAG = 0")
Write back
torchfits.write("output.fits", data, header=header, overwrite=True)
# table_dict is a dict of column names to 1D arrays/tensors
torchfits.table.write("catalog_out.fits", table_dict, header=header, overwrite=True)
Benchmarks
torchfits benchmark evidence is limited to FITS image I/O and FITS table I/O.
Comparators are astropy.io.fits and fitsio; selected CFITSIO behavior is
validated through the torchfits native backend and smoke tests.
Methodology, reproducible commands, results, and known deficits: docs/benchmarks.md
Documentation
| API Reference | Full public API with signatures and examples |
| Roadmap | FITS I/O roadmap and parity tiers |
| Parity Matrix | Supported, partial, unsupported, and out-of-scope features |
| Examples | Runnable scripts for every major workflow |
| Installation | Build from source, GPU setup, troubleshooting |
| Benchmarks | Methodology, commands, and latest numbers |
| Changelog | Version history and migration notes |
| Release Checklist | Maintainer guide for cutting releases |
Contributing
git clone https://github.com/astroai/torchfits.git
cd torchfits
pixi install
pixi run test
The project uses pixi for environment management, ruff for linting, and pytest for testing.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchfits-0.5.0b3.tar.gz.
File metadata
- Download URL: torchfits-0.5.0b3.tar.gz
- Upload date:
- Size: 403.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da09b3959c81a2209d6c2155ef029200b7cedf7a94b4e56b649a204844e96c76
|
|
| MD5 |
22da3ffdb47f8e076e3325dcdbc69d08
|
|
| BLAKE2b-256 |
6f9eda549efad73b8ad888ff20e63286d4a5aee3e24c76f0e16641ba52a2db00
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3.tar.gz:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3.tar.gz -
Subject digest:
da09b3959c81a2209d6c2155ef029200b7cedf7a94b4e56b649a204844e96c76 - Sigstore transparency entry: 2019055667
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50798d9af33b624a3262a62d4ca4a5541c2036d32c436aab99805e6a264e1f0f
|
|
| MD5 |
03c7e392ad03c7b5e58552a29a698843
|
|
| BLAKE2b-256 |
fc2dee3205a7b624c26de0e4e25794aa9aa42f123d3bb9b24518fa0f7bdec8db
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
50798d9af33b624a3262a62d4ca4a5541c2036d32c436aab99805e6a264e1f0f - Sigstore transparency entry: 2019055765
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c3074b73b45aa25e6c135c4afa19236e0c441d2dc8dfb2c102f9e29de39dc2b
|
|
| MD5 |
2009d3df5ef976dd27127921f037dbe8
|
|
| BLAKE2b-256 |
d00ecf2e020d44063b45c57e3c34c8e88b579019dca053a0344c6d7fb5d75d25
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp313-cp313-macosx_11_0_arm64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
5c3074b73b45aa25e6c135c4afa19236e0c441d2dc8dfb2c102f9e29de39dc2b - Sigstore transparency entry: 2019056336
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ec71977cc12ed6a1b131e02ebf68d42f54995b99425250243262f1f2a4463c2
|
|
| MD5 |
41c7c434c622ac42b480874653691fa5
|
|
| BLAKE2b-256 |
6f320c1c88b9e833cf43c3736d20285a1e30433eacf13d6bf186f5a4b9eeac5b
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
7ec71977cc12ed6a1b131e02ebf68d42f54995b99425250243262f1f2a4463c2 - Sigstore transparency entry: 2019056033
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2423ecc3a12e3d0c111afba5123b5fb07ca49a14bd37cbf5f5c4a9169b44287
|
|
| MD5 |
5656e60312d556bbe32a5e7aa6bf1d35
|
|
| BLAKE2b-256 |
95ce67f9f419b816a7496b8cc23f0549232d1ba60bd3cdd4df53ad480a9c0ece
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
b2423ecc3a12e3d0c111afba5123b5fb07ca49a14bd37cbf5f5c4a9169b44287 - Sigstore transparency entry: 2019056218
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
569ceeb8c00952c7a9b91901fe8f6ae4f4ec9dc37d55f20f45d4e629e957b12d
|
|
| MD5 |
848bdbdc5585f3515a57d27aca0cc006
|
|
| BLAKE2b-256 |
ed6c451553d34a45332b31891d944d191a6363e0504a6bea98b375a2dfd84d08
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
569ceeb8c00952c7a9b91901fe8f6ae4f4ec9dc37d55f20f45d4e629e957b12d - Sigstore transparency entry: 2019055936
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9db527ae61156f904b1c6b3e4b97d41a59457f5032622809b5b3a987fd22c7c7
|
|
| MD5 |
35c7d151c6119a5ea6484f676432690a
|
|
| BLAKE2b-256 |
e0ec0bbb22bfd8d128e8985d3cd7b6f43dc213f855543dda4e2956096b6e19c4
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp311-cp311-macosx_11_0_arm64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp311-cp311-macosx_11_0_arm64.whl -
Subject digest:
9db527ae61156f904b1c6b3e4b97d41a59457f5032622809b5b3a987fd22c7c7 - Sigstore transparency entry: 2019055841
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8881cbe7ddbef8eddfa0fdbc663c9b1281a5e6f6a1033da747d42ebef8a1726
|
|
| MD5 |
18a9638f44598302aacc17733674b99e
|
|
| BLAKE2b-256 |
31cfe8f4820c38c6e0e4e29719a85140adb81783a68759fa9622c969e4c27bf3
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
c8881cbe7ddbef8eddfa0fdbc663c9b1281a5e6f6a1033da747d42ebef8a1726 - Sigstore transparency entry: 2019056123
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchfits-0.5.0b3-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: torchfits-0.5.0b3-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d7fc870ce3680e52fba56ad8fc0f0939e6f73988770f7286acd854f45ac0528
|
|
| MD5 |
c5c1b6b134db40f9416888543438261a
|
|
| BLAKE2b-256 |
5d4e7838f46796aa5f967f97a3b548c6c283002443fc6a1c8c8647e085209b29
|
Provenance
The following attestation bundles were made for torchfits-0.5.0b3-cp310-cp310-macosx_11_0_arm64.whl:
Publisher:
build_wheels.yml on astroai/torchfits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchfits-0.5.0b3-cp310-cp310-macosx_11_0_arm64.whl -
Subject digest:
6d7fc870ce3680e52fba56ad8fc0f0939e6f73988770f7286acd854f45ac0528 - Sigstore transparency entry: 2019056412
- Sigstore integration time:
-
Permalink:
astroai/torchfits@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Branch / Tag:
refs/tags/v0.5.0b3 - Owner: https://github.com/astroai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_wheels.yml@bf92229a4999adc007006f67c34b02197fbc3ee8 -
Trigger Event:
push
-
Statement type: