Commit 71542fc2c89ec54fa54a36d0a3f660dfb57f22fb

Authored by Jürgen Knödlseder
1 parent d2dfae6a

Test more branches of cslightcrv

Showing 1 changed file with 85 additions and 84 deletions
test/test_cslightcrv.py
@@ -43,8 +43,8 @@ class Test(gammalib.GPythonTestSuite): @@ -43,8 +43,8 @@ class Test(gammalib.GPythonTestSuite):
43 gammalib.GPythonTestSuite.__init__(self) 43 gammalib.GPythonTestSuite.__init__(self)
44 44
45 # Set members 45 # Set members
46 - self._events_name = "data/crab_events.fits"  
47 - self._model_name = "data/crab.xml" 46 + self._events_name = 'data/crab_events.fits'
  47 + self._model_name = 'data/crab.xml'
48 48
49 # Return 49 # Return
50 return 50 return
@@ -55,11 +55,11 @@ class Test(gammalib.GPythonTestSuite): @@ -55,11 +55,11 @@ class Test(gammalib.GPythonTestSuite):
55 Set all test functions. 55 Set all test functions.
56 """ 56 """
57 # Set test name 57 # Set test name
58 - self.name("cslightcrv") 58 + self.name('cslightcrv')
59 59
60 # Append tests 60 # Append tests
61 - self.append(self._test_cmd, "Test cslightcrv on command line")  
62 - self.append(self._test_python, "Test cslightcrv from Python") 61 + self.append(self._test_cmd, 'Test cslightcrv on command line')
  62 + self.append(self._test_python, 'Test cslightcrv from Python')
63 63
64 # Return 64 # Return
65 return 65 return
@@ -70,10 +70,10 @@ class Test(gammalib.GPythonTestSuite): @@ -70,10 +70,10 @@ class Test(gammalib.GPythonTestSuite):
70 Test cslightcrv on the command line. 70 Test cslightcrv on the command line.
71 """ 71 """
72 # Kluge to set the command (installed version has no README file) 72 # Kluge to set the command (installed version has no README file)
73 - if os.path.isfile("README"):  
74 - cslightcrv = "../cscripts/cslightcrv.py" 73 + if os.path.isfile('README'):
  74 + cslightcrv = '../cscripts/cslightcrv.py'
