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 43 gammalib.GPythonTestSuite.__init__(self)
44 44  
45 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 49 # Return
50 50 return
... ... @@ -55,11 +55,11 @@ class Test(gammalib.GPythonTestSuite):
55 55 Set all test functions.
56 56 """
57 57 # Set test name
58   - self.name("cslightcrv")
  58 + self.name('cslightcrv')
59 59  
60 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 64 # Return
65 65 return
... ... @@ -70,10 +70,10 @@ class Test(gammalib.GPythonTestSuite):
70 70 Test cslightcrv on the command line.
71 71 """
72 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 75 else:
76   - cslightcrv = "cslightcrv"
  76 + cslightcrv = 'cslightcrv'
77 77  
78 78 # Setup cslightcrv command
79 79 cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \
... ... @@ -86,16 +86,16 @@ class Test(gammalib.GPythonTestSuite):
86 86  
87 87 # Execute cslightcrv, make sure we catch any exception
88 88 try:
89   - rc = os.system(cmd+" >/dev/null 2>&1")
  89 + rc = os.system(cmd+' >/dev/null 2>&1')
90 90 except:
91 91 pass
92 92  
93 93 # Check if execution was successful
94 94 self.test_assert(rc == 0,
95   - "Successful cslightcrv execution on command line")
  95 + 'Successful cslightcrv execution on command line')
96 96  
97 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 100 # Setup cslightcrv command
101 101 cmd = cslightcrv+' inobs="events_that_do_not_exist.fits"'+ \
... ... @@ -108,13 +108,13 @@ class Test(gammalib.GPythonTestSuite):
108 108  
109 109 # Execute cslightcrv, make sure we catch any exception
110 110 try:
111   - rc = os.system(cmd+" >/dev/null 2>&1")
  111 + rc = os.system(cmd+' >/dev/null 2>&1')
112 112 except:
113 113 pass
114 114  
115 115 # Check if execution failed
116 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 119 # Return
120 120 return
... ... @@ -126,21 +126,21 @@ class Test(gammalib.GPythonTestSuite):
126 126 """
127 127 # Set-up unbinned cslightcrv
128 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 145 # Run cslightcrv script and save light curve
146 146 lcrv.logFileOpen() # Make sure we get a log file
... ... @@ -148,7 +148,7 @@ class Test(gammalib.GPythonTestSuite):
148 148 lcrv.save()
149 149  
150 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 153 # Now use FILE as time bin algorithm. For this we need first to
154 154 # create an ASCII file. We use now 6 time bins. The ASCII file
... ... @@ -157,31 +157,32 @@ class Test(gammalib.GPythonTestSuite):
157 157 tmin = 51544.50
158 158 tdelta = 0.01
159 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 164 # Set-up unbinned cslightcrv
165 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 181 # Execute cslightcrv script
181 182 lcrv.execute()
182 183  
183 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 187 # Now we setup an observation container on input. We attached the
187 188 # model to the observation container so that cslightcrv should
... ... @@ -194,53 +195,53 @@ class Test(gammalib.GPythonTestSuite):
194 195 # Set-up unbinned cslightcrv from observation container. Now use
195 196 # the GTI algorithm so that we test all timing algorithms.
196 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 209 # Execute cslightcrv script
209 210 lcrv.execute()
210 211  
211 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 215 # Finally we set-up a binned cslightcrv
215 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 240 # Execute cslightcrv script
240 241 lcrv.execute()
241 242  
242 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 246 # Return
246 247 return
... ... @@ -251,8 +252,8 @@ class Test(gammalib.GPythonTestSuite):
251 252 Check light curve file.
252 253 """
253 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 258 # Open FITS file
258 259 fits = gammalib.GFits(filename)
... ... @@ -260,11 +261,11 @@ class Test(gammalib.GPythonTestSuite):
260 261 # Check FITS file structure
261 262 self.test_value(fits.size(), 2,
262 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 265 'FITS file contains "LIGHTCURVE" extension')
265 266  
266 267 # Get LIGHTCURVE table
267   - table = fits["LIGHTCURVE"]
  268 + table = fits['LIGHTCURVE']
268 269  
269 270 # Check FITS table structure
270 271 self.test_value(table.ncols(), len(cols),
... ...