From 479bb6d02379aead31d6d12007e2e5a40ceb4a52 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sun, 31 Jul 2016 21:53:20 +0200 Subject: [PATCH] Remove also fit() and cterror() function from "obsutils" (#1830) --- NEWS | 4 ++-- cscripts/cspull.py | 22 ++++++++++++---------- cscripts/cssens.py | 15 +++++++++------ cscripts/cstsdist.py | 6 ++++-- cscripts/obsutils.py | 88 ++-------------------------------------------------------------------------------------- 5 files changed, 29 insertions(+), 106 deletions(-) diff --git a/NEWS b/NEWS index 0316dc6..f759d34 100644 --- a/NEWS +++ b/NEWS @@ -108,8 +108,8 @@ None cscripts -------- Added the support modules "modutils" and "ioutils" to the cscripts module -and removed the obsolete function "cntmap()" and "modmap()" from the -"obsutils" module (#1830). +and removed the obsolete functions fit(), cterror(), cntmap() and modmap() +from the "obsutils" module (#1830). Examples diff --git a/cscripts/cspull.py b/cscripts/cspull.py index 6f3ab54..54ed2f3 100755 --- a/cscripts/cspull.py +++ b/cscripts/cspull.py @@ -228,17 +228,19 @@ class cspull(ctools.cscript): # Fit model if self['profile'].boolean(): models = self._obs.models() - for i in range(models.size()): - model_name = models[i].name() - like = obsutils.cterror(self._obs, model_name, - log=self._log_clients, - debug=self._logDebug(), - chatter=self._chatter) + for model in models: + like = ctools.cterror(obs) + like['srcname'] = model.name() + like['edisp'] = edisp=self._edisp + like['debug'] = self._logDebug() + like['chatter'] = self._chatter + like.run() else: - like = obsutils.fit(obs, edisp=self._edisp, - log=self._log_clients, - debug=self._logDebug(), - chatter=self._chatter) + like = ctools.ctlike(obs) + like['edisp'] = edisp=self._edisp + like['debug'] = self._logDebug() + like['chatter'] = self._chatter + like.run() # Store results logL = like.opt().value() diff --git a/cscripts/cssens.py b/cscripts/cssens.py index 6e73a20..03e9a86 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -72,7 +72,6 @@ class cssens(ctools.cscript): self._max_iter = 50 self._num_avg = 3 self._log_clients = False - self._debug = False # Initialise application by calling the appropriate class # constructor. @@ -117,8 +116,8 @@ class cssens(ctools.cscript): self._num_avg = self['num_avg'].integer() self._type = self['type'].string() - # Set some fixed parameters - self._debug = self['debug'].boolean() # Debugging in client tools + # Query remaining parameters + self['debug'].boolean() # Derive some parameters self._ebounds = gammalib.GEbounds(self._bins, @@ -347,7 +346,8 @@ class cssens(ctools.cscript): # Simulate events sim = obsutils.sim(self._obs, nbins=self._enumbins, seed=iterations, binsz=self._binsz, npix=self._npix, - log=self._log_clients, debug=self._debug, + log=self._log_clients, + debug=self['debug'].boolean(), edisp=self._edisp) # Determine number of events in simulation @@ -363,8 +363,11 @@ class cssens(ctools.cscript): self._log('\n') # Fit test source - fit = obsutils.fit(sim, log=self._log_clients, debug=self._debug, - edisp=self._edisp) + fit = ctools.ctlike(sim) + fit['edisp'] = edisp=self._edisp + fit['debug'] = self['debug'].boolean() + fit['chatter'] = self['chatter'].integer() + fit.run() # Get model fitting results logL = fit.opt().value() diff --git a/cscripts/cstsdist.py b/cscripts/cstsdist.py index e6f6d23..8ead84b 100755 --- a/cscripts/cstsdist.py +++ b/cscripts/cstsdist.py @@ -165,8 +165,10 @@ class cstsdist(ctools.cscript): self._log('\n') # Fit model - fit = obsutils.fit(sim, log = self._log_clients, - debug = self['debug'].boolean()) + fit = ctools.ctlike(sim) + fit['debug'] = self['debug'].boolean() + fit['chatter'] = self['chatter'].integer() + fit.run() # Get model fitting results logL = fit.opt().value() diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index 0cd848f..170684a 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -193,90 +193,6 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, return obs -# ================ # -# Fit observations # -# ================ # -def fit(obs, log=False, debug=False, chatter=2, edisp=False): - """ - Perform maximum likelihood fitting of observations in the container - - Parameters - ---------- - obs : `~gammalib.GObservations` - Observation container - log : bool, optional - Create log file(s) - debug : bool, optional - Create console dump? - chatter : int, optional - Chatter level - edisp : bool, optional - Apply energy dispersion? - - Returns - ------- - like : `~ctools.ctlike` - ctlike application - """ - # Allocate ctlike application and set parameters - like = ctools.ctlike(obs) - like['debug'] = debug - like['chatter'] = chatter - like['edisp'] = edisp - - # Optionally open the log file - if log: - like.logFileOpen() - - # Run ctlike application. - like.run() - - # Return observations - return like - - -# ============================================================== # -# Fit observations and determine errors using likelihood profile # -# ============================================================== # -def cterror(obs, srcname, log=False, debug=False, chatter=2): - """ - Fit observations and determine errors using likelihood profile - - Parameters - ---------- - obs : `~gammalib.GObservations` - Observation container - srcname : str - Source name - log : bool, optional - Create log file(s) - debug : bool, optional - Create console dump? - chatter : int, optional - Chatter level - - Returns - ------- - error : `~ctools.cterror` - cterror application - """ - # Allocate cterror application and set parameters - error = ctools.cterror(obs) - error['srcname'] = srcname - error['debug'] = debug - error['chatter'] = chatter - - # Optionally open the log file - if log: - error.logFileOpen() - - # Run cterror application. - error.run() - - # Return observations - return error - - # ======================= # # Set one CTA observation # # ======================= # @@ -640,8 +556,8 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, result : dict Dictionary of response cubes """ - # Compute spatial binning for point spread function and - # energy dispersion cubes + # Compute spatial binning for point spread function and energy dispersion + # cubes psf_binsz = 10.0 * binsz psf_nxpix = min(nxpix // 10, 2) # Make sure result is int psf_nypix = min(nypix // 10, 2) # Make sure result is int -- libgit2 0.21.4