带边界的多重高斯拟合(astropy)

2024-09-30 16:28:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个多重高斯拟合。这里有两个问题

  1. 我设置g1,g2和g3,然后把它们加起来得到g?在
  2. 如何使用界限来设置振幅、平均值和标准偏差的限值?或者有人知道如何为这三个值设置一个范围吗?在

我的代码是:

from astropy.modeling.models import Gaussian1D
from astropy.modeling import fitting

np.random.seed(0)
x = x_k
y = y_k
y += np.random.normal(0., 0.2, x.shape)
g1 = Gaussian1D(amplitude=8, mean=-3000, stddev=2000)
g1.bounding_box.amplitude = (5, 10) #I am not sure this format is right because I cannot find an example in astropy
g1.bounding_box.mean = (-4000,-1000)
g2 = Gaussian1D(amplitude=10, mean=0, stddev=2500)
g2.bounding_box.amplitude = (5, 10)
g3 = Gaussian1D(amplitude=8, mean=3000, stddev=2000)
g3.bounding_box.amplitude = (5, 10)
fit_g = fitting.LevMarLSQFitter()
g = fit_g(g1+g2+g3, x, y)

结果是:

^{pr2}$

很明显这不管用。怎么了?在


Tags: fromimportboxnpmeanmodelingstddevastropy