Changeset 2c74c11 in sasmodels for sasmodels/models/guinier_porod.py


Ignore:
Timestamp:
Jul 24, 2016 10:56:45 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:
a4280bd
Parents:
f1765a2
Message:

implicit Iqxy; fix divide by 0 for q=0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/guinier_porod.py

    rec45c4f r2c74c11  
    6363""" 
    6464 
    65 from numpy import inf, sqrt, power, exp 
     65from numpy import inf, sqrt, exp, errstate 
    6666 
    6767name = "guinier_porod" 
     
    9393    """ 
    9494    n = 3.0 - s 
     95    ms = 0.5*(m-s) # =(n-3+m)/2 
     96 
     97    # preallocate return value 
     98    iq = 0.0*q 
    9599 
    96100    # Take care of the singular points 
    97     if rg <= 0.0: 
    98         return 0.0 
    99     if (n-3.0+m) <= 0.0: 
    100         return 0.0 
     101    if rg <= 0.0 or ms <= 0.0: 
     102        return iq 
    101103 
    102104    # Do the calculation and return the function value 
    103     q1 = sqrt((n-3.0+m)*n/2.0)/rg 
    104     if q < q1: 
    105         iq = (1.0/power(q, (3.0-n)))*exp((-q*q*rg*rg)/n) 
    106     else: 
    107         iq = (1.0/power(q, m))*exp(-(n-3.0+m)/2.0)*power(((n-3.0+m)*n/2.0), 
    108                                                          ((n-3.0+m)/2.0))/power(rg, (n-3.0+m)) 
     105    idx = q < sqrt(n*ms)/rg 
     106    with errstate(divide='ignore'): 
     107        iq[idx] = q[idx]**-s * exp(-(q[idx]*rg)**2/n) 
     108        iq[~idx] = q[~idx]**-m * (exp(-ms) * (n*ms/rg**2)**ms) 
    109109    return iq 
    110110 
    111 Iq.vectorized = False  # Iq accepts an array of q values 
    112  
    113 def Iqxy(qx, qy, *args): 
    114     """ 
    115     @param qx:   Input q_x-value 
    116     @param qy:   Input q_y-value 
    117     @param args: Remaining arguments 
    118     """ 
    119     return Iq(sqrt(qx ** 2 + qy ** 2), *args) 
    120  
    121 Iqxy.vectorized = False # Iqxy accepts an array of qx, qy values 
     111Iq.vectorized = True # Iq accepts an array of q values 
    122112 
    123113demo = dict(scale=1.5, background=0.5, rg=60, s=1.0, m=3.0) 
Note: See TracChangeset for help on using the changeset viewer.