Changeset 371b9e2 in sasview


Ignore:
Timestamp:
May 2, 2017 9:24:16 AM (7 years ago)
Author:
krzywon
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:
3ece5dd
Parents:
5d8f9b3
git-author:
Jeff Krzywon <krzywon@…> (05/02/17 09:24:16)
git-committer:
krzywon <krzywon@…> (05/02/17 09:24:16)
Message:

Add support for a fourth reader exception and start the removal of IgorReader? support.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/loader.py

    r5d8f9b3 r371b9e2  
    7171        try: 
    7272            return super(Registry, self).load(path, format=format) 
    73         except NoKnownLoaderException as e: 
    74             pass  # try the ASCII reader 
     73        except NoKnownLoaderException as nkl_e: 
     74            pass  # try the ASCII reader4 
     75        except Exception as reg_e: 
     76            pass 
    7577        try: 
    7678            ascii_loader = ascii_reader.Reader() 
    7779            return ascii_loader.read(path) 
    7880        except DefaultReaderException: 
    79             pass  # Loader specific error to try the cansas XML reader 
     81            pass  # Loader specific error to try the ascii reader 
     82        except FileContentsException: 
     83            # TODO: handle error 
     84            pass 
    8085        try: 
    8186            cansas_loader = cansas_reader.Reader() 
  • src/sas/sascalc/dataloader/loader_exceptions.py

    rda8bb53 r371b9e2  
    1414 
    1515 
    16 class FileContentsException(Exception): 
     16class DefaultReaderException(Exception): 
    1717    """ 
    18     Exception for files with an associated reader, but with no loadable data. 
    19     This is useful for catching loader or file format issues. 
     18    Exception for files with no associated reader. This should be thrown by 
     19    default readers only to tell Loader to try the next reader. 
    2020    """ 
    2121    def __init__(self, e): 
     
    2323 
    2424 
    25 class DefaultReaderException(Exception): 
     25class FileContentsException(Exception): 
    2626    """ 
    27     Exception for files with no associated reader. This should be thrown by 
    28     default readers only to tell Loader to try the next reader. 
     27    Exception for files with an associated reader, but with no loadable data. 
     28    This is useful for catching loader or file format issues. 
    2929    """ 
    3030    def __init__(self, e): 
  • src/sas/sascalc/dataloader/readers/associations.py

    r7a5d066 r371b9e2  
    2424    ".h5": "cansas_reader_HDF5", 
    2525    ".txt": "ascii_reader", 
    26     ".asc": "IgorReader", 
    2726    ".dat": "red2d_reader", 
    2827    ".abs": "abs_reader", 
  • test/sasdataloader/test/utest_abs_reader.py

    rad92c5a r371b9e2  
    8282        self.assertEqual(self.data.dy[1], 0.000315) 
    8383        self.assertEqual(self.data.dx[1], 0.008249) 
    84  
    85  
    86 class IgorReaderTests(unittest.TestCase): 
    87      
    88     def setUp(self): 
    89         # the IgorReader should be able to read this filetype 
    90         # if it can't, stop here. 
    91         reader = IgorReader() 
    92         self.data = reader.read("MAR07232_rest.ASC") 
    93  
    94     def test_igor_checkdata(self): 
    95         """ 
    96             Check the data content to see whether  
    97             it matches the specific file we loaded. 
    98             Check the units too to see whether the 
    99             Data1D defaults changed. Otherwise the 
    100             tests won't pass 
    101         """ 
    102         self.assertEqual(self.data.filename, "MAR07232_rest.ASC") 
    103         self.assertEqual(self.data.meta_data['loader'], "IGOR 2D") 
    104          
    105         self.assertEqual(self.data.source.wavelength_unit, 'A') 
    106         self.assertEqual(self.data.source.wavelength, 8.4) 
    107          
    108         self.assertEqual(self.data.detector[0].distance_unit, 'mm') 
    109         self.assertEqual(self.data.detector[0].distance, 13705) 
    110          
    111         self.assertEqual(self.data.sample.transmission, 0.84357) 
    112          
    113         self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') 
    114         center_x = (68.76 - 1)*5.0 
    115         center_y = (62.47 - 1)*5.0 
    116         self.assertEqual(self.data.detector[0].beam_center.x, center_x) 
    117         self.assertEqual(self.data.detector[0].beam_center.y, center_y) 
    118          
    119         self.assertEqual(self.data.I_unit, '1/cm') 
    120         # 3 points should be suffcient to check that the data is in column 
    121         # major order. 
    122         np.testing.assert_almost_equal(self.data.data[0:3], 
    123                                        [0.279783, 0.28951, 0.167634]) 
    124         np.testing.assert_almost_equal(self.data.qx_data[0:3], 
    125                                        [-0.01849072, -0.01821785, -0.01794498]) 
    126         np.testing.assert_almost_equal(self.data.qy_data[0:3], 
    127                                        [-0.01677435, -0.01677435, -0.01677435]) 
    128  
    129     def test_generic_loader(self): 
    130         # the generic loader should direct the file to IgorReader as well 
    131         data = Loader().load("MAR07232_rest.ASC") 
    132         self.assertEqual(data.meta_data['loader'], "IGOR 2D") 
    13384 
    13485 
Note: See TracChangeset for help on using the changeset viewer.