Changeset 574adc7 in sasview for src/sas/sascalc/fit


Ignore:
Timestamp:
Sep 22, 2017 4:01:32 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
34d7b35
Parents:
9706d88
Message:

convert sascalc to python 2/3 syntax

Location:
src/sas/sascalc/fit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/sas/sascalc/fit/AbstractFitEngine.py

    r50fcb09 r574adc7  
    251251            msg = "FitData1D: invalid error array " 
    252252            msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 
    253             raise RuntimeError, msg 
     253            raise RuntimeError(msg) 
    254254        return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] 
    255255 
  • TabularUnified src/sas/sascalc/fit/Loader.py

    ra1b8fee r574adc7  
    1818        self.dy = dy 
    1919        self.filename = None 
    20          
     20 
    2121    def set_filename(self, path=None): 
    2222        """ 
    23         Store path into a variable.If the user doesn't give  
     23        Store path into a variable.If the user doesn't give 
    2424        a path as a parameter a pop-up 
    2525        window appears to select the file. 
    26          
     26 
    2727        :param path: the path given by the user 
    28          
     28 
    2929        """ 
    3030        self.filename = path 
    31         
     31 
    3232    def get_filename(self): 
    3333        """ return the file's path""" 
    3434        return self.filename 
    35      
     35 
    3636    def set_values(self): 
    3737        """ Store the values loaded from file in local variables""" 
     
    4242            self.x = [] 
    4343            self.y = [] 
    44             self.dx = []  
     44            self.dx = [] 
    4545            self.dy = [] 
    4646            for line in lines: 
     
    5050                    y = float(toks[1]) 
    5151                    dy = float(toks[2]) 
    52                      
     52 
    5353                    self.x.append(x) 
    5454                    self.y.append(y) 
     
    5959            # Sanity check 
    6060            if not len(self.x) == len(self.dx): 
    61                 raise ValueError, "x and dx have different length" 
     61                raise ValueError("x and dx have different length") 
    6262            if not len(self.y) == len(self.dy): 
    63                 raise ValueError, "y and dy have different length" 
    64              
    65              
     63                raise ValueError("y and dy have different length") 
     64 
     65 
    6666    def get_values(self): 
    6767        """ Return x, y, dx, dy""" 
    6868        return self.x, self.y, self.dx, self.dy 
    69      
     69 
    7070    def load_data(self, data): 
    7171        """ Return plottable""" 
     
    7777        #Load its View class 
    7878        #plottable.reset_view() 
    79         
    80      
    81 if __name__ == "__main__":  
     79 
     80 
     81if __name__ == "__main__": 
    8282    load = Load() 
    8383    load.set_filename("testdata_line.txt") 
    84     print(load.get_filename())  
     84    print(load.get_filename()) 
    8585    load.set_values() 
    8686    print(load.get_values()) 
    87      
    88              
     87 
  • TabularUnified src/sas/sascalc/fit/MultiplicationModel.py

    r7432acb r574adc7  
    109109        """ 
    110110        ##set dispersion only from p_model 
    111         for name , value in self.p_model.dispersion.iteritems(): 
     111        for name , value in self.p_model.dispersion.items(): 
    112112            self.dispersion[name] = value 
    113113 
     
    135135        """ 
    136136 
    137         for name , value in self.p_model.params.iteritems(): 
     137        for name , value in self.p_model.params.items(): 
    138138            if not name in self.params.keys() and name not in self.excluded_params: 
    139139                self.params[name] = value 
    140140 
    141         for name , value in self.s_model.params.iteritems(): 
     141        for name , value in self.s_model.params.items(): 
    142142            #Remove the radius_effective from the (P*S) model parameters. 
    143143            if not name in self.params.keys() and name not in self.excluded_params: 
     
    155155        this model's details 
    156156        """ 
    157         for name, detail in self.p_model.details.iteritems(): 
     157        for name, detail in self.p_model.details.items(): 
    158158            if name not in self.excluded_params: 
    159159                self.details[name] = detail 
    160160 
    161         for name , detail in self.s_model.details.iteritems(): 
     161        for name , detail in self.s_model.details.items(): 
    162162            if not name in self.details.keys() or name not in self.exluded_params: 
    163163                self.details[name] = detail 
     
    245245                    return 
    246246 
    247         raise ValueError, "Model does not contain parameter %s" % name 
     247        raise ValueError("Model does not contain parameter %s" % name) 
    248248 
    249249 
  • TabularUnified src/sas/sascalc/fit/expression.py

    ra1b8fee r574adc7  
    5959    occur multiple times.  The return value is a set with the elements in 
    6060    no particular order. 
    61      
     61 
    6262    This is the first step in computing a dependency graph. 
    6363    """ 
     
    8181        offset = end 
    8282    pieces.append(expr[offset:]) 
    83      
     83 
    8484    # Join the pieces and return them 
    8585    return "".join(pieces) 
     
    8888    """ 
    8989    Returns a list of pair-wise dependencies from the parameter expressions. 
    90      
     90 
    9191    For example, if p3 = p1+p2, then find_dependencies([p1,p2,p3]) will 
    9292    return [(p3,p1),(p3,p2)].  For base expressions without dependencies, 
     
    110110    """ 
    111111    Find the parameter substitution we need so that expressions can 
    112     be evaluated without having to traverse a chain of  
     112    be evaluated without having to traverse a chain of 
    113113    model.layer.parameter.value 
    114114    """ 
     
    122122    return definition, substitution 
    123123 
    124 def no_constraints():  
     124def no_constraints(): 
    125125    """ 
    126126    This parameter set has no constraints between the parameters. 
     
    163163 
    164164    Parameter names are assumed to contain only _.a-zA-Z0-9#[] 
    165      
     165 
    166166    Both names are provided for inverse functions, e.g., acos and arccos. 
    167167 
    168168    Should try running the function to identify syntax errors before 
    169169    running it in a fit. 
    170      
     170 
    171171    Use help(fn) to see the code generated for the returned function fn. 
    172172    dis.dis(fn) will show the corresponding python vm instructions. 
     
    239239        if independent == emptyset: 
    240240            cycleset = ", ".join(str(s) for s in left) 
    241             raise ValueError,"Cyclic dependencies amongst %s"%cycleset 
     241            raise ValueError("Cyclic dependencies amongst %s"%cycleset) 
    242242 
    243243        # The possibly resolvable items are those that depend on the independents 
     
    267267        n.sort() 
    268268        items = list(items); items.sort() 
    269         raise Exception,"%s expect %s to contain %s for %s"%(msg,n,items,pairs) 
     269        raise ValueError("%s expect %s to contain %s for %s"%(msg,n,items,pairs)) 
    270270    for lo,hi in pairs: 
    271271        if lo in n and hi in n and n.index(lo) >= n.index(hi): 
    272             raise Exception,"%s expect %s before %s in %s for %s"%(msg,lo,hi,n,pairs) 
     272            raise ValueError("%s expect %s before %s in %s for %s"%(msg,lo,hi,n,pairs)) 
    273273 
    274274def test_deps(): 
     
    288288    # Cycle test 
    289289    pairs = [(1,4),(4,3),(4,5),(5,1)] 
    290     try: n = order_dependencies(pairs) 
    291     except ValueError: pass 
    292     else: raise Exception,"test3 expect ValueError exception for %s"%(pairs,) 
     290    try: 
     291        n = order_dependencies(pairs) 
     292    except ValueError: 
     293        pass 
     294    else: 
     295        raise ValueError("test3 expect ValueError exception for %s"%(pairs,)) 
    293296 
    294297    # large test for gross speed check 
     
    308311    import inspect, dis 
    309312    import math 
    310      
     313 
    311314    symtab = {'a.b.x':1, 'a.c':2, 'a.b':3, 'b.x':4} 
    312315    expr = 'a.b.x + sin(4*pi*a.c) + a.b.x/a.b' 
    313      
     316 
    314317    # Check symbol lookup 
    315318    assert _symbols(expr, symtab) == set([1,2,3]) 
     
    357360    expected = 2*math.pi*math.sin(5/.1875) + 6 
    358361    assert p2.value == expected,"Value was %s, not %s"%(p2.value,expected) 
    359      
     362 
    360363    # Check empty dependency set doesn't crash 
    361364    fn = compile_constraints(*world(p1,p3)) 
     
    381384    fn() 
    382385    assert p5.value == 2.07,"Value for %s was %s"%(p5.expression,p5.value) 
    383      
     386 
    384387 
    385388    # Verify that we capture invalid expressions 
    386     for expr in ['G4.cage', 'M0.cage', 'M1.G1 + *2',  
     389    for expr in ['G4.cage', 'M0.cage', 'M1.G1 + *2', 
    387390                 'piddle', 
    388391                 '5; import sys; print "p0wned"', 
  • TabularUnified src/sas/sascalc/fit/pagestate.py

    r277257f r574adc7  
    313313 
    314314        if len(self.disp_obj_dict) > 0: 
    315             for k, v in self.disp_obj_dict.iteritems(): 
     315            for k, v in self.disp_obj_dict.items(): 
    316316                obj.disp_obj_dict[k] = v 
    317317        if len(self.disp_cb_dict) > 0: 
    318             for k, v in self.disp_cb_dict.iteritems(): 
     318            for k, v in self.disp_cb_dict.items(): 
    319319                obj.disp_cb_dict[k] = v 
    320320        if len(self.values) > 0: 
    321             for k, v in self.values.iteritems(): 
     321            for k, v in self.values.items(): 
    322322                obj.values[k] = v 
    323323        if len(self.weights) > 0: 
    324             for k, v in self.weights.iteritems(): 
     324            for k, v in self.weights.items(): 
    325325                obj.weights[k] = v 
    326326        obj.enable_smearer = copy.deepcopy(self.enable_smearer) 
     
    347347        obj.version = copy.deepcopy(self.version) 
    348348 
    349         for name, state in self.saved_states.iteritems(): 
     349        for name, state in self.saved_states.items(): 
    350350            copy_name = copy.deepcopy(name) 
    351351            copy_state = state.clone() 
     
    430430        """ 
    431431        p_map = [] 
    432         for name, info in params.iteritems(): 
     432        for name, info in params.items(): 
    433433            if ".fittable" in name or ".std" in name or ".upper" in name or \ 
    434434                            ".lower" in name or ".units" in name: 
     
    475475            formfactor, str_params = convert.convert_model( 
    476476                self.formfactorcombobox, str_pars, False, self.version) 
    477             for key, value in str_params.iteritems(): 
     477            for key, value in str_params.items(): 
    478478                params[key] = value 
    479479 
     
    835835            element = newdoc.createElement(item[0]) 
    836836            value_list = getattr(self, item[1]) 
    837             for key, value in value_list.iteritems(): 
     837            for key, value in value_list.items(): 
    838838                sub_element = newdoc.createElement(key) 
    839839                sub_element.setAttribute('name', str(key)) 
     
    848848            element = newdoc.createElement(tagname) 
    849849            value_list = getattr(self, varname) 
    850             for key, value in value_list.iteritems(): 
     850            for key, value in value_list.items(): 
    851851                sub_element = newdoc.createElement(key) 
    852852                sub_element.setAttribute('name', str(key)) 
     
    950950            msg = "PageState no longer supports non-CanSAS" 
    951951            msg += " format for fitting files" 
    952             raise RuntimeError, msg 
     952            raise RuntimeError(msg) 
    953953 
    954954        if node.get('version'): 
     
    12411241            else: 
    12421242                self.call_back(format=ext) 
    1243                 raise RuntimeError, "%s is not a file" % path 
     1243                raise RuntimeError("%s is not a file" % path) 
    12441244 
    12451245            # Return output consistent with the loader's api 
  • TabularUnified src/sas/sascalc/fit/pluginmodel.py

    r5213d22 r574adc7  
    3535            return self.function(x_val)*self.function(y_val) 
    3636        elif x.__class__.__name__ == 'tuple': 
    37             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     37            raise ValueError("Tuples are not allowed as input to BaseComponent models") 
    3838        else: 
    3939            return self.function(x) 
     
    5252            return self.function(x[0])*self.function(x[1]) 
    5353        elif x.__class__.__name__ == 'tuple': 
    54             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     54            raise ValueError("Tuples are not allowed as input to BaseComponent models") 
    5555        else: 
    5656            return self.function(x) 
Note: See TracChangeset for help on using the changeset viewer.