Skip to content

read_fits

Read a 1D spectrum from a FITS file (local path or http(s) URL).

Category Input / output
Backend astropy - wraps the domain-standard astropy implementation
Version 3.0.0
Reads -
Writes spectrum

Linear WCS: λ = CRVAL1 + (p − CRPIX1)·step with 1-based CRPIX1 and step = CD1_1 when present, else CDELT1 (× PC1_1). Logarithmic axes: IRAF DC-FLAG = 1 means CRVAL1/CDELT1 are log10(λ) (axis = 10(…)); a CTYPE1 ending in '-LOG' (WAVE-LOG, AWAV-LOG) is a WCS Paper III logarithmic axis, λ = CRVAL1·exp((p − CRPIX1)·step / CRVAL1). CUNIT1 (or IRAF WAT1 'units=') in nm / µm / m is converted to Å and the original label kept in meta['wavelength_unit_original']. v3.0.0 (contract change, cf. audit C6/C7): (1) CD1_1 now wins over CDELT1 when both exist (v2 preferred CDELT1; a file with CDELT1=1, CD1_1=2 read step 1, now 2, matching astropy.wcs); (2) a header with no CRVAL1/CDELT1/CD1_1 gives the 0-based pixel index with wavelength_unit='pixel' and meta['wcs']='none' (v2 labelled the same numbers 'Angstrom'); (3) a genuine 2-D image is refused unless row= is passed (v2 silently returned row 0); length-1 axes are still squeezed; IRAF multispec/échelle markers redirect to read_echelle_fits; (4) a data-bearing PRIMARY now wins over table extensions (v2 preferred any table); hdu= overrides; (5) ERROR/ERR/ERRS/SIGMA/UNCERT/UNCERTAINTY (1σ) and IVAR (1/√ivar) image extensions and err/error/ivar/sigma/uncertainty/flux_error table columns fill Spectrum1D.uncertainty; MASK extensions and mask/and_mask columns fill Spectrum1D.mask; SDSS loglam columns are decoded as 10loglam; (6) a descending axis is kept as stored and flagged meta['wavelength_descending']=True; (7) an unrecognised CUNIT1 (e.g. 'km/s') is kept verbatim as wavelength_unit instead of being relabelled 'Angstrom'. meta['source'], meta['hdu'], meta['hdu_name'], meta['layout'] and meta['wcs'] document the provenance; the selected HDU's header is kept in Spectrum1D.header. The '-LOG' decoding (v2.0.0) and the IRAF DC-FLAG branch are unchanged.

Parameters

Parameter Default Required Description
path None yes Local path or http(s) URL of the FITS file to read.
hdu None - Extension to read: null = automatic (data-bearing PRIMARY, else the first table with wavelength/flux columns, else the first image extension); an integer index or an EXTNAME string forces one.
row None - 0-based row to read when the data is a 2-D image (or a multi-row table of array cells). null squeezes length-1 axes only and fails on a genuine 2-D image instead of guessing.

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("read_fits", ctx, {
    "path": "<value>",
    "hdu": None,
    "row": None
})
spectro run read_fits --input spectrum.fits \
  --param path=<value> \
  --param hdu=none \
  --param row=none
{
  "tool": "read_fits",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "path": "<value>",
      "hdu": null,
      "row": null
    }
  }
}

Every algorithm is an MCP tool of the same name; describe_algorithm returns this page's metadata as JSON.

References

  • FITS Standard 4.0 — Pence et al. 2010, A&A 524, A42
  • astropy.io.fits — Astropy Collaboration 2022, ApJ 935, 167
  • Greisen & Calabretta 2002, A&A 395, 1061 — WCS Paper I (CDi_j takes precedence over CDELTi / PCi_j; CRPIXi is 1-based).
  • Greisen, Calabretta, Valdes & Allen 2006, A&A 446, 747 — WCS Paper III (spectral coordinates; '-LOG' axes).