These are chat archives for astropy/astropy

7th
Mar 2017
Thomas Spriggs
@tspriggs
Mar 07 2017 18:30
Hey astropy, I am currently trying to combine two 1D Gaussians via the models.Gaussian1D method: gg = g1 + g2 etc. I know you can tie parameters together for the initial vales entered into each of the gaussians (g1 and g2), but is there a way to force the fitted values to be tied to each other? example being tie fitted_amplitude_1 to be 1/3 * fitted_amplitude_0? I am working with spectral data that needs 2 peaks fitted and are at a set distance apart, which is another constraint I would like to keep the same, hope there is a way to do this, if not then not to worry. thanks in advance though for an awesome python package
matrixbot
@matrixbot
Mar 07 2017 18:40
Cadair i think you will have to define a custom model for that one. It will be hard to add a constraint to the fitter I think. (I am not an expert on modelling though).
Cadair I guess one way to do it would be to define a custom model where you reduce the number of fitting parameters by one by making one a function of another one
Thomas Spriggs
@tspriggs
Mar 07 2017 18:49
Thanks for the reply, yea I think either a custom model would work or manually adjusting the values after the fit, both would work
matrixbot
@matrixbot
Mar 07 2017 18:52
Cadair I think what you want to do is have an evaluate function that ties two of the parameters together and then calls the old evaluate method
Cadair on your new model subclass
Cadair then the fitter should just work
Cadair but for the sake of the fitter I think you will want to define your model to have one less parameter or else it will be trying to optimise a parameter that has no impact on the result
Thomas Spriggs
@tspriggs
Mar 07 2017 19:02
thanks for the help, I will give this a go and see where it gets me
Thomas Spriggs
@tspriggs
Mar 07 2017 20:03
found a simpler path: compound the model after fitting g1's data via the LevMarLSQFitter, and then adding it to the second gaussian with constrained variables
matrixbot
@matrixbot
Mar 07 2017 21:22
Cadair Nice! That's rather easier.