Changeset c0ca2e3d in sasview for test


Ignore:
Timestamp:
Apr 8, 2017 6:47:39 AM (7 years ago)
Author:
Ricardo Ferraz Leal <ricleal@…>
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, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
de99a5f0
Parents:
168d359 (diff), 959eb01 (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.
Message:

After merging conflict with master CR/LF

Location:
test
Files:
19 added
3 edited

Legend:

Unmodified
Added
Removed
  • test/sasdataloader/test/testplugings.py

    rb699768 r959eb01  
    3232        output = self.L.load('test_data.test') 
    3333        self.assertEqual(output.x[0], 1234.) 
    34         self.assertTrue(self.L.loaders.has_key('.test')) 
     34        self.assertTrue('.test' in self.L.loaders) 
    3535         
    3636class testZip(unittest.TestCase): 
     
    6161        output = self.L.load('test_data.test') 
    6262        self.assertEqual(output.x[0], 1234.) 
    63         self.assertTrue(self.L.loaders.has_key('.test')) 
     63        self.assertTrue('.test' in self.L.loaders) 
    6464         
    6565         
  • test/sasdataloader/test/utest_averaging.py

    r9a5097c rfa4af76  
    11 
     2import math 
     3import os 
    24import unittest 
    3 import math 
    4  
    5 from sas.sascalc.dataloader.loader import  Loader 
    6 from sas.sascalc.dataloader.manipulations import Ring, CircularAverage, SectorPhi, get_q,reader2D_converter 
    75 
    86import numpy as np 
     7 
    98import sas.sascalc.dataloader.data_info as data_info 
     9from sas.sascalc.dataloader.loader import Loader 
     10from sas.sascalc.dataloader.manipulations import (Boxavg, Boxsum, 
     11                                                  CircularAverage, Ring, 
     12                                                  SectorPhi, SectorQ, SlabX, 
     13                                                  SlabY, get_q, 
     14                                                  reader2D_converter) 
     15 
    1016 
    1117class Averaging(unittest.TestCase): 
     
    1319        Test averaging manipulations on a flat distribution 
    1420    """ 
     21 
    1522    def setUp(self): 
    1623        """ 
     
    1825            should return the predefined height of the distribution (1.0). 
    1926        """ 
    20         x_0  = np.ones([100,100]) 
    21         dx_0 = np.ones([100,100]) 
    22          
     27        x_0 = np.ones([100, 100]) 
     28        dx_0 = np.ones([100, 100]) 
     29 
    2330        self.data = data_info.Data2D(data=x_0, err_data=dx_0) 
    2431        detector = data_info.Detector() 
    25         detector.distance = 1000.0  #mm 
    26         detector.pixel_size.x = 1.0 #mm 
    27         detector.pixel_size.y = 1.0 #mm 
    28          
     32        detector.distance = 1000.0  # mm 
     33        detector.pixel_size.x = 1.0  # mm 
     34        detector.pixel_size.y = 1.0  # mm 
     35 
    2936        # center in pixel position = (len(x_0)-1)/2 
    30         detector.beam_center.x = (len(x_0)-1)/2 #pixel number 
    31         detector.beam_center.y = (len(x_0)-1)/2 #pixel number 
     37        detector.beam_center.x = (len(x_0) - 1) / 2  # pixel number 
     38        detector.beam_center.y = (len(x_0) - 1) / 2  # pixel number 
    3239        self.data.detector.append(detector) 
    33          
     40 
    3441        source = data_info.Source() 
    35         source.wavelength = 10.0 #A 
     42        source.wavelength = 10.0  # A 
    3643        self.data.source = source 
    37          
    38         # get_q(dx, dy, det_dist, wavelength) where units are mm,mm,mm,and A respectively. 
     44 
     45        # get_q(dx, dy, det_dist, wavelength) where units are mm,mm,mm,and A 
     46        # respectively. 
    3947        self.qmin = get_q(1.0, 1.0, detector.distance, source.wavelength) 
    4048 
    4149        self.qmax = get_q(49.5, 49.5, detector.distance, source.wavelength) 
    42          
     50 
    4351        self.qstep = len(x_0) 
    44         x=  np.linspace(start= -1*self.qmax, 
    45                                stop= self.qmax, 
    46                                num= self.qstep, 
    47                                endpoint=True )   
    48         y = np.linspace(start= -1*self.qmax, 
    49                                stop= self.qmax, 
    50                                num= self.qstep, 
    51                                endpoint=True ) 
    52         self.data.x_bins=x 
    53         self.data.y_bins=y 
     52        x = np.linspace(start=-1 * self.qmax, 
     53                        stop=self.qmax, 
     54                        num=self.qstep, 
     55                        endpoint=True) 
     56        y = np.linspace(start=-1 * self.qmax, 
     57                        stop=self.qmax, 
     58                        num=self.qstep, 
     59                        endpoint=True) 
     60        self.data.x_bins = x 
     61        self.data.y_bins = y 
    5462        self.data = reader2D_converter(self.data) 
    55              
     63 
    5664    def test_ring_flat_distribution(self): 
    5765        """ 
    5866            Test ring averaging 
    5967        """ 
    60         r = Ring(r_min=2*self.qmin, r_max=5*self.qmin,  
    61                  center_x=self.data.detector[0].beam_center.x,  
     68        r = Ring(r_min=2 * self.qmin, r_max=5 * self.qmin, 
     69                 center_x=self.data.detector[0].beam_center.x, 
    6270                 center_y=self.data.detector[0].beam_center.y) 
    6371        r.nbins_phi = 20 
    64          
     72 
    6573        o = r(self.data) 
    6674        for i in range(20): 
    6775            self.assertEqual(o.y[i], 1.0) 
    68              
     76 
    6977    def test_sectorphi_full(self): 
    7078        """ 
    7179            Test sector averaging 
    7280        """ 
    73         r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin,  
    74                       phi_min=0, phi_max=math.pi*2.0) 
     81        r = SectorPhi(r_min=self.qmin, r_max=3 * self.qmin, 
     82                      phi_min=0, phi_max=math.pi * 2.0) 
    7583        r.nbins_phi = 20 
    7684        o = r(self.data) 
    7785        for i in range(7): 
    7886            self.assertEqual(o.y[i], 1.0) 
    79              
    80              
     87 
    8188    def test_sectorphi_partial(self): 
    8289        """ 
    8390        """ 
    8491        phi_max = math.pi * 1.5 
    85         r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin,  
     92        r = SectorPhi(r_min=self.qmin, r_max=3 * self.qmin, 
    8693                      phi_min=0, phi_max=phi_max) 
    8794        self.assertEqual(r.phi_max, phi_max) 
     
    9198        for i in range(17): 
    9299            self.assertEqual(o.y[i], 1.0) 
    93              
    94              
    95  
    96 class data_info_tests(unittest.TestCase): 
    97      
     100 
     101 
     102class DataInfoTests(unittest.TestCase): 
     103 
    98104    def setUp(self): 
    99         self.data = Loader().load('MAR07232_rest.ASC') 
    100          
     105        filepath = os.path.join(os.path.dirname( 
     106            os.path.realpath(__file__)), 'MAR07232_rest.ASC') 
     107        self.data = Loader().load(filepath) 
     108 
    101109    def test_ring(self): 
    102110        """ 
    103111            Test ring averaging 
    104112        """ 
    105         r = Ring(r_min=.005, r_max=.01,  
    106                  center_x=self.data.detector[0].beam_center.x,  
     113        r = Ring(r_min=.005, r_max=.01, 
     114                 center_x=self.data.detector[0].beam_center.x, 
    107115                 center_y=self.data.detector[0].beam_center.y, 
    108                  nbins = 20) 
     116                 nbins=20) 
    109117        ##r.nbins_phi = 20 
    110          
    111         o = r(self.data) 
    112         answer = Loader().load('ring_testdata.txt') 
    113          
     118 
     119        o = r(self.data) 
     120        filepath = os.path.join(os.path.dirname( 
     121            os.path.realpath(__file__)), 'ring_testdata.txt') 
     122        answer = Loader().load(filepath) 
     123 
    114124        for i in range(r.nbins_phi - 1): 
    115125            self.assertAlmostEqual(o.x[i + 1], answer.x[i], 4) 
    116126            self.assertAlmostEqual(o.y[i + 1], answer.y[i], 4) 
    117127            self.assertAlmostEqual(o.dy[i + 1], answer.dy[i], 4) 
    118              
     128 
    119129    def test_circularavg(self): 
    120130        """ 
     131        Test circular averaging 
     132        The test data was not generated by IGOR. 
     133        """ 
     134        r = CircularAverage(r_min=.00, r_max=.025, 
     135                            bin_width=0.0003) 
     136        r.nbins_phi = 20 
     137 
     138        o = r(self.data) 
     139 
     140        filepath = os.path.join(os.path.dirname( 
     141            os.path.realpath(__file__)), 'avg_testdata.txt') 
     142        answer = Loader().load(filepath) 
     143        for i in range(r.nbins_phi): 
     144            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     145            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     146            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     147 
     148    def test_box(self): 
     149        """ 
    121150            Test circular averaging 
    122151            The test data was not generated by IGOR. 
    123152        """ 
    124         r = CircularAverage(r_min=.00, r_max=.025,  
    125                  bin_width=0.0003) 
    126         r.nbins_phi = 20 
    127          
    128         o = r(self.data) 
    129  
    130         answer = Loader().load('avg_testdata.txt') 
    131         for i in range(r.nbins_phi): 
    132             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    133             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    134             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    135              
    136     def test_box(self): 
    137         """ 
    138             Test circular averaging 
    139             The test data was not generated by IGOR. 
    140         """ 
    141         from sas.sascalc.dataloader.manipulations import Boxsum, Boxavg 
    142          
     153 
    143154        r = Boxsum(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 
    144155        s, ds, npoints = r(self.data) 
    145156        self.assertAlmostEqual(s, 34.278990899999997, 4) 
    146157        self.assertAlmostEqual(ds, 7.8007981835194293, 4) 
    147         self.assertAlmostEqual(npoints, 324.0000, 4)         
    148      
     158        self.assertAlmostEqual(npoints, 324.0000, 4) 
     159 
    149160        r = Boxavg(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 
    150161        s, ds = r(self.data) 
    151162        self.assertAlmostEqual(s, 0.10579935462962962, 4) 
    152163        self.assertAlmostEqual(ds, 0.024076537603455028, 4) 
    153              
     164 
    154165    def test_slabX(self): 
    155166        """ 
     
    157168            The test data was not generated by IGOR. 
    158169        """ 
    159         from sas.sascalc.dataloader.manipulations import SlabX 
    160          
    161         r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, y_max=0.0002, bin_width=0.0004) 
     170 
     171        r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, 
     172                  y_max=0.0002, bin_width=0.0004) 
    162173        r.fold = False 
    163174        o = r(self.data) 
    164175 
    165         answer = Loader().load('slabx_testdata.txt') 
    166         for i in range(len(o.x)): 
    167             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    168             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    169             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    170              
     176        filepath = os.path.join(os.path.dirname( 
     177            os.path.realpath(__file__)), 'slabx_testdata.txt') 
     178        answer = Loader().load(filepath) 
     179        for i in range(len(o.x)): 
     180            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     181            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     182            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     183 
    171184    def test_slabY(self): 
    172185        """ 
     
    174187            The test data was not generated by IGOR. 
    175188        """ 
    176         from sas.sascalc.dataloader.manipulations import SlabY 
    177          
    178         r = SlabY(x_min=.005, x_max=.01, y_min=-0.01, y_max=0.01, bin_width=0.0004) 
     189 
     190        r = SlabY(x_min=.005, x_max=.01, y_min=- 
     191                  0.01, y_max=0.01, bin_width=0.0004) 
    179192        r.fold = False 
    180193        o = r(self.data) 
    181194 
    182         answer = Loader().load('slaby_testdata.txt') 
    183         for i in range(len(o.x)): 
    184             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    185             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    186             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    187              
     195        filepath = os.path.join(os.path.dirname( 
     196            os.path.realpath(__file__)), 'slaby_testdata.txt') 
     197        answer = Loader().load(filepath) 
     198        for i in range(len(o.x)): 
     199            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     200            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     201            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     202 
    188203    def test_sectorphi_full(self): 
    189204        """ 
     
    193208            The test data was not generated by IGOR. 
    194209        """ 
    195         from sas.sascalc.dataloader.manipulations import SectorPhi 
    196         import math 
    197          
     210 
    198211        nbins = 19 
    199212        phi_min = math.pi / (nbins + 1) 
    200213        phi_max = math.pi * 2 - phi_min 
    201          
     214 
    202215        r = SectorPhi(r_min=.005, 
    203216                      r_max=.01, 
     
    207220        o = r(self.data) 
    208221 
    209         answer = Loader().load('ring_testdata.txt') 
    210         for i in range(len(o.x)): 
    211             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    212             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    213             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    214              
     222        filepath = os.path.join(os.path.dirname( 
     223            os.path.realpath(__file__)), 'ring_testdata.txt') 
     224        answer = Loader().load(filepath) 
     225        for i in range(len(o.x)): 
     226            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     227            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     228            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     229 
    215230    def test_sectorphi_quarter(self): 
    216231        """ 
     
    218233            The test data was not generated by IGOR. 
    219234        """ 
    220         from sas.sascalc.dataloader.manipulations import SectorPhi 
    221         import math 
    222          
    223         r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) 
    224         r.nbins_phi = 20 
    225         o = r(self.data) 
    226  
    227         answer = Loader().load('sectorphi_testdata.txt') 
    228         for i in range(len(o.x)): 
    229             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    230             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    231             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    232              
     235 
     236        r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0) 
     237        r.nbins_phi = 20 
     238        o = r(self.data) 
     239 
     240        filepath = os.path.join(os.path.dirname( 
     241            os.path.realpath(__file__)), 'sectorphi_testdata.txt') 
     242        answer = Loader().load(filepath) 
     243        for i in range(len(o.x)): 
     244            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     245            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     246            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     247 
    233248    def test_sectorq_full(self): 
    234249        """ 
     
    236251            The test data was not generated by IGOR. 
    237252        """ 
    238         from sas.sascalc.dataloader.manipulations import SectorQ 
    239         import math 
    240          
    241         r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) 
    242         r.nbins_phi = 20 
    243         o = r(self.data) 
    244  
    245         answer = Loader().load('sectorq_testdata.txt') 
    246         for i in range(len(o.x)): 
    247             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    248             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    249             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    250              
     253 
     254        r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0) 
     255        r.nbins_phi = 20 
     256        o = r(self.data) 
     257 
     258        filepath = os.path.join(os.path.dirname( 
     259            os.path.realpath(__file__)), 'sectorq_testdata.txt') 
     260        answer = Loader().load(filepath) 
     261        for i in range(len(o.x)): 
     262            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     263            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     264            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     265 
    251266 
    252267if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.