Changeset 298d2d4 in sasmodels for doc


Ignore:
Timestamp:
Mar 26, 2019 11:26:07 AM (5 years ago)
Author:
awashington
Branches:
master
Children:
d522352
Parents:
c9d052d (diff), 598a354 (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 'master' into log_sesans

Location:
doc
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • doc/guide/gpu_setup.rst

    r59485a4 r8b31efa  
    9494Device Selection 
    9595================ 
     96**OpenCL drivers** 
     97 
    9698If you have multiple GPU devices you can tell the program which device to use. 
    9799By default, the program looks for one GPU and one CPU device from available 
     
    104106was used to run the model. 
    105107 
    106 **If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* 
    107 **in your environment settings, and it will only use normal programs.** 
    108  
    109 If you want to use one of the other devices, you can run the following 
     108If you want to use a specific driver and devices, you can run the following 
    110109from the python console:: 
    111110 
     
    115114This will provide a menu of different OpenCL drivers available. 
    116115When one is selected, it will say "set PYOPENCL_CTX=..." 
    117 Use that value as the value of *SAS_OPENCL*. 
     116Use that value as the value of *SAS_OPENCL=driver:device*. 
     117 
     118To use the default OpenCL device (rather than CUDA or None), 
     119set *SAS_OPENCL=opencl*. 
     120 
     121In batch queues, you may need to set *XDG_CACHE_HOME=~/.cache*  
     122(Linux only) to a different directory, depending on how the filesystem  
     123is configured.  You should also set *SAS_DLL_PATH* for CPU-only modules. 
     124 
     125    -DSAS_MODELPATH=path sets directory containing custom models 
     126    -DSAS_OPENCL=vendor:device|cuda:device|none sets the target GPU device 
     127    -DXDG_CACHE_HOME=~/.cache sets the pyopencl cache root (linux only) 
     128    -DSAS_COMPILER=tinycc|msvc|mingw|unix sets the DLL compiler 
     129    -DSAS_OPENMP=1 turns on OpenMP for the DLLs 
     130    -DSAS_DLL_PATH=path sets the path to the compiled modules 
     131 
     132 
     133**CUDA drivers** 
     134 
     135If OpenCL drivers are not available on your system, but NVidia CUDA 
     136drivers are available, then set *SAS_OPENCL=cuda* or 
     137*SAS_OPENCL=cuda:n* for a particular device number *n*.  If no device 
     138number is specified, then the CUDA drivers looks for look for 
     139*CUDA_DEVICE=n* or a file ~/.cuda-device containing n for the device number. 
     140 
     141In batch queues, the SLURM command *sbatch --gres=gpu:1 ...* will set 
     142*CUDA_VISIBLE_DEVICES=n*, which ought to set the correct device 
     143number for *SAS_OPENCL=cuda*.  If not, then set 
     144*CUDA_DEVICE=$CUDA_VISIBLE_DEVICES* within the batch script.  You may 
     145need to set the CUDA cache directory to a folder accessible across the 
     146cluster with *PYCUDA_CACHE_DIR* (or *PYCUDA_DISABLE_CACHE* to disable 
     147caching), and you may need to set environment specific compiler flags 
     148with *PYCUDA_DEFAULT_NVCC_FLAGS*.  You should also set *SAS_DLL_PATH*  
     149for CPU-only modules. 
     150 
     151**No GPU support** 
     152 
     153If you don't want to use OpenCL or CUDA, you can set *SAS_OPENCL=None* 
     154in your environment settings, and it will only use normal programs. 
     155 
     156In batch queues, you may need to set *SAS_DLL_PATH* to a directory 
     157accessible on the compute node. 
     158 
    118159 
    119160Device Testing 
     
    139180the compiler. 
    140181 
    141 On Windows, set *SASCOMPILER=tinycc* for the tinycc compiler, 
    142 *SASCOMPILER=msvc* for the Microsoft Visual C compiler, 
    143 or *SASCOMPILER=mingw* for the MinGW compiler. If TinyCC is available 
     182On Windows, set *SAS_COMPILER=tinycc* for the tinycc compiler, 
     183*SAS_COMPILER=msvc* for the Microsoft Visual C compiler, 
     184or *SAS_COMPILER=mingw* for the MinGW compiler. If TinyCC is available 
    144185on the python path (it is provided with SasView), that will be the 
    145186default. If you want one of the other compilers, be sure to have it 
     
    154195*Document History* 
    155196 
    156 | 2017-09-27 Paul Kienzle 
     197| 2018-10-15 Paul Kienzle 
  • doc/guide/magnetism/magnetism.rst

    rbefe905 rdf87acf  
    8989 
    9090===========   ================================================================ 
    91  M0:sld       $D_M M_0$ 
    92  mtheta:sld   $\theta_M$ 
    93  mphi:sld     $\phi_M$ 
    94  up:angle     $\theta_\mathrm{up}$ 
    95  up:frac_i    $u_i$ = (spin up)/(spin up + spin down) *before* the sample 
    96  up:frac_f    $u_f$ = (spin up)/(spin up + spin down) *after* the sample 
     91 sld_M0       $D_M M_0$ 
     92 sld_mtheta   $\theta_M$ 
     93 sld_mphi     $\phi_M$ 
     94 up_frac_i    $u_i$ = (spin up)/(spin up + spin down) *before* the sample 
     95 up_frac_f    $u_f$ = (spin up)/(spin up + spin down) *after* the sample 
     96 up_angle     $\theta_\mathrm{up}$ 
    9797===========   ================================================================ 
    9898 
    9999.. note:: 
    100     The values of the 'up:frac_i' and 'up:frac_f' must be in the range 0 to 1. 
     100    The values of the 'up_frac_i' and 'up_frac_f' must be in the range 0 to 1. 
    101101 
    102102*Document History* 
  • doc/guide/pd/polydispersity.rst

    r29afc50 rd089a00  
    88.. _polydispersityhelp: 
    99 
    10 Polydispersity Distributions 
    11 ---------------------------- 
    12  
    13 With some models in sasmodels we can calculate the average intensity for a 
    14 population of particles that exhibit size and/or orientational 
    15 polydispersity. The resultant intensity is normalized by the average 
    16 particle volume such that 
     10Polydispersity & Orientational Distributions 
     11-------------------------------------------- 
     12 
     13For some models we can calculate the average intensity for a population of  
     14particles that possess size and/or orientational (ie, angular) distributions.  
     15In SasView we call the former *polydispersity* but use the parameter *PD* to  
     16parameterise both. In other words, the meaning of *PD* in a model depends on  
     17the actual parameter it is being applied too. 
     18 
     19The resultant intensity is then normalized by the average particle volume such  
     20that 
    1721 
    1822.. math:: 
     
    2024  P(q) = \text{scale} \langle F^* F \rangle / V + \text{background} 
    2125 
    22 where $F$ is the scattering amplitude and $\langle\cdot\rangle$ denotes an 
    23 average over the size distribution. 
     26where $F$ is the scattering amplitude and $\langle\cdot\rangle$ denotes an  
     27average over the distribution $f(x; \bar x, \sigma)$, giving 
     28 
     29.. math:: 
     30 
     31  P(q) = \frac{\text{scale}}{V} \int_\mathbb{R}  
     32  f(x; \bar x, \sigma) F^2(q, x)\, dx + \text{background} 
    2433 
    2534Each distribution is characterized by a center value $\bar x$ or 
    2635$x_\text{med}$, a width parameter $\sigma$ (note this is *not necessarily* 
    27 the standard deviation, so read the description carefully), the number of 
    28 sigmas $N_\sigma$ to include from the tails of the distribution, and the 
    29 number of points used to compute the average. The center of the distribution 
    30 is set by the value of the model parameter. The meaning of a polydispersity  
    31 parameter *PD* (not to be confused with a molecular weight distributions  
    32 in polymer science) in a model depends on the type of parameter it is being  
    33 applied too. 
     36the standard deviation, so read the description of the distribution carefully),  
     37the number of sigmas $N_\sigma$ to include from the tails of the distribution,  
     38and the number of points used to compute the average. The center of the  
     39distribution is set by the value of the model parameter. 
    3440 
    3541The distribution width applied to *volume* (ie, shape-describing) parameters  
    3642is relative to the center value such that $\sigma = \mathrm{PD} \cdot \bar x$.  
    37 However, the distribution width applied to *orientation* (ie, angle-describing)  
    38 parameters is just $\sigma = \mathrm{PD}$. 
     43However, the distribution width applied to *orientation* parameters is just  
     44$\sigma = \mathrm{PD}$. 
    3945 
    4046$N_\sigma$ determines how far into the tails to evaluate the distribution, 
    4147with larger values of $N_\sigma$ required for heavier tailed distributions. 
    4248The scattering in general falls rapidly with $qr$ so the usual assumption 
    43 that $G(r - 3\sigma_r)$ is tiny and therefore $f(r - 3\sigma_r)G(r - 3\sigma_r)$ 
     49that $f(r - 3\sigma_r)$ is tiny and therefore $f(r - 3\sigma_r)f(r - 3\sigma_r)$ 
    4450will not contribute much to the average may not hold when particles are large. 
    4551This, too, will require increasing $N_\sigma$. 
    4652 
    4753Users should note that the averaging computation is very intensive. Applying 
    48 polydispersion to multiple parameters at the same time or increasing the 
    49 number of points in the distribution will require patience! However, the 
    50 calculations are generally more robust with more data points or more angles. 
     54polydispersion and/or orientational distributions to multiple parameters at  
     55the same time, or increasing the number of points in the distribution, will  
     56require patience! However, the calculations are generally more robust with  
     57more data points or more angles. 
    5158 
    5259The following distribution functions are provided: 
     
    6471Additional distributions are under consideration. 
    6572 
     73**Beware: when the Polydispersity & Orientational Distribution panel in SasView is** 
     74**first opened, the default distribution for all parameters is the Gaussian Distribution.** 
     75**This may not be suitable. See Suggested Applications below.** 
     76 
     77.. note:: In 2009 IUPAC decided to introduce the new term 'dispersity' to replace  
     78           the term 'polydispersity' (see `Pure Appl. Chem., (2009), 81(2),  
     79           351-353 <http://media.iupac.org/publications/pac/2009/pdf/8102x0351.pdf>`_  
     80           in order to make the terminology describing distributions of chemical  
     81           properties unambiguous. However, these terms are unrelated to the  
     82           proportional size distributions and orientational distributions used in  
     83           SasView models. 
     84 
    6685Suggested Applications 
    6786^^^^^^^^^^^^^^^^^^^^^^ 
    6887 
    69 If applying polydispersion to parameters describing particle sizes, use 
     88If applying polydispersion to parameters describing particle sizes, consider using 
    7089the Lognormal or Schulz distributions. 
    7190 
    7291If applying polydispersion to parameters describing interfacial thicknesses 
    73 or angular orientations, use the Gaussian or Boltzmann distributions. 
     92or angular orientations, consider using the Gaussian or Boltzmann distributions. 
    7493 
    7594If applying polydispersion to parameters describing angles, use the Uniform  
     
    318337^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    319338 
    320 Many commercial Dynamic Light Scattering (DLS) instruments produce a size 
    321 polydispersity parameter, sometimes even given the symbol $p$\ ! This 
    322 parameter is defined as the relative standard deviation coefficient of 
    323 variation of the size distribution and is NOT the same as the polydispersity 
    324 parameters in the Lognormal and Schulz distributions above (though they all 
    325 related) except when the DLS polydispersity parameter is <0.13. 
    326  
    327 .. math:: 
    328  
    329     p_{DLS} = \sqrt(\nu / \bar x^2) 
    330  
    331 where $\nu$ is the variance of the distribution and $\bar x$ is the mean 
    332 value of $x$. 
     339Several measures of polydispersity abound in Dynamic Light Scattering (DLS) and  
     340it should not be assumed that any of the following can be simply equated with  
     341the polydispersity *PD* parameter used in SasView. 
     342 
     343The dimensionless **Polydispersity Index (PI)** is a measure of the width of the  
     344distribution of autocorrelation function decay rates (*not* the distribution of  
     345particle sizes itself, though the two are inversely related) and is defined by  
     346ISO 22412:2017 as 
     347 
     348.. math:: 
     349 
     350    PI = \mu_{2} / \bar \Gamma^2 
     351 
     352where $\mu_\text{2}$ is the second cumulant, and $\bar \Gamma^2$ is the  
     353intensity-weighted average value, of the distribution of decay rates. 
     354 
     355*If the distribution of decay rates is Gaussian* then 
     356 
     357.. math:: 
     358 
     359    PI = \sigma^2 / 2\bar \Gamma^2 
     360 
     361where $\sigma$ is the standard deviation, allowing a **Relative Polydispersity (RP)**  
     362to be defined as 
     363 
     364.. math:: 
     365 
     366    RP = \sigma / \bar \Gamma = \sqrt{2 \cdot PI} 
     367 
     368PI values smaller than 0.05 indicate a highly monodisperse system. Values  
     369greater than 0.7 indicate significant polydispersity. 
     370 
     371The **size polydispersity P-parameter** is defined as the relative standard  
     372deviation coefficient of variation   
     373 
     374.. math:: 
     375 
     376    P = \sqrt\nu / \bar R 
     377 
     378where $\nu$ is the variance of the distribution and $\bar R$ is the mean 
     379value of $R$. Here, the product $P \bar R$ is *equal* to the standard  
     380deviation of the Lognormal distribution. 
     381 
     382P values smaller than 0.13 indicate a monodisperse system. 
    333383 
    334384For more information see: 
    335 S King, C Washington & R Heenan, *Phys Chem Chem Phys*, (2005), 7, 143 
     385 
     386`ISO 22412:2017, International Standards Organisation (2017) <https://www.iso.org/standard/65410.html>`_. 
     387 
     388`Polydispersity: What does it mean for DLS and Chromatography <http://www.materials-talks.com/blog/2014/10/23/polydispersity-what-does-it-mean-for-dls-and-chromatography/>`_. 
     389 
     390`Dynamic Light Scattering: Common Terms Defined, Whitepaper WP111214. Malvern Instruments (2011) <http://www.biophysics.bioc.cam.ac.uk/wp-content/uploads/2011/02/DLS_Terms_defined_Malvern.pdf>`_. 
     391 
     392S King, C Washington & R Heenan, *Phys Chem Chem Phys*, (2005), 7, 143. 
     393 
     394T Allen, in *Particle Size Measurement*, 4th Edition, Chapman & Hall, London (1990). 
    336395 
    337396.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     
    343402| 2018-03-20 Steve King 
    344403| 2018-04-04 Steve King 
     404| 2018-08-09 Steve King 
  • doc/guide/plugin.rst

    r7e6bc45e rc94ab04  
    273273`Form_Factors`_ for more details. 
    274274 
     275**model_info = ...** lets you define a model directly, for example, by 
     276loading and modifying existing models.  This is done implicitly by 
     277:func:`sasmodels.core.load_model_info`, which can create a mixture model 
     278from a pair of existing models.  For example:: 
     279 
     280    from sasmodels.core import load_model_info 
     281    model_info = load_model_info('sphere+cylinder') 
     282 
     283See :class:`sasmodels.modelinfo.ModelInfo` for details about the model 
     284attributes that are defined. 
     285 
    275286Model Parameters 
    276287................ 
     
    291302 
    292303**Note: The order of the parameters in the definition will be the order of the 
    293 parameters in the user interface and the order of the parameters in Iq(), 
    294 Iqac(), Iqabc() and form_volume(). And** *scale* **and** *background* 
    295 **parameters are implicit to all models, so they do not need to be included 
    296 in the parameter table.** 
     304parameters in the user interface and the order of the parameters in Fq(), Iq(), 
     305Iqac(), Iqabc(), form_volume() and shell_volume(). 
     306And** *scale* **and** *background* **parameters are implicit to all models, 
     307so they do not need to be included in the parameter table.** 
    297308 
    298309- **"name"** is the name of the parameter shown on the FitPage. 
     
    363374    scattered intensity. 
    364375 
    365   - "volume" parameters are passed to Iq(), Iqac(), Iqabc() and form_volume(), 
    366     and have polydispersity loops generated automatically. 
     376  - "volume" parameters are passed to Fq(), Iq(), Iqac(), Iqabc(), form_volume() 
     377    and shell_volume(), and have polydispersity loops generated automatically. 
    367378 
    368379  - "orientation" parameters are not passed, but instead are combined with 
     
    424435appropriately smeared pattern. 
    425436 
     437Each .py file also contains a function:: 
     438 
     439        def random(): 
     440        ... 
     441 
     442This function provides a model-specific random parameter set which shows model 
     443features in the USANS to SANS range.  For example, core-shell sphere sets the 
     444outer radius of the sphere logarithmically in `[20, 20,000]`, which sets the Q 
     445value for the transition from flat to falling.  It then uses a beta distribution 
     446to set the percentage of the shape which is shell, giving a preference for very 
     447thin or very thick shells (but never 0% or 100%).  Using `-sets=10` in sascomp 
     448should show a reasonable variety of curves over the default sascomp q range. 
     449The parameter set is returned as a dictionary of `{parameter: value, ...}`. 
     450Any model parameters not included in the dictionary will default according to 
     451the code in the `_randomize_one()` function from sasmodels/compare.py. 
     452 
    426453Python Models 
    427454............. 
     
    476503used. 
    477504 
     505Hollow shapes, where the volume fraction of particle corresponds to the 
     506material in the shell rather than the volume enclosed by the shape, must 
     507also define a *shell_volume(par1, par2, ...)* function.  The parameters 
     508are the same as for *form_volume*.  The *I(q)* calculation should use 
     509*shell_volume* squared as its scale factor for the volume normalization. 
     510The structure factor calculation needs *form_volume* in order to properly 
     511scale the volume fraction parameter, so both functions are required for 
     512hollow shapes. 
     513 
     514**Note: Pure python models do not yet support direct computation of the** 
     515**average of $F(q)$ and $F^2(q)$. Neither do they support orientational** 
     516**distributions or magnetism (use C models if these are required).** 
     517 
    478518Embedded C Models 
    479519................. 
     
    487527This expands into the equivalent C code:: 
    488528 
    489     #include <math.h> 
    490529    double Iq(double q, double par1, double par2, ...); 
    491530    double Iq(double q, double par1, double par2, ...) 
     
    496535*form_volume* defines the volume of the shape. As in python models, it 
    497536includes only the volume parameters. 
     537 
     538*form_volume* defines the volume of the shell for hollow shapes. As in 
     539python models, it includes only the volume parameters. 
    498540 
    499541**source=['fn.c', ...]** includes the listed C source files in the 
     
    533575listed in *source*. 
    534576 
     577Structure Factors 
     578................. 
     579 
     580Structure factor calculations may need the underlying $<F(q)>$ and $<F^2(q)>$ 
     581rather than $I(q)$.  This is used to compute $\beta = <F(q)>^2/<F^2(q)>$ in 
     582the decoupling approximation to the structure factor. 
     583 
     584Instead of defining the *Iq* function, models can define *Fq* as 
     585something like:: 
     586 
     587    double Fq(double q, double *F1, double *F2, double par1, double par2, ...); 
     588    double Fq(double q, double *F1, double *F2, double par1, double par2, ...) 
     589    { 
     590        // Polar integration loop over all orientations. 
     591        ... 
     592        *F1 = 1e-2 * total_F1 * contrast * volume; 
     593        *F2 = 1e-4 * total_F2 * square(contrast * volume); 
     594        return I(q, par1, par2, ...); 
     595    } 
     596 
     597If the volume fraction scale factor is built into the model (as occurs for 
     598the vesicle model, for example), then scale *F1* by $\surd V_f$ so that 
     599$\beta$ is computed correctly. 
     600 
     601Structure factor calculations are not yet supported for oriented shapes. 
     602 
     603Note: only available as a separate C file listed in *source*, or within 
     604a *c_code* block within the python model definition file. 
     605 
    535606Oriented Shapes 
    536607............... 
     
    544615laboratory frame and beam travelling along $-z$. 
    545616 
    546 The oriented C model is called using *Iqabc(qa, qb, qc, par1, par2, ...)* where 
     617The oriented C model (oriented pure Python models are not supported)  
     618is called using *Iqabc(qa, qb, qc, par1, par2, ...)* where 
    547619*par1*, etc. are the parameters to the model.  If the shape is rotationally 
    548620symmetric about *c* then *psi* is not needed, and the model is called 
     
    648720to compute the proper magnetism and orientation, which you can implement 
    649721using *Iqxy(qx, qy, par1, par2, ...)*. 
     722 
     723**Note: Magnetism is not supported in pure Python models.** 
    650724 
    651725Special Functions 
     
    685759    erf, erfc, tgamma, lgamma:  **do not use** 
    686760        Special functions that should be part of the standard, but are missing 
    687         or inaccurate on some platforms. Use sas_erf, sas_erfc and sas_gamma 
    688         instead (see below). Note: lgamma(x) has not yet been tested. 
     761        or inaccurate on some platforms. Use sas_erf, sas_erfc, sas_gamma 
     762        and sas_lgamma instead (see below). 
    689763 
    690764Some non-standard constants and functions are also provided: 
     
    753827        Gamma function sas_gamma\ $(x) = \Gamma(x)$. 
    754828 
    755         The standard math function, tgamma(x) is unstable for $x < 1$ 
     829        The standard math function, tgamma(x), is unstable for $x < 1$ 
    756830        on some platforms. 
    757831 
    758832        :code:`source = ["lib/sas_gamma.c", ...]` 
    759833        (`sas_gamma.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gamma.c>`_) 
     834 
     835    sas_gammaln(x): 
     836        log gamma function sas_gammaln\ $(x) = \log \Gamma(|x|)$. 
     837 
     838        The standard math function, lgamma(x), is incorrect for single 
     839        precision on some platforms. 
     840 
     841        :code:`source = ["lib/sas_gammainc.c", ...]` 
     842        (`sas_gammainc.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gammainc.c>`_) 
     843 
     844    sas_gammainc(a, x), sas_gammaincc(a, x): 
     845        Incomplete gamma function 
     846        sas_gammainc\ $(a, x) = \int_0^x t^{a-1}e^{-t}\,dt / \Gamma(a)$ 
     847        and complementary incomplete gamma function 
     848        sas_gammaincc\ $(a, x) = \int_x^\infty t^{a-1}e^{-t}\,dt / \Gamma(a)$ 
     849 
     850        :code:`source = ["lib/sas_gammainc.c", ...]` 
     851        (`sas_gammainc.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gammainc.c>`_) 
    760852 
    761853    sas_erf(x), sas_erfc(x): 
     
    795887        If $n$ = 0 or 1, it uses sas_J0($x$) or sas_J1($x$), respectively. 
    796888 
     889        Warning: JN(n,x) can be very inaccurate (0.1%) for x not in [0.1, 100]. 
     890 
    797891        The standard math function jn(n, x) is not available on all platforms. 
    798892 
     
    803897        Sine integral Si\ $(x) = \int_0^x \tfrac{\sin t}{t}\,dt$. 
    804898 
     899        Warning: Si(x) can be very inaccurate (0.1%) for x in [0.1, 100]. 
     900 
    805901        This function uses Taylor series for small and large arguments: 
    806902 
    807         For large arguments, 
     903        For large arguments use the following Taylor series, 
    808904 
    809905        .. math:: 
     
    822918 
    823919        :code:`source = ["lib/Si.c", ...]` 
    824         (`Si.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/Si.c>`_) 
     920        (`Si.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_Si.c>`_) 
    825921 
    826922    sas_3j1x_x(x): 
     
    9741070          "radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 
    9751071         0.2, 0.228843], 
    976         [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "ER", 120.], 
    977         [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.], 
     1072        [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 
     1073         0.1, None, None, 120., None, 1.],  # q, F, F^2, R_eff, V, form:shell 
     1074        [{"@S": "hardsphere"}, 0.1, None], 
    9781075    ] 
    9791076 
    9801077 
    981 **tests=[[{parameters}, q, result], ...]** is a list of lists. 
     1078**tests=[[{parameters}, q, Iq], ...]** is a list of lists. 
    9821079Each list is one test and contains, in order: 
    9831080 
     
    9911088- input and output values can themselves be lists if you have several 
    9921089  $q$ values to test for the same model parameters. 
    993 - for testing *ER* and *VR*, give the inputs as "ER" and "VR" respectively; 
    994   the output for *VR* should be the sphere/shell ratio, not the individual 
    995   sphere and shell values. 
     1090- for testing effective radius, volume and form:shell volume ratio, use the 
     1091  extended form of the tests results, with *None, None, R_eff, V, V_r* 
     1092  instead of *Iq*.  This calls the kernel *Fq* function instead of *Iq*. 
     1093- for testing F and F^2 (used for beta approximation) do the same as the 
     1094  effective radius test, but include values for the first two elements, 
     1095  $<F(q)>$ and $<F^2(q)>$. 
     1096- for testing interaction between form factor and structure factor, specify 
     1097  the structure factor name in the parameters as *{"@S": "name", ...}* with 
     1098  the remaining list of parameters defined by the *P@S* product model. 
    9961099 
    9971100.. _Test_Your_New_Model: 
     
    10091112and a check that the model runs. 
    10101113 
    1011 If you are not using sasmodels from SasView, skip this step. 
    1012  
    10131114Recommended Testing 
    10141115................... 
     1116 
     1117**NB: For now, this more detailed testing is only possible if you have a  
     1118SasView build environment available!** 
    10151119 
    10161120If the model compiles and runs, you can next run the unit tests that 
  • doc/guide/scripting.rst

    r4aa5dce r23df833  
    1010The key functions are :func:`sasmodels.core.load_model` for loading the 
    1111model definition and compiling the kernel and 
    12 :func:`sasmodels.data.load_data` for calling sasview to load the data. Need 
    13 the data because that defines the resolution function and the q values to 
    14 evaluate. If there is no data, then use :func:`sasmodels.data.empty_data1D` 
    15 or :func:`sasmodels.data.empty_data2D` to create some data with a given $q$. 
    16  
    17 Using sasmodels through bumps 
    18 ============================= 
    19  
    20 With the data and the model, you can wrap it in a *bumps* model with 
     12:func:`sasmodels.data.load_data` for calling sasview to load the data. 
     13 
     14Preparing data 
     15============== 
     16 
     17Usually you will load data via the sasview loader, with the 
     18:func:`sasmodels.data.load_data` function.  For example:: 
     19 
     20    from sasmodels.data import load_data 
     21    data = load_data("sasmodels/example/093191_201.dat") 
     22 
     23You may want to apply a data mask, such a beam stop, and trim high $q$:: 
     24 
     25    from sasmodels.data import set_beam_stop 
     26    set_beam_stop(data, qmin, qmax) 
     27 
     28The :func:`sasmodels.data.set_beam_stop` method simply sets the *mask* 
     29attribute for the data. 
     30 
     31The data defines the resolution function and the q values to evaluate, so 
     32even if you simulating experiments prior to making measurements, you still 
     33need a data object for reference. Use :func:`sasmodels.data.empty_data1D` 
     34or :func:`sasmodels.data.empty_data2D` to create a container with a 
     35given $q$ and $\Delta q/q$.  For example:: 
     36 
     37    import numpy as np 
     38    from sasmodels.data import empty_data1D 
     39 
     40    # 120 points logarithmically spaced from 0.005 to 0.2, with dq/q = 5% 
     41    q = np.logspace(np.log10(5e-3), np.log10(2e-1), 120) 
     42    data = empty_data1D(q, resolution=0.05) 
     43 
     44To use a more realistic model of resolution, or to load data from a file 
     45format not understood by SasView, you can use :class:`sasmodels.data.Data1D` 
     46or :class:`sasmodels.data.Data2D` directly.  The 1D data uses 
     47*x*, *y*, *dx* and *dy* for $x = q$ and $y = I(q)$, and 2D data uses 
     48*x*, *y*, *z*, *dx*, *dy*, *dz* for $x, y = qx, qy$ and $z = I(qx, qy)$. 
     49[Note: internally, the Data2D object uses SasView conventions, 
     50*qx_data*, *qy_data*, *data*, *dqx_data*, *dqy_data*, and *err_data*.] 
     51 
     52For USANS data, use 1D data, but set *dxl* and *dxw* attributes to 
     53indicate slit resolution:: 
     54 
     55    data.dxl = 0.117 
     56 
     57See :func:`sasmodels.resolution.slit_resolution` for details. 
     58 
     59SESANS data is more complicated; if your SESANS format is not supported by 
     60SasView you need to define a number of attributes beyond *x*, *y*.  For 
     61example:: 
     62 
     63    SElength = np.linspace(0, 2400, 61) # [A] 
     64    data = np.ones_like(SElength) 
     65    err_data = np.ones_like(SElength)*0.03 
     66 
     67    class Source: 
     68        wavelength = 6 # [A] 
     69        wavelength_unit = "A" 
     70    class Sample: 
     71        zacceptance = 0.1 # [A^-1] 
     72        thickness = 0.2 # [cm] 
     73 
     74    class SESANSData1D: 
     75        #q_zmax = 0.23 # [A^-1] 
     76        lam = 0.2 # [nm] 
     77        x = SElength 
     78        y = data 
     79        dy = err_data 
     80        sample = Sample() 
     81    data = SESANSData1D() 
     82 
     83    x, y = ... # create or load sesans 
     84    data = smd.Data 
     85 
     86The *data* module defines various data plotters as well. 
     87 
     88Using sasmodels directly 
     89======================== 
     90 
     91Once you have a computational kernel and a data object, you can evaluate 
     92the model for various parameters using 
     93:class:`sasmodels.direct_model.DirectModel`.  The resulting object *f* 
     94will be callable as *f(par=value, ...)*, returning the $I(q)$ for the $q$ 
     95values in the data.  For example:: 
     96 
     97    import numpy as np 
     98    from sasmodels.data import empty_data1D 
     99    from sasmodels.core import load_model 
     100    from sasmodels.direct_model import DirectModel 
     101 
     102    # 120 points logarithmically spaced from 0.005 to 0.2, with dq/q = 5% 
     103    q = np.logspace(np.log10(5e-3), np.log10(2e-1), 120) 
     104    data = empty_data1D(q, resolution=0.05) 
     105    kernel = load_model("ellipsoid) 
     106    f = DirectModel(data, kernel) 
     107    Iq = f(radius_polar=100) 
     108 
     109Polydispersity information is set with special parameter names: 
     110 
     111    * *par_pd* for polydispersity width, $\Delta p/p$, 
     112    * *par_pd_n* for the number of points in the distribution, 
     113    * *par_pd_type* for the distribution type (as a string), and 
     114    * *par_pd_nsigmas* for the limits of the distribution. 
     115 
     116Using sasmodels through the bumps optimizer 
     117=========================================== 
     118 
     119Like DirectModel, you can wrap data and a kernel in a *bumps* model with 
    21120class:`sasmodels.bumps_model.Model` and create an 
    22 class:`sasmodels.bump_model.Experiment` that you can fit with the *bumps* 
     121class:`sasmodels.bumps_model.Experiment` that you can fit with the *bumps* 
    23122interface. Here is an example from the *example* directory such as 
    24123*example/model.py*:: 
     
    75174    SasViewCom bumps.cli example/model.py --preview 
    76175 
    77 Using sasmodels directly 
    78 ======================== 
    79  
    80 Bumps has a notion of parameter boxes in which you can set and retrieve 
    81 values.  Instead of using bumps, you can create a directly callable function 
    82 with :class:`sasmodels.direct_model.DirectModel`.  The resulting object *f* 
    83 will be callable as *f(par=value, ...)*, returning the $I(q)$ for the $q$ 
    84 values in the data.  Polydisperse parameters use the same naming conventions 
    85 as in the bumps model, with e.g., radius_pd being the polydispersity associated 
    86 with radius. 
     176Calling the computation kernel 
     177============================== 
    87178 
    88179Getting a simple function that you can call on a set of q values and return 
     
    97188python kernel.  Once the kernel is in hand, we can then marshal a set of 
    98189parameters into a :class:`sasmodels.details.CallDetails` object and ship it to 
    99 the kernel using the :func:`sansmodels.direct_model.call_kernel` function.  An 
    100 example should help, *example/cylinder_eval.py*:: 
    101  
    102     from numpy import logspace 
     190the kernel using the :func:`sansmodels.direct_model.call_kernel` function.  To 
     191accesses the underlying $<F(q)>$ and $<F^2(q)>$, use 
     192:func:`sasmodels.direct_model.call_Fq` instead. 
     193 
     194The following example should 
     195help, *example/cylinder_eval.py*:: 
     196 
     197    from numpy import logspace, sqrt 
    103198    from matplotlib import pyplot as plt 
    104199    from sasmodels.core import load_model 
    105     from sasmodels.direct_model import call_kernel 
     200    from sasmodels.direct_model import call_kernel, call_Fq 
    106201 
    107202    model = load_model('cylinder') 
    108203    q = logspace(-3, -1, 200) 
    109204    kernel = model.make_kernel([q]) 
    110     Iq = call_kernel(kernel, dict(radius=200.)) 
    111     plt.loglog(q, Iq) 
     205    pars = {'radius': 200, 'radius_pd': 0.1, 'scale': 2} 
     206    Iq = call_kernel(kernel, pars) 
     207    F, Fsq, Reff, V, Vratio = call_Fq(kernel, pars) 
     208 
     209    plt.loglog(q, Iq, label='2 I(q)') 
     210    plt.loglog(q, F**2/V, label='<F(q)>^2/V') 
     211    plt.loglog(q, Fsq/V, label='<F^2(q)>/V') 
     212    plt.xlabel('q (1/A)') 
     213    plt.ylabel('I(q) (1/cm)') 
     214    plt.title('Cylinder with radius 200.') 
     215    plt.legend() 
    112216    plt.show() 
    113217 
    114 On windows, this can be called from the cmd prompt using sasview as:: 
     218.. figure:: direct_call.png 
     219 
     220    Comparison between $I(q)$, $<F(q)>$ and $<F^2(q)>$ for cylinder model. 
     221 
     222This compares $I(q)$ with $<F(q)>$ and $<F^2(q)>$ for a cylinder 
     223with *radius=200 +/- 20* and *scale=2*. Note that *call_Fq* does not 
     224include scale and background, nor does it normalize by the average volume. 
     225The definition of $F = \rho V \hat F$ scaled by the contrast and 
     226volume, compared to the canonical cylinder $\hat F$, with $\hat F(0) = 1$. 
     227Integrating over polydispersity and orientation, the returned values are 
     228$\sum_{r,w\in N(r_o, r_o/10)} \sum_\theta w F(q,r_o,\theta)\sin\theta$ and 
     229$\sum_{r,w\in N(r_o, r_o/10)} \sum_\theta w F^2(q,r_o,\theta)\sin\theta$. 
     230 
     231On windows, this example can be called from the cmd prompt using sasview as 
     232as the python interpreter:: 
    115233 
    116234    SasViewCom example/cylinder_eval.py 
  • doc/rst_prolog

    r30b60d2 r2c12061  
    99.. |Ang^-3| replace:: |Ang|\ :sup:`-3` 
    1010.. |Ang^-4| replace:: |Ang|\ :sup:`-4` 
     11.. |nm^-1| replace:: nm\ :sup:`-1` 
    1112.. |cm^-1| replace:: cm\ :sup:`-1` 
    1213.. |cm^2| replace:: cm\ :sup:`2` 
  • doc/guide/sesans/sans_to_sesans.rst

    rf0fc507 rd7af1c6  
    3131 
    3232in which :math:`t` is the thickness of the sample and :math:`\lambda` is the wavelength of the neutrons. 
     33 
     34Log Spaced SESANS 
     35----------------- 
     36 
     37For computational efficiency, the integral in the Hankel transform is 
     38converted into a Reimann sum 
     39 
     40 
     41.. math:: G(\delta) \approx 
     42          2 \pi 
     43          \sum_{Q=q_{min}}^{q_{max}} J_0(Q \delta) 
     44          \frac{d \Sigma}{d \Omega} (Q) 
     45          Q \Delta Q \! 
     46 
     47However, this model approximates more than is strictly necessary. 
     48Specifically, it is approximating the entire integral, when it is only 
     49the scattering function that cannot be handled analytically.  A better 
     50approximation might be 
     51 
     52.. math:: G(\delta) \approx 
     53          \sum_{n=0} 2 \pi \frac{d \Sigma}{d \Omega} (q_n) 
     54          \int_{q_{n-1}}^{q_n} J_0(Q \delta) Q dQ 
     55          = 
     56          \sum_{n=0} \frac{2 \pi}{\delta} \frac{d \Sigma}{d \Omega} (q_n) 
     57          (q_n J_1(q_n \delta) - q_{n-1}J_1(q_{n-1} \delta))\!, 
     58 
     59Assume that vectors :math:`q_n` and :math:`I_n` represent the q points 
     60and corresponding intensity data, respectively.  Further assume that 
     61:math:`\delta_m` and :math:`G_m` are the spin echo lengths and 
     62corresponding Hankel transform value. 
     63 
     64.. math:: G_m = H_{nm} I_n 
     65 
     66where 
     67 
     68.. math:: H_{nm} = \frac{2 \pi}{\delta_m} 
     69          (q_n J_1(q_n \delta_m) - q_{n-1} J_1(q_{n-1} \delta_m)) 
     70 
     71Also not that, for the limit as :math:`\delta_m` approaches zero, 
     72 
     73.. math:: G(0) 
     74          = 
     75          \sum_{n=0} \pi \frac{d \Sigma}{d \Omega} (q_n) (q_n^2 - q_{n-1}^2) 
Note: See TracChangeset for help on using the changeset viewer.