Ignore:
Timestamp:
Apr 10, 2017 4:01:46 AM (8 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
6c8fb2c
Parents:
9208346 (diff), c6f3aec (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 ESS_GUI

Location:
src/sas/sasgui/perspectives/fitting/media
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/media/fitting.rst

    rf237c05 r46dfee9  
    33Fitting Documentation 
    44===================== 
     5 
     6.. note:: In Windows use [Alt]-[Cursor left] to return to the previous page 
    57 
    68.. toctree:: 
     
    1820 
    1921   Information on the SasView Optimisers <optimizer.rst> 
    20  
    21    Writing a Plugin <plugin.rst> 
     22       
     23   Converting SANS to SESANS for Fitting <../../../sans_to_sesans> 
     24    
     25   Fitting SESANS Data <../../../sesans_fitting.rst> 
     26    
     27   Writing a Plugin Model <plugin.rst> 
     28       
     29   Computations with a GPU <../../../gpu_computations> 
     30    
  • src/sas/sasgui/perspectives/fitting/media/fitting_help.rst

    rf237c05 r9687d58  
    1818======= 
    1919 
     20.. note:: If some code blocks are not readable, expand the documentation window 
     21 
    2022.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    2123 
     
    3234*  in *Single* fit mode - individual data sets are fitted independently one-by-one 
    3335 
    34 *  in *Simultaneous* fit mode - multiple data sets are fitted simultaneously to the *same* model with/without constrained parameters (this might be useful, for example, if you have measured the same sample at different contrasts) 
     36*  in *Simultaneous* fit mode - multiple data sets are fitted simultaneously to 
     37   the *same* model with/without constrained parameters (this might be useful, 
     38   for example, if you have measured the same sample at different contrasts) 
    3539 
    3640*  in *Batch* fit mode - multiple data sets are fitted sequentially to the *same* model (this might be useful, for example, if you have performed a kinetic or time-resolved experiment and have *lots* of data sets!) 
     
    4145----------------- 
    4246 
    43 By default, the models in SasView are grouped into five categories 
    44  
    45 *  *Shapes* - models describing 'objects' (spheres, cylinders, etc) 
     47The models in SasView are grouped into categories. By default these consist of: 
     48 
     49*  *Cylinder* - cylindrical shapes (disc, right cylinder, cylinder with endcaps 
     50   etc) 
     51*  *Ellipsoid* - ellipsoidal shapes (oblate,prolate, core shell, etc) 
     52*  *Parellelepiped* - as the name implies 
     53*  *Sphere* - sheroidal shapes (sphere, core multishell, vesicle, etc) 
     54*  *Lamellae* - lamellar shapes (lamellar, core shell lamellar, stacked 
     55   lamellar, etc) 
    4656*  *Shape-Independent* - models describing structure in terms of density correlation functions, fractals, peaks, power laws, etc 
    47 *  *Customized Models* - SasView- or User-created (non-library) Python models 
    48 *  *Uncategorised* - other models (for reflectivity, etc) 
     57*  *Paracrystal* - semi ordered structures (bcc, fcc, etc) 
    4958*  *Structure Factor* - S(Q) models 
     59*  *Plugin Models* - User-created (custom/non-library) Python models 
    5060 
    5161Use the *Category* drop-down menu to chose a category of model, then select 
     
    8292.. image:: cat_fig0.bmp 
    8393 
    84 The categorization of all models except the customized models can be reassigned, 
    85 added to, and removed using *Category Manager*. Models can also be hidden from view 
    86 in the drop-down menus. 
     94The categorization of all models except the user supplied Plugin Models can be 
     95reassigned, added to, and removed using *Category Manager*. Models can also be 
     96hidden from view in the drop-down menus. 
    8797 
    8898.. image:: cat_fig1.bmp 
     
    91101^^^^^^^^^^^^^^^^^ 
    92102 
    93 To change category, highlight a model in the list by left-clicking on its entry and 
    94 then click the *Modify* button. Use the *Change Category* panel that appears to make 
    95 the required changes. 
     103To change category, highlight a model in the list by left-clicking on its entry 
     104and then click the *Modify* button. Use the *Change Category* panel that appears 
     105to make the required changes. 
    96106 
    97107.. image:: cat_fig2.bmp 
     
    104114^^^^^^^^^^^^^^^^^^^^^ 
    105115 
    106 Use the *Enable All / Disable All* buttons and the check boxes beside each model to 
    107 select the models to show/hide. To apply the selection, click *Ok*. Otherwise click 
    108 *Cancel*. 
     116Use the *Enable All / Disable All* buttons and the check boxes beside each model 
     117to select the models to show/hide. To apply the selection, click *Ok*. Otherwise 
     118click *Cancel*. 
    109119 
    110120*NB: It may be necessary to change to a different category and then back again* 
     
    116126--------------- 
    117127 
    118 For a complete list of all the library models available in SasView, see the Model Documentation. 
     128For a complete list of all the library models available in SasView, see 
     129the `Model Documentation <../../../index.html>`_ . 
    119130 
    120131It is also possible to add your own models. 
     
    124135.. _Adding_your_own_models: 
    125136 
    126 Adding your own models 
     137Adding your own Models 
    127138---------------------- 
    128139 
    129 There are currently two ways to add your own models to SasView: 
    130  
    131 * Using the :ref:`Custom_Model_Editor` 
    132 * By :ref:`Writing_a_Plugin` 
    133  
    134 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    135  
    136 .. _Custom_Model_Editor: 
    137  
    138 Custom Model Editor 
    139 ------------------- 
    140  
    141 From the *Fitting* option in the menu bar, select *Edit Custom Model*. 
    142  
    143 .. image:: edit_model_menu.bmp 
    144  
    145 and then one of the options 
    146  
    147 *  *New* - to create a new custom model template 
    148 *  *Sum|Multi(p1,p2)* - to create a new model by summing/multiplying existing models in the model library 
    149 *  *Advanced* - to edit a new custom model 
    150 *  *Delete* - to delete a custom model 
    151  
    152 New 
    153 ^^^^ 
     140There are essentially three ways to generate new fitting models for SasView: 
     141 
     142*  Using the SasView :ref:`New_Plugin_Model` helper dialog (best for beginners 
     143   and/or relatively simple models) 
     144*  By copying/editing an existing model (this can include models generated by 
     145   the New Plugin Model* dialog) in the :ref:`Python_shell` or  
     146   :ref:`Advanced_Plugin_Editor` (suitable for all use cases) 
     147*  By writing a model from scratch outside of SasView (only recommended for code 
     148   monkeys!) 
     149 
     150Please read the guidance on :ref:`Writing_a_Plugin` before proceeding. 
     151 
     152**To be found by SasView your model must reside in the *~\\.sasview\\plugin_models* folder.** 
     153 
     154.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     155 
     156.. _Plugin_Model_Operations: 
     157 
     158Plugin Model Operations 
     159----------------------- 
     160 
     161From the *Fitting* option in the menu bar, select *Plugin Model Operations* 
     162 
     163.. image:: edit_model_menu.png 
     164 
     165and then one of the sub-options 
     166 
     167*  *New Plugin Model* - to create a plugin model template with a helper dialog 
     168*  *Sum|Multi(p1,p2)* - to create a plugin model by summing/multiplying *existing models* in the model library 
     169*  *Advanced Plugin Editor* - to create/edit a plugin model in a Python shell 
     170*  *Delete Plugin Models* - to delete a plugin model 
     171*  *Load Plugin Models* - to (re-)load plugin models 
     172 
     173.. _New_Plugin_Model: 
     174 
     175New Plugin Model 
     176^^^^^^^^^^^^^^^^ 
     177 
     178Relatively straightforward models can be programmed directly from the SasView 
     179GUI using the *New Plugin Model Function*. 
    154180 
    155181.. image:: new_model.bmp 
    156182 
    157 A model template generated by this option can be viewed and further modified using 
    158 the :ref:`Advanced` option. 
    159  
    160 *NB: "Fit Parameters" has been split into two sections, those which can be 
    161 polydisperse (shape and orientation parameters) and those which are not 
    162 (scattering length densities, for example).* 
     183When using this feature, be aware that even if your code has errors, including  
     184syntax errors, a model file is still generated. When you then correct the errors  
     185and click 'Apply' again to re-compile you will get an error informing you that  
     186the model already exists if the 'Overwrite' box is not checked. In this case you  
     187will need to supply a new model function name. By default the 'Overwrite' box is  
     188*checked*\ . 
     189 
     190Also note that the 'Fit Parameters' have been split into two sections: those 
     191which can be polydisperse (shape and orientation parameters) and those which are 
     192not (eg, scattering length densities). 
     193 
     194A model file generated by this option can be viewed and further modified using 
     195the :ref:`Advanced_Plugin_Editor` . 
    163196 
    164197Sum|Multi(p1,p2) 
     
    167200.. image:: sum_model.bmp 
    168201 
    169 This option creates a custom model of the form 
    170  
    171 Custom Model = scale_factor \* (model1 +/\* model2) 
    172  
    173 In the *Easy Sum/Multi Editor* give the new custom model a function name and brief 
    174 description (to appear under the *Details* button on the *Fit Page*). Then select 
     202This option creates a custom Plugin Model of the form:: 
     203 
     204     Plugin Model = scale_factor * {(scale_1 * model_1) +/- (scale_2 * model_2)} + background 
     205 
     206or:: 
     207 
     208     Plugin Model = scale_factor * model_1 /* model_2 + background 
     209 
     210In the *Easy Sum/Multi Editor* give the new model a function name and brief 
     211description (to appear under the *Details* button on the *FitPage*). Then select 
    175212two existing models, as p1 and p2, and the required operator, '+' or '*' between 
    176213them. Finally, click the *Apply* button to generate the model and then click *Close*. 
    177214 
    178 *NB: Any changes to a custom model generated in this way only become effective after* 
    179 *it is re-selected from the model drop-down menu on the Fit Page.* 
    180  
    181 .. _Advanced: 
    182  
    183 Advanced 
    184 ^^^^^^^^ 
    185  
    186 Selecting this option shows all the custom models in the plugin model folder 
    187  
    188   *C:\\Users\\[username]\\.sasview\\plugin_models* - (on Windows) 
     215Any changes to a plugin model generated in this way only become effective *after* it is re-selected from the model drop-down menu on the FitPage. 
     216 
     217.. _Advanced_Plugin_Editor: 
     218 
     219Advanced Plugin Editor 
     220^^^^^^^^^^^^^^^^^^^^^^ 
     221 
     222Selecting this option shows all the plugin models in the plugin model folder, on Windows this is 
     223 
     224  *C:\\Users\\{username}\\.sasview\\plugin_models* 
    189225 
    190226You can edit, modify, and save the Python code in any of these models using the 
    191 *Advanced Custom Model Editor*. 
    192  
    193 See :ref:`Writing_a_Plugin` for details on the plugin format. 
    194  
    195 *NB: Sum/Product models are still using the SasView 3.x model format.  Unless 
    196 you are confident about what you are doing, it is recommended that you 
    197 only modify lines denoted with the ## <----- comments!* 
    198  
    199 When editing is complete, select *Run -> Compile* from the *Model Editor* menu bar. An 
    200 *Info* box will appear with the results of the compilation and model unit tests. The 
    201 model will only be usable if the tests 'pass'. 
    202  
    203 To use the model, go to the relevant *Fit Page*, select the *Customized Models* 
     227*Advanced Plugin Model Editor*. Note that this is actually the same tool as the :ref:`Python_shell` . 
     228 
     229For details of the SasView plugin model format see :ref:`Writing_a_Plugin` . 
     230 
     231.. note:: Model files generated with the Sum/Multi option are still using the SasView 3.x model format. Unless you are confident about what you are doing, it is recommended that you only modify lines denoted with the ## <----- comments! 
     232 
     233When editing is complete, select *Run* > *Check Model* from the *Advanced Plugin Model Editor* menu bar. An *Info* box will appear with the results of the compilation and model unit tests. The model will only be usable if the tests 'pass'. 
     234 
     235.. image:: ../calculator/new_pycrust_example_2.png 
     236 
     237To use the model, go to the relevant *Fit Page*, select the *Plugin Models* 
    204238category and then select the model from the drop-down menu. 
    205239 
    206 *NB: Any changes to a custom model generated in this way only become effective after* 
    207 *it is re-selected from the model drop-down menu on the Fit Page.* 
    208  
    209 Delete 
    210 ^^^^^^ 
    211  
    212 Simply highlight the custom model to be removed. This operation is final! 
    213  
    214 *NB: Custom models shipped with SasView cannot be removed in this way.* 
    215  
    216 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    217  
    218   .. _Writing_a_Plugin: 
    219  
    220   Writing a Plugin 
    221   ---------------- 
    222  
    223   Advanced users can write their own model in Python and save it to the the SasView 
    224   *plugin_models* folder 
    225  
    226     *C:\\Users\\[username]\\.sasview\\plugin_models* - (on Windows) 
    227  
    228   in .py format. The next time SasView is started it will compile the plugin and add 
    229   it to the list of *Customized Models*. 
    230  
    231   It is recommended that existing plugin models be used as templates. 
     240Any changes to a plugin model generated in this way only become effective *after* it is re-selected from the model drop-down menu on the FitPage. 
     241 
     242Delete Plugin Models 
     243^^^^^^^^^^^^^^^^^^^^ 
     244 
     245Simply highlight the plugin model to be removed. The operation is final!!! 
     246 
     247*NB: Models shipped with SasView cannot be removed in this way.* 
     248 
     249Load Plugin Models 
     250^^^^^^^^^^^^^^^^^^ 
     251 
     252This option loads (or re-loads) all models present in the 
     253*~\\.sasview\\plugin_models* folder. 
    232254 
    233255.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     
    392414:ref:`Assessing_Fit_Quality`. 
    393415 
    394 *NB: If you need to use a customized model, you must ensure that model is available* 
    395 *first (see* :ref:`Adding_your_own_models` *).* 
     416*NB: If you need to use a custom Plugin Model, you must ensure that model is 
     417available first (see* :ref:`Adding_your_own_models` *).* 
    396418 
    397419Method 
     
    476498If multiple data sets are in one file, load just that file. *Unselect All Data*, then 
    477499select a single initial data set to be fitted. Fit that selected data set as described 
    478 above under :ref:`Single_Fit_Mode` . 
    479  
    480 *NB: If you need to use a customized model, you must ensure that model is available* 
    481 *first (see* :ref:`Adding_your_own_models` *).* 
     500above under :ref:`Single_Fit_Mode`. 
     501 
     502*NB: If you need to use a custom Plugin Model, you must ensure that model is 
     503available first (see* :ref:`Adding_your_own_models` *).* 
    482504 
    483505Method 
     
    617639.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    618640 
    619 .. note::  This help document was last changed by Steve King, 04Jun2015 
     641.. note::  This help document was last changed by Steve King, 10Oct2016 
  • src/sas/sasgui/perspectives/fitting/media/plugin.rst

    rf237c05 r9687d58  
    11.. _Writing_a_Plugin: 
    22 
    3 Writing a Plugin 
    4 ================ 
    5  
    6 Users can write their own models and save it to the the SasView 
    7 *plugin_models* folder 
    8  
    9   *C:\\Users\\[username]\\.sasview\\plugin_models* - (on Windows) 
    10  
    11 The next time SasView is started it will compile the plugin and add 
    12 it to the list of *Customized Models*.  It is recommended that an 
    13 existing model be used as a template. 
    14  
    15 This page was originally written by our MOST experienced developers, 
    16 but has subsequently been edited by our LEAST experienced developer who felt 
    17 some instructions could have been clearer, and learnt one or two things that 
    18 were missing altogether! But they succeeded in converting a model that passed 
    19 testing, so there is no reason why you should not be able to do the same. 
    20  
    21 SasView has three ways of writing models: 
    22  
    23 - As a pure python model : Example - 
     3Writing a Plugin Model 
     4====================== 
     5 
     6.. note:: If some code blocks are not readable, expand the documentation window 
     7 
     8Introduction 
     9^^^^^^^^^^^^ 
     10 
     11There are essentially three ways to generate new fitting models for SasView: 
     12 
     13* Using the SasView :ref:`New_Plugin_Model` helper dialog (best for beginners 
     14  and/or relatively simple models) 
     15* By copying/editing an existing model (this can include models generated by 
     16  the *New Plugin Model* dialog) in the :ref:`Python_shell` or 
     17  :ref:`Advanced_Plugin_Editor` as described below (suitable for all use cases) 
     18* By writing a model from scratch outside of SasView (only recommended for 
     19  code monkeys!) 
     20 
     21Overview 
     22^^^^^^^^ 
     23 
     24If you write your own model and save it to the the SasView *plugin_models* folder 
     25 
     26  *C:\\Users\\{username}\\.sasview\\plugin_models* (on Windows) 
     27 
     28the next time SasView is started it will compile the plugin and add 
     29it to the list of *Plugin Models* in a FitPage. 
     30 
     31SasView models can be of three types: 
     32 
     33- A pure python model : Example - 
    2434  `broadpeak.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/broad_peak.py>`_ 
    25 - As a python model with embedded C : Example - 
     35- A python model with embedded C : Example - 
    2636  `sphere.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/sphere.py>`_ 
    27 - As a python wrapper with separate C code : Example - 
     37- A python wrapper with separate C code : Example - 
    2838  `cylinder.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/cylinder.py>`_, 
    2939  `cylinder.c <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/cylinder.c>`_ 
    3040 
    31 Many models are available for download from the 
    32 `model marketplace <http://marketplace.sasview.org/>`_. 
    33  
    34 The builtin modules are available in the *sasmodels-data/models* subdirectory 
    35 of the sasview distribution.  On Windows, this will be something like 
    36 *C:\Program Files (x86)\SasView\models*.  On MacOSX, these will be within 
     41The built-in modules are available in the *sasmodels-data\\models* subdirectory 
     42of your SasView installation folder.  On Windows, this will be something like 
     43*C:\\Program Files (x86)\\SasView\\sasmodels-data\\models*.  On Mac OSX, these will be within 
    3744the application bundle as 
    3845*/Applications/SasView 4.0.app/Contents/Resources/sasmodels-data/models*. 
    3946 
     47Other models are available for download from our 
     48`Model Marketplace <http://marketplace.sasview.org/>`_. You can contribute your own models to the  
     49Marketplace aswell. 
     50 
    4051Create New Model Files 
    4152^^^^^^^^^^^^^^^^^^^^^^ 
    4253 
    43 In the *~/.sasview/plugin_models* directory, copy the appropriate files 
    44 (using the examples above as templates) to mymodel.py (and mymodel.c, etc) 
     54In the *~\\.sasview\\plugin_models* directory, copy the appropriate files 
     55(we recommend using the examples above as templates) to mymodel.py (and mymodel.c, etc) 
    4556as required, where "mymodel" is the name for the model you are creating. 
    4657 
    4758*Please follow these naming rules:* 
    4859 
    49 - No capitalization and thus no CamelCase. 
    50 - If necessary use underscore to separate (i.e. barbell not BarBell or 
     60- No capitalization and thus no CamelCase 
     61- If necessary use underscore to separate words (i.e. barbell not BarBell or 
    5162  broad_peak not BroadPeak) 
    52 - Don't include “model” in the name (i.e. barbell not BarBellModel) 
     63- Do not include "model" in the name (i.e. barbell not BarBellModel) 
    5364 
    5465 
    5566Edit New Model Files 
    5667^^^^^^^^^^^^^^^^^^^^ 
     68 
     69Model Contents 
     70.............. 
    5771 
    5872The model interface definition is in the .py file.  This file contains: 
     
    6579    - without spaces (use underscores to separate words instead) 
    6680    - without any capitalization or CamelCase 
    67     - without incorporating the word 'model' 
     81    - without incorporating the word "model" 
    6882    - examples: *barbell* **not** *BarBell*; *broad_peak* **not** *BroadPeak*;  
    6983      *barbell* **not** *BarBellModel* 
     
    7286   - this is the **title** string in the *.py* file 
    7387   - this is a one or two line description of the model, which will appear 
    74      at the start of the model documentation and as a tooltip in the GUI 
     88     at the start of the model documentation and as a tooltip in the SasView GUI 
    7589 
    7690- a **short discription**: 
    7791   - this is the **description** string in the *.py* file 
    7892   - this is a medium length description which appears when you click 
    79      *Description* on the model fit page 
     93     *Description* on the model FitPage 
    8094 
    8195- a **parameter table**: 
     
    8599   - this is ReStructuredText enclosed between the r""" and """ delimiters 
    86100     at the top of the *.py* file 
     101   - what you write here is abstracted into the SasView help documentation 
     102   - this is what other users will refer to when they want to know what your model does;  
     103     so please be helpful! 
    87104 
    88105- a **definition** of the model: 
     
    97114 
    98115- a **plot** of the function, with a **figure caption**: 
    99    - this is automatically generated from the default parameters 
     116   - this is automatically generated from your default parameters 
    100117 
    101118- at least one **reference**: 
     
    107124   - the *.py* file should also contain a comment identifying *who* 
    108125     converted/created the model file 
     126 
     127Models that do not conform to these requirements will *never* be incorporated  
     128into the built-in library. 
    109129 
    110130More complete documentation for the sasmodels package can be found at 
     
    170190 
    171191The model should include a **formula** written using LaTeX markup. 
    172 The above example uses the *math* command to make a displayed equation.  You 
     192The example above uses the *math* command to make a displayed equation.  You 
    173193can also use *\$formula\$* for an inline formula. This is handy for defining 
    174194the relationship between the model parameters and formula variables, such 
    175195as the phrase "\$r\$ is the radius" used above.  The live demo MathJax 
    176196page `<http://www.mathjax.org/>`_ is handy for checking that the equations 
    177 will look like you expect. 
     197will look like you intend. 
    178198 
    179199Math layout uses the `amsmath <http://www.ams.org/publications/authors/tex/amslatex>`_ 
     
    207227 
    208228    name = "sphere"  # optional: defaults to the filename without .py 
     229 
    209230    title = "Spheres with uniform scattering length density" 
     231 
    210232    description = """\ 
    211233    P(q)=(scale/V)*[3V(sld-sld_solvent)*(sin(qr)-qr cos(qr)) 
     
    216238        sld_solvent: the SLD of the solvent 
    217239    """ 
     240 
    218241    category = "shape:sphere" 
     242 
    219243    single = True   # optional: defaults to True 
     244 
    220245    opencl = False  # optional: defaults to False 
     246 
    221247    structure_factor = False  # optional: defaults to False 
    222248 
     
    229255**title = "short description"** is short description of the model which 
    230256is included after the model name in the automatically generated documentation. 
    231 The title can also be used for a tooltip, for example. 
     257The title can also be used for a tooltip. 
    232258 
    233259**description = """doc string"""** is a longer description of the model. It 
    234 shows up when you press the "Description" button of the SasView fit page. 
     260shows up when you press the "Description" button of the SasView FitPage. 
    235261It should give a brief description of the equation and the parameters 
    236262without the need to read the entire model documentation. The triple quotes 
    237263allow you to write the description over multiple lines. Keep the lines 
    238264short since the GUI will wrap each one separately if they are too long. 
    239 **Make sure the parameter names in the description match the model definition.** 
     265**Make sure the parameter names in the description match the model definition!** 
    240266 
    241267**category = "shape:sphere"** defines where the model will appear in the 
    242268model documentation.  In this example, the model will appear alphabetically 
    243 in the list of spheroid models. 
     269in the list of spheroid models in the *Shape* category. 
    244270 
    245271**single = True** indicates that the model can be run using single 
     
    275301        ["radius",      "Ang",        50, [0, inf],    "volume", "Sphere radius"], 
    276302    ] 
    277     # pylint: disable=bad-whitespace, line-too-long 
     303    # pylint: enable=bad-whitespace, line-too-long 
    278304 
    279305**parameters = [["name", "units", default, [min,max], "type", "tooltip"],...]** 
    280 defines the parameters form the model. 
    281  
    282 - **the order of the parameters in the definition will be the order of 
    283   the parameters in the user interface and the order of the parameters 
    284   in Iq(), Iqxy() and form_volume().** 
    285  
    286 - **scale and background parameters are implicit to all models, so 
    287   they do not need to be included in the parameter table** 
    288  
    289 - **"name"** is the name of the parameter shown on the fit screen 
     306defines the parameters that form the model. 
     307 
     308**Note: The order of the parameters in the definition will be the order of the  
     309parameters in the user interface and the order of the parameters in Iq(),  
     310Iqxy() and form_volume(). And** *scale* **and** *background* **parameters are  
     311implicit to all models, so they do not need to be included in the parameter table.** 
     312 
     313- **"name"** is the name of the parameter shown on the FitPage. 
    290314 
    291315  - parameter names should follow the mathematical convention; e.g., 
    292     *radius_core* not *core_radius*, or *sld_solvent* not *solvent_sld* 
     316    *radius_core* not *core_radius*, or *sld_solvent* not *solvent_sld*. 
     317 
    293318  - model parameter names should be consistent between different models, 
    294319    so *sld_solvent*, for example, should have exactly the same name 
    295     in every model 
     320    in every model. 
     321 
    296322  - to see all the parameter names currently in use, type the following in the 
    297323    python shell/editor under the Tools menu:: 
     
    301327 
    302328    *re-use* as many as possible!!! 
     329 
    303330  - use "name[n]" for multiplicity parameters, where *n* is the name of 
    304331    the parameter defining the number of shells/layers/segments, etc. 
     
    306333- **"units"** are displayed along with the parameter name 
    307334 
    308   - every parameter should have units; use "None" if there are no units 
     335  - every parameter should have units; use "None" if there are no units. 
     336 
    309337  - **sld's should be given in units of 1e-6/Ang^2, and not simply 
    310338    1/Ang^2 to be consistent with the builtin models.  Adjust your formulas 
    311339    appropriately.** 
     340 
    312341  - fancy units markup is available for some units, including:: 
    313342 
     
    322351      and using negative exponents instead of the / operator, though 
    323352      the unit name should use the / operator for consistency. 
    324     - post a message to the sasview developers list with the changes 
    325  
    326 - **default** is the initial value for the parameter 
     353    - please post a message to the SasView developers mailing list with your changes. 
     354 
     355- **default** is the initial value for the parameter. 
    327356 
    328357  - **the parameter default values are used to auto-generate a plot of 
    329358    the model function in the documentation.** 
    330359 
    331 - **[min, max]** are the lower and upper limits on the parameter 
    332  
    333   - lower and upper limits can be any number, or -inf or inf. 
     360- **[min, max]** are the lower and upper limits on the parameter. 
     361 
     362  - lower and upper limits can be any number, or *-inf* or *inf*. 
     363 
    334364  - the limits will show up as the default limits for the fit making it easy, 
    335365    for example, to force the radius to always be greater than zero. 
    336366 
    337 - **"type"** can be one of: "", "sld", "volume", or "orientation" 
     367  - these are hard limits defining the valid range of parameter values; 
     368    polydisperity distributions will be truncated at the limits. 
     369 
     370- **"type"** can be one of: "", "sld", "volume", or "orientation". 
    338371 
    339372  - "sld" parameters can have magnetic moments when fitting magnetic models; 
    340373    depending on the spin polarization of the beam and the $q$ value being 
    341374    examined, the effective sld for that material will be used to compute the 
    342     scattered intensity 
     375    scattered intensity. 
     376 
    343377  - "volume" parameters are passed to Iq(), Iqxy(), and form_volume(), and 
    344378    have polydispersity loops generated automatically. 
     379 
    345380  - "orientation" parameters are only passed to Iqxy(), and have angular 
    346381    dispersion. 
     
    380415............. 
    381416 
    382 For pure python models, define the Iq funtion:: 
     417For pure python models, define the *Iq* function:: 
    383418 
    384419      import numpy as np 
     
    391426The parameters *par1, par2, ...* are the list of non-orientation parameters 
    392427to the model in the order that they appear in the parameter table. 
    393 **Note that the autogenerated model file uses *x* rather than *q*.** 
     428**Note that the autogenerated model file uses** *x* **rather than** *q*. 
    394429 
    395430The *.py* file should import trigonometric and exponential functions from 
    396 numpy rather that from math.  This lets us evaluate the model for the whole 
     431numpy rather than from math.  This lets us evaluate the model for the whole 
    397432range of $q$ values at once rather than looping over each $q$ separately in 
    398433python.  With $q$ as a vector, you cannot use if statements, but must instead 
     
    430465list includes the *volume* parameters in order.  This is used for a weighted 
    431466volume normalization so that scattering is on an absolute scale.  If 
    432 *form_volume* is not definded, then the default *form_volume = 1.0* will be 
     467*form_volume* is not defined, then the default *form_volume = 1.0* will be 
    433468used. 
    434469 
     
    436471................. 
    437472 
    438 Like pure python models, inline C models need define an *Iq* function:: 
     473Like pure python models, inline C models need to define an *Iq* function:: 
    439474 
    440475    Iq = """ 
     
    451486    } 
    452487 
    453 The C model operates on a single $q$ value at a time.  The code will be 
    454 run in parallel across different $q$ values, either on the graphics card 
    455 or the processor. 
    456  
    457 Rather than returning NAN from Iq, you must define the *INVALID(v)*.  The 
    458 *v* parameter lets you access all the parameters in the model using 
    459 *v.par1*, *v.par2*, etc. For example:: 
    460  
    461     #define INVALID(v) (v.bell_radius < v.radius) 
    462  
    463488*Iqxy* is similar to *Iq*, except it uses parameters *qx, qy* instead of *q*, 
    464 and it includes orientation parameters. As in python models, *form_volume* 
    465 includes only the volume parameters.  *Iqxy* will default to 
    466 *Iq(sqrt(qx**2 + qy**2), par1, ...)* and *form_volume* will default to 1.0. 
    467  
    468 The C code follows the C99 standard, including the usual math functions, 
    469 as defined in 
    470 `OpenCL <https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/mathFunctions.html>`_. 
    471  
    472 The standard constants and functions include the following:: 
    473  
    474     M_PI = pi 
    475     M_PI_2 = pi/2 
    476     M_PI_4 = pi/4 
    477     M_E = e 
    478     M_SQRT1_2 = 1/sqrt(2) 
    479     NAN = NaN 
    480     INFINITY = 1/0 
    481     erf(x) = error function 
    482     erfc(x) = 1-erf(x) 
    483     expm1(x) = exp(x) - 1 
    484     tgamma(x) = gamma function 
    485  
    486 Some non-standard constants and functions are also provided:: 
    487  
    488     M_PI_180 = pi/180 
    489     M_4PI_3 = 4pi/3 
    490     square(x) = x*x 
    491     cube(x) = x*x*x 
    492     sinc(x) = sin(x)/x, with sin(0)/0 -> 1 
    493     SINCOS(x, s, c) sets s=sin(angle) and c=cos(angle) 
    494     powr(x, y) = x^y for x >= 0 
    495     pown(x, n) = x^n for n integer 
    496  
    497 **source=['lib/fn.c', ...]** includes the listed C source files in the 
     489and it includes orientation parameters. 
     490 
     491*form_volume* defines the volume of the shape. As in python models, it  
     492includes only the volume parameters. 
     493 
     494*Iqxy* will default to *Iq(sqrt(qx**2 + qy**2), par1, ...)* and 
     495*form_volume* will default to 1.0. 
     496 
     497**source=['fn.c', ...]** includes the listed C source files in the 
    498498program before *Iq* and *Iqxy* are defined. This allows you to extend the 
    499 library of available C functions. Additional special functions and 
    500 scattering calculations are defined in 
    501 `sasmodels/models/lib <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib>`_, 
    502 including:: 
    503  
    504     sph_j1c(x) = 3 j1(x)/x = 3 (sin(x) - x cos(x))/x^3  [spherical bessel function] 
    505     sas_J1c(x) = 2 J1(x)/x  [bessel function of the first kind] 
    506     sas_gamma(x) = gamma function  [tgamma is unstable below 1] 
    507     sas_erf(x) = error function [erf is broken on some Intel OpenCL drivers] 
    508     sas_erfc(x) = 1-erf(x) 
    509     sas_J0(x) = J0(x) 
    510     sas_J1(x) = J1(x) 
    511     sas_JN(x) = JN(x) 
    512     Si(x) = integral sin(z)/z from 0 to x 
    513     Gauss76Wt = gaussian quadrature weights for 76 point integral 
    514     Gauss76Z = gaussian quadrature values for 76 point integral 
    515  
    516 These functions have been tuned to be fast and numerically stable down 
    517 to $q=0$ even in single precision.  In some cases they work around bugs 
    518 which appear on some platforms but not others. 
     499library of C functions available to your model. 
    519500 
    520501Models are defined using double precision declarations for the 
    521 parameters and return values.  Declarations and constants will be converted 
    522 to float or long double depending on the precision requested. 
     502parameters and return values.  When a model is run using single 
     503precision or long double precision, each variable is converted 
     504to the target type, depending on the precision requested. 
     505 
    523506**Floating point constants must include the decimal point.**  This allows us 
    524507to convert values such as 1.0 (double precision) to 1.0f (single precision) 
     
    529512use the builtin constant M_PI rather than 4*atan(1); it is faster and smaller! 
    530513 
    531 FLOAT_SIZE is the number of bytes in the converted variables. If your 
    532 algorithm depends on precision (which is not uncommon for numerical 
    533 algorithms), use the following:: 
    534  
    535     #if FLOAT_SIZE>4 
    536     ... code for double precision ... 
    537     #else 
    538     ... code for single precision ... 
    539     #endif 
    540  
    541 A value defined as SAS_DOUBLE will stay double precision; this should 
    542 not be used since some graphics card don't support double precision. 
    543  
     514The C model operates on a single $q$ value at a time.  The code will be 
     515run in parallel across different $q$ values, either on the graphics card 
     516or the processor. 
     517 
     518Rather than returning NAN from Iq, you must define the *INVALID(v)*.  The 
     519*v* parameter lets you access all the parameters in the model using 
     520*v.par1*, *v.par2*, etc. For example:: 
     521 
     522    #define INVALID(v) (v.bell_radius < v.radius) 
     523 
     524Special Functions 
     525................. 
     526 
     527The C code follows the C99 standard, with the usual math functions, 
     528as defined in 
     529`OpenCL <https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/mathFunctions.html>`_. 
     530This includes the following: 
     531 
     532    M_PI, M_PI_2, M_PI_4, M_SQRT1_2, M_E: 
     533        $\pi$, $\pi/2$, $\pi/4$, $1/\sqrt{2}$ and Euler's constant $e$ 
     534    exp, log, pow(x,y), expm1, sqrt: 
     535        Power functions $e^x$, $\ln x$, $x^y$, $e^x - 1$, $\sqrt{x}$. 
     536        The function expm1(x) is accurate across all $x$, including $x$ 
     537        very close to zero. 
     538    sin, cos, tan, asin, acos, atan: 
     539        Trigonometry functions and inverses, operating on radians. 
     540    sinh, cos, tanh, asinh, acosh, atanh: 
     541        Hyperbolic trigonometry functions. 
     542    atan2(y,x): 
     543        Angle from the $x$\ -axis to the point $(x,y)$, which is equal to 
     544        $\tan^{-1}(y/x)$ corrected for quadrant.  That is, if $x$ and $y$ are 
     545        both negative, then atan2(y,x) returns a value in quadrant III where 
     546        atan(y/x) would return a value in quadrant I. Similarly for 
     547        quadrants II and IV when $x$ and $y$ have opposite sign. 
     548    fmin(x,y), fmax(x,y), trunc, rint: 
     549        Floating point functions.  rint(x) returns the nearest integer. 
     550    NAN: 
     551        NaN, Not a Number, $0/0$.  Use isnan(x) to test for NaN.  Note that 
     552        you cannot use :code:`x == NAN` to test for NaN values since that 
     553        will always return false.  NAN does not equal NAN! 
     554    INFINITY: 
     555        $\infty, 1/0$.  Use isinf(x) to test for infinity, or isfinite(x) 
     556        to test for finite and not NaN. 
     557    erf, erfc, tgamma, lgamma:  **do not use** 
     558        Special functions that should be part of the standard, but are missing 
     559        or inaccurate on some platforms. Use sas_erf, sas_erfc and sas_gamma 
     560        instead (see below). Note: lgamma(x) has not yet been tested. 
     561 
     562Some non-standard constants and functions are also provided: 
     563 
     564    M_PI_180, M_4PI_3: 
     565        $\frac{\pi}{180}$, $\frac{4\pi}{3}$ 
     566    SINCOS(x, s, c): 
     567        Macro which sets s=sin(x) and c=cos(x). The variables *c* and *s* 
     568        must be declared first. 
     569    square(x): 
     570        $x^2$ 
     571    cube(x): 
     572        $x^3$ 
     573    sas_sinx_x(x): 
     574        $\sin(x)/x$, with limit $\sin(0)/0 = 1$. 
     575    powr(x, y): 
     576        $x^y$ for $x \ge 0$; this is faster than general $x^y$ on some GPUs. 
     577    pown(x, n): 
     578        $x^n$ for $n$ integer; this is faster than general $x^n$ on some GPUs. 
     579    FLOAT_SIZE: 
     580        The number of bytes in a floating point value.  Even though all 
     581        variables are declared double, they may be converted to single 
     582        precision float before running. If your algorithm depends on 
     583        precision (which is not uncommon for numerical algorithms), use 
     584        the following:: 
     585 
     586            #if FLOAT_SIZE>4 
     587            ... code for double precision ... 
     588            #else 
     589            ... code for single precision ... 
     590            #endif 
     591    SAS_DOUBLE: 
     592        A replacement for :code:`double` so that the declared variable will 
     593        stay double precision; this should generally not be used since some 
     594        graphics cards do not support double precision.  There is no provision 
     595        for forcing a constant to stay double precision. 
     596 
     597The following special functions and scattering calculations are defined in 
     598`sasmodels/models/lib <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib>`_. 
     599These functions have been tuned to be fast and numerically stable down 
     600to $q=0$ even in single precision.  In some cases they work around bugs 
     601which appear on some platforms but not others, so use them where needed. 
     602Add the files listed in :code:`source = ["lib/file.c", ...]` to your *model.py* 
     603file in the order given, otherwise these functions will not be available. 
     604 
     605    polevl(x, c, n): 
     606        Polynomial evaluation $p(x) = \sum_{i=0}^n c_i x^i$ using Horner's 
     607        method so it is faster and more accurate. 
     608 
     609        $c = \{c_n, c_{n-1}, \ldots, c_0 \}$ is the table of coefficients, 
     610        sorted from highest to lowest. 
     611 
     612        :code:`source = ["lib/polevl.c", ...]` (`link to code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/polevl.c>`_) 
     613 
     614    p1evl(x, c, n): 
     615        Evaluation of normalized polynomial $p(x) = x^n + \sum_{i=0}^{n-1} c_i x^i$ 
     616        using Horner's method so it is faster and more accurate. 
     617 
     618        $c = \{c_{n-1}, c_{n-2} \ldots, c_0 \}$ is the table of coefficients, 
     619        sorted from highest to lowest. 
     620 
     621        :code:`source = ["lib/polevl.c", ...]` 
     622        (`link to code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/polevl.c>`_) 
     623 
     624    sas_gamma(x): 
     625        Gamma function $\text{sas_gamma}(x) = \Gamma(x)$. 
     626 
     627        The standard math function, tgamma(x) is unstable for $x < 1$ 
     628        on some platforms. 
     629 
     630        :code:`source = ["lib/sasgamma.c", ...]` 
     631        (`link to code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gamma.c>`_) 
     632 
     633    sas_erf(x), sas_erfc(x): 
     634        Error function 
     635        $\text{sas_erf}(x) = \frac{2}{\sqrt\pi}\int_0^x e^{-t^2}\,dt$ 
     636        and complementary error function 
     637        $\text{sas_erfc}(x) = \frac{2}{\sqrt\pi}\int_x^{\infty} e^{-t^2}\,dt$. 
     638 
     639        The standard math functions erf(x) and erfc(x) are slower and broken 
     640        on some platforms. 
     641 
     642        :code:`source = ["lib/polevl.c", "lib/sas_erf.c", ...]` 
     643        (`link to error functions' code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_erf.c>`_) 
     644 
     645    sas_J0(x): 
     646        Bessel function of the first kind $\text{sas_J0}(x)=J_0(x)$ where 
     647        $J_0(x) = \frac{1}{\pi}\int_0^\pi \cos(x\sin(\tau))\,d\tau$. 
     648 
     649        The standard math function j0(x) is not available on all platforms. 
     650 
     651        :code:`source = ["lib/polevl.c", "lib/sas_J0.c", ...]` 
     652        (`link to Bessel function's code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_J0.c>`_) 
     653 
     654    sas_J1(x): 
     655        Bessel function of the first kind  $\text{sas_J1}(x)=J_1(x)$ where 
     656        $J_1(x) = \frac{1}{\pi}\int_0^\pi \cos(\tau - x\sin(\tau))\,d\tau$. 
     657 
     658        The standard math function j1(x) is not available on all platforms. 
     659 
     660        :code:`source = ["lib/polevl.c", "lib/sas_J1.c", ...]` 
     661        (`link to Bessel function's code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_J1.c>`_) 
     662 
     663    sas_JN(n, x): 
     664        Bessel function of the first kind and integer order $n$: 
     665        $\text{sas_JN}(n, x)=J_n(x)$ where 
     666        $J_n(x) = \frac{1}{\pi}\int_0^\pi \cos(n\tau - x\sin(\tau))\,d\tau$. 
     667        If $n$ = 0 or 1, it uses sas_J0(x) or sas_J1(x), respectively. 
     668 
     669        The standard math function jn(n, x) is not available on all platforms. 
     670 
     671        :code:`source = ["lib/polevl.c", "lib/sas_J0.c", "lib/sas_J1.c", "lib/sas_JN.c", ...]` 
     672        (`link to Bessel function's code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_JN.c>`_) 
     673 
     674    sas_Si(x): 
     675        Sine integral $\text{Si}(x) = \int_0^x \tfrac{\sin t}{t}\,dt$. 
     676 
     677        This function uses Taylor series for small and large arguments: 
     678 
     679        For large arguments, 
     680 
     681        .. math:: 
     682 
     683             \text{Si}(x) \sim \frac{\pi}{2} 
     684             - \frac{\cos(x)}{x}\left(1 - \frac{2!}{x^2} + \frac{4!}{x^4} - \frac{6!}{x^6} \right) 
     685             - \frac{\sin(x)}{x}\left(\frac{1}{x} - \frac{3!}{x^3} + \frac{5!}{x^5} - \frac{7!}{x^7}\right) 
     686 
     687        For small arguments, 
     688 
     689        .. math:: 
     690 
     691           \text{Si}(x) \sim x 
     692           - \frac{x^3}{3\times 3!} + \frac{x^5}{5 \times 5!} - \frac{x^7}{7 \times 7!} 
     693           + \frac{x^9}{9\times 9!} - \frac{x^{11}}{11\times 11!} 
     694 
     695        :code:`source = ["lib/Si.c", ...]` 
     696        (`link to code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/Si.c>`_) 
     697 
     698    sas_3j1x_x(x): 
     699        Spherical Bessel form 
     700        $\text{sph_j1c}(x) = 3 j_1(x)/x = 3 (\sin(x) - x \cos(x))/x^3$, 
     701        with a limiting value of 1 at $x=0$, where $j_1(x)$ is the spherical 
     702        Bessel function of the first kind and first order. 
     703 
     704        This function uses a Taylor series for small $x$ for numerical accuracy. 
     705 
     706        :code:`source = ["lib/sas_3j1x_x.c", ...]` 
     707        (`link to code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_3j1x_x.c>`_) 
     708 
     709 
     710    sas_2J1x_x(x): 
     711        Bessel form $\text{sas_J1c}(x) = 2 J_1(x)/x$, with a limiting value 
     712        of 1 at $x=0$, where $J_1(x)$ is the Bessel function of first kind 
     713        and first order. 
     714 
     715        :code:`source = ["lib/polevl.c", "lib/sas_J1.c", ...]` 
     716        (`link to Bessel form's code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_J1.c>`_) 
     717 
     718 
     719    Gauss76Z[i], Gauss76Wt[i]: 
     720        Points $z_i$ and weights $w_i$ for 76-point Gaussian quadrature, respectively, 
     721        computing $\int_{-1}^1 f(z)\,dz \approx \sum_{i=1}^{76} w_i\,f(z_i)$. 
     722 
     723        Similar arrays are available in :code:`gauss20.c` for 20-point 
     724        quadrature and in :code:`gauss150.c` for 150-point quadrature. 
     725 
     726        :code:`source = ["lib/gauss76.c", ...]` 
     727        (`link to code <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/gauss76.c>`_) 
     728 
     729 
     730 
     731Problems with C models 
     732...................... 
     733 
     734The graphics processor (GPU) in your computer is a specialized computer tuned 
     735for certain kinds of problems.  This leads to strange restrictions that you 
     736need to be aware of.  Your code may work fine on some platforms or for some 
     737models, but then return bad values on other platforms.  Some examples of 
     738particular problems: 
     739 
     740  **(1) Code is too complex, or uses too much memory.**  GPU devices only have a 
     741  limited amount of memory available for each processor.  If you run programs 
     742  which take too much memory, then rather than running multiple values in parallel 
     743  as it usually does, the GPU may only run a single version of the code at a 
     744  time, making it slower than running on the CPU.  It may fail to run on 
     745  some platforms, or worse, cause the screen to go blank or the system to reboot. 
     746 
     747  **(2) Code takes too long.**  Because GPU devices are used for the computer 
     748  display, the OpenCL drivers are very careful about the amount of time they 
     749  will allow any code to run.  For example, on OS X, the model will stop running 
     750  after 5 seconds regardless of whether the computation is complete.  You may end up 
     751  with only some of your 2D array defined, with the rest containing random 
     752  data. Or it may cause the screen to go blank or the system to reboot. 
     753 
     754  **(3) Memory is not aligned**.  The GPU hardware is specialized to operate on 
     755  multiple values simultaneously.  To keep the GPU simple the values in memory 
     756  must be aligned with the different GPU compute engines.  Not following these 
     757  rules can lead to unexpected values being loaded into memory, and wrong answers 
     758  computed.  The conclusion from a very long and strange debugging session was 
     759  that any arrays that you declare in your model should be a multiple of four. 
     760  For example:: 
     761 
     762      double Iq(q, p1, p2, ...) 
     763      { 
     764          double vector[8];  // Only going to use seven slots, but declare 8 
     765          ... 
     766      } 
     767 
     768The first step when your model is behaving strangely is to set **single=False**. 
     769This automatically restricts the model to only run on the CPU, or on high-end 
     770GPU cards.  There can still be problems even on high-end cards, so you can force 
     771the model off the GPU by setting **opencl=False**.  This runs the model 
     772as a normal C program without any GPU restrictions so you know that 
     773strange results are probably from your code rather than the environment.  Once 
     774the code is debugged, you can compare your output to the output on the GPU. 
     775 
     776Although it can be difficult to get your model to work on the GPU, the reward 
     777can be a model that runs 1000x faster on a good card.  Even your laptop may 
     778show a 50x improvement or more over the equivalent pure python model. 
    544779 
    545780External C Models 
     
    548783External C models are very much like embedded C models, except that 
    549784*Iq*, *Iqxy* and *form_volume* are defined in an external source file 
    550 loaded using the *source=[...]*  method. You need to supply the function 
     785loaded using the *source=[...]* statement. You need to supply the function 
    551786declarations for each of these that you need instead of building them 
    552787automatically from the parameter table. 
     
    557792Form Factors 
    558793............ 
    559  
    560 :: 
    561  
    562     def ER(radius, thickness): 
    563         """Effective radius of a core-shell sphere.""" 
    564         return radius + thickness 
    565794 
    566795Away from the dilute limit you can estimate scattering including 
     
    572801form averaged over all the polydispersity values. 
    573802 
    574 Consider the *core_shell_sphere*, which has a simple effective radius 
     803:: 
     804 
     805    def ER(radius, thickness): 
     806        """Effective radius of a core-shell sphere.""" 
     807        return radius + thickness 
     808 
     809Now consider the *core_shell_sphere*, which has a simple effective radius 
    575810equal to the radius of the core plus the thickness of the shell, as 
    576811shown above. Given polydispersity over *(r1, r2, ..., rm)* in radius and 
     
    597832one return value for each point in the mesh grid. 
    598833 
    599 *NOTE: we may be removing or modifying this feature soon.*  As of this 
    600 writing, core-shell sphere returns (1., 1.) for *VR*, giving a volume 
    601 ratio of 1.0. 
     834*NOTE: we may be removing or modifying this feature soon. As of the  
     835time of writing, core-shell sphere returns (1., 1.) for VR, giving a volume 
     836ratio of 1.0.* 
    602837 
    603838Unit Tests 
     
    624859- a dictionary of parameter values. This can be {} using the default 
    625860  parameters, or filled with some parameters that will be different 
    626   from the default, such as {‘radius’:10.0, ‘sld’:4}. Unlisted parameters 
     861  from the default, such as {‘radius’:10.0, ‘sld’:4}. Unlisted parameters 
    627862  will be given the default values. 
    628863- the input $q$ value or tuple of $(q_x, q_y)$ values. 
     
    640875^^^^^^^^^^^^^^^^^^^ 
    641876 
    642 If you are editing your model from the SasView GUI, you can test it 
    643 by selecting *Run -> Compile* from the *Model Editor* menu bar. An 
    644 *Info* box will appear with the results of the compilation and a 
    645 check that the model runs. 
     877Minimal Testing 
     878............... 
     879 
     880Either open the :ref:`Python_shell` (*Tools* > *Python Shell/Editor*) or the :ref:`Advanced_Plugin_Editor` (*Fitting* > *Plugin Model Operations* > *Advanced  
     881Plugin Editor*), load your model, and then select *Run > Check Model* from the  
     882menu bar. 
     883 
     884An *Info* box will appear with the results of the compilation and a check that  
     885the model runs. 
     886 
     887Recommended Testing 
     888................... 
    646889 
    647890If the model compiles and runs, you can next run the unit tests that 
    648 you have added using the **test=** values. Switch to the *Shell* tab 
     891you have added using the **test =** values. Switch to the *Shell* tab 
    649892and type the following:: 
    650893 
     
    686929For the random models, 
    687930 
    688 - sld will be in(-0.5,10.5), 
    689 - angles (theta, phi, psi) will be in (-180,180), 
    690 - angular dispersion will be in (0,45), 
    691 - polydispersity will be in (0,1) 
    692 - other values will be in (0, 2*v) where v is the value of the parameter in demo. 
    693  
    694 Dispersion parameters n, sigma and type will be unchanged from demo so that 
     931- *sld* will be in the range (-0.5,10.5), 
     932- angles (*theta, phi, psi*) will be in the range (-180,180), 
     933- angular dispersion will be in the range (0,45), 
     934- polydispersity will be in the range (0,1) 
     935- other values will be in the range (0, 2\ *v*), where *v* is the value of the parameter in demo. 
     936 
     937Dispersion parameters *n*\, *sigma* and *type* will be unchanged from demo so that 
    695938run times are predictable. 
    696939 
     
    701944 
    702945 
    703 Clean Lint 
    704 ^^^^^^^^^^ 
    705  
    706 **NB: For now we are not providing pylint with SasView; unless you have a 
    707 SasView development environment available, you can ignore this section.** 
     946Clean Lint - (Developer Version Only) 
     947^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
     948 
     949**NB: For now we are not providing pylint with the installer version of SasView;  
     950so unless you have a SasView build environment available, you can ignore this section!** 
    708951 
    709952Run the lint check with:: 
     
    717960for standard model functions *Iq*, *Iqxy*, etc. 
    718961 
    719 We will have delinting sessions at the SasView code camps, where we can 
     962We will have delinting sessions at the SasView Code Camps, where we can 
    720963decide on standards for model files, parameter names, etc. 
    721964 
    722 For now, you can tell pylint to ignore things.  For example, to align you 
     965For now, you can tell pylint to ignore things.  For example, to align your 
    723966parameters in blocks:: 
    724967 
     
    738981Don't put in too many pylint statements, though, since they make the code ugly. 
    739982 
    740 Check The Docs 
    741 ^^^^^^^^^^^^^^ 
     983Check The Docs - (Developer Version Only) 
     984^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    742985 
    743986You can get a rough idea of how the documentation will look using the 
     
    756999- `amsmath <http://www.ams.org/publications/authors/tex/amslatex>`_ 
    7571000 
    758 Finally 
    759 ^^^^^^^ 
     1001There is also a neat online WYSIWYG ReStructuredText editor at http://rst.ninjs.org\ . 
     1002 
     1003Share Your Model! 
     1004^^^^^^^^^^^^^^^^^ 
    7601005 
    7611006Once compare and the unit test(s) pass properly and everything is done, 
    7621007consider adding your model to the 
    763 `model marketplace <http://marketplace.sasview.org/>`_. 
    764  
     1008`Model Marketplace <http://marketplace.sasview.org/>`_ so that others may use it! 
     1009 
     1010.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     1011 
     1012.. note::  This help document was last changed by Steve King, 25Oct2016 
  • src/sas/sasgui/perspectives/fitting/media/sm_help.rst

    r7805458 r27aabc1  
    2020================== 
    2121 
    22 Sometimes it will be necessary to correct reduced experimental data for the 
    23 physical effects of the instrumental geometry in use. This process is called 
    24 *desmearing*. However, calculated/simulated data - which by definition will be 
    25 perfect/exact - can be *smeared* to make it more representative of what might 
    26 actually be measured experimentally. 
    27  
    28 SasView provides the following three smearing algorithms: 
     22Sometimes the instrumental geometry used to acquire the experimental data has  
     23an impact on the clarity of features in the reduced scattering curve. For  
     24example, peaks or fringes might be slightly broadened. This is known as  
     25*Q resolution smearing*. To compensate for this effect one can either try and  
     26remove the resolution contribution - a process called *desmearing* - or add the  
     27resolution contribution into a model calculation/simulation (which by definition  
     28will be exact) to make it more representative of what has been measured  
     29experimentally - a process called *smearing*. SasView will do the latter. 
     30 
     31Both smearing and desmearing rely on functions to describe the resolution  
     32effect. SasView provides three smearing algorithms: 
    2933 
    3034*  *Slit Smearing* 
    3135*  *Pinhole Smearing* 
    3236*  *2D Smearing* 
     37 
     38SasView also has an option to use Q resolution data (estimated at the time of  
     39data reduction) supplied in a reduced data file: the *Use dQ data* radio button. 
     40 
     41.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     42 
     43dQ Smearing 
     44----------- 
     45  
     46If this option is checked, SasView will assume that the supplied dQ values  
     47represent the standard deviations of Gaussian functions. 
    3348 
    3449.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
Note: See TracChangeset for help on using the changeset viewer.