Changeset 5a8cdbb in sasview for test


Ignore:
Timestamp:
Aug 1, 2017 12:02:35 PM (7 years ago)
Author:
lewis
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:
511ccb2d
Parents:
248ff73 (diff), bc04647 (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 ticket-876

Location:
test
Files:
28 added
3 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • test/fileconverter/test/utest_nxcansas_writer.py

    r248ff73 r5a8cdbb  
    6262        if os.path.isfile(self.write_file_1d): 
    6363            os.remove(self.write_file_1d) 
     64        if os.path.isfile(self.write_file_2d): 
     65            os.remove(self.write_file_2d) 
  • test/pr_inversion/test/utest_invertor.py

    rac07a3a raaf5e49  
    66# Disable "too many methods" complaint  
    77# pylint: disable-msg=R0904  
    8  
    9  
    10 import unittest, math, numpy 
     8from __future__ import print_function 
     9 
     10 
     11import os 
     12import unittest 
     13import math 
     14import numpy 
    1115from sas.sascalc.pr.invertor import Invertor 
    12          
     16 
     17 
    1318class TestFiguresOfMerit(unittest.TestCase): 
    1419             
     
    235240            self.assertTrue(chi2/51.0<10.0) 
    236241        except: 
    237             print "chi2 =", chi2/51.0 
     242            print("chi2 =", chi2/51.0) 
    238243            raise 
    239244         
     
    263268            self.assertTrue(self.invertor.chi2/len(x)<200.00) 
    264269        except: 
    265             print "Chi2(I(q)) =", self.invertor.chi2/len(x) 
     270            print("Chi2(I(q)) =", self.invertor.chi2/len(x)) 
    266271            raise 
    267272         
     
    297302            self.assertTrue(chi2/51.0<50.0) 
    298303        except: 
    299             print "chi2(P(r)) =", chi2/51.0 
     304            print("chi2(P(r)) =", chi2/51.0) 
    300305            raise 
    301306         
     
    341346            self.assertTrue(self.invertor.chi2>0) 
    342347        except: 
    343             print "Chi2 =", self.invertor.chi2 
     348            print("Chi2 =", self.invertor.chi2) 
    344349            raise 
    345350                             
     
    365370            self.assertTrue(self.invertor.chi2>0) 
    366371        except: 
    367             print "Chi2 =", self.invertor.chi2 
     372            print("Chi2 =", self.invertor.chi2) 
    368373            raise 
    369374         
     
    416421         
    417422        # Save 
    418         self.invertor.to_file("test_output.txt") 
     423        f_name = "test_output.txt" 
     424        self.invertor.to_file(f_name) 
    419425     
    420426        # Load 
    421         self.invertor.from_file("test_output.txt") 
     427        self.invertor.from_file(f_name) 
    422428        self.assertEqual(self.invertor.d_max, 160.0) 
    423429        self.assertEqual(self.invertor.alpha, 0.0007) 
    424430        self.assertEqual(self.invertor.chi2, 836.797) 
    425431        self.assertAlmostEqual(self.invertor.pr(self.invertor.out, 10.0), 903.31577041, 4) 
     432        if os.path.isfile(f_name): 
     433            os.remove(f_name) 
    426434         
    427435    def test_qmin(self): 
  • test/run_one.py

    raaad4c95 raaf5e49  
    11#!/usr/bin/env python 
     2from __future__ import print_function 
    23 
    34import os 
     
    2425#print "\n".join(sys.path) 
    2526test_path,test_file = splitpath(abspath(sys.argv[1])) 
    26 print "=== testing:",sys.argv[1] 
     27print("=== testing:",sys.argv[1]) 
    2728#print test_path, test_file 
    2829sys.argv = [sys.argv[0]] 
  • test/sasdataloader/plugins/test_reader.py

    r959eb01 raaf5e49  
    88copyright 2008, University of Tennessee 
    99""" 
     10from __future__ import print_function 
     11 
    1012import os 
    1113import numpy as np 
     
    5961    reader = Reader() 
    6062    output = reader.read("../test/test_data.test") 
    61     print output.x 
     63    print(output.x) 
    6264     
    6365     
  • test/sasdataloader/test/sequence_tests.py

    r959eb01 raaf5e49  
     1from __future__ import print_function 
     2 
    13from DataLoader.loader import Loader 
    24from DataLoader.readers.IgorReader import Reader as igor_reader 
     
    810    out2 = Loader().load("MAR07232_rest.ASC") 
    911    if len(out2.detector)>1: 
    10         print "Consecutive reads using Loader failed" 
     12        print("Consecutive reads using Loader failed") 
    1113 
    1214def consecutive_reader(): 
     
    1416    out2 = igor_reader().read("MAR07232_rest.ASC") 
    1517    if len(out2.detector)>1: 
    16         print "Consecutive reads using Readers failed" 
    17         print out1 
    18         print out2 
     18        print("Consecutive reads using Readers failed") 
     19        print(out1) 
     20        print(out2) 
    1921 
    2022def single_abs(): 
     
    2931    single_igor() 
    3032    single_abs() 
    31     print "Test passed" 
     33    print("Test passed") 
  • test/sasdataloader/test/testplugings.py

    r959eb01 r17c9436  
    33""" 
    44 
     5import os 
    56import unittest 
    67from sas.sascalc.dataloader.loader import  Loader, Registry 
     
    4142        # Create module 
    4243        import zipfile 
    43         z = zipfile.PyZipFile("plugins.zip", 'w') 
     44        f_name = "plugins.zip" 
     45        z = zipfile.PyZipFile(f_name, 'w') 
    4446        z.writepy("../plugins", "") 
    4547        z.close() 
     48        if os.path.isfile(f_name): 
     49            os.remove(f_name) 
    4650         
    4751    def testplugin_checksetup(self): 
  • test/sasdataloader/test/utest_abs_reader.py

    r371b9e2 r5a8cdbb  
    22    Unit tests for data manipulations 
    33""" 
     4from __future__ import print_function 
    45 
    56import unittest 
     
    78from sas.sascalc.dataloader.loader import Loader 
    89from sas.sascalc.dataloader.readers.IgorReader import Reader as IgorReader 
    9 from sas.sascalc.dataloader.readers.abs_reader import Reader as ABSReader 
    10  
    11  
    12 class ABSReaderTests(unittest.TestCase): 
    13      
     10from sas.sascalc.dataloader.readers.abs_reader import Reader as AbsReader 
     11from sas.sascalc.dataloader.readers.hfir1d_reader import Reader as HFIRReader 
     12from sas.sascalc.dataloader.readers.danse_reader import Reader as DANSEReader 
     13from sas.sascalc.dataloader.readers.cansas_reader import Reader as CANSASReader 
     14 
     15from sas.sascalc.dataloader.data_info import Data1D 
     16 
     17import os.path 
     18 
     19 
     20class abs_reader(unittest.TestCase): 
     21 
    1422    def setUp(self): 
    15         self.data_list = ABSReader().read("jan08002.ABS") 
    16         self.data = self.data_list[0] 
    17          
     23        reader = AbsReader() 
     24        self.data = reader.read("jan08002.ABS") 
     25 
    1826    def test_abs_checkdata(self): 
    1927        """ 
    20             Check the data content to see whether  
     28            Check the data content to see whether 
    2129            it matches the specific file we loaded. 
    2230            Check the units too to see whether the 
     
    2634        self.assertEqual(self.data.filename, "jan08002.ABS") 
    2735        self.assertEqual(self.data.meta_data['loader'], "IGOR 1D") 
    28          
     36 
    2937        self.assertEqual(self.data.source.wavelength_unit, 'A') 
    3038        self.assertEqual(self.data.source.wavelength, 6.0) 
    31          
     39 
    3240        self.assertEqual(self.data.detector[0].distance_unit, 'mm') 
    3341        self.assertEqual(self.data.detector[0].distance, 1000.0) 
    34          
     42 
    3543        self.assertEqual(self.data.sample.transmission, 0.5667) 
    36          
     44 
    3745        self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') 
    3846        center_x = 114.58*5.08 
     
    4048        self.assertEqual(self.data.detector[0].beam_center.x, center_x) 
    4149        self.assertEqual(self.data.detector[0].beam_center.y, center_y) 
    42          
     50 
    4351        self.assertEqual(self.data.y_unit, '1/cm') 
    4452        self.assertEqual(self.data.x[0], 0.002618) 
     
    4654        self.assertEqual(self.data.x[2], 0.01309) 
    4755        self.assertEqual(self.data.x[126], 0.5828) 
    48          
     56 
    4957        self.assertEqual(self.data.y[0], 0.02198) 
    5058        self.assertEqual(self.data.y[1], 0.02201) 
    5159        self.assertEqual(self.data.y[2], 0.02695) 
    5260        self.assertEqual(self.data.y[126], 0.2958) 
    53          
     61 
    5462        self.assertEqual(self.data.dy[0], 0.002704) 
    5563        self.assertEqual(self.data.dy[1], 0.001643) 
    5664        self.assertEqual(self.data.dy[2], 0.002452) 
    5765        self.assertEqual(self.data.dy[126], 1) 
    58          
     66 
    5967    def test_checkdata2(self): 
    6068        self.assertEqual(self.data.dy[126], 1) 
    6169 
    62  
    63 class HFIRReaderTests(unittest.TestCase): 
     70    def test_generic_loader(self): 
     71        # the generic loader should work as well 
     72        data = Loader().load("jan08002.ABS") 
     73        self.assertEqual(data.meta_data['loader'], "IGOR 1D") 
     74 
     75 
     76class hfir_reader(unittest.TestCase): 
    6477 
    6578    def setUp(self): 
    66         self.data = Loader().load("S2-30dq.d1d") 
     79        reader = HFIRReader() 
     80        self.data = reader.read("S2-30dq.d1d") 
    6781 
    6882    def test_hfir_checkdata(self): 
    6983        """ 
    70             Check the data content to see whether  
     84            Check the data content to see whether 
    7185            it matches the specific file we loaded. 
    7286        """ 
     
    7690        self.assertEqual(len(self.data.x), 134) 
    7791        self.assertEqual(len(self.data.y), 134) 
    78         #          Q           I               dI          dQ   
     92        #          Q           I               dI          dQ 
    7993        # Point 1: 0.003014    0.003010        0.000315    0.008249 
    8094        self.assertEqual(self.data.x[1], 0.003014) 
     
    8397        self.assertEqual(self.data.dx[1], 0.008249) 
    8498 
    85  
    86 class DanseReaderTests(unittest.TestCase): 
    87      
     99    def test_generic_loader(self): 
     100        # the generic loader should work as well 
     101        data = Loader().load("S2-30dq.d1d") 
     102        self.assertEqual(data.meta_data['loader'], "HFIR 1D") 
     103 
     104 
     105class igor_reader(unittest.TestCase): 
     106 
    88107    def setUp(self): 
    89         self.data = Loader().load("MP_New.sans") 
    90  
    91     def test_checkdata(self): 
    92         """ 
    93             Check the data content to see whether  
     108        # the IgorReader should be able to read this filetype 
     109        # if it can't, stop here. 
     110        reader = IgorReader() 
     111        self.data = reader.read("MAR07232_rest.ASC") 
     112 
     113    def test_igor_checkdata(self): 
     114        """ 
     115            Check the data content to see whether 
    94116            it matches the specific file we loaded. 
    95117            Check the units too to see whether the 
     
    97119            tests won't pass 
    98120        """ 
     121        self.assertEqual(self.data.filename, "MAR07232_rest.ASC") 
     122        self.assertEqual(self.data.meta_data['loader'], "IGOR 2D") 
     123 
     124        self.assertEqual(self.data.source.wavelength_unit, 'A') 
     125        self.assertEqual(self.data.source.wavelength, 8.4) 
     126 
     127        self.assertEqual(self.data.detector[0].distance_unit, 'mm') 
     128        self.assertEqual(self.data.detector[0].distance, 13705) 
     129 
     130        self.assertEqual(self.data.sample.transmission, 0.84357) 
     131 
     132        self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') 
     133        center_x = (68.76 - 1)*5.0 
     134        center_y = (62.47 - 1)*5.0 
     135        self.assertEqual(self.data.detector[0].beam_center.x, center_x) 
     136        self.assertEqual(self.data.detector[0].beam_center.y, center_y) 
     137 
     138        self.assertEqual(self.data.I_unit, '1/cm') 
     139        # 3 points should be suffcient to check that the data is in column 
     140        # major order. 
     141        np.testing.assert_almost_equal(self.data.data[0:3], 
     142                                       [0.279783, 0.28951, 0.167634]) 
     143        np.testing.assert_almost_equal(self.data.qx_data[0:3], 
     144                                       [-0.01849072, -0.01821785, -0.01794498]) 
     145        np.testing.assert_almost_equal(self.data.qy_data[0:3], 
     146                                       [-0.01677435, -0.01677435, -0.01677435]) 
     147 
     148    def test_generic_loader(self): 
     149        # the generic loader should direct the file to IgorReader as well 
     150        data = Loader().load("MAR07232_rest.ASC") 
     151        self.assertEqual(data.meta_data['loader'], "IGOR 2D") 
     152 
     153 
     154class DanseReaderTests(unittest.TestCase): 
     155 
     156    def setUp(self): 
     157        reader = DANSEReader() 
     158        self.data = reader.read("MP_New.sans") 
     159 
     160    def test_checkdata(self): 
     161        """ 
     162            Check the data content to see whether 
     163            it matches the specific file we loaded. 
     164            Check the units too to see whether the 
     165            Data1D defaults changed. Otherwise the 
     166            tests won't pass 
     167        """ 
    99168        self.assertEqual(self.data.filename, "MP_New.sans") 
    100169        self.assertEqual(self.data.meta_data['loader'], "DANSE") 
    101          
     170 
    102171        self.assertEqual(self.data.source.wavelength_unit, 'A') 
    103172        self.assertEqual(self.data.source.wavelength, 7.5) 
    104          
     173 
    105174        self.assertEqual(self.data.detector[0].distance_unit, 'mm') 
    106175        self.assertAlmostEqual(self.data.detector[0].distance, 5414.99, 3) 
    107          
     176 
    108177        self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') 
    109178        center_x = 68.74*5.0 
     
    111180        self.assertEqual(self.data.detector[0].beam_center.x, center_x) 
    112181        self.assertEqual(self.data.detector[0].beam_center.y, center_y) 
    113          
     182 
    114183        self.assertEqual(self.data.I_unit, '1/cm') 
    115184        self.assertEqual(self.data.data[0], 1.57831) 
     
    121190        self.assertEqual(self.data.err_data[2], 2.06313) 
    122191 
    123   
     192    def test_generic_loader(self): 
     193        # the generic loader should work as well 
     194        data = Loader().load("MP_New.sans") 
     195        self.assertEqual(data.meta_data['loader'], "DANSE") 
     196 
     197 
    124198class cansas_reader(unittest.TestCase): 
    125      
     199 
    126200    def setUp(self): 
     201        reader = CANSASReader() 
     202        data = reader.read("cansas1d.xml") 
     203        self.data = data[0] 
     204 
     205    def test_generic_loader(self): 
     206        # the generic loader should work as well 
    127207        data = Loader().load("cansas1d.xml") 
    128         self.data = data[0] 
    129   
     208        self.assertEqual(data[0].meta_data['loader'], "CanSAS XML 1D") 
     209 
    130210    def test_cansas_checkdata(self): 
    131211        self.assertEqual(self.data.filename, "cansas1d.xml") 
    132212        self._checkdata() 
    133          
     213 
    134214    def _checkdata(self): 
    135215        """ 
    136             Check the data content to see whether  
     216            Check the data content to see whether 
    137217            it matches the specific file we loaded. 
    138218            Check the units too to see whether the 
     
    140220            tests won't pass 
    141221        """ 
    142          
    143222        self.assertEqual(self.data.run[0], "1234") 
    144223        self.assertEqual(self.data.meta_data['loader'], "CanSAS XML 1D") 
    145          
     224 
    146225        # Data 
    147226        self.assertEqual(len(self.data.x), 2) 
     
    158237        self.assertEqual(self.data.run_name['1234'], 'run name') 
    159238        self.assertEqual(self.data.title, "Test title") 
    160          
     239 
    161240        # Sample info 
    162241        self.assertEqual(self.data.sample.ID, "SI600-new-long") 
     
    164243        self.assertEqual(self.data.sample.thickness_unit, 'mm') 
    165244        self.assertAlmostEqual(self.data.sample.thickness, 1.03) 
    166          
     245 
    167246        self.assertAlmostEqual(self.data.sample.transmission, 0.327) 
    168          
     247 
    169248        self.assertEqual(self.data.sample.temperature_unit, 'C') 
    170249        self.assertEqual(self.data.sample.temperature, 0) 
     
    178257        self.assertAlmostEqual(self.data.sample.orientation.y, 0.02, 6) 
    179258 
    180         self.assertEqual(self.data.sample.details[0], "http://chemtools.chem.soton.ac.uk/projects/blog/blogs.php/bit_id/2720")  
    181         self.assertEqual(self.data.sample.details[1], "Some text here")  
    182          
     259        self.assertEqual(self.data.sample.details[0], "http://chemtools.chem.soton.ac.uk/projects/blog/blogs.php/bit_id/2720") 
     260        self.assertEqual(self.data.sample.details[1], "Some text here") 
     261 
    183262        # Instrument info 
    184263        self.assertEqual(self.data.instrument, "canSAS instrument") 
    185          
     264 
    186265        # Source 
    187266        self.assertEqual(self.data.source.radiation, "neutron") 
    188          
     267 
    189268        self.assertEqual(self.data.source.beam_size_unit, "mm") 
    190269        self.assertEqual(self.data.source.beam_size_name, "bm") 
    191270        self.assertEqual(self.data.source.beam_size.x, 12) 
    192271        self.assertEqual(self.data.source.beam_size.y, 13) 
    193          
     272 
    194273        self.assertEqual(self.data.source.beam_shape, "disc") 
    195          
     274 
    196275        self.assertEqual(self.data.source.wavelength_unit, "A") 
    197276        self.assertEqual(self.data.source.wavelength, 6) 
    198          
     277 
    199278        self.assertEqual(self.data.source.wavelength_max_unit, "nm") 
    200279        self.assertAlmostEqual(self.data.source.wavelength_max, 1.0) 
     
    203282        self.assertEqual(self.data.source.wavelength_spread_unit, "percent") 
    204283        self.assertEqual(self.data.source.wavelength_spread, 14.3) 
    205          
     284 
    206285        # Collimation 
    207286        _found1 = False 
     
    209288        self.assertEqual(self.data.collimation[0].length, 123.) 
    210289        self.assertEqual(self.data.collimation[0].name, 'test coll name') 
    211          
     290 
    212291        for item in self.data.collimation[0].aperture: 
    213292            self.assertEqual(item.size_unit,'mm') 
    214293            self.assertEqual(item.distance_unit,'mm') 
    215294 
    216             if item.size.x==50 \ 
    217                 and item.distance==11000.0 \ 
    218                 and item.name=='source' \ 
    219                 and item.type=='radius': 
     295            if item.size.x == 50 \ 
     296                and item.distance == 11000.0 \ 
     297                and item.name == 'source' \ 
     298                and item.type == 'radius': 
    220299                _found1 = True 
    221             elif item.size.x==1.0 \ 
    222                 and item.name=='sample' \ 
    223                 and item.type=='radius': 
     300            elif item.size.x == 1.0 \ 
     301                and item.name == 'sample' \ 
     302                and item.type == 'radius': 
    224303                _found2 = True 
    225                  
    226         if _found1==False or _found2==False: 
    227             raise RuntimeError, "Could not find all data %s %s" % (_found1, _found2)  
    228              
     304 
     305        if _found1 == False or _found2 == False: 
     306            raise RuntimeError, "Could not find all data %s %s" % (_found1, _found2) 
     307 
    229308        # Detector 
    230309        self.assertEqual(self.data.detector[0].name, "fictional hybrid") 
    231310        self.assertEqual(self.data.detector[0].distance_unit, "mm") 
    232311        self.assertEqual(self.data.detector[0].distance, 4150) 
    233          
     312 
    234313        self.assertEqual(self.data.detector[0].orientation_unit, "degree") 
    235314        self.assertAlmostEqual(self.data.detector[0].orientation.x, 1.0, 6) 
    236315        self.assertEqual(self.data.detector[0].orientation.y, 0.0) 
    237316        self.assertEqual(self.data.detector[0].orientation.z, 0.0) 
    238          
     317 
    239318        self.assertEqual(self.data.detector[0].offset_unit, "m") 
    240319        self.assertEqual(self.data.detector[0].offset.x, .001) 
    241320        self.assertEqual(self.data.detector[0].offset.y, .002) 
    242321        self.assertEqual(self.data.detector[0].offset.z, None) 
    243          
     322 
    244323        self.assertEqual(self.data.detector[0].beam_center_unit, "mm") 
    245324        self.assertEqual(self.data.detector[0].beam_center.x, 322.64) 
    246325        self.assertEqual(self.data.detector[0].beam_center.y, 327.68) 
    247326        self.assertEqual(self.data.detector[0].beam_center.z, None) 
    248          
     327 
    249328        self.assertEqual(self.data.detector[0].pixel_size_unit, "mm") 
    250329        self.assertEqual(self.data.detector[0].pixel_size.x, 5) 
    251330        self.assertEqual(self.data.detector[0].pixel_size.y, 5) 
    252331        self.assertEqual(self.data.detector[0].pixel_size.z, None) 
    253          
     332 
    254333        # Process 
    255334        _found_term1 = False 
     
    259338            self.assertTrue(item.date in ['04-Sep-2007 18:35:02', 
    260339                                          '03-SEP-2006 11:42:47']) 
    261             print item.term 
     340            print(item.term) 
    262341            for t in item.term: 
    263                 if t['name']=="ABS:DSTAND" \ 
    264                     and t['unit']=='mm' \ 
    265                     and float(t['value'])==1.0: 
     342                if (t['name'] == "ABS:DSTAND" 
     343                    and t['unit'] == 'mm' 
     344                    and float(t['value']) == 1.0): 
    266345                    _found_term2 = True 
    267                 elif t['name']=="radialstep" \ 
    268                     and t['unit']=='mm' \ 
    269                     and float(t['value'])==10.0: 
     346                elif (t['name'] == "radialstep" 
     347                      and t['unit'] == 'mm' 
     348                      and float(t['value']) == 10.0): 
    270349                    _found_term1 = True 
    271                      
    272         if _found_term1==False or _found_term2==False: 
     350 
     351        if _found_term1 == False or _found_term2 == False: 
    273352            raise RuntimeError, "Could not find all process terms %s %s" % (_found_term1, _found_term2) 
    274353 
    275354    def test_writer(self): 
    276         from sas.sascalc.dataloader.readers.cansas_reader import Reader 
    277         r = Reader() 
    278         x = np.ones(5) 
    279         y = np.ones(5) 
    280         dy = np.ones(5) 
    281          
     355        r = CANSASReader() 
     356 
    282357        filename = "write_test.xml" 
    283358        r.write(filename, self.data) 
     
    286361        self.assertEqual(self.data.filename, filename) 
    287362        self._checkdata() 
     363        if os.path.isfile(filename): 
     364            os.remove(filename) 
    288365 
    289366    def test_units(self): 
     
    293370        """ 
    294371        filename = "cansas1d_units.xml" 
    295         data = Loader().load(filename) 
     372        data = CANSASReader().read(filename) 
    296373        self.data = data[0] 
    297374        self.assertEqual(self.data.filename, filename) 
     
    304381        """ 
    305382        filename = "cansas1d_badunits.xml" 
    306         data = Loader().load(filename) 
     383        data = CANSASReader().read(filename) 
    307384        self.data = data[0] 
    308385        self.assertEqual(self.data.filename, filename) 
     
    311388        # This one should 
    312389        self.assertAlmostEqual(self.data.sample.transmission, 0.327) 
    313          
     390 
    314391        self.assertEqual(self.data.meta_data['loader'], "CanSAS XML 1D") 
    315         print self.data.errors 
     392        print(self.data.errors) 
    316393        self.assertEqual(len(self.data.errors), 1) 
    317394 
     
    321398        """ 
    322399        filename = "cansas1d_slit.xml" 
    323         data = Loader().load(filename) 
     400        data = CANSASReader().read(filename) 
    324401        self.data = data[0] 
    325402        self.assertEqual(self.data.filename, filename) 
    326403        self.assertEqual(self.data.run[0], "1234") 
    327          
     404 
    328405        # Data 
    329406        self.assertEqual(len(self.data.x), 2) 
  • test/sasdataloader/test/utest_averaging.py

    r8ffafd1 r5a8cdbb  
    11 
    22import math 
     3import os 
    34import unittest 
     5from scipy.stats import binned_statistic_2d 
    46import numpy as np 
     7 
    58import sas.sascalc.dataloader.data_info as data_info 
    69from sas.sascalc.dataloader.loader import Loader 
    7 from sas.sascalc.dataloader.manipulations import Boxsum, Boxavg, Ring, get_q,\ 
    8     CircularAverage, SectorPhi, SectorQ, reader2D_converter, SlabX, SlabY 
     10from sas.sascalc.dataloader.manipulations import (Boxavg, Boxsum, 
     11                                                  CircularAverage, Ring, 
     12                                                  SectorPhi, SectorQ, SlabX, 
     13                                                  SlabY, get_q, 
     14                                                  reader2D_converter) 
    915 
    1016 
     
    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]) 
     27        x_0 = np.ones([100, 100]) 
     28        dx_0 = np.ones([100, 100]) 
    2229 
    2330        self.data = data_info.Data2D(data=x_0, err_data=dx_0) 
    2431        detector = data_info.Detector() 
    2532        detector.distance = 1000.0  # mm 
    26         detector.pixel_size.x = 1.0 # mm 
    27         detector.pixel_size.y = 1.0 # mm 
     33        detector.pixel_size.x = 1.0  # mm 
     34        detector.pixel_size.y = 1.0  # mm 
    2835 
    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 
    3744 
    38         # get_q(dx, dy, det_dist, wavelength) where units are mm, mm, mm, and A 
     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        self.qmax = get_q(49.5, 49.5, detector.distance, source.wavelength) 
    4149 
    4250        self.qstep = len(x_0) 
    43         x=  np.linspace(start= -1*self.qmax, 
    44                                stop= self.qmax, 
    45                                num= self.qstep, 
    46                                endpoint=True )   
    47         y = np.linspace(start= -1*self.qmax, 
    48                                stop= self.qmax, 
    49                                num= self.qstep, 
    50                                endpoint=True ) 
    51         self.data.x_bins=x 
    52         self.data.y_bins=y 
     51        x = np.linspace(start=-1 * self.qmax, 
     52                        stop=self.qmax, 
     53                        num=self.qstep, 
     54                        endpoint=True) 
     55        y = np.linspace(start=-1 * self.qmax, 
     56                        stop=self.qmax, 
     57                        num=self.qstep, 
     58                        endpoint=True) 
     59        self.data.x_bins = x 
     60        self.data.y_bins = y 
    5361        self.data = reader2D_converter(self.data) 
    5462 
     
    5765            Test ring averaging 
    5866        """ 
    59         r = Ring(r_min=2*self.qmin, r_max=5*self.qmin,  
    60                  center_x=self.data.detector[0].beam_center.x,  
     67        r = Ring(r_min=2 * self.qmin, r_max=5 * self.qmin, 
     68                 center_x=self.data.detector[0].beam_center.x, 
    6169                 center_y=self.data.detector[0].beam_center.y) 
    6270        r.nbins_phi = 20 
     
    7078            Test sector averaging 
    7179        """ 
    72         r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin,  
    73                       phi_min=0, phi_max=math.pi*2.0) 
     80        r = SectorPhi(r_min=self.qmin, r_max=3 * self.qmin, 
     81                      phi_min=0, phi_max=math.pi * 2.0) 
    7482        r.nbins_phi = 20 
    7583        o = r(self.data) 
     
    8189        """ 
    8290        phi_max = math.pi * 1.5 
    83         r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin,  
     91        r = SectorPhi(r_min=self.qmin, r_max=3 * self.qmin, 
    8492                      phi_min=0, phi_max=phi_max) 
    8593        self.assertEqual(r.phi_max, phi_max) 
     
    94102 
    95103    def setUp(self): 
    96         self.data = Loader().load('MAR07232_rest.ASC') 
     104        filepath = os.path.join(os.path.dirname( 
     105            os.path.realpath(__file__)), 'MAR07232_rest.ASC') 
     106        self.data = Loader().load(filepath) 
    97107 
    98108    def test_ring(self): 
     
    100110            Test ring averaging 
    101111        """ 
    102         r = Ring(r_min=.005, r_max=.01,  
    103                  center_x=self.data.detector[0].beam_center.x,  
     112        r = Ring(r_min=.005, r_max=.01, 
     113                 center_x=self.data.detector[0].beam_center.x, 
    104114                 center_y=self.data.detector[0].beam_center.y, 
    105                  nbins = 20) 
    106         # r.nbins_phi = 20 
    107  
    108         o = r(self.data) 
    109         data_list = Loader().load('ring_testdata.txt') 
    110         answer = data_list[0] 
     115                 nbins=20) 
     116        ##r.nbins_phi = 20 
     117 
     118        o = r(self.data) 
     119        filepath = os.path.join(os.path.dirname( 
     120            os.path.realpath(__file__)), 'ring_testdata.txt') 
     121        answer = Loader().load(filepath) 
    111122 
    112123        for i in range(r.nbins_phi - 1): 
     
    115126            self.assertAlmostEqual(o.dy[i + 1], answer.dy[i], 4) 
    116127 
    117     def test_circular_avg(self): 
     128    def test_circularavg(self): 
     129        """ 
     130        Test circular averaging 
     131        The test data was not generated by IGOR. 
     132        """ 
     133        r = CircularAverage(r_min=.00, r_max=.025, 
     134                            bin_width=0.0003) 
     135        r.nbins_phi = 20 
     136 
     137        o = r(self.data) 
     138 
     139        filepath = os.path.join(os.path.dirname( 
     140            os.path.realpath(__file__)), 'avg_testdata.txt') 
     141        answer = Loader().load(filepath) 
     142        for i in range(r.nbins_phi): 
     143            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     144            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     145            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     146 
     147    def test_box(self): 
    118148        """ 
    119149            Test circular averaging 
    120150            The test data was not generated by IGOR. 
    121151        """ 
    122         r = CircularAverage(r_min=.00, r_max=.025,  
    123                  bin_width=0.0003) 
    124         r.nbins_phi = 20 
    125         o = r(self.data) 
    126  
    127         output = Loader().load('avg_testdata.txt') 
    128         answer = output[0] 
    129         for i in range(r.nbins_phi): 
    130             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    131             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    132             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    133  
    134     def test_box(self): 
    135         """ 
    136             Test circular averaging 
    137             The test data was not generated by IGOR. 
    138         """ 
     152 
    139153        r = Boxsum(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 
    140154        s, ds, npoints = r(self.data) 
    141155        self.assertAlmostEqual(s, 34.278990899999997, 4) 
    142156        self.assertAlmostEqual(ds, 7.8007981835194293, 4) 
    143         self.assertAlmostEqual(npoints, 324.0000, 4)         
     157        self.assertAlmostEqual(npoints, 324.0000, 4) 
    144158 
    145159        r = Boxavg(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 
     
    153167            The test data was not generated by IGOR. 
    154168        """ 
    155         r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, y_max=0.0002, bin_width=0.0004) 
     169 
     170        r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, 
     171                  y_max=0.0002, bin_width=0.0004) 
    156172        r.fold = False 
    157173        o = r(self.data) 
    158174 
    159         output = Loader().load('slabx_testdata.txt') 
    160         answer = output[0] 
     175        filepath = os.path.join(os.path.dirname( 
     176            os.path.realpath(__file__)), 'slabx_testdata.txt') 
     177        answer = Loader().load(filepath) 
    161178        for i in range(len(o.x)): 
    162179            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     
    169186            The test data was not generated by IGOR. 
    170187        """ 
    171         r = SlabY(x_min=.005, x_max=.01, y_min=-0.01, y_max=0.01, bin_width=0.0004) 
     188 
     189        r = SlabY(x_min=.005, x_max=.01, y_min=- 
     190                  0.01, y_max=0.01, bin_width=0.0004) 
    172191        r.fold = False 
    173192        o = r(self.data) 
    174193 
    175         output = Loader().load('slaby_testdata.txt') 
    176         answer = output[0] 
     194        filepath = os.path.join(os.path.dirname( 
     195            os.path.realpath(__file__)), 'slaby_testdata.txt') 
     196        answer = Loader().load(filepath) 
    177197        for i in range(len(o.x)): 
    178198            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     
    183203        """ 
    184204            Test sector averaging I(phi) 
    185             When considering the whole azimuthal range (2pi),  
     205            When considering the whole azimuthal range (2pi), 
    186206            the answer should be the same as ring averaging. 
    187207            The test data was not generated by IGOR. 
    188208        """ 
     209 
    189210        nbins = 19 
    190211        phi_min = math.pi / (nbins + 1) 
     
    198219        o = r(self.data) 
    199220 
    200         output = Loader().load('ring_testdata.txt') 
    201         answer = output[0] 
    202         for i in range(len(o.x)): 
    203             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    204             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    205             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    206              
     221        filepath = os.path.join(os.path.dirname( 
     222            os.path.realpath(__file__)), 'ring_testdata.txt') 
     223        answer = Loader().load(filepath) 
     224        for i in range(len(o.x)): 
     225            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     226            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     227            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     228 
    207229    def test_sectorphi_quarter(self): 
    208230        """ 
     
    210232            The test data was not generated by IGOR. 
    211233        """ 
    212         r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) 
    213         r.nbins_phi = 20 
    214         o = r(self.data) 
    215  
    216         output = Loader().load('sectorphi_testdata.txt') 
    217         answer = output[0] 
    218         for i in range(len(o.x)): 
    219             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    220             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    221             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
    222              
     234 
     235        r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0) 
     236        r.nbins_phi = 20 
     237        o = r(self.data) 
     238 
     239        filepath = os.path.join(os.path.dirname( 
     240            os.path.realpath(__file__)), 'sectorphi_testdata.txt') 
     241        answer = Loader().load(filepath) 
     242        for i in range(len(o.x)): 
     243            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     244            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     245            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     246 
    223247    def test_sectorq_full(self): 
    224248        """ 
     
    226250            The test data was not generated by IGOR. 
    227251        """ 
    228         r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) 
    229         r.nbins_phi = 20 
    230         o = r(self.data) 
    231  
    232         output = Loader().load('sectorq_testdata.txt') 
    233         answer = output[0] 
    234         for i in range(len(o.x)): 
    235             self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
    236             self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
    237             self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     252 
     253        r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0) 
     254        r.nbins_phi = 20 
     255        o = r(self.data) 
     256 
     257        filepath = os.path.join(os.path.dirname( 
     258            os.path.realpath(__file__)), 'sectorq_testdata.txt') 
     259        answer = Loader().load(filepath) 
     260        for i in range(len(o.x)): 
     261            self.assertAlmostEqual(o.x[i], answer.x[i], 4) 
     262            self.assertAlmostEqual(o.y[i], answer.y[i], 4) 
     263            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 
     264 
     265    def test_sectorq_log(self): 
     266        """ 
     267            Test sector averaging I(q) 
     268            The test data was not generated by IGOR. 
     269        """ 
     270 
     271        r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0, base=10) 
     272        r.nbins_phi = 20 
     273        o = r(self.data) 
     274 
     275        expected_binning = np.logspace(np.log10(0.005), np.log10(0.01), 20, base=10) 
     276        for i in range(len(o.x)): 
     277            self.assertAlmostEqual(o.x[i], expected_binning[i], 3) 
     278 
     279        # TODO: Test for Y values (o.y) 
     280        # print len(self.data.x_bins) 
     281        # print len(self.data.y_bins) 
     282        # print self.data.q_data.shape 
     283        # data_to_bin = np.array(self.data.q_data) 
     284        # data_to_bin = data_to_bin.reshape(len(self.data.x_bins), len(self.data.y_bins)) 
     285        # H, xedges, yedges, binnumber = binned_statistic_2d(self.data.x_bins, self.data.y_bins, data_to_bin, 
     286        #     bins=[[0, math.pi / 2.0], expected_binning], statistic='mean') 
     287        # xedges_width = (xedges[1] - xedges[0]) 
     288        # xedges_center = xedges[1:] - xedges_width / 2 
     289 
     290        # yedges_width = (yedges[1] - yedges[0]) 
     291        # yedges_center = yedges[1:] - yedges_width / 2 
     292 
     293        # print H.flatten().shape 
     294        # print o.y.shape 
    238295 
    239296 
  • test/sasdataloader/test/utest_cansas.py

    r7432acb r1fc50fb2  
    4646        self.schema_1_0 = "cansas1d_v1_0.xsd" 
    4747        self.schema_1_1 = "cansas1d_v1_1.xsd" 
    48  
     48        self.write_1_0_filename = "isis_1_0_write_test.xml" 
     49        self.write_1_1_filename = "isis_1_1_write_test.xml" 
    4950 
    5051    def get_number_of_entries(self, dictionary, name, i): 
     
    5657        return name 
    5758 
    58  
    5959    def test_invalid_xml(self): 
    6060        """ 
     
    6262        """ 
    6363        invalid = StringIO.StringIO('<a><c></b></a>') 
    64         reader = XMLreader(invalid) 
    65  
     64        XMLreader(invalid) 
    6665 
    6766    def test_xml_validate(self): 
     
    8281        self.assertFalse(xmlschema.validate(invalid)) 
    8382 
    84  
    8583    def test_real_xml(self): 
    8684        reader = XMLreader(self.xml_valid, self.schema_1_0) 
     
    9088        else: 
    9189            self.assertFalse(valid) 
    92  
    9390 
    9491    def _check_data(self, data): 
     
    105102        self.assertTrue(data.meta_data["xmlpreprocess"] is not None) 
    106103 
    107  
    108104    def _check_data_1_1(self, data): 
    109105        spectrum = data.trans_spectrum[0] 
    110106        self.assertTrue(len(spectrum.wavelength) == 138) 
    111107 
    112  
    113108    def test_cansas_xml(self): 
    114         filename = "isis_1_1_write_test.xml" 
    115109        xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 
    116110        valid = xmlreader.validate_xml() 
    117111        xmlreader.set_processing_instructions() 
    118112        self.assertTrue(valid) 
    119         fo = open(self.isis_1_1) 
    120         str = fo.read() 
    121113        reader_generic = Loader() 
    122114        dataloader = reader_generic.load(self.isis_1_1) 
     
    128120            self._check_data(cansasreader[i]) 
    129121            self._check_data_1_1(cansasreader[i]) 
    130             reader_generic.save(filename, dataloader[i], None) 
    131             fo = open(filename) 
    132             str = fo.read() 
     122            reader_generic.save(self.write_1_1_filename, dataloader[i], None) 
    133123            reader2 = Loader() 
    134             return_data = reader2.load(filename) 
     124            self.assertTrue(os.path.isfile(self.write_1_1_filename)) 
     125            return_data = reader2.load(self.write_1_1_filename) 
    135126            written_data = return_data[0] 
    136127            self._check_data(written_data) 
    137  
     128        if os.path.isfile(self.write_1_1_filename): 
     129            os.remove(self.write_1_1_filename) 
    138130 
    139131    def test_double_trans_spectra(self): 
     
    144136        for item in data: 
    145137            self._check_data(item) 
    146  
    147138 
    148139    def test_entry_name_recurse(self): 
     
    155146        self.assertTrue(len(d) == 6) 
    156147 
    157  
    158148    def test_load_cansas_file(self): 
    159         valid = [] 
    160149        reader1 = XMLreader(self.xml_valid, self.schema_1_0) 
    161150        self.assertTrue(reader1.validate_xml()) 
     
    173162        self.assertFalse(reader7.validate_xml()) 
    174163 
    175  
    176164    def test_invalid_cansas(self): 
    177165        list = self.loader.load(self.cansas1d_notitle) 
     
    184172        self.assertTrue(data.detector[0].distance == 4150) 
    185173 
    186  
    187174    def test_old_cansas_files(self): 
    188175        reader1 = XMLreader(self.cansas1d, self.schema_1_0) 
    189176        self.assertTrue(reader1.validate_xml()) 
    190177        file_loader = Loader() 
    191         file1 = file_loader.load(self.cansas1d) 
     178        file_loader.load(self.cansas1d) 
    192179        reader2 = XMLreader(self.cansas1d_units, self.schema_1_0) 
    193180        self.assertTrue(reader2.validate_xml()) 
     
    197184        self.assertTrue(reader4.validate_xml()) 
    198185 
    199  
    200186    def test_save_cansas_v1_0(self): 
    201         filename = "isis_1_0_write_test.xml" 
    202187        xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) 
    203188        valid = xmlreader.validate_xml() 
     
    210195            self._check_data(dataloader[i]) 
    211196            self._check_data(cansasreader[i]) 
    212             reader_generic.save(filename, dataloader[i], None) 
     197            reader_generic.save(self.write_1_0_filename, dataloader[i], None) 
    213198            reader2 = Reader() 
    214             return_data = reader2.read(filename) 
     199            self.assertTrue(os.path.isfile(self.write_1_0_filename)) 
     200            return_data = reader2.read(self.write_1_0_filename) 
    215201            written_data = return_data[0] 
    216             xmlwrite = XMLreader(filename, self.schema_1_0) 
     202            XMLreader(self.write_1_0_filename, self.schema_1_0) 
    217203            valid = xmlreader.validate_xml() 
    218204            self.assertTrue(valid) 
    219205            self._check_data(written_data) 
    220  
     206        if os.path.isfile(self.write_1_0_filename): 
     207            os.remove(self.write_1_0_filename) 
    221208 
    222209    def test_processing_instructions(self): 
     
    224211        valid = reader.validate_xml() 
    225212        if valid: 
    226             ## find the processing instructions and make into a dictionary 
     213            # find the processing instructions and make into a dictionary 
    227214            dic = self.get_processing_instructions(reader) 
    228215            self.assertTrue(dic == {'xml-stylesheet': \ 
     
    232219            xmldoc = minidom.parseString(xml) 
    233220 
    234             ## take the processing instructions and put them back in 
     221            # take the processing instructions and put them back in 
    235222            xmldoc = self.set_processing_instructions(xmldoc, dic) 
    236             xml_output = xmldoc.toprettyxml() 
    237  
     223            xmldoc.toprettyxml() 
    238224 
    239225    def set_processing_instructions(self, minidom_object, dic): 
     
    243229            minidom_object.insertBefore(pi, xmlroot) 
    244230        return minidom_object 
    245  
    246231 
    247232    def get_processing_instructions(self, xml_reader_object): 
  • 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     
  • test/sasrealspace/test/early_test.py

    r959eb01 raaf5e49  
     1from __future__ import print_function 
    12 
    23import VolumeCanvas 
     
    3031        t_0 = time.time() 
    3132        value_1 = 1.0e8*canvas.getIq(0.1) 
    32         print "density = 0.1:  output=%g  time=%g" % (value_1, time.time()-t_0) 
     33        print("density = 0.1:  output=%g  time=%g" % (value_1, time.time()-t_0)) 
    3334         
    3435        t_0 = time.time() 
    3536        canvas.setParam('lores_density', 1) 
    3637        value_1 = 1.0e8*canvas.getIq(0.1) 
    37         print "density = 1000:  output=%g  time=%g" % (value_1, time.time()-t_0) 
     38        print("density = 1000:  output=%g  time=%g" % (value_1, time.time()-t_0)) 
    3839         
    3940        t_0 = time.time() 
    4041        canvas.setParam('lores_density', 0.01) 
    4142        value_1 = 1.0e8*canvas.getIq(0.1) 
    42         print "density = 0.00001:  output=%g  time=%g" % (value_1, time.time()-t_0) 
    43         print 
     43        print("density = 0.00001:  output=%g  time=%g" % (value_1, time.time()-t_0)) 
     44        print() 
    4445     
    4546     
     
    6364        #ana_1 = form_factor(q, radius) 
    6465         
    65         print "q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1) 
     66        print("q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)) 
    6667     
    6768def test_2(): 
     
    7374    shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol 
    7475    shell_sld = -1.0*core_vol/shell_vol 
    75     print "Shell SLD", shell_sld 
     76    print("Shell SLD", shell_sld) 
    7677 
    7778     
     
    126127        ana_1 = sphere.run(q) 
    127128         
    128         print "q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1) 
     129        print("q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)) 
    129130        out.write( "%g  %g  %g\n" % (q, sim_1, ana_1)) 
    130131 
     
    168169        #ana_1 = form_factor(q, radius) 
    169170         
    170         print "q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1) 
     171        print("q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)) 
    171172 
    172173def test_5(): 
     
    193194    ana = ana.runXY([0.1, 0.1]) 
    194195    sim = model.getIq2D(0.1, 0.1) 
    195     print ana, sim, sim/ana, ana/sim 
     196    print(ana, sim, sim/ana, ana/sim) 
    196197 
    197198def test_6(): 
     
    232233     
    233234     
    234     print model.npts 
     235    print(model.npts) 
    235236    for i in range(40): 
    236237        qmax = 0.5 
     
    240241        anaY = ana.runXY([0, qmax*i/40.0]) 
    241242        simY = model.getIq2D(0, qmax*i/40.0) 
    242         print anaX, simX, simX/anaX, '|', anaY, simY, simY/anaY 
     243        print(anaX, simX, simX/anaX, '|', anaY, simY, simY/anaY) 
    243244     
    244245def test_7(): 
    245246    from sas.models.CoreShellModel import CoreShellModel 
    246     print "Testing core-shell" 
     247    print("Testing core-shell") 
    247248    radius = 15 
    248249    thickness = 5 
     
    287288        ana_val = ana.runXY([q, 0.2]) 
    288289        sim_val, err = canvas.getIq2DError(q, 0.2) 
    289         print ana_val, sim_val, sim_val/ana_val, err, (sim_val-ana_val)/err 
     290        print(ana_val, sim_val, sim_val/ana_val, err, (sim_val-ana_val)/err) 
    290291     
    291292     
  • test/sasrealspace/test/sim_validation.py

    rac07a3a raaf5e49  
    55    @license: This software is provided as part of the DANSE project 
    66""" 
     7from __future__ import print_function 
     8 
    79import math, time, pylab 
    810 
    911try: 
    1012    import VolumeCanvas 
    11     print "Testing local version" 
     13    print("Testing local version") 
    1214except: 
    13     print "Testing installed version" 
     15    print("Testing installed version") 
    1416    import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 
    1517      
     
    250252        ana = validator.run_ana(q) 
    251253        sim, err = validator.run_sim(q) 
    252         print "q=%-g  ana=%-g  sim=%-g  err=%-g  diff=%-g (%-g) %s" % (q, ana, sim, err,  
    253                         (sim-ana), sim/ana, str(math.fabs(sim-ana)>err)) 
     254        print("q=%-g  ana=%-g  sim=%-g  err=%-g  diff=%-g (%-g) %s" % (q, ana, sim, err,  
     255                        (sim-ana), sim/ana, str(math.fabs(sim-ana)>err))) 
    254256        output.write("%g  %g  %g  %g\n" % (q, ana, sim, err)) 
    255257    output.close() 
     
    278280        ana = validator.run_ana2D(q*math.cos(phi), q*math.sin(phi)) 
    279281        sim, err = validator.run_sim2D(q*math.cos(phi), q*math.sin(phi)) 
    280         print "q=%-g  ana=%-g  sim=%-g  err=%-g  diff=%-g (%-g) %s" % (q, ana, sim, err,  
    281                         (sim-ana), sim/ana, str(math.fabs(sim-ana)>err)) 
     282        print("q=%-g  ana=%-g  sim=%-g  err=%-g  diff=%-g (%-g) %s" % (q, ana, sim, err,  
     283                        (sim-ana), sim/ana, str(math.fabs(sim-ana)>err))) 
    282284        output.write("%g  %g  %g  %g\n" % (q, ana, sim, err)) 
    283     print "Time elapsed: ", time.time()-t_0 
     285    print("Time elapsed: ", time.time()-t_0) 
    284286    output.close() 
    285287        
     
    306308    for d in d_list: 
    307309        sim, err = validator.run_sim(q, density=d) 
    308         print "d=%-g  ana=%-g  sim=%-g  err=%-g  diff=%-g (%g) %s" % \ 
     310        print("d=%-g  ana=%-g  sim=%-g  err=%-g  diff=%-g (%g) %s" % \ 
    309311            (d, ana, sim, err, (sim-ana), (sim-ana)/ana,  
    310              str(math.fabs(sim-ana)>err)) 
     312             str(math.fabs(sim-ana)>err))) 
    311313        output.write("%g  %g  %g  %g \n" % (d, ana, sim, err)) 
    312314    output.close() 
  • test/sasrealspace/test/utest_oriented.py

    r959eb01 raaf5e49  
    33    @copyright: University of Tennessee, for the DANSE project 
    44""" 
     5from __future__ import print_function 
    56 
    67import unittest, math, sys 
     
    1617try: 
    1718    import VolumeCanvas 
    18     print "Testing local version" 
     19    print("Testing local version") 
    1920except: 
    20     print sys.exc_value 
     21    print(sys.exc_value) 
    2122    #testing the version that is working on 
    22     print "Testing installed version" 
     23    print("Testing installed version") 
    2324    import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 
    2425  
     
    241242            self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    242243        except: 
    243             print "Error", ana_val, sim_val, sim_val/ana_val 
     244            print("Error", ana_val, sim_val, sim_val/ana_val) 
    244245            raise sys.exc_type, sys.exc_value 
    245246 
     
    395396            self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    396397        except: 
    397             print "Error", ana_val, sim_val, sim_val/ana_val 
     398            print("Error", ana_val, sim_val, sim_val/ana_val) 
    398399            raise sys.exc_type, sys.exc_value 
    399400 
     
    407408            self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    408409        except: 
    409             print "Error", ana_val, sim_val, sim_val/ana_val 
     410            print("Error", ana_val, sim_val, sim_val/ana_val) 
    410411            raise sys.exc_type, sys.exc_value 
    411412 
     
    419420            self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    420421        except: 
    421             print "Error", ana_val, sim_val, sim_val/ana_val 
     422            print("Error", ana_val, sim_val, sim_val/ana_val) 
    422423            raise sys.exc_type, sys.exc_value 
    423424 
     
    431432            self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    432433        except: 
    433             print "Error", ana_val, sim_val, sim_val/ana_val 
     434            print("Error", ana_val, sim_val, sim_val/ana_val) 
    434435            raise sys.exc_type, sys.exc_value 
    435436 
  • test/sasrealspace/test/utest_realspace.py

    r45dffa69 raaf5e49  
    33    @author: Mathieu Doucet / UTK 
    44""" 
     5from __future__ import print_function 
    56 
    67import unittest, math, time 
     
    1516try: 
    1617    import VolumeCanvas 
    17     print "Testing local version" 
     18    print("Testing local version") 
    1819except: 
    1920    import sys 
    20     print sys.exc_value 
     21    print(sys.exc_value) 
    2122    #testing the version that is working on 
    22     print "Testing installed version" 
     23    print("Testing installed version") 
    2324    import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 
    2425      
  • test/utest_sasview.py

    r959eb01 raaf5e49  
    11#!/usr/bin/env python 
     2from __future__ import print_function 
     3 
    24import os 
    35import subprocess 
     
    8082                    if has_failed: 
    8183                        failed += 1 
    82                         print "Result for %s (%s): FAILED" % (module_name, module_dir) 
    83                         print std_out 
     84                        print("Result for %s (%s): FAILED" % (module_name, module_dir)) 
     85                        print(std_out) 
    8486                    else: 
    8587                        passed += 1 
    86                         print "Result for %s: SUCCESS" % module_name 
     88                        print("Result for %s: SUCCESS" % module_name) 
    8789 
    88     print "\n----------------------------------------------" 
     90    print("\n----------------------------------------------") 
    8991    if n_tests == 0: 
    90         print "No tests." 
     92        print("No tests.") 
    9193    else: 
    92         print "Results by test modules:" 
    93         print "    PASSED: %d" % passed 
     94        print("Results by test modules:") 
     95        print("    PASSED: %d" % passed) 
    9496        ratio = 100.0*failed/(failed+passed) 
    95         print "    FAILED: %d    (%.0f%%)" % (failed,ratio) 
     97        print("    FAILED: %d    (%.0f%%)" % (failed,ratio)) 
    9698 
    97         print "Results by tests:" 
    98         print "    Tests run:    %d" % n_tests 
    99         print "    Tests failed: %d" % n_failures 
    100         print "    Test errors:  %d" % n_errors 
    101     print "----------------------------------------------" 
     99        print("Results by tests:") 
     100        print("    Tests run:    %d" % n_tests) 
     101        print("    Tests failed: %d" % n_failures) 
     102        print("    Test errors:  %d" % n_errors) 
     103    print("----------------------------------------------") 
    102104     
    103105    return failed 
  • test/sascalculator/test/utest_slit_length_calculator.py

    r959eb01 rb09095a  
    55import unittest 
    66from sas.sascalc.dataloader.readers.ascii_reader import Reader 
    7 from  sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator as calculator 
     7from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator \ 
     8    as calculator 
    89 
    9 import os.path 
    1010 
    11 class slit_calculator(unittest.TestCase): 
     11class SlitCalculator(unittest.TestCase): 
    1212     
    1313    def setUp(self): 
     
    1515        self.reader = Reader() 
    1616         
    17     def test_slitlength_calculation(self): 
     17    def test_slit_length_calculation(self): 
    1818        """ 
    1919            Test slit_length_calculator" 
    2020        """ 
    21         f = self.reader.read("beam profile.DAT") 
     21        list = self.reader.read("beam profile.DAT") 
     22        self.assertTrue(len(list) == 1) 
     23        f = list[0] 
    2224        cal = calculator() 
    2325        cal.set_data(f.x,f.y) 
    24         slitlength = cal.calculate_slit_length() 
     26        slit_length = cal.calculate_slit_length() 
    2527         
    2628        # The value "5.5858" was obtained by manual calculation. 
    2729        # It turns out our slit length is FWHM/2 
    28         self.assertAlmostEqual(slitlength,5.5858/2, 3) 
     30        self.assertAlmostEqual(slit_length, 5.5858/2, 3) 
    2931         
    3032         
  • test/sasdataloader/test/utest_ascii.py

    r959eb01 rad92c5a  
    66 
    77import unittest 
    8 from sas.sascalc.dataloader.loader import  Loader 
    9   
    10 import os.path 
     8from sas.sascalc.dataloader.loader import Loader 
    119 
    12 class abs_reader(unittest.TestCase): 
     10 
     11class ABSReaderTests(unittest.TestCase): 
    1312     
    1413    def setUp(self): 
    1514        self.loader = Loader() 
    16          
     15        self.f1_list = self.loader.load("ascii_test_1.txt") 
     16        self.f1 = self.f1_list[0] 
     17        self.f2_list = self.loader.load("ascii_test_2.txt") 
     18        self.f2 = self.f2_list[0] 
     19        self.f3_list = self.loader.load("ascii_test_3.txt") 
     20        self.f3 = self.f3_list[0] 
     21        self.f4_list = self.loader.load("ascii_test_4.abs") 
     22        self.f4 = self.f4_list[0] 
     23        self.f5_list = self.loader.load("ascii_test_5.txt") 
     24        self.f5 = self.f5_list[0] 
     25 
    1726    def test_checkdata(self): 
    1827        """ 
    1928            Test .ABS file loaded as ascii 
    2029        """ 
    21         f = self.loader.load("ascii_test_1.txt") 
    2230        # The length of the data is 10 
    23         self.assertEqual(len(f.x), 10) 
    24         self.assertEqual(f.x[0],0.002618) 
    25         self.assertEqual(f.x[9],0.0497) 
    26         self.assertEqual(f.x_unit, '1/A') 
    27         self.assertEqual(f.y_unit, '1/cm') 
     31        self.assertEqual(len(self.f1.x), 10) 
     32        self.assertEqual(self.f1.x[0],0.002618) 
     33        self.assertEqual(self.f1.x[9],0.0497) 
     34        self.assertEqual(self.f1.x_unit, '1/A') 
     35        self.assertEqual(self.f1.y_unit, '1/cm') 
    2836         
    29         self.assertEqual(f.meta_data['loader'],"ASCII") 
    30          
     37        self.assertEqual(self.f1.meta_data['loader'],"ASCII") 
     38 
    3139    def test_truncated_1(self): 
    3240        """ 
     
    3846            as though it were the start of a footer). 
    3947        """ 
    40         # Test .ABS file loaded as ascii 
    41         f = self.loader.load("ascii_test_2.txt") 
    42         # The length of the data is 10 
    43         self.assertEqual(len(f.x), 5) 
    44         self.assertEqual(f.x[0],0.002618) 
    45         self.assertEqual(f.x[4],0.02356) 
    46          
     48        # The length of the data is 5 
     49        self.assertEqual(len(self.f2.x), 5) 
     50        self.assertEqual(self.f2.x[0],0.002618) 
     51        self.assertEqual(self.f2.x[4],0.02356) 
     52 
    4753    def test_truncated_2(self): 
    4854        """ 
     
    5258            reading at the first inconsitent line. 
    5359        """ 
    54         # Test .ABS file loaded as ascii 
    55         f = self.loader.load("ascii_test_3.txt") 
    5660        # The length of the data is 5 
    57         self.assertEqual(len(f.x), 5) 
    58         self.assertEqual(f.x[0],0.002618) 
    59         self.assertEqual(f.x[4],0.02356) 
    60          
     61        self.assertEqual(len(self.f3.x), 5) 
     62        self.assertEqual(self.f3.x[0],0.002618) 
     63        self.assertEqual(self.f3.x[4],0.02356) 
     64 
    6165    def test_truncated_3(self): 
    6266        """ 
     
    6670            reading at the last line of header. 
    6771        """ 
    68         # Test .ABS file loaded as ascii 
    69         f = self.loader.load("ascii_test_4.abs") 
    7072        # The length of the data is 5 
    71         self.assertEqual(len(f.x), 5) 
    72         self.assertEqual(f.x[0],0.012654) 
    73         self.assertEqual(f.x[4],0.02654) 
    74          
     73        self.assertEqual(len(self.f4.x), 5) 
     74        self.assertEqual(self.f4.x[0],0.012654) 
     75        self.assertEqual(self.f4.x[4],0.02654) 
     76 
    7577    def test_truncated_4(self): 
    7678        """ 
     
    7880            Only the last 5 2-col lines should be read. 
    7981        """ 
    80         # Test .ABS file loaded as ascii 
    81         f = self.loader.load("ascii_test_5.txt") 
    8282        # The length of the data is 5 
    83         self.assertEqual(len(f.x), 5) 
    84         self.assertEqual(f.x[0],0.02879) 
    85         self.assertEqual(f.x[4],0.0497) 
    86          
     83        self.assertEqual(len(self.f5.x), 5) 
     84        self.assertEqual(self.f5.x[0],0.02879) 
     85        self.assertEqual(self.f5.x[4],0.0497) 
     86 
    8787    def test_truncated_5(self): 
    8888        """ 
    89             Test a 6-col ascii file with complex header where one of them has a letter and  
    90             many lines with 2 or 2 columns in the middle of the data section. 
    91             Only last four lines should be read. 
     89            Test a 6-col ascii file with complex header where one of them has a 
     90            letter and many lines with 2 or 2 columns in the middle of the data 
     91            section. Will be rejected because fewer than 5 lines. 
    9292        """ 
    9393        # Test .ABS file loaded as ascii 
     
    9898        except: 
    9999            self.assertEqual(f, None) 
    100          
     100 
    101101if __name__ == '__main__': 
    102102    unittest.main() 
  • test/sasdataloader/test/utest_red2d_reader.py

    r959eb01 r248ff73  
    77import unittest 
    88from sas.sascalc.dataloader.loader import  Loader 
    9   
     9 
    1010import os.path 
    1111 
    1212class abs_reader(unittest.TestCase): 
    13      
     13 
    1414    def setUp(self): 
    1515        self.loader = Loader() 
    16          
     16 
    1717    def test_checkdata(self): 
    1818        """ 
    1919            Test .DAT file loaded as IGOR/DAT 2D Q_map 
    2020        """ 
    21         f = self.loader.load("exp18_14_igor_2dqxqy.dat") 
     21        f = self.loader.load("exp18_14_igor_2dqxqy.dat")[0] 
    2222        # The length of the data is 10 
    2323        self.assertEqual(len(f.qx_data),  36864) 
     
    2626        self.assertEqual(f.Q_unit, '1/A') 
    2727        self.assertEqual(f.I_unit, '1/cm') 
    28          
     28 
    2929        self.assertEqual(f.meta_data['loader'],"IGOR/DAT 2D Q_map") 
    30          
    31          
     30 
     31 
    3232if __name__ == '__main__': 
    3333    unittest.main() 
    34     
  • test/sasinvariant/test/utest_use_cases.py

    r959eb01 rb09095a  
    66import unittest 
    77from sas.sascalc.dataloader.loader import  Loader 
    8  
    98from sas.sascalc.invariant import invariant 
     9 
    1010 
    1111class Data1D: 
    1212    pass 
    13      
     13 
     14 
    1415class TestLineFit(unittest.TestCase): 
    1516    """ 
     
    1718    """ 
    1819    def setUp(self): 
    19         self.data = Loader().load("linefittest.txt") 
    20          
     20        self.data_list = Loader().load("linefittest.txt") 
     21        self.data = self.data_list[0] 
     22 
    2123    def test_fit_line_data(self): 
    2224        """  
    2325            Fit_Test_1: test linear fit, ax +b, without fixed 
    2426        """ 
    25          
     27 
    2628        # Create invariant object. Background and scale left as defaults. 
    2729        fit = invariant.Extrapolator(data=self.data) 
    2830         
    29         ##Without holding 
     31        # Without holding 
    3032        p, dp = fit.fit(power=None) 
    3133 
     
    3335        self.assertAlmostEquals(p[0], 2.3983,3) 
    3436        self.assertAlmostEquals(p[1], 0.87833,3) 
    35  
    3637 
    3738    def test_fit_line_data_fixed(self): 
     
    3940            Fit_Test_2: test linear fit, ax +b, with 'a' fixed 
    4041        """ 
    41          
     42 
    4243        # Create invariant object. Background and scale left as defaults. 
    4344        fit = invariant.Extrapolator(data=self.data) 
    44          
    45         #With holding a = -power =4 
     45 
     46        # With holding a = -power =4 
    4647        p, dp = fit.fit(power=-4) 
    4748 
     
    4950        self.assertAlmostEquals(p[0], 4) 
    5051        self.assertAlmostEquals(p[1], -4.0676,3) 
    51          
     52 
     53 
    5254class TestLineFitNoweight(unittest.TestCase): 
    5355    """ 
     
    5557    """ 
    5658    def setUp(self): 
    57         self.data = Loader().load("linefittest_no_weight.txt") 
    58          
     59        self.data_list = Loader().load("linefittest_no_weight.txt") 
     60        self.data = self.data_list[0] 
     61 
    5962    def skip_test_fit_line_data_no_weight(self): 
    6063        """  
    6164            Fit_Test_1: test linear fit, ax +b, without fixed 
    6265        """ 
    63          
     66 
    6467        # Create invariant object. Background and scale left as defaults. 
    6568        fit = invariant.Extrapolator(data=self.data) 
    66          
    67         ##Without holding 
     69 
     70        # Without holding 
    6871        p, dp = fit.fit(power=None) 
    6972 
     
    7174        self.assertAlmostEquals(p[0], 2.4727,3) 
    7275        self.assertAlmostEquals(p[1], 0.6,3) 
    73  
    7476 
    7577    def test_fit_line_data_fixed_no_weight(self): 
     
    7779            Fit_Test_2: test linear fit, ax +b, with 'a' fixed 
    7880        """ 
    79          
     81 
    8082        # Create invariant object. Background and scale left as defaults. 
    8183        fit = invariant.Extrapolator(data=self.data) 
    82          
     84 
    8385        #With holding a = -power =4 
    8486        p, dp = fit.fit(power=-4) 
     
    8789        self.assertAlmostEquals(p[0], 4) 
    8890        self.assertAlmostEquals(p[1], -7.8,3) 
    89                  
     91 
     92 
    9093class TestInvPolySphere(unittest.TestCase): 
    9194    """ 
     
    9396    """ 
    9497    def setUp(self): 
    95         self.data = Loader().load("PolySpheres.txt") 
    96          
     98        self.data_list = Loader().load("PolySpheres.txt") 
     99        self.data = self.data_list[0] 
     100 
    97101    def test_wrong_data(self): 
    98102        """ test receiving Data1D not of type loader""" 
    99  
    100  
    101103        self.assertRaises(ValueError,invariant.InvariantCalculator, Data1D()) 
    102          
     104 
    103105    def test_use_case_1(self): 
    104106        """ 
     
    107109        # Create invariant object. Background and scale left as defaults. 
    108110        inv = invariant.InvariantCalculator(data=self.data) 
    109          
     111 
    110112        # We have to be able to tell the InvariantCalculator whether we want the 
    111113        # extrapolation or not. By default, when the user doesn't specify, we 
    112         # should compute Q* without extrapolation. That's what should be done in __init__. 
    113          
     114        # should compute Q* without extrapolation. That's what should be done 
     115        # in __init__. 
     116 
    114117        # We call get_qstar() with no argument, which signifies that we do NOT 
    115118        # want extrapolation. 
    116119        qstar = inv.get_qstar() 
    117          
     120 
    118121        # The volume fraction and surface use Q*. That means that the following  
    119122        # methods should check that Q* has been computed. If not, it should  
     
    121124        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
    122125        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    123          
     126 
    124127        # Test results 
    125128        self.assertAlmostEquals(qstar, 7.48959e-5,2) 
    126129        self.assertAlmostEquals(v, 0.005644689, 4) 
    127130        self.assertAlmostEquals(s , 941.7452, 3) 
    128          
     131 
    129132    def test_use_case_2(self): 
    130133        """ 
    131             Invariant without extrapolation. Invariant, volume fraction and surface  
    132             are given with errors. 
    133         """ 
    134         # Create invariant object. Background and scale left as defaults. 
    135         inv = invariant.InvariantCalculator(data=self.data) 
    136          
     134        Invariant without extrapolation. Invariant, volume fraction and surface  
     135        are given with errors. 
     136        """ 
     137        # Create invariant object. Background and scale left as defaults. 
     138        inv = invariant.InvariantCalculator(data=self.data) 
     139 
    137140        # Get the invariant with errors 
    138141        qstar, qstar_err = inv.get_qstar_with_error() 
    139          
     142 
    140143        # The volume fraction and surface use Q*. That means that the following  
    141144        # methods should check that Q* has been computed. If not, it should  
     
    147150        self.assertAlmostEquals(v, 0.005644689, 1) 
    148151        self.assertAlmostEquals(s , 941.7452, 3) 
    149         
    150          
     152 
    151153    def test_use_case_3(self): 
    152154        """ 
     
    155157        # Create invariant object. Background and scale left as defaults. 
    156158        inv = invariant.InvariantCalculator(data=self.data) 
    157          
     159 
    158160        # Set the extrapolation parameters for the low-Q range 
    159          
     161 
    160162        # The npts parameter should have a good default. 
    161163        # The range parameter should be 'high' or 'low' 
    162164        # The function parameter should default to None. If it is None, 
    163         #    the method should pick a good default (Guinier at low-Q and 1/q^4 at high-Q). 
    164         #    The method should also check for consistency of the extrapolation and function 
    165         #    parameters. For instance, you might not want to allow 'high' and 'guinier'. 
     165        #    the method should pick a good default 
     166        #    (Guinier at low-Q and 1/q^4 at high-Q). 
     167        #    The method should also check for consistency of the extrapolation 
     168        #    and function parameters. For instance, you might not want to allow 
     169        #    'high' and 'guinier'. 
    166170        # The power parameter (not shown below) should default to 4. 
    167171        inv.set_extrapolation(range='low', npts=10, function='guinier') 
    168          
    169         # The version of the call without error 
    170         # At this point, we could still compute Q* without extrapolation by calling 
    171         # get_qstar with arguments, or with extrapolation=None. 
     172 
     173        # The version of the call without error 
     174        # At this point, we could still compute Q* without extrapolation by 
     175        # calling get_qstar with arguments, or with extrapolation=None. 
    172176        qstar = inv.get_qstar(extrapolation='low') 
    173          
     177 
    174178        # The version of the call with error 
    175179        qstar, qstar_err = inv.get_qstar_with_error(extrapolation='low') 
     
    178182        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
    179183        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    180          
     184 
    181185        # Test results 
    182186        self.assertAlmostEquals(qstar, 7.49e-5, 1) 
    183187        self.assertAlmostEquals(v, 0.005648401, 4) 
    184188        self.assertAlmostEquals(s , 941.7452, 3) 
    185              
     189 
    186190    def test_use_case_4(self): 
    187191        """ 
     
    190194        # Create invariant object. Background and scale left as defaults. 
    191195        inv = invariant.InvariantCalculator(data=self.data) 
     196 
     197        # Set the extrapolation parameters for the high-Q range 
     198        inv.set_extrapolation(range='high', npts=10, function='power_law', 
     199                              power=4) 
    192200         
    193         # Set the extrapolation parameters for the high-Q range 
    194         inv.set_extrapolation(range='high', npts=10, function='power_law', power=4) 
    195          
    196         # The version of the call without error 
    197         # The function parameter defaults to None, then is picked to be 'power_law' for extrapolation='high' 
     201        # The version of the call without error 
     202        # The function parameter defaults to None, then is picked to be 
     203        # 'power_law' for extrapolation='high' 
    198204        qstar = inv.get_qstar(extrapolation='high') 
    199          
     205 
    200206        # The version of the call with error 
    201207        qstar, qstar_err = inv.get_qstar_with_error(extrapolation='high') 
     
    204210        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
    205211        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    206          
     212 
    207213        # Test results 
    208214        self.assertAlmostEquals(qstar, 7.49e-5,2) 
    209215        self.assertAlmostEquals(v, 0.005952674, 3) 
    210216        self.assertAlmostEquals(s , 941.7452, 3) 
    211          
     217 
    212218    def test_use_case_5(self): 
    213219        """ 
     
    216222        # Create invariant object. Background and scale left as defaults. 
    217223        inv = invariant.InvariantCalculator(data=self.data) 
    218          
     224 
    219225        # Set the extrapolation parameters for the low- and high-Q ranges 
    220226        inv.set_extrapolation(range='low', npts=10, function='guinier') 
    221         inv.set_extrapolation(range='high', npts=10, function='power_law', power=4) 
    222          
    223         # The version of the call without error 
    224         # The function parameter defaults to None, then is picked to be 'power_law' for extrapolation='high' 
     227        inv.set_extrapolation(range='high', npts=10, function='power_law', 
     228                              power=4) 
     229 
     230        # The version of the call without error 
     231        # The function parameter defaults to None, then is picked to be 
     232        # 'power_law' for extrapolation='high' 
    225233        qstar = inv.get_qstar(extrapolation='both') 
    226234         
     
    231239        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
    232240        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    233          
     241 
    234242        # Test results 
    235243        self.assertAlmostEquals(qstar, 7.88981e-5,2) 
    236244        self.assertAlmostEquals(v, 0.005952674, 3) 
    237245        self.assertAlmostEquals(s , 941.7452, 3) 
    238        
     246 
    239247    def test_use_case_6(self): 
    240248        """ 
     
    243251        # Create invariant object. Background and scale left as defaults. 
    244252        inv = invariant.InvariantCalculator(data=self.data) 
    245          
     253 
    246254        # Set the extrapolation parameters for the high-Q range 
    247255        inv.set_extrapolation(range='low', npts=10, function='power_law', power=4) 
    248          
     256 
    249257        # The version of the call without error 
    250258        # The function parameter defaults to None, then is picked to be 'power_law' for extrapolation='high' 
    251259        qstar = inv.get_qstar(extrapolation='low') 
    252          
     260 
    253261        # The version of the call with error 
    254262        qstar, qstar_err = inv.get_qstar_with_error(extrapolation='low') 
     
    257265        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
    258266        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    259          
     267 
    260268        # Test results 
    261269        self.assertAlmostEquals(qstar, 7.49e-5,2) 
    262270        self.assertAlmostEquals(v, 0.005952674, 3) 
    263271        self.assertAlmostEquals(s , 941.7452, 3) 
    264          
     272 
     273 
    265274class TestInvPinholeSmear(unittest.TestCase): 
    266275    """ 
     
    271280        list = Loader().load("latex_smeared.xml") 
    272281        self.data_q_smear = list[0] 
    273      
     282 
    274283    def test_use_case_1(self): 
    275284        """ 
     
    278287        inv = invariant.InvariantCalculator(data=self.data_q_smear) 
    279288        qstar = inv.get_qstar() 
    280          
     289 
    281290        v = inv.get_volume_fraction(contrast=2.6e-6) 
    282291        s = inv.get_surface(contrast=2.6e-6, porod_const=2) 
     
    285294        self.assertAlmostEquals(v, 0.115352622, 2) 
    286295        self.assertAlmostEquals(s , 941.7452, 3 ) 
    287          
     296 
    288297    def test_use_case_2(self): 
    289298        """ 
     
    293302        # Create invariant object. Background and scale left as defaults. 
    294303        inv = invariant.InvariantCalculator(data=self.data_q_smear) 
    295          
     304 
    296305        # Get the invariant with errors 
    297306        qstar, qstar_err = inv.get_qstar_with_error() 
     
    303312        self.assertAlmostEquals(v, 0.115352622, 2) 
    304313        self.assertAlmostEquals(s , 941.7452, 3 ) 
    305         
     314 
    306315    def test_use_case_3(self): 
    307316        """ 
     
    319328        v, dv = inv.get_volume_fraction_with_error(contrast=2.6e-6) 
    320329        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    321          
     330 
    322331        # Test results 
    323332        self.assertAlmostEquals(qstar, 0.00138756,2) 
    324333        self.assertAlmostEquals(v, 0.117226896,2) 
    325334        self.assertAlmostEquals(s ,941.7452, 3) 
    326        
     335 
    327336    def test_use_case_4(self): 
    328337        """ 
     
    337346        # The version of the call with error 
    338347        qstar, qstar_err = inv.get_qstar_with_error(extrapolation='high') 
    339          
    340         # Get the volume fraction and surface 
    341         # WHY SHOULD THIS FAIL? 
    342         #self.assertRaises(RuntimeError, inv.get_volume_fraction_with_error, 2.6e-6) 
    343          
    344         # Check that an exception is raised when the 'surface' is not defined 
    345         # WHY SHOULD THIS FAIL? 
    346         #self.assertRaises(RuntimeError, inv.get_surface_with_error, 2.6e-6, 2) 
    347348 
    348349        # Test results 
    349350        self.assertAlmostEquals(qstar, 0.0045773,2) 
    350         
     351 
    351352    def test_use_case_5(self): 
    352353        """ 
     
    357358        # Set the extrapolation parameters for the low- and high-Q ranges 
    358359        inv.set_extrapolation(range='low', npts=10, function='guinier') 
    359         inv.set_extrapolation(range='high', npts=10, function='power_law', power=4) 
    360         # The version of the call without error 
    361         # The function parameter defaults to None, then is picked to be 'power_law' for extrapolation='high' 
     360        inv.set_extrapolation(range='high', npts=10, function='power_law', 
     361                              power=4) 
     362        # The version of the call without error 
     363        # The function parameter defaults to None, then is picked to be 
     364        # 'power_law' for extrapolation='high' 
    362365        qstar = inv.get_qstar(extrapolation='both') 
    363366        # The version of the call with error 
    364367        qstar, qstar_err = inv.get_qstar_with_error(extrapolation='both') 
    365          
    366         # Get the volume fraction and surface 
    367         # WHY SHOULD THIS FAIL? 
    368         #self.assertRaises(RuntimeError, inv.get_volume_fraction_with_error, 2.6e-6) 
    369         #self.assertRaises(RuntimeError, inv.get_surface_with_error, 2.6e-6, 2) 
    370          
     368 
    371369        # Test results 
    372370        self.assertAlmostEquals(qstar, 0.00460319,3) 
Note: See TracChangeset for help on using the changeset viewer.