Changeset 6edb74a in sasmodels


Ignore:
Timestamp:
Feb 19, 2015 3:59:14 PM (10 years ago)
Author:
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:
3a45c2c, fd1c792
Parents:
16bc3fc
Message:

support for pure python models without polydispersity

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernelpy.py

    rf786ff3 r6edb74a  
    8787        self.pd_pars = pd_pars 
    8888 
    89     def __call__(self, fixed, pd, cutoff): 
     89    def __call__(self, fixed, pd, cutoff=1e-5): 
    9090        #print "fixed",fixed 
    9191        #print "pd", pd 
     
    144144    ########################################################## 
    145145 
    146     # weight vector, to be populated by polydispersity loops 
    147146    weight = np.empty(len(pd), 'd') 
    148  
    149     # identify which pd parameters are volume parameters 
    150     vol_weight_index = np.array([(index in vol_index) for index in pd_index]) 
    151  
    152     # Sort parameters in decreasing order of pd length 
    153     Npd = np.array([len(pdi[0]) for pdi in pd], 'i') 
    154     order = np.argsort(Npd)[::-1] 
    155     stride = np.cumprod(Npd[order]) 
    156     pd = [pd[index] for index in order] 
    157     pd_index = pd_index[order] 
    158     vol_weight_index = vol_weight_index[order] 
    159  
    160     fast_value = pd[0][0] 
    161     fast_weight = pd[0][1] 
     147    if weight.size > 0: 
     148        # weight vector, to be populated by polydispersity loops 
     149 
     150        # identify which pd parameters are volume parameters 
     151        vol_weight_index = np.array([(index in vol_index) for index in pd_index]) 
     152 
     153        # Sort parameters in decreasing order of pd length 
     154        Npd = np.array([len(pdi[0]) for pdi in pd], 'i') 
     155        order = np.argsort(Npd)[::-1] 
     156        stride = np.cumprod(Npd[order]) 
     157        pd = [pd[index] for index in order] 
     158        pd_index = pd_index[order] 
     159        vol_weight_index = vol_weight_index[order] 
     160 
     161        fast_value = pd[0][0] 
     162        fast_weight = pd[0][1] 
     163    else: 
     164        stride = np.array([1]) 
     165        vol_weight_index = slice(None, None) 
    162166 
    163167    ret = np.zeros_like(args[0]) 
     
    169173        fast_index = k%stride[0] 
    170174        if fast_index == 0:  # bottom loop complete ... check all other loops 
    171             for i,index, in enumerate(k%stride): 
    172                 args[pd_index[i]] = pd[i][0][index] 
    173                 weight[i] = pd[i][1][index] 
     175            if weight.size > 0: 
     176                for i,index, in enumerate(k%stride): 
     177                    args[pd_index[i]] = pd[i][0][index] 
     178                    weight[i] = pd[i][1][index] 
    174179        else: 
    175180            args[pd_index[0]] = fast_value[fast_index] 
  • sasmodels/models/broad_peak.py

    r636adb6 r6edb74a  
    5151 
    5252import numpy as np 
    53 from numpy import pi, inf, sin, cos, sqrt, exp, log 
     53from numpy import pi, inf, sin, cos, sqrt, exp, log, fabs 
    5454 
    5555name = "broad_peak" 
     
    9292def Iq(q, porod_scale, porod_exp, lorentz_scale, lorentz_length, peak_pos, lorentz_exp): 
    9393    inten = porod_scale/pow(q,porod_exp) + lorentz_scale/(1.0 \ 
    94         + pow((math.fabs(q-peak_pos)*lorentz_length),lorentz_exp)) 
     94        + pow((fabs(q-peak_pos)*lorentz_length),lorentz_exp)) 
    9595    return inten   
    9696 
Note: See TracChangeset for help on using the changeset viewer.