Ignore:
Timestamp:
Mar 12, 2015 10:32:02 AM (9 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
7d64b0e
Parents:
6b0fc72
Message:

Modified the cansas reader and the dataloader to be more explicit in the
errors that occurred when loading data files. Also, only each error now
only appears a single time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/dataloader/readers/cansas_reader.py

    r9dedf40 rd26dea0  
    105105    base_ns = "{cansas1d/1.0}" 
    106106 
    107     logging = [] 
    108     errors = [] 
     107    logging = None 
     108    errors = None 
    109109 
    110110    type_name = "canSAS" 
     
    120120    def __init__(self): 
    121121        ## List of errors 
    122         self.errors = [] 
     122        self.errors = set() 
     123        self.logging = [] 
    123124        self.encoding = None 
    124125 
     
    252253        for error in self.errors: 
    253254            data1d.errors.append(error) 
    254         del self.errors[:] 
     255        self.errors.clear() 
    255256        numpy.trim_zeros(data1d.x) 
    256257        numpy.trim_zeros(data1d.y) 
     
    301302        attr = node.attrib 
    302303        value_unit = '' 
     304        err_msg = None 
    303305        if 'unit' in attr and new_current_level.get('unit') is not None: 
    304306            try: 
     
    322324                        value_unit = local_unit 
    323325                        err_msg = "Unit converter is not available.\n" 
    324                         self.errors.append(err_msg) 
    325326                else: 
    326327                    value_unit = local_unit 
     
    333334                            ".format(data1d.{0})" 
    334335                exec intermediate.format(unitname, "{0}", "{1}") 
    335                 self.errors.append(err_msg) 
    336336                value_unit = local_unit 
    337337            except: 
     
    340340                err_msg += "\"{0}\" unit [{1}]" 
    341341                err_msg = err_msg.format(tagname, local_unit) 
    342                 self.errors.append(err_msg) 
    343342                value_unit = local_unit 
    344343        elif 'unit' in attr: 
    345344            value_unit = attr['unit'] 
     345        if err_msg: 
     346            self.errors.add(err_msg) 
    346347        node_value = "float({0})".format(node_value) 
    347348        return node_value, value_unit 
     
    355356        """ 
    356357        if data1d == None: 
    357             self.errors = [] 
     358            self.errors = set() 
    358359            x_vals = numpy.empty(0) 
    359360            y_vals = numpy.empty(0) 
     
    697698            node.append(point) 
    698699            self.write_node(point, "Q", datainfo.x[i], 
    699                             {'unit': datainfo.x_unit}) 
     700                            {'unit': datainfo._xunit}) 
    700701            if len(datainfo.y) >= i: 
    701702                self.write_node(point, "I", datainfo.y[i], 
    702                                 {'unit': datainfo.y_unit}) 
     703                                {'unit': datainfo._yunit}) 
    703704            if datainfo.dy != None and len(datainfo.dy) > i: 
    704705                self.write_node(point, "Idev", datainfo.dy[i], 
    705                                 {'unit': datainfo.y_unit}) 
     706                                {'unit': datainfo._yunit}) 
    706707            if datainfo.dx != None and len(datainfo.dx) > i: 
    707708                self.write_node(point, "Qdev", datainfo.dx[i], 
    708                                 {'unit': datainfo.x_unit}) 
     709                                {'unit': datainfo._xunit}) 
    709710            if datainfo.dxw != None and len(datainfo.dxw) > i: 
    710711                self.write_node(point, "dQw", datainfo.dxw[i], 
    711                                 {'unit': datainfo.x_unit}) 
     712                                {'unit': datainfo._xunit}) 
    712713            if datainfo.dxl != None and len(datainfo.dxl) > i: 
    713714                self.write_node(point, "dQl", datainfo.dxl[i], 
    714                                 {'unit': datainfo.x_unit}) 
     715                                {'unit': datainfo._xunit}) 
    715716 
    716717    def _write_trans_spectrum(self, datainfo, entry_node): 
     
    11691170                            err_mess += " %s unit [%s]; expecting [%s]\n  %s" \ 
    11701171                                % (variable, units, local_unit, exc_value) 
    1171                             self.errors.append(err_mess) 
     1172                            self.errors.add(err_mess) 
    11721173                            if optional: 
    11731174                                logging.info(err_mess) 
     
    11781179                        % (variable, units) 
    11791180                        err_mess += " expecting [%s]" % local_unit 
    1180                         self.errors.append(err_mess) 
     1181                        self.errors.add(err_mess) 
    11811182                        if optional: 
    11821183                            logging.info(err_mess) 
Note: See TracChangeset for help on using the changeset viewer.