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=
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¶
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).
Related algorithms¶
read_ascii_spectrum- Read a 1D spectrum from a two- or three-column text file.read_echelle_fits- Read a multi-order échelle FITS file intoctx.spectra.read_sdss_spectrum- Read an SDSS-format spectrum (spec-*.fits) intoctx.spectrum.read_votable_spectrum- Read a 1D spectrum from a VOTable file (the IVOA Virtual Observatory format).