read_spectrum

msaexp.spectrum.read_spectrum(inp, spectrum_extension='SPEC1D', sys_err=0.02, err_mask=(5, 0.5), err_median_filter=[11, 0.2], **kwargs)[source]

Read a spectrum and apply flux and/or uncertainty scaling

Flux scaling corr is applied if there are POLY[i] keywords in the spectrum metadata, with

>>> coeffs = [header[f'POLY{i}'] for i in range(order+1)]
>>> corr = np.polyval(coeffs, np.log(spec['wave']*1.e4))
Parameters
inpstr or HDUList

Fits filename of a file that includes a BinTableHDU table of an extracted spectrum. Alternatively, can be an HDUList itself

spectrum_extensionstr

Extension name of 1D spectrum in file or HDUList input

sys_errfloat

Systematic uncertainty added in quadrature with err array

err_maskfloat, float or None

Mask pixels where err < np.percentile(err[err > 0], err_mask[0])*err_mask[1]

err_median_filterint, float or None

Mask pixels where err < nd.median_filter(err, err_median_filter[0])*err_median_filter[1]

Returns
specTable

Spectrum table. Existing columns in file should be

  • wave : observed-frame wavelength, microns

  • flux : flux density, microJansky

  • err : Uncertainty on `flux`

Columns calculated here are

  • corr : flux scaling

  • escale : extra scaling of uncertainties

  • full_err : Full uncertainty including sys_err

  • R : spectral resolution

  • valid : Data are valid