Commit 474ea1c6fc9693b8ea927165eaa51ad2f66f9098

Authored by Luigi Tibaldo
1 parent 2aab75b7

added test script

cscripts/obsutils.py
@@ -808,6 +808,9 @@ def get_onoff_obs(cls, obs): @@ -808,6 +808,9 @@ def get_onoff_obs(cls, obs):
808 phagen['etruemin'] = cls['etruemin'].real() 808 phagen['etruemin'] = cls['etruemin'].real()
809 phagen['etruemax'] = cls['etruemax'].real() 809 phagen['etruemax'] = cls['etruemax'].real()
810 phagen['etruebins'] = cls['etruebins'].integer() 810 phagen['etruebins'] = cls['etruebins'].integer()
  811 + phagen['chatter'] = cls['chatter'].integer()
  812 + phagen['clobber'] = cls['clobber'].boolean()
  813 + phagen['debug'] = cls['debug'].boolean()
811 phagen.run() 814 phagen.run()
812 815
813 onoff_obs = phagen.obs().copy() 816 onoff_obs = phagen.obs().copy()
test/test_cslightcrv.py
@@ -42,6 +42,9 @@ class Test(test): @@ -42,6 +42,9 @@ class Test(test):
42 # Call base class constructor 42 # Call base class constructor
43 test.__init__(self) 43 test.__init__(self)
44 44
  45 + # Add off-axis events for classical analysis
  46 + self._myevents1 = self._datadir + '/crab_offaxis1.fits'
  47 +
45 # Return 48 # Return
46 return 49 return
47 50
@@ -73,7 +76,7 @@ class Test(test): @@ -73,7 +76,7 @@ class Test(test):
73 ' inmodel="'+self._model+'" srcname="Crab"'+ \ 76 ' inmodel="'+self._model+'" srcname="Crab"'+ \
74 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ 77 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
75 ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \ 78 ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \
76 - ' tbins=3 enumbins=0 emin=0.1 emax=100.0'+ \ 79 + ' tbins=3 method="CUBE" enumbins=0 emin=0.1 emax=100.0'+ \
77 ' outfile="lightcurve_cmd1.fits"'+ \ 80 ' outfile="lightcurve_cmd1.fits"'+ \
78 ' logfile="cslightcrv_cmd1.log" chatter=1' 81 ' logfile="cslightcrv_cmd1.log" chatter=1'
79 82
@@ -93,7 +96,7 @@ class Test(test): @@ -93,7 +96,7 @@ class Test(test):
93 ' inmodel="'+self._model+'" srcname="Crab"'+ \ 96 ' inmodel="'+self._model+'" srcname="Crab"'+ \
94 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ 97 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
95 ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \ 98 ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \
96 - ' tbins=3 enumbins=0 emin=0.1 emax=100.0'+ \ 99 + ' tbins=3 method="CUBE" enumbins=0 emin=0.1 emax=100.0'+ \
97 ' outfile="lightcurve_cmd1.fits"'+ \ 100 ' outfile="lightcurve_cmd1.fits"'+ \
98 ' logfile="cslightcrv_cmd2.log" debug=yes' 101 ' logfile="cslightcrv_cmd2.log" debug=yes'
99 102
@@ -123,6 +126,7 @@ class Test(test): @@ -123,6 +126,7 @@ class Test(test):
123 lcrv['tmin'] = 'MJD 51544.50' 126 lcrv['tmin'] = 'MJD 51544.50'
124 lcrv['tmax'] = 'MJD 51544.53' 127 lcrv['tmax'] = 'MJD 51544.53'
125 lcrv['tbins'] = 3 128 lcrv['tbins'] = 3
  129 + lcrv['method'] = 'CUBE'
126 lcrv['enumbins'] = 0 130 lcrv['enumbins'] = 0
127 lcrv['emin'] = 0.1 131 lcrv['emin'] = 0.1
128 lcrv['emax'] = 100.0 132 lcrv['emax'] = 100.0
@@ -159,6 +163,7 @@ class Test(test): @@ -159,6 +163,7 @@ class Test(test):
159 lcrv['irf'] = self._irf 163 lcrv['irf'] = self._irf
160 lcrv['tbinalg'] = 'FILE' 164 lcrv['tbinalg'] = 'FILE'
161 lcrv['tbinfile'] = 'cslightcrv_py2.dat' 165 lcrv['tbinfile'] = 'cslightcrv_py2.dat'
  166 + lcrv['method'] = 'CUBE'
