Commit 3426cca07b9a050411a27daeb4319eb4ccd3e380
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,10 +167,8 @@ def observation(ra=0.0, dec=0.0, emin=0.1, emax=100.0, | ||
| 167 | e_max.TeV(emax) | 167 | e_max.TeV(emax) |
| 168 | ebounds.setlog(e_min, e_max, ebins) | 168 | ebounds.setlog(e_min, e_max, ebins) |
| 169 | gti = GGti() | 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 | gti.append(tmin, tmax) | 172 | gti.append(tmin, tmax) |
| 175 | map = GSkymap("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, ebins) | 173 | map = GSkymap("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, ebins) |
| 176 | cube = GCTAEventCube(map, ebounds, gti) | 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,24 +198,10 @@ def test_irf(model, ra=0.0, dec=0.0, npix=100, filename="cntmap.fits"): | ||
| 200 | 198 | ||
| 201 | # Set CTA observation | 199 | # Set CTA observation |
| 202 | obs = observation(ra=ra, dec=dec, npix=npix) | 200 | obs = observation(ra=ra, dec=dec, npix=npix) |
| 203 | - src = GSkyDir() | ||
| 204 | - src.radec_deg(ra, dec) | ||
| 205 | 201 | ||
| 206 | # Loop over all bins | 202 | # Loop over all bins |
| 207 | for bin in obs.events(): | 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 | bin.counts(irf) | 205 | bin.counts(irf) |
| 222 | 206 | ||
| 223 | # Save observation | 207 | # Save observation |
| @@ -238,27 +222,14 @@ def test_grad(model, ra=0.0, dec=0.0, filename="gradmap.fits", ipar=2): | @@ -238,27 +222,14 @@ def test_grad(model, ra=0.0, dec=0.0, filename="gradmap.fits", ipar=2): | ||
| 238 | print model | 222 | print model |
| 239 | 223 | ||
| 240 | # Set CTA observation | 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 | # Make sure that parameter is free | 227 | # Make sure that parameter is free |
| 246 | model[ipar].free() | 228 | model[ipar].free() |
| 247 | 229 | ||
| 248 | # Loop over all bins | 230 | # Loop over all bins |
| 249 | for bin in obs.events(): | 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 | grad = obs.model_grad(model, bin, ipar) | 232 | grad = obs.model_grad(model, bin, ipar) |
| 260 | - | ||
| 261 | - # Set bin | ||
| 262 | bin.counts(grad) | 233 | bin.counts(grad) |
| 263 | 234 | ||
| 264 | # Save observation | 235 | # Save observation |
| @@ -276,10 +247,10 @@ if __name__ == '__main__': | @@ -276,10 +247,10 @@ if __name__ == '__main__': | ||
| 276 | Test diffuse models. | 247 | Test diffuse models. |
| 277 | """ | 248 | """ |
| 278 | # Dump header | 249 | # Dump header |
| 279 | |||
| 280 | - print "***********************" | ||
| 281 | - print "* Test diffuse models *" | ||
| 282 | - print "***********************" | 250 | + print("") |
| 251 | + print("***********************") | ||
| 252 | + print("* Test diffuse models *") | ||
| 253 | + print("***********************") | ||
| 283 | 254 | ||
| 284 | # Test IRF | 255 | # Test IRF |
| 285 | # test_irf(ptsrc_model()) | 256 | # test_irf(ptsrc_model()) |