Example #1
0
def better_bumps(model):

    zin=[]
    zout=[]
    chis=[]
    dzs=[]
    nllfs=[]

    # for zs in np.arange(.05,.45,.005):
    #     #print("zs", zs)
    #     model.atomListModel.atomModels[0].z.value = zs
    #     model.update()
    #     schi=model.nllf()
    #     nllfs.append(schi)
    #     zin.append(zs)

    xpeaks = findmin(zin,nllfs,10)
    print('xpeak', xpeaks)
    # these are experimental values, shortcut
    model.atomListModel.atomModels[0].z.value = .35973
    model.atomListModel.atomModels[5].x.value = .07347
    model.atomListModel.atomModels[5].y.value = .07347
    model.update()
    problem = bumps.FitProblem(model)

    result = fitters.fit(problem, method='lm')
    for p, v in zip(problem._parameters, result.dx):
        p.dx = v

    return result.x, result.dx, problem.chisq(), problem._parameters
Example #2
0
def fit(model):
    #Create a problem from the model with bumps, then fit and solve it
    problem = bumps.FitProblem(model)
    monitor = fitter.StepMonitor(problem, open("sxtalFitMonitor.txt","w"))
    fitted = fitter.LevenbergMarquardtFit(problem)
    x, dx = fitted.solve(monitors=[monitor])
    return x, dx, problem.chisq()
Example #3
0
def graphError():

	cell = Mod.makeCell(crystalCell, spaceGroup.xtalSystem)
	m = S.Model(tt, sfs2, backg, wavelength, spaceGroup, cell,
        	[atomList], exclusions,
        	scale=0.06298,hkls=refList, error=error,  extinction=[0.0001054])
	m.atomListModel.atomModels[0].z.range(0,0.5)

        z = 0
	xval = []
	y = []
	while (z < 0.5):

	    	#Set a range on the x value of the first atom in the model
    		m.atomListModel.atomModels[0].z.value = z
    		m.atomListModel.atomModels[0].z.range(0, 0.5)
    		problem = bumps.FitProblem(m)
		#    monitor = fitter.StepMonitor(problem, open("sxtalFitMonitor.txt","w"))

        	fitted = fitter.LevenbergMarquardtFit(problem)
    		x, dx = fitted.solve()
    		xval.append(x[0])
    		y.append(problem.chisq())
                print(x, problem.chisq())
    		z += 0.005

	fig = plt.figure()#
	mpl.pyplot.scatter(xval, yval)
	mpl.pyplot.xlabel("Pr z coordinate")
	mpl.pyplot.ylabel("X2 value")
	fig.savefig('/mnt/storage/prnio_chisq_vals_optcfl_lm.png')
Example #4
0
    def fit(self, model):

        #Create a problem from the model with bumps,
        #then fit and solve it
        problem = bumps.FitProblem(model)
        fitted = fitter.LevenbergMarquardtFit(problem)
        x, dx = fitted.solve()
        return x, dx, problem.chisq()
Example #5
0
def fit(model):

    #Create a problem from the model with bumps,
    #then fit and solve it
    problem = bumps.FitProblem(model)
    fitted = fitter.LevenbergMarquardtFit(problem)
    x, dx = fitted.solve()

    #return:
    # x: parameter values
    # dx: uncertainty on parameters
    # chi squared value for model
    return x, dx, problem.chisq()
Example #6
0
def fit(model):

    print("Fitting problem...")

    #Crate a problem from the model with bumps,
    #then fit and solve it
    problem = bumps.FitProblem(model)
    print(problem.labels())
    fitted = fitter.MPFit(problem)
    x, dx = fitted.solve()

    print(problem.nllf())
    problem.model_update()
    model.update()

    print(problem.nllf())
    return x, dx
Example #7
0
def fitFullModel():

	cell = Mod.makeCell(crystalCell, spaceGroup.xtalSystem)

	#Define a model
	m = S.Model(tt, sfs2, backg, wavelength, spaceGroup, cell,
        	[atomList], exclusions,
        	scale=0.06298,hkls=refList, error=error,  extinction=[0.0001054])

        m.u.range(0,2)
        m.zero.pm(0.1)
        m.v.range(-2,0)
        m.w.range(0,2)
        m.eta.range(0,1)
        m.scale.range(0,10)
        m.base.pm(250)

        for atomModel in m.atomListModel.atomModels:
            atomModel.x.pm(0.1)
            atomModel.z.pm(0.1)
            if (atomModel.atom.multip == atomModel.sgmultip):
                # atom lies on a general position
                atomModel.x.pm(0.1)
                atomModel.y.pm(0.1)
                atomModel.z.pm(0.1)

	m.atomListModel.atomModels[0].z.value = 0.3
	m.atomListModel.atomModels[0].z.range(0,0.5) 

   	problem = bumps.FitProblem(m)
        fitted = fitter.SimplexFit(problem)
    	x, dx = fitted.solve(steps=50)
        problem.model_update()

        print(problem.summarize())
        print(x, dx, problem.chisq())
Example #8
0
    Mq.scale.range(0.1, 40)
    Mq.center.range(-0.1, 0.1)
    Mq.A0.range(0, 0.05)
    Mq.A1.range(0, 1)
    Mq.hwhm1.range(0, 0.5)
    Mq.hwhm2.range(0, 3)

    # Q-independent parameters
    if i == 0:
        QA0 = Mq.A0
    else:
        Mq.A0 = QA0

    M.append(Mq)

problem = bmp.FitProblem(M)

# Preview of the settings
print('Initial chisq', problem.chisq_str())

problem.plot()

result = fit(problem, method='lm', steps=100, verbose=True)

problem.plot()

# Print chi**2 and parameters' values after fit
print("final chisq", problem.chisq_str())
for k, v, dv in zip(problem.labels(), result.x, result.dx):
    print(k, ":", format_uncertainty(v, dv))
Example #9
0
model.b5.range(20, 50)
model.a5.range(-2, 2)
model.b6.range(20, 50)
model.a6.range(-2, 2)
model.b7.range(20, 50)
model.a7.range(-2, 2)
model.b8.range(20, 50)
model.a8.range(-2, 2)
model.b9.range(20, 50)
model.a9.range(-2, 2)
model.b10.range(20, 50)
model.a10.range(-2, 2)
model.b11.range(20, 50)
model.a11.range(-2, 2)
model.b12.range(20, 50)
model.a12.range(-2, 2)
model.b13.range(20, 50)
model.a13.range(-2, 2)
model.b14.range(20, 50)
model.a14.range(-2, 2)
model.b15.range(20, 50)
model.a15.range(-2, 2)
model.b16.range(20, 50)
model.a16.range(-2, 2)
model.b17.range(20, 50)
model.a17.range(-2, 2)
# model.center.range(41.5, 44.5)
# model.fwhm.range(0, 3)

problem = bumps.FitProblem(model)