source:
sasmodels/sasmodels/list_pars.py
@
dedcf34
Last change on this file since dedcf34 was 3330bb4, checked in by ajj, 7 years ago | |
---|---|
|
|
File size: 1.4 KB |
Line | |
---|---|
1 | """ |
2 | List all parameters used along with the models which use them. |
3 | |
4 | Usage: |
5 | |
6 | python -m sasmodels.list_pars [-v] |
7 | |
8 | If '-v' is given, then list the models containing the parameter in |
9 | addition to just the parameter name. |
10 | """ |
11 | from __future__ import print_function |
12 | |
13 | import sys |
14 | |
15 | from .core import load_model_info, list_models |
16 | from .compare import columnize |
17 | |
18 | def 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 | |
32 | def 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 | |
46 | def 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 | |
59 | if __name__ == "__main__": |
60 | main() |
Note: See TracBrowser
for help on using the repository browser.