core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change
on this file since d5b5b71 was
785cbec,
checked in by Paul Kienzle <pkienzle@…>, 8 years ago
|
doc fixes
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[a84a0ca] | 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 | |
---|
[785cbec] | 15 | from .core import load_model_info, list_models |
---|
| 16 | from .compare import columnize |
---|
[a84a0ca] | 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 = {} |
---|
[785cbec] | 25 | for name in list_models(): |
---|
[a84a0ca] | 26 | model_info = load_model_info(name) |
---|
[6d6508e] | 27 | for p in model_info.parameters.kernel_parameters: |
---|
[a84a0ca] | 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.