162 lcrv['enumbins'] = 0 167 lcrv['enumbins'] = 0
163 lcrv['emin'] = 0.1 168 lcrv['emin'] = 0.1
164 lcrv['emax'] = 100.0 169 lcrv['emax'] = 100.0
@@ -188,6 +193,7 @@ class Test(test): @@ -188,6 +193,7 @@ class Test(test):
188 lcrv['caldb'] = self._caldb 193 lcrv['caldb'] = self._caldb
189 lcrv['irf'] = self._irf 194 lcrv['irf'] = self._irf
190 lcrv['tbinalg'] = 'GTI' 195 lcrv['tbinalg'] = 'GTI'
  196 + lcrv['method'] = 'CUBE'
191 lcrv['enumbins'] = 0 197 lcrv['enumbins'] = 0
192 lcrv['emin'] = 0.1 198 lcrv['emin'] = 0.1
193 lcrv['emax'] = 100.0 199 lcrv['emax'] = 100.0
@@ -201,7 +207,7 @@ class Test(test): @@ -201,7 +207,7 @@ class Test(test):
201 # Check light curve 207 # Check light curve
202 self._check_light_curve('cslightcrv_py3.fits', 1) 208 self._check_light_curve('cslightcrv_py3.fits', 1)
203 209
204 - # Finally we set-up a binned cslightcrv 210 + # Binned cslightcrv
205 lcrv = cscripts.cslightcrv() 211 lcrv = cscripts.cslightcrv()
206 lcrv['inobs'] = self._events 212 lcrv['inobs'] = self._events
207 lcrv['inmodel'] = self._model 213 lcrv['inmodel'] = self._model
@@ -212,6 +218,7 @@ class Test(test): @@ -212,6 +218,7 @@ class Test(test):
212 lcrv['tmin'] = 'MJD 51544.50' 218 lcrv['tmin'] = 'MJD 51544.50'
213 lcrv['tmax'] = 'MJD 51544.53' 219 lcrv['tmax'] = 'MJD 51544.53'
214 lcrv['tbins'] = 2 220 lcrv['tbins'] = 2
  221 + lcrv['method'] = 'CUBE'
215 lcrv['emin'] = 0.1 222 lcrv['emin'] = 0.1
216 lcrv['emax'] = 100.0 223 lcrv['emax'] = 100.0
217 lcrv['enumbins'] = 10 224 lcrv['enumbins'] = 10
@@ -232,6 +239,45 @@ class Test(test): @@ -232,6 +239,45 @@ class Test(test):
232 # Check light curve 239 # Check light curve
233 self._check_light_curve('cslightcrv_py4.fits', 2) 240 self._check_light_curve('cslightcrv_py4.fits', 2)
234 241
  242 + # cslightcrv with classical analysis
  243 +
  244 + # first we build an observation container to pass the model
  245 + # to csphagen that will change the background to OnOff
  246 + obs = gammalib.GObservations()
  247 + for s, events in enumerate([self._myevents1]):
  248 + run = gammalib.GCTAObservation(events)
  249 + run.id(str(s + 1))
  250 + run.response(self._irf, gammalib.GCaldb('cta', self._caldb))
  251 + run.model(gammalib.GModels(self._model))
  252 + obs.append(run)
  253 +
  254 + # set up cslightcrv
  255 + lcrv = cscripts.cslightcrv()
  256 + lcrv['inobs'] = obs
  257 + lcrv['srcname'] = 'Crab'
  258 + lcrv['tbinalg'] = 'LIN'
  259 + lcrv['tmin'] = 6.3110887e8
  260 + lcrv['tmax'] = 6.3110977e8
  261 + lcrv['tbins'] = 2
  262 + lcrv['method'] = 'ONOFF'
  263 + lcrv['emin'] = 0.1
  264 + lcrv['emax'] = 100.0
  265 + lcrv['enumbins'] = 10
  266 + lcrv['coordsys'] = 'CEL'
  267 + lcrv['xref'] = 83.63
  268 + lcrv['yref'] = 22.01
  269 + lcrv['rad'] = 0.2
  270 + lcrv['statistic'] = 'WSTAT'
  271 + lcrv['outfile'] = 'cslightcrv_py5.fits'
  272 + lcrv['logfile'] = 'cslightcrv_py5.log'
  273 + lcrv['chatter'] = 4
  274 +
  275 + # Execute cslightcrv script
  276 + lcrv.execute()
  277 +
  278 + # Check light curve
  279 + self._check_light_curve('cslightcrv_py5.fits', 2)
  280 +
235 # Return 281 # Return
236 return 282 return
237 283