Ignore:
Timestamp:
Oct 20, 2016 3:54:06 PM (8 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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
880e845, cf1910f
Parents:
8b645cc
Message:

Fixes #738: No errors are thrown on loading projects with fits, plus linting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/pagestate.py

    r467202f rc8e1996  
    4646                            ["npts", "npts", "float"], 
    4747                            ["categorycombobox", "categorycombobox", "string"], 
    48                             ["formfactorcombobox", "formfactorcombobox", "string"], 
    49                             ["structurecombobox", "structurecombobox", "string"], 
     48                            ["formfactorcombobox", "formfactorcombobox", 
     49                             "string"], 
     50                            ["structurecombobox", "structurecombobox", 
     51                             "string"], 
    5052                            ["multi_factor", "multi_factor", "float"], 
    5153                            ["magnetic_on", "magnetic_on", "bool"], 
     
    6567                            ["smearer", "smearer", "float"], 
    6668                            ["smear_type", "smear_type", "string"], 
    67                             ["dq_l", "dq_l", "string"], 
    68                             ["dq_r", "dq_r", "string"], 
     69                            ["dq_l", "dq_l", "float"], 
     70                            ["dq_r", "dq_r", "float"], 
    6971                            ["dx_max", "dx_max", "float"], 
    7072                            ["dx_min", "dx_min", "float"], 
     
    8082                            ["str_parameters", "str_parameters"], 
    8183                            ["orientation_parameters", "orientation_params"], 
    82                             ["dispersity_parameters", "orientation_params_disp"], 
     84                            ["dispersity_parameters", 
     85                             "orientation_params_disp"], 
    8386                            ["fixed_param", "fixed_param"], 
    8487                            ["fittable_param", "fittable_param"]] 
     
    120123            try: 
    121124                return node.get(item[0]).strip() == "True" 
    122             except: 
     125            except Exception: 
    123126                return None 
    124127        else: 
    125128            try: 
    126129                return float(node.get(item[0])) 
    127             except: 
     130            except Exception: 
    128131                return None 
    129132 
     
    188191        # page name 
    189192        self.page_name = "" 
    190         # Contains link between model, all its parameters, and panel organization 
     193        # Contains link between model, its parameters, and panel organization 
    191194        self.parameters = [] 
    192195        # String parameter list that can not be fitted 
     
    305308        obj.fittable_param = copy.deepcopy(self.fittable_param) 
    306309        obj.orientation_params = copy.deepcopy(self.orientation_params) 
    307         obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) 
     310        obj.orientation_params_disp = \ 
     311            copy.deepcopy(self.orientation_params_disp) 
    308312        obj.enable_disp = copy.deepcopy(self.enable_disp) 
    309313        obj.disable_disp = copy.deepcopy(self.disable_disp) 
     
    397401        rep += "data : %s\n" % str(self.data) 
    398402        rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \ 
    399                (str(self.qmin),str(self.qmax), str(self.npts)) 
     403               (str(self.qmin), str(self.qmax), str(self.npts)) 
    400404        rep += "Dispersion selection : %s\n" % str(self.disp_box) 
    401405        rep += "Smearing enable : %s\n" % str(self.enable_smearer) 
     
    413417 
    414418        rep += "2D enable : %s\n" % str(self.enable2D) 
    415         rep += "All parameters checkbox selected: %s\n" % str(self.cb1) 
     419        rep += "All parameters checkbox selected: %s\n" % self.cb1 
    416420        rep += "Value of Chisqr : %s\n" % str(self.tcChi) 
    417         rep += "Smear object : %s\n" % str(self.smearer) 
    418         rep += "Smear type : %s\n" % str(self.smear_type) 
     421        rep += "Smear object : %s\n" % self.smearer 
     422        rep += "Smear type : %s\n" % self.smear_type 
    419423        rep += "dq_l  : %s\n" % self.dq_l 
    420424        rep += "dq_r  : %s\n" % self.dq_r 
     
    478482                value = content[1] 
    479483            except Exception: 
    480                 msg = "Report string expected 'name: value' but got %r"%line 
     484                msg = "Report string expected 'name: value' but got %r" % line 
    481485                logging.error(msg) 
    482486            if name.count("State created"): 
     
    493497            if name == "value": 
    494498                param_string += value + ',' 
     499            fixed_parameter = False 
    495500            if name == "selected": 
    496501                if value == u' False': 
    497502                    fixed_parameter = True 
    498                 else: 
    499                     fixed_parameter = False 
    500503            if name == "error value": 
    501504                if fixed_parameter: 
     
    617620        dialog.Show() 
    618621 
    619     def _toXML_helper(self, thelist, element, newdoc): 
     622    def _to_xml_helper(self, thelist, element, newdoc): 
    620623        """ 
    621624        Helper method to create xml file for saving state 
     
    635638            element.appendChild(sub_element) 
    636639 
    637     def toXML(self, file="fitting_state.fitv", doc=None, 
    638               entry_node=None, batch_fit_state=None): 
     640    def to_xml(self, file="fitting_state.fitv", doc=None, 
     641               entry_node=None, batch_fit_state=None): 
    639642        """ 
    640643        Writes the state of the fit panel to file, as XML. 
     
    648651        :param entry_node: XML node within the XML document at which we 
    649652                           will append the data [optional] 
     653        :param batch_fit_state: simultaneous fit state 
    650654        """ 
    651655        from xml.dom.minidom import getDOMImplementation 
     
    746750        for item in LIST_OF_STATE_PARAMETERS: 
    747751            element = newdoc.createElement(item[0]) 
    748             self._toXML_helper(thelist=getattr(self, item[1]), 
    749                                element=element, newdoc=newdoc) 
     752            self._to_xml_helper(thelist=getattr(self, item[1]), 
     753                                element=element, newdoc=newdoc) 
    750754            inputs.appendChild(element) 
    751755 
     
    765769            for constraint in batch_fit_state.constraints_list: 
    766770                if constraint.model_cbox.GetValue() != "": 
    767                     # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer 
     771                    # model_cbox, param_cbox, egal_txt, constraint, 
     772                    # btRemove, sizer 
    768773                    doc_cons = newdoc.createElement('constraint') 
    769774                    doc_cons.setAttribute('model_cbox', 
     
    808813            return newdoc 
    809814 
    810     def _fromXML_helper(self, node, list): 
     815    def _from_xml_helper(self, node, list): 
    811816        """ 
    812817        Helper function to write state to xml 
     
    858863                         [maximum_displayed, maximum_value], unit]) 
    859864 
    860     def fromXML(self, file=None, node=None): 
     865    def from_xml(self, file=None, node=None): 
    861866        """ 
    862867        Load fitting state from a file 
     
    887892                    logging.error(msg) 
    888893 
    889             # Parse fitting attributes 
    890             entry = get_content('ns:Attributes', node) 
    891             for item in LIST_OF_DATA_ATTRIBUTES: 
    892                 node = get_content('ns:%s' % item[0], entry) 
    893                 setattr(self, item[0], parse_entry_helper(node, item)) 
    894  
    895894            if entry is not None: 
     895                # Parse fitting attributes 
     896                entry = get_content('ns:Attributes', node) 
     897                for item in LIST_OF_DATA_ATTRIBUTES: 
     898                    node = get_content('ns:%s' % item[0], entry) 
     899                    setattr(self, item[0], parse_entry_helper(node, item)) 
     900 
    896901                for item in LIST_OF_STATE_ATTRIBUTES: 
    897902                    node = get_content('ns:%s' % item[0], entry) 
     
    900905                for item in LIST_OF_STATE_PARAMETERS: 
    901906                    node = get_content("ns:%s" % item[0], entry) 
    902                     self._fromXML_helper(node=node, list=getattr(self, item[1])) 
     907                    self._from_xml_helper(node=node, 
     908                                          list=getattr(self, item[1])) 
    903909 
    904910                # Recover _disp_obj_dict from xml file 
     
    950956        """ 
    951957        images = [] 
    952         # some imports 
    953         import wx 
    954958 
    955959        # Reset memory 
     
    958962 
    959963        # For no figures in the list, prepare empty plot 
    960         if figs == None or len(figs) == 0: 
     964        if figs is None or len(figs) == 0: 
    961965            figs = [None] 
    962966 
     
    965969        self.imgRAM = wx.MemoryFSHandler() 
    966970        for fig in figs: 
    967             if figs != None: 
     971            if fig is not None: 
    968972                ind = figs.index(fig) 
    969973                canvas = canvases[ind] 
    970974 
    971             #store the image in wx.FileSystem Object 
     975            # store the image in wx.FileSystem Object 
    972976            wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 
    973977 
     
    975979            ind = figs.index(fig) 
    976980 
    977             #AddFile, image can be retrieved with 'memory:filename' 
     981            # AddFile, image can be retrieved with 'memory:filename' 
    978982            self.imgRAM.AddFile('img_fit%s.png' % ind, 
    979983                                canvas.bitmap, wx.BITMAP_TYPE_PNG) 
    980984 
    981             #append figs 
     985            # append figs 
    982986            images.append(fig) 
    983987 
     
    989993    Class to load a .fitv fitting file 
    990994    """ 
    991     ## File type 
     995    # File type 
    992996    type_name = "Fitting" 
    993997 
    994     ## Wildcards 
     998    # Wildcards 
    995999    type = ["Fitting files (*.fitv)|*.fitv" 
    9961000            "SASView file (*.svs)|*.svs"] 
    997     ## List of allowed extensions 
     1001    # List of allowed extensions 
    9981002    ext = ['.fitv', '.FITV', '.svs', 'SVS'] 
    9991003 
     
    10091013 
    10101014        """ 
    1011         ## Call back method to be executed after a file is read 
     1015        # Call back method to be executed after a file is read 
    10121016        self.call_back = call_back 
    1013         ## CanSAS format flag 
     1017        # CanSAS format flag 
    10141018        self.cansas = cansas 
    10151019        self.state = None 
     
    10271031 
    10281032        """ 
    1029         if self.cansas == True: 
     1033        if self.cansas: 
    10301034            return self._read_cansas(path) 
    10311035 
     
    10611065        for item in datainfo.run: 
    10621066            runname = {} 
    1063             if datainfo.run_name.has_key(item) and \ 
     1067            if item in datainfo.run_name and \ 
    10641068                            len(str(datainfo.run_name[item])) > 1: 
    10651069                runname = {'name': datainfo.run_name[item]} 
     
    10761080            root_node = doc.createElement(item[0]) 
    10771081            new_node.appendChild(root_node) 
    1078             temp_list = None 
    10791082            temp_list = getattr(datainfo, item[1]) 
    10801083 
     
    11131116                                       datainfo.sample.position.z, 
    11141117                                       {"unit": datainfo.sample.position_unit}) 
    1115         if written == True: 
     1118        if written: 
    11161119            sample.appendChild(pos) 
    11171120 
     
    11211124        written = written | write_node(doc, ori, "pitch", 
    11221125                                       datainfo.sample.orientation.y, 
    1123                                        {"unit": datainfo.sample.orientation_unit}) 
     1126                                       {"unit": 
     1127                                            datainfo.sample.orientation_unit}) 
    11241128        written = written | write_node(doc, ori, "yaw", 
    11251129                                       datainfo.sample.orientation.z, 
    1126                                        {"unit": datainfo.sample.orientation_unit}) 
    1127         if written == True: 
     1130                                       {"unit": 
     1131                                            datainfo.sample.orientation_unit}) 
     1132        if written: 
    11281133            sample.appendChild(ori) 
    11291134 
     
    11531158                                       datainfo.source.beam_size.z, 
    11541159                                       {"unit": datainfo.source.beam_size_unit}) 
    1155         if written == True: 
     1160        if written: 
    11561161            source.appendChild(size) 
    11571162 
     
    11981203                written = written | write_node(doc, size, "z", apert.size.z, 
    11991204                                               {"unit": apert.size_unit}) 
    1200                 if written == True: 
     1205                if written: 
    12011206                    ap.appendChild(size) 
    12021207 
     
    12101215                                           item.slit_length, 
    12111216                                           {"unit": item.slit_length_unit}) 
    1212             if written == True: 
     1217            if written: 
    12131218                instr.appendChild(det) 
    12141219 
     
    12201225            written = written | write_node(doc, off, "z", item.offset.z, 
    12211226                                           {"unit": item.offset_unit}) 
    1222             if written == True: 
     1227            if written: 
    12231228                det.appendChild(off) 
    12241229 
     
    12321237                                           item.beam_center.z, 
    12331238                                           {"unit": item.beam_center_unit}) 
    1234             if written == True: 
     1239            if written: 
    12351240                det.appendChild(center) 
    12361241 
     
    12421247            written = written | write_node(doc, pix, "z", item.pixel_size.z, 
    12431248                                           {"unit": item.pixel_size_unit}) 
    1244             if written == True: 
     1249            if written: 
    12451250                det.appendChild(pix) 
    12461251 
     
    12531258            written = written | write_node(doc, ori, "yaw", item.orientation.z, 
    12541259                                           {"unit": item.orientation_unit}) 
    1255             if written == True: 
     1260            if written: 
    12561261                det.appendChild(ori) 
    12571262 
     
    12901295                # Create an empty state 
    12911296                state = PageState() 
    1292                 state.fromXML(node=nodes[0]) 
     1297                state.from_xml(node=nodes[0]) 
    12931298 
    12941299        except: 
     
    13141319                simfitstate_0 = simfitstate[0] 
    13151320                all = simfitstate_0.xpath('ns:select_all', 
    1316                                         namespaces={'ns': CANSAS_NS}) 
     1321                                          namespaces={'ns': CANSAS_NS}) 
    13171322                atts = all[0].attrib 
    13181323                checked = atts.get('checked') 
    13191324                sim_fit_state.select_all = bool(checked) 
    13201325                model_list = simfitstate_0.xpath('ns:model_list', 
    1321                                                namespaces={'ns': CANSAS_NS}) 
     1326                                                 namespaces={'ns': CANSAS_NS}) 
    13221327                model_list_items = model_list[0].xpath('ns:model_list_item', 
    1323                                                    namespaces={'ns': CANSAS_NS}) 
     1328                                                       namespaces={'ns': 
     1329                                                                    CANSAS_NS}) 
    13241330                for model in model_list_items: 
    13251331                    attrs = model.attrib 
     
    13681374            return return_value, _ 
    13691375 
    1370         #Parse 2D 
     1376        # Parse 2D 
    13711377        data_info = Data2D() 
    13721378 
     
    15901596        for entry in nodes: 
    15911597            for item in LIST_OF_DATA_2D_ATTR: 
    1592                 #get node 
     1598                # get node 
    15931599                node = get_content('ns:%s' % item[0], entry) 
    15941600                setattr(data_info, item[1], parse_entry_helper(node, item)) 
     
    16331639                    entry_list = root.xpath('ns:SASentry', 
    16341640                                            namespaces={'ns': CANSAS_NS}) 
    1635                     name_map = {} 
    16361641                    for entry in entry_list: 
    16371642                        try: 
     
    16791684                        state.data.is_data = state.is_data 
    16801685                    if output[ind].run_name is not None\ 
    1681                         and len(output[ind].run_name) != 0: 
     1686                         and len(output[ind].run_name) != 0: 
    16821687                        if isinstance(output[ind].run_name, dict): 
    16831688                            name = output[ind].run_name.keys()[0] 
     
    17151720            # Write the XML document 
    17161721        else: 
    1717             doc = fitstate.toXML(file=filename) 
     1722            doc = fitstate.to_xml(file=filename) 
    17181723 
    17191724        # Save the document no matter the type 
     
    17491754 
    17501755        if state is not None: 
    1751             doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry, 
    1752                               batch_fit_state=self.batchfit_params) 
     1756            doc = state.to_xml(doc=doc, file=data.filename, entry_node=sasentry, 
     1757                               batch_fit_state=self.batchfit_params) 
    17531758 
    17541759        return doc 
Note: See TracChangeset for help on using the changeset viewer.