Changeset 1780d59 in sasmodels


Ignore:
Timestamp:
Aug 24, 2014 10:27:38 PM (10 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:
1f21edf
Parents:
ce27e21
Message:

hack sasview model polydispersity

Location:
sasmodels
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/gpu.py

    rce27e21 r1780d59  
    270270        loops_N = [np.uint32(len(p[0])) for p in pd_pars] 
    271271 
     272        #import sys; print >>sys.stderr,"opencl eval",pars 
    272273        #print "opencl eval",pars 
    273274        if len(loops) > MAX_LOOPS: 
  • sasmodels/models/cylinder_clone.c

    rce27e21 r1780d59  
    209209    // The additional volume factor is for polydisperse volume normalization. 
    210210    const real s = (sldCyl - sldSolv) * form_volume(radius, length); 
    211     return REAL(1.0e8) * form * s * s; // * correction; 
    212 } 
     211    return REAL(4.0e8) * form * s * s; // * correction; 
     212} 
  • sasmodels/sasview_model.py

    rce27e21 r1780d59  
    44import numpy as np 
    55 
    6 def make_class(name, class_name=None): 
     6def make_class(name, class_name=None, dtype='single'): 
    77    from .core import opencl_model 
    88    if class_name is None: 
    99        class_name = "".join(part.capitalize() for part in name.split('_')+['model']) 
    10     model =  opencl_model(name) 
     10    model =  opencl_model(name, dtype=dtype) 
    1111    class ConstructedModel(SasviewModel): 
    1212        kernel = model 
    1313        def __init__(self, multfactor=1): 
    14             if self.kernel is None: 
    15                 self.__class__.kernel = opencl_model(name) 
    1614            SasviewModel.__init__(self, self.kernel) 
    1715    ConstructedModel.__name__ = class_name 
     
    4644                'width': 0, 
    4745                'npts': 35, 
    48                 'nsigma': 3, 
     46                'nsigmas': 3, 
    4947                'type': 'gaussian', 
    5048            } 
     
    160158        Return a list of all available parameters for the model 
    161159        """ 
    162         list = [] 
    163  
    164         for item in self.dispersion.keys(): 
    165             for p in self.dispersion[item].keys(): 
    166                 if p not in ['type']: 
    167                     list.append('%s.%s' % (item.lower(), p.lower())) 
    168  
    169         return list 
     160        # TODO: fix test so that parameter order doesn't matter 
     161        ret = ['%s.%s'%(d.lower(), p) 
     162               for d in self._model.info['partype']['pd-2d'] 
     163               for p in ('npts', 'nsigmas', 'width')] 
     164        #print ret 
     165        return ret 
    170166 
    171167    def clone(self): 
     
    295291        :param dispersion: dispersion object of type Dispersion 
    296292        """ 
    297         if parameter.lower() in (s.name.lower() for s in self.params.keys()): 
     293        if parameter.lower() in (s.lower() for s in self.params.keys()): 
     294            # TODO: Store the disperser object directly in the model. 
     295            # The current method of creating one on the fly whenever it is 
     296            # needed is kind of funky. 
     297            # Note: can't seem to get disperser parameters from sasview 
     298            # (1) Could create a sasview model that has not yet # been 
     299            # converted, assign the disperser to one of its polydisperse 
     300            # parameters, then retrieve the disperser parameters from the 
     301            # sasview model.  (2) Could write a disperser parameter retriever 
     302            # in sasview.  (3) Could modify sasview to use sasmodels.weights 
     303            # dispersers. 
     304            # For now, rely on the fact that the sasview only ever uses 
     305            # new dispersers in the set_dispersion call and create a new 
     306            # one instead of trying to assign parameters. 
     307            from . import weights 
     308            disperser = weights.dispersers[dispersion.__class__.__name__] 
     309            dispersion = weights.models[disperser]() 
    298310            self.dispersion[parameter] = dispersion.get_pars() 
    299311        else: 
     
    321333        dis = self.dispersion[par] 
    322334        v,w = weights.get_weights( 
    323             dis['type'], dis['npts'], dis['width'], dis['nsigma'], 
     335            dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 
    324336            self.params[par], limits[par], par in relative) 
    325337        return v,w/w.max() 
     338 
  • sasmodels/weights.py

    rce27e21 r1780d59  
    3838        For orientation parameters use absolute. 
    3939        """ 
    40         npts, width, nsigmas = self.npts, self.width, self.nsigmas 
    4140        sigma = self.width * center if relative else self.width 
    4241        if sigma == 0: 
     
    122121)) 
    123122 
    124 def get_weights(disperser, n, width, nsigma, value, limits, relative): 
     123 
     124def get_weights(disperser, n, width, nsigmas, value, limits, relative): 
    125125    cls = models[disperser] 
    126     obj = cls(n, width, nsigma) 
     126    obj = cls(n, width, nsigmas) 
    127127    v,w = obj.get_weights(value, limits[0], limits[1], relative) 
    128128    return v,w 
     129 
     130# Hack to allow sasview dispersion objects to interoperate with sasmodels 
     131dispersers = dict((v.__name__,k) for k,v in models.items()) 
     132dispersers['DispersionModel'] = RectangleDispersion.type 
     133 
Note: See TracChangeset for help on using the changeset viewer.