Make it easier to deal with line flux for "mixed" (f_nu+lambda or f_lambda+nu) spectra
- Dominant language
- Python
- Stars
- 204
- Forks
- 134
- Avg merge
- 12h 55m
- Merged PRs (30d)
- 1
Description
This issue was pointed out initially by @lib-j, and I'm posting some more details it here after investigating the matter a bit.
The core problem is this: when doing a line flux measurement on a spectrum that has "mixed" spectral x and y axis units (I.e. the flux is f_nu while the spectral axis is wavelength, or the flux is f_lambda when the spectral axis is frequency/energy), it's hard to get anything that's in more conventional units. A more concrete example is:
```
>>> from astropy import units as u
>>> import specutils
>>> from specutils.analysis import line_flux
>>> spec = specutils.Spectrum1D(spectral_axis=[1,2,3]*u.micron, flux=[3,4,5]*u.Jy)
>>> lflx = line_flux(spec, specutils.SpectralRegion(1*u.micron, 3*u.micron))
>>> lflx
>>> lflx.to(u.erg/u.s * u.cm**-2, u.spectral_density(spec.spectral_axis))
UnitConversionError: 'Jy micron' (force) and 'erg / (cm2 s)' are not convertible
```
whereas @lib-j rightly wanted some way for that to easily work. One can hack it by doing something like:
```
>>> (lflx/u.micron).to(u.erg/u.s * u.cm**-2 / u.micron, u.spectral_density(spec.spectral_axis))*u.micron
```
but that's exceedingly un-intuitive.
So there's two possible fixes (which are not mutually exclusive...)
1. Add an equivalency for spectral flux which addresses these unit combinations - could go in `specutils` or in `astropy`
2. Have `line_flux` have an `output_unit` keyword which recognizes the case above and automatically does the transformation. This could even internally *use* my 1 just above here, so we could do both.
(I could swear I already made this issue, but can't find it now. Apologies if it turns out there's a duplicate here!)
Contributor guide
Research direction
Start with specutils.analysis.line_flux and reproduce the Spectrum1D/SpectralRegion example using mixed spectral and flux units. Investigate the existing unit-conversion behavior, then determine how an equivalency or line_flux output_unit should make the requested conventional line-flux conversion work; done means the example converts without the manual workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100