- Timestamp:
- Sep 19, 2017 1:02:20 PM (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:
- 932519a
- Parents:
- a859f99
- Location:
- test/corfunc/test
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/corfunc/test/utest_corfunc.py
rbe51cf6 r1f21a43 14 14 def setUp(self): 15 15 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 16 25 self.calculator = CorfuncCalculator(data=self.data, lowerq=0.013, 17 26 upperq=(0.15, 0.24)) 27 self.calculator.background = 0.3 18 28 self.extrapolation = None 29 self.results = [np.loadtxt(filename+"_out.txt").T[2] 30 for filename in ("gamma1", "gamma3", "idf")] 19 31 20 32 def extrapolate(self): 21 33 params, extrapolation, s2 = self.calculator.compute_extrapolation() 22 23 34 # 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)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) 28 39 29 40 # Ensure the extraplation tends to the background value … … 62 73 self.assertAlmostEqual(transform1.y[0], 1) 63 74 self.assertAlmostEqual(transform1.y[-1], 0, 5) 64 self.transformation = transform 175 self.transformation = transforms 65 76 66 77 def extract_params(self): 67 params = self.calculator.extract_parameters(self.transformation )78 params = self.calculator.extract_parameters(self.transformation[0]) 68 79 self.assertIsNotNone(params) 69 80 self.assertEqual(len(params), 6) 70 81 self.assertLess(abs(params['max']-75), 2.5) # L_p ~= 75 71 82 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 72 93 # Ensure tests are ran in correct order; 73 94 # Each test depends on the one before it 74 95 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] 76 97 for test in steps: 77 98 try: … … 83 104 84 105 def load_data(filename="98929.txt"): 85 data = np.loadtxt(filename, dtype=np.float 32)106 data = np.loadtxt(filename, dtype=np.float64) 86 107 q = data[:,0] 87 108 iq = data[:,1]
Note: See TracChangeset
for help on using the changeset viewer.