75 else: 75 else:
76 - cslightcrv = "cslightcrv" 76 + cslightcrv = 'cslightcrv'
77 77
78 # Setup cslightcrv command 78 # Setup cslightcrv command
79 cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \ 79 cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \
@@ -86,16 +86,16 @@ class Test(gammalib.GPythonTestSuite): @@ -86,16 +86,16 @@ class Test(gammalib.GPythonTestSuite):
86 86
87 # Execute cslightcrv, make sure we catch any exception 87 # Execute cslightcrv, make sure we catch any exception
88 try: 88 try:
89 - rc = os.system(cmd+" >/dev/null 2>&1") 89 + rc = os.system(cmd+' >/dev/null 2>&1')
90 except: 90 except:
91 pass 91 pass
92 92
93 # Check if execution was successful 93 # Check if execution was successful
94 self.test_assert(rc == 0, 94 self.test_assert(rc == 0,
95 - "Successful cslightcrv execution on command line") 95 + 'Successful cslightcrv execution on command line')
96 96
97 # Check light curve 97 # Check light curve
98 - self._check_light_curve("lightcurve_cmd1.fits", 3) 98 + self._check_light_curve('lightcurve_cmd1.fits', 3)
99 99
100 # Setup cslightcrv command 100 # Setup cslightcrv command
101 cmd = cslightcrv+' inobs="events_that_do_not_exist.fits"'+ \ 101 cmd = cslightcrv+' inobs="events_that_do_not_exist.fits"'+ \
@@ -108,13 +108,13 @@ class Test(gammalib.GPythonTestSuite): @@ -108,13 +108,13 @@ class Test(gammalib.GPythonTestSuite):
108 108
109 # Execute cslightcrv, make sure we catch any exception 109 # Execute cslightcrv, make sure we catch any exception
110 try: 110 try:
111 - rc = os.system(cmd+" >/dev/null 2>&1") 111 + rc = os.system(cmd+' >/dev/null 2>&1')
112 except: 112 except:
113 pass 113 pass
114 114
115 # Check if execution failed 115 # Check if execution failed
116 self.test_assert(rc != 0, 116 self.test_assert(rc != 0,
117 - "Failure of cslightcrv execution on command line") 117 + 'Failure of cslightcrv execution on command line')
118 118
119 # Return 119 # Return
120 return 120 return
@@ -126,21 +126,21 @@ class Test(gammalib.GPythonTestSuite): @@ -126,21 +126,21 @@ class Test(gammalib.GPythonTestSuite):
126 """ 126 """
127 # Set-up unbinned cslightcrv 127 # Set-up unbinned cslightcrv
128 lcrv = cscripts.cslightcrv() 128 lcrv = cscripts.cslightcrv()
129 - lcrv["inobs"] = self._events_name  
130 - lcrv["inmodel"] = self._model_name  
131 - lcrv["srcname"] = "Crab"  
132 - lcrv["caldb"] = "prod2"  
133 - lcrv["irf"] = "South_0.5h"  
134 - lcrv["tbinalg"] = "LIN"  
135 - lcrv["tmin"] = 51544.50  
136 - lcrv["tmax"] = 51544.53  
137 - lcrv["tbins"] = 3  
138 - lcrv["enumbins"] = 0  
139 - lcrv["emin"] = 0.1  
140 - lcrv["emax"] = 100.0  
141 - lcrv["outfile"] = "lightcurve_py1.fits"  
142 - lcrv["logfile"] = "cslightcrv_py1.log"  
143 - lcrv["chatter"] = 2 129 + lcrv['inobs'] = self._events_name
  130 + lcrv['inmodel'] = self._model_name
  131 + lcrv['srcname'] = 'Crab'
  132 + lcrv['caldb'] = 'prod2'
  133 + lcrv['irf'] = 'South_0.5h'
  134 + lcrv['tbinalg'] = 'LIN'
  135 + lcrv['tmin'] = 51544.50
  136 + lcrv['tmax'] = 51544.53
  137 + lcrv['tbins'] = 3
  138 + lcrv['enumbins'] = 0
  139 + lcrv['emin'] = 0.1
  140 + lcrv['emax'] = 100.0
  141 + lcrv['outfile'] = 'cslightcrv_py1.fits'
  142 + lcrv['logfile'] = 'cslightcrv_py1.log'
  143 + lcrv['chatter'] = 2
144 144
145 # Run cslightcrv script and save light curve 145 # Run cslightcrv script and save light curve
146 lcrv.logFileOpen() # Make sure we get a log file 146 lcrv.logFileOpen() # Make sure we get a log file
@@ -148,7 +148,7 @@ class Test(gammalib.GPythonTestSuite): @@ -148,7 +148,7 @@ class Test(gammalib.GPythonTestSuite):
148 lcrv.save() 148 lcrv.save()
149 149
150 # Check light curve 150 # Check light curve
151 - self._check_light_curve("lightcurve_py1.fits", 3) 151 + self._check_light_curve('cslightcrv_py1.fits', 3)
152 152
153 # Now use FILE as time bin algorithm. For this we need first to 153 # Now use FILE as time bin algorithm. For this we need first to
154 # create an ASCII file. We use now 6 time bins. The ASCII file 154 # create an ASCII file. We use now 6 time bins. The ASCII file
@@ -157,31 +157,32 @@ class Test(gammalib.GPythonTestSuite): @@ -157,31 +157,32 @@ class Test(gammalib.GPythonTestSuite):
157 tmin = 51544.50 157 tmin = 51544.50
158 tdelta = 0.01 158 tdelta = 0.01
159 for i in range(csv.nrows()): 159 for i in range(csv.nrows()):
160 - csv[i,0] = "%.5f" % (tmin + i * tdelta)  
161 - csv[i,1] = "%.5f" % (tmin + (i+1) * tdelta)  
162 - csv.save("lightcurve_py2.dat", " ", True) 160 + csv[i,0] = '%.5f' % (tmin + i * tdelta)
  161 + csv[i,1] = '%.5f' % (tmin + (i+1) * tdelta)
  162 + csv.save('cslightcrv_py2.dat', ' ', True)
