Changeset 6c497b7 in sasview for test


Ignore:
Timestamp:
Apr 16, 2017 11:01:30 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
f94a935
Parents:
de99a5f0 (diff), e5cbbce (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:

Merge branch 'master' into log_binning

Location:
test
Files:
19 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • test/pr_inversion/test/utest_invertor.py

    r959eb01 rac07a3a  
    576576    data_err = np.zeros(0) 
    577577    scale    = None 
    578     if not path == None: 
     578    if path is not None: 
    579579        input_f = open(path,'r') 
    580580        buff    = input_f.read() 
  • test/sasdataloader/test/utest_cansas.py

    r959eb01 r7432acb  
    103103        self.assertAlmostEqual(data.detector[1].distance, 4145.02) 
    104104        self.assertTrue(data.process[0].name == "Mantid generated CanSAS1D XML") 
    105         self.assertTrue(data.meta_data["xmlpreprocess"] != None) 
     105        self.assertTrue(data.meta_data["xmlpreprocess"] is not None) 
    106106 
    107107 
  • test/sasrealspace/test/sim_validation.py

    r959eb01 rac07a3a  
    3232            #return: mean, error 
    3333        """ 
    34         if not density == None: 
     34        if density is not None: 
    3535            self.density = density 
    3636            self.create() 
     
    4545            #return: mean, error 
    4646        """ 
    47         if not density == None: 
     47        if density is not None: 
    4848            self.density = density 
    4949            self.create() 
  • test/sasrealspace/test/utest_realspace.py

    r959eb01 r45dffa69  
    326326        self.canvas.setParam('%s.radius' % handle, self.outer_radius) 
    327327        self.canvas.setParam('%s.contrast' % handle, self.shell_sld) 
    328         if not order1 == None: 
     328        if order1 is not None: 
    329329            self.canvas.setParam('%s.order' % handle, order1) 
    330330        
     
    332332        self.canvas.setParam('%s.radius' % handle2, self.radius) 
    333333        self.canvas.setParam('%s.contrast' % handle2, 1.0) 
    334         if not order2 == None: 
     334        if order2 is not None: 
    335335            self.canvas.setParam('%s.order' % handle2, order2) 
    336336                
  • 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__': 
  • test/sasguiframe/test/utest_manipulations.py

    r959eb01 rc0ca2e3d  
    22    Unit tests for data manipulations 
    33""" 
    4 #TODO: what happens if you add a Data1D to a Data2D? 
    5  
     4# TODO: what happens if you add a Data1D to a Data2D? 
     5 
     6import math 
     7import os.path 
    68import unittest 
    7 import math 
     9 
    810import numpy as np 
    9 from sas.sascalc.dataloader.loader import  Loader 
    10 from sas.sasgui.guiframe.dataFitting import Data1D, Data2D 
    11 from sas.sasgui.guiframe.dataFitting import Data1D as Theory1D 
    12   
    13 import os.path 
    14  
    15 class data_info_tests(unittest.TestCase): 
    16      
     11 
     12from sas.sascalc.dataloader.loader import Loader 
     13from sas.sasgui.guiframe.dataFitting import Data1D 
     14from sas.sasgui.guiframe.dataFitting import Data2D 
     15 
     16 
     17class DataInfoTests(unittest.TestCase): 
     18 
    1719    def setUp(self): 
    1820        data = Loader().load("cansas1d.xml") 
    1921        self.data = data[0] 
    20          
     22 
    2123    def test_clone1D(self): 
    2224        """ 
     
    2426        """ 
    2527        clone = self.data.clone_without_data() 
    26          
     28 
    2729        for i in range(len(self.data.detector)): 
    28             self.assertEqual(self.data.detector[i].distance, clone.detector[i].distance) 
    29              
    30 class theory1d_tests(unittest.TestCase): 
    31      
     30            self.assertEqual( 
     31                self.data.detector[i].distance, clone.detector[i].distance) 
     32 
     33 
     34class Theory1DTests(unittest.TestCase): 
     35 
    3236    def setUp(self): 
    3337        data = Loader().load("cansas1d.xml") 
    3438        self.data = data[0] 
    35          
     39 
    3640    def test_clone_theory1D(self): 
    3741        """ 
    3842            Test basic cloning 
    3943        """ 
    40         theory = Theory1D(x=[], y=[], dy=None) 
     44        theory = Data1D(x=[], y=[], dy=None) 
    4145        theory.clone_without_data(clone=self.data) 
    4246        theory.copy_from_datainfo(data1d=self.data) 
    4347        for i in range(len(self.data.detector)): 
    44             self.assertEqual(self.data.detector[i].distance, theory.detector[i].distance) 
    45              
     48            self.assertEqual( 
     49                self.data.detector[i].distance, theory.detector[i].distance) 
     50 
    4651        for i in range(len(self.data.x)): 
    4752            self.assertEqual(self.data.x[i], theory.x[i]) 
     
    4954            self.assertEqual(self.data.dy[i], theory.dy[i]) 
    5055 
    51 class manip_tests(unittest.TestCase): 
    52      
     56 
     57class ManipTests(unittest.TestCase): 
     58 
    5359    def setUp(self): 
    5460        # Create two data sets to play with 
    5561        x_0 = np.ones(5) 
    5662        for i in range(5): 
    57             x_0[i] = x_0[i]*(i+1.0) 
    58              
    59         y_0 = 2.0*np.ones(5) 
    60         dy_0 = 0.5*np.ones(5) 
     63            x_0[i] = x_0[i] * (i + 1.0) 
     64 
     65        y_0 = 2.0 * np.ones(5) 
     66        dy_0 = 0.5 * np.ones(5) 
    6167        self.data = Data1D(x_0, y_0, dy=dy_0) 
    62          
     68 
    6369        x = self.data.x 
    6470        y = np.ones(5) 
    6571        dy = np.ones(5) 
    6672        self.data2 = Data1D(x, y, dy=dy) 
    67          
    68          
     73 
    6974    def test_load(self): 
    7075        """ 
     
    7378        # There should be 5 entries in the file 
    7479        self.assertEqual(len(self.data.x), 5) 
    75          
     80 
    7681        for i in range(5): 
    7782            # The x values should be from 1 to 5 
    78             self.assertEqual(self.data.x[i], float(i+1)) 
    79          
     83            self.assertEqual(self.data.x[i], float(i + 1)) 
     84 
    8085            # All y-error values should be 0.5 
    81             self.assertEqual(self.data.dy[i], 0.5)     
    82              
     86            self.assertEqual(self.data.dy[i], 0.5) 
     87 
    8388            # All y values should be 2.0 
    84             self.assertEqual(self.data.y[i], 2.0)     
    85          
     89            self.assertEqual(self.data.y[i], 2.0) 
     90 
    8691    def test_add(self): 
    87         result = self.data2+self.data 
     92        result = self.data2 + self.data 
    8893        for i in range(5): 
    8994            self.assertEqual(result.y[i], 3.0) 
    90             self.assertEqual(result.dy[i], math.sqrt(0.5**2+1.0)) 
    91          
     95            self.assertEqual(result.dy[i], math.sqrt(0.5**2 + 1.0)) 
     96 
    9297    def test_sub(self): 
    93         result = self.data2-self.data 
     98        result = self.data2 - self.data 
    9499        for i in range(5): 
    95100            self.assertEqual(result.y[i], -1.0) 
    96             self.assertEqual(result.dy[i], math.sqrt(0.5**2+1.0)) 
    97          
     101            self.assertEqual(result.dy[i], math.sqrt(0.5**2 + 1.0)) 
     102 
    98103    def test_mul(self): 
    99         result = self.data2*self.data 
     104        result = self.data2 * self.data 
    100105        for i in range(5): 
    101106            self.assertEqual(result.y[i], 2.0) 
    102             self.assertEqual(result.dy[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 
    103          
     107            self.assertEqual(result.dy[i], math.sqrt( 
     108                (0.5 * 1.0)**2 + (1.0 * 2.0)**2)) 
     109 
    104110    def test_div(self): 
    105         result = self.data2/self.data 
     111        result = self.data2 / self.data 
    106112        for i in range(5): 
    107113            self.assertEqual(result.y[i], 0.5) 
    108             self.assertEqual(result.dy[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 
    109          
     114            self.assertEqual(result.dy[i], math.sqrt( 
     115                (1.0 / 2.0)**2 + (0.5 * 1.0 / 4.0)**2)) 
     116 
    110117    def test_radd(self): 
    111         result = self.data+3.0 
     118        result = self.data + 3.0 
    112119        for i in range(5): 
    113120            self.assertEqual(result.y[i], 5.0) 
    114121            self.assertEqual(result.dy[i], 0.5) 
    115              
    116         result = 3.0+self.data 
     122 
     123        result = 3.0 + self.data 
    117124        for i in range(5): 
    118125            self.assertEqual(result.y[i], 5.0) 
    119126            self.assertEqual(result.dy[i], 0.5) 
    120              
     127 
    121128    def test_rsub(self): 
    122         result = self.data-3.0 
     129        result = self.data - 3.0 
    123130        for i in range(5): 
    124131            self.assertEqual(result.y[i], -1.0) 
    125132            self.assertEqual(result.dy[i], 0.5) 
    126              
    127         result = 3.0-self.data 
     133 
     134        result = 3.0 - self.data 
    128135        for i in range(5): 
    129136            self.assertEqual(result.y[i], 1.0) 
    130137            self.assertEqual(result.dy[i], 0.5) 
    131              
     138 
    132139    def test_rmul(self): 
    133         result = self.data*3.0 
     140        result = self.data * 3.0 
    134141        for i in range(5): 
    135142            self.assertEqual(result.y[i], 6.0) 
    136143            self.assertEqual(result.dy[i], 1.5) 
    137              
    138         result = 3.0*self.data 
     144 
     145        result = 3.0 * self.data 
    139146        for i in range(5): 
    140147            self.assertEqual(result.y[i], 6.0) 
    141148            self.assertEqual(result.dy[i], 1.5) 
    142              
     149 
    143150    def test_rdiv(self): 
    144         result = self.data/4.0 
     151        result = self.data / 4.0 
    145152        for i in range(5): 
    146153            self.assertEqual(result.y[i], 0.5) 
    147154            self.assertEqual(result.dy[i], 0.125) 
    148              
    149         result = 6.0/self.data 
     155 
     156        result = 6.0 / self.data 
    150157        for i in range(5): 
    151158            self.assertEqual(result.y[i], 3.0) 
    152             self.assertEqual(result.dy[i], 6.0*0.5/4.0) 
    153              
    154 class manip_2D(unittest.TestCase): 
    155      
     159            self.assertEqual(result.dy[i], 6.0 * 0.5 / 4.0) 
     160 
     161 
     162class Manin2DTests(unittest.TestCase): 
     163 
    156164    def setUp(self): 
    157165        # Create two data sets to play with 
    158         x_0 = 2.0*np.ones(25) 
    159         dx_0 = 0.5*np.ones(25) 
     166        x_0 = 2.0 * np.ones(25) 
     167        dx_0 = 0.5 * np.ones(25) 
    160168        qx_0 = np.arange(25) 
    161169        qy_0 = np.arange(25) 
    162170        mask_0 = np.zeros(25) 
    163         dqx_0 = np.arange(25)/100 
    164         dqy_0 = np.arange(25)/100 
     171        dqx_0 = np.arange(25) / 100 
     172        dqy_0 = np.arange(25) / 100 
    165173        q_0 = np.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 
    166         self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0,  
    167                            qy_data=qy_0, q_data=q_0, mask=mask_0,  
     174        self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 
     175                           qy_data=qy_0, q_data=q_0, mask=mask_0, 
    168176                           dqx_data=dqx_0, dqy_data=dqy_0) 
    169          
     177 
    170178        y = np.ones(25) 
    171179        dy = np.ones(25) 
     
    174182        mask = np.zeros(25) 
    175183        q = np.sqrt(qx * qx + qy * qy) 
    176         self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy,  
     184        self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 
    177185                            q_data=q, mask=mask) 
    178          
    179          
     186 
    180187    def test_load(self): 
    181188        """ 
     
    184191        # There should be 5 entries in the file 
    185192        self.assertEqual(np.size(self.data.data), 25) 
    186          
     193 
    187194        for i in range(25): 
    188195            # All y-error values should be 0.5 
    189             self.assertEqual(self.data.err_data[i], 0.5)     
    190              
     196            self.assertEqual(self.data.err_data[i], 0.5) 
     197 
    191198            # All y values should be 2.0 
    192             self.assertEqual(self.data.data[i], 2.0)     
    193          
     199            self.assertEqual(self.data.data[i], 2.0) 
     200 
    194201    def test_add(self): 
    195         result = self.data2+self.data 
     202        result = self.data2 + self.data 
    196203        for i in range(25): 
    197204            self.assertEqual(result.data[i], 3.0) 
    198             self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 
    199          
     205            self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 
     206 
    200207    def test_sub(self): 
    201         result = self.data2-self.data 
    202         for i in range(25): 
    203                 self.assertEqual(result.data[i], -1.0) 
    204                 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 
    205          
     208        result = self.data2 - self.data 
     209        for i in range(25): 
     210            self.assertEqual(result.data[i], -1.0) 
     211            self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 
     212 
    206213    def test_mul(self): 
    207         result = self.data2*self.data 
     214        result = self.data2 * self.data 
    208215        for i in range(25): 
    209216            self.assertEqual(result.data[i], 2.0) 
    210             self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 
    211          
     217            self.assertEqual(result.err_data[i], math.sqrt( 
     218                (0.5 * 1.0)**2 + (1.0 * 2.0)**2)) 
     219 
    212220    def test_div(self): 
    213         result = self.data2/self.data 
     221        result = self.data2 / self.data 
    214222        for i in range(25): 
    215223            self.assertEqual(result.data[i], 0.5) 
    216             self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 
    217          
     224            self.assertEqual(result.err_data[i], math.sqrt( 
     225                (1.0 / 2.0)**2 + (0.5 * 1.0 / 4.0)**2)) 
     226 
    218227    def test_radd(self): 
    219         result = self.data+3.0 
     228        result = self.data + 3.0 
    220229        for i in range(25): 
    221230            self.assertEqual(result.data[i], 5.0) 
    222231            self.assertEqual(result.err_data[i], 0.5) 
    223     
    224         result = 3.0+self.data 
     232 
     233        result = 3.0 + self.data 
    225234        for i in range(25): 
    226235            self.assertEqual(result.data[i], 5.0) 
    227236            self.assertEqual(result.err_data[i], 0.5) 
    228              
     237 
    229238    def test_rsub(self): 
    230         result = self.data-3.0 
     239        result = self.data - 3.0 
    231240        for i in range(25): 
    232241            self.assertEqual(result.data[i], -1.0) 
    233242            self.assertEqual(result.err_data[i], 0.5) 
    234      
    235         result = 3.0-self.data 
     243 
     244        result = 3.0 - self.data 
    236245        for i in range(25): 
    237246            self.assertEqual(result.data[i], 1.0) 
    238247            self.assertEqual(result.err_data[i], 0.5) 
    239              
     248 
    240249    def test_rmul(self): 
    241         result = self.data*3.0 
     250        result = self.data * 3.0 
    242251        for i in range(25): 
    243252            self.assertEqual(result.data[i], 6.0) 
    244253            self.assertEqual(result.err_data[i], 1.5) 
    245   
    246         result = 3.0*self.data 
     254 
     255        result = 3.0 * self.data 
    247256        for i in range(25): 
    248257            self.assertEqual(result.data[i], 6.0) 
    249258            self.assertEqual(result.err_data[i], 1.5) 
    250              
     259 
    251260    def test_rdiv(self): 
    252         result = self.data/4.0 
     261        result = self.data / 4.0 
    253262        for i in range(25): 
    254263            self.assertEqual(result.data[i], 0.5) 
    255264            self.assertEqual(result.err_data[i], 0.125) 
    256265 
    257         result = 6.0/self.data 
     266        result = 6.0 / self.data 
    258267        for i in range(25): 
    259268            self.assertEqual(result.data[i], 3.0) 
    260             self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 
    261      
    262 class extra_manip_2D(unittest.TestCase): 
    263      
     269            self.assertEqual(result.err_data[i], 6.0 * 0.5 / 4.0) 
     270 
     271 
     272class ExtraManip2DTests(unittest.TestCase): 
     273 
    264274    def setUp(self): 
    265275        # Create two data sets to play with 
    266         x_0 = 2.0*np.ones(25) 
    267         dx_0 = 0.5*np.ones(25) 
     276        x_0 = 2.0 * np.ones(25) 
     277        dx_0 = 0.5 * np.ones(25) 
    268278        qx_0 = np.arange(25) 
    269279        qy_0 = np.arange(25) 
    270280        mask_0 = np.zeros(25) 
    271         dqx_0 = np.arange(25)/100 
    272         dqy_0 = np.arange(25)/100 
     281        dqx_0 = np.arange(25) / 100 
     282        dqy_0 = np.arange(25) / 100 
    273283        q_0 = np.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 
    274         self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0,  
    275                            qy_data=qy_0, q_data=q_0, mask=mask_0,  
     284        self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 
     285                           qy_data=qy_0, q_data=q_0, mask=mask_0, 
    276286                           dqx_data=dqx_0, dqy_data=dqy_0) 
    277          
     287 
    278288        y = np.ones(25) 
    279289        dy = np.ones(25) 
     
    282292        mask = np.zeros(25) 
    283293        q = np.sqrt(qx * qx + qy * qy) 
    284         self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy,  
     294        self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 
    285295                            q_data=q, mask=mask) 
    286          
    287          
     296 
    288297    def test_load(self): 
    289298        """ 
     
    292301        # There should be 5 entries in the file 
    293302        self.assertEqual(np.size(self.data.data), 25) 
    294          
     303 
    295304        for i in range(25): 
    296305            # All y-error values should be 0.5 
    297             self.assertEqual(self.data.err_data[i], 0.5)     
    298              
     306            self.assertEqual(self.data.err_data[i], 0.5) 
     307 
    299308            # All y values should be 2.0 
    300             self.assertEqual(self.data.data[i], 2.0)     
    301          
     309            self.assertEqual(self.data.data[i], 2.0) 
     310 
    302311    def test_add(self): 
    303         result = self.data2+self.data 
     312        result = self.data2 + self.data 
    304313        for i in range(25): 
    305314            self.assertEqual(result.data[i], 3.0) 
    306             self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 
    307          
     315            self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 
     316 
    308317    def test_sub(self): 
    309         result = self.data2-self.data 
    310         for i in range(25): 
    311                 self.assertEqual(result.data[i], -1.0) 
    312                 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 
    313          
     318        result = self.data2 - self.data 
     319        for i in range(25): 
     320            self.assertEqual(result.data[i], -1.0) 
     321            self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 
     322 
    314323    def test_mul(self): 
    315         result = self.data2*self.data 
     324        result = self.data2 * self.data 
    316325        for i in range(25): 
    317326            self.assertEqual(result.data[i], 2.0) 
    318             self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 
    319          
     327            self.assertEqual(result.err_data[i], math.sqrt( 
     328                (0.5 * 1.0)**2 + (1.0 * 2.0)**2)) 
     329 
    320330    def test_div(self): 
    321         result = self.data2/self.data 
     331        result = self.data2 / self.data 
    322332        for i in range(25): 
    323333            self.assertEqual(result.data[i], 0.5) 
    324             self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 
    325          
     334            self.assertEqual(result.err_data[i], math.sqrt( 
     335                (1.0 / 2.0)**2 + (0.5 * 1.0 / 4.0)**2)) 
     336 
    326337    def test_radd(self): 
    327         result = self.data+3.0 
     338        result = self.data + 3.0 
    328339        for i in range(25): 
    329340            self.assertEqual(result.data[i], 5.0) 
    330341            self.assertEqual(result.err_data[i], 0.5) 
    331     
    332         result = 3.0+self.data 
     342 
     343        result = 3.0 + self.data 
    333344        for i in range(25): 
    334345            self.assertEqual(result.data[i], 5.0) 
    335346            self.assertEqual(result.err_data[i], 0.5) 
    336              
     347 
    337348    def test_rsub(self): 
    338         result = self.data-3.0 
     349        result = self.data - 3.0 
    339350        for i in range(25): 
    340351            self.assertEqual(result.data[i], -1.0) 
    341352            self.assertEqual(result.err_data[i], 0.5) 
    342      
    343         result = 3.0-self.data 
     353 
     354        result = 3.0 - self.data 
    344355        for i in range(25): 
    345356            self.assertEqual(result.data[i], 1.0) 
    346357            self.assertEqual(result.err_data[i], 0.5) 
    347              
     358 
    348359    def test_rmul(self): 
    349         result = self.data*3.0 
     360        result = self.data * 3.0 
    350361        for i in range(25): 
    351362            self.assertEqual(result.data[i], 6.0) 
    352363            self.assertEqual(result.err_data[i], 1.5) 
    353   
    354         result = 3.0*self.data 
     364 
     365        result = 3.0 * self.data 
    355366        for i in range(25): 
    356367            self.assertEqual(result.data[i], 6.0) 
    357368            self.assertEqual(result.err_data[i], 1.5) 
    358              
     369 
    359370    def test_rdiv(self): 
    360         result = self.data/4.0 
     371        result = self.data / 4.0 
    361372        for i in range(25): 
    362373            self.assertEqual(result.data[i], 0.5) 
    363374            self.assertEqual(result.err_data[i], 0.125) 
    364375 
    365         result = 6.0/self.data 
     376        result = 6.0 / self.data 
    366377        for i in range(25): 
    367378            self.assertEqual(result.data[i], 3.0) 
    368             self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 
     379            self.assertEqual(result.err_data[i], 6.0 * 0.5 / 4.0) 
     380 
    369381 
    370382if __name__ == '__main__': 
    371383    unittest.main() 
    372     
Note: See TracChangeset for help on using the changeset viewer.