source: sasview/test/sasdataloader/test/utest_smearing.py @ ef908db

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ef908db was ef908db, checked in by krzywon, 8 years ago

Remove all tests referring to saview Models and delete unused test files.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"""
2    Unit tests for data manipulations
3"""
4
5
6import unittest
7import numpy, math
8from sas.sascalc.dataloader.loader import  Loader
9from sas.sascalc.dataloader.data_info import Data1D, Data2D
10#from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection
11from sas.sascalc.data_util.qsmearing import SlitSmearer, QSmearer, smear_selection
12import os.path
13from time import time
14class smear_tests(unittest.TestCase):
15   
16    def setUp(self):
17        data = Loader().load("cansas1d_slit.xml")
18        self.data = data[0]
19       
20        x = 0.001*numpy.arange(1,11)
21        y = 12.0-numpy.arange(1,11)
22        dxl = 0.00*numpy.ones(10)
23        dxw = 0.00*numpy.ones(10)
24        dx = 0.00*numpy.ones(10)
25       
26        self.data.dx = dx
27        self.data.x = x
28        self.data.y = y
29        self.data.dxl = dxl
30        self.data.dxw = dxw
31       
32    def test_slit(self):
33        """
34            Test identity smearing
35        """
36        # Create smearer for our data
37        s = SlitSmearer(self.data)
38       
39        input = 12.0-numpy.arange(1,11)
40        output = s(input)
41        for i in range(len(input)):
42            self.assertEquals(input[i], output[i])
43
44    def test_slit2(self):
45        """
46            Test basic smearing
47        """
48        dxl = 0.005*numpy.ones(10)
49        dxw = 0.0*numpy.ones(10)
50        self.data.dxl = dxl
51        self.data.dxw = dxw
52        # Create smearer for our data
53        s = SlitSmearer(self.data)
54       
55        input = 12.0-numpy.arange(1,11)
56        output = s(input)
57        # The following commented line was the correct output for even bins [see smearer.cpp for details]
58        #answer = [ 9.666,  9.056,  8.329,  7.494,  6.642,  5.721,  4.774,  3.824,  2.871, 2.   ]
59        answer = [ 9.0618,  8.6401,  8.1186,  7.1391,  6.1528,  5.5555,     4.5584,  3.5606,  2.5623, 2.    ]
60        for i in range(len(input)):
61            self.assertAlmostEqual(answer[i], output[i], 3)
62       
63    def test_q(self):
64        """
65            Test identity resolution smearing
66        """
67        # Create smearer for our data
68        s = QSmearer(self.data)
69       
70        input = 12.0-numpy.arange(1,11)
71        output = s(input)
72        for i in range(len(input)):
73            self.assertAlmostEquals(input[i], output[i], 5)
74
75    def test_q2(self):
76        """
77            Test basic smearing
78        """
79        dx = 0.001*numpy.ones(10)
80        self.data.dx = dx
81
82        # Create smearer for our data
83        s = QSmearer(self.data)
84       
85        input = 12.0-numpy.arange(1,11)
86        output = s(input)
87       
88        answer = [ 10.44785079,   9.84991299,   8.98101708,   
89                  7.99906585,   6.99998311,   6.00001689,
90                  5.00093415,   4.01898292,   3.15008701,   2.55214921]
91        for i in range(len(input)):
92            self.assertAlmostEqual(answer[i], output[i], 2)
93       
94if __name__ == '__main__':
95    unittest.main()
96   
Note: See TracBrowser for help on using the repository browser.