163 163
164 # Set-up unbinned cslightcrv 164 # Set-up unbinned cslightcrv
165 lcrv = cscripts.cslightcrv() 165 lcrv = cscripts.cslightcrv()
166 - lcrv["inobs"] = self._events_name  
167 - lcrv["inmodel"] = self._model_name  
168 - lcrv["srcname"] = "Crab"  
169 - lcrv["caldb"] = "prod2"  
170 - lcrv["irf"] = "South_0.5h"  
171 - lcrv["tbinalg"] = "FILE"  
172 - lcrv["tbinfile"] = "lightcurve_py2.dat"  
173 - lcrv["enumbins"] = 0  
174 - lcrv["emin"] = 0.1  
175 - lcrv["emax"] = 100.0  
176 - lcrv["outfile"] = "lightcurve_py2.fits"  
177 - lcrv["logfile"] = "cslightcrv_py2.log"  
178 - lcrv["chatter"] = 3 166 + lcrv['inobs'] = self._events_name
  167 + lcrv['inmodel'] = self._model_name
  168 + lcrv['srcname'] = 'Crab'
  169 + lcrv['caldb'] = 'prod2'
  170 + lcrv['irf'] = 'South_0.5h'
  171 + lcrv['tbinalg'] = 'FILE'
  172 + lcrv['tbinfile'] = 'cslightcrv_py2.dat'
  173 + lcrv['enumbins'] = 0
  174 + lcrv['emin'] = 0.1
  175 + lcrv['emax'] = 100.0
  176 + lcrv['fix_bkg'] = True
  177 + lcrv['outfile'] = 'cslightcrv_py2.fits'
  178 + lcrv['logfile'] = 'cslightcrv_py2.log'
  179 + lcrv['chatter'] = 3
179 180
180 # Execute cslightcrv script 181 # Execute cslightcrv script
181 lcrv.execute() 182 lcrv.execute()
182 183
183 # Check light curve 184 # Check light curve
184 - self._check_light_curve("lightcurve_py2.fits", 2) 185 + self._check_light_curve('cslightcrv_py2.fits', 2)
185 186
186 # Now we setup an observation container on input. We attached the 187 # Now we setup an observation container on input. We attached the
187 # model to the observation container so that cslightcrv should 188 # model to the observation container so that cslightcrv should
@@ -194,53 +195,53 @@ class Test(gammalib.GPythonTestSuite): @@ -194,53 +195,53 @@ class Test(gammalib.GPythonTestSuite):
194 # Set-up unbinned cslightcrv from observation container. Now use 195 # Set-up unbinned cslightcrv from observation container. Now use
195 # the GTI algorithm so that we test all timing algorithms. 196 # the GTI algorithm so that we test all timing algorithms.
196 lcrv = cscripts.cslightcrv(obs) 197 lcrv = cscripts.cslightcrv(obs)
197 - lcrv["srcname"] = "Crab"  
198 - lcrv["caldb"] = "prod2"  
199 - lcrv["irf"] = "South_0.5h"  
200 - lcrv["tbinalg"] = "GTI"  
201 - lcrv["enumbins"] = 0  
202 - lcrv["emin"] = 0.1  
203 - lcrv["emax"] = 100.0  
204 - lcrv["outfile"] = "lightcurve_py3.fits"  
205 - lcrv["logfile"] = "cslightcrv_py3.log"  
206 - lcrv["chatter"] = 4 198 + lcrv['srcname'] = 'Crab'
  199 + lcrv['caldb'] = 'prod2'
  200 + lcrv['irf'] = 'South_0.5h'
  201 + lcrv['tbinalg'] = 'GTI'
  202 + lcrv['enumbins'] = 0
  203 + lcrv['emin'] = 0.1
  204 + lcrv['emax'] = 100.0
  205 + lcrv['outfile'] = 'cslightcrv_py3.fits'
  206 + lcrv['logfile'] = 'cslightcrv_py3.log'
  207 + lcrv['chatter'] = 4
