Changeset 9e771a3 in sasmodels for sasmodels/details.py


Ignore:
Timestamp:
Oct 18, 2017 8:51:08 PM (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:
94f4543
Parents:
9b7b23f
Message:

sort out weights (seems to be correct this time)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/details.py

    r3c24ccd r9e771a3  
    234234    # skipping scale and background when building values and weights 
    235235    values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ()) 
    236     weights = correct_theta_weights(kernel.info.parameters, values, weights) 
     236    weights = correct_theta_weights(kernel.info.parameters, dispersity, weights) 
    237237    length = np.array([len(w) for w in weights]) 
    238238    offset = np.cumsum(np.hstack((0, length))) 
     
    247247    return call_details, data, is_magnetic 
    248248 
    249 def correct_theta_weights(parameters, values, weights): 
     249def correct_theta_weights(parameters, dispersity, weights): 
    250250    # type: (ParameterTable, Sequence[np.ndarray], Sequence[np.ndarray]) -> Sequence[np.ndarray] 
    251251    """ 
    252252    If there is a theta parameter, update the weights of that parameter so that 
    253     the cosine weighting required for polar integration is preserved.  Avoid 
    254     evaluation strictly at the pole, which would otherwise send the weight to 
    255     zero. 
    256  
    257     Note: values and weights do not include scale and background 
    258     """ 
    259     # TODO: document code, explaining why scale and background are skipped 
    260     # given that we don't have scale and background in the list, we 
    261     # should be calling the variables something other than values and weights 
     253    the cosine weighting required for polar integration is preserved. 
     254 
     255    Avoid evaluation strictly at the pole, which would otherwise send the 
     256    weight to zero.  This is probably not a problem in practice (if dispersity 
     257    is +/- 90, then you probably should be using a 1-D model of the circular 
     258    average). 
     259 
     260    Note: scale and background parameters are not include in the tuples for 
     261    dispersity and weights, so index is parameters.theta_offset, not 
     262    parameters.theta_offset+2 
     263 
     264    Returns updated weights vectors 
     265    """ 
     266    # TODO: explain in a comment why scale and background are missing 
    262267    # Apparently the parameters.theta_offset similarly skips scale and 
    263     # and background, so the indexing works out. 
     268    # and background, so the indexing works out, but they are still shipped 
     269    # to the kernel, so we need to add two there. 
    264270    if parameters.theta_offset >= 0: 
    265271        index = parameters.theta_offset 
    266         theta = values[index] 
    267         theta_weight = np.minimum(abs(cos(radians(theta))), 1e-6) 
    268         # copy the weights list so we can update it 
    269         weights = list(weights) 
    270         weights[index] = theta_weight*np.asarray(weights[index]) 
    271         weights = tuple(weights) 
     272        theta = dispersity[index] 
     273        # TODO: modify the dispersity vector to avoid the theta=-90,90,270,... 
     274        theta_weight = abs(cos(radians(theta))) 
     275        weights = tuple(theta_weight*v if k == index else v 
     276                        for k, v in enumerate(weights)) 
    272277    return weights 
    273278 
Note: See TracChangeset for help on using the changeset viewer.