[9e85792] | 1 | """ |
---|
| 2 | Unit tests for fitting module |
---|
| 3 | """ |
---|
| 4 | import unittest |
---|
| 5 | from sans.guitools.plottables import Theory1D |
---|
| 6 | from sans.guitools.plottables import Data1D |
---|
| 7 | from sans.fit.ScipyFitting import Parameter |
---|
| 8 | import math |
---|
| 9 | class testFitModule(unittest.TestCase): |
---|
| 10 | |
---|
| 11 | def test2models2dataonconstraint(self): |
---|
| 12 | """ test fitting for two set of data and one model with a constraint""" |
---|
| 13 | from sans.fit.Loader import Load |
---|
| 14 | load= Load() |
---|
| 15 | #Load the first set of data |
---|
| 16 | load.set_filename("testdata1.txt") |
---|
| 17 | load.set_values() |
---|
| 18 | data1 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
| 19 | load.load_data(data1) |
---|
| 20 | |
---|
| 21 | #Load the second set of data |
---|
| 22 | load.set_filename("testdata2.txt") |
---|
| 23 | load.set_values() |
---|
| 24 | data2 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
| 25 | load.load_data(data2) |
---|
| 26 | |
---|
| 27 | #Importing the Fit module |
---|
| 28 | from sans.fit.Fitting import Fit |
---|
| 29 | fitter= Fit() |
---|
| 30 | # Receives the type of model for the fitting |
---|
| 31 | from sans.guitools.LineModel import LineModel |
---|
| 32 | model1 = LineModel() |
---|
| 33 | model2 = LineModel() |
---|
| 34 | #set engine for scipy |
---|
| 35 | fitter.fit_engine('park') |
---|
| 36 | engine = fitter.returnEngine() |
---|
| 37 | #Do the fit |
---|
| 38 | engine.set_param( model1,"M1", {'A':2,'B':3}) |
---|
| 39 | engine.set_model(model1,1) |
---|
| 40 | engine.set_data(data1,1) |
---|
| 41 | #print "m1 param b", M1.B |
---|
| 42 | engine.set_param( model2,"M2", {'A':1,'B':'2*M1.B'}) |
---|
| 43 | engine.set_model(model2,2) |
---|
| 44 | engine.set_data(data2,2) |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | print engine.fit({'A':2,'B':1},None,None) |
---|
| 48 | |
---|