source: sasmodels/sasmodels/list_pars.py @ 9acade6

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

doc fixes

  • 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_info, list_models
16from .compare import 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 list_models():
26        model_info = load_model_info(name)
27        for p in model_info.parameters.kernel_parameters:
28            partable.setdefault(p.name, [])
29            partable[p.name].append(name)
30    return partable
31
32def list_pars(names_only=True):
33    """
34    Print all parameters in all models.
35
36    If *names_only* then only print the parameter name, not the models it
37    occurs in.
38    """
39    partable = find_pars()
40    if names_only:
41        print(columnize(list(sorted(partable.keys()))))
42    else:
43        for k, v in sorted(partable.items()):
44            print("%s: %s"%(k, ", ".join(v)))
45
46def main():
47    """
48    Program to list the parameters used across all models.
49    """
50    if len(sys.argv) == 2 and sys.argv[1] == '-v':
51        verbose = True
52    elif len(sys.argv) == 1:
53        verbose = False
54    else:
55        print(__doc__)
56        sys.exit(1)
57    list_pars(names_only=not verbose)
58
59if __name__ == "__main__":
60    main()
Note: See TracBrowser for help on using the repository browser.