Changeset 0ff62d4 in sasmodels for sasmodels/details.py


Ignore:
Timestamp:
Apr 15, 2016 12:31:35 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:
f2f67a6
Parents:
8f6817d
Message:

refactor: move dispersion_mesh alongside build_details in kernel.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/details.py

    r8d62008 r0ff62d4  
    8383        print("theta par", self.buffer[-1]) 
    8484 
    85 def build_details(kernel, pairs): 
    86     values, weights = zip(*pairs) 
    87     if max([len(w) for w in weights]) > 1: 
    88         call_details = poly_details(kernel.info, weights) 
    89     else: 
    90         call_details = mono_details(kernel.info) 
    91     weights, values = [np.hstack(v) for v in (weights, values)] 
    92     weights = weights.astype(dtype=kernel.dtype) 
    93     values = values.astype(dtype=kernel.dtype) 
    94     return call_details, weights, values 
    95  
    9685def mono_details(model_info): 
    9786    call_details = CallDetails(model_info) 
     
    139128    raise NotImplementedError("Can't handle constraints yet") 
    140129 
    141  
    142 try: 
    143     np.meshgrid([]) 
    144     meshgrid = np.meshgrid 
    145 except ValueError: 
    146     # CRUFT: np.meshgrid requires multiple vectors 
    147     def meshgrid(*args): 
    148         if len(args) > 1: 
    149             return np.meshgrid(*args) 
    150         else: 
    151             return [np.asarray(v) for v in args] 
    152  
    153 def dispersion_mesh(model_info, pars): 
    154     """ 
    155     Create a mesh grid of dispersion parameters and weights. 
    156  
    157     Returns [p1,p2,...],w where pj is a vector of values for parameter j 
    158     and w is a vector containing the products for weights for each 
    159     parameter set in the vector. 
    160     """ 
    161     value, weight = zip(*pars) 
    162     weight = [w if w else [1.] for w in weight] 
    163     weight = np.vstack([v.flatten() for v in meshgrid(*weight)]) 
    164     weight = np.prod(weight, axis=0) 
    165     value = [v.flatten() for v in meshgrid(*value)] 
    166     lengths = [par.length for par in model_info.parameters.kernel_parameters 
    167                if par.type == 'volume'] 
    168     if any(n > 1 for n in lengths): 
    169         pars = [] 
    170         offset = 0 
    171         for n in lengths: 
    172             pars.append(np.vstack(value[offset:offset+n]) if n > 1 else value[offset]) 
    173             offset += n 
    174         value = pars 
    175     return value, weight 
    176  
    177  
Note: See TracChangeset for help on using the changeset viewer.