Changeset 3c24ccd in sasmodels for sasmodels/direct_model.py


Ignore:
Timestamp:
Oct 18, 2017 10:03:43 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
ef8e68c
Parents:
fbb9397
Message:

add -weights option to sascomp to show dispersity distribution

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/direct_model.py

    r32f87a5 r3c24ccd  
    5555    *mono* is True if polydispersity should be set to none on all parameters. 
    5656    """ 
    57     parameters = calculator.info.parameters 
    58     if mono: 
    59         active = lambda name: False 
    60     elif calculator.dim == '1d': 
    61         active = lambda name: name in parameters.pd_1d 
    62     elif calculator.dim == '2d': 
    63         active = lambda name: name in parameters.pd_2d 
    64     else: 
    65         active = lambda name: True 
    66  
    67     #print("pars",[p.id for p in parameters.call_parameters]) 
    68     mesh = [get_weights(p, pars, active(p.name)) 
    69             for p in parameters.call_parameters] 
    70  
     57    mesh = get_mesh(calculator.info, pars, dim=calculator.dim, mono=mono) 
    7158    call_details, values, is_magnetic = make_kernel_args(calculator, mesh) 
    7259    #print("values:", values) 
    7360    return calculator(call_details, values, cutoff, is_magnetic) 
    74  
    7561 
    7662def call_ER(model_info, pars): 
     
    128114    return x, y, model_info.profile_axes 
    129115 
    130  
    131 def get_weights(parameter, values, active=True): 
    132     # type: (Parameter, Dict[str, float]) -> Tuple[np.ndarray, np.ndarray] 
     116def get_mesh(model_info, values, dim='1d', mono=False): 
     117    # type: (ModelInfo, Dict[str, float], str, bool) -> List[Tuple[float, np.ndarray, np.ndarry]] 
     118    """ 
     119    Retrieve the dispersity mesh described by the parameter set. 
     120 
     121    Returns a list of *(value, dispersity, weights)* with one tuple for each 
     122    parameter in the model call parameters.  Inactive parameters return the 
     123    default value with a weight of 1.0. 
     124    """ 
     125    parameters = model_info.parameters 
     126    if mono: 
     127        active = lambda name: False 
     128    elif dim == '1d': 
     129        active = lambda name: name in parameters.pd_1d 
     130    elif dim == '2d': 
     131        active = lambda name: name in parameters.pd_2d 
     132    else: 
     133        active = lambda name: True 
     134 
     135    #print("pars",[p.id for p in parameters.call_parameters]) 
     136    mesh = [_get_par_weights(p, values, active(p.name)) 
     137            for p in parameters.call_parameters] 
     138    return mesh 
     139 
     140 
     141def _get_par_weights(parameter, values, active=True): 
     142    # type: (Parameter, Dict[str, float]) -> Tuple[float, np.ndarray, np.ndarray] 
    133143    """ 
    134144    Generate the distribution for parameter *name* given the parameter values 
Note: See TracChangeset for help on using the changeset viewer.