Ignore:
Timestamp:
Apr 9, 2017 5:38:18 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, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
46d210d, b61bd57, 2ab812d
Parents:
8eb9043
git-author:
Jeff Krzywon <krzywon@…> (04/09/17 05:38:18)
git-committer:
krzywon <krzywon@…> (04/09/17 05:38:18)
Message:

Loading XML files saved through no longer throwing errors. see #938

File:
1 edited

Legend:

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

    r8434365 r527a190  
    156156                    # If the file does not match the schema, raise this error 
    157157                    invalid_xml = self.find_invalid_xml() 
    158                     invalid_xml = INVALID_XML.format(basename + extension) + invalid_xml 
    159                     self.errors.add(invalid_xml) 
     158                    if invalid_xml != "": 
     159                        invalid_xml = INVALID_XML.format(basename + extension) + invalid_xml 
     160                        self.errors.add(invalid_xml) 
    160161                    # Try again with an invalid CanSAS schema, that requires only a data set in each 
    161162                    base_name = xml_reader.__file__ 
     
    261262                # I and Q - 1D data 
    262263                elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 
    263                     unit_list = unit.split("|") 
    264                     if len(unit_list) > 1: 
    265                         self.current_dataset.yaxis(unit_list[0].strip(), 
    266                                                    unit_list[1].strip()) 
    267                     else: 
    268                         self.current_dataset.yaxis("Intensity", unit) 
     264                    self.current_dataset.yaxis("Intensity", unit) 
    269265                    self.current_dataset.y = np.append(self.current_dataset.y, data_point) 
    270266                elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 
    271267                    self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 
    272268                elif tagname == 'Q': 
    273                     unit_list = unit.split("|") 
    274                     if len(unit_list) > 1: 
    275                         self.current_dataset.xaxis(unit_list[0].strip(), 
    276                                                    unit_list[1].strip()) 
    277                     else: 
    278                         self.current_dataset.xaxis("Q", unit) 
     269                    self.current_dataset.xaxis("Q", unit) 
    279270                    self.current_dataset.x = np.append(self.current_dataset.x, data_point) 
    280271                elif tagname == 'Qdev': 
     
    290281                elif tagname == 'Sesans': 
    291282                    self.current_datainfo.isSesans = bool(data_point) 
     283                    self.current_dataset.xaxis(attr.get('x_axis'), 
     284                                                attr.get('x_unit')) 
     285                    self.current_dataset.yaxis(attr.get('y_axis'), 
     286                                                attr.get('y_unit')) 
    292287                elif tagname == 'zacceptance': 
    293288                    self.current_datainfo.sample.zacceptance = (data_point, unit) 
     
    781776                    value_unit = local_unit 
    782777            except KeyError: 
    783                 err_msg = "CanSAS reader: unexpected " 
    784                 err_msg += "\"{0}\" unit [{1}]; " 
    785                 err_msg = err_msg.format(tagname, local_unit) 
    786                 err_msg += "expecting [{0}]".format(default_unit) 
     778                # Do not throw an error for loading Sesans data in cansas xml 
     779                # This is a temporary fix. 
     780                if local_unit != "A" and local_unit != 'pol': 
     781                    err_msg = "CanSAS reader: unexpected " 
     782                    err_msg += "\"{0}\" unit [{1}]; " 
     783                    err_msg = err_msg.format(tagname, local_unit) 
     784                    err_msg += "expecting [{0}]".format(default_unit) 
    787785                value_unit = local_unit 
    788786            except: 
     
    10351033            node.append(point) 
    10361034            self.write_node(point, "Q", datainfo.x[i], 
    1037                             {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 
     1035                            {'unit': datainfo.x_unit}) 
    10381036            if len(datainfo.y) >= i: 
    10391037                self.write_node(point, "I", datainfo.y[i], 
    1040                                 {'unit': datainfo._yaxis + " | " + datainfo._yunit}) 
     1038                                {'unit': datainfo.y_unit}) 
    10411039            if datainfo.dy is not None and len(datainfo.dy) > i: 
    10421040                self.write_node(point, "Idev", datainfo.dy[i], 
    1043                                 {'unit': datainfo._yaxis + " | " + datainfo._yunit}) 
     1041                                {'unit': datainfo.y_unit}) 
    10441042            if datainfo.dx is not None and len(datainfo.dx) > i: 
    10451043                self.write_node(point, "Qdev", datainfo.dx[i], 
    1046                                 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 
     1044                                {'unit': datainfo.x_unit}) 
    10471045            if datainfo.dxw is not None and len(datainfo.dxw) > i: 
    10481046                self.write_node(point, "dQw", datainfo.dxw[i], 
    1049                                 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 
     1047                                {'unit': datainfo.x_unit}) 
    10501048            if datainfo.dxl is not None and len(datainfo.dxl) > i: 
    10511049                self.write_node(point, "dQl", datainfo.dxl[i], 
    1052                                 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 
     1050                                {'unit': datainfo.x_unit}) 
    10531051        if datainfo.isSesans: 
    1054             sesans = self.create_element("Sesans") 
     1052            sesans_attrib = {'x_axis': datainfo._xaxis, 
     1053                             'y_axis': datainfo._yaxis, 
     1054                             'x_unit': datainfo.x_unit, 
     1055                             'y_unit': datainfo.y_unit} 
     1056            sesans = self.create_element("Sesans", attrib=sesans_attrib) 
    10551057            sesans.text = str(datainfo.isSesans) 
    1056             node.append(sesans) 
    1057             self.write_node(node, "zacceptance", datainfo.sample.zacceptance[0], 
     1058            entry_node.append(sesans) 
     1059            self.write_node(entry_node, "zacceptance", datainfo.sample.zacceptance[0], 
    10581060                             {'unit': datainfo.sample.zacceptance[1]}) 
    10591061 
Note: See TracChangeset for help on using the changeset viewer.