- Timestamp:
- Sep 20, 2017 7:55:53 AM (7 years ago)
- 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. - Location:
- test
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
test/corfunc/test/utest_corfunc.py
r253eb6c6 r86ba9d6 2 2 Unit Tests for CorfuncCalculator class 3 3 """ 4 from __future__ import division, print_function 4 5 5 6 import unittest 6 7 import time 8 7 9 import numpy as np 10 8 11 from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator 9 12 from sas.sascalc.dataloader.data_info import Data1D … … 14 17 def setUp(self): 15 18 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 16 28 self.calculator = CorfuncCalculator(data=self.data, lowerq=0.013, 17 29 upperq=(0.15, 0.24)) 30 self.calculator.background = 0.3 18 31 self.extrapolation = None 32 self.transformation = None 33 self.results = [np.loadtxt(filename+"_out.txt").T[2] 34 for filename in ("gamma1", "gamma3", "idf")] 19 35 20 36 def extrapolate(self): 21 params, extrapolation = self.calculator.compute_extrapolation() 22 37 params, extrapolation, s2 = self.calculator.compute_extrapolation() 23 38 # Check the extrapolation parameters 24 self.assertAlmostEqual(params['A'], 4.1 9, places=2)25 self.assertAlmostEqual(params['B'], -254 70, 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) 28 43 29 44 # Ensure the extraplation tends to the background value … … 57 72 break 58 73 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 64 80 65 81 def extract_params(self): 66 params = self.calculator.extract_parameters(self.transformation )82 params = self.calculator.extract_parameters(self.transformation[0]) 67 83 self.assertIsNotNone(params) 68 84 self.assertEqual(len(params), 6) 69 85 self.assertLess(abs(params['max']-75), 2.5) # L_p ~= 75 70 86 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 71 99 # Ensure tests are ran in correct order; 72 100 # Each test depends on the one before it 73 101 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] 75 103 for test in steps: 76 104 try: 77 105 test() 78 106 except Exception as e: 107 raise 79 108 self.fail("{} failed ({}: {})".format(test, type(e), e)) 80 109 81 110 82 111 def load_data(filename="98929.txt"): 83 data = np.loadtxt(filename, dtype=np.float 32)112 data = np.loadtxt(filename, dtype=np.float64) 84 113 q = data[:,0] 85 114 iq = data[:,1] -
test/utest_sasview.py
rb54440d rbe51cf6 62 62 proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) 63 63 std_out, std_err = proc.communicate() 64 #print std_out64 #print(">>>>>> standard out", file_path, "\n", std_out, "\n>>>>>>>>> end stdout", file_path) 65 65 #sys.exit() 66 66 m = re.search("Ran ([0-9]+) test", std_out) … … 82 82 failed += 1 83 83 print("Result for %s (%s): FAILED" % (module_name, module_dir)) 84 print(std_out)84 #print(std_out) 85 85 else: 86 86 passed += 1 -
test/sasdataloader/test/utest_abs_reader.py
ra78a02f rae69c690 333 333 self.assertEqual(self.data.x[1], 0.03) 334 334 self.assertAlmostEquals(self.data.y[1], 1001.0) 335 self.assertEqual(self.data.dx[0], 0.0)336 335 self.assertEqual(self.data.dxl[1], 0.005) 337 336 self.assertEqual(self.data.dxw[1], 0.001)
Note: See TracChangeset
for help on using the changeset viewer.