source: sasview/DataLoader/test/utest_smearing.py @ 7b0fd65

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 7b0fd65 was 4fe4394, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

implemented smearer selection

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