source: sasmodels/sasmodels/list_pars.py @ 5c962df

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

delint

  • Property mode set to 100644
File size: 1.5 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_definition
16from .generate import make_info
17from .compare import MODELS, columnize
18
19def find_pars():
20    """
21    Find all parameters in all models.
22
23    Returns the reference table *{parameter: [model, model, ...]}*
24    """
25    partable = {}
26    for name in sorted(MODELS):
27        definition = load_model_definition(name)
28        info = make_info(definition)
29        for p in info['parameters']:
30            pname = p[0]
31            partable.setdefault(pname, [])
32            partable[pname].append(name)
33    return partable
34
35def list_pars(names_only=True):
36    """
37    Print all parameters in all models.
38
39    If *names_only* then only print the parameter name, not the models it
40    occurs in.
41    """
42    partable = find_pars()
43    if names_only:
44        print(columnize(list(sorted(partable.keys()))))
45    else:
46        for k, v in sorted(partable.items()):
47            print("%s: %s"%(k, ", ".join(v)))
48
49def main():
50    """
51    Program to list the parameters used across all models.
52    """
53    if len(sys.argv) == 2 and sys.argv[1] == '-v':
54        verbose = True
55    elif len(sys.argv) == 1:
56        verbose = False
57    else:
58        print(__doc__)
59        sys.exit(1)
60    list_pars(names_only=not verbose)
61
62if __name__ == "__main__":
63    main()
Note: See TracBrowser for help on using the repository browser.