Changeset d0876c9d in sasmodels


Ignore:
Timestamp:
Mar 30, 2016 2:34:39 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:
aaf75b6
Parents:
d1c4760 (diff), fb5914f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'polydisp' of github.com:sasview/sasmodels into polydisp

Location:
sasmodels
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    rd19962c rfb5914f  
    241241                 else ([pars.get(p.name, p.default)], [])) 
    242242                for p in parameters.call_parameters] 
    243     values, weights = zip(*vw_pairs) 
    244  
     243 
     244    details, weights, values = build_details(kernel, vw_pairs) 
     245    return kernel(details, weights, values, cutoff) 
     246 
     247def build_details(kernel, pairs): 
     248    values, weights = zip(*pairs) 
    245249    if max([len(w) for w in weights]) > 1: 
    246250        details = generate.poly_details(kernel.info, weights) 
    247251    else: 
    248252        details = kernel.info['mono_details'] 
    249  
    250253    weights, values = [np.hstack(v) for v in (weights, values)] 
    251  
    252254    weights = weights.astype(dtype=kernel.dtype) 
    253255    values = values.astype(dtype=kernel.dtype) 
    254     return kernel(details, weights, values, cutoff) 
     256    return details, weights, values 
     257 
    255258 
    256259def call_ER_VR(model_info, vol_pars): 
  • sasmodels/modelinfo.py

    rce896fd rfb5914f  
    432432                         if p.polydisperse and p.type != 'magnetic') 
    433433 
    434     def user_parameters(self, pars, is2d): 
     434    def user_parameters(self, pars={}, is2d=True): 
    435435        """ 
    436436        Return the list of parameters for the given data type. 
     
    493493                if table: 
    494494                    # look up length from incoming parameters 
    495                     table_length = int(pars[p.length_control]) 
     495                    table_length = int(pars.get(p.length_control, p.length)) 
    496496                    del dependent[p.length_control] # first entry seen 
    497497                    for k in range(1, table_length+1): 
  • sasmodels/sasview_model.py

    rce896fd rfb5914f  
    2121 
    2222from . import core 
    23 from . import generate 
     23from . import weights 
    2424 
    2525def standard_models(): 
     
    5252    """ 
    5353    def __init__(self): 
    54         self._kernel = None 
     54        self._model = None 
    5555        model_info = self._model_info 
    5656        parameters = model_info['parameters'] 
     
    7575        self.params = collections.OrderedDict() 
    7676        self.dispersion = dict() 
    77         partype = model_info['partype'] 
    78  
    79         for p in model_info['parameters']: 
     77 
     78        self.orientation_params = [] 
     79        self.magnetic_params = [] 
     80        self.fixed = [] 
     81        for p in parameters.user_parameters(): 
    8082            self.params[p.name] = p.default 
    8183            self.details[p.name] = [p.units] + p.limits 
    82  
    83         for name in partype['pd-2d']: 
    84             self.dispersion[name] = { 
    85                 'width': 0, 
    86                 'npts': 35, 
    87                 'nsigmas': 3, 
    88                 'type': 'gaussian', 
    89             } 
    90  
    91         self.orientation_params = ( 
    92             partype['orientation'] 
    93             + [n + '.width' for n in partype['orientation']] 
    94             + partype['magnetic']) 
    95         self.magnetic_params = partype['magnetic'] 
    96         self.fixed = [n + '.width' for n in partype['pd-2d']] 
     84            if p.polydisperse: 
     85                self.dispersion[p.name] = { 
     86                    'width': 0, 
     87                    'npts': 35, 
     88                    'nsigmas': 3, 
     89                    'type': 'gaussian', 
     90                } 
     91            if p.type == 'orientation': 
     92                self.orientation_params.append(p.name) 
     93                self.orientation_params.append(p.name+".width") 
     94                self.fixed.append(p.name+".width") 
     95            if p.type == 'magnetic': 
     96                self.orientation_params.append(p.name) 
     97                self.magnetic_params.append(p.name) 
     98                self.fixed.append(p.name+".width") 
     99 
    97100        self.non_fittable = [] 
    98101 
     
    113116    def __get_state__(self): 
    114117        state = self.__dict__.copy() 
    115         model_id = self._model_info['id'] 
    116118        state.pop('_kernel') 
    117119        # May need to reload model info on set state since it has pointers 
     
    122124    def __set_state__(self, state): 
    123125        self.__dict__ = state 
    124         self._kernel = None 
     126        self._model = None 
    125127 
    126128    def __str__(self): 
     
    211213    def getDispParamList(self): 
    212214        """ 
    213         Return a list of all available parameters for the model 
     215        Return a list of polydispersity parameters for the model 
    214216        """ 
    215217        # TODO: fix test so that parameter order doesn't matter 
    216         ret = ['%s.%s' % (d.lower(), p) 
    217                for d in self._model_info['partype']['pd-2d'] 
    218                for p in ('npts', 'nsigmas', 'width')] 
     218        ret = ['%s.%s' % (p.name.lower(), ext) 
     219               for p in self._model_info['parameters'].user_parameters() 
     220               for ext in ('npts', 'nsigmas', 'width') 
     221               if p.polydisperse] 
    219222        #print(ret) 
    220223        return ret 
     
    289292            # Check whether we have a list of ndarrays [qx,qy] 
    290293            qx, qy = qdist 
    291             partype = self._model_info['partype'] 
    292             if not partype['orientation'] and not partype['magnetic']: 
     294            if not self._model_info['parameters'].has_2d: 
    293295                return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) 
    294296            else: 
     
    312314        to the card for each evaluation. 
    313315        """ 
    314         if self._kernel is None: 
    315             self._kernel = core.build_model(self._model_info) 
     316        if self._model is None: 
     317            self._model = core.build_model(self._model_info, platform='dll') 
    316318        q_vectors = [np.asarray(q) for q in args] 
    317         fn = self._kernel(q_vectors) 
    318         pars = [self.params[v] for v in fn.fixed_pars] 
    319         pd_pars = [self._get_weights(p) for p in fn.pd_pars] 
    320         result = fn(pars, pd_pars, self.cutoff) 
    321         fn.q_input.release() 
    322         fn.release() 
     319        kernel = self._model.make_kernel(q_vectors) 
     320        pairs = [self._get_weights(p) 
     321                 for p in self._model_info['parameters'].call_parameters] 
     322        details, weights, values = core.build_details(kernel, pairs) 
     323        return kernel(details, weights, values, cutoff=self.cutoff) 
     324        kernel.q_input.release() 
     325        kernel.release() 
    323326        return result 
    324327 
     
    393396    def _get_weights(self, par): 
    394397        """ 
    395             Return dispersion weights 
    396             :param par parameter name 
    397         """ 
    398         from . import weights 
    399  
    400         relative = self._model_info['partype']['pd-rel'] 
    401         limits = self._model_info['limits'] 
    402         dis = self.dispersion[par] 
    403         value, weight = weights.get_weights( 
    404             dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 
    405             self.params[par], limits[par], par in relative) 
    406         return value, weight / np.sum(weight) 
    407  
     398        Return dispersion weights for parameter 
     399        """ 
     400        if par.polydisperse: 
     401            dis = self.dispersion[par.name] 
     402            value, weight = weights.get_weights( 
     403                dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 
     404                self.params[par.name], par.limits, par.relative_pd) 
     405            return value, weight / np.sum(weight) 
     406        else: 
     407            return [self.params[par.name]], [] 
     408 
     409def test_model(): 
     410    Cylinder = make_class('cylinder') 
     411    cylinder = Cylinder() 
     412    return cylinder.evalDistribution([0.1,0.1]) 
     413 
     414if __name__ == "__main__": 
     415    print("cylinder(0.1,0.1)=%g"%test_model()) 
  • sasmodels/compare.py

    rd19962c rd1c4760  
    784784    n1 = int(args[1]) if len(args) > 1 else 1 
    785785    n2 = int(args[2]) if len(args) > 2 else 1 
     786    use_sasview = any(engine=='sasview' and count>0 
     787                      for engine, count in zip(engines, [n1, n2])) 
    786788 
    787789    # Get demo parameters from model definition, or use default parameters 
     
    811813    #import pprint; pprint.pprint(model_info) 
    812814    constrain_pars(model_info, pars) 
    813     constrain_new_to_old(model_info, pars) 
     815    if use_sasview: 
     816        constrain_new_to_old(model_info, pars) 
    814817    if opts['show_pars']: 
    815818        print(str(parlist(model_info, pars, opts['is2d']))) 
  • sasmodels/convert.py

    rce896fd rd1c4760  
    138138    namelist = name.split('*') if '*' in name else [name] 
    139139    for name in namelist: 
    140         if name == 'pearl_necklace': 
     140        if name == 'stacked_disks': 
     141            _remove_pd(oldpars, 'n_stacking', name) 
     142        elif name == 'pearl_necklace': 
    141143            _remove_pd(oldpars, 'num_pearls', name) 
    142144            _remove_pd(oldpars, 'thick_string', name) 
  • sasmodels/models/_spherepy.py

    r49da079 rd7028dc  
    11r""" 
    2 For information about polarised and magnetic scattering, click here_. 
    3  
    4 .. _here: polar_mag_help.html 
     2For information about polarised and magnetic scattering, see  
     3the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
    54 
    65Definition 
  • sasmodels/models/fuzzy_sphere.py

    r0cc31e1 rd7028dc  
    11r""" 
    2 For information about polarised and magnetic scattering, click here_. 
    3  
    4 .. _here: polar_mag_help.html 
     2For information about polarised and magnetic scattering, see  
     3the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
    54 
    65Definition 
  • sasmodels/models/multilayer_vesicle.py

    rc6ca41e rd7028dc  
    2929    is used as the effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 
    3030 
    31  
    32  
    33 For information about polarised and magnetic scattering, click here_. 
    34  
    35 .. _here: polar_mag_help.html 
     31For information about polarised and magnetic scattering, see  
     32the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
    3633 
    3734This code is based on the form factor calculations implemented in the NIST 
  • sasmodels/models/sphere.py

    r49da079 rd7028dc  
    11r""" 
    2 For information about polarised and magnetic scattering, click here_. 
    3  
    4 .. _here: polar_mag_help.html 
     2For information about polarised and magnetic scattering, see  
     3the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
    54 
    65Definition 
  • sasmodels/models/stacked_disks.py

    re664a11 r53215cf  
    100100J S Higgins and H C Benoit, *Polymers and Neutron Scattering*, Clarendon, Oxford, 1994 
    101101 
     102**Author:** NIST IGOR/DANSE **on:** pre 2010 
     103 
     104**Last Modified by:** Piotr Rozyczko **on:** February 18, 2016 
     105 
     106**Last Reviewed by:** Richard Heenan **on:** March 22, 2016 
    102107""" 
    103108 
     
    157162 
    158163tests = [ 
    159     # Accuracy tests based on content in test/utest_extra_models.py 
     164    # Accuracy tests based on content in test/utest_extra_models.py. 
     165    # Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB 
    160166    [{'core_thick': 10.0, 
    161167      'layer_thick': 15.0, 
     
    171177      'background': 0.001, 
    172178     }, 0.001, 5075.12], 
     179 
     180    [{'core_thick': 10.0, 
     181      'layer_thick': 15.0, 
     182      'radius': 3000.0, 
     183      'n_stacking': 5.0, 
     184      'sigma_d': 0.0, 
     185      'sld_core': 4.0, 
     186      'sld_layer': -0.4, 
     187      'solvent_sd': 5.0, 
     188      'theta': 0.0, 
     189      'phi': 0.0, 
     190      'scale': 0.01, 
     191      'background': 0.001, 
     192     }, 0.001, 5065.12793824], 
     193 
     194    [{'core_thick': 10.0, 
     195      'layer_thick': 15.0, 
     196      'radius': 3000.0, 
     197      'n_stacking': 5.0, 
     198      'sigma_d': 0.0, 
     199      'sld_core': 4.0, 
     200      'sld_layer': -0.4, 
     201      'solvent_sd': 5.0, 
     202      'theta': 0.0, 
     203      'phi': 0.0, 
     204      'scale': 0.01, 
     205      'background': 0.001, 
     206     }, 0.164, 0.0127673597265], 
    173207 
    174208    [{'core_thick': 10.0, 
Note: See TracChangeset for help on using the changeset viewer.