Changeset 93c2ef2 in sasview for park_integration


Ignore:
Timestamp:
May 21, 2008 11:10:45 AM (17 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
acb8788
Parents:
4a0536a
Message:

some modif

File:
1 edited

Legend:

Unmodified
Added
Removed
  • park_integration/test/testfitting.py

    r4a0536a r93c2ef2  
    22    Unit tests for fitting module  
    33""" 
    4 import unittest,fittings 
     4import unittest 
    55from sans.guitools.plottables import Theory1D 
    66from sans.guitools.plottables import Data1D 
     7from FittingModule import Parameter 
     8import math 
    79class testFitModule(unittest.TestCase): 
    810    """ test fitting """ 
     
    5557        load= Load() 
    5658        load.set_filename("testdata_line.txt") 
    57         self.assertEqual(load.get_filename(),"testdata_line.txt") 
    5859        load.set_values() 
    5960        x,y,dx,dy = load.get_values() 
    60          
    6161        data1 = Data1D(x=[], y=[],dx=None, dy=None) 
    6262        load.load_data(data1) 
     63         
    6364        # Receives the type of model for the fitting 
    6465        from sans.guitools.LineModel import LineModel 
    65         self.model  = LineModel() 
    66            
     66        model  = LineModel() 
     67         
    6768        from FittingModule import Fitting 
    68         fitting= Fitting(data1,None) 
    69         fitting.set_model(self.model) 
    70         self.assertEqual(fitting.fit_engine(),True) 
    71         fitting.set_data(x,y,dx,dy) 
    72         chisqr, out, cov= fitting.fit() 
    73         self.assertAlmostEqual(out[1],2.5) 
    74         self.assertAlmostEquals(out[0],4.0) 
    75         self.assertAlmostEquals(out[1]+cov[1][1],2.5) 
    76         self.assertAlmostEquals(out[0]+cov[0][0],4.0) 
     69        Fit= Fitting() 
     70        Fit.set_data(data1) 
     71        Fit.set_model(model) 
    7772         
     73        default_A = model.getParam('A')  
     74        default_B = model.getParam('B')  
     75        cstA = Parameter(model, 'A', default_A) 
     76        cstB  = Parameter(model, 'B', default_B) 
     77        chisqr, out, cov=Fit.fit([cstA,cstB],None,None) 
     78        print"fit only one data",chisqr, out, cov    
     79        
     80        self.assertEqual(Fit.fit_engine(),True) 
     81         
     82        self.assert_(math.fabs(out[1]-2.5)/math.sqrt(cov[1][1]) < 2) 
     83        print "chisqr",chisqr/len(data1.x) 
     84        self.assert_(chisqr/len(data1.x) < 2) 
     85#        self.assertAlmostEqual(out[1],2.5) 
     86        #self.assertAlmostEquals(out[0],4.0) 
     87        #self.assertAlmostEquals(out[1]+cov[1][1],2.5) 
     88        #self.assertAlmostEquals(out[0]+cov[0][0],4.0) 
     89         
Note: See TracChangeset for help on using the changeset viewer.