Skip to main content

High-performance FITS I/O for PyTorch

Project description

torchfits

PyPI version Python 3.11+ License: GPL v2

High-performance FITS I/O for PyTorch.

torchfits overview

Install

pip install torchfits

For local source builds, prepare vendored native dependencies first:

./extern/vendor.sh

Quick Start

import torch
import torchfits

# Read image
img, header = torchfits.read("image.fits", return_header=True)

# Read table with projection + pushdown filter
table = torchfits.table.read(
    "catalog.fits",
    hdu=1,
    columns=["OBJID", "RA", "DEC"],
    where="DEC > 0"
)

# Stream large tables
for batch in torchfits.table.scan("catalog.fits", hdu=1, batch_size=100_000):
    ...

# In-place table mutation
torchfits.table.append_rows("catalog.fits", {"RA": [1.23], "DEC": [-0.42]}, hdu=1)

WCS convenience with payload HDU autodetection:

wcs = torchfits.get_wcs("image_or_mef.fits", hdu="auto")
sky = wcs.pixel_to_world(torch.tensor([[0.0, 0.0]], dtype=torch.float64))

Features

  • FITS image I/O: full reads, subset reads, writes.
  • FITS table I/O: projection, row slicing, row filtering, streaming.
  • FITS table mutation: append/insert/delete/update rows and column edits.
  • Interop: Arrow, Polars, DuckDB.

Performance

  • Optimized for repeated reads, compressed images, and ML data-loading workflows.
  • 0.2.0 release benchmark snapshot shows torchfits ahead in 87/88 read_full cases vs fitsio and 87/88 vs fitsio_torch (details in docs/benchmarks.md).
  • benchmark_ml_loader.py on CPU is near-parity and run-order/cache sensitive; current release run showed:
    • Uncompressed median: 0.985x vs fitsio
    • Compressed median: 1.008x vs fitsio
  • Re-run on your target hardware: pixi run python benchmarks/benchmark_ml_loader.py --device cpu

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.0.tar.gz (459.0 kB view details)

Uploaded Source

Built Distribution

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

torchfits-0.2.0-cp313-cp313-macosx_14_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for torchfits-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3bc7e766d854f988f1e0672ad9aa8a6cde6f10a20fa0da555e6b997b37669153
MD5 9725a629f84d291c11463326b60327ac
BLAKE2b-256 cecf439c96f4c623cc031654fc09e8c54d600e46cd9c92e0f778f24f984d02b5

See more details on using hashes here.

File details

Details for the file torchfits-0.2.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for torchfits-0.2.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fd987a4dc9c1e3d04993fd3e2bfc8c248a6126c0b8a6cfe3810c0c89c3b95415
MD5 6b374810143e5c3e45ec08488e4a20d3
BLAKE2b-256 c3b091c2acf20cca79caecd6527cb6c87728b0e0c9a9bf0cb8854a87ccdffe09

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