Reading Spectra

NIRDust provides easy and quick functionalities to read your spectra. If you have your data in FITS format or just a common text ASCII file, you can use one of the following functions. If you don’t have your data in any of these formats, by the end of this tutorial you can see how to load your data to create a NirdustSpectrum object directly.

Reading from a FITS file

Let’s say you have your spectra in a FITS file. This format, in most cases, comes with a header and a science extension. The science extension stores the flux intesity of the spectrum and the respective pixel axis. The header has the information to transform the pixel axis into a spectral axis. The manual input of the redshift of the galaxy, which isn’t included in most headers, is necesary to get the spectral axis in rest frame. The following code shows the easiest way to read a spectrum:

[2]:
import nirdust as nd

nuclear_spectrum = nd.read_fits("nuclear_spectrum.fits", z=0.00183)

# Show some information
nuclear_spectrum
[2]:
NirdustSpectrum(z=0.00183, spectral_length=1751, spectral_range=[18889.58-25106.71] Angstrom)

If your FITS file has multiple extensions, the automatic detection of the science extension may fail. In such cases, you can manually indicate the correct extension by passing the parameter extension=1 to the function (if 1 is the correct number).

Reading from an ASCII file

The function read_table can be used to read directly from a text file and supports multiple formats. In this case the file should contain these two columns: wavelength [A] and flux [arbitrary units]. If you have multiple columns you should indicate which columns correspond to the spectrum data. For a list of supported formats see this link.

[ ]:
spectrum = nd.read_table("file_name.csv", wavelength_column=2, flux_column=4, format="csv")
[ ]: