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.
  • Reads .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 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.3.0-cp310-abi3-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

fitsy-0.3.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.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

fitsy-0.3.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.3.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: fitsy-0.3.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.0 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.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 366dd38f34834f2c8f05003f90e0b094d78be1ee172a885010269db73fdc89d5
MD5 a497aeb4d425710bf832437a5d3eb09a
BLAKE2b-256 12bef4288ec364caea9456de5ab8a5b0df516eeb8856980d0b75b7b80b7812cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.3.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.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fitsy-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7154ce4f3ba796eba5a168d5547f8b3dedd8411c97fc1522e1209e93b05959a
MD5 32f99db9376e9a8804e345d552d7c24b
BLAKE2b-256 f1f1de0916d1fb07691bd89a41040e38e596805dec796ceb0b610de11937393b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.3.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.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fitsy-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8e3d92ef97b28bf51ca6203140f16380e090634b8cd59fc28074795129faf23a
MD5 ec5dec827256520f26a7fe0ab40cfc05
BLAKE2b-256 daa614f36af85964a426ad7bee5c9ff4385b1b0e71ad9ebb1b107e0248b73596

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.3.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.3.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fitsy-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a0b627cd96f65ae83d2bdc17bfa91f8924d286527defa2ea4da2a454ba20d71
MD5 4d88cb3a4c8ab96595c58c2826a45e0c
BLAKE2b-256 13238f4afaef0a89014e3fa846130ffe1b0dbe47218d7c37fba7e2c13f711af2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.3.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.3.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for fitsy-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4033634b75e0330bfb47dfc250adb26f5be63bdeaee95971f7cdcddd2ca3d623
MD5 8045c3ad8888e966b259cf679f5995ec
BLAKE2b-256 e37fbc39b45a1642be80046d02da710c8d6d1e36e1eee89f3c5de7b7d4a9be1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitsy-0.3.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

0.4.0

5 files

This release

0.3.0 This release

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