Changeset 5c4b674 in sasview for guiframe/state_reader.py


Ignore:
Timestamp:
Mar 2, 2011 4:35:08 PM (13 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
883e5f5
Parents:
22b3fe1
Message:

working on data panel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/state_reader.py

    ra07e72f r5c4b674  
    3939from lxml import etree 
    4040import xml.dom.minidom 
    41 from DataLoader.readers.cansas_reader import Reader as CansasReader 
     41 
    4242has_converter = True 
    4343try: 
     
    4646    has_converter = False 
    4747 
    48 CANSAS_NS = "cansas1d/1.0" 
     48STATE_NS = "State/1.0" 
    4949 
    5050def write_node(doc, parent, name, value, attr={}): 
     
    7676    :return: Element, or None 
    7777    """ 
    78     nodes = node.xpath(location, namespaces={'ns': CANSAS_NS}) 
     78    nodes = node.xpath(location, namespaces={'ns': STATE_NODE}) 
    7979     
    8080    if len(nodes)>0: 
     
    9090    :param node: node to start at 
    9191    """ 
    92     nodes = node.xpath(location, namespaces={'ns': CANSAS_NS}) 
     92    nodes = node.xpath(location, namespaces={'ns': STATE_NODE}) 
    9393     
    9494    value = None 
     
    9999        except: 
    100100            # Could not pass, skip and return None 
    101             msg = "cansas_reader.get_float: could not " 
     101            msg = "state_reader.get_float: could not " 
    102102            msg += " convert '%s' to float" % nodes[0].text 
    103103            logging.error(msg) 
     
    107107 
    108108             
    109 class Reader1D(CansasReader): 
     109class Reader1D: 
    110110    """ 
    111     Class to load cansas 1D XML files 
     111    read state of a plugin  and available data  
    112112     
    113113    :Dependencies: 
     
    125125     
    126126    def __init__(self): 
    127         CansasReader.__init__(self) 
    128127        ## List of errors 
    129128        self.errors = [] 
     
    155154                 
    156155                entry_list = root.xpath('/ns:SASroot/ns:SASentry', 
    157                                          namespaces={'ns': CANSAS_NS}) 
     156                                         namespaces={'ns': STATE_NODE}) 
    158157                 
    159158                for entry in entry_list: 
     
    196195         
    197196        # Look up run number    
    198         nodes = dom.xpath('ns:Run', namespaces={'ns': CANSAS_NS}) 
     197        nodes = dom.xpath('ns:Run', namespaces={'ns': STATE_NODE}) 
    199198        for item in nodes:     
    200199            if item.text is not None: 
     
    210209 
    211210        # Notes 
    212         note_list = dom.xpath('ns:SASnote', namespaces={'ns': CANSAS_NS}) 
     211        note_list = dom.xpath('ns:SASnote', namespaces={'ns': STATE_NODE}) 
    213212        for note in note_list: 
    214213            try: 
     
    218217                        data_info.notes.append(note_value) 
    219218            except: 
    220                 err_mess = "cansas_reader.read: error processing" 
     219                err_mess = "state_reader.read: error processing" 
    221220                err_mess += " entry notes\n  %s" % sys.exc_value 
    222221                self.errors.append(err_mess) 
     
    238237         
    239238        nodes = dom.xpath('ns:SASsample/ns:details',  
    240                           namespaces={'ns': CANSAS_NS}) 
     239                          namespaces={'ns': STATE_NODE}) 
    241240        for item in nodes: 
    242241            try: 
     
    246245                        data_info.sample.details.append(detail_value) 
    247246            except: 
    248                 err_mess = "cansas_reader.read: error processing " 
     247                err_mess = "state_reader.read: error processing " 
    249248                err_mess += " sample details\n  %s" % sys.exc_value 
    250249                self.errors.append(err_mess) 
     
    299298        # Collimation info ################### 
    300299        nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation',  
    301                           namespaces={'ns': CANSAS_NS}) 
     300                          namespaces={'ns': STATE_NODE}) 
    302301        for item in nodes: 
    303302            collim = Collimation() 
     
    307306             
    308307            # Look for apertures 
    309             apert_list = item.xpath('ns:aperture', namespaces={'ns': CANSAS_NS}) 
     308            apert_list = item.xpath('ns:aperture', namespaces={'ns': STATE_NODE}) 
    310309            for apert in apert_list: 
    311310                aperture =  Aperture() 
     
    331330        # Detector info ###################### 
    332331        nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', 
    333                            namespaces={'ns': CANSAS_NS}) 
     332                           namespaces={'ns': STATE_NODE}) 
    334333        for item in nodes: 
    335334             
     
    373372 
    374373        # Processes info ###################### 
    375         nodes = dom.xpath('ns:SASprocess', namespaces={'ns': CANSAS_NS}) 
     374        nodes = dom.xpath('ns:SASprocess', namespaces={'ns': STATE_NODE}) 
    376375        for item in nodes: 
    377376            process = Process() 
     
    380379            self._store_content('ns:description', item, 'description', process) 
    381380             
    382             term_list = item.xpath('ns:term', namespaces={'ns': CANSAS_NS}) 
     381            term_list = item.xpath('ns:term', namespaces={'ns': STATE_NODE}) 
    383382            for term in term_list: 
    384383                try: 
     
    390389                        process.term.append(term_attr) 
    391390                except: 
    392                     err_mess = "cansas_reader.read: error processing " 
     391                    err_mess = "state_reader.read: error processing " 
    393392                    err_mess += " process term\n  %s" % sys.exc_value 
    394393                    self.errors.append(err_mess) 
     
    396395             
    397396            note_list = item.xpath('ns:SASprocessnote',  
    398                                    namespaces={'ns': CANSAS_NS}) 
     397                                   namespaces={'ns': STATE_NODE}) 
    399398            for note in note_list: 
    400399                if note.text is not None: 
     
    405404             
    406405        # Data info ###################### 
    407         nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 
     406        nodes = dom.xpath('ns:SASdata', namespaces={'ns': STATE_NODE}) 
    408407        if len(nodes) > 1: 
    409408            msg = "CanSAS reader is not compatible with multiple" 
     
    411410            raise RuntimeError, msg 
    412411         
    413         nodes = dom.xpath('ns:SASdata/ns:Idata', namespaces={'ns': CANSAS_NS}) 
     412        nodes = dom.xpath('ns:SASdata/ns:Idata', namespaces={'ns': STATE_NODE}) 
    414413 
    415414        x  = numpy.zeros(0) 
     
    634633                write_node(doc, pt, "Idev", datainfo.dy[i], 
    635634                            {'unit':datainfo.y_unit}) 
    636  
    637          
     635        #data gui info 
     636        gui_info = doc.createElement("DataInfoGui") 
     637         
     638        write_node(doc, gui_info, "group_id", 'group_id') 
     639        for item in datainfo.group_id: 
     640            write_node(doc, gui_info, "group_id", str(item)) 
     641        write_node(doc, gui_info, "name", datainfo.name) 
     642        write_node(doc, gui_info, "id", datainfo.id) 
     643        write_node(doc, gui_info, "group_id", datainfo.groud_id) 
     644        write_node(doc, gui_info, "name", datainfo.name) 
     645        write_node(doc, gui_info, "is_data", datainfo.is_data) 
     646        write_node(doc, gui_info, "xtransform", datainfo.xtransform) 
     647        write_node(doc, gui_info, "scale", datainfo.scale) 
     648        write_node(doc, gui_info, "ytransform", datainfo.ytransform) 
     649        write_node(doc, gui_info, "path", datainfo.path) 
     650        node.appendChild(gui_info) 
    638651        # Sample info 
    639652        sample = doc.createElement("SASsample") 
     
    922935            
    923936 
    924 class Reader2D(CansasReader): 
     937class Reader2D: 
    925938    """ 
    926     Class to load a .fitv fitting file 
     939    Class to load a basic guiframe state 
    927940    """ 
    928941    ## File type 
     
    11541167        return doc, entry_node 
    11551168    
    1156     def _parse_state(self, entry): 
     1169    def _parse_state(self, entry, NODE_NAME= 'state'): 
    11571170        """ 
    11581171        Read a fit result from an XML node 
     
    11661179        # Locate the P(r) node 
    11671180        try: 
    1168             nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, namespaces={'ns': CANSAS_NS}) 
     1181            nodes = entry.xpath('ns:%s' % NODE_NAME, namespaces={'ns': STATE_NODE}) 
    11691182            if nodes !=[]: 
    11701183                # Create an empty state 
     
    11871200         
    11881201        """ 
    1189         node = dom.xpath('ns:data_class', namespaces={'ns': CANSAS_NS}) 
     1202        node = dom.xpath('ns:data_class', namespaces={'ns': STATE_NODE}) 
    11901203        if not node or node[0].text.lstrip().rstrip() != "Data2D": 
    11911204            return CansasReader._parse_entry(self, dom) 
     
    11981211         
    11991212        # Look up run number    
    1200         nodes = dom.xpath('ns:Run', namespaces={'ns': CANSAS_NS}) 
     1213        nodes = dom.xpath('ns:Run', namespaces={'ns': STATE_NODE}) 
    12011214        for item in nodes:     
    12021215            if item.text is not None: 
     
    12111224 
    12121225        # Notes 
    1213         note_list = dom.xpath('ns:SASnote', namespaces={'ns': CANSAS_NS}) 
     1226        note_list = dom.xpath('ns:SASnote', namespaces={'ns': STATE_NODE}) 
    12141227        for note in note_list: 
    12151228            try: 
     
    12191232                        data_info.notes.append(note_value) 
    12201233            except: 
    1221                 err_mess = "cansas_reader.read: error processing entry notes\n  %s" % sys.exc_value 
     1234                err_mess = "state_reader.read: error processing entry notes\n  %s" % sys.exc_value 
    12221235                self.errors.append(err_mess) 
    12231236                logging.error(err_mess) 
     
    12371250                     dom, 'temperature', data_info.sample) 
    12381251         
    1239         nodes = dom.xpath('ns:SASsample/ns:details', namespaces={'ns': CANSAS_NS}) 
     1252        nodes = dom.xpath('ns:SASsample/ns:details', namespaces={'ns': STATE_NODE}) 
    12401253        for item in nodes: 
    12411254            try: 
     
    12451258                        data_info.sample.details.append(detail_value) 
    12461259            except: 
    1247                 err_mess = "cansas_reader.read: error processing sample details\n  %s" % sys.exc_value 
     1260                err_mess = "state_reader.read: error processing sample details\n  %s" % sys.exc_value 
    12481261                self.errors.append(err_mess) 
    12491262                logging.error(err_mess) 
     
    12961309         
    12971310        # Collimation info ################### 
    1298         nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation', namespaces={'ns': CANSAS_NS}) 
     1311        nodes = dom.xpath('ns:SASinstrument/ns:SAScollimation', namespaces={'ns': STATE_NODE}) 
    12991312        for item in nodes: 
    13001313            collim = Collimation() 
     
    13041317             
    13051318            # Look for apertures 
    1306             apert_list = item.xpath('ns:aperture', namespaces={'ns': CANSAS_NS}) 
     1319            apert_list = item.xpath('ns:aperture', namespaces={'ns': STATE_NODE}) 
    13071320            for apert in apert_list: 
    13081321                aperture =  Aperture() 
     
    13271340         
    13281341        # Detector info ###################### 
    1329         nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', namespaces={'ns': CANSAS_NS}) 
     1342        nodes = dom.xpath('ns:SASinstrument/ns:SASdetector', namespaces={'ns': STATE_NODE}) 
    13301343        for item in nodes: 
    13311344             
     
    13601373 
    13611374        # Processes info ###################### 
    1362         nodes = dom.xpath('ns:SASprocess', namespaces={'ns': CANSAS_NS}) 
     1375        nodes = dom.xpath('ns:SASprocess', namespaces={'ns': STATE_NODE}) 
    13631376        for item in nodes: 
    13641377            process = Process() 
     
    13671380            self._store_content('ns:description', item, 'description', process) 
    13681381             
    1369             term_list = item.xpath('ns:term', namespaces={'ns': CANSAS_NS}) 
     1382            term_list = item.xpath('ns:term', namespaces={'ns': STATE_NODE}) 
    13701383            for term in term_list: 
    13711384                try: 
     
    13771390                        process.term.append(term_attr) 
    13781391                except: 
    1379                     err_mess = "cansas_reader.read: error processing process term\n  %s" % sys.exc_value 
     1392                    err_mess = "state_reader.read: error processing process term\n  %s" % sys.exc_value 
    13801393                    self.errors.append(err_mess) 
    13811394                    logging.error(err_mess) 
    13821395             
    1383             note_list = item.xpath('ns:SASprocessnote', namespaces={'ns': CANSAS_NS}) 
     1396            note_list = item.xpath('ns:SASprocessnote', namespaces={'ns': STATE_NODE}) 
    13841397            for note in note_list: 
    13851398                if note.text is not None: 
     
    13901403             
    13911404        # Data info ###################### 
    1392         nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 
     1405        nodes = dom.xpath('ns:SASdata', namespaces={'ns': STATE_NODE}) 
    13931406        if len(nodes)>1: 
    13941407            raise RuntimeError, "CanSAS reader is not compatible with multiple SASdata entries" 
     
    14391452                    # Specifying the namespace will take care of the file format version  
    14401453                    root = tree.getroot() 
    1441                     entry_list = root.xpath('ns:SASentry', namespaces={'ns': CANSAS_NS}) 
     1454                    entry_list = root.xpath('ns:SASentry', namespaces={'ns': STATE_NODE}) 
    14421455                    for entry in entry_list:    
    14431456                        try: 
     
    15871600    logging.basicConfig(level=logging.ERROR, 
    15881601                        format='%(asctime)s %(levelname)s %(message)s', 
    1589                         filename='cansas_reader.log', 
     1602                        filename='state_reader.log', 
    15901603                        filemode='w') 
    15911604    reader = Reader() 
Note: See TracChangeset for help on using the changeset viewer.