207 208
208 # Execute cslightcrv script 209 # Execute cslightcrv script
209 lcrv.execute() 210 lcrv.execute()
210 211
211 # Check light curve 212 # Check light curve
212 - self._check_light_curve("lightcurve_py3.fits", 1) 213 + self._check_light_curve('cslightcrv_py3.fits', 1)
213 214
214 # Finally we set-up a binned cslightcrv 215 # Finally we set-up a binned cslightcrv
215 lcrv = cscripts.cslightcrv() 216 lcrv = cscripts.cslightcrv()
216 - lcrv["inobs"] = self._events_name  
217 - lcrv["inmodel"] = self._model_name  
218 - lcrv["srcname"] = "Crab"  
219 - lcrv["caldb"] = "prod2"  
220 - lcrv["irf"] = "South_0.5h"  
221 - lcrv["tbinalg"] = "LIN"  
222 - lcrv["tmin"] = 51544.50  
223 - lcrv["tmax"] = 51544.53  
224 - lcrv["tbins"] = 2  
225 - lcrv["emin"] = 0.1  
226 - lcrv["emax"] = 100.0  
227 - lcrv["enumbins"] = 10  
228 - lcrv["coordsys"] = "CEL"  
229 - lcrv["proj"] = "TAN"  
230 - lcrv["xref"] = 83.63  
231 - lcrv["yref"] = 22.01  
232 - lcrv["nxpix"] = 20  
233 - lcrv["nypix"] = 20  
234 - lcrv["binsz"] = 0.02  
235 - lcrv["outfile"] = "lightcurve_py4.fits"  
236 - lcrv["logfile"] = "cslightcrv_py4.log"  
237 - lcrv["chatter"] = 4 217 + lcrv['inobs'] = self._events_name
  218 + lcrv['inmodel'] = self._model_name
  219 + lcrv['srcname'] = 'Crab'
  220 + lcrv['caldb'] = 'prod2'
  221 + lcrv['irf'] = 'South_0.5h'
  222 + lcrv['tbinalg'] = 'LIN'
  223 + lcrv['tmin'] = 51544.50
  224 + lcrv['tmax'] = 51544.53
  225 + lcrv['tbins'] = 2
  226 + lcrv['emin'] = 0.1
  227 + lcrv['emax'] = 100.0
  228 + lcrv['enumbins'] = 10
  229 + lcrv['coordsys'] = 'CEL'
  230 + lcrv['proj'] = 'TAN'
  231 + lcrv['xref'] = 83.63
  232 + lcrv['yref'] = 22.01
  233 + lcrv['nxpix'] = 20
  234 + lcrv['nypix'] = 20
  235 + lcrv['binsz'] = 0.02
  236 + lcrv['outfile'] = 'cslightcrv_py4.fits'
  237 + lcrv['logfile'] = 'cslightcrv_py4.log'
  238 + lcrv['chatter'] = 4
238 239
239 # Execute cslightcrv script 240 # Execute cslightcrv script
240 lcrv.execute() 241 lcrv.execute()
241 242
242 # Check light curve 243 # Check light curve
243 - self._check_light_curve("lightcurve_py4.fits", 2) 244 + self._check_light_curve('cslightcrv_py4.fits', 2)
244 245
245 # Return 246 # Return
246 return 247 return
@@ -251,8 +252,8 @@ class Test(gammalib.GPythonTestSuite): @@ -251,8 +252,8 @@ class Test(gammalib.GPythonTestSuite):
251 Check light curve file. 252 Check light curve file.
252 """ 253 """
253 # Expected column names 254 # Expected column names
254 - cols = ["MJD", "e_MJD", "Prefactor", "e_Prefactor",  
255 - "Index", "e_Index", "TS", "UpperLimit"] 255 + cols = ['MJD', 'e_MJD', 'Prefactor', 'e_Prefactor',
  256 + 'Index', 'e_Index', 'TS', 'UpperLimit']
256 257
257 # Open FITS file 258 # Open FITS file
258 fits = gammalib.GFits(filename) 259 fits = gammalib.GFits(filename)
@@ -260,11 +261,11 @@ class Test(gammalib.GPythonTestSuite): @@ -260,11 +261,11 @@ class Test(gammalib.GPythonTestSuite):
260 # Check FITS file structure 261 # Check FITS file structure
261 self.test_value(fits.size(), 2, 262 self.test_value(fits.size(), 2,
262 'Check for 2 extensions in light curve FITS file') 263 'Check for 2 extensions in light curve FITS file')
263 - self.test_assert(fits.contains("LIGHTCURVE"), 264 + self.test_assert(fits.contains('LIGHTCURVE'),
264 'FITS file contains "LIGHTCURVE" extension') 265 'FITS file contains "LIGHTCURVE" extension')
265 266
266 # Get LIGHTCURVE table 267 # Get LIGHTCURVE table
267 - table = fits["LIGHTCURVE"] 268 + table = fits['LIGHTCURVE']
268 269
269 # Check FITS table structure 270 # Check FITS table structure
270 self.test_value(table.ncols(), len(cols), 271 self.test_value(table.ncols(), len(cols),