Commit 8c7c388f0be094ba524ba9fff5a0a4c6dc47c765
1 parent
7130da33
add optional parameters
Showing
1 changed file
with
47 additions
and
12 deletions
examples/make_ts_distributions.py
| @@ -98,20 +98,54 @@ if __name__ == '__main__': | @@ -98,20 +98,54 @@ if __name__ == '__main__': | ||
| 98 | Create TS distribution in a number of energy bands. | 98 | Create TS distribution in a number of energy bands. |
| 99 | """ | 99 | """ |
| 100 | # Get input arguments | 100 | # Get input arguments |
| 101 | - usage = "make_ts_distributions ntrials [max_threads]" | ||
| 102 | - if len(sys.argv) < 2 or len(sys.argv) > 3: | 101 | + usage = "make_ts_distributions [-n ntrials] [-e enumbins] [-m max_threads]" |
| 102 | + if len(sys.argv) < 1: | ||
| 103 | print usage | 103 | print usage |
| 104 | sys.exit() | 104 | sys.exit() |
| 105 | 105 | ||
| 106 | - # Set number of trials | ||
| 107 | - ntrials = int(sys.argv[1]) | ||
| 108 | - | ||
| 109 | - # Set maximum number of threads (default: 1) | ||
| 110 | - if len(sys.argv) == 3: | ||
| 111 | - max_threads = int(sys.argv[2]) | ||
| 112 | - else: | ||
| 113 | - max_threads = 1 | ||
| 114 | - | 106 | + # Set default parameters |
| 107 | + ntrials = 100 | ||
| 108 | + enumbins = 0 | ||
| 109 | + duration = 1800000.0 | ||
| 110 | + max_threads = 1 | ||
| 111 | + | ||
| 112 | + # Parameter dictionnary | ||
| 113 | + pars = [{'option': '-n', 'value': ntrials}, \ | ||
| 114 | + {'option': '-e', 'value': enumbins}, \ | ||
| 115 | + {'option': '-d', 'value': duration}, \ | ||
| 116 | + {'option': '-m', 'value': max_threads}] | ||
| 117 | + | ||
| 118 | + # Gather parameters from command line | ||
| 119 | + i = 1 | ||
| 120 | + while i < len(sys.argv): | ||
| 121 | + | ||
| 122 | + # Search for options | ||
| 123 | + for par in pars: | ||
| 124 | + if sys.argv[i] == par['option']: | ||
| 125 | + if len(sys.argv) > i+1: | ||
| 126 | + i += 1 | ||
| 127 | + try: | ||
| 128 | + par['value'] = int(sys.argv[i]) | ||
| 129 | + except: | ||
| 130 | + print usage | ||
| 131 | + sys.exit() | ||
| 132 | + else: | ||
| 133 | + print usage | ||
| 134 | + sys.exit() | ||
| 135 | + | ||
| 136 | + # Next item | ||
| 137 | + i += 1 | ||
| 138 | + | ||
| 139 | + # Recover parameters | ||
| 140 | + ntrials = pars[0]['value'] | ||
| 141 | + enumbins = pars[1]['value'] | ||
| 142 | + duration = pars[2]['value'] | ||
| 143 | + max_threads = pars[3]['value'] | ||
| 144 | + #print ntrials | ||
| 145 | + #print enumbins | ||
| 146 | + #print duration | ||
| 147 | + #print max_threads | ||
| 148 | + | ||
| 115 | # Loop over energy bands. The energy bands are those that are also | 149 | # Loop over energy bands. The energy bands are those that are also |
| 116 | # used for sensitivity computation. | 150 | # used for sensitivity computation. |
| 117 | for ieng in range(21): | 151 | for ieng in range(21): |
| @@ -135,7 +169,8 @@ if __name__ == '__main__': | @@ -135,7 +169,8 @@ if __name__ == '__main__': | ||
| 135 | 169 | ||
| 136 | # Set arguments | 170 | # Set arguments |
| 137 | args = (loge, emin, emax) | 171 | args = (loge, emin, emax) |
| 138 | - kwargs = {'ntrials': ntrials} | 172 | + kwargs = {'ntrials': ntrials, 'enumbins': enumbins, \ |
| 173 | + 'duration': duration} | ||
| 139 | 174 | ||
| 140 | # Generate pull distribution | 175 | # Generate pull distribution |
| 141 | p = processing.Process(target=create_ts, args=args, kwargs=kwargs) | 176 | p = processing.Process(target=create_ts, args=args, kwargs=kwargs) |