source: sasview/DataLoader/test/utest_smearing.py @ 97dea6c

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 97dea6c was 5859862, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

dataloader: fixed problem with uneven binning. Added utility method to get first and last bins in unsmeared q.

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[d00f8ff]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
[4fe4394]10from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection
[d00f8ff]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)
[4fe4394]23        dx = 0.00*numpy.ones(10)
[d00f8ff]24       
[4fe4394]25        self.data.dx = dx
[d00f8ff]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)
[5859862]56        # The following commented line was the correct output for even bins [see smearer.cpp for details]
57        #answer = [ 9.666,  9.056,  8.329,  7.494,  6.642,  5.721,  4.774,  3.824,  2.871, 2.   ]
58        answer = [ 9.2302,  8.6806,  7.9533,  7.1673,  6.2889,  5.4,     4.5028,  3.5744,  2.6083, 2.    ]
[d00f8ff]59        for i in range(len(input)):
[a3f8d58]60            self.assertAlmostEqual(answer[i], output[i], 2)
[d00f8ff]61       
62    def test_q(self):
63        """
64            Test identity resolution smearing
65        """
66        # Create smearer for our data
67        s = QSmearer(self.data)
68       
69        input = 12.0-numpy.arange(1,11)
70        output = s(input)
71        for i in range(len(input)):
[a3f8d58]72            self.assertAlmostEquals(input[i], output[i], 5)
[d00f8ff]73
74    def test_q2(self):
75        """
76            Test basic smearing
77        """
78        dx = 0.001*numpy.ones(10)
79        self.data.dx = dx
80
81        # Create smearer for our data
82        s = QSmearer(self.data)
83       
84        input = 12.0-numpy.arange(1,11)
85        output = s(input)
86       
87        answer = [ 10.44785079,   9.84991299,   8.98101708,   
88                  7.99906585,   6.99998311,   6.00001689,
89                  5.00093415,   4.01898292,   3.15008701,   2.55214921]
90        for i in range(len(input)):
91            self.assertAlmostEqual(answer[i], output[i], 5)
92     
93
94if __name__ == '__main__':
95    unittest.main()
96   
Note: See TracBrowser for help on using the repository browser.