Changeset 278ddee in sasview for src/sas/sascalc/dataloader/readers


Ignore:
Timestamp:
Apr 11, 2017 7:51:05 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:
beba407
Parents:
7f75a3f (diff), 97c60f8 (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.
git-author:
Jeff Krzywon <krzywon@…> (04/11/17 07:51:05)
git-committer:
krzywon <krzywon@…> (04/11/17 07:51:05)
Message:

Merge branch 'master' into ticket-876

# Conflicts:
# src/sas/sascalc/dataloader/readers/ascii_reader.py
# src/sas/sascalc/dataloader/readers/xml_reader.py

Location:
src/sas/sascalc/dataloader/readers
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/ascii_reader.py

    r7f75a3f r235f514  
    1717import os 
    1818from sas.sascalc.dataloader.data_info import Data1D 
    19 from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    2019 
    2120# Check whether we have a converter available 
     
    129128                        if new_lentoks > 2: 
    130129                            _dy = float(toks[2]) 
    131                         has_error_dy = False if _dy == None else True 
     130                        has_error_dy = False if _dy is None else True 
    132131 
    133132                        # If a 4th row is present, consider it dx 
    134133                        if new_lentoks > 3: 
    135134                            _dx = float(toks[3]) 
    136                         has_error_dx = False if _dx == None else True 
     135                        has_error_dx = False if _dx is None else True 
    137136 
    138137                        # Delete the previously stored lines of data candidates if 
     
    174173                if not is_data: 
    175174                    msg = "ascii_reader: x has no data" 
    176                     raise FileContentsException, msg 
     175                    raise RuntimeError, msg 
    177176                # Sanity check 
    178177                if has_error_dy == True and not len(ty) == len(tdy): 
    179178                    msg = "ascii_reader: y and dy have different length" 
    180                     raise FileContentsException, msg 
     179                    raise RuntimeError, msg 
    181180                if has_error_dx == True and not len(tx) == len(tdx): 
    182181                    msg = "ascii_reader: y and dy have different length" 
    183                     raise FileContentsException, msg 
     182                    raise RuntimeError, msg 
    184183                # If the data length is zero, consider this as 
    185184                # though we were not able to read the file. 
    186185                if len(tx) == 0: 
    187                     raise FileContentsException, "ascii_reader: could not load file" 
     186                    raise RuntimeError, "ascii_reader: could not load file" 
    188187 
    189188                #Let's re-order the data to make cal. 
  • src/sas/sascalc/dataloader/readers/associations.py

    re5c09cf r959eb01  
    1818import logging 
    1919import json 
     20 
     21logger = logging.getLogger(__name__) 
    2022 
    2123FILE_NAME = 'defaults.json' 
     
    6769                    msg = "read_associations: skipping association" 
    6870                    msg += " for %s\n  %s" % (ext.lower(), sys.exc_value) 
    69                     logging.error(msg) 
     71                    logger.error(msg) 
    7072    else: 
    7173        print "Could not find reader association settings\n  %s [%s]" % (__file__, os.getcwd()) 
     
    8183    :param registry_function: function to be called to register each reader 
    8284    """ 
    83     logging.info("register_readers is now obsolete: use read_associations()") 
     85    logger.info("register_readers is now obsolete: use read_associations()") 
    8486    import abs_reader 
    8587    import ascii_reader 
  • src/sas/sascalc/dataloader/readers/cansas_constants.py

    rad4632c r63d773c  
    135135                             "Sesans": {"storeas": "content"}, 
    136136                             "zacceptance": {"storeas": "float"}, 
     137                             "yacceptance": {"storeas": "float"}, 
    137138                             "<any>" : ANY 
    138139                            } 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r7f75a3f r278ddee  
    3434import xml.dom.minidom 
    3535from xml.dom.minidom import parseString 
     36 
     37logger = logging.getLogger(__name__) 
    3638 
    3739PREPROCESS = "xmlpreprocess" 
     
    291293                elif tagname == 'Sesans': 
    292294                    self.current_datainfo.isSesans = bool(data_point) 
     295                elif tagname == 'yacceptance': 
     296                    self.current_datainfo.sample.yacceptance = (data_point, unit) 
    293297                elif tagname == 'zacceptance': 
    294298                    self.current_datainfo.sample.zacceptance = (data_point, unit) 
     
    809813        :param data1d: presumably a Data1D object 
    810814        """ 
    811         if self.current_dataset == None: 
     815        if self.current_dataset is None: 
    812816            x_vals = np.empty(0) 
    813817            y_vals = np.empty(0) 
     
    897901        # Write the file 
    898902        file_ref = open(filename, 'w') 
    899         if self.encoding == None: 
     903        if self.encoding is None: 
    900904            self.encoding = "UTF-8" 
    901905        doc.write(file_ref, encoding=self.encoding, 
     
    10171021        :param entry_node: lxml node ElementTree object to be appended to 
    10181022        """ 
    1019         if datainfo.run == None or datainfo.run == []: 
     1023        if datainfo.run is None or datainfo.run == []: 
    10201024            datainfo.run.append(RUN_NAME_DEFAULT) 
    10211025            datainfo.run_name[RUN_NAME_DEFAULT] = RUN_NAME_DEFAULT 
     
    10611065            sesans.text = str(datainfo.isSesans) 
    10621066            node.append(sesans) 
     1067            self.write_node(node, "yacceptance", datainfo.sample.yacceptance[0], 
     1068                             {'unit': datainfo.sample.yacceptance[1]}) 
    10631069            self.write_node(node, "zacceptance", datainfo.sample.zacceptance[0], 
    10641070                             {'unit': datainfo.sample.zacceptance[1]}) 
     
    11331139                self.write_node(point, "T", spectrum.transmission[i], 
    11341140                                {'unit': spectrum.transmission_unit}) 
    1135                 if spectrum.transmission_deviation != None \ 
     1141                if spectrum.transmission_deviation is not None \ 
    11361142                and len(spectrum.transmission_deviation) >= i: 
    11371143                    self.write_node(point, "Tdev", 
     
    12131219                                 str(datainfo.source.name)) 
    12141220        self.append(source, instr) 
    1215         if datainfo.source.radiation == None or datainfo.source.radiation == '': 
     1221        if datainfo.source.radiation is None or datainfo.source.radiation == '': 
    12161222            datainfo.source.radiation = "neutron" 
    12171223        self.write_node(source, "radiation", datainfo.source.radiation) 
     
    12541260        :param instr: lxml node ElementTree object to be appended to 
    12551261        """ 
    1256         if datainfo.collimation == [] or datainfo.collimation == None: 
     1262        if datainfo.collimation == [] or datainfo.collimation is None: 
    12571263            coll = Collimation() 
    12581264            datainfo.collimation.append(coll) 
     
    12991305        :param inst: lxml instrument node to be appended to 
    13001306        """ 
    1301         if datainfo.detector == None or datainfo.detector == []: 
     1307        if datainfo.detector is None or datainfo.detector == []: 
    13021308            det = Detector() 
    13031309            det.name = "" 
     
    14641470                local_unit = None 
    14651471                exec "local_unit = storage.%s_unit" % toks[0] 
    1466                 if local_unit != None and units.lower() != local_unit.lower(): 
     1472                if local_unit is not None and units.lower() != local_unit.lower(): 
    14671473                    if HAS_CONVERTER == True: 
    14681474                        try: 
     
    14771483                            self.errors.add(err_mess) 
    14781484                            if optional: 
    1479                                 logging.info(err_mess) 
     1485                                logger.info(err_mess) 
    14801486                            else: 
    14811487                                raise ValueError, err_mess 
     
    14861492                        self.errors.add(err_mess) 
    14871493                        if optional: 
    1488                             logging.info(err_mess) 
     1494                            logger.info(err_mess) 
    14891495                        else: 
    14901496                            raise ValueError, err_mess 
  • src/sas/sascalc/dataloader/readers/danse_reader.py

    r9a5097c r235f514  
    1919from sas.sascalc.dataloader.data_info import Data2D, Detector 
    2020from sas.sascalc.dataloader.manipulations import reader2D_converter 
     21 
     22logger = logging.getLogger(__name__) 
    2123 
    2224# Look for unit converter 
     
    142144                            error.append(err) 
    143145                        except: 
    144                             logging.info("Skipping line:%s,%s" %(data_str, 
     146                            logger.info("Skipping line:%s,%s" %(data_str, 
    145147                                                                sys.exc_value)) 
    146148             
     
    164166                 
    165167                x_vals.append(qx) 
    166                 if xmin == None or qx < xmin: 
     168                if xmin is None or qx < xmin: 
    167169                    xmin = qx 
    168                 if xmax == None or qx > xmax: 
     170                if xmax is None or qx > xmax: 
    169171                    xmax = qx 
    170172             
     
    179181                 
    180182                y_vals.append(qy) 
    181                 if ymin == None or qy < ymin: 
     183                if ymin is None or qy < ymin: 
    182184                    ymin = qy 
    183                 if ymax == None or qy > ymax: 
     185                if ymax is None or qy > ymax: 
    184186                    ymax = qy 
    185187             
     
    196198                    msg = "Skipping entry (v1.0):%s,%s" % (str(data[i_pt]), 
    197199                                                           sys.exc_value) 
    198                     logging.info(msg) 
     200                    logger.info(msg) 
    199201                 
    200202                # Get bin number 
     
    271273                raise ValueError, msg 
    272274            else: 
    273                 logging.info("Danse_reader Reading %s \n" % filename) 
     275                logger.info("Danse_reader Reading %s \n" % filename) 
    274276             
    275277            # Store loading process information 
  • src/sas/sascalc/dataloader/readers/tiff_reader.py

    r9a5097c r959eb01  
    1616from sas.sascalc.dataloader.data_info import Data2D 
    1717from sas.sascalc.dataloader.manipulations import reader2D_converter 
    18      
     18 
     19logger = logging.getLogger(__name__) 
     20 
    1921class Reader: 
    2022    """ 
     
    7678                value = float(val) 
    7779            except: 
    78                 logging.error("tiff_reader: had to skip a non-float point") 
     80                logger.error("tiff_reader: had to skip a non-float point") 
    7981                continue 
    8082             
  • src/sas/sascalc/dataloader/readers/xml_reader.py

    r7f75a3f r235f514  
    1818from lxml import etree 
    1919from lxml.builder import E 
     20 
     21logger = logging.getLogger(__name__) 
    2022 
    2123PARSER = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False) 
     
    7072            self.xmldoc = etree.parse(self.xml, parser=PARSER) 
    7173            self.xmlroot = self.xmldoc.getroot() 
    72         except etree.XMLSyntaxError: 
    73             raise 
     74        except etree.XMLSyntaxError as xml_error: 
     75            logger.info(xml_error) 
    7476        except Exception: 
    7577            self.xml = None 
     
    8890            self.xmlroot = etree.fromstring(tag_soup) 
    8991        except etree.XMLSyntaxError as xml_error: 
    90             logging.info(xml_error) 
     92            logger.info(xml_error) 
    9193        except Exception: 
    9294            self.xml = None 
     
    102104            self.schemadoc = etree.parse(self.schema, parser=PARSER) 
    103105        except etree.XMLSyntaxError as xml_error: 
    104             logging.info(xml_error) 
     106            logger.info(xml_error) 
    105107        except Exception: 
    106108            self.schema = None 
     
    238240        :param name: The name of the element to be created 
    239241        """ 
    240         if attrib == None: 
     242        if attrib is None: 
    241243            attrib = {} 
    242244        return etree.Element(name, attrib, nsmap) 
     
    297299        """ 
    298300        text = str(text) 
    299         if attrib == None: 
     301        if attrib is None: 
    300302            attrib = {} 
    301303        elem = E(elementname, attrib, text) 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    rc94280c r7f75a3f  
    1313    TransmissionSpectrum, Detector 
    1414from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
     15from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    1516 
    1617 
     
    7576            if extension in self.ext or self.allow_all: 
    7677                # Load the data file 
    77                 self.raw_data = h5py.File(filename, 'r') 
     78                try: 
     79                    self.raw_data = h5py.File(filename, 'r') 
     80                except Exception as e: 
     81                    raise FileContentsException, e 
    7882                # Read in all child elements of top level SASroot 
    7983                self.read_children(self.raw_data, []) 
Note: See TracChangeset for help on using the changeset viewer.