Changeset 279e371 in sasview


Ignore:
Timestamp:
Apr 18, 2012 11:26:13 AM (12 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
499fe7a
Parents:
3ee4d96
Message:

Fixing code style problems

Files:
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • fittingview/src/sans/perspectives/fitting/models.py

    r61184df r279e371  
    484484        self.model_name_list.append(DebyeModel.__name__) 
    485485         
    486         #FractalModel (a c-model)is now being used instead of FractalAbsModel. 
    487486        from sans.models.FractalModel import FractalModel 
    488487        self.shape_indep_list.append(FractalModel ) 
  • sansmodels/src/sans/models/BEPolyelectrolyte.py

    r27972c1d r279e371  
    1 #!/usr/bin/env python 
    2 """  
    3      
    4     Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ 
     1"""     
     2 Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ 
    53                       *(q^(2)-(12*h*C/b^(2))) 
    6     BEPolyelectrolyte as a BaseComponent model 
     4 BEPolyelectrolyte as a BaseComponent model 
    75""" 
    86 
     
    119 
    1210class BEPolyelectrolyte(BaseComponent): 
    13     
    1411    """ 
    1512        Class that evaluates a BEPolyelectrolyte. 
     
    3734        ## Name of the model 
    3835        self.name = "BEPolyelectrolyte" 
    39         self.description=""" 
     36        self.description = """ 
    4037        F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k^(2))/(1+(r02)^(2)) 
    4138            *(q^(2)+k^(2))*(q^(2)-(12*h*C/b^(2)))+bkd 
     
    5350        ## Define parameters 
    5451        self.params = {} 
    55         self.params['k']    = 10 
    56         self.params['lb']   = 7.1 
    57         self.params['h']    = 12 
    58         self.params['b']    = 10 
    59         self.params['cs']   = 0.0 
    60         self.params['alpha']= 0.05 
    61         self.params['c']    = 0.7 
     52        self.params['k']     = 10 
     53        self.params['lb']    = 7.1 
     54        self.params['h']     = 12 
     55        self.params['b']     = 10 
     56        self.params['cs']    = 0.0 
     57        self.params['alpha'] = 0.05 
     58        self.params['c']     = 0.7 
    6259        self.params['background']  = 0.0 
    63          
    6460 
    6561        ## Parameter details [units, min, max] 
    6662        self.details = {} 
    67         self.details['k']    = ['[barns]', None, None] 
    68         self.details['lb'] = ['[A]', None, None] 
    69         self.details['h']   = ['[1/A^(2)]', None, None] 
    70         self.details['b']    = ['[A]', None, None] 
    71         self.details['cs'] = ['[mol/L]', None, None] 
    72         self.details['alpha']   = ['', None, None] 
    73         self.details['c']    = ['[mol/L]', None, None] 
     63        self.details['k']     = ['[barns]', None, None] 
     64        self.details['lb']    = ['[A]', None, None] 
     65        self.details['h']     = ['[1/A^(2)]', None, None] 
     66        self.details['b']     = ['[A]', None, None] 
     67        self.details['cs']    = ['[mol/L]', None, None] 
     68        self.details['alpha'] = ['', None, None] 
     69        self.details['c']     = ['[mol/L]', None, None] 
    7470        self.details['background'] = ['[1/cm]', None, None] 
    7571        #list of parameter that cannot be fitted 
    76         self.fixed= [] 
     72        self.fixed = [] 
    7773                
    7874    def _BEPoly(self, x): 
     
    8985        Ca = self.params['c'] * 6.022136e-4 
    9086        #remove singulars 
    91         if self.params['alpha']<=0 or self.params['c']<=0 or self.params['b']==0 or self.params['lb']<=0: 
     87        if self.params['alpha']<=0 or self.params['c']<=0\ 
     88            or self.params['b']==0 or self.params['lb']<=0: 
    9289            return 0 
    9390        else: 
     
    9794             
    9895            r02 = 1.0/self.params['alpha']/math.sqrt(Ca) * \ 
    99                     (self.params['b']/math.sqrt((48.0*math.pi *self.params['lb']))) 
     96                    (self.params['b']/\ 
     97                     math.sqrt((48.0*math.pi*self.params['lb']))) 
    10098             
    101             return self.params['k']/( 4.0 * math.pi * self.params['lb'] * self.params['alpha']**2 ) \ 
     99            return self.params['k']/( 4.0 * math.pi * self.params['lb'] \ 
     100                                      * self.params['alpha']**2 ) \ 
    102101                   * ( x**2 + K2 ) / ( 1.0 + r02**2 * ( x**2 + K2 ) \ 
    103102                        * (x**2 - ( 12.0 * self.params['h'] \ 
    104103                        * Ca/(self.params['b']**2) ))) \ 
    105104                        + self.params['background'] 
    106              
    107105    
    108106    def run(self, x = 0.0): 
  • sansmodels/src/sans/models/BroadPeakModel.py

    r411d8bf r279e371  
    1 #!/usr/bin/env python 
    21"""  
    3 BroadPeakModel function as a BaseComponent model 
     2    BroadPeakModel function as a BaseComponent model 
    43""" 
    54 
     
    6160        inten = self.params['scale_p']/pow(x,self.params['exponent_p']) 
    6261        inten += self.params['scale_l']/(1.0 + \ 
    63                 power((math.fabs(x-self.params['q_peak'])*self.params['length_l']),\ 
     62                power((math.fabs(x-self.params['q_peak'])\ 
     63                       *self.params['length_l']),\ 
    6464                    self.params['exponent_l'])) 
    6565 
     
    7878            return self._broadpeak(x[0]) 
    7979        elif x.__class__.__name__ == 'tuple': 
    80             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     80            raise ValueError, "Tuples are not allowed as input to models" 
    8181        else: 
    8282            return self._broadpeak(x) 
     
    9393            return self._broadpeak(q) 
    9494        elif x.__class__.__name__ == 'tuple': 
    95             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     95            raise ValueError, "Tuples are not allowed as input to models" 
    9696        else: 
    9797            return self._broadpeak(x) 
  • sansmodels/src/sans/models/Constant.py

    r988130c6 r279e371  
    1 #!/usr/bin/env python 
    2 """ Provide constant function as a BaseComponent model 
     1"""  
     2    Provide constant function as a BaseComponent model 
    33""" 
    44 
     
    2020        ## Name of the model 
    2121        self.name = "Constant" 
    22         self.description='F(c)= c where c is a constant' 
     22        self.description = 'F(c)= c where c is a constant' 
    2323        ## Parameter details [units, min, max] 
    2424        self.details = {} 
     
    2626        self.params['value'] = 1.0 
    2727        #list of parameter that cannot be fitted 
    28         self.fixed= [] 
     28        self.fixed = [] 
    2929    def clone(self): 
    3030        """ Return a identical copy of self """ 
  • sansmodels/src/sans/models/CoreMultiShellModel.py

    r339ce67 r279e371  
    1     
     1""" 
     2    Core-Multi-Shell model 
     3""" 
    24from sans.models.BaseComponent import BaseComponent 
    35from sans.models.CoreFourShellModel import CoreFourShellModel 
     
    1113    def __init__(self, multfactor=1): 
    1214        BaseComponent.__init__(self) 
    13         """ 
    14         :param n_shells: number of shells in the model, assumes 1<= n_shells <=4. 
    15         """ 
    1615 
    1716        ## Setting  model name model description 
    18         self.description="" 
    1917        model = CoreFourShellModel() 
    2018        self.model = model 
    2119        self.name = "CoreMultiShellModel" 
    22         self.description="" 
     20        self.description = "" 
    2321        self.n_shells = multfactor 
    2422        ## Define parameters 
     
    4543        # [int(maximum no. of functionality),"str(Titl), 
    4644        # [str(name of function0),...], [str(x-asix name of sld),...]] 
    47         self.multiplicity_info = [max_nshells,"No. of Shells:",[],['Radius']] 
    48  
    49         ## parameters with orientation: can be removed since there is no orientational params 
     45        self.multiplicity_info = [max_nshells, "No. of Shells:", [], ['Radius']] 
     46 
     47        ## parameters with orientation: 
    5048        for item in self.model.orientation_params: 
    5149            self.orientation_params.append(item) 
    52                  
    5350         
    5451    def _clone(self, obj): 
     
    5754        data members to a fresh copy. 
    5855        """ 
    59         obj.params     = copy.deepcopy(self.params) 
    60         obj.description     = copy.deepcopy(self.description) 
    61         obj.details    = copy.deepcopy(self.details) 
     56        obj.params = copy.deepcopy(self.params) 
     57        obj.description = copy.deepcopy(self.description) 
     58        obj.details = copy.deepcopy(self.details) 
    6259        obj.dispersion = copy.deepcopy(self.dispersion) 
    63         obj.model  = self.model.clone() 
     60        obj.model = self.model.clone() 
    6461 
    6562        return obj 
    66      
    6763     
    6864    def _set_dispersion(self): 
     
    7571            nshell = 0 
    7672            if name.split('_')[0] == 'thick': 
    77                 while nshell<self.n_shells: 
     73                while nshell < self.n_shells: 
    7874                    nshell += 1 
    7975                    if name.split('_')[1] == 'shell%s' % str(nshell): 
    80                         self.dispersion[name]= value 
     76                        self.dispersion[name] = value 
    8177                    else:  
    8278                        continue 
    8379            else: 
    84                 self.dispersion[name]= value 
     80                self.dispersion[name] = value 
    8581                               
    8682 
     
    9490            nshell = 0 
    9591            if name.split('_')[0] == 'thick' or name.split('_')[0] == 'sld': 
    96                 if name.split('_')[1] == 'solv' or name.split('_')[1] == 'core0': 
    97                     self.params[name]= value 
     92                if name.split('_')[1] == 'solv' \ 
     93                    or name.split('_')[1] == 'core0': 
     94                    self.params[name] = value 
    9895                    continue 
    99                 while nshell<self.n_shells: 
     96                while nshell < self.n_shells: 
    10097                    nshell += 1 
    10198                    if name.split('_')[1] == 'shell%s' % str(nshell): 
    102                         self.params[name]= value 
     99                        self.params[name] = value 
    103100                        continue 
    104101            else: 
    105                 self.params[name]= value 
     102                self.params[name] = value 
    106103             
    107104             
     
    116113        for name ,detail in self.model.details.iteritems(): 
    117114            if name in self.params.iterkeys(): 
    118                 self.details[name]= detail 
     115                self.details[name] = detail 
    119116             
    120117     
     
    131128 
    132129                for nshell in range(self.n_shells,max_nshells): 
    133                     if key.split('_')[0] == 'sld' and key.split('_')[1] == 'shell%s' % str(nshell+1): 
     130                    if key.split('_')[0] == 'sld' and \ 
     131                        key.split('_')[1] == 'shell%s' % str(nshell+1): 
    134132                        try: 
    135133                            value = self.model.params['sld_solv'] 
    136134                            self.model.setParam(key, value) 
    137                         except: pass 
     135                        except: 
     136                            message = "CoreMultiShellModel evaluation problem" 
     137                            raise RuntimeError, message 
    138138 
    139139    def getProfile(self): 
     
    155155         
    156156        # for shells 
    157         for n in range(1,self.n_shells+1): 
     157        for n in range(1, self.n_shells+1): 
    158158            # Left side of each shells 
    159159            r0 = r[len(r)-1]             
     
    186186        self._setParamHelper( name, value) 
    187187        ## setParam to model  
    188         if name=='sld_solv': 
    189             # the sld_*** model.params not in params must set to value of sld_solv 
     188        if name == 'sld_solv': 
     189            # the sld_*** model.params not in params  
     190            # must set to value of sld_solv 
    190191            for key in self.model.params.iterkeys(): 
    191192                if key not in self.params.keys()and key.split('_')[0] == 'sld': 
    192                         self.model.setParam(key, value) 
     193                    self.model.setParam(key, value) 
    193194        self.model.setParam( name, value) 
    194195 
     
    199200        #look for dispersion parameters 
    200201        toks = name.split('.') 
    201         if len(toks)==2: 
     202        if len(toks) == 2: 
    202203            for item in self.dispersion.keys(): 
    203204                if item.lower()==toks[0].lower(): 
     
    224225 
    225226        self.fixed.sort() 
    226         pass          
    227227                 
    228228    def run(self, x = 0.0): 
     
    250250    ## Now (May27,10) directly uses the model eval function  
    251251    ## instead of the for-loop in Base Component. 
    252     def evalDistribution(self, x = []): 
     252    def evalDistribution(self, x): 
    253253        """  
    254254        Evaluate the model in cartesian coordinates 
     
    267267        :dispersion: dispersion object of type DispersionModel 
    268268        """ 
    269         value= None 
     269        value = None 
    270270        try: 
    271271            if parameter in self.model.dispersion.keys(): 
    272                 value= self.model.set_dispersion(parameter, dispersion) 
     272                value = self.model.set_dispersion(parameter, dispersion) 
    273273            self._set_dispersion() 
    274274            return value 
  • sansmodels/src/sans/models/CorrLengthModel.py

    r411d8bf r279e371  
    5656        Model definition 
    5757        """ 
    58         inten = self.params['scale_p']/pow(x,self.params['exponent_p']) 
     58        inten = self.params['scale_p']/pow(x, self.params['exponent_p']) 
    5959        inten += self.params['scale_l']/(1.0 + \ 
    60                 power((x*self.params['length_l']),self.params['exponent_l'])) 
     60                power((x*self.params['length_l']), self.params['exponent_l'])) 
    6161        inten += self.params['background'] 
    6262 
     
    7373            return self._corrlength(x[0]) 
    7474        elif x.__class__.__name__ == 'tuple': 
    75             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     75            raise ValueError, "Tuples are not allowed as input to models" 
    7676        else: 
    7777            return self._corrlength(x) 
     
    8888            return self._corrlength(q) 
    8989        elif x.__class__.__name__ == 'tuple': 
    90             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     90            raise ValueError, "Tuples are not allowed as input to models" 
    9191        else: 
    9292            return self._corrlength(x) 
  • sansmodels/src/sans/models/Cos.py

    r96672c0 r279e371  
    1 #!/usr/bin/env python 
    2 """ Provide cos(x) function as a BaseComponent model 
     1"""  
     2    Provide cos(x) function as a BaseComponent model 
    33""" 
    44 
     
    77  
    88class Cos(BaseComponent): 
    9     """ Class that evaluates a cos(x) model.  
     9    """  
     10        Class that evaluates a cos(x) model.  
    1011    """ 
    1112         
     
    1819        ## Name of the model 
    1920        self.name = "Cos" 
    20         self.description='F(x)=cos(x)' 
     21        self.description = 'F(x)=cos(x)' 
    2122        ## Parameter details [units, min, max] 
    2223        self.details = {} 
     
    3435            return math.cos(x[0]*math.cos(x[1]))*math.cos(x[0]*math.sin(x[1])) 
    3536        elif x.__class__.__name__ == 'tuple': 
    36             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     37            raise ValueError, "Tuples are not allowed as input to models" 
    3738        else: 
    3839            return math.cos(x) 
     
    4647            return math.cos(x[0])*math.cos(x[1]) 
    4748        elif x.__class__.__name__ == 'tuple': 
    48             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     49            raise ValueError, "Tuples are not allowed as input to models" 
    4950        else: 
    5051            return math.cos(x) 
    51     
    52 # End of file 
     52 
  • sansmodels/src/sans/models/DebyeModel.py

    r26e4a24 r279e371  
    1 #!/usr/bin/env python 
    21"""  
    32    Provide F(x) = 2( exp(-x) + x - 1 )/x**2 
     
    65    Debye function as a BaseComponent model 
    76""" 
    8  
    97from sans.models.BaseComponent import BaseComponent 
    108import math 
    119 
    1210class DebyeModel(BaseComponent): 
    13     
    1411    """ 
    1512        Class that evaluates a Debye model. 
     
    3229        ## Name of the model 
    3330        self.name = "Debye" 
    34         self.description="""  
     31        self.description = """  
    3532        F(x) = 2( exp(-x) + x - 1 )/x**2 
    3633        with x = (q*R_g)**2 
     
    5350        self.details['background'] = ['[1/cm]', None, None] 
    5451        #list of parameter that cannot be fitted 
    55         self.fixed= []       
     52        self.fixed = []  
     53              
    5654    def _debye(self, x): 
    5755        """ 
     
    6563        y = (x * self.params['rg'])**2.0 
    6664        if x == 0: 
    67             D=1 
     65            D = 1 
    6866        else: 
    69            D = 2.0*( math.exp(-y) + y -1.0 )/y**2.0 
    70         return self.params['scale']* D + self.params['background'] 
     67            D = 2.0*( math.exp(-y) + y -1.0 )/y**2.0 
     68        return self.params['scale'] * D + self.params['background'] 
    7169    
    7270    def run(self, x = 0.0): 
     
    7876            return self._debye(x[0]) 
    7977        elif x.__class__.__name__ == 'tuple': 
    80             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     78            raise ValueError, "Tuples are not allowed as input to models" 
    8179        else: 
    8280            return self._debye(x) 
     
    9189            return self._debye(q) 
    9290        elif x.__class__.__name__ == 'tuple': 
    93             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     91            raise ValueError, "Tuples are not allowed as input to models" 
    9492        else: 
    9593            return self._debye(x) 
  • sansmodels/src/sans/models/DisperseModel.py

    r0abf7bf r279e371  
    1 #!/usr/bin/env python 
    21"""  
    3 Wrapper for the Disperser class extension 
    4  
    5 :author: Mathieu Doucet / UTK 
    6  
    7 :contact: mathieu.doucet@nist.gov 
    8  
     2    Wrapper for the Disperser class extension 
    93""" 
    10  
    114from sans.models.BaseComponent import BaseComponent 
    125from sans_extension.c_models import Disperser 
     
    147class DisperseModel(Disperser, BaseComponent): 
    158    """  
    16         Wrapper class for the Disperser extension 
    17         Python class that takes a model and averages its output 
    18         for a distribution of its parameters. 
    19            
    20         The parameters to be varied are specified at instantiation time. 
    21         The distributions are Gaussian, with std deviations specified for 
    22         each parameter at instantiation time. 
    23          
    24         Example: :: 
    25          
    26                 cyl = CylinderModel() 
    27                 disp = DisperseModel(cyl, ['cyl_phi'], [0.3]) 
    28                 disp.run([0.01, 1.57]) 
    29                  
     9    Wrapper class for the Disperser extension 
     10    Python class that takes a model and averages its output 
     11    for a distribution of its parameters. 
     12       
     13    The parameters to be varied are specified at instantiation time. 
     14    The distributions are Gaussian, with std deviations specified for 
     15    each parameter at instantiation time. 
     16     
     17    Example: :: 
     18     
     19        cyl = CylinderModel() 
     20        disp = DisperseModel(cyl, ['cyl_phi'], [0.3]) 
     21        disp.run([0.01, 1.57]) 
     22         
    3023    """ 
    3124         
     
    3427        Initialization  
    3528         
    36         :param model: Model to disperse [BaseComponent] 
    37         :param paramList: list of parameters to disperse [List of strings] 
    38         :param sigmaList: list of std deviations for Gaussian dispersion 
    39                                         [List of floats] 
     29        :param model: Model to disperse [BaseComponent] 
     30        :param paramList: list of parameters to disperse [List of strings] 
     31        :param sigmaList: list of std deviations for Gaussian dispersion 
     32                    [List of floats] 
    4033         
    4134        """ 
     
    4841        ## Keep track of the underlying model 
    4942        self.model = model 
    50         self.description='' 
     43        self.description ='' 
    5144        #list of parameter that cannot be fitted 
    52         self.fixed= [] 
     45        self.fixed = [] 
    5346         
    5447    def clone(self): 
    5548        """ Return a identical copy of self """ 
    56         obj = DisperseModel(self.model, self.params['paramList'], self.params['sigmaList']) 
    57         return obj   
     49        return DisperseModel(self.model, self.params['paramList'],  
     50                             self.params['sigmaList'])  
    5851    
    5952    def setParam(self, name, value): 
    60         """ 
    61         """ 
    62         if name.lower() in self.params: 
    63                 BaseComponent.setParam(self, name, value) 
    64         else: 
    65                 self.model.setParam(name, value) 
     53        """ 
     54            Set a parameter value 
     55            :param name: parameter name 
     56        """ 
     57        if name.lower() in self.params: 
     58            BaseComponent.setParam(self, name, value) 
     59        else: 
     60            self.model.setParam(name, value) 
    6661    
    6762    def getParam(self, name): 
    68         """ 
    69         """ 
    70         if name.lower() in self.params: 
    71                 return BaseComponent.getParam(self, name) 
    72         else: 
    73                 return self.model.getParam(name) 
     63        """ 
     64            Get the value of the given parameter 
     65            :param name: parameter name 
     66        """ 
     67        if name.lower() in self.params: 
     68            return BaseComponent.getParam(self, name) 
     69        else: 
     70            return self.model.getParam(name) 
    7471    
    7572    def run(self, x = 0.0): 
    7673        """  
    77         Evaluate the model 
    78              
    79         :param x: input q, or [q,phi] 
    80          
    81         :return: scattering function P(q) 
    82          
     74            Evaluate the model 
     75            :param x: input q, or [q,phi] 
     76            :return: scattering function P(q) 
    8377        """ 
    8478        return Disperser.run(self, x) 
     
    8680    def runXY(self, x = 0.0): 
    8781        """  
    88         Evaluate the model 
    89          
    90         :param x: input q, or [q,phi] 
    91          
    92         :return: scattering function P(q) 
    93          
     82            Evaluate the model 
     83            :param x: input q, or [q,phi] 
     84            :return: scattering function P(q) 
    9485        """ 
    9586        return Disperser.runXY(self, x) 
  • sansmodels/src/sans/models/FractalCoreShellModel.py

    r31f9d0c2 r279e371  
    131131            if name  == 'scale': 
    132132                name = 'volfraction' 
    133             self.params[name]= value 
     133            self.params[name] = value 
    134134        self.params['frac_dim'] = 2.0 
    135135        self.params['cor_length'] = 100.0   
     
    206206                +self._fractalcore(x[0])*self.model.run(x) 
    207207        elif x.__class__.__name__ == 'tuple': 
    208             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     208            raise ValueError, "Tuples are not allowed as input to models" 
    209209        else: 
    210210            return self.params['background']\ 
     
    222222        if x.__class__.__name__ == 'list': 
    223223            q = math.sqrt(x[0]**2 + x[1]**2) 
    224             return self.params['background']+self._fractalcore(q)*self.model.runXY(x) 
     224            return self.params['background']\ 
     225                +self._fractalcore(q)*self.model.runXY(x) 
    225226        elif x.__class__.__name__ == 'tuple': 
    226             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     227            raise ValueError, "Tuples are not allowed as input to models" 
    227228        else: 
    228             return self.params['background']+self._fractalcore(x)*self.model.runXY(x) 
    229  
     229            return self.params['background']\ 
     230                +self._fractalcore(x)*self.model.runXY(x) 
    230231 
    231232    def set_dispersion(self, parameter, dispersion): 
  • sansmodels/src/sans/models/GaussLorentzGelModel.py

    r79411b2 r279e371  
    1 #!/usr/bin/env python 
    21"""  
    3 Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) 
    4 GaussLorentzGel function as a BaseComponent model 
     2    Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) 
     3    GaussLorentzGel function as a BaseComponent model 
    54""" 
    6  
    75from sans.models.BaseComponent import BaseComponent 
    86import math 
     
    5654        #list of parameter that cannot be fitted 
    5755        self.fixed = []   
     56         
    5857    def _gausslorentzgel(self, x): 
    5958        """ 
    6059        Model definition 
    6160        """ 
    62         inten = self.params['scale_g']*math.exp(-1.0*x*x*self.params['stat_colength']* \ 
     61        inten = self.params['scale_g'] \ 
     62                *math.exp(-1.0*x*x*self.params['stat_colength']* \ 
    6363                self.params['stat_colength']/2.0) + self.params['scale_l']/ \ 
    6464                (1.0 + (x*self.params['dyn_colength'])* \ 
     
    7474            return self._gausslorentzgel(x[0]) 
    7575        elif x.__class__.__name__ == 'tuple': 
    76             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     76            raise ValueError, "Tuples are not allowed as input to models" 
    7777        else: 
    7878            return self._gausslorentzgel(x) 
     
    8787            return self._gausslorentzgel(q) 
    8888        elif x.__class__.__name__ == 'tuple': 
    89             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     89            raise ValueError, "Tuples are not allowed as input to models" 
    9090        else: 
    9191            return self._gausslorentzgel(x) 
  • sansmodels/src/sans/models/GuinierModel.py

    r1ed3834 r279e371  
    1 #!/usr/bin/env python 
    21"""  
    32    Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) 
    43    Guinier function as a BaseComponent model 
    54""" 
    6  
    75from sans.models.BaseComponent import BaseComponent 
    86import math 
     
    2826        ## Name of the model 
    2927        self.name = "Guinier" 
    30         self.description=""" I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 ) 
     28        self.description = """ I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 ) 
    3129         
    3230                        List of default parameters: 
     
    4341        self.details['rg']    = ['[A]', None, None] 
    4442        #list of parameter that cannot be fitted 
    45         self.fixed= []   
     43        self.fixed = []   
     44         
    4645    def _guinier(self, x): 
    47         return self.params['scale'] * math.exp( -(self.params['rg']*x)**2 / 3.0 )   
     46        """ 
     47            Evaluate guinier function 
     48            :param x: q-value 
     49        """ 
     50        return self.params['scale']*math.exp( -(self.params['rg']*x)**2/3.0 )   
    4851    
    4952    def run(self, x = 0.0): 
    50         """ Evaluate the model 
     53        """  
     54            Evaluate the model 
    5155            @param x: input q-value (float or [float, float] as [r, theta]) 
    5256            @return: (guinier value) 
     
    5559            return self._guinier(x[0]) 
    5660        elif x.__class__.__name__ == 'tuple': 
    57             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     61            raise ValueError, "Tuples are not allowed as input to models" 
    5862        else: 
    5963            return self._guinier(x) 
     
    6872            return self._guinier(q) 
    6973        elif x.__class__.__name__ == 'tuple': 
    70             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     74            raise ValueError, "Tuples are not allowed as input to models" 
    7175        else: 
    7276            return self._guinier(x) 
  • sansmodels/src/sans/models/GuinierPorodModel.py

    r8f20419d r279e371  
    1 #!/usr/bin/env python 
    21"""  
    3 I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 
    4     = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 
    5 Guinier function as a BaseComponent model 
     2    I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 
     3        = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 
     4    Guinier function as a BaseComponent model 
    65""" 
    7  
    86from sans.models.BaseComponent import BaseComponent 
    97from math import sqrt,exp 
     
    2422        ## Name of the model 
    2523        self.name = "GuinierPorod" 
    26         self.description=""" I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 
     24        self.description = """ 
     25         I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 
    2726         = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 
    2827                        where ql = sqrt((m-s)(3-s)/2)/Rg. 
     
    4948 
    5049        #list of parameter that cannot be fitted 
    51         self.fixed= []   
     50        self.fixed = []   
    5251         
    5352    def _guinier_porod(self, x): 
     
    6564         
    6665        #do the calculation and return the function value 
    67         q1=sqrt((n-3.0+m)*n/2.0)/Rg 
     66        q1 = sqrt((n-3.0+m)*n/2.0)/Rg 
    6867        if qval < q1: 
    6968            F = (G/pow(qval,(3.0-n)))*exp((-qval*qval*Rg*Rg)/n)  
    7069        else: 
    71             F = (G/pow(qval,m))*exp(-(n-3.0+m)/2.0)*pow(((n-3.0+m)*n/2.0), 
     70            F = (G/pow(qval, m))*exp(-(n-3.0+m)/2.0)*pow(((n-3.0+m)*n/2.0), 
    7271                                        ((n-3.0+m)/2.0))/pow(Rg,(n-3.0+m)) 
    7372        inten = F + bgd 
     
    8382            return self._guinier_porod(x[0]) 
    8483        elif x.__class__.__name__ == 'tuple': 
    85             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     84            raise ValueError, "Tuples are not allowed as input to models" 
    8685        else: 
    8786            return self._guinier_porod(x) 
     
    9695            return self._guinier_porod(q) 
    9796        elif x.__class__.__name__ == 'tuple': 
    98             raise ValueError, "Tuples are not allowed as input to BaseComponent models" 
     97            raise ValueError, "Tuples are not allowed as input to models" 
    9998        else: 
    10099            return self._guinier_porod(x) 
  • sansmodels/test/utest_other_models.py

    r6e2d708 r279e371  
    14471447        self.comp.setParam('B', 0.0) 
    14481448        self.assertRaises(ZeroDivisionError, self.comp.run, 10) 
    1449         #self.assert_(numpy.isfinite(self.comp.run(0.0)))   
    1450          
    1451         
    1452 class TestFractalAbsModel(unittest.TestCase): 
    1453     """ Unit tests for FractalAbsModel""" 
    1454      
    1455     def setUp(self): 
    1456         from sans.models.FractalAbsModel import FractalAbsModel 
    1457         self.comp = FractalAbsModel() 
    1458         self.comp.setParam('scale', 0.05) 
    1459         self.comp.setParam('radius', 5.0) 
    1460         self.comp.setParam('fractal_dim', 2.0) 
    1461         self.comp.setParam('cor_length',100.0) 
    1462         self.comp.setParam('sldBlock', 2.0e-6) 
    1463         self.comp.setParam('sldSolv', 6.35e-6) 
    1464         self.comp.setParam('background',0.0) 
    1465          
    1466         self.x = numpy.array([0.4, 1.3]) 
    1467         self.y = numpy.array([0.5, 1.57]) 
    1468          
    1469         self.x_array = self.comp.evalDistribution(self.x) 
    1470         self.y_array = self.comp.evalDistribution(self.y) 
    1471         qx_prime = numpy.reshape(self.x, [1,len(self.x)]) 
    1472         qy_prime = numpy.reshape(self.y, [len(self.y),1]) 
    1473         self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) 
    1474          
    1475     def test1D(self): 
    1476         """ Test 1D model for a Fractal Abs Model""" 
    1477         self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3) 
    1478          
    1479     def test1D_2(self): 
    1480         """ Test 2D model for a Fractal Abs Model""" 
    1481         self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3) 
    1482          
    1483     def testEval_1D(self): 
    1484         """ Test 1D model for a Fractal Abs Model with evalDistribution""" 
    1485         self.assertEquals(self.comp.run(0.4),self.x_array[0]) 
    1486         self.assertEquals(self.comp.run(1.3),self.x_array[1]) 
    1487          
    1488     def testEval_2D(self): 
    1489         """ Test 2D model for a Fractal Abs Model with evalDistribution""" 
    1490         self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) 
    1491         self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) 
    1492  
    1493     # No more singular point 
    1494     #def testCriticalPoint(self): 
    1495     #    """ Test Fractal Abs at the critical point""" 
    1496     #    self.assert_(numpy.isfinite(self.comp.run(0.0)))     
     1449        #self.assert_(numpy.isfinite(self.comp.run(0.0)))        
    14971450    
    14981451class TestFractalModel(unittest.TestCase): 
Note: See TracChangeset for help on using the changeset viewer.