Changeset 13374be in sasview for test


Ignore:
Timestamp:
Sep 20, 2017 7:55:53 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:
fca1f50
Parents:
6d62b7f (diff), 2a399ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into 4_1_issues

Location:
test
Files:
3 added
3 edited

Legend:

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

    r253eb6c6 r86ba9d6  
    22Unit Tests for CorfuncCalculator class 
    33""" 
     4from __future__ import division, print_function 
    45 
    56import unittest 
    67import time 
     8 
    79import numpy as np 
     10 
    811from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator 
    912from sas.sascalc.dataloader.data_info import Data1D 
     
    1417    def setUp(self): 
    1518        self.data = load_data() 
     19        # Note: to generate target values from the GUI: 
     20        # * load the data from test/corfunc/test/98929.txt 
     21        # * set qrange to (0, 0.013), (0.15, 0.24) 
     22        # * select fourier transform type 
     23        # * click Calculate Bg 
     24        # * click Extrapolate 
     25        # * click Compute Parameters 
     26        # * copy the Guinier and Porod values to the extrapolate function 
     27        # * for each graph, grab the data from DataInfo and store it in _out.txt 
    1628        self.calculator = CorfuncCalculator(data=self.data, lowerq=0.013, 
    1729            upperq=(0.15, 0.24)) 
     30        self.calculator.background = 0.3 
    1831        self.extrapolation = None 
     32        self.transformation = None 
     33        self.results = [np.loadtxt(filename+"_out.txt").T[2] 
     34                        for filename in ("gamma1", "gamma3", "idf")] 
    1935 
    2036    def extrapolate(self): 
    21         params, extrapolation = self.calculator.compute_extrapolation() 
    22  
     37        params, extrapolation, s2 = self.calculator.compute_extrapolation() 
    2338        # 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) 
     39        self.assertAlmostEqual(params['A'], 4.18970, places=5) 
     40        self.assertAlmostEqual(params['B'], -25469.9, places=1) 
     41        self.assertAlmostEqual(params['K'], 4.44660e-5, places=10) 
     42        #self.assertAlmostEqual(params['sigma'], 1.70181e-10, places=15) 
    2843 
    2944        # Ensure the extraplation tends to the background value 
     
    5772                break 
    5873 
    59     def transform_callback(self, transform): 
    60         self.assertIsNotNone(transform) 
    61         self.assertAlmostEqual(transform.y[0], 1) 
    62         self.assertAlmostEqual(transform.y[-1], 0, 5) 
    63         self.transformation = transform 
     74    def transform_callback(self, transforms): 
     75        transform1, transform3, idf = transforms 
     76        self.assertIsNotNone(transform1) 
     77        self.assertAlmostEqual(transform1.y[0], 1) 
     78        self.assertAlmostEqual(transform1.y[-1], 0, 5) 
     79        self.transformation = transforms 
    6480 
    6581    def extract_params(self): 
    66         params = self.calculator.extract_parameters(self.transformation) 
     82        params = self.calculator.extract_parameters(self.transformation[0]) 
    6783        self.assertIsNotNone(params) 
    6884        self.assertEqual(len(params), 6) 
    6985        self.assertLess(abs(params['max']-75), 2.5) # L_p ~= 75 
    7086 
     87    def check_transforms(self): 
     88        gamma1, gamma3, idf = self.transformation 
     89        gamma1_out, gamma3_out, idf_out = self.results 
     90        def compare(a, b): 
     91            return max(abs((a-b)/b)) 
     92        #print("gamma1 diff", compare(gamma1.y[gamma1.x<=200.], gamma1_out)) 
     93        #print("gamma3 diff", compare(gamma3.y[gamma3.x<=200.], gamma3_out)) 
     94        #print("idf diff", compare(idf.y[idf.x<=200.], idf_out)) 
     95        #self.assertLess(compare(gamma1.y[gamma1.x<=200.], gamma1_out), 1e-10) 
     96        #self.assertLess(compare(gamma3.y[gamma3.x<=200.], gamma3_out), 1e-10) 
     97        #self.assertLess(compare(idf.y[idf.x<=200.], idf_out), 1e-10) 
     98 
    7199    # Ensure tests are ran in correct order; 
    72100    # Each test depends on the one before it 
    73101    def test_calculator(self): 
    74         steps = [self.extrapolate, self.transform, self.extract_params] 
     102        steps = [self.extrapolate, self.transform, self.extract_params, self.check_transforms] 
    75103        for test in steps: 
    76104            try: 
    77105                test() 
    78106            except Exception as e: 
     107                raise 
    79108                self.fail("{} failed ({}: {})".format(test, type(e), e)) 
    80109 
    81110 
    82111def load_data(filename="98929.txt"): 
    83     data = np.loadtxt(filename, dtype=np.float32) 
     112    data = np.loadtxt(filename, dtype=np.float64) 
    84113    q = data[:,0] 
    85114    iq = data[:,1] 
  • test/utest_sasview.py

    rb54440d rbe51cf6  
    6262                    proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) 
    6363                    std_out, std_err = proc.communicate() 
    64                     #print std_out 
     64                    #print(">>>>>> standard out", file_path, "\n", std_out, "\n>>>>>>>>> end stdout", file_path) 
    6565                    #sys.exit() 
    6666                    m = re.search("Ran ([0-9]+) test", std_out) 
     
    8282                        failed += 1 
    8383                        print("Result for %s (%s): FAILED" % (module_name, module_dir)) 
    84                         print(std_out) 
     84                        #print(std_out) 
    8585                    else: 
    8686                        passed += 1 
  • test/sasdataloader/test/utest_abs_reader.py

    ra78a02f rae69c690  
    333333        self.assertEqual(self.data.x[1], 0.03) 
    334334        self.assertAlmostEquals(self.data.y[1], 1001.0) 
    335         self.assertEqual(self.data.dx[0], 0.0) 
    336335        self.assertEqual(self.data.dxl[1], 0.005) 
    337336        self.assertEqual(self.data.dxw[1], 0.001) 
Note: See TracChangeset for help on using the changeset viewer.