Commit b0c53a445ba3edfbcb73d324692f56936698b429

Authored by knodlseder
1 parent cbd6ed20

add ntrials as parameter

examples/make_ts_distributions.py
@@ -46,7 +46,7 @@ except: @@ -46,7 +46,7 @@ except:
46 # ====================== # 46 # ====================== #
47 # Create TS distribution # 47 # Create TS distribution #
48 # ====================== # 48 # ====================== #
49 -def create_ts(loge, emin, emax, ntrials=3, duration=180000.0, \ 49 +def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, \
50 enumbins=0, log=False): 50 enumbins=0, log=False):
51 """ 51 """
52 Create TS distribution. 52 Create TS distribution.
@@ -98,14 +98,17 @@ if __name__ == '__main__': @@ -98,14 +98,17 @@ 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 [max_threads]"  
102 - if len(sys.argv) < 1 or len(sys.argv) > 2: 101 + usage = "make_ts_distributions ntrials [max_threads]"
  102 + if len(sys.argv) < 2 or len(sys.argv) > 3:
103 print usage 103 print usage
104 sys.exit() 104 sys.exit()
  105 +
  106 + # Set number of trials
  107 + ntrials = int(sys.argv[1])
105 108
106 # Set maximum number of threads (default: 1) 109 # Set maximum number of threads (default: 1)
107 - if len(sys.argv) == 2:  
108 - max_threads = int(sys.argv[1]) 110 + if len(sys.argv) == 3:
  111 + max_threads = int(sys.argv[2])
109 else: 112 else:
110 max_threads = 1 113 max_threads = 1
111 114
@@ -118,17 +121,21 @@ if __name__ == &#39;__main__&#39;: @@ -118,17 +121,21 @@ if __name__ == &#39;__main__&#39;:
118 emean = pow(10.0, loge) 121 emean = pow(10.0, loge)
119 emin = pow(10.0, loge-0.1) 122 emin = pow(10.0, loge-0.1)
120 emax = pow(10.0, loge+0.1) 123 emax = pow(10.0, loge+0.1)
  124 + if loge < 0:
  125 + loge = "m"+str(abs(loge))
  126 + else:
  127 + loge = "p"+str(abs(loge))
121 128
122 # Processing support? 129 # Processing support?
123 if has_processing: 130 if has_processing:
124 131
125 # Wait until one thread has finished 132 # Wait until one thread has finished
126 while len(processing.activeChildren()) >= max_threads: 133 while len(processing.activeChildren()) >= max_threads:
127 - time.sleep(60) 134 + time.sleep(10)
128 135
129 # Set arguments 136 # Set arguments
130 args = (loge, emin, emax) 137 args = (loge, emin, emax)
131 - kwargs = {} 138 + kwargs = {'ntrials': ntrials}
132 139
133 # Generate pull distribution 140 # Generate pull distribution
134 p = processing.Process(target=create_ts, args=args, kwargs=kwargs) 141 p = processing.Process(target=create_ts, args=args, kwargs=kwargs)
@@ -147,4 +154,4 @@ if __name__ == &#39;__main__&#39;: @@ -147,4 +154,4 @@ if __name__ == &#39;__main__&#39;:
147 154
148 # Wait until all threads finished 155 # Wait until all threads finished
149 while len(processing.activeChildren()) > 0: 156 while len(processing.activeChildren()) > 0:
150 - time.sleep(60) 157 + time.sleep(10)