Changeset fcd7bbd in sasmodels for sasmodels/generate.py
- Timestamp:
- Mar 16, 2016 9:27:13 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 70bbb74
- Parents:
- 63776d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
r2f0c07d rfcd7bbd 80 80 is selected, or when an initial value is not otherwise specified. 81 81 82 [*lb*, *ub*] are the hard limits on the parameter value, used to limit83 the polydispersity density function. In the fit, the parameter limits82 *limits = [lb, ub]* are the hard limits on the parameter value, used to 83 limit the polydispersity density function. In the fit, the parameter limits 84 84 given to the fit are the limits on the central value of the parameter. 85 85 If there is polydispersity, it will evaluate parameter values outside … … 216 216 import re 217 217 import string 218 from collections import namedtuple 218 219 219 220 import numpy as np 221 222 PARAMETER_FIELDS = ['name', 'units', 'default', 'limits', 'type', 'description'] 223 Parameter = namedtuple('Parameter', PARAMETER_FIELDS) 220 224 221 225 #TODO: determine which functions are useful outside of generate … … 293 297 """ 294 298 column_widths = [ 295 max(len(p [0]) for p in pars),296 max(len(p [-1]) for p in pars),297 max(len(format_units(p [1])) for p in pars),299 max(len(p.name) for p in pars), 300 max(len(p.description) for p in pars), 301 max(len(format_units(p.units)) for p in pars), 298 302 PARTABLE_VALUE_WIDTH, 299 303 ] … … 310 314 for p in pars: 311 315 lines.append(" ".join([ 312 "%-*s" % (column_widths[0], p [0]),313 "%-*s" % (column_widths[1], p [-1]),314 "%-*s" % (column_widths[2], format_units(p [1])),315 "%*g" % (column_widths[3], p [2]),316 "%-*s" % (column_widths[0], p.name), 317 "%-*s" % (column_widths[1], p.description), 318 "%-*s" % (column_widths[2], format_units(p.units)), 319 "%*g" % (column_widths[3], p.default), 316 320 ])) 317 321 lines.append(sep) … … 469 473 fixed_2d = partype['fixed-1d'] 470 474 471 iq_parameters = [p [0]475 iq_parameters = [p.name 472 476 for p in model_info['parameters'][2:] # skip scale, background 473 if p [0]in set(fixed_1d + pd_1d)]474 iqxy_parameters = [p [0]477 if p.name in set(fixed_1d + pd_1d)] 478 iqxy_parameters = [p.name 475 479 for p in model_info['parameters'][2:] # skip scale, background 476 if p [0]in set(fixed_2d + pd_2d)]477 volume_parameters = [p [0]480 if p.name in set(fixed_2d + pd_2d)] 481 volume_parameters = [p.name 478 482 for p in model_info['parameters'] 479 if p [4]== 'volume']483 if p.type == 'volume'] 480 484 481 485 # Fill in defintions for volume parameters … … 606 610 607 611 for p in pars: 608 name, ptype = p[0], p[4] 609 if ptype == 'volume': 610 partype['pd-1d'].append(name) 611 partype['pd-2d'].append(name) 612 partype['pd-rel'].add(name) 613 elif ptype == 'magnetic': 614 partype['fixed-2d'].append(name) 615 elif ptype == 'orientation': 616 partype['pd-2d'].append(name) 617 elif ptype == '': 618 partype['fixed-1d'].append(name) 619 partype['fixed-2d'].append(name) 612 if p.type == 'volume': 613 partype['pd-1d'].append(p.name) 614 partype['pd-2d'].append(p.name) 615 partype['pd-rel'].add(p.name) 616 elif p.type == 'magnetic': 617 partype['fixed-2d'].append(p.name) 618 elif p.type == 'orientation': 619 partype['pd-2d'].append(p.name) 620 elif p.type == '': 621 partype['fixed-1d'].append(p.name) 622 partype['fixed-2d'].append(p.name) 620 623 else: 621 raise ValueError("unknown parameter type %r" % p type)622 partype[p type].append(name)624 raise ValueError("unknown parameter type %r" % p.type) 625 partype[p.type].append(p.name) 623 626 624 627 return partype … … 628 631 Process parameter block, precalculating parameter details. 629 632 """ 633 # convert parameters into named tuples 634 pars = [Parameter(*p) for p in model_info['parameters']] 630 635 # Fill in the derived attributes 631 partype = categorize_parameters(model_info['parameters']) 632 model_info['limits'] = dict((p[0], p[3]) for p in model_info['parameters']) 636 model_info['parameters'] = pars 637 partype = categorize_parameters(pars) 638 model_info['limits'] = dict((p.name, p.limits) for p in pars) 633 639 model_info['partype'] = partype 634 model_info['defaults'] = dict((p [0], p[2]) for p in model_info['parameters'])640 model_info['defaults'] = dict((p.name, p.default) for p in pars) 635 641 if model_info.get('demo', None) is None: 636 642 model_info['demo'] = model_info['defaults'] … … 649 655 * *id* is the id of the kernel 650 656 * *name* is the display name of the kernel 657 * *filename* is the full path to the module defining the file (if any) 651 658 * *title* is a short description of the kernel 652 659 * *description* is a long description of the kernel (this doesn't seem
Note: See TracChangeset
for help on using the changeset viewer.