Changeset 9890053 in sasmodels for sasmodels/core.py


Ignore:
Timestamp:
Mar 3, 2015 2:31:38 PM (9 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:
59c4c4e
Parents:
49f92c1
Message:

add smoke tests for ER/VR; check that smoke test results are valid floats

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r84e01d2 r9890053  
    5353    return v,w/np.sum(w) 
    5454 
     55def dispersion_mesh(pars): 
     56    """ 
     57    Create a mesh grid of dispersion parameters and weights. 
     58 
     59    Returns [p1,p2,...],w where pj is a vector of values for parameter j 
     60    and w is a vector containing the products for weights for each 
     61    parameter set in the vector. 
     62    """ 
     63    values, weights = zip(*pars) 
     64    if len(values) > 1: 
     65        values = [v.flatten() for v in np.meshgrid(*values)] 
     66        weights = np.vstack([v.flatten() for v in np.meshgrid(*weights)]) 
     67        weights = np.prod(weights, axis=0) 
     68    return values, weights 
     69 
    5570def call_kernel(kernel, pars, cutoff=1e-5): 
    5671    fixed_pars = [pars.get(name, kernel.info['defaults'][name]) 
     
    5974    return kernel(fixed_pars, pd_pars, cutoff=cutoff) 
    6075 
     76def call_ER(kernel, pars): 
     77    ER = kernel.info.get('ER', None) 
     78    if ER is None: 
     79        return 1.0 
     80    else: 
     81        vol_pars = [get_weights(kernel, pars, name) 
     82                    for name in kernel.info['partype']['volume']] 
     83        values, weights = dispersion_mesh(vol_pars) 
     84        fv = ER(*values) 
     85        #print values[0].shape, weights.shape, fv.shape 
     86        return np.sum(weights*fv) / np.sum(weights) 
     87 
     88def call_VR(kernel, pars): 
     89    VR = kernel.info.get('VR', None) 
     90    if VR is None: 
     91        return 1.0 
     92    else: 
     93        vol_pars = [get_weights(kernel, pars, name) 
     94                    for name in kernel.info['partype']['volume']] 
     95        values, weights = dispersion_mesh(vol_pars) 
     96        whole,part = VR(*values) 
     97        return np.sum(weights*part)/np.sum(weights*whole) 
     98 
Note: See TracChangeset for help on using the changeset viewer.