[AstroPy] Astropy model fitting
Zé Vinícius
jvmirca at gmail.com
Sun Apr 2 04:13:43 EDT 2017
Hi Ravi,
As you mentioned, I also think this cannot be done with astropy compound models.
It would be really awesome if we could get compound models out of more complex operations (e.g. convolution).
However, I think you can do that with numpy and scipy, with something like that (?):
import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import curve_fit
def gaussian_convolved_with_ramp(x, alpha, beta):
ramp = alpha * x
gauss = np.exp(-0.5 * (x - beta) ** 2.)
return np.convolve(ramp, gauss)
if __name__ == "__main__":
xp = np.linspace(-7, 7, 100)
g = gaussian_convolved(xp, 1, 0)
toy_data = g + 10 * np.random.standard_normal(len(g))
g_est, g_est_cov = curve_fit(gaussian_convolved_with_ramp, xp, toy_data)
print(g_est)
print(g_est_cov)
x = np.linspace(-7, 7, len(g))
plt.plot(x, toy_data, x, gaussian_convolved_with_ramp(xp, *g_est))
plt.show()
Cheers,
Zé
> On Apr 1, 2017, at 11:53 PM, banyal <banyal at iiap.res.in> wrote:
>
>
>
> -------- Original Message --------
> Subject: Astropy model fitting
> Date: 2017-04-02 12:19
> From: banyal <banyal at iiap.res.in>
> To: Astronomical Python mailing list <astropy at scipy.org>
>
> Hi,
> I have a very general question related to model fitting in Astropy. I want to use astropy.modeling to fit observational data to a compound model of type f*g, where * is a convolution operator, f is high resolution stellar spectra (template) and g is instrument response (a gaussian form, with amplitude, mean and stddev as fitting parameters). The objective is to use nonlinear LSF to extract the fitting parameters of a gaussian function which best describe the instrument response. Essentially, the model has an integral form (f*g) that must fit the data in least square sense. After going through the astropy.modeling documentation, it seems the construction of a compound model in astropy is so far limited to combining individual models with elementary arithmetic operations (convolution not included). Is there a way around this?? Or to put it another way, can I define a custom function of (f*g) and still use Astropy.modeling to do the least square fitting?? Many thanks will appreciate any thought on this.
>
> With best wishes
> Ravi
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170402/a95ff44f/attachment.html>
More information about the AstroPy
mailing list