From 699cd5ee3b15244fb29f7a2f29b9572a0083a7c4 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Mon, 23 Oct 2017 12:20:15 +0200 Subject: [PATCH] The following scripts now have csobservation as base class: csebins, csmodelselect, csobs2caldb, csobsinfo, csobsselect, and csphagen. The script cstsmapsplit has cslikelihood as base class. --- cscripts/csebins.py | 23 ++++++++--------------- cscripts/csmodelselect.py | 24 +++++++++--------------- cscripts/csobs2caldb.py | 25 +++++++++---------------- cscripts/csobsinfo.py | 22 +++++++--------------- cscripts/csobsselect.py | 35 +++++++++++------------------------ cscripts/csphagen.py | 51 ++++++++++++++++++++------------------------------- cscripts/csresmap.py | 43 ++++++++++++++++++------------------------- cscripts/cssens.py | 2 +- cscripts/csspec.py | 4 ++-- cscripts/cstsdist.py | 2 +- cscripts/cstsmapsplit.py | 53 ++++++++++++++++++----------------------------------- 11 files changed, 104 insertions(+), 180 deletions(-) diff --git a/cscripts/csebins.py b/cscripts/csebins.py index ba3b2ee..79d2d87 100755 --- a/cscripts/csebins.py +++ b/cscripts/csebins.py @@ -27,7 +27,7 @@ import ctools # ============= # # csebins class # # ============= # -class csebins(ctools.cscript): +class csebins(ctools.csobservation): """ Generates energy boundaries for stacked analysis """ @@ -37,19 +37,12 @@ class csebins(ctools.cscript): """ Constructor """ - # Set name and version - self._name = 'csebins' - self._version = ctools.__version__ + # Initialise application by calling the appropriate class constructor + self._init_csobservation('csebins', ctools.__version__, argv) # Set members self._ebounds = gammalib.GEbounds() - # Initialise observation container from constructor arguments. - self._obs, argv = self._set_input_obs(argv) - - # Initialise script by calling the appropriate class constructor. - self._init_cscript(argv) - # Return return @@ -60,7 +53,7 @@ class csebins(ctools.cscript): Get parameters from parfile """ # Initialise observation container if it is currently empty - if self._obs.size() == 0: + if self.obs().size() == 0: # Query "inobs" parameter filename = self['inobs'].filename() @@ -68,13 +61,13 @@ class csebins(ctools.cscript): # If an observation definition file was provided then load it, # otherwise build a single observation with response information if self._is_valid_filename(filename): - self._obs = gammalib.GObservations(filename) + self.obs(gammalib.GObservations(filename)) else: cta = gammalib.GCTAObservation() caldb = gammalib.GCaldb('cta', self['caldb'].string()) rsp = gammalib.GCTAResponseIrf(self['irf'].string(), caldb) cta.response(rsp) - self._obs.append(cta) + self.obs().append(cta) # Query input parameters self['emin'].real() @@ -260,13 +253,13 @@ class csebins(ctools.cscript): self._get_parameters() # Write observation into logger - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') # Write header self._log_header1(gammalib.TERSE, 'Define energy boundaries') # Define energy boundaries for observation container - self._set_ebounds(self._obs) + self._set_ebounds(self.obs()) # Return return diff --git a/cscripts/csmodelselect.py b/cscripts/csmodelselect.py index 2ad3c84..9d8b85f 100755 --- a/cscripts/csmodelselect.py +++ b/cscripts/csmodelselect.py @@ -26,7 +26,7 @@ import ctools # =================== # # csmodelselect class # # =================== # -class csmodelselect(ctools.cscript): +class csmodelselect(ctools.csobservation): """ Selects model from a model definition XML file """ @@ -36,19 +36,13 @@ class csmodelselect(ctools.cscript): """ Constructor """ + # Initialise application by calling the appropriate class constructor + self._init_csobservation('csmodelselect', ctools.__version__, argv) # Set name - self._name = 'csmodelselect' - self._version = ctools.__version__ - - # Initialise observation container from constructor arguments - self._obs, argv = self._set_input_obs(argv) # Initialise class members self._models = gammalib.GModels() - # Initialise application by calling the appropriate class constructor - self._init_cscript(argv) - # Return return @@ -77,8 +71,8 @@ class csmodelselect(ctools.cscript): # If there are no observations in container then get them from the # parameter file - if self._obs.size() == 0: - self._obs = self._get_observations(False) + if self.obs().size() == 0: + self.obs(self._get_observations(False)) # Get models self._models = gammalib.GModels(self['inmodel'].filename()) @@ -237,10 +231,10 @@ class csmodelselect(ctools.cscript): models = gammalib.GModels() # Write input observation container into logger - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') # Write input models into logger - self._log_models(gammalib.VERBOSE, self._models, 'Input model') + self._log_models(gammalib.NORMAL, self._models, 'Input model') # Write header self._log_header1(gammalib.NORMAL, 'Model selection') @@ -250,7 +244,7 @@ class csmodelselect(ctools.cscript): # If model should be selected then set model parameters and append # model to the output container - if self._select_model(model, self._obs): + if self._select_model(model, self.obs()): # Set model parameters model = self._set_model_parameters(model) @@ -262,7 +256,7 @@ class csmodelselect(ctools.cscript): self._models = models # Write selected models into logger - self._log_models(gammalib.VERBOSE, self._models, 'Selected model') + self._log_models(gammalib.NORMAL, self._models, 'Selected model') # Return return diff --git a/cscripts/csobs2caldb.py b/cscripts/csobs2caldb.py index 17c354c..00c81e4 100755 --- a/cscripts/csobs2caldb.py +++ b/cscripts/csobs2caldb.py @@ -29,7 +29,7 @@ from cscripts import calutils # ================= # # csobs2caldb class # # ================= # -class csobs2caldb(ctools.cscript): +class csobs2caldb(ctools.csobservation): """ Creates a calibration database entry for an IACT observation. @@ -46,9 +46,8 @@ class csobs2caldb(ctools.cscript): """ Constructor """ - # Set name and version - self._name = 'csobs2caldb' - self._version = ctools.__version__ + # Initialise application by calling the appropriate class constructor + self._init_csobservation('csobs2caldb', ctools.__version__, argv) # Initialise members self._observation = gammalib.GCTAObservation() @@ -61,12 +60,6 @@ class csobs2caldb(ctools.cscript): self._caldb_inx = gammalib.GFits() self._irf_fits = gammalib.GFits() - # Initialise observation container from constructor arguments. - self._obs, argv = self._set_input_obs(argv) - - # Initialise script by calling the appropriate class constructor. - self._init_cscript(argv) - # Return return @@ -81,11 +74,11 @@ class csobs2caldb(ctools.cscript): """ # Load observation container from "inobs" parameter in case that # the observation container is still empty. - if self._obs.is_empty(): - self._obs = gammalib.GObservations(self['inobs'].filename()) + if self.obs().is_empty(): + self.obs(gammalib.GObservations(self['inobs'].filename())) # Raise an exception if the observation container is empty - if self._obs.is_empty(): + if self.obs().is_empty(): raise ValueError('No or empty observation provided for ' 'parameter "inobs".') @@ -93,12 +86,12 @@ class csobs2caldb(ctools.cscript): index = self['index'].integer() # Raise an exception if the index is not valid - if index < 0 or index >= self._obs.size(): + if index < 0 or index >= self.obs().size(): raise IndexError('Parameter "index=%d" outside the validity ' - 'range [0,%d].' % (index, self._obs.size())) + 'range [0,%d].' % (index, self.obs().size())) # Get observation - self._observation = self._obs[index] + self._observation = self.obs()[index] # Make sure we have a CTA observation if not self._observation.classname() == 'GCTAObservation': diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py index 2418464..8e0c2cb 100755 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -26,7 +26,7 @@ import ctools # =============== # # csobsinfo class # # =============== # -class csobsinfo(ctools.cscript): +class csobsinfo(ctools.csobservation): """ Shows the content of an observation container """ @@ -36,9 +36,8 @@ class csobsinfo(ctools.cscript): """ Constructor. """ - # Set name - self._name = 'csobsinfo' - self._version = ctools.__version__ + # Initialise application by calling the appropriate class constructor + self._init_csobservation('csobsinfo', ctools.__version__, argv) # Initialise class members self._obj_dir = None @@ -51,13 +50,6 @@ class csobsinfo(ctools.cscript): self._ebounds = gammalib.GEbounds() self._gti = gammalib.GGti() - # Initialise observation container from constructor arguments. - self._obs, argv = self._set_input_obs(argv) - - # Initialise application by calling the appropriate class - # constructor. - self._init_cscript(argv) - # Return return @@ -68,9 +60,9 @@ class csobsinfo(ctools.cscript): Get parameters from parfile and setup the observation """ # Get parameters - if self._obs.size() == 0: + if self.obs().size() == 0: self._require_inobs('csobsinfo::get_parameters') - self._obs = self._get_observations(False) + self.obs(self._get_observations(False)) # Initialise object position self._obj_dir = gammalib.GSkyDir() @@ -127,10 +119,10 @@ class csobsinfo(ctools.cscript): # Write header if self._logTerse(): self._log('\n') - self._log.header1(gammalib.number('Observation', self._obs.size())) + self._log.header1(gammalib.number('Observation', self.obs().size())) # Loop over observations - for obs in self._obs: + for obs in self.obs(): # Skip non-CTA observations if not obs.classname() == 'GCTAObservation': diff --git a/cscripts/csobsselect.py b/cscripts/csobsselect.py index 2460262..01c213b 100755 --- a/cscripts/csobsselect.py +++ b/cscripts/csobsselect.py @@ -26,7 +26,7 @@ import ctools # ================= # # csobsselect class # # ================= # -class csobsselect(ctools.cscript): +class csobsselect(ctools.csobservation): """ Selects observations from an observation definition XML file """ @@ -36,15 +36,8 @@ class csobsselect(ctools.cscript): """ Constructor """ - # Set name - self._name = 'csobsselect' - self._version = ctools.__version__ - - # Initialise observation container from constructor arguments - self._obs, argv = self._set_input_obs(argv) - # Initialise application by calling the appropriate class constructor - self._init_cscript(argv) + self._init_csobservation('csobsselect', ctools.__version__, argv) # Return return @@ -57,9 +50,9 @@ class csobsselect(ctools.cscript): """ # If there are no observations in container then query the inobs # parameter - if self._obs.size() == 0: + if self.obs().is_empty(): self['inobs'].filename() - + # Query relevant pointing selection parameters pntselect = self['pntselect'].string() coordsys = self['coordsys'].string() @@ -81,8 +74,8 @@ class csobsselect(ctools.cscript): # If there are no observations in container then get them from the # parameter file - if self._obs.size() == 0: - self._obs = self._get_observations(False) + if self.obs().is_empty(): + self.obs(self._get_observations(False)) # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -280,23 +273,23 @@ class csobsselect(ctools.cscript): selected_obs = gammalib.GObservations() # Write input observation container into logger - self._log_observations(gammalib.NORMAL, self._obs, 'Input observation') + self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') # Write header self._log_header1(gammalib.TERSE, 'Observation selection') # Loop over observations - for obs in self._obs: + for obs in self.obs(): # If observation is selected then append observation if self._select_observation(obs): selected_obs.append(obs) # Copy selected observations into observation - self._obs = selected_obs + self.obs(selected_obs) # Write input observation container into logger - self._log_observations(gammalib.NORMAL, self._obs, 'Selected observation') + self._log_observations(gammalib.NORMAL, self.obs(), 'Selected observation') # Return return @@ -324,17 +317,11 @@ class csobsselect(ctools.cscript): outobs.url()) # Save observations - self._obs.save(outobs) + self.obs().save(outobs) # Return return - def obs(self): - """ - Return observation container - """ - return self._obs - # ======================== # # Main routine entry point # diff --git a/cscripts/csphagen.py b/cscripts/csphagen.py index 39ffe2e..06cc068 100755 --- a/cscripts/csphagen.py +++ b/cscripts/csphagen.py @@ -28,7 +28,7 @@ import sys # =============== # # csfindobs class # # =============== # -class csphagen(ctools.cscript): +class csphagen(ctools.csobservation): """ Generate PHA, ARF and RMF files for classical IACT spectral analysis """ @@ -38,18 +38,10 @@ class csphagen(ctools.cscript): """ Constructor """ - # Set name, version - self._name = 'csphagen' - self._version = ctools.__version__ - - # Initialise observation container from constructor arguments - self._obs, argv = self._set_input_obs(argv) - # Initialise application by calling the appropriate class constructor - self._init_cscript(argv) + self._init_csobservation('csphagen', ctools.__version__, argv) # Initialise other variables - self._outobs = gammalib.GObservations() self._ebounds = gammalib.GEbounds() self._src_dir = gammalib.GSkyDir() self._src_reg = gammalib.GSkyRegions() @@ -69,7 +61,7 @@ class csphagen(ctools.cscript): """ # Setup observations (require response and allow event list, don't # allow counts cube) - self._setup_observations(self._obs, True, True, False) + self._setup_observations(self.obs(), True, True, False) # Set energy bounds self._ebounds = self._create_ebounds() @@ -114,8 +106,8 @@ class csphagen(ctools.cscript): # If there are no observations in container then get them from the # parameter file - if self._obs.size() == 0: - self._obs = self._get_observations(False) + if self.obs().is_empty(): + self.obs(self._get_observations(False)) # Write input parameters into logger self._log_parameters(gammalib.TERSE) @@ -200,18 +192,18 @@ class csphagen(ctools.cscript): self._get_parameters() # Write observation into logger - self._log_observations(gammalib.NORMAL, self._obs, 'Observation') + self._log_observations(gammalib.NORMAL, self.obs(), 'Observation') # Write header self._log_header1(gammalib.NORMAL, 'Generation of source and background spectra') # Initialise run variables - self._outobs = gammalib.GObservations() + outobs = gammalib.GObservations() self._bkg_regs = [] # Loop through observations and generate pha, arf, rmf files - for obs in self._obs: + for obs in self.obs(): # Initialise background regions for this observation bkg_reg = gammalib.GSkyRegions() @@ -230,25 +222,28 @@ class csphagen(ctools.cscript): self._src_reg, bkg_reg) onoff.id(obs.id()) - self._outobs.append(onoff) + outobs.append(onoff) self._bkg_regs.append({'regions': bkg_reg, 'id': obs.id()}) else: self._log_string(gammalib.NORMAL, 'Observation %s not included ' 'in spectra generation' % (obs.id())) # Stack observations - if self._outobs.size() > 1 and self['stack'].boolean() == True: + if outobs.size() > 1 and self['stack'].boolean() == True: # Write header self._log_header1(gammalib.NORMAL, 'Stacking %d observations' % - (self._outobs.size())) + (outobs.size())) # Stack observations - stacked_obs = gammalib.GCTAOnOffObservation(self._outobs) + stacked_obs = gammalib.GCTAOnOffObservation(outobs) # Put stacked observations in output container - self._outobs = gammalib.GObservations() - self._outobs.append(stacked_obs) + outobs = gammalib.GObservations() + outobs.append(stacked_obs) + + # Set observation container + self.obs(outobs) # Return return @@ -266,7 +261,7 @@ class csphagen(ctools.cscript): clobber = self['clobber'].boolean() # Loop over all observation in container - for obs in self._outobs: + for obs in self.obs(): # Set filenames if self['stack'].boolean(): @@ -274,7 +269,7 @@ class csphagen(ctools.cscript): offname = prefix + '_stacked_pha_off.fits' arfname = prefix + '_stacked_arf.fits' rmfname = prefix + '_stacked_rmf.fits' - elif self._outobs.size() > 1: + elif self.obs().size() > 1: onname = prefix + '_%s_pha_on.fits' % (obs.id()) offname = prefix + '_%s_pha_off.fits' % (obs.id()) arfname = prefix + '_%s_arf.fits' % (obs.id()) @@ -298,7 +293,7 @@ class csphagen(ctools.cscript): self._log_value(gammalib.NORMAL, 'RMF file', arfname) # Save observation definition XML file - self._outobs.save(outobs) + self.obs().save(outobs) # Log file name self._log_value(gammalib.NORMAL, 'Obs. definition XML file', outobs) @@ -326,12 +321,6 @@ class csphagen(ctools.cscript): # Return return - def obs(self): - """ - Return observation container - """ - return self._outobs - # ======================== # # Main routine entry point # diff --git a/cscripts/csresmap.py b/cscripts/csresmap.py index fd16675..ab286cc 100755 --- a/cscripts/csresmap.py +++ b/cscripts/csresmap.py @@ -27,7 +27,7 @@ import ctools # ============== # # csresmap class # # ============== # -class csresmap(ctools.cscript): +class csresmap(ctools.csobservation): """ Generates a residual map """ @@ -37,21 +37,14 @@ class csresmap(ctools.cscript): """ Constructor """ - # Set name - self._name = 'csresmap' - self._version = ctools.__version__ + # Initialise application by calling the appropriate class constructor + self._init_csobservation('csresmap', ctools.__version__, argv) # Initialise class members self._resmap = None self._use_maps = False self._skip_binning = False - # Initialise observation container from constructor arguments - self._obs, argv = self._set_input_obs(argv) - - # Initialise application by calling the appropriate class constructor - self._init_cscript(argv) - # Return return @@ -69,7 +62,7 @@ class csresmap(ctools.cscript): # if the "inobs" parameter is a counts cube. If the "inobs" parameter # represents a FITS file and if this FITS file is a counts cube then # set self._skip_binning=True - if self._obs.size() == 0 and self['inobs'].filename() != 'NONE': + if self.obs().size() == 0 and self['inobs'].filename() != 'NONE': filename = gammalib.GFilename(self['inobs'].filename()) if filename.is_fits(): cta = gammalib.GCTAObservation() @@ -88,20 +81,20 @@ class csresmap(ctools.cscript): if not self._use_maps: # Set observation if not done before - if self._obs.size() == 0: + if self.obs().size() == 0: self._require_inobs('csresmap.get_parameters()') - self._obs = self._get_observations() + self.obs(self._get_observations()) # If we have exactly one binned CTA observation then signal that # the binning can be skipped - if self._obs.size() == 1 and \ - self._obs[0].classname() == 'GCTAObservation' and \ - self._obs[0].eventtype() == 'CountsCube': + if self.obs().size() == 1 and \ + self.obs()[0].classname() == 'GCTAObservation' and \ + self.obs()[0].eventtype() == 'CountsCube': self._skip_binning = True # Set models if we have none - if self._obs.models().size() == 0: - self._obs.models(self['inmodel'].filename()) + if self.obs().models().size() == 0: + self.obs().models(self['inmodel'].filename()) # If no binning is provided in the observation then query now # the counts cube binning parameters @@ -153,7 +146,7 @@ class csresmap(ctools.cscript): self._get_parameters() # Write observation into logger - self._log_observations(gammalib.NORMAL, self._obs, 'Observation') + self._log_observations(gammalib.NORMAL, self.obs(), 'Observation') # If a counts and model cube are specified then load them as sky map if self._use_maps: @@ -166,7 +159,7 @@ class csresmap(ctools.cscript): # Do not build counts cube if we have already one in the observation # container if self._skip_binning: - cta_counts_cube = gammalib.GCTAEventCube(self._obs[0].events()) + cta_counts_cube = gammalib.GCTAEventCube(self.obs()[0].events()) # ... otherwise generate one now from the event list else: @@ -175,7 +168,7 @@ class csresmap(ctools.cscript): self._log_header1(gammalib.TERSE, 'Generate binned map (ctbin)') # Create countsmap - binning = ctools.ctbin(self._obs) + binning = ctools.ctbin(self.obs()) binning['xref'] = self['xref'].real() binning['yref'] = self['yref'].real() binning['proj'] = self['proj'].string() @@ -184,7 +177,7 @@ class csresmap(ctools.cscript): binning['nxpix'] = self['nxpix'].integer() binning['nypix'] = self['nypix'].integer() binning['binsz'] = self['binsz'].real() - if self['ebinalg'].string() == "FILE": + if self['ebinalg'].string() == 'FILE': binning['ebinfile'] = self['ebinfile'].filename().file() else: binning['enumbins'] = self['enumbins'].integer() @@ -205,7 +198,7 @@ class csresmap(ctools.cscript): self._log_header1(gammalib.TERSE, 'Generate model map (ctmodel)') # Create model map - model = ctools.ctmodel(self._obs) + model = ctools.ctmodel(self.obs()) model.cube(cta_counts_cube) model['chatter'] = self['chatter'].integer() model['clobber'] = self['clobber'].boolean() @@ -324,7 +317,7 @@ class csresmap(ctools.cscript): # Set default name is user name is empty if not name: - user_name = self._name + user_name = self._name() else: user_name = name @@ -342,7 +335,7 @@ class csresmap(ctools.cscript): Set model """ # Copy models - self._obs.models(models) + self.obs().models(models) # Return return diff --git a/cscripts/cssens.py b/cscripts/cssens.py index dd6ff23..f380784 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -596,7 +596,7 @@ class cssens(ctools.csobservation): self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') # Write models into logger - self._log_models(gammalib.TERSE, models, 'Input model') + self._log_models(gammalib.NORMAL, models, 'Input model') # Get sensitivity type sensitivity_type = self['type'].string() diff --git a/cscripts/csspec.py b/cscripts/csspec.py index 957826b..3f9518f 100755 --- a/cscripts/csspec.py +++ b/cscripts/csspec.py @@ -66,7 +66,7 @@ class csspec(ctools.csobservation): Get parameters from parfile and setup the observation """ # Set observation if not done before - if self.obs().size() == 0: + if self.obs().is_empty(): self._require_inobs('csspec::get_parameters()') self.obs(self._get_observations()) @@ -74,7 +74,7 @@ class csspec(ctools.csobservation): self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) # Set models if we have none - if self.obs().models().size() == 0: + if self.obs().models().is_empty(): self.obs().models(self['inmodel'].filename()) # Query source name diff --git a/cscripts/cstsdist.py b/cscripts/cstsdist.py index 1b8a481..6b4ebcc 100755 --- a/cscripts/cstsdist.py +++ b/cscripts/cstsdist.py @@ -227,7 +227,7 @@ class cstsdist(ctools.csobservation): self._log_observations(gammalib.NORMAL, self.obs(), 'Input observation') # Write models into logger - self._log_models(gammalib.TERSE, self.obs().models(), 'Input model') + self._log_models(gammalib.NORMAL, self.obs().models(), 'Input model') # Write header self._log_header1(gammalib.TERSE, 'Generate TS distribution') diff --git a/cscripts/cstsmapsplit.py b/cscripts/cstsmapsplit.py index ad8c322..9544074 100755 --- a/cscripts/cstsmapsplit.py +++ b/cscripts/cstsmapsplit.py @@ -28,7 +28,7 @@ import ctools # ================== # # cstsmapsplit class # # ================== # -class cstsmapsplit(ctools.cscript): +class cstsmapsplit(ctools.cslikelihood): """ Generates commands to split TS map computation @@ -44,10 +44,8 @@ class cstsmapsplit(ctools.cscript): """ Constructor """ - - # Set name and version - self._name = 'cstsmapsplit' - self._version = ctools.__version__ + # Initialise application by calling the appropriate class constructor + self._init_cslikelihood('cstsmapsplit', ctools.__version__, argv) # Set data members self._outmap = gammalib.GFilename() @@ -57,13 +55,6 @@ class cstsmapsplit(ctools.cscript): self._map = gammalib.GSkyMap() self._cmd = [] self._srcname = '' - - # Initialise observation container from constructor arguments. - self._obs, argv = self._set_input_obs(argv) - - # Initialise application by calling the appropriate class - # constructor. - self._init_cscript(argv) # Return return @@ -74,17 +65,16 @@ class cstsmapsplit(ctools.cscript): """ Get parameters from parfile and setup the observation """ - # If there are no observations in container then get some ... - if self._obs.size() == 0: - self._obs = self._get_observations() + if self.obs().size() == 0: + self.obs(self._get_observations()) # Set models if we have none - if self._obs.models().size() == 0: - self._obs.models(self['inmodel'].filename()) + if self.obs().models().size() == 0: + self.obs().models(self['inmodel'].filename()) # Get TS map paramters - self._map = self._create_map(self._obs) + self._map = self._create_map(self.obs()) self._srcname = self['srcname'].string() self._outmap = self['outmap'].filename() @@ -108,30 +98,29 @@ class cstsmapsplit(ctools.cscript): logl : float Log-likelihood of null hypothesis """ - # Store original models - models_orig = self._obs.models() + models_orig = self.obs().models() # Get models instance - models0 = self._obs.models() + models0 = self.obs().models() # Remove test source models0.remove(self._srcname) # Initialise optimizer - opt = gammalib.GOptimizerLM() + #opt = gammalib.GOptimizerLM() # Set models for null hypothesis - self._obs.models(models0) + self.obs().models(models0) # Optimise observation container - self._obs.optimize(opt) + self.obs().optimize(self.opt()) # Set original models to container - self._obs.models(models_orig) + self.obs().models(models_orig) # Return optimised log-likelihood of null hypothesis - return -(opt.value()) + return -(self.opt().value()) # Public methods @@ -147,12 +136,8 @@ class cstsmapsplit(ctools.cscript): self._get_parameters() # Write information into logger - if self._logTerse(): - self._log('\n') - self._log.header1('Test source') - model = self._obs.models()[self._srcname] - self._log(str(model)) - self._log('\n') + self._log_header1(gammalib.TERSE, 'Test source') + self._log_string(gammalib.TERSE, str(self.obs().models()[self._srcname])) # Set log-likelihood to zero logL0 = 0.0 @@ -161,9 +146,7 @@ class cstsmapsplit(ctools.cscript): if self._compute_null: # Write information into logger - if self._logTerse(): - self._log('\n') - self._log.header1('Compute null hypothesis') + self._log_header1(gammalib.TERSE, 'Compute null hypothesis') # Compute null hypothesis logL0 = self._compute_null_hypothesis() -- libgit2 0.21.4