QuickstartΒΆ

Every code sample below is a runnable script in the examples/ directory at the repo root. The image used throughout the guide is a 1948 photographic-plate scan of NGC 2403 (1448 x 2172 pixels, TAN+SIP WCS), bundled at examples/data/ngc2403.fits.gz.

Run any example with:

python examples/python/quickstart.py     # Python
cargo run --example wcs                  # Rust
"""Quickstart: open a FITS file, read pixels, headers, and WCS.

Run from the repo root:

    python examples/python/quickstart.py
"""

import fitsy

with fitsy.open("examples/data/ngc2403.fits.gz") as f:
    hdu = f[0]
    print(hdu.bitpix, hdu.axes)  # 16  [1448, 2172]
    data = hdu.data  # numpy.ndarray, shape (2172, 1448)
    print("data shape:", data.shape, "dtype:", data.dtype)

    wcs = hdu.wcs()  # Wcs (TAN + SIP)
    if wcs is not None:
        ra, dec = wcs.pixel_to_celestial(724.0, 1086.0)
        print(f"center: RA={ra:.4f}  Dec={dec:.4f}")

Writing files and reading tables are covered in their own sections; see Writing FITS files and Reading images.