- Timestamp:
- Mar 26, 2019 11:26:07 AM (6 years ago)
- 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. - Location:
- doc
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/gpu_setup.rst
r59485a4 r8b31efa 94 94 Device Selection 95 95 ================ 96 **OpenCL drivers** 97 96 98 If you have multiple GPU devices you can tell the program which device to use. 97 99 By default, the program looks for one GPU and one CPU device from available … … 104 106 was used to run the model. 105 107 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 108 If you want to use a specific driver and devices, you can run the following 110 109 from the python console:: 111 110 … … 115 114 This will provide a menu of different OpenCL drivers available. 116 115 When one is selected, it will say "set PYOPENCL_CTX=..." 117 Use that value as the value of *SAS_OPENCL*. 116 Use that value as the value of *SAS_OPENCL=driver:device*. 117 118 To use the default OpenCL device (rather than CUDA or None), 119 set *SAS_OPENCL=opencl*. 120 121 In batch queues, you may need to set *XDG_CACHE_HOME=~/.cache* 122 (Linux only) to a different directory, depending on how the filesystem 123 is 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 135 If OpenCL drivers are not available on your system, but NVidia CUDA 136 drivers are available, then set *SAS_OPENCL=cuda* or 137 *SAS_OPENCL=cuda:n* for a particular device number *n*. If no device 138 number 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 141 In batch queues, the SLURM command *sbatch --gres=gpu:1 ...* will set 142 *CUDA_VISIBLE_DEVICES=n*, which ought to set the correct device 143 number for *SAS_OPENCL=cuda*. If not, then set 144 *CUDA_DEVICE=$CUDA_VISIBLE_DEVICES* within the batch script. You may 145 need to set the CUDA cache directory to a folder accessible across the 146 cluster with *PYCUDA_CACHE_DIR* (or *PYCUDA_DISABLE_CACHE* to disable 147 caching), and you may need to set environment specific compiler flags 148 with *PYCUDA_DEFAULT_NVCC_FLAGS*. You should also set *SAS_DLL_PATH* 149 for CPU-only modules. 150 151 **No GPU support** 152 153 If you don't want to use OpenCL or CUDA, you can set *SAS_OPENCL=None* 154 in your environment settings, and it will only use normal programs. 155 156 In batch queues, you may need to set *SAS_DLL_PATH* to a directory 157 accessible on the compute node. 158 118 159 119 160 Device Testing … … 139 180 the compiler. 140 181 141 On Windows, set *SAS COMPILER=tinycc* for the tinycc compiler,142 *SAS COMPILER=msvc* for the Microsoft Visual C compiler,143 or *SAS COMPILER=mingw* for the MinGW compiler. If TinyCC is available182 On Windows, set *SAS_COMPILER=tinycc* for the tinycc compiler, 183 *SAS_COMPILER=msvc* for the Microsoft Visual C compiler, 184 or *SAS_COMPILER=mingw* for the MinGW compiler. If TinyCC is available 144 185 on the python path (it is provided with SasView), that will be the 145 186 default. If you want one of the other compilers, be sure to have it … … 154 195 *Document History* 155 196 156 | 201 7-09-27Paul Kienzle197 | 2018-10-15 Paul Kienzle -
doc/guide/magnetism/magnetism.rst
rbefe905 rdf87acf 89 89 90 90 =========== ================================================================ 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 sample96 up :frac_f $u_f$ = (spin up)/(spin up + spin down) *after* the sample91 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}$ 97 97 =========== ================================================================ 98 98 99 99 .. 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. 101 101 102 102 *Document History* -
doc/guide/pd/polydispersity.rst
r29afc50 rd089a00 8 8 .. _polydispersityhelp: 9 9 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 10 Polydispersity & Orientational Distributions 11 -------------------------------------------- 12 13 For some models we can calculate the average intensity for a population of 14 particles that possess size and/or orientational (ie, angular) distributions. 15 In SasView we call the former *polydispersity* but use the parameter *PD* to 16 parameterise both. In other words, the meaning of *PD* in a model depends on 17 the actual parameter it is being applied too. 18 19 The resultant intensity is then normalized by the average particle volume such 20 that 17 21 18 22 .. math:: … … 20 24 P(q) = \text{scale} \langle F^* F \rangle / V + \text{background} 21 25 22 where $F$ is the scattering amplitude and $\langle\cdot\rangle$ denotes an 23 average over the size distribution. 26 where $F$ is the scattering amplitude and $\langle\cdot\rangle$ denotes an 27 average 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} 24 33 25 34 Each distribution is characterized by a center value $\bar x$ or 26 35 $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. 36 the standard deviation, so read the description of the distribution carefully), 37 the number of sigmas $N_\sigma$ to include from the tails of the distribution, 38 and the number of points used to compute the average. The center of the 39 distribution is set by the value of the model parameter. 34 40 35 41 The distribution width applied to *volume* (ie, shape-describing) parameters 36 42 is 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}$.43 However, the distribution width applied to *orientation* parameters is just 44 $\sigma = \mathrm{PD}$. 39 45 40 46 $N_\sigma$ determines how far into the tails to evaluate the distribution, 41 47 with larger values of $N_\sigma$ required for heavier tailed distributions. 42 48 The 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)$49 that $f(r - 3\sigma_r)$ is tiny and therefore $f(r - 3\sigma_r)f(r - 3\sigma_r)$ 44 50 will not contribute much to the average may not hold when particles are large. 45 51 This, too, will require increasing $N_\sigma$. 46 52 47 53 Users 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. 54 polydispersion and/or orientational distributions to multiple parameters at 55 the same time, or increasing the number of points in the distribution, will 56 require patience! However, the calculations are generally more robust with 57 more data points or more angles. 51 58 52 59 The following distribution functions are provided: … … 64 71 Additional distributions are under consideration. 65 72 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 66 85 Suggested Applications 67 86 ^^^^^^^^^^^^^^^^^^^^^^ 68 87 69 If applying polydispersion to parameters describing particle sizes, use88 If applying polydispersion to parameters describing particle sizes, consider using 70 89 the Lognormal or Schulz distributions. 71 90 72 91 If applying polydispersion to parameters describing interfacial thicknesses 73 or angular orientations, usethe Gaussian or Boltzmann distributions.92 or angular orientations, consider using the Gaussian or Boltzmann distributions. 74 93 75 94 If applying polydispersion to parameters describing angles, use the Uniform … … 318 337 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 319 338 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$. 339 Several measures of polydispersity abound in Dynamic Light Scattering (DLS) and 340 it should not be assumed that any of the following can be simply equated with 341 the polydispersity *PD* parameter used in SasView. 342 343 The dimensionless **Polydispersity Index (PI)** is a measure of the width of the 344 distribution of autocorrelation function decay rates (*not* the distribution of 345 particle sizes itself, though the two are inversely related) and is defined by 346 ISO 22412:2017 as 347 348 .. math:: 349 350 PI = \mu_{2} / \bar \Gamma^2 351 352 where $\mu_\text{2}$ is the second cumulant, and $\bar \Gamma^2$ is the 353 intensity-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 361 where $\sigma$ is the standard deviation, allowing a **Relative Polydispersity (RP)** 362 to be defined as 363 364 .. math:: 365 366 RP = \sigma / \bar \Gamma = \sqrt{2 \cdot PI} 367 368 PI values smaller than 0.05 indicate a highly monodisperse system. Values 369 greater than 0.7 indicate significant polydispersity. 370 371 The **size polydispersity P-parameter** is defined as the relative standard 372 deviation coefficient of variation 373 374 .. math:: 375 376 P = \sqrt\nu / \bar R 377 378 where $\nu$ is the variance of the distribution and $\bar R$ is the mean 379 value of $R$. Here, the product $P \bar R$ is *equal* to the standard 380 deviation of the Lognormal distribution. 381 382 P values smaller than 0.13 indicate a monodisperse system. 333 383 334 384 For 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 392 S King, C Washington & R Heenan, *Phys Chem Chem Phys*, (2005), 7, 143. 393 394 T Allen, in *Particle Size Measurement*, 4th Edition, Chapman & Hall, London (1990). 336 395 337 396 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ … … 343 402 | 2018-03-20 Steve King 344 403 | 2018-04-04 Steve King 404 | 2018-08-09 Steve King -
doc/guide/plugin.rst
r7e6bc45e rc94ab04 273 273 `Form_Factors`_ for more details. 274 274 275 **model_info = ...** lets you define a model directly, for example, by 276 loading and modifying existing models. This is done implicitly by 277 :func:`sasmodels.core.load_model_info`, which can create a mixture model 278 from 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 283 See :class:`sasmodels.modelinfo.ModelInfo` for details about the model 284 attributes that are defined. 285 275 286 Model Parameters 276 287 ................ … … 291 302 292 303 **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.**304 parameters in the user interface and the order of the parameters in Fq(), Iq(), 305 Iqac(), Iqabc(), form_volume() and shell_volume(). 306 And** *scale* **and** *background* **parameters are implicit to all models, 307 so they do not need to be included in the parameter table.** 297 308 298 309 - **"name"** is the name of the parameter shown on the FitPage. … … 363 374 scattered intensity. 364 375 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. 367 378 368 379 - "orientation" parameters are not passed, but instead are combined with … … 424 435 appropriately smeared pattern. 425 436 437 Each .py file also contains a function:: 438 439 def random(): 440 ... 441 442 This function provides a model-specific random parameter set which shows model 443 features in the USANS to SANS range. For example, core-shell sphere sets the 444 outer radius of the sphere logarithmically in `[20, 20,000]`, which sets the Q 445 value for the transition from flat to falling. It then uses a beta distribution 446 to set the percentage of the shape which is shell, giving a preference for very 447 thin or very thick shells (but never 0% or 100%). Using `-sets=10` in sascomp 448 should show a reasonable variety of curves over the default sascomp q range. 449 The parameter set is returned as a dictionary of `{parameter: value, ...}`. 450 Any model parameters not included in the dictionary will default according to 451 the code in the `_randomize_one()` function from sasmodels/compare.py. 452 426 453 Python Models 427 454 ............. … … 476 503 used. 477 504 505 Hollow shapes, where the volume fraction of particle corresponds to the 506 material in the shell rather than the volume enclosed by the shape, must 507 also define a *shell_volume(par1, par2, ...)* function. The parameters 508 are the same as for *form_volume*. The *I(q)* calculation should use 509 *shell_volume* squared as its scale factor for the volume normalization. 510 The structure factor calculation needs *form_volume* in order to properly 511 scale the volume fraction parameter, so both functions are required for 512 hollow 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 478 518 Embedded C Models 479 519 ................. … … 487 527 This expands into the equivalent C code:: 488 528 489 #include <math.h>490 529 double Iq(double q, double par1, double par2, ...); 491 530 double Iq(double q, double par1, double par2, ...) … … 496 535 *form_volume* defines the volume of the shape. As in python models, it 497 536 includes only the volume parameters. 537 538 *form_volume* defines the volume of the shell for hollow shapes. As in 539 python models, it includes only the volume parameters. 498 540 499 541 **source=['fn.c', ...]** includes the listed C source files in the … … 533 575 listed in *source*. 534 576 577 Structure Factors 578 ................. 579 580 Structure factor calculations may need the underlying $<F(q)>$ and $<F^2(q)>$ 581 rather than $I(q)$. This is used to compute $\beta = <F(q)>^2/<F^2(q)>$ in 582 the decoupling approximation to the structure factor. 583 584 Instead of defining the *Iq* function, models can define *Fq* as 585 something 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 597 If the volume fraction scale factor is built into the model (as occurs for 598 the vesicle model, for example), then scale *F1* by $\surd V_f$ so that 599 $\beta$ is computed correctly. 600 601 Structure factor calculations are not yet supported for oriented shapes. 602 603 Note: only available as a separate C file listed in *source*, or within 604 a *c_code* block within the python model definition file. 605 535 606 Oriented Shapes 536 607 ............... … … 544 615 laboratory frame and beam travelling along $-z$. 545 616 546 The oriented C model is called using *Iqabc(qa, qb, qc, par1, par2, ...)* where 617 The oriented C model (oriented pure Python models are not supported) 618 is called using *Iqabc(qa, qb, qc, par1, par2, ...)* where 547 619 *par1*, etc. are the parameters to the model. If the shape is rotationally 548 620 symmetric about *c* then *psi* is not needed, and the model is called … … 648 720 to compute the proper magnetism and orientation, which you can implement 649 721 using *Iqxy(qx, qy, par1, par2, ...)*. 722 723 **Note: Magnetism is not supported in pure Python models.** 650 724 651 725 Special Functions … … 685 759 erf, erfc, tgamma, lgamma: **do not use** 686 760 Special functions that should be part of the standard, but are missing 687 or inaccurate on some platforms. Use sas_erf, sas_erfc andsas_gamma688 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). 689 763 690 764 Some non-standard constants and functions are also provided: … … 753 827 Gamma function sas_gamma\ $(x) = \Gamma(x)$. 754 828 755 The standard math function, tgamma(x) is unstable for $x < 1$829 The standard math function, tgamma(x), is unstable for $x < 1$ 756 830 on some platforms. 757 831 758 832 :code:`source = ["lib/sas_gamma.c", ...]` 759 833 (`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>`_) 760 852 761 853 sas_erf(x), sas_erfc(x): … … 795 887 If $n$ = 0 or 1, it uses sas_J0($x$) or sas_J1($x$), respectively. 796 888 889 Warning: JN(n,x) can be very inaccurate (0.1%) for x not in [0.1, 100]. 890 797 891 The standard math function jn(n, x) is not available on all platforms. 798 892 … … 803 897 Sine integral Si\ $(x) = \int_0^x \tfrac{\sin t}{t}\,dt$. 804 898 899 Warning: Si(x) can be very inaccurate (0.1%) for x in [0.1, 100]. 900 805 901 This function uses Taylor series for small and large arguments: 806 902 807 For large arguments ,903 For large arguments use the following Taylor series, 808 904 809 905 .. math:: … … 822 918 823 919 :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>`_) 825 921 826 922 sas_3j1x_x(x): … … 974 1070 "radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 975 1071 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], 978 1075 ] 979 1076 980 1077 981 **tests=[[{parameters}, q, result], ...]** is a list of lists.1078 **tests=[[{parameters}, q, Iq], ...]** is a list of lists. 982 1079 Each list is one test and contains, in order: 983 1080 … … 991 1088 - input and output values can themselves be lists if you have several 992 1089 $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. 996 1099 997 1100 .. _Test_Your_New_Model: … … 1009 1112 and a check that the model runs. 1010 1113 1011 If you are not using sasmodels from SasView, skip this step.1012 1013 1114 Recommended Testing 1014 1115 ................... 1116 1117 **NB: For now, this more detailed testing is only possible if you have a 1118 SasView build environment available!** 1015 1119 1016 1120 If the model compiles and runs, you can next run the unit tests that -
doc/guide/scripting.rst
r4aa5dce r23df833 10 10 The key functions are :func:`sasmodels.core.load_model` for loading the 11 11 model 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 14 Preparing data 15 ============== 16 17 Usually 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 23 You 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 28 The :func:`sasmodels.data.set_beam_stop` method simply sets the *mask* 29 attribute for the data. 30 31 The data defines the resolution function and the q values to evaluate, so 32 even if you simulating experiments prior to making measurements, you still 33 need a data object for reference. Use :func:`sasmodels.data.empty_data1D` 34 or :func:`sasmodels.data.empty_data2D` to create a container with a 35 given $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 44 To use a more realistic model of resolution, or to load data from a file 45 format not understood by SasView, you can use :class:`sasmodels.data.Data1D` 46 or :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 52 For USANS data, use 1D data, but set *dxl* and *dxw* attributes to 53 indicate slit resolution:: 54 55 data.dxl = 0.117 56 57 See :func:`sasmodels.resolution.slit_resolution` for details. 58 59 SESANS data is more complicated; if your SESANS format is not supported by 60 SasView you need to define a number of attributes beyond *x*, *y*. For 61 example:: 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 86 The *data* module defines various data plotters as well. 87 88 Using sasmodels directly 89 ======================== 90 91 Once you have a computational kernel and a data object, you can evaluate 92 the model for various parameters using 93 :class:`sasmodels.direct_model.DirectModel`. The resulting object *f* 94 will be callable as *f(par=value, ...)*, returning the $I(q)$ for the $q$ 95 values 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 109 Polydispersity 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 116 Using sasmodels through the bumps optimizer 117 =========================================== 118 119 Like DirectModel, you can wrap data and a kernel in a *bumps* model with 21 120 class:`sasmodels.bumps_model.Model` and create an 22 class:`sasmodels.bump _model.Experiment` that you can fit with the *bumps*121 class:`sasmodels.bumps_model.Experiment` that you can fit with the *bumps* 23 122 interface. Here is an example from the *example* directory such as 24 123 *example/model.py*:: … … 75 174 SasViewCom bumps.cli example/model.py --preview 76 175 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. 176 Calling the computation kernel 177 ============================== 87 178 88 179 Getting a simple function that you can call on a set of q values and return … … 97 188 python kernel. Once the kernel is in hand, we can then marshal a set of 98 189 parameters 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 190 the kernel using the :func:`sansmodels.direct_model.call_kernel` function. To 191 accesses the underlying $<F(q)>$ and $<F^2(q)>$, use 192 :func:`sasmodels.direct_model.call_Fq` instead. 193 194 The following example should 195 help, *example/cylinder_eval.py*:: 196 197 from numpy import logspace, sqrt 103 198 from matplotlib import pyplot as plt 104 199 from sasmodels.core import load_model 105 from sasmodels.direct_model import call_kernel 200 from sasmodels.direct_model import call_kernel, call_Fq 106 201 107 202 model = load_model('cylinder') 108 203 q = logspace(-3, -1, 200) 109 204 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() 112 216 plt.show() 113 217 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 222 This compares $I(q)$ with $<F(q)>$ and $<F^2(q)>$ for a cylinder 223 with *radius=200 +/- 20* and *scale=2*. Note that *call_Fq* does not 224 include scale and background, nor does it normalize by the average volume. 225 The definition of $F = \rho V \hat F$ scaled by the contrast and 226 volume, compared to the canonical cylinder $\hat F$, with $\hat F(0) = 1$. 227 Integrating 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 231 On windows, this example can be called from the cmd prompt using sasview as 232 as the python interpreter:: 115 233 116 234 SasViewCom example/cylinder_eval.py -
doc/rst_prolog
r30b60d2 r2c12061 9 9 .. |Ang^-3| replace:: |Ang|\ :sup:`-3` 10 10 .. |Ang^-4| replace:: |Ang|\ :sup:`-4` 11 .. |nm^-1| replace:: nm\ :sup:`-1` 11 12 .. |cm^-1| replace:: cm\ :sup:`-1` 12 13 .. |cm^2| replace:: cm\ :sup:`2` -
doc/guide/sesans/sans_to_sesans.rst
rf0fc507 rd7af1c6 31 31 32 32 in which :math:`t` is the thickness of the sample and :math:`\lambda` is the wavelength of the neutrons. 33 34 Log Spaced SESANS 35 ----------------- 36 37 For computational efficiency, the integral in the Hankel transform is 38 converted 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 47 However, this model approximates more than is strictly necessary. 48 Specifically, it is approximating the entire integral, when it is only 49 the scattering function that cannot be handled analytically. A better 50 approximation 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 59 Assume that vectors :math:`q_n` and :math:`I_n` represent the q points 60 and corresponding intensity data, respectively. Further assume that 61 :math:`\delta_m` and :math:`G_m` are the spin echo lengths and 62 corresponding Hankel transform value. 63 64 .. math:: G_m = H_{nm} I_n 65 66 where 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 71 Also 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.