source: sasmodels/Models/weights.py @ a42fec0

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since a42fec0 was a42fec0, checked in by HMP1 <helen.park@…>, 10 years ago

Speed-up of 3X, compare.py working

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import numpy as np
2
3class GaussianDispersion(object):
4    def __init__(self, npts=35, width=0, nsigmas=3): #number want, percent deviation, #standard deviations from mean
5        self.type = 'gaussian'
6        self.npts = npts
7        self.width = width
8        self.nsigmas = nsigmas
9
10    def get_pars(self):
11        return self.__dict__
12
13    def get_weights(self, center, min, max, relative):
14        """ *center* is the center of the distribution
15        *min*,*max* are the min, max allowed values
16        *relative* is True if the width is relative to the center instead of absolute
17        For polydispersity use relative.  For orientation parameters use absolute."""
18        npts, width, nsigmas = self.npts, self.width, self.nsigmas
19        sigma = width * center if relative else width
20        if sigma == 0:
21            return np.array([center],'d'), np.array([1.], 'd')
22        x = center + np.linspace(-nsigmas * sigma, +nsigmas * sigma, npts)
23        x = x[(x >= min) & (x <= max)]
24        px = np.exp((x-center)**2 / (-2.0 * sigma * sigma))
25        return x, px
26
Note: See TracBrowser for help on using the repository browser.