Commit 3426cca07b9a050411a27daeb4319eb4ccd3e380

Authored by Jürgen Knödlseder
1 parent ad4ddf8d

Don't use cast anymore and make Python 3 compatible.

Showing 1 changed file with 8 additions and 37 deletions
inst/cta/test/test_model.py
... ... @@ -167,10 +167,8 @@ def observation(ra=0.0, dec=0.0, emin=0.1, emax=100.0,
167 167 e_max.TeV(emax)
168 168 ebounds.setlog(e_min, e_max, ebins)
169 169 gti = GGti()
170   - tmin = GTime()
171   - tmax = GTime()
172   - tmin.met(0.0)
173   - tmax.met(duration)
  170 + tmin = GTime(0.0)
  171 + tmax = GTime(duration)
174 172 gti.append(tmin, tmax)
175 173 map = GSkymap("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, ebins)
176 174 cube = GCTAEventCube(map, ebounds, gti)
... ... @@ -200,24 +198,10 @@ def test_irf(model, ra=0.0, dec=0.0, npix=100, filename="cntmap.fits"):
200 198  
201 199 # Set CTA observation
202 200 obs = observation(ra=ra, dec=dec, npix=npix)
203   - src = GSkyDir()
204   - src.radec_deg(ra, dec)
205 201  
206 202 # Loop over all bins
207 203 for bin in obs.events():
208   -
209   - # Cast to CTA bin
210   - bin = cast_GCTAEventBin(bin)
211   -
212   - # Set bin energy and time as source energy and time (no dispersion)
213   - srcDir = bin.dir()
214   - srcEng = bin.energy()
215   - srcTime = bin.time()
216   -
217   - # Compute IRF
218   - irf = obs.response().irf(bin, model, srcEng, srcTime, obs) * bin.size()
219   -
220   - # Set bin
  204 + irf = model.eval(bin, obs) * bin.size()
221 205 bin.counts(irf)
222 206  
223 207 # Save observation
... ... @@ -238,27 +222,14 @@ def test_grad(model, ra=0.0, dec=0.0, filename="gradmap.fits", ipar=2):
238 222 print model
239 223  
240 224 # Set CTA observation
241   - obs = observation()
242   - src = GSkyDir()
243   - src.radec_deg(ra, dec)
  225 + obs = observation(ra=ra, dec=dec, npix=npix)
244 226  
245 227 # Make sure that parameter is free
246 228 model[ipar].free()
247 229  
248 230 # Loop over all bins
249 231 for bin in obs.events():
250   -
251   - # Cast to CTA bin
252   - bin = cast_GCTAEventBin(bin)
253   -
254   - # Set bin energy and time as source energy and time (no dispersion)
255   - srcEng = bin.energy()
256   - srcTime = bin.time()
257   -
258   - # Compute gradient
259 232 grad = obs.model_grad(model, bin, ipar)
260   -
261   - # Set bin
262 233 bin.counts(grad)
263 234  
264 235 # Save observation
... ... @@ -276,10 +247,10 @@ if __name__ == '__main__':
276 247 Test diffuse models.
277 248 """
278 249 # Dump header
279   - print
280   - print "***********************"
281   - print "* Test diffuse models *"
282   - print "***********************"
  250 + print("")
  251 + print("***********************")
  252 + print("* Test diffuse models *")
  253 + print("***********************")
283 254  
284 255 # Test IRF
285 256 # test_irf(ptsrc_model())
... ...