Changeset 1f21a43 in sasview for test


Ignore:
Timestamp:
Sep 19, 2017 11:02:20 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
932519a
Parents:
a859f99
Message:

more complete corfunc test

Location:
test/corfunc/test
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • test/corfunc/test/utest_corfunc.py

    rbe51cf6 r1f21a43  
    1414    def setUp(self): 
    1515        self.data = load_data() 
     16        # Note: to generate target values from the GUI: 
     17        # * load the data from test/corfunc/test/98929.txt 
     18        # * set qrange to (0, 0.013), (0.15, 0.24) 
     19        # * select fourier transform type 
     20        # * click Calculate Bg 
     21        # * click Extrapolate 
     22        # * click Compute Parameters 
     23        # * copy the Guinier and Porod values to the extrapolate function 
     24        # * for each graph, grab the data from DataInfo and store it in _out.txt 
    1625        self.calculator = CorfuncCalculator(data=self.data, lowerq=0.013, 
    1726            upperq=(0.15, 0.24)) 
     27        self.calculator.background = 0.3 
    1828        self.extrapolation = None 
     29        self.results = [np.loadtxt(filename+"_out.txt").T[2] 
     30                        for filename in ("gamma1", "gamma3", "idf")] 
    1931 
    2032    def extrapolate(self): 
    2133        params, extrapolation, s2 = self.calculator.compute_extrapolation() 
    22  
    2334        # Check the extrapolation parameters 
    24         self.assertAlmostEqual(params['A'], 4.19, places=2) 
    25         self.assertAlmostEqual(params['B'], -25470, places=0) 
    26         self.assertAlmostEqual(params['K'], 4.5e-5, places=2) 
    27         self.assertAlmostEqual(params['sigma'], 2.2e-10, places=2) 
     35        self.assertAlmostEqual(params['A'], 4.18970, places=5) 
     36        self.assertAlmostEqual(params['B'], -25469.9, places=1) 
     37        self.assertAlmostEqual(params['K'], 4.44660e-5, places=10) 
     38        self.assertAlmostEqual(params['sigma'], 1.70181e-10, places=15) 
    2839 
    2940        # Ensure the extraplation tends to the background value 
     
    6273        self.assertAlmostEqual(transform1.y[0], 1) 
    6374        self.assertAlmostEqual(transform1.y[-1], 0, 5) 
    64         self.transformation = transform1 
     75        self.transformation = transforms 
    6576 
    6677    def extract_params(self): 
    67         params = self.calculator.extract_parameters(self.transformation) 
     78        params = self.calculator.extract_parameters(self.transformation[0]) 
    6879        self.assertIsNotNone(params) 
    6980        self.assertEqual(len(params), 6) 
    7081        self.assertLess(abs(params['max']-75), 2.5) # L_p ~= 75 
    7182 
     83    def check_transforms(self): 
     84        gamma1, gamma3, idf = self.transformation 
     85        gamma1_out, gamma3_out, idf_out = self.results 
     86        def compare(a, b): 
     87            return max(abs((a-b)/b)) 
     88        #np.savetxt("gamma1_test.txt", np.vstack((gamma1.x[gamma1.x<=200.], gamma1.y[gamma1.x<=200.])).T) 
     89        self.assertLess(compare(gamma1.y[gamma1.x<=200.], gamma1_out), 1e-10) 
     90        self.assertLess(compare(gamma3.y[gamma3.x<=200.], gamma3_out), 1e-10) 
     91        self.assertLess(compare(idf.y[idf.x<=200.], idf_out), 1e-10) 
     92 
    7293    # Ensure tests are ran in correct order; 
    7394    # Each test depends on the one before it 
    7495    def test_calculator(self): 
    75         steps = [self.extrapolate, self.transform, self.extract_params] 
     96        steps = [self.extrapolate, self.transform, self.extract_params, self.check_transforms] 
    7697        for test in steps: 
    7798            try: 
     
    83104 
    84105def load_data(filename="98929.txt"): 
    85     data = np.loadtxt(filename, dtype=np.float32) 
     106    data = np.loadtxt(filename, dtype=np.float64) 
    86107    q = data[:,0] 
    87108    iq = data[:,1] 
Note: See TracChangeset for help on using the changeset viewer.