Changeset 513efc5 in sasmodels for sasmodels/models/two_lorentzian.py


Ignore:
Timestamp:
Jan 20, 2016 2:50:50 AM (8 years ago)
Author:
piotr
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:
7ed702f
Parents:
30b4ddf
Message:

Code review issues from PK addressed.

Added Taylor expansion utility function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/two_lorentzian.py

    r421e55c r513efc5  
    11r""" 
    2 This model calculates an empirical functional form for SAS data characterized by two Lorentzian-type functions. 
     2This model calculates an empirical functional form for SAS data characterized 
     3by two Lorentzian-type functions. 
    34 
    45Definition 
     
    1213 
    1314where $A$ = Lorentzian scale factor #1, $C$ = Lorentzian scale #2, 
    14 $\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and $m$ are the respective 
    15 power law exponents (set $n = m = 2$ for Ornstein-Zernicke behaviour). 
     15$\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and 
     16$m$ are the respective power law exponents (set $n = m = 2$ for 
     17Ornstein-Zernicke behaviour). 
    1618 
    1719For 2D data the scattering intensity is calculated in the same way as 1D, 
     
    5254category = "shape-independent" 
    5355 
    54 #             ["name", "units", default, [lower, upper], "type", "description"], 
    55 parameters = [["lorentz_scale_1",  "",     10.0, [-inf, inf], "", "First power law scale factor"], 
    56               ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", "First Lorentzian screening length"], 
    57               ["lorentz_exp_1",    "",      3.0, [-inf, inf], "", "First exponent of power law"], 
    58               ["lorentz_scale_2",  "",      1.0, [-inf, inf], "", "Second scale factor for broad Lorentzian peak"], 
    59               ["lorentz_length_2", "Ang",  10.0, [-inf, inf], "", "Second Lorentzian screening length"], 
    60               ["lorentz_exp_2",    "",      2.0, [-inf, inf], "", "Second exponent of power law"], 
     56#            ["name", "units", default, [lower, upper], "type", "description"], 
     57parameters = [["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"], 
    6169              ] 
    6270 
    6371 
    64 def Iq(q, lorentz_scale_1, lorentz_length_1, lorentz_exp_1, lorentz_scale_2, lorentz_length_2, lorentz_exp_2): 
     72def 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): 
    6579 
    6680    """ 
     
    7589    """ 
    7690 
    77     intensity  = lorentz_scale_1/(1.0 + power(q*lorentz_length_1, lorentz_exp_1)) 
    78     intensity += lorentz_scale_2/(1.0 + power(q*lorentz_length_2, lorentz_exp_2)) 
     91    intensity  = lorentz_scale_1/(1.0 + 
     92                                  power(q*lorentz_length_1, lorentz_exp_1)) 
     93    intensity += lorentz_scale_2/(1.0 + 
     94                                  power(q*lorentz_length_2, lorentz_exp_2)) 
    7995 
    8096    return intensity 
     
    101117               lorentz_exp_1='exponent_1',  lorentz_exp_2='exponent_2') 
    102118 
    103 tests = [[{'lorentz_scale_1': 10, 'lorentz_length_1': 100.0, 'lorentz_exp_1' : 3.0, 
    104           'lorentz_scale_2': 1, 'lorentz_length_2': 10.0, 'lorentz_exp_2' : 2.0, 
     119tests = [[{'lorentz_scale_1':   10.0, 
     120           'lorentz_length_1': 100.0, 
     121           'lorentz_exp_1':      3.0, 
     122           'lorentz_scale_2':    1.0, 
     123           'lorentz_length_2':  10.0, 
     124           'lorentz_exp_2':      2.0, 
    105125           }, 0.000332070182643, 10.9996228107], 
    106126 
    107          [{'lorentz_scale_1': 0, 'lorentz_length_1': 0.0, 'lorentz_exp_1' : 0.0, 
    108           'lorentz_scale_2': 0, 'lorentz_length_2': 0.0, 'lorentz_exp_2' : 0.0, 
    109            'background':100. 
     127         [{'lorentz_scale_1':  0.0, 
     128           'lorentz_length_1': 0.0, 
     129           'lorentz_exp_1':    0.0, 
     130           'lorentz_scale_2':  0.0, 
     131           'lorentz_length_2': 0.0, 
     132           'lorentz_exp_2':    0.0, 
     133           'background':     100.0 
    110134           }, 5.0, 100.0], 
    111135 
    112          [{'lorentz_scale_1': 200, 'lorentz_length_1': 10.0, 'lorentz_exp_1' : 0.1, 
    113           'lorentz_scale_2': 0.1, 'lorentz_length_2': 5.0, 'lorentz_exp_2' : 2.0 
     136         [{'lorentz_scale_1': 200.0, 
     137           'lorentz_length_1': 10.0, 
     138           'lorentz_exp_1':     0.1, 
     139           'lorentz_scale_2':   0.1, 
     140           'lorentz_length_2':  5.0, 
     141           'lorentz_exp_2':     2.0 
    114142           }, 20000., 45.5659201896], 
    115143         ] 
Note: See TracChangeset for help on using the changeset viewer.