Specutils: Combining Voigt1D + Exponential1D in fitting gives strange behavior with units
Description
I combine a Voigt and Exponential Profile to model absorption spectra. And when I do the model works as expected, giving proper units. But after I run
Expected behavior
After fitting, the fitted model should just give the same model but with fitted and changed parameters but it doesn't.
Actual behavior
"Exponential1D: Units of input 'x', (dimensionless), could not be converted to required input units of Angstrom (length)"
Steps to Reproduce
import astropy.units as u
from astropy.modeling import models, fitting
from specutils.spectra import Spectrum1D
from specutils.fitting import fit_lines
import numpy as np
v = models.Voigt1D(amplitude_L=2., x_0=100 * u.Angstrom, fwhm_L=1*u.Angstrom, fwhm_G=1*u.Angstrom)
e = models.Exponential1D(amplitude=1., tau=-1., fixed={'tau': True, 'amplitude': True})
ve = v | e
x = np.linspace(95,105,1000) * u.Angstrom
y_model = ve(x)
y_data = ve(x) + np.random.normal(0, 0.2, size=x.shape)
spec_data = Spectrum1D(flux=y_data, spectral_axis=x)
ve_fitted = fit_lines(spec_data, ve)
ve_fitted(x)
System Details
Linux-4.18.0-372.26.1.el8_6.x86_64-x86_64-with-redhat-8.6-Ootpa Python 3.7.13 (default, Mar 29 2022, 02:18:16) [GCC 7.5.0] Numpy 1.21.5 pyerfa 2.0.0 astropy 4.3.1 Scipy 1.7.3 Matplotlib 3.5.2 Specutils 1.8.1
Welcome to Astropy 👋 and thank you for your first issue!
A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.
GitHub issues in the Astropy repository are used to track bug reports and feature requests; If your issue poses a question about how to use Astropy, please instead raise your question in the Astropy Discourse user forum and close this issue.
If you feel that this issue has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].
I am moving this to specutils and see if this is a downstream issue first. Thanks!
If think that the proper way of creating a compound model would be to use + instead of |, i.e.:
ve = v + e,
since | stands for a bitwise OR. The exponential model should be updated respectively by adding a unit to tau:
e = models.Exponential1D(amplitude=1., tau=-1. * u.Angstrom, fixed={'tau': True, 'amplitude': True})
After these updates, ve_fitted(x) works as expected.