From 75e6edfb8a5045f05d7fdd19ecb872434ace7dd9 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sun, 24 May 2015 00:35:07 +0200 Subject: [PATCH] Adapt benchmark to new interface --- examples/benchmark_cta_analysis.py | 59 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/examples/benchmark_cta_analysis.py b/examples/benchmark_cta_analysis.py index 62b6d4d..452489e 100755 --- a/examples/benchmark_cta_analysis.py +++ b/examples/benchmark_cta_analysis.py @@ -167,10 +167,10 @@ def binned_pipeline(duration): return telapsed, tctlike -# ============================ # -# Cube-style analysis pipeline # -# ============================ # -def cube_pipeline(duration): +# ========================= # +# Stacked analysis pipeline # +# ========================= # +def stacked_pipeline(duration): """ Cube-style analysis pipeline. """ @@ -260,17 +260,34 @@ def cube_pipeline(duration): psfcube["yref"].real(dec) psfcube.run() - # Set exposure and PSF cube for first CTA observation - obs = bin.obs() - cta = gammalib.GCTAObservation(obs[0]) - cta.response(expcube.expcube(), psfcube.psfcube()) - obs[0] = cta + # Create background cube + bkgcube = ctools.ctbkgcube(sim.obs()) + bkgcube["incube"].filename("NONE") + bkgcube["ebinalg"].string("LOG") + bkgcube["emin"].real(emin) + bkgcube["emax"].real(emax) + bkgcube["enumbins"].integer(enumbins) + bkgcube["nxpix"].integer(10) + bkgcube["nypix"].integer(10) + bkgcube["binsz"].real(1.0) + bkgcube["coordsys"].string(coordsys) + bkgcube["proj"].string(proj) + bkgcube["xref"].real(ra) + bkgcube["yref"].real(dec) + bkgcube.run() + + # Attach background model to observation container + bin.obs().models(bkgcube.models()) + + # Set Exposure and Psf cube for first CTA observation + # (ctbin will create an observation with a single container) + bin.obs()[0].response(expcube.expcube(), psfcube.psfcube(), bkgcube.bkgcube()) # Get ctlike start CPU time tctlike = time.clock() # Perform maximum likelihood fitting - like = ctools.ctlike(obs) + like = ctools.ctlike(bin.obs()) like.run() # Get stop CPU time @@ -292,16 +309,16 @@ if __name__ == '__main__': print("*************************************") print("* CTA analysis benchmark *") print("*************************************") - print(" Duration Unbinned Binned Cube-style ctlike-UB ctlike-B ctlike-CS") + print(" Duration Unbinned Binned Stacked ctlike-UB ctlike-B ctlike-S") # Initialize arrays a_duration = [] a_unbinned = [] a_binned = [] - a_cube = [] + a_stacked = [] c_unbinned = [] c_binned = [] - c_cube = [] + c_stacked = [] # Perform benchmarks duration = 1800.0 @@ -309,22 +326,22 @@ if __name__ == '__main__': # Perform analyses t_unbinned, ct_unbinned = unbinned_pipeline(duration) - t_binned, ct_binned = binned_pipeline(duration) - t_cube, ct_cube = cube_pipeline(duration) + t_binned, ct_binned = binned_pipeline(duration) + t_stacked, ct_stacked = stacked_pipeline(duration) # Collect results a_duration.append(duration/3600.0) a_unbinned.append(t_unbinned) a_binned.append(t_binned) - a_cube.append(t_cube) + a_stacked.append(t_stacked) c_unbinned.append(ct_unbinned) c_binned.append(ct_binned) - c_cube.append(ct_cube) + c_stacked.append(ct_stacked) # Print results print("%10.0f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f" % \ - (duration, t_unbinned, t_binned, t_cube, \ - ct_unbinned, ct_binned, ct_cube)) + (duration, t_unbinned, t_binned, t_stacked, \ + ct_unbinned, ct_binned, ct_stacked)) # Increment duration duration *= 2.0 @@ -335,10 +352,10 @@ if __name__ == '__main__': plt.title("CTA analysis benchmark") plt.loglog(a_duration, a_unbinned, 'ro-', label='unbinned') plt.loglog(a_duration, a_binned, 'bo-', label='binned') - plt.loglog(a_duration, a_cube, 'go-', label='cube-style') + plt.loglog(a_duration, a_stacked, 'go-', label='cube-style') plt.loglog(a_duration, c_unbinned, 'ro--') plt.loglog(a_duration, c_binned, 'bo--') - plt.loglog(a_duration, c_cube, 'go--') + plt.loglog(a_duration, c_stacked, 'go--') plt.xlabel("Duration (hours)") plt.ylabel("CPU time (seconds)") plt.legend(loc="lower right") -- libgit2 0.21.4