[1d4017a] | 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 | """ |
---|
[5c962df] | 11 | from __future__ import print_function |
---|
| 12 | |
---|
[1d4017a] | 13 | import sys |
---|
| 14 | |
---|
| 15 | from .core import load_model_definition |
---|
| 16 | from .generate import make_info |
---|
| 17 | from .compare import MODELS, columnize |
---|
| 18 | |
---|
| 19 | def find_pars(): |
---|
[5c962df] | 20 | """ |
---|
| 21 | Find all parameters in all models. |
---|
| 22 | |
---|
| 23 | Returns the reference table *{parameter: [model, model, ...]}* |
---|
| 24 | """ |
---|
[1d4017a] | 25 | partable = {} |
---|
| 26 | for name in sorted(MODELS): |
---|
| 27 | definition = load_model_definition(name) |
---|
| 28 | info = make_info(definition) |
---|
| 29 | for p in info['parameters']: |
---|
| 30 | pname = p[0] |
---|
| 31 | partable.setdefault(pname, []) |
---|
| 32 | partable[pname].append(name) |
---|
| 33 | return partable |
---|
| 34 | |
---|
| 35 | def list_pars(names_only=True): |
---|
[5c962df] | 36 | """ |
---|
| 37 | Print all parameters in all models. |
---|
| 38 | |
---|
| 39 | If *names_only* then only print the parameter name, not the models it |
---|
| 40 | occurs in. |
---|
| 41 | """ |
---|
[1d4017a] | 42 | partable = find_pars() |
---|
| 43 | if names_only: |
---|
| 44 | print(columnize(list(sorted(partable.keys())))) |
---|
| 45 | else: |
---|
[823e620] | 46 | for k, v in sorted(partable.items()): |
---|
[1d4017a] | 47 | print("%s: %s"%(k, ", ".join(v))) |
---|
| 48 | |
---|
| 49 | def main(): |
---|
[5c962df] | 50 | """ |
---|
| 51 | Program to list the parameters used across all models. |
---|
| 52 | """ |
---|
[1d4017a] | 53 | if len(sys.argv) == 2 and sys.argv[1] == '-v': |
---|
| 54 | verbose = True |
---|
| 55 | elif len(sys.argv) == 1: |
---|
| 56 | verbose = False |
---|
| 57 | else: |
---|
| 58 | print(__doc__) |
---|
| 59 | sys.exit(1) |
---|
| 60 | list_pars(names_only=not verbose) |
---|
| 61 | |
---|
| 62 | if __name__ == "__main__": |
---|
[5c962df] | 63 | main() |
---|