Changeset 841753c in sasmodels


Ignore:
Timestamp:
Jan 28, 2016 3:42:34 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
d4666ca
Parents:
69ec80f
Message:

delint

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extra/pylint.rc

    r37a7252 r841753c  
    6464    star-args, 
    6565    unbalanced-tuple-unpacking, 
     66    locally-enabled, 
    6667    locally-disabled, 
    6768 
     
    107108good-names=_, 
    108109    input, 
    109     i,j,k,n,x,y,z, 
     110    h,i,j,k,n,w,x,y,z, 
    110111    q,qx,qy,qz, 
    111112    dt,dx,dy,dz,id, 
    112     Iq,dIq,Qx,Qy,Qz, 
     113    Iq,dIq,Qx,Qy,Qz,Iqxy, 
    113114    p, 
    114115    ER, call_ER, VR, call_VR, 
     116    Rmax, SElength, 
    115117 
    116118# Bad variable names which should always be refused, separated by a comma 
     
    335337 
    336338# Maximum number of arguments for function / method 
    337 max-args=5 
     339max-args=15 
    338340 
    339341# Argument names that match this expression will be ignored. Default to name 
     
    342344 
    343345# Maximum number of locals for function / method body 
    344 max-locals=15 
     346max-locals=25 
    345347 
    346348# Maximum number of return / yield for function / method body 
  • sasmodels/compare.py

    r4f2478e r841753c  
    533533    if Nbase > 0: 
    534534        if Ncomp > 0: plt.subplot(131) 
    535         plot_theory(data, base_value, view=view, plot_data=False, limits=limits) 
     535        plot_theory(data, base_value, view=view, use_data=False, limits=limits) 
    536536        plt.title("%s t=%.1f ms"%(base.engine, base_time)) 
    537537        #cbar_title = "log I" 
    538538    if Ncomp > 0: 
    539539        if Nbase > 0: plt.subplot(132) 
    540         plot_theory(data, comp_value, view=view, plot_data=False, limits=limits) 
     540        plot_theory(data, comp_value, view=view, use_data=False, limits=limits) 
    541541        plt.title("%s t=%.1f ms"%(comp.engine, comp_time)) 
    542542        #cbar_title = "log I" 
     
    548548            err, errstr, errview = abs(relerr), "rel err", "log" 
    549549        #err,errstr = base/comp,"ratio" 
    550         plot_theory(data, None, resid=err, view=errview, plot_data=False) 
     550        plot_theory(data, None, resid=err, view=errview, use_data=False) 
    551551        plt.title("max %s = %.3g"%(errstr, max(abs(err)))) 
    552552        #cbar_title = errstr if errview=="linear" else "log "+errstr 
  • sasmodels/models/be_polyelectrolyte.py

    r07a6700 r841753c  
    5050""" 
    5151 
    52 from numpy import inf, power, pi, sqrt 
     52from numpy import inf, pi, sqrt 
    5353 
    5454name = "be_polyelectrolyte" 
    5555title = "Polyelectrolyte with the RPA expression derived by Borue and Erukhimovich" 
    5656description = """ 
    57             Evaluate 
    58             F(x) = K 1/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) 
    59                  (q^(2)+k2) (q^(2)-(12 h C/b^(2))) 
     57    Evaluate 
     58    F(x) = K 1/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) 
     59         (q^(2)+k2) (q^(2)-(12 h C/b^(2))) 
    6060 
    61             has 3 internal parameters : 
    62                    The inverse Debye Length: K2 = 4 pi Lb (2 Cs+alpha C) 
    63                    r02 =1/alpha/Ca^(0.5) (B/(48 pi Lb)^(0.5)) 
    64                    Ca = 6.022136e-4 C 
    65             """ 
     61    has 3 internal parameters : 
     62           The inverse Debye Length: K2 = 4 pi Lb (2 Cs+alpha C) 
     63           r02 =1/alpha/Ca^(0.5) (B/(48 pi Lb)^(0.5)) 
     64           Ca = 6.022136e-4 C 
     65    """ 
    6666category = "shape-independent" 
    6767 
    68 #            ["name", "units", default, [lower, upper], "type", "description"], 
    69 parameters = [["contrast_factor",       "barns",   10.0,  [-inf, inf], "", "Contrast factor of the polymer"], 
    70               ["bjerrum_length",        "Ang",      7.1,  [0, inf],    "", "Bjerrum length"], 
    71               ["virial_param",          "1/Ang^2", 12.0,  [-inf, inf], "", "Virial parameter"], 
    72               ["monomer_length",        "Ang",     10.0,  [0, inf],    "", "Monomer length"], 
    73               ["salt_concentration",    "mol/L",    0.0,  [-inf, inf], "", "Concentration of monovalent salt"], 
    74               ["ionization_degree",     "",         0.05, [0, inf],    "", "Degree of ionization"], 
    75               ["polymer_concentration", "mol/L",    0.7,  [0, inf],    "", "Polymer molar concentration"], 
    76               ] 
     68# pylint: disable=bad-whitespace,line-too-long 
     69#   ["name",                  "units", default, [lower, upper], "type", "description"], 
     70parameters = [ 
     71    ["contrast_factor",       "barns",    10.0,  [-inf, inf], "", "Contrast factor of the polymer"], 
     72    ["bjerrum_length",        "Ang",       7.1,  [0, inf],    "", "Bjerrum length"], 
     73    ["virial_param",          "1/Ang^2",  12.0,  [-inf, inf], "", "Virial parameter"], 
     74    ["monomer_length",        "Ang",      10.0,  [0, inf],    "", "Monomer length"], 
     75    ["salt_concentration",    "mol/L",     0.0,  [-inf, inf], "", "Concentration of monovalent salt"], 
     76    ["ionization_degree",     "",          0.05, [0, inf],    "", "Degree of ionization"], 
     77    ["polymer_concentration", "mol/L",     0.7,  [0, inf],    "", "Polymer molar concentration"], 
     78    ] 
     79# pylint: enable=bad-whitespace,line-too-long 
    7780 
    7881 
     
    106109 
    107110def Iqxy(qx, qy, *args): 
    108         iq = Iq(sqrt(qx**2 + qy**2), *args) 
    109  
    110         return iq 
     111    return Iq(sqrt(qx**2 + qy**2), *args) 
    111112 
    112113Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values 
     
    133134               polymer_concentration='c') 
    134135 
     136# pylint: disable=bad-whitespace 
    135137tests = [ 
    136          # Accuracy tests based on content in test/utest_other_models.py 
    137          [{'contrast_factor':       10.0, 
    138            'bjerrum_length':         7.1, 
    139            'virial_param':          12.0, 
    140            'monomer_length':        10.0, 
    141            'salt_concentration':     0.0, 
    142            'ionization_degree':      0.05, 
    143            'polymer_concentration':  0.7, 
    144            'background':             0.001, 
    145            }, 0.001, 0.0948379], 
     138    # Accuracy tests based on content in test/utest_other_models.py 
     139    [{'contrast_factor':       10.0, 
     140      'bjerrum_length':         7.1, 
     141      'virial_param':          12.0, 
     142      'monomer_length':        10.0, 
     143      'salt_concentration':     0.0, 
     144      'ionization_degree':      0.05, 
     145      'polymer_concentration':  0.7, 
     146      'background':             0.001, 
     147     }, 0.001, 0.0948379], 
    146148 
    147          # Additional tests with larger range of parameters 
    148          [{'contrast_factor':       10.0, 
    149            'bjerrum_length':       100.0, 
    150            'virial_param':           3.0, 
    151            'monomer_length':         1.0, 
    152            'salt_concentration':    10.0, 
    153            'ionization_degree':      2.0, 
    154            'polymer_concentration': 10.0, 
    155            }, 0.1, -3.75693800588], 
     149    # Additional tests with larger range of parameters 
     150    [{'contrast_factor':       10.0, 
     151      'bjerrum_length':       100.0, 
     152      'virial_param':           3.0, 
     153      'monomer_length':         1.0, 
     154      'salt_concentration':    10.0, 
     155      'ionization_degree':      2.0, 
     156      'polymer_concentration': 10.0, 
     157     }, 0.1, -3.75693800588], 
    156158 
    157          [{'contrast_factor':       10.0, 
    158            'bjerrum_length':       100.0, 
    159            'virial_param':           3.0, 
    160            'monomer_length':         1.0, 
    161            'salt_concentration':    10.0, 
    162            'ionization_degree':      2.0, 
    163            'polymer_concentration': 10.0, 
    164            'background':           100.0 
    165            }, 5.0, 100.029142149], 
     159    [{'contrast_factor':       10.0, 
     160      'bjerrum_length':       100.0, 
     161      'virial_param':           3.0, 
     162      'monomer_length':         1.0, 
     163      'salt_concentration':    10.0, 
     164      'ionization_degree':      2.0, 
     165      'polymer_concentration': 10.0, 
     166      'background':           100.0 
     167     }, 5.0, 100.029142149], 
    166168 
    167          [{'contrast_factor':     100.0, 
    168            'bjerrum_length':       10.0, 
    169            'virial_param':        180.0, 
    170            'monomer_length':        1.0, 
    171            'salt_concentration':    0.1, 
    172            'ionization_degree':     0.5, 
    173            'polymer_concentration': 0.1, 
    174            }, 200., 1.80664667511e-06], 
    175          ] 
     169    [{'contrast_factor':     100.0, 
     170      'bjerrum_length':       10.0, 
     171      'virial_param':        180.0, 
     172      'monomer_length':        1.0, 
     173      'salt_concentration':    0.1, 
     174      'ionization_degree':     0.5, 
     175      'polymer_concentration': 0.1, 
     176     }, 200., 1.80664667511e-06], 
     177    ] 
     178# pylint: enable=bad-whitespace 
  • sasmodels/models/pearl_necklace.py

    rcf404cb r841753c  
    11r""" 
    2 This model provides the form factor for a pearl necklace composed of two  
    3 elements: *N* pearls (homogeneous spheres of radius *R*) freely jointed by *M*  
     2This model provides the form factor for a pearl necklace composed of two 
     3elements: *N* pearls (homogeneous spheres of radius *R*) freely jointed by *M* 
    44rods (like strings - with a total mass *Mw* = *M* \* *m*\ :sub:`r` + *N* \* *m*\ 
    5 :sub:`s`, and the string segment length (or edge separation) *l*  
     5:sub:`s`, and the string segment length (or edge separation) *l* 
    66(= *A* - 2\ *R*)). *A* is the center-to-center pearl separation distance. 
    77 
     
    1313---------- 
    1414 
    15 The output of the scattering intensity function for the PearlNecklaceModel is  
     15The output of the scattering intensity function for the PearlNecklaceModel is 
    1616given by (Schweins, 2004) 
    1717 
     
    3737    \beta(q) &= \frac{\int_{qR}^{q(A-R)}\frac{sin(t)}{t}dt}{ql} 
    3838 
    39 where the mass *m*\ :sub:`i` is (SLD\ :sub:`i` - SLD\ :sub:`solvent`) \*  
     39where the mass *m*\ :sub:`i` is (SLD\ :sub:`i` - SLD\ :sub:`solvent`) \* 
    4040(volume of the *N* pearls/rods). *V* is the total volume of the necklace. 
    4141 
    42 The 2D scattering intensity is the same as $P(q)$ above, regardless of the  
     42The 2D scattering intensity is the same as $P(q)$ above, regardless of the 
    4343orientation of the *q* vector. 
    4444 
     
    5454REFERENCE 
    5555 
    56 R Schweins and K Huber, *Particle Scattering Factor of Pearl Necklace Chains*,  
     56R Schweins and K Huber, *Particle Scattering Factor of Pearl Necklace Chains*, 
    5757*Macromol. Symp.* 211 (2004) 25-42 2004 
    5858""" 
     
    7979 
    8080#             ["name", "units", default, [lower, upper], "type","description"], 
    81 parameters = [["radius", "Angstrom", 80.0, [0, inf], "volume",  
     81parameters = [["radius", "Angstrom", 80.0, [0, inf], "volume", 
    8282               "Mean radius of the chained spheres"], 
    83               ["edge_separation", "Angstrom", 350.0, [0, inf], "volume",  
     83              ["edge_separation", "Angstrom", 350.0, [0, inf], "volume", 
    8484               "Mean separation of chained particles"], 
    85               ["string_thickness", "Angstrom", 2.5, [0, inf], "volume",  
     85              ["string_thickness", "Angstrom", 2.5, [0, inf], "volume", 
    8686               "Thickness of the chain linkage"], 
    87               ["number_of_pearls", "none", 3, [0, inf], "volume",  
     87              ["number_of_pearls", "none", 3, [0, inf], "volume", 
    8888               "Mean number of pearls in each necklace"], 
    89               ["sld", "Angstrom^2", 1.0, [-inf, inf], "",  
     89              ["sld", "Angstrom^2", 1.0, [-inf, inf], "", 
    9090               "Scattering length density of the chained spheres"], 
    91               ["string_sld", "Angstrom^2", 1.0, [-inf, inf], "",  
     91              ["string_sld", "Angstrom^2", 1.0, [-inf, inf], "", 
    9292               "Scattering length density of the chain linkage"], 
    93               ["solvent_sld", "Angstrom^2", 6.3, [-inf, inf], "",  
     93              ["solvent_sld", "Angstrom^2", 6.3, [-inf, inf], "", 
    9494               "Scattering length density of the solvent"], 
    95               ] 
     95             ] 
    9696 
    9797source = ["lib/Si.c", "pearl_necklace.c"] 
     
    110110# names and the target sasview model name. 
    111111oldname = 'PearlNecklaceModel' 
    112 oldpars = dict(scale='scale',background='background',radius='radius', 
     112oldpars = dict(scale='scale', background='background', radius='radius', 
    113113               number_of_pearls='num_pearls', solvent_sld='sld_solv', 
    114114               string_thickness='thick_string', sld='sld_pearl', 
  • sasmodels/models/power_law.py

    reb69cce r841753c  
    1212    I(q) = \text{scale} \cdot q^{-\text{power}} + \text{background} 
    1313 
    14 Note the minus sign in front of the exponent. The exponent *power*  
     14Note the minus sign in front of the exponent. The exponent *power* 
    1515should therefore be entered as a **positive** number for fitting. 
    1616 
    17 Also note that unlike many other models, *scale* in this model  
    18 is NOT explicitly related to a volume fraction. Be careful if  
     17Also note that unlike many other models, *scale* in this model 
     18is NOT explicitly related to a volume fraction. Be careful if 
    1919combining this model with other models. 
    2020 
     
    3131from numpy import inf, sqrt 
    3232 
    33 name =  "power_law" 
     33name = "power_law" 
    3434title = "Simple power law with a flat background" 
    3535 
    36 description = """\ 
    37         Evaluates the function 
    38         I(q) = scale * q^(-power) + background 
    39         NB: enter power as a positive number! 
    40         """ 
     36description = """ 
     37    Evaluates the function 
     38    I(q) = scale * q^(-power) + background 
     39    NB: enter power as a positive number! 
     40    """ 
    4141category = "shape-independent" 
    4242 
     
    4545 
    4646# NB: Scale and Background are implicit parameters on every model 
    47 def Iq(q,power): 
     47def Iq(q, power): 
     48    # pylint: disable=missing-docstring 
    4849    inten = (q**-power) 
    4950    return inten 
     
    5152 
    5253def Iqxy(qx, qy, *args): 
     54    # pylint: disable=missing-docstring 
    5355    return Iq(sqrt(qx ** 2 + qy ** 2), *args) 
    5456Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values 
     
    6466 
    6567tests = [ 
    66         [ {'scale': 1.0, 'power': 4.0, 'background' : 0.0}, [0.0106939, 0.469418], [7.64644e+07, 20.5949]] 
    67         ] 
     68    [{'scale': 1.0, 'power': 4.0, 'background' : 0.0}, 
     69     [0.0106939, 0.469418], [7.64644e+07, 20.5949]], 
     70    ] 
  • sasmodels/resolution2d.py

    r9404dd3 r841753c  
    22#This software was developed by the University of Tennessee as part of the 
    33#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    4 #project funded by the US National Science Foundation.  
     4#project funded by the US National Science Foundation. 
    55#See the license text in license.txt 
    66""" 
     
    1919## Defaults 
    2020NR = {'xhigh':10, 'high':5, 'med':5, 'low':3} 
    21 NPHI ={'xhigh':20, 'high':12, 'med':6, 'low':4} 
     21NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4} 
    2222 
    2323class Pinhole2D(Resolution): 
     
    2525    Gaussian Q smearing class for SAS 2d data 
    2626    """ 
    27       
     27 
    2828    def __init__(self, data=None, index=None, 
    2929                 nsigma=NSIGMA, accuracy='Low', coords='polar'): 
    3030        """ 
    3131        Assumption: equally spaced bins in dq_r, dq_phi space. 
    32          
     32 
    3333        :param data: 2d data used to set the smearing parameters 
    3434        :param index: 1d array with len(data) to define the range 
     
    4242        ## number of bins in r axis for over-sampling 
    4343        self.nr = NR[accuracy.lower()] 
    44         ## number of bins in phi axis for over-sampling  
     44        ## number of bins in phi axis for over-sampling 
    4545        self.nphi = NPHI[accuracy.lower()] 
    4646        ## maximum nsigmas 
    47         self.nsigma= nsigma 
     47        self.nsigma = nsigma 
    4848        self.coords = coords 
    4949        self._init_data(data, index) 
     
    8585    def _calc_res(self): 
    8686        """ 
    87         Over sampling of r_nbins times phi_nbins, calculate Gaussian weights,  
     87        Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 
    8888        then find smeared intensity 
    89         """     
     89        """ 
    9090        nr, nphi = self.nr, self.nphi 
    9191        # Total number of bins = # of bins 
     
    143143        if self.coords == 'polar': 
    144144            q_r = sqrt(qx**2 + qy**2) 
    145             qx_res = ( (dqx*cos(dphi) + q_r) * cos(-q_phi) + 
     145            qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) + 
    146146                           dqy*sin(dphi) * sin(-q_phi)) 
    147147            qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) + 
     
    167167        else: 
    168168            return theory 
    169  
    170 """ 
    171 if __name__ == '__main__': 
    172     ## Test w/ 2D linear function 
    173     x = 0.001*np.arange(1, 11) 
    174     dx = np.ones(len(x))*0.0003 
    175     y = 0.001*np.arange(1, 11) 
    176     dy = np.ones(len(x))*0.001 
    177     z = np.ones(10) 
    178     dz = sqrt(z) 
    179  
    180     from sas.dataloader import Data2D 
    181     #for i in range(10): print(i, 0.001 + i*0.008/9.0) 
    182     #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) ))) 
    183     out = Data2D() 
    184     out.data = z 
    185     out.qx_data = x 
    186     out.qy_data = y 
    187     out.dqx_data = dx 
    188     out.dqy_data = dy 
    189     out.q_data = sqrt(dx * dx + dy * dy) 
    190     index = np.ones(len(x), dtype = bool) 
    191     out.mask = index 
    192     from sas.models.LineModel import LineModel 
    193     model = LineModel() 
    194     model.setParam("A", 0) 
    195  
    196     smear = Smearer2D(out, model, index) 
    197     #smear.set_accuracy('Xhigh') 
    198     value = smear.get_value() 
    199     ## All data are ones, so the smeared should also be ones. 
    200     print("Data length =", len(value)) 
    201     print(" 2D linear function, I = 0 + 1*qy") 
    202     text = " Gaussian weighted averaging on a 2D linear function will " 
    203     text += "provides the results same as without the averaging." 
    204     print(text) 
    205     print("qx_data", "qy_data", "I_nonsmear", "I_smeared") 
    206     for ind in range(len(value)): 
    207         print(x[ind], y[ind], model.evalDistribution([x, y])[ind], value[ind]) 
    208  
    209  
    210 if __name__ == '__main__': 
    211     ## Another Test w/ constant function 
    212     x = 0.001*np.arange(1,11) 
    213     dx = np.ones(len(x))*0.001 
    214     y = 0.001*np.arange(1,11) 
    215     dy = np.ones(len(x))*0.001 
    216     z = np.ones(10) 
    217     dz = sqrt(z) 
    218  
    219     from DataLoader import Data2D 
    220     #for i in range(10): print(i, 0.001 + i*0.008/9.0) 
    221     #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) ))) 
    222     out = Data2D() 
    223     out.data = z 
    224     out.qx_data = x 
    225     out.qy_data = y 
    226     out.dqx_data = dx 
    227     out.dqy_data = dy 
    228     index = np.ones(len(x), dtype = bool) 
    229     out.mask = index 
    230     from sas.models.Constant import Constant 
    231     model = Constant() 
    232  
    233     value = Smearer2D(out,model,index).get_value() 
    234     ## All data are ones, so the smeared values should also be ones. 
    235     print("Data length =",len(value), ", Data=",value) 
    236 """ 
Note: See TracChangeset for help on using the changeset viewer.