Exemplo n.º 1
0
    p_1_clg_Norm[i*3:(i+1)*3] = clf.weights_[i], clf.means_[i], sqrt(clf.covars_[i])

p_1_clg                                                 = Rescale_GaussianParameters(p_1_clg_Norm, A_Values, mu_Values, Number_Gaussians)
Wave_Gaussian_clg, Flux_Gaussian_clg, zerolev_Gaussian_clg  = ResampleGaussian(p_1_clg, Wave[Ind_left:Ind_right], Continuum[Ind_left:Ind_right])

#---------Kmpfit method no normalized----------

#Guessing components
ncomps = 0
Q = 1
cutamp = 0.01 * max(y) 
cutsig = 2.0
print 'puttinig in'
print x, y, continuum_error_norm, cutamp, cutsig, Number_Gaussians
while ncomps != 2 and Q < 8:
    comps = gauest(x, y, continuum_error_norm, cutamp, cutsig, q=Q, ncomp=Number_Gaussians)
    ncomps = len(comps)
    Q += 1

print 'the comps are', comps

p_0_kmpfit_Norm = []
for c in p_0:
    p_0_kmpfit_Norm.append(round(c, 3))


fitobj = kmpfit.Fitter(residuals=my_residuals, data=(x, y, continuum_error_norm, Number_Gaussians))

Dictionary_Conditions = [0] * (Number_Gaussians*3)
for i in range(Number_Gaussians):
    A_i, mu_i, sigma_i = p_0_kmpfit_Norm[i*3:(i+1)*3]
    p_1_clg, Wave[Ind_left:Ind_right], Continuum[Ind_left:Ind_right])

#---------Kmpfit method no normalized----------

#Guessing components
ncomps = 0
Q = 1
cutamp = 0.01 * max(y)
cutsig = 2.0
print 'puttinig in'
print x, y, continuum_error_norm, cutamp, cutsig, Number_Gaussians
while ncomps != 2 and Q < 8:
    comps = gauest(x,
                   y,
                   continuum_error_norm,
                   cutamp,
                   cutsig,
                   q=Q,
                   ncomp=Number_Gaussians)
    ncomps = len(comps)
    Q += 1

print 'the comps are', comps

p_0_kmpfit_Norm = []
for c in p_0:
    p_0_kmpfit_Norm.append(round(c, 3))

fitobj = kmpfit.Fitter(residuals=my_residuals,
                       data=(x, y, continuum_error_norm, Number_Gaussians))
Exemplo n.º 3
0
x = numpy.linspace(-5, 10, N)
truepars1 = [10.0, 5.0, 1.0, 3.0, -1.0, 1.5, 0.0]
#p0 = [9, 4.5, 0.8, 0]
y = my_model(truepars1, x, 2) + 0.3*numpy.random.randn(len(x))
err = 0.3*numpy.random.randn(N)

cutamp = 0.1*y.max()
cutsig = 5.0
rms = 0.3
# We use gauest to get the initial estimates
# Gauest returns a list with up to ncomp tuples of which each tuple contains the amplitude, 
# the centre and the dispersion of the gaussian, in that order.
ncomps = 0
Q = 1
while ncomps != 2 and Q < 8:
   comps = gauest(x, y, rms, cutamp, cutsig, q=Q, ncomp=2)
   ncomps = len(comps)
   Q += 1

if ncomps != 2:
   raise Exception("Cannot estimate two components")

print("Gauest with cutamp, cutsig, rms", cutamp, cutsig, rms)
print("Number of components found:", ncomps)
print("Value of Q for which 2 comps. were found:", Q-1)

p0 = []
for c in comps:
   p0 += c
p0.append(0.0)   # Zero level
print("Initial estimates p0=", p0)
  xse = xs
  yse = ys

# thresholds for filters
cutamp = 0.1*yse.max()
cutsig = 5.0
rms = 0.3

# Gauest returns a list with up to ncomp tuples 
# of which each tuple contains the amplitude, 
# the centre and the dispersion of the gaussian, in that order.

ncomps = 0
Q = 6
while ncomps != 2 and Q < 15:
   comps = gauest(yse, rms, cutamp, cutsig, q=Q, ncomp=2)
   ncomps = len(comps)
   Q += 1

if ncomps == 2:
   d = xse[1] - xse[0]
   p0 = []
   for comp in comps:          # Scale to real x range
      p0.append(comp[0])
      p0.append(xse[0] + comp[1]*d), 
      p0.append(comp[2]*d)

   print("Gauest with cutamp, cutsig, rms", cutamp, cutsig, rms)
   print("Number of components found:", ncomps)
   print("Value of Q for which 2 comps. were found:", Q-1)
   print("Found ampl, center, dispersion:", p0)
Exemplo n.º 5
0
    xse = xs
    yse = ys

# thresholds for filters
cutamp = 0.1 * yse.max()
cutsig = 5.0
rms = 0.3

# Gauest returns a list with up to ncomp tuples
# of which each tuple contains the amplitude,
# the centre and the dispersion of the gaussian, in that order.

ncomps = 0
Q = 6
while ncomps != 2 and Q < 15:
    comps = gauest(yse, rms, cutamp, cutsig, q=Q, ncomp=2)
    ncomps = len(comps)
    Q += 1

if ncomps == 2:
    d = xse[1] - xse[0]
    p0 = []
    for comp in comps:  # Scale to real x range
        p0.append(comp[0])
        p0.append(xse[0] + comp[1] * d),
        p0.append(comp[2] * d)

    print("Gauest with cutamp, cutsig, rms", cutamp, cutsig, rms)
    print("Number of components found:", ncomps)
    print("Value of Q for which 2 comps. were found:", Q - 1)
    print("Found ampl, center, dispersion:", p0)