Fitting a model with the composition operator sometime like (physical_model | response) where physical model has units has one unit e.g. watts or photons etc and the response model has other units e.g. dn or counts doesn't seem to work as expected and raises an error.
Expected behavior
The unit chain from each model to the next in taken into account rather than only the input and output units from the compound model and the fitter return the correct result.
How to Reproduce
import astropy.units as u
import numpy as np
from astropy.modeling import models, fitting
e = np.linspace(0, 25, 100) * u.keV
phys = models.Linear1D(slope=-4*u.ph/u.keV, intercept=100*u.ph)
phys.output_units = {'y': u.ph}
response = models.Linear1D(slope=1*u.ct/u.ph, intercept=0*u.ct)
response.output_units = {'y': u.ct}
comb = phys | response
fake_data = comb(e)
fit = fitting.LevMarLSQFitter()
res = fit(comb, e, fake_data)
UnitConversionError: 'ph' and 'ct' are not convertible
Description
Fitting a model with the composition operator sometime like
(physical_model | response)
where physical model has units has one unit e.g. watts or photons etc and the response model has other units e.g. dn or counts doesn't seem to work as expected and raises an error.Expected behavior
The unit chain from each model to the next in taken into account rather than only the input and output units from the compound model and the fitter return the correct result.
How to Reproduce
Versions