Commit c01c64f273f169c25020ac8c98ad521bbdfb0324

Authored by sohm
1 parent b1679652

sim() function now returns both, the ctbin and ctobssim object. Before it return…

…ed the ctbin output in case of a binned analysis, which screwed up the cntmap function
Showing 1 changed file with 9 additions and 11 deletions
scripts/obsutils.py
@@ -61,10 +61,15 @@ def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0, @@ -61,10 +61,15 @@ def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0,
61 # events are not added together, they still apply to each observation 61 # events are not added together, they still apply to each observation
62 # separately. 62 # separately.
63 sim.run() 63 sim.run()
  64 +
  65 + # Make a deep copy of the observation that will be returned
  66 + # (the ctobssim object will go out of scope one the function is
  67 + # left)
  68 + obssim = sim.obs().copy()
  69 + obsbin = None
64 70
65 # Binned option? 71 # Binned option?
66 if nbins > 0: 72 if nbins > 0:
67 -  
68 # Determine common energy boundaries for observations 73 # Determine common energy boundaries for observations
69 emin = None 74 emin = None
70 emax = None 75 emax = None
@@ -79,7 +84,7 @@ def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0, @@ -79,7 +84,7 @@ def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0,
79 emax = run_emax 84 emax = run_emax
80 elif run_emax > emax: 85 elif run_emax > emax:
81 emax = run_emax 86 emax = run_emax
82 - 87 +
83 # Allocate ctbin application and set parameters 88 # Allocate ctbin application and set parameters
84 bin = ctools.ctbin(sim.obs()) 89 bin = ctools.ctbin(sim.obs())
85 bin["ebinalg"].string("LOG") 90 bin["ebinalg"].string("LOG")
@@ -108,20 +113,13 @@ def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0, @@ -108,20 +113,13 @@ def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0,
108 # Make a deep copy of the observation that will be returned 113 # Make a deep copy of the observation that will be returned
109 # (the ctbin object will go out of scope one the function is 114 # (the ctbin object will go out of scope one the function is
110 # left) 115 # left)
111 - obs = bin.obs().copy() 116 + obsbin = bin.obs().copy()
112 117
113 - else:  
114 -  
115 - # Make a deep copy of the observation that will be returned  
116 - # (the ctobssim object will go out of scope one the function is  
117 - # left)  
118 - obs = sim.obs().copy()  
119 -  
120 # Delete the simulation 118 # Delete the simulation
121 del sim 119 del sim
122 120
123 # Return observation container 121 # Return observation container
124 - return obs 122 + return obsbin,obssim
125 123
126 124
127 # ================ # 125 # ================ #