Changeset d07c883 in sasmodels


Ignore:
Timestamp:
Jan 29, 2016 7:49:42 AM (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:
803f835
Parents:
299edd2 (diff), ed82794 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of github.com:sasview/sasmodels

Location:
sasmodels
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/bumps_model.py

    r37a7252 r190fc2b  
    1212""" 
    1313 
     14import warnings 
     15 
     16import numpy as np 
     17 
     18from .data import plot_theory 
     19from .direct_model import DataMixin 
     20 
    1421__all__ = [ 
    1522    "Model", "Experiment", 
    1623    ] 
    17  
    18 import warnings 
    19  
    20 import numpy as np 
    21  
    22 from .data import plot_theory 
    23 from .direct_model import DataMixin 
    2424 
    2525# CRUFT: old style bumps wrapper which doesn't separate data and model 
  • sasmodels/compare.py

    r1d4017a rd07c883  
    2828 
    2929from __future__ import print_function 
     30 
     31import sys 
     32import math 
     33from os.path import basename, dirname, join as joinpath 
     34import glob 
     35import datetime 
     36import traceback 
     37 
     38import numpy as np 
     39 
     40from . import core 
     41from . import kerneldll 
     42from . import generate 
     43from .data import plot_theory, empty_data1D, empty_data2D 
     44from .direct_model import DirectModel 
     45from .convert import revert_model, constrain_new_to_old 
    3046 
    3147USAGE = """ 
     
    8096           + USAGE) 
    8197 
    82  
    83  
    84 import sys 
    85 import math 
    86 from os.path import basename, dirname, join as joinpath 
    87 import glob 
    88 import datetime 
    89 import traceback 
    90  
    91 import numpy as np 
    92  
     98kerneldll.ALLOW_SINGLE_PRECISION_DLLS = True 
     99 
     100# List of available models 
    93101ROOT = dirname(__file__) 
    94 sys.path.insert(0, ROOT)  # Make sure sasmodels is first on the path 
    95  
    96  
    97 from . import core 
    98 from . import kerneldll 
    99 from . import generate 
    100 from .data import plot_theory, empty_data1D, empty_data2D 
    101 from .direct_model import DirectModel 
    102 from .convert import revert_model, constrain_new_to_old 
    103 kerneldll.ALLOW_SINGLE_PRECISION_DLLS = True 
    104  
    105 # List of available models 
    106102MODELS = [basename(f)[:-3] 
    107103          for f in sorted(glob.glob(joinpath(ROOT, "models", "[a-zA-Z]*.py")))] 
  • sasmodels/core.py

    r1d4017a rd07c883  
    22Core model handling routines. 
    33""" 
    4 __all__ = [ 
    5     "list_models", "load_model_definition", "precompile_dll", 
    6     "load_model", "make_kernel", "call_kernel", "call_ER", "call_VR", 
    7     ] 
    84 
    95from os.path import basename, dirname, join as joinpath 
     
    2420    HAVE_OPENCL = False 
    2521 
     22__all__ = [ 
     23    "list_models", "load_model_definition", "precompile_dll", 
     24    "load_model", "make_kernel", "call_kernel", "call_ER", "call_VR", 
     25] 
    2626 
    2727def list_models(): 
  • sasmodels/generate.py

    re66c9f9 r190fc2b  
    197197# TODO: identify model files which have changed since loading and reload them. 
    198198 
    199 __all__ = ["make", "doc", "sources", "convert_type"] 
    200  
    201199import sys 
    202200from os.path import abspath, dirname, join as joinpath, exists, basename, \ 
     
    206204 
    207205import numpy as np 
     206 
     207__all__ = ["make", "doc", "sources", "convert_type"] 
     208 
    208209C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 
    209210 
     
    216217    F128 = None 
    217218 
    218  
    219219# Scale and background, which are parameters common to every form factor 
    220220COMMON_PARAMETERS = [ 
     
    222222    ["background", "1/cm", 0, [0, np.inf], "", "Source background"], 
    223223    ] 
    224  
    225224 
    226225# Conversion from units defined in the parameter table for each model 
     
    266265 
    267266def format_units(units): 
     267    """ 
     268    Convert units into ReStructured Text format. 
     269    """ 
    268270    return "string" if isinstance(units, list) else RST_UNITS.get(units, units) 
    269271 
     
    335337    """ 
    336338    Convert code from double precision to the desired type. 
     339 
     340    Floating point constants are tagged with 'f' for single precision or 'L' 
     341    for long double precision. 
    337342    """ 
    338343    if dtype == F16: 
     
    350355 
    351356def _convert_type(source, type_name, constant_flag): 
     357    """ 
     358    Replace 'double' with *type_name* in *source*, tagging floating point 
     359    constants with *constant_flag*. 
     360    """ 
    352361    # Convert double keyword to float/long double/half. 
    353362    # Accept an 'n' # parameter for vector # values, where n is 2, 4, 8 or 16. 
     
    625634                            %re.escape(string.punctuation)) 
    626635def _convert_section_titles_to_boldface(lines): 
     636    """ 
     637    Do the actual work of identifying and converting section headings. 
     638    """ 
    627639    prior = None 
    628640    for line in lines: 
     
    642654        yield prior 
    643655 
    644 def convert_section_titles_to_boldface(string): 
    645     return "\n".join(_convert_section_titles_to_boldface(string.split('\n'))) 
     656def convert_section_titles_to_boldface(s): 
     657    """ 
     658    Use explicit bold-face rather than section headings so that the table of 
     659    contents is not polluted with section names from the model documentation. 
     660 
     661    Sections are identified as the title line followed by a line of punctuation 
     662    at least as long as the title line. 
     663    """ 
     664    return "\n".join(_convert_section_titles_to_boldface(s.split('\n'))) 
    646665 
    647666def doc(kernel_module): 
     
    666685 
    667686def demo_time(): 
     687    """ 
     688    Show how long it takes to process a model. 
     689    """ 
    668690    from .models import cylinder 
    669691    import datetime 
     
    674696 
    675697def main(): 
     698    """ 
     699    Program which prints the source produced by the model. 
     700    """ 
    676701    if len(sys.argv) <= 1: 
    677702        print("usage: python -m sasmodels.generate modelname") 
  • sasmodels/models/be_polyelectrolyte.py

    r841753c r168052c  
    4444J F Joanny, L Leibler, *Journal de Physique*, 51 (1990) 545 
    4545 
    46 A Moussaid, F Schosseler, J P Munch, S Candau, *J. Journal de Physique II France*, 3 (1993) 573 
     46A Moussaid, F Schosseler, J P Munch, S Candau, 
     47*J. Journal de Physique II France*, 3 (1993) 573 
    4748 
    4849E Raphael, J F Joanny, *Europhysics Letters*, 11 (1990) 179 
     
    5556title = "Polyelectrolyte with the RPA expression derived by Borue and Erukhimovich" 
    5657description = """ 
    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))) 
     58            Evaluate 
     59            F(x) = K 1/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) 
     60                 (q^(2)+k2) (q^(2)-(12 h C/b^(2))) 
    6061 
    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     """ 
     62            has 3 internal parameters : 
     63                   The inverse Debye Length: K2 = 4 pi Lb (2 Cs+alpha C) 
     64                   r02 =1/alpha/Ca^(0.5) (B/(48 pi Lb)^(0.5)) 
     65                   Ca = 6.022136e-4 C 
     66            """ 
    6667category = "shape-independent" 
    6768 
    68 # pylint: disable=bad-whitespace,line-too-long 
    69 #   ["name",                  "units", default, [lower, upper], "type", "description"], 
     69# pylint: disable=bad-whitespace, line-too-long 
     70#   ["name", "units", default, [lower, upper], "type", "description"], 
    7071parameters = [ 
    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"], 
     72    ["contrast_factor",       "barns",   10.0,  [-inf, inf], "", "Contrast factor of the polymer"], 
     73    ["bjerrum_length",        "Ang",      7.1,  [0, inf],    "", "Bjerrum length"], 
     74    ["virial_param",          "1/Ang^2", 12.0,  [-inf, inf], "", "Virial parameter"], 
     75    ["monomer_length",        "Ang",     10.0,  [0, inf],    "", "Monomer length"], 
     76    ["salt_concentration",    "mol/L",    0.0,  [-inf, inf], "", "Concentration of monovalent salt"], 
     77    ["ionization_degree",     "",         0.05, [0, inf],    "", "Degree of ionization"], 
     78    ["polymer_concentration", "mol/L",    0.7,  [0, inf],    "", "Polymer molar concentration"], 
    7879    ] 
    79 # pylint: enable=bad-whitespace,line-too-long 
     80# pylint: enable=bad-whitespace, line-too-long 
    8081 
    8182 
    8283def Iq(q, 
    83        contrast_factor, 
    84        bjerrum_length, 
    85        virial_param, 
    86        monomer_length, 
    87        salt_concentration, 
    88        ionization_degree, 
    89        polymer_concentration): 
     84       contrast_factor=10.0, 
     85       bjerrum_length=7.1, 
     86       virial_param=12.0, 
     87       monomer_length=10.0, 
     88       salt_concentration=0.0, 
     89       ionization_degree=0.05, 
     90       polymer_concentration=0.7): 
     91    """ 
     92    :param q:                     Input q-value 
     93    :param contrast_factor:       Contrast factor of the polymer 
     94    :param bjerrum_length:        Bjerrum length 
     95    :param virial_param:          Virial parameter 
     96    :param monomer_length:        Monomer length 
     97    :param salt_concentration:    Concentration of monovalent salt 
     98    :param ionization_degree:     Degree of ionization 
     99    :param polymer_concentration: Polymer molar concentration 
     100    :return:                      1-D intensity 
     101    """ 
    90102 
    91103    concentration = polymer_concentration * 6.022136e-4 
    92104 
    93105    k_square = 4.0 * pi * bjerrum_length * (2*salt_concentration + 
    94             ionization_degree * concentration) 
     106                                            ionization_degree * concentration) 
    95107 
    96108    r0_square = 1.0/ionization_degree/sqrt(concentration) * \ 
    97             (monomer_length/sqrt((48.0*pi*bjerrum_length))) 
     109                (monomer_length/sqrt((48.0*pi*bjerrum_length))) 
    98110 
    99111    term1 = contrast_factor/(4.0 * pi * bjerrum_length * 
    100         ionization_degree**2) * (q**2 + k_square) 
     112                             ionization_degree**2) * (q**2 + k_square) 
    101113 
    102114    term2 = 1.0 + r0_square**2 * (q**2 + k_square) * \ 
     
    109121 
    110122def Iqxy(qx, qy, *args): 
    111     return Iq(sqrt(qx**2 + qy**2), *args) 
     123    """ 
     124    :param qx:   Input q_x-value 
     125    :param qy:   Input q_y-value 
     126    :param args: Remaining arguments 
     127    :return:     2D-Intensity 
     128    """ 
     129    iq = Iq(sqrt(qx**2 + qy**2), *args) 
     130    return iq 
    112131 
    113132Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values 
     
    134153               polymer_concentration='c') 
    135154 
    136 # pylint: disable=bad-whitespace 
    137155tests = [ 
     156 
    138157    # Accuracy tests based on content in test/utest_other_models.py 
    139158    [{'contrast_factor':       10.0, 
     
    176195     }, 200., 1.80664667511e-06], 
    177196    ] 
    178 # pylint: enable=bad-whitespace 
  • sasmodels/models/flexible_cylinder.py

    rf94d8a2 r168052c  
    11r""" 
    2 This model provides the form factor, $P(q)$, for a flexible cylinder where the form factor 
    3 is normalized by the volume of the cylinder. 
     2This model provides the form factor, $P(q)$, for a flexible cylinder 
     3where the form factor is normalized by the volume of the cylinder. 
    44**Inter-cylinder interactions are NOT provided for.** 
    55 
     
    88    P(q) = \text{scale} \left<F^2\right>/V + \text{background} 
    99 
    10 where the averaging $\left<\ldots\right>$ is applied only for the 1D calculation 
     10where the averaging $\left<\ldots\right>$ is applied only for the 1D 
     11calculation 
    1112 
    12 The 2D scattering intensity is the same as 1D, regardless of the orientation of the q vector which is defined as 
     13The 2D scattering intensity is the same as 1D, regardless of the orientation of 
     14the q vector which is defined as 
    1315 
    1416.. math:: 
     
    2224 
    2325 
    24 The chain of contour length, $L$, (the total length) can be described as a chain of some number of 
    25 locally stiff segments of length $l_p$, the persistence length (the length along the cylinder over 
    26 which the flexible cylinder can be considered a rigid rod). 
     26The chain of contour length, $L$, (the total length) can be described as a 
     27chain of some number of locally stiff segments of length $l_p$, the persistence 
     28length (the length along the cylinder over which the flexible cylinder can be 
     29considered a rigid rod). 
    2730The Kuhn length $(b = 2*l_p)$ is also used to describe the stiffness of a chain. 
    2831 
    2932The returned value is in units of $cm^-1$, on absolute scale. 
    3033 
    31 In the parameters, the sldCyl and sldSolv represent the SLD of the chain/cylinder and solvent respectively. 
     34In the parameters, the sldCyl and sldSolv represent the SLD of the chain/cylinder 
     35and solvent respectively. 
    3236 
    3337 
     
    3741 
    3842 
    39 Our model uses the form factor calculations implemented in a c-library provided by the NIST Center 
    40 for Neutron Research (Kline, 2006). 
     43Our model uses the form factor calculations implemented in a c-library provided 
     44by the NIST Center for Neutron Research (Kline, 2006). 
    4145 
    4246 
     
    4549    'Method 3 With Excluded Volume' is used. 
    4650    The model is a parametrization of simulations of a discrete representation 
    47     of the worm-like chain model of Kratky and Porod applied in the pseudocontinuous limit. 
     51    of the worm-like chain model of Kratky and Porod applied in the 
     52    pseudocontinuous limit. 
    4853    See equations (13,26-27) in the original reference for the details. 
    4954 
     
    5156---------- 
    5257 
    53 J S Pedersen and P Schurtenberger. *Scattering functions of semiflexible polymers with and 
    54 without excluded volume effects.* Macromolecules, 29 (1996) 7602-7612 
     58J S Pedersen and P Schurtenberger. *Scattering functions of semiflexible 
     59polymers with and without excluded volume effects.* Macromolecules, 
     6029 (1996) 7602-7612 
    5561 
    5662Correction of the formula can be found in 
    5763 
    58 W R Chen, P D Butler and L J Magid, *Incorporating Intermicellar Interactions in the Fitting of 
    59 SANS Data from Cationic Wormlike Micelles.* Langmuir, 22(15) 2006 6539-6548 
     64W R Chen, P D Butler and L J Magid, *Incorporating Intermicellar Interactions 
     65in the Fitting of SANS Data from Cationic Wormlike Micelles.* Langmuir, 
     6622(15) 2006 6539-6548 
    6067""" 
    6168from numpy import inf 
    6269 
    6370name = "flexible_cylinder" 
    64 title = "Flexible cylinder where the form factor is normalized by the volume of the cylinder." 
    65 description = """Note : scale and contrast=sld-solvent_sld are both multiplicative factors in the 
    66                 model and are perfectly correlated. One or 
    67                 both of these parameters must be held fixed 
     71title = "Flexible cylinder where the form factor is normalized by the volume" \ 
     72        "of the cylinder." 
     73description = """Note : scale and contrast=sld-solvent_sld are both 
     74                multiplicative factors in the model and are perfectly 
     75                correlated. One or both of these parameters must be held fixed 
    6876                during model fitting. 
    6977              """ 
     
    7179category = "shape:cylinder" 
    7280 
     81# pylint: disable=bad-whitespace, line-too-long 
    7382#             ["name", "units", default, [lower, upper], "type", "description"], 
    7483parameters = [ 
    75               ["length",      "Ang",       1000.0, [0, inf],    "volume", "Length of the flexible cylinder"], 
    76               ["kuhn_length", "Ang",        100.0, [0, inf],    "volume", "Kuhn length of the flexible cylinder"], 
    77               ["radius",      "Ang",         20.0, [0, inf],    "volume", "Radius of the flexible cylinder"], 
    78               ["sld",         "1e-6/Ang^2",   1.0, [-inf, inf], "",       "Cylinder scattering length density"], 
    79               ["solvent_sld", "1e-6/Ang^2",   6.3, [-inf, inf], "",       "Solvent scattering length density"], 
    80              ] 
    81  
     84    ["length",      "Ang",       1000.0, [0, inf],    "volume", "Length of the flexible cylinder"], 
     85    ["kuhn_length", "Ang",        100.0, [0, inf],    "volume", "Kuhn length of the flexible cylinder"], 
     86    ["radius",      "Ang",         20.0, [0, inf],    "volume", "Radius of the flexible cylinder"], 
     87    ["sld",         "1e-6/Ang^2",   1.0, [-inf, inf], "",       "Cylinder scattering length density"], 
     88    ["solvent_sld", "1e-6/Ang^2",   6.3, [-inf, inf], "",       "Solvent scattering length density"], 
     89    ] 
     90# pylint: enable=bad-whitespace, line-too-long 
    8291source = ["lib/J1.c", "lib/wrc_cyl.c", "flexible_cylinder.c"] 
    8392 
     
    94103 
    95104tests = [ 
    96          # Accuracy tests based on content in test/utest_other_models.py 
    97          # Currently fails in OCL 
    98          # [{'length':     1000.0, 
    99          #  'kuhn_length': 100.0, 
    100          #  'radius':       20.0, 
    101          #  'sld':           1.0, 
    102          #  'solvent_sld':   6.3, 
    103          #  'background':    0.0001, 
    104          #  }, 0.001, 3509.2187], 
     105    # Accuracy tests based on content in test/utest_other_models.py 
     106    # Currently fails in OCL 
     107    # [{'length':     1000.0, 
     108    #  'kuhn_length': 100.0, 
     109    #  'radius':       20.0, 
     110    #  'sld':           1.0, 
     111    #  'solvent_sld':   6.3, 
     112    #  'background':    0.0001, 
     113    #  }, 0.001, 3509.2187], 
    105114 
    106          # Additional tests with larger range of parameters 
    107          [{'length':     1000.0, 
    108            'kuhn_length': 100.0, 
    109            'radius':       20.0, 
    110            'sld':           1.0, 
    111            'solvent_sld':   6.3, 
    112            'background':    0.0001, 
    113            }, 1.0, 0.000595345], 
    114         [{'length':        10.0, 
    115            'kuhn_length': 800.0, 
    116            'radius':        2.0, 
    117            'sld':           6.0, 
    118            'solvent_sld':  12.3, 
    119            'background':    0.001, 
    120            }, 0.1, 1.55228], 
    121        [{'length':        100.0, 
    122            'kuhn_length': 800.0, 
    123            'radius':       50.0, 
    124            'sld':           0.1, 
    125            'solvent_sld':   5.1, 
    126            'background':    0.0, 
    127            }, 1.0, 0.000938456] 
    128          ] 
     115    # Additional tests with larger range of parameters 
     116    [{'length':    1000.0, 
     117      'kuhn_length': 100.0, 
     118      'radius':       20.0, 
     119      'sld':           1.0, 
     120      'solvent_sld':   6.3, 
     121      'background':    0.0001, 
     122     }, 1.0, 0.000595345], 
     123    [{'length':        10.0, 
     124      'kuhn_length': 800.0, 
     125      'radius':        2.0, 
     126      'sld':           6.0, 
     127      'solvent_sld':  12.3, 
     128      'background':    0.001, 
     129     }, 0.1, 1.55228], 
     130    [{'length':        100.0, 
     131      'kuhn_length': 800.0, 
     132      'radius':       50.0, 
     133      'sld':           0.1, 
     134      'solvent_sld':   5.1, 
     135      'background':    0.0, 
     136     }, 1.0, 0.000938456] 
     137    ] 
    129138 
  • sasmodels/models/gauss_lorentz_gel.py

    r07a6700 r168052c  
    4242---------- 
    4343 
    44 G Evmenenko, E Theunissen, K Mortensen, H Reynaers, *Polymer*, 42 (2001) 2907-2913 
     44G Evmenenko, E Theunissen, K Mortensen, H Reynaers, *Polymer*, 
     4542 (2001) 2907-2913 
    4546 
    4647""" 
    4748 
    48 from numpy import inf, pi, sqrt, exp 
     49from numpy import inf, sqrt, exp 
    4950 
    5051name = "gauss_lorentz_gel" 
     
    6364            """ 
    6465category = "shape-independent" 
    65  
     66# pylint: disable=bad-whitespace, line-too-long 
    6667#            ["name", "units", default, [lower, upper], "type", "description"], 
    6768parameters = [["gauss_scale_factor",   "",    100.0,  [-inf, inf], "", "Gauss scale factor"], 
     
    6970              ["lorentz_scale_factor", "",     50.0,  [-inf, inf], "", "Lorentzian scale factor"], 
    7071              ["dynamic_cor_length",   "Ang",  20.0,  [0, inf],    "", "Dynamic correlation length"], 
    71               ] 
    72  
     72             ] 
     73# pylint: enable=bad-whitespace, line-too-long 
    7374 
    7475def Iq(q, 
    75        gauss_scale_factor, 
    76        static_cor_length, 
    77        lorentz_scale_factor, 
    78        dynamic_cor_length): 
     76       gauss_scale_factor=100.0, 
     77       static_cor_length=100.0, 
     78       lorentz_scale_factor=50.0, 
     79       dynamic_cor_length=20.0): 
     80    """ 
    7981 
    80         term1 = gauss_scale_factor *\ 
    81                 exp(-1.0*q*q*static_cor_length*static_cor_length/2.0) 
    82         term2 = lorentz_scale_factor /\ 
    83                 (1.0+(q*dynamic_cor_length)*(q*dynamic_cor_length)) 
     82    :param q:                    Input q-value 
     83    :param gauss_scale_factor:   Gauss scale factor 
     84    :param static_cor_length:    Static correlation length 
     85    :param lorentz_scale_factor: Lorentzian scale factor 
     86    :param dynamic_cor_length:   Dynamic correlation length 
     87    :return:                     1-D intensity 
     88    """ 
    8489 
    85         return term1 + term2 
     90    term1 = gauss_scale_factor *\ 
     91            exp(-1.0*q*q*static_cor_length*static_cor_length/2.0) 
     92    term2 = lorentz_scale_factor /\ 
     93            (1.0+(q*dynamic_cor_length)*(q*dynamic_cor_length)) 
     94 
     95    return term1 + term2 
    8696 
    8797Iq.vectorized = True  # Iq accepts an array of q values 
     
    8999 
    90100def Iqxy(qx, qy, *args): 
    91         iq = Iq(sqrt(qx**2 + qy**2), *args) 
     101    """ 
     102    :param qx:   Input q_x-value 
     103    :param qy:   Input q_y-value 
     104    :param args: Remaining aruments 
     105    :return:     2-D intensity 
     106    """ 
    92107 
    93         return iq 
     108    return Iq(sqrt(qx**2 + qy**2), *args) 
    94109 
    95110Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values 
     
    111126 
    112127tests = [ 
    113          # Accuracy tests based on content in test/utest_extra_models.py 
    114          [{'gauss_scale_factor':  100.0, 
    115            'static_cor_length':   100.0, 
    116            'lorentz_scale_factor': 50.0, 
    117            'dynamic_cor_length':   20.0, 
    118            }, 0.001, 149.481], 
    119128 
    120          [{'gauss_scale_factor':  100.0, 
    121            'static_cor_length':   100.0, 
    122            'lorentz_scale_factor': 50.0, 
    123            'dynamic_cor_length':   20.0, 
    124            }, 0.105363, 9.1903], 
     129    # Accuracy tests based on content in test/utest_extra_models.py 
     130    [{'gauss_scale_factor':  100.0, 
     131      'static_cor_length':   100.0, 
     132      'lorentz_scale_factor': 50.0, 
     133      'dynamic_cor_length':   20.0, 
     134     }, 0.001, 149.481], 
    125135 
    126          [{'gauss_scale_factor':  100.0, 
    127            'static_cor_length':   100.0, 
    128            'lorentz_scale_factor': 50.0, 
    129            'dynamic_cor_length':   20.0, 
    130            }, 0.441623, 0.632811], 
     136    [{'gauss_scale_factor':  100.0, 
     137      'static_cor_length':   100.0, 
     138      'lorentz_scale_factor': 50.0, 
     139      'dynamic_cor_length':   20.0, 
     140     }, 0.105363, 9.1903], 
    131141 
    132          # Additional tests with larger range of parameters 
    133          [{'gauss_scale_factor':  10.0, 
    134            'static_cor_length':  100.0, 
    135            'lorentz_scale_factor': 3.0, 
    136            'dynamic_cor_length':   1.0, 
    137            }, 0.1, 2.9702970297], 
     142    [{'gauss_scale_factor':  100.0, 
     143      'static_cor_length':   100.0, 
     144      'lorentz_scale_factor': 50.0, 
     145      'dynamic_cor_length':   20.0, 
     146     }, 0.441623, 0.632811], 
    138147 
    139          [{'gauss_scale_factor':  10.0, 
    140            'static_cor_length':  100.0, 
    141            'lorentz_scale_factor': 3.0, 
    142            'dynamic_cor_length':   1.0, 
    143            'background':         100.0 
    144            }, 5.0, 100.115384615], 
     148    # Additional tests with larger range of parameters 
     149    [{'gauss_scale_factor':  10.0, 
     150      'static_cor_length':  100.0, 
     151      'lorentz_scale_factor': 3.0, 
     152      'dynamic_cor_length':   1.0, 
     153     }, 0.1, 2.9702970297], 
    145154 
    146          [{'gauss_scale_factor':  10.0, 
    147            'static_cor_length':  100.0, 
    148            'lorentz_scale_factor': 3.0, 
    149            'dynamic_cor_length':   1.0, 
    150            }, 200., 7.49981250469e-05], 
    151          ] 
     155    [{'gauss_scale_factor':  10.0, 
     156      'static_cor_length':  100.0, 
     157      'lorentz_scale_factor': 3.0, 
     158      'dynamic_cor_length':   1.0, 
     159      'background':         100.0 
     160     }, 5.0, 100.115384615], 
     161 
     162    [{'gauss_scale_factor':  10.0, 
     163      'static_cor_length':  100.0, 
     164      'lorentz_scale_factor': 3.0, 
     165      'dynamic_cor_length':   1.0, 
     166     }, 200., 7.49981250469e-05], 
     167    ] 
  • sasmodels/models/gel_fit.py

    r513efc5 r168052c  
    77in the position of the polymer chains that ensure thermodynamic equilibrium, 
    88and a longer distance (denoted here as $a2$ ) needed to account for the static 
    9 accumulations of polymer pinned down by junction points or clusters of such points. 
    10 The latter is derived from a simple Guinier function. 
     9accumulations of polymer pinned down by junction points or clusters of such 
     10points. The latter is derived from a simple Guinier function. 
    1111 
    1212 
     
    4040--------- 
    4141 
    42 Mitsuhiro Shibayama, Toyoichi Tanaka, Charles C Han, J. Chem. Phys. 1992, 97 (9), 
    43 6829-6841 
     42Mitsuhiro Shibayama, Toyoichi Tanaka, Charles C Han, 
     43*J. Chem. Phys.* 1992, 97 (9), 6829-6841 
    4444 
    4545Simon Mallam, Ferenc Horkay, Anne-Marie Hecht, Adrian R Rennie, Erik Geissler, 
    46 Macromolecules 1991, 24, 543-548 
     46*Macromolecules* 1991, 24, 543-548 
    4747 
    4848""" 
     
    6262category = "shape-independent" 
    6363 
     64# pylint: disable=bad-whitespace, line-too-long 
    6465#             ["name", "units", default, [lower, upper], "type","description"], 
    6566parameters = [["guinier_scale",    "cm^{-1}",   1.7, [-inf, inf], "", "Guinier length scale"], 
     
    6869              ["fractal_exp",      "",          2.0, [0, inf],    "", "Fractal exponent"], 
    6970              ["cor_length",       "Ang",      16.0, [0, inf],    "", "Correlation length"] 
    70               ] 
    71  
     71             ] 
     72# pylint: enable=bad-whitespace, line-too-long 
    7273 
    7374source = ["gel_fit.c"] 
     
    9293           'fractal_exp': 10.0, 
    9394           'cor_length': 20.0 
    94            }, 0.1, 0.716532], 
     95          }, 0.1, 0.716532], 
    9596 
    9697         [{'guinier_scale': 4.0, 
     
    100101           'cor_length': 20.0, 
    101102           'background': 20.0, 
    102            }, 5.0, 20.1224653026], 
    103  
    104          ] 
     103          }, 5.0, 20.1224653026], 
     104        ] 
  • sasmodels/models/mass_fractal.py

    r87edabf r168052c  
    5252--------- 
    5353 
    54 D Mildner and P Hall, *J. Phys. D: Appl. Phys.*,  19 (1986) 1535-1545 Equation(9) 
     54D Mildner and P Hall, *J. Phys. D: Appl. Phys.*, 
     5519 (1986) 1535-1545 Equation(9) 
    5556 
    5657 
     
    7980category = "shape-independent" 
    8081 
     82# pylint: disable=bad-whitespace, line-too-long 
    8183#             ["name", "units", default, [lower, upper], "type","description"], 
    8284parameters = [["radius",        "Ang",  10.0, [0.0, inf], "", "Particle radius"], 
    8385              ["mass_dim",      "",      1.9, [1.0, 6.0], "", "Mass fractal dimension"], 
    8486              ["cutoff_length", "Ang", 100.0, [0.0, inf], "", "Cut-off length"], 
    85               ] 
    86  
     87             ] 
     88# pylint: enable=bad-whitespace, line-too-long 
    8789 
    8890source = ["lib/sph_j1c.c", "lib/lanczos_gamma.c", "mass_fractal.c"] 
     
    99101 
    100102tests = [ 
    101          # Accuracy tests based on content in test/utest_other_models.py 
    102          [{'radius':         10.0, 
    103            'mass_dim':        1.9, 
    104            'cutoff_length': 100.0, 
    105            }, 0.05, 279.59322], 
    106103 
    107          # Additional tests with larger range of parameters 
    108          [{'radius':        2.0, 
    109            'mass_dim':      3.3, 
    110            'cutoff_length': 1.0, 
    111            }, 0.5, 1.29016774904], 
     104    # Accuracy tests based on content in test/utest_other_models.py 
     105    [{'radius':         10.0, 
     106      'mass_dim':        1.9, 
     107      'cutoff_length': 100.0, 
     108     }, 0.05, 279.59322], 
    112109 
    113          [{'radius':        1.0, 
    114            'mass_dim':      1.3, 
    115            'cutoff_length': 1.0, 
    116            'background':    0.8, 
    117            }, 0.001, 1.69747015932], 
     110    # Additional tests with larger range of parameters 
     111    [{'radius':        2.0, 
     112      'mass_dim':      3.3, 
     113      'cutoff_length': 1.0, 
     114     }, 0.5, 1.29016774904], 
    118115 
    119          [{'radius':        1.0, 
    120            'mass_dim':      2.3, 
    121            'cutoff_length': 1.0, 
    122            'scale':        10.0, 
    123            }, 0.051, 11.6227966145], 
    124          ] 
     116    [{'radius':        1.0, 
     117      'mass_dim':      1.3, 
     118      'cutoff_length': 1.0, 
     119      'background':    0.8, 
     120     }, 0.001, 1.69747015932], 
     121 
     122    [{'radius':        1.0, 
     123      'mass_dim':      2.3, 
     124      'cutoff_length': 1.0, 
     125      'scale':        10.0, 
     126     }, 0.051, 11.6227966145], 
     127    ] 
  • sasmodels/models/mass_surface_fractal.py

    r07a6700 r168052c  
    5454P Schmidt, *J Appl. Cryst.*, 24 (1991) 414-435 Equation(19) 
    5555 
    56 A J Hurd, D W Schaefer, J E Martin, *Phys. Rev. A*, 35 (1987) 2361-2364 Equation(2) 
     56A J Hurd, D W Schaefer, J E Martin, *Phys. Rev. A*, 
     5735 (1987) 2361-2364 Equation(2) 
    5758 
    5859""" 
     
    7980category = "shape-independent" 
    8081 
     82# pylint: disable=bad-whitespace, line-too-long 
    8183#             ["name", "units", default, [lower, upper], "type","description"], 
    8284parameters = [["mass_dim",      "",    1.8, [1e-16, 6.0], "", 
     
    8890              ["primary_rg", "Ang", 4000.,  [0.0, inf], "", 
    8991               "Primary particle radius of gyration"], 
    90               ] 
    91  
     92             ] 
     93# pylint: enable=bad-whitespace, line-too-long 
    9294 
    9395source = ["mass_surface_fractal.c"] 
     
    107109 
    108110tests = [ 
    109          # Accuracy tests based on content in test/utest_other_models.py 
    110          [{'mass_dim':      1.8, 
    111            'surface_dim':   2.3, 
    112            'cluster_rg':   86.7, 
    113            'primary_rg': 4000.0, 
    114            }, 0.05, 1.77537e-05], 
    115111 
    116          # Additional tests with larger range of parameters 
    117          [{'mass_dim':      3.3, 
    118            'surface_dim':   1.0, 
    119            'cluster_rg':   90.0, 
    120            'primary_rg': 4000.0, 
    121            }, 0.001, 0.18462699016], 
     112    # Accuracy tests based on content in test/utest_other_models.py 
     113    [{'mass_dim':      1.8, 
     114      'surface_dim':   2.3, 
     115      'cluster_rg':   86.7, 
     116      'primary_rg': 4000.0, 
     117     }, 0.05, 1.77537e-05], 
    122118 
    123          [{'mass_dim':      1.3, 
    124            'surface_dim':   1.0, 
    125            'cluster_rg':   90.0, 
    126            'primary_rg': 2000.0, 
    127            'background':    0.8, 
    128            }, 0.001, 1.16539753641], 
     119    # Additional tests with larger range of parameters 
     120    [{'mass_dim':      3.3, 
     121      'surface_dim':   1.0, 
     122      'cluster_rg':   90.0, 
     123      'primary_rg': 4000.0, 
     124     }, 0.001, 0.18462699016], 
    129125 
    130          [{'mass_dim':      2.3, 
    131            'surface_dim':   1.0, 
    132            'cluster_rg':   90.0, 
    133            'primary_rg': 1000.0, 
    134            'scale':        10.0, 
    135            }, 0.051, 0.000169548800377], 
    136          ] 
     126    [{'mass_dim':      1.3, 
     127      'surface_dim':   1.0, 
     128      'cluster_rg':   90.0, 
     129      'primary_rg': 2000.0, 
     130      'background':    0.8, 
     131     }, 0.001, 1.16539753641], 
     132 
     133    [{'mass_dim':      2.3, 
     134      'surface_dim':   1.0, 
     135      'cluster_rg':   90.0, 
     136      'primary_rg': 1000.0, 
     137      'scale':        10.0, 
     138     }, 0.051, 0.000169548800377], 
     139    ] 
  • sasmodels/models/polymer_excl_volume.py

    r07a6700 r168052c  
    113113category = "shape-independent" 
    114114 
     115# pylint: disable=bad-whitespace, line-too-long 
    115116#             ["name", "units", default, [lower, upper], "type", "description"], 
    116117parameters = [["rg",        "Ang", 60.0, [0, inf],    "", "Radius of Gyration"], 
    117118              ["porod_exp", "",     3.0, [-inf, inf], "", "Porod exponent"], 
    118               ] 
     119             ] 
     120# pylint: enable=bad-whitespace, line-too-long 
    119121 
    120122 
    121 def Iq(q, rg, porod_exp): 
    122  
     123def Iq(q, 
     124       rg=60.0, 
     125       porod_exp=3.0): 
    123126    """ 
    124127    :param q:         Input q-value (float or [float, float]) 
     
    131134    o2nu = 1.0/(2.0*nu) 
    132135 
    133     intensity = ((1.0/(nu*power(u, o2nu))) * (gamma(o2nu)*gammainc(o2nu, u) - 
     136    intensity = ((1.0/(nu*power(u, o2nu))) * 
     137                 (gamma(o2nu)*gammainc(o2nu, u) - 
    134138                  1.0/power(u, o2nu) * gamma(porod_exp) * 
    135139                  gammainc(porod_exp, u))) * (q > 0) + 1.0*(q <= 0) 
     
    141145 
    142146def Iqxy(qx, qy, *args): 
    143         iq = Iq(sqrt(qx**2 + qy**2), *args) 
     147    """ 
     148    :param qx:   Input q_x-value 
     149    :param qy:   Input q_y-value 
     150    :param args: Remaining arguments 
     151    :return:     2D-Intensity 
     152    """ 
    144153 
    145         return iq 
     154    return Iq(sqrt(qx**2 + qy**2), *args) 
    146155 
    147156Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values 
     
    158167 
    159168tests = [ 
    160          # Accuracy tests based on content in test/polyexclvol_default_igor.txt 
    161          [{'rg': 60, 'porod_exp': 3.0}, 0.001, 0.998801], 
    162          [{'rg': 60, 'porod_exp': 3.0}, 0.105363, 0.0162751], 
    163          [{'rg': 60, 'porod_exp': 3.0}, 0.665075, 6.56261e-05], 
     169    # Accuracy tests based on content in test/polyexclvol_default_igor.txt 
     170    [{'rg': 60, 'porod_exp': 3.0}, 0.001, 0.998801], 
     171    [{'rg': 60, 'porod_exp': 3.0}, 0.105363, 0.0162751], 
     172    [{'rg': 60, 'porod_exp': 3.0}, 0.665075, 6.56261e-05], 
    164173 
    165          # Additional tests with larger range of parameters 
    166          [{'rg': 10, 'porod_exp': 4.0}, 0.1, 0.723436675809], 
    167          [{'rg': 2.2, 'porod_exp': 22.0, 'background': 100.0}, 5.0, 100.0], 
    168          [{'rg': 1.1, 'porod_exp': 1, 'background': 10.0, 'scale': 1.25}, 
    169          20000., 10.0000712097] 
    170          ] 
     174    # Additional tests with larger range of parameters 
     175    [{'rg': 10, 'porod_exp': 4.0}, 0.1, 0.723436675809], 
     176    [{'rg': 2.2, 'porod_exp': 22.0, 'background': 100.0}, 5.0, 100.0], 
     177    [{'rg': 1.1, 'porod_exp': 1, 'background': 10.0, 'scale': 1.25}, 
     178     20000., 10.0000712097] 
     179    ] 
  • sasmodels/models/star_polymer.py

    r55b283e8 r168052c  
    5555        """ 
    5656category = "shape-independent" 
    57  
     57# pylint: disable=bad-whitespace, line-too-long 
    5858#             ["name", "units", default, [lower, upper], "type","description"], 
    5959parameters = [["radius2", "Ang", 100.0, [0.0, inf], "", "Ensemble radius of gyration squared of an arm"], 
    6060              ["arms",    "",      3,   [1.0, 6.0], "", "Number of arms in the model"], 
    61               ] 
    62  
     61             ] 
     62# pylint: enable=bad-whitespace, line-too-long 
    6363 
    6464source = ["star_polymer.c"] 
     
    7575tests = [[{'radius2': 2.0, 
    7676           'arms':    3.3, 
    77            }, 0.5, 0.850646091108], 
     77          }, 0.5, 0.850646091108], 
    7878 
    7979         [{'radius2':    1.0, 
    8080           'arms':       2.0, 
    8181           'background': 1.8, 
    82            }, 1.0, 2.53575888234], 
    83          ] 
     82          }, 1.0, 2.53575888234], 
     83        ] 
  • sasmodels/models/surface_fractal.py

    r07a6700 r168052c  
    8080category = "shape-independent" 
    8181 
     82# pylint: disable=bad-whitespace, line-too-long 
    8283#             ["name", "units", default, [lower, upper], "type","description"], 
    8384parameters = [["radius",        "Ang", 10.0, [0, inf],   "", 
     
    8788              ["cutoff_length", "Ang", 500., [0.0, inf], "", 
    8889               "Cut-off Length"], 
    89               ] 
    90  
     90             ] 
     91# pylint: enable=bad-whitespace, line-too-long 
    9192 
    9293source = ["lib/sph_j1c.c", "lib/lanczos_gamma.c", "surface_fractal.c"] 
     
    101102 
    102103tests = [ 
    103          # Accuracy tests based on content in test/utest_other_models.py 
    104          [{'radius': 10.0, 'surface_dim': 2.0, 'cutoff_length': 500.0, 
    105            }, 0.05, 301428.65916], 
     104    # Accuracy tests based on content in test/utest_other_models.py 
     105    [{'radius': 10.0, 
     106      'surface_dim': 2.0, 
     107      'cutoff_length': 500.0, 
     108     }, 0.05, 301428.65916], 
    106109 
    107          # Additional tests with larger range of parameters 
    108          [{'radius': 1.0, 'surface_dim': 1.0, 'cutoff_length': 10.0, 
    109            }, 0.332070182643, 1125.00321004], 
     110    # Additional tests with larger range of parameters 
     111    [{'radius': 1.0, 
     112      'surface_dim': 1.0, 
     113      'cutoff_length': 10.0, 
     114     }, 0.332070182643, 1125.00321004], 
    110115 
    111          [{'radius': 3.5, 'surface_dim': 0.1, 'cutoff_length': 30.0, 
    112            'background': 0.01, 
    113            }, 5.0, 0.00999998891322], 
     116    [{'radius': 3.5, 
     117      'surface_dim': 0.1, 
     118      'cutoff_length': 30.0, 
     119      'background': 0.01, 
     120     }, 5.0, 0.00999998891322], 
    114121 
    115          [{'radius': 3.0, 'surface_dim': 1.0, 'cutoff_length': 33.0, 
    116            'scale': 0.1, 
    117            }, 0.51, 2.50020147004], 
    118          ] 
     122    [{'radius': 3.0, 
     123      'surface_dim': 1.0, 
     124      'cutoff_length': 33.0, 
     125      'scale': 0.1, 
     126     }, 0.51, 2.50020147004], 
     127    ] 
  • sasmodels/models/two_lorentzian.py

    r07a6700 r168052c  
    5454category = "shape-independent" 
    5555 
     56# pylint: disable=bad-whitespace, line-too-long 
    5657#            ["name", "units", default, [lower, upper], "type", "description"], 
    57 parameters = [["lorentz_scale_1",  "",     10.0, [-inf, inf], "", 
    58                "First power law scale factor"], 
    59               ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", 
    60                "First Lorentzian screening length"], 
    61               ["lorentz_exp_1",    "",      3.0, [-inf, inf], "", 
    62                "First exponent of power law"], 
    63               ["lorentz_scale_2",  "",      1.0, [-inf, inf], "", 
    64                "Second scale factor for broad Lorentzian peak"], 
    65               ["lorentz_length_2", "Ang",  10.0, [-inf, inf], "", 
    66                "Second Lorentzian screening length"], 
    67               ["lorentz_exp_2",    "",      2.0, [-inf, inf], "", 
    68                "Second exponent of power law"], 
    69               ] 
     58parameters = [["lorentz_scale_1",  "",     10.0, [-inf, inf], "", "First power law scale factor"], 
     59              ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", "First Lorentzian screening length"], 
     60              ["lorentz_exp_1",    "",      3.0, [-inf, inf], "", "First exponent of power law"], 
     61              ["lorentz_scale_2",  "",      1.0, [-inf, inf], "", "Second scale factor for broad Lorentzian peak"], 
     62              ["lorentz_length_2", "Ang",  10.0, [-inf, inf], "", "Second Lorentzian screening length"], 
     63              ["lorentz_exp_2",    "",      2.0, [-inf, inf], "", "Second exponent of power law"], 
     64             ] 
     65# pylint: enable=bad-whitespace, line-too-long 
    7066 
    7167 
    7268def Iq(q, 
    73        lorentz_scale_1, 
    74        lorentz_length_1, 
    75        lorentz_exp_1, 
    76        lorentz_scale_2, 
    77        lorentz_length_2, 
    78        lorentz_exp_2): 
     69       lorentz_scale_1=10.0, 
     70       lorentz_length_1=100.0, 
     71       lorentz_exp_1=3.0, 
     72       lorentz_scale_2=1.0, 
     73       lorentz_length_2=10.0, 
     74       lorentz_exp_2=2.0): 
    7975 
    8076    """ 
     
    8884    :return:                    Calculated intensity 
    8985    """ 
    90  
     86# pylint: disable=bad-whitespace 
    9187    intensity  = lorentz_scale_1/(1.0 + 
    9288                                  power(q*lorentz_length_1, lorentz_exp_1)) 
    9389    intensity += lorentz_scale_2/(1.0 + 
    9490                                  power(q*lorentz_length_2, lorentz_exp_2)) 
     91# pylint: enable=bad-whitespace 
    9592 
    9693    return intensity 
     
    10097 
    10198def Iqxy(qx, qy, *args): 
    102         iq = Iq(sqrt(qx**2 + qy**2), *args) 
     99    """ 
     100    :param qx:   Input q_x-value 
     101    :param qy:   Input q_y-value 
     102    :param args: Remaining arguments 
     103    :return:     2D-Intensity 
     104    """ 
    103105 
    104         return iq 
     106    return Iq(sqrt(qx**2 + qy**2), *args) 
    105107 
    106108Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values 
     
    108110 
    109111demo = dict(scale=1, background=0.1, 
    110             lorentz_scale_1=10, lorentz_length_1=100.0, lorentz_exp_1=3.0, 
    111             lorentz_scale_2=1,  lorentz_length_2=10,    lorentz_exp_2=2.0) 
     112            lorentz_scale_1=10, 
     113            lorentz_length_1=100.0, 
     114            lorentz_exp_1=3.0, 
     115            lorentz_scale_2=1, 
     116            lorentz_length_2=10, 
     117            lorentz_exp_2=2.0) 
    112118 
    113119oldname = "TwoLorentzianModel" 
    114120oldpars = dict(background='background', 
    115                lorentz_scale_1='scale_1',   lorentz_scale_2='scale_2', 
    116                lorentz_length_1='length_1', lorentz_length_2='length_2', 
    117                lorentz_exp_1='exponent_1',  lorentz_exp_2='exponent_2') 
     121               lorentz_scale_1='scale_1', 
     122               lorentz_scale_2='scale_2', 
     123               lorentz_length_1='length_1', 
     124               lorentz_length_2='length_2', 
     125               lorentz_exp_1='exponent_1', 
     126               lorentz_exp_2='exponent_2') 
    118127 
    119128tests = [ 
    120          # Accuracy tests based on content in test/utest_extra_models.py 
    121          [{'lorentz_scale_1':   10.0, 
    122            'lorentz_length_1': 100.0, 
    123            'lorentz_exp_1':      3.0, 
    124            'lorentz_scale_2':    1.0, 
    125            'lorentz_length_2':  10.0, 
    126            'lorentz_exp_2':      2.0, 
    127            'background':         0.1, 
    128            }, 0.001, 11.08991], 
    129129 
    130          [{'lorentz_scale_1':   10.0, 
    131            'lorentz_length_1': 100.0, 
    132            'lorentz_exp_1':      3.0, 
    133            'lorentz_scale_2':    1.0, 
    134            'lorentz_length_2':  10.0, 
    135            'lorentz_exp_2':      2.0, 
    136            'background':         0.1, 
    137            }, 0.150141, 0.410245], 
     130    # Accuracy tests based on content in test/utest_extra_models.py 
     131    [{'lorentz_scale_1':   10.0, 
     132      'lorentz_length_1': 100.0, 
     133      'lorentz_exp_1':      3.0, 
     134      'lorentz_scale_2':    1.0, 
     135      'lorentz_length_2':  10.0, 
     136      'lorentz_exp_2':      2.0, 
     137      'background':         0.1, 
     138     }, 0.001, 11.08991], 
    138139 
    139          [{'lorentz_scale_1':   10.0, 
    140            'lorentz_length_1': 100.0, 
    141            'lorentz_exp_1':      3.0, 
    142            'lorentz_scale_2':    1.0, 
    143            'lorentz_length_2':  10.0, 
    144            'lorentz_exp_2':      2.0, 
    145            'background':         0.1, 
    146            }, 0.442528, 0.148699], 
     140    [{'lorentz_scale_1':   10.0, 
     141      'lorentz_length_1': 100.0, 
     142      'lorentz_exp_1':      3.0, 
     143      'lorentz_scale_2':    1.0, 
     144      'lorentz_length_2':  10.0, 
     145      'lorentz_exp_2':      2.0, 
     146      'background':         0.1, 
     147     }, 0.150141, 0.410245], 
    147148 
    148          # Additional tests with larger range of parameters 
    149          [{'lorentz_scale_1':   10.0, 
    150            'lorentz_length_1': 100.0, 
    151            'lorentz_exp_1':      3.0, 
    152            'lorentz_scale_2':    1.0, 
    153            'lorentz_length_2':  10.0, 
    154            'lorentz_exp_2':      2.0, 
    155            }, 0.000332070182643, 10.9996228107], 
     149    [{'lorentz_scale_1':   10.0, 
     150      'lorentz_length_1': 100.0, 
     151      'lorentz_exp_1':      3.0, 
     152      'lorentz_scale_2':    1.0, 
     153      'lorentz_length_2':  10.0, 
     154      'lorentz_exp_2':      2.0, 
     155      'background':         0.1, 
     156     }, 0.442528, 0.148699], 
    156157 
    157          [{'lorentz_scale_1':  0.0, 
    158            'lorentz_length_1': 0.0, 
    159            'lorentz_exp_1':    0.0, 
    160            'lorentz_scale_2':  0.0, 
    161            'lorentz_length_2': 0.0, 
    162            'lorentz_exp_2':    0.0, 
    163            'background':     100.0 
    164            }, 5.0, 100.0], 
     158    # Additional tests with larger range of parameters 
     159    [{'lorentz_scale_1':   10.0, 
     160      'lorentz_length_1': 100.0, 
     161      'lorentz_exp_1':      3.0, 
     162      'lorentz_scale_2':    1.0, 
     163      'lorentz_length_2':  10.0, 
     164      'lorentz_exp_2':      2.0, 
     165     }, 0.000332070182643, 10.9996228107], 
    165166 
    166          [{'lorentz_scale_1': 200.0, 
    167            'lorentz_length_1': 10.0, 
    168            'lorentz_exp_1':     0.1, 
    169            'lorentz_scale_2':   0.1, 
    170            'lorentz_length_2':  5.0, 
    171            'lorentz_exp_2':     2.0 
    172            }, 20000., 45.5659201896], 
    173          ] 
     167    [{'lorentz_scale_1':  0.0, 
     168      'lorentz_length_1': 0.0, 
     169      'lorentz_exp_1':    0.0, 
     170      'lorentz_scale_2':  0.0, 
     171      'lorentz_length_2': 0.0, 
     172      'lorentz_exp_2':    0.0, 
     173      'background':     100.0 
     174     }, 5.0, 100.0], 
     175 
     176    [{'lorentz_scale_1': 200.0, 
     177      'lorentz_length_1': 10.0, 
     178      'lorentz_exp_1':     0.1, 
     179      'lorentz_scale_2':   0.1, 
     180      'lorentz_length_2':  5.0, 
     181      'lorentz_exp_2':     2.0 
     182     }, 20000., 45.5659201896], 
     183    ] 
  • sasmodels/resolution.py

    rfdc538a r190fc2b  
    55""" 
    66from __future__ import division 
     7 
     8from scipy.special import erf 
     9from numpy import sqrt, log, log10 
     10import numpy as np 
    711 
    812__all__ = ["Resolution", "Perfect1D", "Pinhole1D", "Slit1D", 
     
    1115           "interpolate", "linear_extrapolation", "geometric_extrapolation", 
    1216           ] 
    13  
    14 from scipy.special import erf 
    15 from numpy import sqrt, log, log10 
    16 import numpy as np 
    1717 
    1818MINIMUM_RESOLUTION = 1e-8 
  • sasmodels/sesans.py

    r384d114 r190fc2b  
    4343    *I* [cm$^{-1}$] is the value of the SANS model at *q* 
    4444    """ 
    45     G = np.zeros(len(SElength), 'd') 
    46     for i in range(len(SElength)): 
    47         integr = besselj(0, q*SElength[i])*Iq*q 
    48         G[i] = np.sum(integr) 
     45    G = np.zeros_like(SElength, 'd') 
     46    for i, SElength_i in enumerate(SElength): 
     47        integral = besselj(0, q*SElength_i)*Iq*q 
     48        G[i] = np.sum(integral) 
    4949 
    5050    # [m^-1] step size in q, needed for integration 
    51     dq=(q[1]-q[0])*1e10 
     51    dq = (q[1]-q[0])*1e10 
    5252 
    5353    # integration step, convert q into [m**-1] and 2 pi circle integration 
  • sasmodels/data.py

    r69ec80f r299edd2  
    8787 
    8888class Data1D(object): 
     89    """ 
     90    1D data object. 
     91 
     92    Note that this definition matches the attributes from sasview, with 
     93    some generic 1D data vectors and some SAS specific definitions.  Some 
     94    refactoring to allow consistent naming conventions between 1D, 2D and 
     95    SESANS data would be helpful. 
     96 
     97    **Attributes** 
     98 
     99    *x*, *dx*: $q$ vector and gaussian resolution 
     100 
     101    *y*, *dy*: $I(q)$ vector and measurement uncertainty 
     102 
     103    *mask*: values to include in plotting/analysis 
     104 
     105    *dxl*: slit widths for slit smeared data, with *dx* ignored 
     106 
     107    *qmin*, *qmax*: range of $q$ values in *x* 
     108 
     109    *filename*: label for the data line 
     110 
     111    *_xaxis*, *_xunit*: label and units for the *x* axis 
     112 
     113    *_yaxis*, *_yunit*: label and units for the *y* axis 
     114    """ 
    89115    def __init__(self, x=None, y=None, dx=None, dy=None): 
    90116        self.x, self.y, self.dx, self.dy = x, y, dx, dy 
     
    93119        self.qmin = x.min() if x is not None else np.NaN 
    94120        self.qmax = x.max() if x is not None else np.NaN 
    95         self.mask = np.isnan(y) if y is not None else None 
     121        # TODO: why is 1D mask False and 2D mask True? 
     122        self.mask = (np.isnan(y) if y is not None 
     123                     else np.zeros_like(x,'b') if x is not None 
     124                     else None) 
    96125        self._xaxis, self._xunit = "x", "" 
    97126        self._yaxis, self._yunit = "y", "" 
     
    114143 
    115144class Data2D(object): 
     145    """ 
     146    2D data object. 
     147 
     148    Note that this definition matches the attributes from sasview. Some 
     149    refactoring to allow consistent naming conventions between 1D, 2D and 
     150    SESANS data would be helpful. 
     151 
     152    **Attributes** 
     153 
     154    *qx_data*, *dqx_data*: $q_x$ matrix and gaussian resolution 
     155 
     156    *qy_data*, *dqy_data*: $q_y$ matrix and gaussian resolution 
     157 
     158    *data*, *err_data*: $I(q)$ matrix and measurement uncertainty 
     159 
     160    *mask*: values to exclude from plotting/analysis 
     161 
     162    *qmin*, *qmax*: range of $q$ values in *x* 
     163 
     164    *filename*: label for the data line 
     165 
     166    *_xaxis*, *_xunit*: label and units for the *x* axis 
     167 
     168    *_yaxis*, *_yunit*: label and units for the *y* axis 
     169 
     170    *_zaxis*, *_zunit*: label and units for the *y* axis 
     171 
     172    *Q_unit*, *I_unit*: units for Q and intensity 
     173 
     174    *x_bins*, *y_bins*: grid steps in *x* and *y* directions 
     175    """ 
    116176    def __init__(self, x=None, y=None, z=None, dx=None, dy=None, dz=None): 
    117177        self.qx_data, self.dqx_data = x, dx 
    118178        self.qy_data, self.dqy_data = y, dy 
    119179        self.data, self.err_data = z, dz 
    120         self.mask = ~np.isnan(z) if z is not None else None 
     180        self.mask = (~np.isnan(z) if z is not None 
     181                     else np.ones_like(x) if x is not None 
     182                     else None) 
    121183        self.q_data = np.sqrt(x**2 + y**2) 
    122184        self.qmin = 1e-16 
     
    126188        self.Q_unit = "1/A" 
    127189        self.I_unit = "1/cm" 
    128         self.xaxis("Q_x", "A^{-1}") 
    129         self.yaxis("Q_y", "A^{-1}") 
    130         self.zaxis("Intensity", r"\text{cm}^{-1}") 
     190        self.xaxis("Q_x", "1/A") 
     191        self.yaxis("Q_y", "1/A") 
     192        self.zaxis("Intensity", "1/cm") 
    131193        self._xaxis, self._xunit = "x", "" 
    132194        self._yaxis, self._yunit = "y", "" 
     
    157219 
    158220class Vector(object): 
     221    """ 
     222    3-space vector of *x*, *y*, *z* 
     223    """ 
    159224    def __init__(self, x=None, y=None, z=None): 
    160225        self.x, self.y, self.z = x, y, z 
     
    235300    """ 
    236301    Plot data loaded by the sasview loader. 
     302 
     303    *data* is a sasview data object, either 1D, 2D or SESANS. 
     304 
     305    *view* is log or linear. 
     306 
     307    *limits* sets the intensity limits on the plot; if None then the limits 
     308    are inferred from the data. 
    237309    """ 
    238310    # Note: kind of weird using the plot result functions to plot just the 
     
    249321def plot_theory(data, theory, resid=None, view='log', 
    250322                use_data=True, limits=None): 
     323    """ 
     324    Plot theory calculation. 
     325 
     326    *data* is needed to define the graph properties such as labels and 
     327    units, and to define the data mask. 
     328 
     329    *theory* is a matrix of the same shape as the data. 
     330 
     331    *view* is log or linear 
     332 
     333    *use_data* is True if the data should be plotted as well as the theory. 
     334 
     335    *limits* sets the intensity limits on the plot; if None then the limits 
     336    are inferred from the data. 
     337    """ 
    251338    if hasattr(data, 'lam'): 
    252339        _plot_result_sesans(data, theory, resid, use_data=True, limits=limits) 
     
    258345 
    259346def protect(fn): 
     347    """ 
     348    Decorator to wrap calls in an exception trapper which prints the 
     349    exception and continues.  Keyboard interrupts are ignored. 
     350    """ 
    260351    def wrapper(*args, **kw): 
    261352        try: 
    262353            return fn(*args, **kw) 
     354        except KeyboardInterrupt: 
     355            raise 
    263356        except: 
    264357            traceback.print_exc() 
     
    332425@protect 
    333426def _plot_result_sesans(data, theory, resid, use_data, limits=None): 
     427    """ 
     428    Plot SESANS results. 
     429    """ 
    334430    import matplotlib.pyplot as plt 
    335431    use_data = use_data and data.y is not None 
     
    459555 
    460556def demo(): 
     557    """ 
     558    Load and plot a SAS dataset. 
     559    """ 
    461560    data = load_data('DEC07086.DAT') 
    462561    set_beam_stop(data, 0.004) 
Note: See TracChangeset for help on using the changeset viewer.