Commit 479bb6d02379aead31d6d12007e2e5a40ceb4a52

Authored by Jürgen Knödlseder
1 parent 0a5b1abe

Remove also fit() and cterror() function from "obsutils" (#1830)

These functions are not really observation utilities, and they are not really needed either since they encapsulate only a few lines of code.
@@ -108,8 +108,8 @@ None @@ -108,8 +108,8 @@ None
108 cscripts 108 cscripts
109 -------- 109 --------
110 Added the support modules "modutils" and "ioutils" to the cscripts module 110 Added the support modules "modutils" and "ioutils" to the cscripts module
111 -and removed the obsolete function "cntmap()" and "modmap()" from the  
112 -"obsutils" module (#1830). 111 +and removed the obsolete functions fit(), cterror(), cntmap() and modmap()
  112 +from the "obsutils" module (#1830).
113 113
114 114
115 Examples 115 Examples
cscripts/cspull.py
@@ -228,17 +228,19 @@ class cspull(ctools.cscript): @@ -228,17 +228,19 @@ class cspull(ctools.cscript):
228 # Fit model 228 # Fit model
229 if self['profile'].boolean(): 229 if self['profile'].boolean():
230 models = self._obs.models() 230 models = self._obs.models()
231 - for i in range(models.size()):  
232 - model_name = models[i].name()  
233 - like = obsutils.cterror(self._obs, model_name,  
234 - log=self._log_clients,  
235 - debug=self._logDebug(),  
236 - chatter=self._chatter) 231 + for model in models:
  232 + like = ctools.cterror(obs)
  233 + like['srcname'] = model.name()
  234 + like['edisp'] = edisp=self._edisp
  235 + like['debug'] = self._logDebug()
  236 + like['chatter'] = self._chatter
  237 + like.run()
237 else: 238 else:
238 - like = obsutils.fit(obs, edisp=self._edisp,  
239 - log=self._log_clients,  
240 - debug=self._logDebug(),  
241 - chatter=self._chatter) 239 + like = ctools.ctlike(obs)
  240 + like['edisp'] = edisp=self._edisp
  241 + like['debug'] = self._logDebug()
  242 + like['chatter'] = self._chatter
  243 + like.run()
242 244
243 # Store results 245 # Store results
244 logL = like.opt().value() 246 logL = like.opt().value()
cscripts/cssens.py
@@ -72,7 +72,6 @@ class cssens(ctools.cscript): @@ -72,7 +72,6 @@ class cssens(ctools.cscript):
72 self._max_iter = 50 72 self._max_iter = 50
73 self._num_avg = 3 73 self._num_avg = 3
74 self._log_clients = False 74 self._log_clients = False
75 - self._debug = False  
76 75
77 # Initialise application by calling the appropriate class 76 # Initialise application by calling the appropriate class
78 # constructor. 77 # constructor.
@@ -117,8 +116,8 @@ class cssens(ctools.cscript): @@ -117,8 +116,8 @@ class cssens(ctools.cscript):
117 self._num_avg = self['num_avg'].integer() 116 self._num_avg = self['num_avg'].integer()
118 self._type = self['type'].string() 117 self._type = self['type'].string()
119 118
120 - # Set some fixed parameters  
121 - self._debug = self['debug'].boolean() # Debugging in client tools 119 + # Query remaining parameters
  120 + self['debug'].boolean()
122 121
123 # Derive some parameters 122 # Derive some parameters
124 self._ebounds = gammalib.GEbounds(self._bins, 123 self._ebounds = gammalib.GEbounds(self._bins,
@@ -347,7 +346,8 @@ class cssens(ctools.cscript): @@ -347,7 +346,8 @@ class cssens(ctools.cscript):
347 # Simulate events 346 # Simulate events
348 sim = obsutils.sim(self._obs, nbins=self._enumbins, seed=iterations, 347 sim = obsutils.sim(self._obs, nbins=self._enumbins, seed=iterations,
349 binsz=self._binsz, npix=self._npix, 348 binsz=self._binsz, npix=self._npix,
350 - log=self._log_clients, debug=self._debug, 349 + log=self._log_clients,
  350 + debug=self['debug'].boolean(),
351 edisp=self._edisp) 351 edisp=self._edisp)
352 352
353 # Determine number of events in simulation 353 # Determine number of events in simulation
@@ -363,8 +363,11 @@ class cssens(ctools.cscript): @@ -363,8 +363,11 @@ class cssens(ctools.cscript):
363 self._log('\n') 363 self._log('\n')
364 364
365 # Fit test source 365 # Fit test source
366 - fit = obsutils.fit(sim, log=self._log_clients, debug=self._debug,  
367 - edisp=self._edisp) 366 + fit = ctools.ctlike(sim)
  367 + fit['edisp'] = edisp=self._edisp
  368 + fit['debug'] = self['debug'].boolean()
  369 + fit['chatter'] = self['chatter'].integer()
  370 + fit.run()
368 371
369 # Get model fitting results 372 # Get model fitting results
370 logL = fit.opt().value() 373 logL = fit.opt().value()
cscripts/cstsdist.py
@@ -165,8 +165,10 @@ class cstsdist(ctools.cscript): @@ -165,8 +165,10 @@ class cstsdist(ctools.cscript):
165 self._log('\n') 165 self._log('\n')
166 166
167 # Fit model 167 # Fit model
168 - fit = obsutils.fit(sim, log = self._log_clients,  
169 - debug = self['debug'].boolean()) 168 + fit = ctools.ctlike(sim)
  169 + fit['debug'] = self['debug'].boolean()
  170 + fit['chatter'] = self['chatter'].integer()
  171 + fit.run()
170 172
171 # Get model fitting results 173 # Get model fitting results
172 logL = fit.opt().value() 174 logL = fit.opt().value()
cscripts/obsutils.py
@@ -193,90 +193,6 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, @@ -193,90 +193,6 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0,
193 return obs 193 return obs
194 194
195 195
196 -# ================ #  
197 -# Fit observations #  
198 -# ================ #  
199 -def fit(obs, log=False, debug=False, chatter=2, edisp=False):  
200 - """  
201 - Perform maximum likelihood fitting of observations in the container  
202 -  
203 - Parameters  
204 - ----------  
205 - obs : `~gammalib.GObservations`  
206 - Observation container  
207 - log : bool, optional  
208 - Create log file(s)  
209 - debug : bool, optional  
210 - Create console dump?  
211 - chatter : int, optional  
212 - Chatter level  
213 - edisp : bool, optional  
214 - Apply energy dispersion?  
215 -  
216 - Returns  
217 - -------  
218 - like : `~ctools.ctlike`  
219 - ctlike application  
220 - """  
221 - # Allocate ctlike application and set parameters  
222 - like = ctools.ctlike(obs)  
223 - like['debug'] = debug  
224 - like['chatter'] = chatter  
225 - like['edisp'] = edisp  
226 -  
227 - # Optionally open the log file  
228 - if log:  
229 - like.logFileOpen()  
230 -  
231 - # Run ctlike application.  
232 - like.run()  
233 -  
234 - # Return observations  
235 - return like  
236 -  
237 -  
238 -# ============================================================== #  
239 -# Fit observations and determine errors using likelihood profile #  
240 -# ============================================================== #  
241 -def cterror(obs, srcname, log=False, debug=False, chatter=2):  
242 - """  
243 - Fit observations and determine errors using likelihood profile  
244 -  
245 - Parameters  
246 - ----------  
247 - obs : `~gammalib.GObservations`  
248 - Observation container  
249 - srcname : str  
250 - Source name  
251 - log : bool, optional  
252 - Create log file(s)  
253 - debug : bool, optional  
254 - Create console dump?  
255 - chatter : int, optional  
256 - Chatter level  
257 -  
258 - Returns  
259 - -------  
260 - error : `~ctools.cterror`  
261 - cterror application  
262 - """  
263 - # Allocate cterror application and set parameters  
264 - error = ctools.cterror(obs)  
265 - error['srcname'] = srcname  
266 - error['debug'] = debug  
267 - error['chatter'] = chatter  
268 -  
269 - # Optionally open the log file  
270 - if log:  
271 - error.logFileOpen()  
272 -  
273 - # Run cterror application.  
274 - error.run()  
275 -  
276 - # Return observations  
277 - return error  
278 -  
279 -  
280 # ======================= # 196 # ======================= #
281 # Set one CTA observation # 197 # Set one CTA observation #
282 # ======================= # 198 # ======================= #
@@ -640,8 +556,8 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -640,8 +556,8 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
640 result : dict 556 result : dict
641 Dictionary of response cubes 557 Dictionary of response cubes
642 """ 558 """
643 - # Compute spatial binning for point spread function and  
644 - # energy dispersion cubes 559 + # Compute spatial binning for point spread function and energy dispersion
  560 + # cubes
645 psf_binsz = 10.0 * binsz 561 psf_binsz = 10.0 * binsz
646 psf_nxpix = min(nxpix // 10, 2) # Make sure result is int 562 psf_nxpix = min(nxpix // 10, 2) # Make sure result is int
647 psf_nypix = min(nypix // 10, 2) # Make sure result is int 563 psf_nypix = min(nypix // 10, 2) # Make sure result is int