Changes in sasmodels/generate.py [cd3dba0:4eac427] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
rcd3dba0 r4eac427 99 99 The kernel module must set variables defining the kernel meta data: 100 100 101 *id* is an implicit variable formed from the filename. It will be 102 a valid python identifier, and will be used as the reference into 103 the html documentation, with '_' replaced by '-'. 104 105 *name* is the model name as displayed to the user. If it is missing, 106 it will be constructed from the id. 101 *name* is the model name 107 102 108 103 *title* is a short description of the model, suitable for a tool tip, … … 119 114 the kernel functions. 120 115 121 *category* is the default category for the model. Models in the122 *structure-factor* category do not have *scale* and *background*123 added.124 125 116 *source* is the list of C-99 source files that must be joined to 126 117 create the OpenCL kernel functions. The files defining the functions … … 143 134 this step is significant. 144 135 136 An *info* dictionary is constructed from the kernel meta data and 137 returned to the caller. 138 139 Additional fields can be defined in the kernel definition file that 140 are not needed for sas modelling. 141 145 142 *demo* is a dictionary of parameter=value defining a set of 146 parameters to use by default when *compare* is called. Any 147 parameter not set in *demo* gets the initial value from the 148 parameter list. *demo* is mostly needed to set the default 149 polydispersity values for tests. 143 parameters to use by default when *compare* is called. 150 144 151 145 *oldname* is the name of the model in sasview before sasmodels … … 155 149 of the new model against the values of the old model before 156 150 you are ready to add the new model to sasmodels. 157 158 159 An *info* dictionary is constructed from the kernel meta data and160 returned to the caller.161 151 162 152 The model evaluator, function call sequence consists of q inputs and the return vector, … … 200 190 201 191 import sys 202 from os.path import abspath, dirname, join as joinpath, exists , basename192 from os.path import abspath, dirname, join as joinpath, exists 203 193 import re 204 194 … … 243 233 # description and its parameter table. The remainder of the doc comes 244 234 # from the module docstring. 245 DOC_HEADER = """.. _%( id)s:246 247 %( name)s235 DOC_HEADER = """.. _%(name)s: 236 237 %(label)s 248 238 ======================================================= 249 239 … … 264 254 Generate the parameter table to include in the sphinx documentation. 265 255 """ 256 pars = COMMON_PARAMETERS + pars 266 257 column_widths = [ 267 258 max(len(p[0]) for p in pars), … … 532 523 } 533 524 534 def make_info(kernel_module): 535 """ 536 Interpret the model definition file, categorizing the parameters. 537 """ 525 def make(kernel_module): 526 """ 527 Build an OpenCL/ctypes function from the definition in *kernel_module*. 528 529 The module can be loaded with a normal python import statement if you 530 know which module you need, or with __import__('sasmodels.model.'+name) 531 if the name is in a string. 532 """ 533 # TODO: allow Iq and Iqxy to be defined in python 538 534 #print kernelfile 539 category = getattr(kernel_module, 'category', None)540 parameters = COMMON_PARAMETERS + kernel_module.parameters541 # Default the demo parameters to the starting values for the individual542 # parameters if an explicit demo parameter set has not been specified.543 demo_parameters = getattr(kernel_module, 'demo', None)544 if demo_parameters is None:545 demo_parameters = dict((p[0],p[2]) for p in parameters)546 filename = abspath(kernel_module.__file__)547 kernel_id = basename(filename)[:-3]548 name = getattr(kernel_module, 'name', None)549 if name is None:550 name = " ".join(w.capitalize() for w in kernel_id.split('_'))551 535 info = dict( 552 id = kernel_id, # string used to load the kernel553 536 filename=abspath(kernel_module.__file__), 554 name= name,537 name=kernel_module.name, 555 538 title=kernel_module.title, 556 539 description=kernel_module.description, 557 category=category, 558 parameters=parameters, 559 demo=demo_parameters, 540 parameters=COMMON_PARAMETERS + kernel_module.parameters, 560 541 source=getattr(kernel_module, 'source', []), 561 542 oldname=kernel_module.oldname, … … 569 550 info['partype'] = categorize_parameters(info['parameters']) 570 551 info['defaults'] = dict((p[0], p[2]) for p in info['parameters']) 571 return info 572 573 def make(kernel_module): 574 """ 575 Build an OpenCL/ctypes function from the definition in *kernel_module*. 576 577 The module can be loaded with a normal python import statement if you 578 know which module you need, or with __import__('sasmodels.model.'+name) 579 if the name is in a string. 580 """ 581 info = make_info(kernel_module) 552 582 553 # Assume if one part of the kernel is python then all parts are. 583 554 source = make_model(info) if not callable(info['Iq']) else None … … 588 559 Return the documentation for the model. 589 560 """ 590 info = make_info(kernel_module) 591 subst = dict(id=info['id'].replace('_', '-'), 592 name=info['name'], 593 title=info['title'], 594 parameters=make_partable(info['parameters']), 561 subst = dict(name=kernel_module.name.replace('_', '-'), 562 label=" ".join(kernel_module.name.split('_')).capitalize(), 563 title=kernel_module.title, 564 parameters=make_partable(kernel_module.parameters), 595 565 docs=kernel_module.__doc__) 596 566 return DOC_HEADER % subst
Note: See TracChangeset
for help on using the changeset viewer.