- Timestamp:
- Sep 3, 2018 5:55:57 AM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- da1c8d1, 475ff58
- Parents:
- 39c2de9 (diff), bd7630d (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. - git-author:
- Steve K <smk78@…> (09/03/18 05:55:57)
- git-committer:
- GitHub <noreply@…> (09/03/18 05:55:57)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/scripting.rst
r4aa5dce rbd7630d 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
Note: See TracChangeset
for help on using the changeset viewer.