Skip to main content

Strictly-conformant FITS 4.0 reader and writer.

Project description

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 and a Rust crate with minimal dependencies.

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_celestial(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 --features python

Rust

[dependencies]
fitsy = { version = "0.1.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 (ra, dec) = wcs.pixel_to_celestial(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.

License

Apache 2.0 or MIT, at your option.

Project details


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.1.3-cp310-abi3-win_amd64.whl (886.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

fitsy-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (945.2 kB view details)

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

fitsy-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (899.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

fitsy-0.1.3-cp310-abi3-macosx_11_0_arm64.whl (880.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

fitsy-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl (921.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: fitsy-0.1.3-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 886.0 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fitsy-0.1.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f3f0ec96e4e1f6ae9b4c96d3faf02c22c6c7c64a86f8aaba0db44fb403bb732f
MD5 2ba6cec2c135834e8b92c0be30ba3969
BLAKE2b-256 4886fa59a09b3771f00afcba3098399982a09c510ad76d6fffff09d2116ad0c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fitsy-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ed52de3b857a60ddc45b6204c404bccc209e578251fa4fa06736600d1872dce
MD5 272fea3707a4296a200817702c642565
BLAKE2b-256 25e8b75856c2ff62c9238a8b3df64d443d0bca24b52a50c01831739be3700ddd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fitsy-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ebd27d6b3d14ce442575e92e0bced259003d19f4a6c6c1311d0a6d1b06e2e2d9
MD5 60185de91412433784213430f5d87018
BLAKE2b-256 a7a80b1763e75ef25c5beb905f8222a42cf7fdd0965e7436618e3aa8a189c5bb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: fitsy-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 880.3 kB
  • 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

Hashes for fitsy-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 462ea4f789414619681f28c47662aa4f81aadc1a482d53983a6b849efb9517cc
MD5 1880f3626ec14d591e9c3b89929a37e9
BLAKE2b-256 e583cadd8946e57182b1b9e23d29f0bddcfe0022d0d26aee897ef0f211a3553d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fitsy-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6a450b41e371651e159d159898f43851dd76ae6db5d21acb311c533c695cffae
MD5 c65094fbe703d0b7aebecb07fe553f08
BLAKE2b-256 5d713d6dd7725d18a72cccf94c3379629ab83092759ac6329b8634e0b3812d36

See more details on using hashes here.

Provenance

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

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