specutils icon indicating copy to clipboard operation
specutils copied to clipboard

Specutils needs to document how to create a Spectrum1D using flambda units

Open janerigby opened this issue 3 years ago • 2 comments

It would be very helpful if the specutils documentation would show how to create a Spectrum1D using flambda (specific intensity, for example erg/s/cm^2/Angstrom) as the flux unit. The only examples in the documentation at present are for fnu (flux density, for example, Jy).

Both fnu and flambda are used widely in astronomy. Confusing fnu for flambda is one of the most common errors in astronomy, which could be prevented by better documentation. And since there is no shortcut unit when working with flambda, it's not at all obvious how to input an flambda spectrum into Spectrum1D. This creates a big barrier to entry for new users.

janerigby avatar Jul 23 '21 13:07 janerigby

I think I was able to kludge this functionality. It is ugly. cols = ('restwave', 'flam', 'flam_u') sp = pandas.read_csv(spectrumfile, delim_whitespace=True, comment='#', names=cols) flam_unit = u.erg / u.s / u.cm / u.cm / u.Angstrom spec_1D= specutils.Spectrum1D(spectral_axis = sp['restwave'].values * u.AA, flux=(sp['flam'].values * flam_unit)) print(spec_1D)

janerigby avatar Jul 23 '21 14:07 janerigby

I am not sure why you need a kludge here. The basic instantiation is exactly the same, and F_lambda units are even used in the first example in the Getting started section of the docs https://specutils.readthedocs.io/en/stable/ which, in a one-liner, is equivalent to spec = Spectrum1D(spectral_axis=wavelength_arr * u.AA, flux=flux_arr * u.Unit('erg cm-2 s-1 AA-1')) i.e. always following the scheme input_data * flux_unit, which is really no different whether you use u.Unit('erg / (cm2 s AA)'), u.Unit('W m-2 nm-1') or u.Jy.

[the example is a bit pedestrian as you could directly read that spectrum with spec = Spectrum1D.read('https://data.sdss.org/sas/dr16/sdss/spectro/redux/26/spectra/1323/spec-1323-52797-0012.fits') using the default loader, but it probably serves just as well for illustrating the individual components.] EDIT: directly using the loader is not that straightforward either, since for the measurements further down in the example to work, one needs to clear the spec.mask.

dhomeier avatar Jul 23 '21 19:07 dhomeier