source: sasmodels/sasmodels/list_pars.py @ 2d81cfe

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 2d81cfe was 2d81cfe, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

lint

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[3330bb4]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
[72be531]13import argparse
[3330bb4]14
15from .core import load_model_info, list_models
16from .compare import columnize
17
[72be531]18def find_pars(type=None):
[3330bb4]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:
[72be531]28            if type is None or p.type == type:
29                partable.setdefault(p.name, [])
30                partable[p.name].append(name)
[3330bb4]31    return partable
32
[72be531]33def list_pars(names_only=True, type=None):
[3330bb4]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    """
[72be531]40    partable = find_pars(type)
[3330bb4]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    """
[72be531]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        'type', 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 '' if v == 'none' else v,
63        help="only list arguments of the given type")
64    args = parser.parse_args()
65
66    list_pars(names_only=not args.verbose, type=args.type)
[3330bb4]67
68if __name__ == "__main__":
69    main()
Note: See TracBrowser for help on using the repository browser.