Commit 35fceede88bafd6b65cde46aedbed7d256acae6f
1 parent
ed19ef6c
Adapt test scripts to new GCaldb interface.
Showing
3 changed files
with
13 additions
and
54 deletions
inst/cta/test/example_binned_ml_fit.py
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | # This script performs a binned maximum likelihood analysis of CTA data. | 3 | # This script performs a binned maximum likelihood analysis of CTA data. |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2012 Juergen Knoedlseder | 5 | +# Copyright (C) 2012-2014 Juergen Knoedlseder |
| 6 | # | 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -109,13 +109,13 @@ if __name__ == '__main__': | @@ -109,13 +109,13 @@ if __name__ == '__main__': | ||
| 109 | print("... please wait for a few seconds") | 109 | print("... please wait for a few seconds") |
| 110 | 110 | ||
| 111 | # Set parameters | 111 | # Set parameters |
| 112 | - irf = "kb_E_50h_v3" | 112 | + irf = "cta_dummy_irf" |
| 113 | caldb = "../caldb" | 113 | caldb = "../caldb" |
| 114 | model = "data/crab.xml" | 114 | model = "data/crab.xml" |
| 115 | cntmap = "data/crab_cntmap.fits" | 115 | cntmap = "data/crab_cntmap.fits" |
| 116 | 116 | ||
| 117 | # Perform binned analysis | 117 | # Perform binned analysis |
| 118 | - result = binned_analysis(model, cntmap, irf, caldb) | 118 | + result = binned_analysis(model, cntmap, irf, GCaldb(caldb)) |
| 119 | 119 | ||
| 120 | # Print model results | 120 | # Print model results |
| 121 | print(result) | 121 | print(result) |
inst/cta/test/example_sim_psf.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script simulated the PSF distribution. | 3 | +# This script simulates the PSF distribution. |
| 4 | # | 4 | # |
| 5 | -# Based on the MAGIC spectrum of the Crab nebula, and by assuming a powerlaw, | ||
| 6 | -# it will create a Monte Carlo sample of photons. | ||
| 7 | -# | ||
| 8 | -# If matplotlib is installed, the spectrum will be displayed on the screen. | 5 | +# If matplotlib is installed, the PSF will be displayed on the screen. |
| 9 | # | 6 | # |
| 10 | # -------------------------------------------------------------------------- | 7 | # -------------------------------------------------------------------------- |
| 11 | # | 8 | # |
| 12 | -# Copyright (C) 2013 Juergen Knoedlseder | 9 | +# Copyright (C) 2013-2014 Juergen Knoedlseder |
| 13 | # | 10 | # |
| 14 | # This program is free software: you can redistribute it and/or modify | 11 | # This program is free software: you can redistribute it and/or modify |
| 15 | # it under the terms of the GNU General Public License as published by | 12 | # it under the terms of the GNU General Public License as published by |
| @@ -29,47 +26,9 @@ from gammalib import * | @@ -29,47 +26,9 @@ from gammalib import * | ||
| 29 | from math import * | 26 | from math import * |
| 30 | 27 | ||
| 31 | 28 | ||
| 32 | -# ======================== # | ||
| 33 | -# Simulate CTA observation # | ||
| 34 | -# ======================== # | ||
| 35 | -def simulate(xmlname, e_min, e_max, area, duration): | ||
| 36 | - """ | ||
| 37 | - Simulate CTA observation. | ||
| 38 | - """ | ||
| 39 | - # Allocate MC parameters | ||
| 40 | - dir = GSkyDir() | ||
| 41 | - emin = GEnergy() | ||
| 42 | - emax = GEnergy() | ||
| 43 | - tmin = GTime(0.0) | ||
| 44 | - tmax = GTime(duration) | ||
| 45 | - | ||
| 46 | - # Define MC parameters | ||
| 47 | - dir.radec_deg(83.6331, 22.0145) | ||
| 48 | - radius = 10.0 | ||
| 49 | - emin.TeV(e_min) | ||
| 50 | - emax.TeV(e_max) | ||
| 51 | - | ||
| 52 | - # Allocate random number generator | ||
| 53 | - ran = GRan() | ||
| 54 | - | ||
| 55 | - # Load models and extract first model | ||
| 56 | - models = GModels(xmlname) | ||
| 57 | - model = models[0] | ||
| 58 | - print(model) | ||
| 59 | - | ||
| 60 | - # Simulate photons | ||
| 61 | - photons = model.mc(area, dir, radius, emin, emax, tmin, tmax, ran) | ||
| 62 | - | ||
| 63 | - # Print photons | ||
| 64 | - print(str(len(photons)) + " photons simulated.") | ||
| 65 | - | ||
| 66 | - # Return photons | ||
| 67 | - return photons | ||
| 68 | - | ||
| 69 | - | ||
| 70 | -# ======== # | ||
| 71 | -# Show PSF # | ||
| 72 | -# ======== # | 29 | +# ============ # |
| 30 | +# Simulate PSF # | ||
| 31 | +# ============ # | ||
| 73 | def sim_psf(response, energy, r_max=0.8, rbins=1000, nmc=1000000): | 32 | def sim_psf(response, energy, r_max=0.8, rbins=1000, nmc=1000000): |
| 74 | """ | 33 | """ |
| 75 | Simulate PSF and show results using matplotlib (if available). | 34 | Simulate PSF and show results using matplotlib (if available). |
| @@ -160,8 +119,8 @@ if __name__ == '__main__': | @@ -160,8 +119,8 @@ if __name__ == '__main__': | ||
| 160 | print("****************") | 119 | print("****************") |
| 161 | 120 | ||
| 162 | # Load response | 121 | # Load response |
| 163 | - rsp = GCTAResponse("irf_test.fits", | ||
| 164 | - "../caldb/data/cta/e/bcf/000002") | 122 | + rsp = GCTAResponse("irf_file.fits", |
| 123 | + GCaldb("../caldb/data/cta/e/bcf/IFAE20120510_50h_King")) | ||
| 165 | 124 | ||
| 166 | # Simulate PSF | 125 | # Simulate PSF |
| 167 | sim_psf(rsp, 1.0) | 126 | sim_psf(rsp, 1.0) |
inst/cta/test/test_model.py
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | # This script tests the model computations using the CTA response function. | 3 | # This script tests the model computations using the CTA response function. |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2011-2013 Jurgen Knodlseder | 5 | +# Copyright (C) 2011-2014 Jurgen Knodlseder |
| 6 | # | 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -150,7 +150,7 @@ def observation(ra=0.0, dec=0.0, emin=0.1, emax=100.0, | @@ -150,7 +150,7 @@ def observation(ra=0.0, dec=0.0, emin=0.1, emax=100.0, | ||
| 150 | obs = GCTAObservation() | 150 | obs = GCTAObservation() |
| 151 | 151 | ||
| 152 | # Set response | 152 | # Set response |
| 153 | - obs.response("kb_E_50h_v3", "../caldb") | 153 | + obs.response("cta_dummy_irf", GCaldb("../caldb")) |
| 154 | 154 | ||
| 155 | # Set pointing | 155 | # Set pointing |
| 156 | dir = GSkyDir() | 156 | dir = GSkyDir() |