Changeset 793d802 in sasmodels


Ignore:
Timestamp:
Aug 8, 2017 6:19:28 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
cdf7dac
Parents:
870a2f4 (diff), 997c9ca (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 doc_update

Files:
14 added
5 deleted
17 edited
8 moved

Legend:

Unmodified
Added
Removed
  • sasmodels/__init__.py

    r79906d1 r997c9ca  
    1414defining new models. 
    1515""" 
    16 __version__ = "0.94" 
     16__version__ = "0.97" 
    1717 
    1818def data_files(): 
  • sasmodels/modelinfo.py

    rbb4b509 r724257c  
    722722    parameters = make_parameter_table(getattr(kernel_module, 'parameters', [])) 
    723723    demo = expand_pars(parameters, getattr(kernel_module, 'demo', None)) 
    724     filename = abspath(kernel_module.__file__) 
     724    filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 
    725725    kernel_id = splitext(basename(filename))[0] 
    726726    name = getattr(kernel_module, 'name', None) 
     
    729729 
    730730    info.id = kernel_id  # string used to load the kernel 
    731     info.filename = abspath(kernel_module.__file__) 
     731    info.filename = filename 
    732732    info.name = name 
    733733    info.title = getattr(kernel_module, 'title', name+" model") 
  • sasmodels/sasview_model.py

    r749a7d4 r724257c  
    1515import traceback 
    1616import logging 
    17 from os.path import basename, splitext 
     17from os.path import basename, splitext, abspath, getmtime 
    1818import thread 
    1919 
     
    4040    pass 
    4141 
     42logger = logging.getLogger(__name__) 
     43 
    4244calculation_lock = thread.allocate_lock() 
    4345 
     46#: True if pre-existing plugins, with the old names and parameters, should 
     47#: continue to be supported. 
    4448SUPPORT_OLD_STYLE_PLUGINS = True 
     49 
     50# TODO: separate x_axis_label from multiplicity info 
     51MultiplicityInfo = collections.namedtuple( 
     52    'MultiplicityInfo', 
     53    ["number", "control", "choices", "x_axis_label"], 
     54) 
     55 
     56#: set of defined models (standard and custom) 
     57MODELS = {}  # type: Dict[str, SasviewModelType] 
     58#: custom model {path: model} mapping so we can check timestamps 
     59MODEL_BY_PATH = {}  # type: Dict[str, SasviewModelType] 
     60 
     61def find_model(modelname): 
     62    # type: (str) -> SasviewModelType 
     63    """ 
     64    Find a model by name.  If the model name ends in py, try loading it from 
     65    custom models, otherwise look for it in the list of builtin models. 
     66    """ 
     67    # TODO: used by sum/product model to load an existing model 
     68    # TODO: doesn't handle custom models properly 
     69    if modelname.endswith('.py'): 
     70        return load_custom_model(modelname) 
     71    elif modelname in MODELS: 
     72        return MODELS[modelname] 
     73    else: 
     74        raise ValueError("unknown model %r"%modelname) 
     75 
     76 
     77# TODO: figure out how to say that the return type is a subclass 
     78def load_standard_models(): 
     79    # type: () -> List[SasviewModelType] 
     80    """ 
     81    Load and return the list of predefined models. 
     82 
     83    If there is an error loading a model, then a traceback is logged and the 
     84    model is not returned. 
     85    """ 
     86    for name in core.list_models(): 
     87        try: 
     88            MODELS[name] = _make_standard_model(name) 
     89        except Exception: 
     90            logger.error(traceback.format_exc()) 
     91    if SUPPORT_OLD_STYLE_PLUGINS: 
     92        _register_old_models() 
     93 
     94    return list(MODELS.values()) 
     95 
     96 
     97def load_custom_model(path): 
     98    # type: (str) -> SasviewModelType 
     99    """ 
     100    Load a custom model given the model path. 
     101    """ 
     102    model = MODEL_BY_PATH.get(path, None) 
     103    if model is not None and model.timestamp == getmtime(path): 
     104        #logger.info("Model already loaded %s", path) 
     105        return model 
     106 
     107    #logger.info("Loading model %s", path) 
     108    kernel_module = custom.load_custom_kernel_module(path) 
     109    if hasattr(kernel_module, 'Model'): 
     110        model = kernel_module.Model 
     111        # Old style models do not set the name in the class attributes, so 
     112        # set it here; this name will be overridden when the object is created 
     113        # with an instance variable that has the same value. 
     114        if model.name == "": 
     115            model.name = splitext(basename(path))[0] 
     116        if not hasattr(model, 'filename'): 
     117            model.filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 
     118        if not hasattr(model, 'id'): 
     119            model.id = splitext(basename(model.filename))[0] 
     120    else: 
     121        model_info = modelinfo.make_model_info(kernel_module) 
     122        model = _make_model_from_info(model_info) 
     123    model.timestamp = getmtime(path) 
     124 
     125    # If a model name already exists and we are loading a different model, 
     126    # use the model file name as the model name. 
     127    if model.name in MODELS and not model.filename == MODELS[model.name].filename: 
     128        _previous_name = model.name 
     129        model.name = model.id 
     130 
     131        # If the new model name is still in the model list (for instance, 
     132        # if we put a cylinder.py in our plug-in directory), then append 
     133        # an identifier. 
     134        if model.name in MODELS and not model.filename == MODELS[model.name].filename: 
     135            model.name = model.id + '_user' 
     136        logger.info("Model %s already exists: using %s [%s]", 
     137                    _previous_name, model.name, model.filename) 
     138 
     139    MODELS[model.name] = model 
     140    MODEL_BY_PATH[path] = model 
     141    return model 
     142 
     143 
     144def _make_standard_model(name): 
     145    # type: (str) -> SasviewModelType 
     146    """ 
     147    Load the sasview model defined by *name*. 
     148 
     149    *name* can be a standard model name or a path to a custom model. 
     150 
     151    Returns a class that can be used directly as a sasview model. 
     152    """ 
     153    kernel_module = generate.load_kernel_module(name) 
     154    model_info = modelinfo.make_model_info(kernel_module) 
     155    return _make_model_from_info(model_info) 
     156 
    45157 
    46158def _register_old_models(): 
     
    60172    import sas.models 
    61173    from sasmodels.conversion_table import CONVERSION_TABLE 
    62     for new_name, conversion in CONVERSION_TABLE.get((3,1,2), {}).items(): 
     174    for new_name, conversion in CONVERSION_TABLE.get((3, 1, 2), {}).items(): 
    63175        # CoreShellEllipsoidModel => core_shell_ellipsoid:1 
    64176        new_name = new_name.split(':')[0] 
     
    69181        setattr(sas.models, old_path, ConstructedModule) 
    70182        sys.modules[old_path] = ConstructedModule 
    71  
    72  
    73 # TODO: separate x_axis_label from multiplicity info 
    74 MultiplicityInfo = collections.namedtuple( 
    75     'MultiplicityInfo', 
    76     ["number", "control", "choices", "x_axis_label"], 
    77 ) 
    78  
    79 MODELS = {} 
    80 def find_model(modelname): 
    81     # type: (str) -> SasviewModelType 
    82     """ 
    83     Find a model by name.  If the model name ends in py, try loading it from 
    84     custom models, otherwise look for it in the list of builtin models. 
    85     """ 
    86     # TODO: used by sum/product model to load an existing model 
    87     # TODO: doesn't handle custom models properly 
    88     if modelname.endswith('.py'): 
    89         return load_custom_model(modelname) 
    90     elif modelname in MODELS: 
    91         return MODELS[modelname] 
    92     else: 
    93         raise ValueError("unknown model %r"%modelname) 
    94  
    95  
    96 # TODO: figure out how to say that the return type is a subclass 
    97 def load_standard_models(): 
    98     # type: () -> List[SasviewModelType] 
    99     """ 
    100     Load and return the list of predefined models. 
    101  
    102     If there is an error loading a model, then a traceback is logged and the 
    103     model is not returned. 
    104     """ 
    105     models = [] 
    106     for name in core.list_models(): 
    107         try: 
    108             MODELS[name] = _make_standard_model(name) 
    109             models.append(MODELS[name]) 
    110         except Exception: 
    111             logging.error(traceback.format_exc()) 
    112     if SUPPORT_OLD_STYLE_PLUGINS: 
    113         _register_old_models() 
    114  
    115     return models 
    116  
    117  
    118 def load_custom_model(path): 
    119     # type: (str) -> SasviewModelType 
    120     """ 
    121     Load a custom model given the model path. 
    122     """ 
    123     kernel_module = custom.load_custom_kernel_module(path) 
    124     try: 
    125         model = kernel_module.Model 
    126         # Old style models do not set the name in the class attributes, so 
    127         # set it here; this name will be overridden when the object is created 
    128         # with an instance variable that has the same value. 
    129         if model.name == "": 
    130             model.name = splitext(basename(path))[0] 
    131         if not hasattr(model, 'filename'): 
    132             model.filename = kernel_module.__file__ 
    133             # For old models, treat .pyc and .py files interchangeably. 
    134             # This is needed because of the Sum|Multi(p1,p2) types of models 
    135             # and the convoluted way in which they are created. 
    136             if model.filename.endswith(".py"): 
    137                 logging.info("Loading %s as .pyc", model.filename) 
    138                 model.filename = model.filename+'c' 
    139         if not hasattr(model, 'id'): 
    140             model.id = splitext(basename(model.filename))[0] 
    141     except AttributeError: 
    142         model_info = modelinfo.make_model_info(kernel_module) 
    143         model = _make_model_from_info(model_info) 
    144  
    145     # If a model name already exists and we are loading a different model, 
    146     # use the model file name as the model name. 
    147     if model.name in MODELS and not model.filename == MODELS[model.name].filename: 
    148         _previous_name = model.name 
    149         model.name = model.id 
    150          
    151         # If the new model name is still in the model list (for instance, 
    152         # if we put a cylinder.py in our plug-in directory), then append 
    153         # an identifier. 
    154         if model.name in MODELS and not model.filename == MODELS[model.name].filename: 
    155             model.name = model.id + '_user' 
    156         logging.info("Model %s already exists: using %s [%s]", _previous_name, model.name, model.filename) 
    157  
    158     MODELS[model.name] = model 
    159     return model 
    160  
    161  
    162 def _make_standard_model(name): 
    163     # type: (str) -> SasviewModelType 
    164     """ 
    165     Load the sasview model defined by *name*. 
    166  
    167     *name* can be a standard model name or a path to a custom model. 
    168  
    169     Returns a class that can be used directly as a sasview model. 
    170     """ 
    171     kernel_module = generate.load_kernel_module(name) 
    172     model_info = modelinfo.make_model_info(kernel_module) 
    173     return _make_model_from_info(model_info) 
    174183 
    175184 
     
    283292 
    284293    #: names of the orientation parameters in the order they appear 
    285     orientation_params = None # type: Sequence[str] 
     294    orientation_params = None # type: List[str] 
    286295    #: names of the magnetic parameters in the order they appear 
    287     magnetic_params = None    # type: Sequence[str] 
     296    magnetic_params = None    # type: List[str] 
    288297    #: names of the fittable parameters 
    289     fixed = None              # type: Sequence[str] 
     298    fixed = None              # type: List[str] 
    290299    # TODO: the attribute fixed is ill-named 
    291300 
     
    611620        ## to calculate_Iq 
    612621        #if calculation_lock.locked(): 
    613         #    logging.info("calculation waiting for another thread to complete") 
    614         #    logging.info("\n".join(traceback.format_stack())) 
     622        #    logger.info("calculation waiting for another thread to complete") 
     623        #    logger.info("\n".join(traceback.format_stack())) 
    615624 
    616625        with calculation_lock: 
  • .gitignore

    r8a5f021 rc26897a  
    1111/doc/api/ 
    1212/doc/model/ 
    13 /doc/ref/models 
     13/doc/guide/models 
    1414.mplconfig 
    1515/pylint_violations.txt 
  • doc/conf.py

    r39674a0 r8ae8532  
    4242             ] 
    4343 
     44# Redirect mathjax to a different CDN 
     45mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML" 
     46 
    4447# Add any paths that contain templates here, relative to this directory. 
    4548templates_path = ['_templates'] 
  • doc/developer/calculator.rst

    re822c97 r870a2f4  
    11.. currentmodule:: sasmodels 
     2 
     3.. _Calculator_Interface: 
    24 
    35Calculator Interface 
     
    79model calculator which implements the polydispersity and magnetic SLD 
    810calculations.  There are three separate implementations of this layer, 
    9 *kernelcl.py* for OpenCL, which operates on a single Q value at a time, 
    10 *kerneldll.c* for the DLL, which loops over a vector of Q values, and 
    11 *kernelpy.py* for python models which operates on vector Q values. 
     11:mod:`kernelcl` for OpenCL, which operates on a single Q value at a time, 
     12:mod:`kerneldll` for the DLL, which loops over a vector of Q values, and 
     13:mod:`kernelpy` for python models which operates on vector Q values. 
    1214 
    1315Each implementation provides three different calls *Iq*, *Iqxy* and *Imagnetic* 
  • doc/developer/index.rst

    rb85be2d r2e66ef5  
    77   :maxdepth: 4 
    88 
     9   overview.rst 
    910   calculator.rst 
  • doc/genapi.py

    ra5b8477 r2e66ef5  
    22import os.path 
    33 
    4 MODULE_TEMPLATE=""".. Autogenerated by genmods.py 
     4MODULE_TEMPLATE = """.. Autogenerated by genmods.py 
    55 
    66****************************************************************************** 
     
    1919""" 
    2020 
    21 INDEX_TEMPLATE=""".. Autogenerated by genmods.py 
     21INDEX_TEMPLATE = """.. Autogenerated by genmods.py 
    2222 
    2323.. _api-index: 
     
    4646        os.makedirs(dir) 
    4747 
    48     for module,name in modules: 
    49         with open(os.path.join(dir,module+'.rst'), 'w') as f: 
     48    for module, name in modules: 
     49        with open(os.path.join(dir, module+'.rst'), 'w') as f: 
    5050            f.write(MODULE_TEMPLATE%locals()) 
    5151 
    52     rsts = "\n   ".join(module+'.rst' for module,name in modules) 
    53     with open(os.path.join(dir,'index.rst'),'w') as f: 
     52    rsts = "\n   ".join(module+'.rst' for module, name in modules) 
     53    with open(os.path.join(dir, 'index.rst'), 'w') as f: 
    5454        f.write(INDEX_TEMPLATE%locals()) 
    5555 
    5656 
    57 modules=[ 
    58     #('__init__', 'Top level namespace'), 
     57modules = [ 
     58    ('__init__', 'Sasmodels package'), 
    5959    #('alignment', 'GPU data alignment [unused]'), 
    6060    ('bumps_model', 'Bumps interface'), 
     61    ('compare_many', 'Batch compare models on different compute engines'), 
    6162    ('compare', 'Compare models on different compute engines'), 
    6263    ('convert', 'Sasview to sasmodel converter'), 
     
    6667    ('direct_model', 'Simple interface'), 
    6768    ('exception', 'Annotate exceptions'), 
    68     #('frozendict', 'Freeze a dictionary to make it immutable'), 
    6969    ('generate', 'Model parser'), 
    7070    ('kernel', 'Evaluator type definitions'), 
     
    7979    ('resolution', '1-D resolution functions'), 
    8080    ('resolution2d', '2-D resolution functions'), 
     81    ('rst2html', 'Convert doc strings the web pages'), 
    8182    ('sasview_model', 'Sasview interface'), 
    8283    ('sesans', 'SESANS calculation routines'), 
    83     #('transition', 'Model stepper for automatic model selection'), 
    8484    ('weights', 'Distribution functions'), 
    8585] 
    86 package='sasmodels' 
    87 package_name='Reference' 
     86package = 'sasmodels' 
     87package_name = 'Reference' 
    8888genfiles(package, package_name, modules) 
  • doc/gentoc.py

    r40a87fa r990d8df  
    1616    from sasmodels.modelinfo import ModelInfo 
    1717 
    18 TEMPLATE="""\ 
     18TEMPLATE = """\ 
    1919.. 
    2020    Generated from doc/gentoc.py -- DO NOT EDIT -- 
     
    3030""" 
    3131 
    32 MODEL_TOC_PATH = "ref/models" 
     32MODEL_TOC_PATH = "guide/models" 
    3333 
    3434def _make_category(category_name, label, title, parent=None): 
     
    6565        # assume model is in sasmodels/models/name.py, and ignore the full path 
    6666        model_name = basename(item)[:-3] 
    67         if model_name.startswith('_'): continue 
     67        if model_name.startswith('_'): 
     68            continue 
    6869        model_info = load_model_info(model_name) 
    6970        if model_info.category is None: 
    7071            print("Missing category for", item, file=sys.stderr) 
    7172        else: 
    72             category.setdefault(model_info.category,[]).append(model_name) 
     73            category.setdefault(model_info.category, []).append(model_name) 
    7374 
    7475    # Check category names 
    75     for k,v in category.items(): 
     76    for k, v in category.items(): 
    7677        if len(v) == 1: 
    77             print("Category %s contains only %s"%(k,v[0]), file=sys.stderr) 
     78            print("Category %s contains only %s"%(k, v[0]), file=sys.stderr) 
    7879 
    7980    # Generate category files for the table of contents. 
     
    8687    # alphabetical order before them. 
    8788 
    88     if not exists(MODEL_TOC_PATH): mkdir(MODEL_TOC_PATH) 
     89    if not exists(MODEL_TOC_PATH): 
     90        mkdir(MODEL_TOC_PATH) 
    8991    model_toc = _make_category( 
    90         'index',  'Models', 'Model Functions') 
     92        'index', 'Models', 'Model Functions') 
    9193    #shape_toc = _make_category( 
    9294    #    'shape',  'Shapes', 'Shape Functions', model_toc) 
    9395    free_toc = _make_category( 
    94         'shape-independent',  'Shape-independent', 
     96        'shape-independent', 'Shape-independent', 
    9597        'Shape-Independent Functions') 
    9698    struct_toc = _make_category( 
    97         'structure-factor',  'Structure-factor', 'Structure Factors') 
    98     custom_toc = _make_category( 
    99         'custom-models', 'Custom-models', 'Custom Models') 
     99        'structure-factor', 'Structure-factor', 'Structure Factors') 
     100    #custom_toc = _make_category( 
     101    #    'custom-models', 'Custom-models', 'Custom Models') 
    100102 
    101103    # remember to top level categories 
     
    105107        'shape-independent':free_toc, 
    106108        'structure-factor': struct_toc, 
    107         'custom': custom_toc, 
     109        #'custom': custom_toc, 
    108110        } 
    109111 
    110112    # Process the model lists 
    111     for k,v in sorted(category.items()): 
     113    for k, v in sorted(category.items()): 
    112114        if ':' in k: 
    113             cat,subcat = k.split(':') 
     115            cat, subcat = k.split(':') 
    114116            _maybe_make_category(cat, v, cat_files, model_toc) 
    115117            cat_file = cat_files[cat] 
    116             label = "-".join((cat,subcat)) 
     118            label = "-".join((cat, subcat)) 
    117119            filename = label 
    118             title = subcat.capitalize()+" Functions" 
     120            title = subcat.capitalize() + " Functions" 
    119121            sub_toc = _make_category(filename, label, title, cat_file) 
    120122            for model in sorted(v): 
     
    130132    _add_subcategory('shape-independent', model_toc) 
    131133    _add_subcategory('structure-factor', model_toc) 
    132     _add_subcategory('custom-models', model_toc) 
     134    #_add_subcategory('custom-models', model_toc) 
    133135 
    134136    # Close the top-level category files 
    135137    #model_toc.close() 
    136     for f in cat_files.values(): f.close() 
     138    for f in cat_files.values(): 
     139        f.close() 
    137140 
    138141 
  • doc/guide/index.rst

    rbb6f0f3 r2e66ef5  
    1 ********** 
    2 SAS Models 
    3 ********** 
     1**************** 
     2SAS Models Guide 
     3**************** 
    44 
    5 Small angle X-ray and Neutron (SAXS and SANS) scattering examines the 
    6 scattering patterns produced by a beam travelling through the sample 
    7 and scattering at low angles.  The scattering is computed as a function 
    8 of $q_x$ and $q_y$, which for a given beam wavelength corresponds to 
    9 particular scattering angles. Each pixel on the detector corresponds to 
    10 a different scattering angle. If the sample is unoriented, the scattering 
    11 pattern will appear as rings on the detector.  In this case, a circular 
    12 average can be taken with 1-dimension data at $q = \surd (q_x^2 + q_y^2)$ 
    13 compared to the orientationally averaged SAS scattering pattern. 
     5.. toctree:: 
     6   :numbered: 4 
     7   :maxdepth: 4 
    148 
    15 Models have certain features in common. 
    16  
    17 Every model has a *scale* and a *background*. 
    18  
    19 Talk about orientation, with diagrams for orientation so that we don't need 
    20 a link on every model page? 
    21  
    22 .. _orientation: 
    23  
    24 .. figure: img/orientation1.jpg 
    25  
    26     Orientation in 3D 
    27  
    28 .. figure: img/orientation2.jpg 
    29  
    30     Orientation cross sections 
    31  
    32 Talk about polydispersity. 
    33  
    34 Talk about magnetism, converting the magnetism help file to inline text here, 
    35 with links so that models can point back to it. 
    36  
    37 Need to talk about structure factors even though we don't have any 
    38 implemented yet. 
     9   intro.rst 
     10   install.rst 
     11   pd/polydispersity.rst 
     12   resolution.rst 
     13   magnetism/magnetism.rst 
     14   sesans/sans_to_sesans.rst 
     15   sesans/sesans_fitting.rst 
     16   plugin.rst 
     17   scripting.rst 
     18   refs.rst 
  • doc/guide/magnetism/magnetism.rst

    rdeb854f r990d8df  
    22 
    33Polarisation/Magnetic Scattering 
    4 ======================================================= 
     4================================ 
    55 
    6 In earlier versions of SasView magnetic scattering was implemented in just five  
    7 (2D) models 
    8  
    9 *  :ref:`sphere` 
    10 *  :ref:`core-shell-sphere` 
    11 *  :ref:`core-multi-shell` 
    12 *  :ref:`cylinder` 
    13 *  :ref:`parallelepiped` 
    14  
    15 From SasView 4.x it is implemented on most models in the 'shape' category. 
    16  
    17 In general, the scattering length density (SLD = $\beta$) in each region where the 
    18 SLD is uniform, is a combination of the nuclear and magnetic SLDs and, for polarised 
    19 neutrons, also depends on the spin states of the neutrons. 
     6Models which define a scattering length density parameter can be evaluated 
     7 as magnetic models. In general, the scattering length density (SLD = 
     8 $\beta$) in each region where the SLD is uniform, is a combination of the 
     9 nuclear and magnetic SLDs and, for polarised neutrons, also depends on the 
     10 spin states of the neutrons. 
    2011 
    2112For magnetic scattering, only the magnetization component $\mathbf{M_\perp}$ 
     
    9889.. note:: 
    9990    This help document was last changed by Steve King, 02May2015 
     91 
     92* Document History * 
     93 
     94| 2017-05-08 Paul Kienzle 
  • doc/guide/sesans/sesans_fitting.rst

    r3330bb4 r8ae8532  
    77=================== 
    88 
    9 .. note:: A proper installation of the developers setup of SasView (http://trac.sasview.org/wiki/AnacondaSetup) is a prerequisite for using these instructions. 
     9.. note:: 
     10 
     11    A proper installation of the developers setup of SasView 
     12    (http://trac.sasview.org/wiki/AnacondaSetup) is a prerequisite for 
     13    using these instructions. 
    1014 
    1115It is possible to fit SESANS measurements from the command line in Python. 
     
    1317Simple Fits 
    1418........... 
    15 In the folder sasmodels/example the file sesans_sphere_2micron.py gives an example of how to fit a shape to a measurement. 
     19In the folder sasmodels/example the file sesans_sphere_2micron.py gives 
     20an example of how to fit a shape to a measurement. 
    1621 
    1722The command:: 
     
    2328.. image:: sesans_img/SphereLineFitSasView.png 
    2429 
    25 All the parameters and names in sesans_sphere_2micron.py (shown below) can be adjusted to fit your own problem:: 
     30All the parameters and names in sesans_sphere_2micron.py (shown below) can 
     31be adjusted to fit your own problem:: 
    2632 
    2733  """ 
     
    6470  # Constraints 
    6571  # model.param_name = f(other params) 
    66   # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 
    67   # a custom parameter 
     72  # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius 
     73  # and scale are model functions and phi is a custom parameter 
    6874  model.scale = phi*(1-phi) 
    6975 
     
    7480Incorporating a Structure Factor 
    7581................................ 
    76 An example of how to also include a structure factor can be seen in the following example taken from Washington et al.,  
    77 *Soft Matter*\, (2014), 10, 3016 (dx.doi.org/10.1039/C3SM53027B). These are time-of-flight measurements, which is the  
    78 reason that not the polarisation is plotted, but the :math:`\frac{log(P/P_0)}{\lambda^2}` . The sample is a dispersion  
    79 of core-shell colloids at a high volume fraction with hard sphere interactions. 
     82An example of how to also include a structure factor can be seen in the 
     83following example taken from Washington et al., *Soft Matter*\, (2014), 10, 3016 
     84(dx.doi.org/10.1039/C3SM53027B). These are time-of-flight measurements, which 
     85is the reason that not the polarisation is plotted, but the 
     86:math:`\frac{log(P/P_0)}{\lambda^2}` . The sample is a dispersion of 
     87core-shell colloids at a high volume fraction with hard sphere interactions. 
    8088 
    8189The fit can be started by:: 
     
    8795.. image:: sesans_img/HardSphereLineFitSasView.png 
    8896 
    89 The code sesans_parameters_css-hs.py can then be used as a template for a fitting problem with a structure factor:: 
     97The code sesans_parameters_css-hs.py can then be used as a template for a 
     98fitting problem with a structure factor:: 
    9099 
    91100 """ 
     
    131140 # Constraints 
    132141 # model.param_name = f(other params) 
    133  # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 
    134  # a custom parameter 
     142 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius 
     143 # and scale are model functions and phi is a custom parameter 
    135144 model.scale = phi*(1-phi) 
    136145 model.volfraction = phi 
  • doc/index.rst

    r7bb290c r8ae8532  
    1 Introduction 
    2 ============ 
     1sasmodels 
     2========= 
     3Small angle X-ray and Neutron scattering (SAXS and SANS) examines the 
     4scattering patterns produced by a beam travelling through the sample 
     5and scattering at low angles.  The scattering is computed as a function 
     6of reciprocal space $q$, which arises from a combination of beam wavelength 
     7and scattering angles. Each pixel on the detector corresponds to 
     8a different scattering angle, and has a distinct $q_x$ and $q_y$. If the 
     9sample is unoriented, the scattering pattern will appear as rings on the 
     10detector.  In this case, a circular average can be taken with 1-dimension 
     11data at $q = \surd (q_x^2 + q_y^2)$ compared to the orientationally 
     12averaged SAS scattering pattern. 
     13 
    314The sasmodels package provides theory functions for small angle scattering 
    4 calculations. 
     15calculations for different shapes, including the effects of resolution, 
     16polydispersity and orientational dispersion. 
    517 
    618.. htmlonly:: 
     
    1527 
    1628   guide/index.rst 
     29   guide/models/index.rst 
    1730   developer/index.rst 
    18    ref/index.rst 
    19    ref/models/index.rst 
    2031   api/index.rst 
    2132 
     
    2839.. htmlonly:: 
    2940  * :ref:`search` 
    30  
    31  
    32  
    33  
    34    
    35  
  • example/model.py

    r1182da5 r2e66ef5  
    1717model = Model(kernel, 
    1818    scale=0.08, 
    19     r_polar=15, r_equatorial=800, 
     19    radius_polar=15, radius_equatorial=800, 
    2020    sld=.291, sld_solvent=7.105, 
    2121    background=0, 
    2222    theta=90, phi=0, 
    2323    theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3, 
    24     r_polar_pd=0.222296, r_polar_pd_n=1, r_polar_pd_nsigma=0, 
    25     r_equatorial_pd=.000128, r_equatorial_pd_n=1, r_equatorial_pd_nsigma=0, 
     24    radius_polar_pd=0.222296, radius_polar_pd_n=1, radius_polar_pd_nsigma=0, 
     25    radius_equatorial_pd=.000128, radius_equatorial_pd_n=1, radius_equatorial_pd_nsigma=0, 
    2626    phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, 
    2727    ) 
    2828 
    2929# SET THE FITTING PARAMETERS 
    30 model.r_polar.range(15, 1000) 
    31 model.r_equatorial.range(15, 1000) 
     30model.radius_polar.range(15, 1000) 
     31model.radius_equatorial.range(15, 1000) 
    3232model.theta_pd.range(0, 360) 
    3333model.background.range(0,1000) 
  • sasmodels/alignment.py

    r7ae2b7f r870a2f4  
    4242    view[:] = x 
    4343    return view 
    44  
  • sasmodels/core.py

    r650c6d2 r2e66ef5  
    117117    Load model info and build model. 
    118118 
    119     *model_name* is the name of the model as used by :func:`load_model_info`. 
    120     Additional keyword arguments are passed directly to :func:`build_model`. 
     119    *model_name* is the name of the model, or perhaps a model expression 
     120    such as sphere*hardsphere or sphere+cylinder. 
     121 
     122    *dtype* and *platform* are given by :func:`build_model`. 
    121123    """ 
    122124    return build_model(load_model_info(model_name), 
     
    128130    """ 
    129131    Load a model definition given the model name. 
     132 
     133    *model_name* is the name of the model, or perhaps a model expression 
     134    such as sphere*hardsphere or sphere+cylinder. 
    130135 
    131136    This returns a handle to the module defining the model.  This can be 
     
    227232 
    228233    Possible types include 'half', 'single', 'double' and 'quad'.  If the 
    229     type is 'fast', then this is equivalent to dtype 'single' with the 
    230     fast flag set to True. 
     234    type is 'fast', then this is equivalent to dtype 'single' but using 
     235    fast native functions rather than those with the precision level guaranteed 
     236    by the OpenCL standard. 
     237 
     238    Platform preference can be specfied ("ocl" vs "dll"), with the default 
     239    being OpenCL if it is availabe.  If the dtype name ends with '!' then 
     240    platform is forced to be DLL rather than OpenCL. 
     241 
     242    This routine ignores the preferences within the model definition.  This 
     243    is by design.  It allows us to test models in single precision even when 
     244    we have flagged them as requiring double precision so we can easily check 
     245    the performance on different platforms without having to change the model 
     246    definition. 
    231247    """ 
    232248    # Assign default platform, overriding ocl with dll if OpenCL is unavailable 
  • sasmodels/models/multilayer_vesicle.py

    r5d23de2 r870a2f4  
    7171  sufficiently fine grained in certain cases. Please report any such occurences 
    7272  to the SasView team. Generally, for the best possible experience: 
    73  * Start with the best possible guess 
    74  * Using a priori knowledge, hold as many parameters fixed as possible 
    75  * if N=1, tw (water thickness) must by definition be zero. Both N and tw should 
     73 
     74 - Start with the best possible guess 
     75 - Using a priori knowledge, hold as many parameters fixed as possible 
     76 - if N=1, tw (water thickness) must by definition be zero. Both N and tw should 
    7677   be fixed during fitting. 
    77  * If N>1, use constraints to keep N > 1 
    78  * Because N only really moves in integer steps, it may get "stuck" if the 
     78 - If N>1, use constraints to keep N > 1 
     79 - Because N only really moves in integer steps, it may get "stuck" if the 
    7980   optimizer step size is too small so care should be taken 
    8081   If you experience problems with this please contact the SasView team and let 
  • sasmodels/resolution.py

    rb32caab r990d8df  
    437437    .. math:: 
    438438 
    439          \log \Delta q = (\log q_n - log q_1) / (n - 1) 
     439         \log \Delta q = (\log q_n - \log q_1) / (n - 1) 
    440440 
    441441    From this we can compute the number of steps required to extend $q$ 
     
    451451 
    452452         n_\text{extend} = (n-1) (\log q_\text{max} - \log q_n) 
    453             / (\log q_n - log q_1) 
     453            / (\log q_n - \log q_1) 
    454454    """ 
    455455    q = np.sort(q) 
     
    459459        log_delta_q = log(10.) / points_per_decade 
    460460    if q_min < q[0]: 
    461         if q_min < 0: q_min = q[0]*MINIMUM_ABSOLUTE_Q 
     461        if q_min < 0: 
     462            q_min = q[0]*MINIMUM_ABSOLUTE_Q 
    462463        n_low = log_delta_q * (log(q[0])-log(q_min)) 
    463464        q_low = np.logspace(log10(q_min), log10(q[0]), np.ceil(n_low)+1)[:-1] 
  • sasmodels/rst2html.py

    rf2f5413 r870a2f4  
    3838    - mathml 
    3939    - mathjax 
    40     See `http://docutils.sourceforge.net/docs/user/config.html#math-output`_ 
     40    See `<http://docutils.sourceforge.net/docs/user/config.html#math-output>`_ 
    4141    for details. 
    4242 
     
    176176        from PyQt5.QtCore import QUrl 
    177177    except ImportError: 
    178         from PyQt4.QtWebkit import QWebView 
     178        from PyQt4.QtWebKit import QWebView 
    179179        from PyQt4.QtCore import QUrl 
    180180    helpView = QWebView() 
     
    204204        from PyQt5.QtCore import QUrl 
    205205    except ImportError: 
    206         from PyQt4.QtWebkit import QWebView 
     206        from PyQt4.QtWebKit import QWebView 
    207207        from PyQt4.QtCore import QUrl 
    208208    frame = QWebView() 
     
    211211    sys.exit(app.exec_()) 
    212212 
     213def can_use_qt(): 
     214    """ 
     215    Return True if QWebView exists. 
     216 
     217    Checks first in PyQt5 then in PyQt4 
     218    """ 
     219    try: 
     220        from PyQt5.QtWebKitWidgets import QWebView 
     221        return True 
     222    except ImportError: 
     223        try: 
     224            from PyQt4.QtWebKit import QWebView 
     225            return True 
     226        except ImportError: 
     227            return False 
     228 
    213229def view_help(filename, qt=False): 
    214230    import os 
    215     url="file:///"+os.path.abspath(filename).replace("\\","/") 
     231 
     232    if qt: 
     233        qt = can_use_qt() 
     234 
     235    url = "file:///"+os.path.abspath(filename).replace("\\", "/") 
    216236    if filename.endswith('.rst'): 
    217237        html = load_rst_as_html(filename) 
Note: See TracChangeset for help on using the changeset viewer.