Side-by-side replacements for common FITS I/O tasks. torchfits covers
tensor/dataframe FITS I/O — see Parity for the full matrix. For
runnable workflows, start with Examples.
Medians from Round-3 scorecard (exhaustive_mps_20260719_143706); see
Benchmarks host scorecard. Absolute highlight times refresh
with each soak — prefer docs/benchmarks.md#performance-highlights when
numbers disagree. Narrow-table predicate_filter and MegaCam
torchfits_cached still lag fitsio on some hosts.
Astropy: Scaling (applying BSCALE and BZERO keywords) is applied on the CPU when the HDU data is initialized. Integer types (like uint16 or int32) are promoted to double-precision float64 in memory if the scaling yields floating-point numbers.
torchfits: Optional on-device scaling via torchfits.read(..., scale_on_device=True) (via **kwargs into the read pipeline). Raw integers transfer to GPU/MPS; BSCALE/BZERO apply in device registers, yielding float32 instead of Astropy's default float64. read_tensor has no scale_on_device parameter — use read() or pass raw_scale=True on read_tensor for storage dtypes.
Astropy: Tables are represented as astropy.table.Table or numpy.recarray.
torchfits: FITS tables are dataframes on disk. Default path is
torchfits.table.read → pyarrow.Table (portable dataframe). Tensor columns
use table.read_torch. Native Polars uses
table.read_polars. VLAs become Arrow list columns.
Astropy: HDU handles (HDUList) are not thread-safe. Opening the same file in multiple background threads can lead to file descriptor and read-pointer conflicts.
torchfits: Since 1.0.0rc2, concurrent reads open a private CFITSIO fitsfile* per call (CFITSIO R2). Shared metadata (SharedReadMeta) and the raw fd use pread and stay mutex-guarded; they do not share CHDU state across threads. For PyTorch DataLoader workers, use torchfits.data datasets with make_loader: map-style datasets read independently per worker; iterable datasets shard by worker_id. Pre-warm handle sizing with torchfits.cache.optimize_for_dataset(paths) when the dataset exposes a files list.