New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fitting different datasets simultaneously, using models with parameters tied across models #8814
Comments
Here is an example with 1D datasets: I'm fitting lines in a time series of spectra. I know that the position of the lines does not change (because they are formed several au form the star in the outer disk where changes of the disk structure take long), however, the flux might change much faster as the irradiation from the star changes. So, I want to fit several spectra at the same time, for simplicity, let's assume that I use a Gaussian as the model. The positions of all Gaussians is the same, but the values is unknown a priory (it's a free parameter of the fit), the fluxes are all different. |
Last, a model where |
I just discovered https://docs.astropy.org/en/latest/api/astropy.modeling.fitting.JointFitter.html#astropy.modeling.fitting.JointFitter |
I think something along the lines of |
The JointFitter does work and likely can do some of the fitting described. Just submitted a PR to provide docs and an email. See #12720. |
tl;dr -- Does #12720 completely resolve this issue? |
Not fully. Tying parameters between models using a python function is not supported by JointFitter at this time. |
Given two models called
a
with parametersa1, a2
andb
with parametersb1, b2
, I want to do a joint fit, ofa
evaluated ondata1
(in my example that data is a two-dimensional image) andb
evaluated ondata2
(in my example a different image which happens to have the same dimensionality, but in the general case, that could be different), such that parametersa1
andb1
are tied through some arbitrary python function (in my example: the identity function,a1 = b1
).I'll describe my specific use case in mode detail. In this case, I deal with PSF fitting, but note that this is outside of the scope of current
photutils
and the modeling problem is more general. I can give examples for fitting spectra or SEDs, too, I just happened to come upon this problem by working with images right now, that's why I describe this example here: I have two images. They show the same object on the same WCS, but that object has different fluxes (duh, it's in different bands). Unfortunately, there are a lot of unususable pixles in both images (saturated from a near-by object). Thus, I'd like to fit a psf (let's call the modelspsf1
andpsf2
) to both images at the same time and require that x, y are the same, but the flux is different. So, I have two models, evaluated on two different datasets (psf_621_copy
on image1 with parameters x, y, amplitude_1 andpsf_845_copy
evaluated on image2 with parameters x, y, flux2). I want to minimize the combined fit statistic. Is there a reasonable way to make that happen with astropy now or do I have to wait for #8769?Maybe something like
psf1 | psf2
evaluated on data that is a list with two elements (image 1 and amplitude2). But then, how do I couple x and y?Seems that a problem like this is not unique to me, but I don't find a way to express it well in the current astropy modelling paradigm.
I'm not asking for help with a specific problem, I'm describing the use case here for a feature request. If that's already possible in the current version, an example in the docs might be enough.
For reference, I'll paste below how I address this problem with a custom model, but I feel that there should be (and maybe is already?) a way to make that work by using operations on models as opposed to coding up a user model:
The text was updated successfully, but these errors were encountered: