source: sasmodels/sasmodels/list_pars.py @ b297ba9

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since b297ba9 was b297ba9, checked in by Paul Kienzle <pkienzle@…>, 7 months ago

lint

  • Property mode set to 100644
File size: 1.9 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 argparse
14
15from .core import load_model_info, list_models
16from .compare import columnize
17
18def find_pars(kind=None):
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            if kind is None or p.type == kind:
29                partable.setdefault(p.name, [])
30                partable[p.name].append(name)
31    return partable
32
33def list_pars(names_only=True, kind=None):
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(kind)
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    parser = argparse.ArgumentParser(
52        description="Find all parameters in all models",
53        )
54    parser.add_argument(
55        '-v', '--verbose',
56        action='store_true',
57        help="list models which use this argument")
58    parser.add_argument(
59        'kind', default="any", nargs='?',
60        metavar="volume|orientation|sld|none|any",
61        choices=['volume', 'orientation', 'sld', None, 'any'],
62        type=lambda v: None if v == 'any' else None if v == 'none' else v,
63        help="only list arguments of the given kind")
64    args = parser.parse_args()
65
66    list_pars(names_only=not args.verbose, kind=args.kind)
67
68if __name__ == "__main__":
69    main()
Note: See TracBrowser for help on using the repository browser.