Changeset 745b7bb in sasmodels


Ignore:
Timestamp:
Aug 4, 2016 11:32:17 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:
4e0968b
Parents:
54bcd4a
Message:

spherical sld: doc cleanup

Files:
1 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • doc/genmodel.py

    ra5b8477 r745b7bb  
    66sys.path.insert(0, os.path.abspath('..')) 
    77from sasmodels import generate, core 
    8 from sasmodels.direct_model import DirectModel 
     8from sasmodels.direct_model import DirectModel, call_profile 
    99from sasmodels.data import empty_data1D, empty_data2D 
    1010 
     
    1717    from sasmodels.kernel import KernelModel 
    1818    from sasmodels.modelinfo import ModelInfo 
     19 
    1920 
    2021def plot_1d(model, opts, ax): 
     
    5556    ax.set_xlabel(r'$Q_x \/(\AA^{-1})$') 
    5657    ax.set_ylabel(r'$Q_y \/(\AA^{-1})$') 
     58 
     59def plot_profile_inset(model_info, ax): 
     60    p = ax.get_position() 
     61    width, height = 0.4*(p.x1-p.x0), 0.4*(p.y1-p.y0) 
     62    left, bottom = p.x1-width, p.y1-height 
     63    inset = plt.gcf().add_axes([left, bottom, width, height]) 
     64    x, y, labels = call_profile(model_info) 
     65    inset.plot(x, y, '-') 
     66    inset.locator_params(nbins=4) 
     67    #inset.set_xlabel(labels[0]) 
     68    #inset.set_ylabel(labels[1]) 
     69    inset.text(0.99, 0.99, "profile", 
     70               horizontalalignment="right", 
     71               verticalalignment="top", 
     72               transform=inset.transAxes) 
    5773 
    5874def figfile(model_info): 
     
    100116        ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height]) 
    101117        plot_1d(model, opts, ax1d) 
     118 
     119    if model_info.profile: 
     120        plot_profile_inset(model_info, ax1d) 
    102121 
    103122    # Save image in model/img 
  • sasmodels/direct_model.py

    r9eb3632 r745b7bb  
    7373    #print("values:", values) 
    7474    return calculator(call_details, values, cutoff, is_magnetic) 
     75 
    7576 
    7677def get_weights(parameter, values): 
     
    9596        disperser, npts, width, nsigma, value, limits, relative) 
    9697    return value, weight / np.sum(weight) 
     98 
     99 
     100def call_profile(model_info, **pars): 
     101    args = {} 
     102    for p in model_info.parameters.kernel_parameters: 
     103        if p.length > 1: 
     104            value = np.array([pars.get(p.id+str(j), p.default) 
     105                              for j in range(1, p.length+1)]) 
     106        else: 
     107            value = pars.get(p.id, p.default) 
     108        args[p.id] = value 
     109    x, y = model_info.profile(**args) 
     110    return x, y, model_info.profile_axes 
     111 
    97112 
    98113class DataMixin(object): 
     
    290305        self._set_data(Iq, noise=noise) 
    291306 
     307    def profile(self, **pars): 
     308        # type: (**float) -> None 
     309        """ 
     310        Generate a plottable profile. 
     311        """ 
     312        return call_profile(self.model.info, **pars) 
     313 
    292314def main(): 
    293315    # type: () -> None 
  • sasmodels/models/spherical_sld.py

    r54bcd4a r745b7bb  
    11r""" 
    2 This model calculates an empirical functional form for SAS data using 
    3 SpericalSLD profile 
    4  
    5 Similarly to the OnionExpShellModel, this model provides the form factor, 
    6 P(q), for a multi-shell sphere, where the interface between the each neighboring 
    7 shells can be described by one of a number of functions including error, 
    8 power-law, and exponential functions. 
    9 This model is to calculate the scattering intensity by building a continuous 
    10 custom SLD profile against the radius of the particle. 
    11 The SLD profile is composed of a flat core, a flat solvent, a number (up to 9 ) 
    12 flat shells, and the interfacial layers between the adjacent flat shells 
    13 (or core, and solvent) (see below). 
    14  
    15 .. figure:: img/spherical_sld_profile.gif 
    16  
    17     Exemplary SLD profile 
     2Similarly to the onion, this model provides the form factor, $P(q)$, for 
     3a multi-shell sphere, where the interface between the each neighboring 
     4shells can be described by the error function, power-law, or exponential 
     5functions.  The scattering intensity is computed by building a continuous 
     6custom SLD profile along the radius of the particle. The SLD profile is 
     7composed of a number of uniform shells with interfacial shells between them. 
     8 
     9.. figure:: img/spherical_sld_profile.png 
     10 
     11    Example SLD profile 
    1812 
    1913Unlike the <onion> model (using an analytical integration), the interfacial 
    20 layers here are sub-divided and numerically integrated assuming each of the 
    21 sub-layers are described by a line function. 
    22 The number of the sub-layer can be given by users by setting the integer values 
    23 of npts_inter. The form factor is normalized by the total volume of the sphere. 
     14shells here are sub-divided and numerically integrated assuming each 
     15sub-shell is described by a line function, with *n_steps* sub-shells per 
     16interface. The form factor is normalized by the total volume of the sphere. 
    2417 
    2518Definition 
     
    4235 
    4336 
    44 so that individual terms can be calcualted as follows: 
     37so that individual terms can be calculated as follows: 
    4538 
    4639.. math:: 
     
    7265 
    7366 
    74 Here we assumed that the SLDs of the core and solvent are constant against $r$. 
     67Here we assumed that the SLDs of the core and solvent are constant in $r$. 
    7568The SLD at the interface between shells, $\rho_{\text {inter}_i}$ 
    7669is calculated with a function chosen by an user, where the functions are 
     
    107100The functions are normalized so that they vary between 0 and 1, and they are 
    108101constrained such that the SLD is continuous at the boundaries of the interface 
    109 as well as each sub-layers. Thus B and C are determined. 
    110  
    111 Once $\rho_{\text{inter}_i}$ is found at the boundary of the sub-layer of the 
     102as well as each sub-shell. Thus B and C are determined. 
     103 
     104Once $\rho_{\text{inter}_i}$ is found at the boundary of the sub-shell of the 
    112105interface, we can find its contribution to the form factor $P(q)$ 
    113106 
     
    121114    4 \pi \sum_{j=0}^{npts_{\text{inter}_i} -1 } \Big[ 
    122115    3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } 
    123     ( r_{j} ) V ( r_{ \text{sublayer}_j } ) 
     116    ( r_{j} ) V ( r_{ \text{subshell}_j } ) 
    124117    \Big[ \frac {r_j^2 \beta_\text{out}^2 \sin(\beta_\text{out}) 
    125118    - (\beta_\text{out}^2-2) \cos(\beta_\text{out}) } 
     
    127120 
    128121    - 3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } 
    129     ( r_{j} ) V ( r_{ \text{sublayer}_j-1 } ) 
     122    ( r_{j} ) V ( r_{ \text{subshell}_j-1 } ) 
    130123    \Big[ \frac {r_{j-1}^2 \sin(\beta_\text{in}) 
    131124    - (\beta_\text{in}^2-2) \cos(\beta_\text{in}) } 
     
    152145 
    153146 
    154 We assume the $\rho_{\text{inter}_i} (r)$ can be approximately linear 
    155 within a sub-layer $j$ 
    156  
    157 Finally form factor can be calculated by 
     147We assume $\rho_{\text{inter}_j} (r)$ is approximately linear 
     148within the sub-shell $j$. 
     149 
     150Finally the form factor can be calculated by 
    158151 
    159152.. math:: 
     
    169162    q = \sqrt{q_x^2 + q_y^2} 
    170163 
    171  
    172 .. figure:: img/spherical_sld_1d.jpg 
    173  
    174     1D plot using the default values (w/400 data point). 
    175  
    176 .. figure:: img/spherical_sld_default_profile.jpg 
    177  
    178     SLD profile from the default values. 
    179  
    180164.. note:: 
     165 
    181166    The outer most radius is used as the effective radius for S(Q) 
    182167    when $P(Q) * S(Q)$ is applied. 
     
    206191# pylint: disable=bad-whitespace, line-too-long 
    207192#            ["name", "units", default, [lower, upper], "type", "description"], 
    208 parameters = [["n_shells",             "",           1,      [1, 11],        "volume", "number of shells"], 
     193parameters = [["n_shells",             "",           1,      [1, 10],        "volume", "number of shells"], 
    209194              ["sld_solvent",          "1e-6/Ang^2", 1.0,    [-inf, inf],    "sld", "solvent sld"], 
    210195              ["sld[n_shells]",        "1e-6/Ang^2", 4.06,   [-inf, inf],    "sld", "sld of the shell"], 
     
    258243    rho.append(sld_solvent) 
    259244    # return sld profile (r, beta) 
    260     return np.asarray(z), np.asarray(rho)*1e-6 
     245    return np.asarray(z), np.asarray(rho) 
    261246 
    262247 
  • sasmodels/sasview_model.py

    r4edec6f r745b7bb  
    323323                beta is a list of the corresponding SLD values 
    324324        """ 
    325         args = [] # type: List[Union[float, np.ndarray]] 
     325        args = {} # type: Dict[str, Any] 
    326326        for p in self._model_info.parameters.kernel_parameters: 
    327327            if p.id == self.multiplicity_info.control: 
    328                 args.append(float(self.multiplicity)) 
     328                value = float(self.multiplicity) 
    329329            elif p.length == 1: 
    330                 args.append(self.params.get(p.id, np.NaN)) 
     330                value = self.params.get(p.id, np.NaN) 
    331331            else: 
    332                 args.append([self.params.get(p.id+str(k), np.NaN) 
    333                              for k in range(1,p.length+1)]) 
    334         return self._model_info.profile(*args) 
     332                value = np.array([self.params.get(p.id+str(k), np.NaN) 
     333                                  for k in range(1,p.length+1)] 
     334            args[p.id] = value 
     335 
     336        return self._model_info.profile(**args) 
    335337 
    336338    def setParam(self, name, value): 
Note: See TracChangeset for help on using the changeset viewer.