I have the following model functions. Classic gaussian:
def gauss_model(x, mu, sigma):
return np.exp(-0.5*((x-mu)/sigma)**2)
And a gauss-hermite parametrization, taking account for skewness (parameter h3) and kurtosis (parameter h4) of the distribution:
def losvd_param(v, v_rot, v_disp, h3, h4):
y = np.asarray((np.asarray(v)-v_rot)/(v_disp))
return (np.exp(-0.5 * y**2) * (1 + h3*((2*np.sqrt(2)*y**3-3*np.sqrt(2)*y)/np.sqrt(6)) + h4*((4*y**4-12*y**2+3)/np.sqrt(24))))
Fitting and plotting:
p0_1=[1300,250]
boundslow_1=[1000, 100]
boundsup_1 = [1400, 300]
p0_2 = [1300, 250, 0, 0]
boundslow_2 = [1000, 100, -0.1, -0.1]
boundsup_2 = [1400, 300, 0.1, 0.1]
gh_moments = curve_fit(gauss_model, vel_corr_peak, broadening_func/max(broadening_func),p0=p0_1, bounds=((boundslow_1),(boundsup_1)))[0]
gh_moments_2 = curve_fit(losvd_param, vel_corr_peak, broadening_func/max(broadening_func), p0=p0_2,bounds=((boundslow_2),(boundsup_2)))[0]
plt.plot(vel_corr_peak, broadening_func/max(broadening_func),linewidth='2', label='data', color='black')
plt.plot(vel_corr_peak, gauss_model(vel_corr_peak, *gh_moments)/max(gauss_model(vel_corr_peak, *gh_moments)),'--',color='red', label='gauss fit')
plt.plot(vel_corr_peak, losvd_param(vel_corr_peak, *gh_moments_2)/max(losvd_param(vel_corr_peak, *gh_moments_2)),':', color='green', label='gauss hermite fit')
One can see that the gauss-hermite-fit is a bit closer to the actual data but dont match perfectly.
If somebody wants to try the data: x-values:
[449.99918644287044, 479.9991322057285, 509.9990779685865, 539.9990237314445, 569.9989694943025, 599.9989152571605, 629.9988610200186, 659.9988067828766, 689.9987525457346, 719.9986983085927, 749.9986440714507, 779.9985898343087, 809.9985355971668, 839.9984813600248, 869.9984271228828, 899.9983728857409, 929.9983186485989, 959.998264411457, 989.998210174315, 1019.998155937173, 1049.998101700031, 1079.998047462889, 1109.997993225747, 1139.997938988605, 1169.997884751463, 1199.997830514321, 1229.9977762771791, 1259.9977220400372, 1289.9976678028952, 1319.9976135657532, 1349.9975593286113, 1379.9975050914693, 1409.9974508543273, 1439.9973966171854, 1469.9973423800434, 1499.9972881429014, 1529.9972339057595, 1559.9971796686175, 1589.9971254314755, 1619.9970711943336, 1649.9970169571916, 1679.9969627200496, 1709.9969084829077, 1739.9968542457657, 1769.9968000086237, 1799.9967457714818, 1829.9966915343398, 1859.9966372971978, 1889.9965830600559, 1919.996528822914, 1949.996474585772, 1979.99642034863, 2009.996366111488, 2039.996311874346, 2069.996257637204, 2099.996203400062, 2129.99614916292, 2159.996094925778, 2189.996040688636, 2219.995986451494, 2249.9959322143523]
y-values:
[ 0.48158957 0.51413024 0.57190115 0.65708852 0.77221168 0.91982261 1.10264097 1.323603 1.58568143 1.89166066 2.24396947 2.644586 3.09482201 3.59482773 4.14336694 4.73762031 5.3729276 6.04262429 6.73776387 7.44733358 8.15834164 8.85608227 9.52454256 10.14681488 10.7061444 11.18626665 11.5724327 11.85204538 12.0153712 12.05641108 11.97274977 11.76629065 11.44282113 11.01225276 10.48774599 9.88509761 9.22202859 8.51728797 7.7897047 7.05722644 6.33620579 5.64081325 4.98267552 4.37045974 3.8098805 3.30392459 2.85318343 2.45615909 2.10979453 1.80999646 1.55202573 1.33111531 1.14267783 0.98268788 0.84772486 0.73512314 0.64325468 0.57105697 0.51828786 0.48509208 0.47235733]