Skip to main content
Fitsy

Read and write astronomical FITS files with WCS coordinates.

  • Reads and writes fits files of all image types, and tables (bin and ascii).
  • Query subsets of images without loading the whole thing.
  • Read and write .fz compressed images.
  • Parses all WCS Projections, including spectral (if we are missing one let me know!)
  • SIP, TPV, TNX, and DSS distortion support.
  • Support for fitting WCS as well.
  • Hierarchy/History support.

Available as a Python package, a Rust crate with minimal dependencies, and a command-line tool.

Full documentation: https://dahlend.github.io/fitsy/

I have tried my best to make this fully compliant with modern fits requirements, if something is missing please let me know.

Memory Mapping

The fits standard defines data using big-endian values, all modern computers are little endian. What this means is that when you load data from a fits file, the moment you do anything with it (even plot it) your computer has to flip the endian-ness of the data. This means putting it into memory. As a result of this, memory mapping is pretty much useless in practice.

Because of this, Fitsy has optimized loading subsections of data from images into memory instead of memory mapping, this includes editing in place.

Python

pip install fitsy
import fitsy
import numpy as np

# Read
with fitsy.open("image.fits") as f:
    hdu = f[0]  # ImageHdu
    data = hdu.data  # full array in RAM, native byte order
    tile = hdu.section[0:256, 0:256]  # decode only this slice (large files)
    wcs = hdu.wcs()
    ra, dec = wcs.pixel_to_world([512.0, 512.0])

# Write
img = fitsy.image(np.zeros((512, 512), dtype=np.float32), header={"OBJECT": "test"})
fitsy.write("out.fits", [img])

Build the wheel from source

maturin build --release
# or for local development:
maturin develop

Rust

[dependencies]
fitsy = { version = "0.3", features = ["compression"] }
use fitsy::{FitsFile, Hdu, ImageBuilder, write};

// Read
let file = FitsFile::open("image.fits")?;
let Hdu::Image(img) = file.hdu(0)? else {
    return Err("not an image".into());
};
let data = img.read_physical()?;       // BZERO/BSCALE applied, f64 output
let wcs = file.wcs(0, ' ')?.unwrap();
let world = wcs.pixel_to_world(&[512.0, 512.0])?;

// Write
let pixels = vec![0.0_f32; 512 * 512];
let hdu = ImageBuilder::new(vec![512u64, 512], pixels)?
    .primary(true)
    .card("OBJECT", "test", None)
    .build()?;
write("out.fits", &[hdu], /* overwrite = */ false)?;

Optional features: compression (default), nalgebra, faer, python.

Command line

The crate also installs a fitsy binary:

cargo install fitsy
fitsy info <file>                        # one line per HDU, plus WCS details
fitsy header <file> [--hdu N] [filter]   # dump parsed header cards
fitsy checksum <file>                    # verify CHECKSUM / DATASUM
fitsy stats <file> [--hdu N]             # pixel statistics for image HDUs
fitsy fpack <input> [-o out]             # write a tile-compressed (.fz) copy
fitsy funpack <input> [-o out]           # write a tile-decompressed copy

License

Apache 2.0 or MIT, at your option.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

fitsy-0.4.0-cp310-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

fitsy-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

fitsy-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

fitsy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

fitsy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file fitsy-0.4.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: fitsy-0.4.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fitsy-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7dd3feb3f70b1f30b73124a22a4d0dff8135872329dc1f9302addb884a7ee2a1
MD5 59adb305520672dabe86e3b83ba72837
BLAKE2b-256 e60b562ccc8eea8de493117cc1354e678adcb6a0cb705f8c24c460c01cb32fcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.4.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on dahlend/fitsy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fitsy-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fitsy-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c9b9cb49b7cfc62016ddce12e6e793d39e6ddccc83a3e1881729a9d8384056e0
MD5 df968c263cf84efe4953c392d473347d
BLAKE2b-256 2b6f3ab5b44f0a7ea439a0e19609e8eea342229006fe100f187d2cfe8dadc274

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on dahlend/fitsy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fitsy-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fitsy-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c4c463bfe0dd6ecbe03771eae9c7767eda8fad4bb8331dec44ae750c95395d7f
MD5 07c15aa8d87602e5208282cfb5509051
BLAKE2b-256 681a56114d4ea350709a459a29140d80a5abb558106bf6c5e92bad48c71d1cba

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on dahlend/fitsy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fitsy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fitsy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c808879ec59622cdae2924c06fe49f0926ab8299f120b8190bf2d6f4fe28ebb5
MD5 9b12acc14234e4bd89225e3445b96bba
BLAKE2b-256 ae1df76ce104ced514480d5f1089f1da80461dd15277864cdeda6708962c166b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on dahlend/fitsy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fitsy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for fitsy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5d0dedae96787102a0af88911f34df806beeb222c3b9f726b97bf55ca8c7d930
MD5 5a7f487ab9c65d9704b046b5899b5773
BLAKE2b-256 b5b1fad6de5ca71201b98addcc6b4da776d87e1ce814d034c7bd02ca2fdea928

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on dahlend/fitsy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.0

5 files

This release

0.4.0 This release

5 files

0.3.0

5 files

0.2.0

5 files

0.1.4

5 files

0.1.3

5 files

0.1.2

5 files

0.1.1

5 files

0.1.0

5 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page