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

Uploaded CPython 3.10+Windows x86-64

fitsy-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (938.1 kB view details)

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

fitsy-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (894.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

fitsy-0.1.4-cp310-abi3-macosx_11_0_arm64.whl (873.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

fitsy-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl (916.5 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: fitsy-0.1.4-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 877.9 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.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7afb1c77d7f8e244dbfe8c1ac8e4be885c99e5728cb6abc089653cb1060c20b1
MD5 9783bbdadcd62c6ef91bae63108b10ac
BLAKE2b-256 d72d4a2001ac20a2908c28d4502ffbd806025177314f0264de29481b98be290b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fitsy-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4aefd7e86f9bb104bef5f8a9b3e4a4c0b6a1a3881c2dee8edfc50cf76883562c
MD5 93c0b67c89f13b3fb77276af6682b1d7
BLAKE2b-256 6cd4052070b8710afd21312fb07b4c9bfdc6be913ed6cf50538a7634a4077ee3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fitsy-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 16bcc79568cb4dbcd53b1c3021324c940938f205878e727a9f11778fa206eab9
MD5 f9cb5b8df8d463e1b2f925ee7d0349c8
BLAKE2b-256 c8684d83045624211fce8dfccb3ca8154e169d5ef2ad5eb2788a11d842b68aeb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: fitsy-0.1.4-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 873.0 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.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1697979f340a41405105d5fc61932f0ddd19299b34913fb291e537f80891ea3
MD5 411dfcf59c33e537ed4a8dcbb897f56e
BLAKE2b-256 4858050b42e0c62952eaa143947dd639509450799015a23c9893cefec6f0f322

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fitsy-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5397779193ab4fff7673a8b660a5a43b3f140f3e5336c7904c310cfa7de2c061
MD5 de85b2d34562ba67aada905962b6f166
BLAKE2b-256 972dfb5154966022572d52cf224ac4146dc0c6403b5a4c35fabc892704076bc3

See more details on using hashes here.

Provenance

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