source: sasmodels/sasmodels/list_pars.py @ 17bbadd

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 17bbadd was 17bbadd, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

refactor so all model defintion queries use model_info; better documentation of model_info structure; initial implementation of product model (broken)

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"""
2List all parameters used along with the models which use them.
3
4Usage:
5
6    python -m sasmodels.list_pars [-v]
7
8If '-v' is given, then list the models containing the parameter in
9addition to just the parameter name.
10"""
11from __future__ import print_function
12
13import sys
14
15from .core import load_model_info
16from .compare import MODELS, columnize
17
18def find_pars():
19    """
20    Find all parameters in all models.
21
22    Returns the reference table *{parameter: [model, model, ...]}*
23    """
24    partable = {}
25    for name in sorted(MODELS):
26        model_info = load_model_info(name)
27        for p in model_info['parameters']:
28            pname = p[0]
29            partable.setdefault(pname, [])
30            partable[pname].append(name)
31    return partable
32
33def list_pars(names_only=True):
34    """
35    Print all parameters in all models.
36
37    If *names_only* then only print the parameter name, not the models it
38    occurs in.
39    """
40    partable = find_pars()
41    if names_only:
42        print(columnize(list(sorted(partable.keys()))))
43    else:
44        for k, v in sorted(partable.items()):
45            print("%s: %s"%(k, ", ".join(v)))
46
47def main():
48    """
49    Program to list the parameters used across all models.
50    """
51    if len(sys.argv) == 2 and sys.argv[1] == '-v':
52        verbose = True
53    elif len(sys.argv) == 1:
54        verbose = False
55    else:
56        print(__doc__)
57        sys.exit(1)
58    list_pars(names_only=not verbose)
59
60if __name__ == "__main__":
61    main()
Note: See TracBrowser for help on using the repository browser.