[AstroPy] Astropy model fitting
Axel Donath
axel.donath at mpi-hd.mpg.de
Wed Apr 5 03:41:17 EDT 2017
Hi Ravi and Zé,
I remember that I've worked on this during the preparation for mentoring
a GSoC
project 2015. Indeed it would not be that much work to include
convolution as an
operation for compound models. Unfortunately I didn't find time to work
on this
anymore. Here's a little gist with the proof of concept:
https://gist.github.com/adonath/4f6aef5f125b2cca4ae5edbd978ffc0b
I was suprised to see that it still works. Maybe someone is motivated to
turn this
into a little PR for astropy core? The remaining task would be to
integrate this
into the exiting modeling API, e.g. by introducing a helper function
`convolve_models`,
'overloading' the existing `convolve_fft` method or introducing a new
symbol
operator. I'd be happy to review the PR, but I don't have time to work
on this myself.
Cheers, Axel
Am 2017-04-02 10:13, schrieb Zé Vinícius:
> 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
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
More information about the AstroPy
mailing list