def _get_parameters(self): """ Get parameters from parfile and setup the observation """ # Set observation if not done before if self.obs().size() == 0: self.obs(self._get_observations()) # Set observation statistic self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) # Get source name self._srcname = self['srcname'].string() # Set models if we have none if self.obs().models().size() == 0: self.obs().models(self['inmodel'].filename()) # Query parameters self['edisp'].boolean() self['ntrials'].integer() self['debug'].boolean() self['outfile'].filename() # Write input parameters into logger self._log_parameters(gammalib.TERSE) # Set number of processes for multiprocessing self._nthreads = mputils.nthreads(self) # Return return
def _test_nthreads(self): """ Test nthreads() function """ # Set reference number of CPU's n0 = 1 n739 = 1 try: from multiprocessing import cpu_count n0 = cpu_count() n739 = 739 except: pass # Check nthreads=0. In this case the nthreads() function should return # the number of CPU's that are available, provided that the # multiprocessing module is available. If the module is not available # the function returns 1. cls, pars, cpy_pars = self._setup_mputils_test() pars.append( gammalib.GApplicationPar('nthreads', 'i', 'h', '0', '', '', '')) nthreads = mputils.nthreads(cls) self.test_value(nthreads, n0, 'Check nthreads=0') cls.pars(cpy_pars) # Check nthreads=739. In this case the nthreads() function should # return 739, provided that the multiprocessing module is available. # If the module is not available the function returns 1. cls, pars, cpy_pars = self._setup_mputils_test() pars.append( gammalib.GApplicationPar('nthreads', 'i', 'h', '739', '', '', '')) nthreads = mputils.nthreads(cls) self.test_value(nthreads, n739, 'Check nthreads=739') cls.pars(cpy_pars) # Return return
def _get_parameters(self): """ Get user parameters from parfile """ # Set observation if not done before if self.obs().size() == 0: self.obs(self._set_obs(self['emin'].real(), self['emax'].real())) # Set observation statistic self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) # Set models if we have none if self.obs().models().size() == 0: self.obs().models(self['inmodel'].filename()) # Get source name self._srcname = self['srcname'].string() # Read further parameters emin = self['emin'].real() emax = self['emax'].real() bins = self['bins'].integer() # Query parameters for binned if requested enumbins = self['enumbins'].integer() if not enumbins == 0: self['npix'].integer() self['binsz'].real() # Query input parameters self['sigma'].real() self['max_iter'].integer() self['type'].string() self['outfile'].filename() self['edisp'].boolean() self['debug'].boolean() # Derive some parameters self._ebounds = gammalib.GEbounds(bins, gammalib.GEnergy(emin, 'TeV'), gammalib.GEnergy(emax, 'TeV')) # Write input parameters into logger self._log_parameters(gammalib.TERSE) # Set number of processes for multiprocessing self._nthreads = mputils.nthreads(self) # Return return
def _get_parameters(self): """ Get parameters from parfile """ # Setup observations (require response and allow event list, don't # allow counts cube) self._setup_observations(self.obs(), True, True, False) # Set observation statistic self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) # Set models if there are none in the container if self.obs().models().size() == 0: self.obs().models(self['inmodel'].filename()) # Get phase boundaries self._phbins = self._create_tbounds() # Set On/Off analysis flag and query relevant user parameters self._onoff = self._is_onoff() # Get source name self._srcname = self['srcname'].string() # If cube analysis is selected # Set stacked analysis flag and query relevant user parameters if not self._onoff: self._stacked = self._is_stacked() # Query the hidden parameters, just in case self['edisp'].boolean() # Read ahead output parameters if self._read_ahead(): self['outfile'].filename() # Write input parameters into logger self._log_parameters(gammalib.TERSE) # Set number of processes for multiprocessing self._nthreads = mputils.nthreads(self) # Return return
def _get_parameters(self): """ Get parameters from parfile and setup the observation """ # Set observation if not done before if self.obs().is_empty(): self._require_inobs('csspec::get_parameters()') self.obs(self._get_observations()) # Set observation statistic self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) # Set models if we have none if self.obs().models().is_empty(): self.obs().models(self['inmodel'].filename()) # Query source name self['srcname'].string() # Get spectrum generation method self._method = self['method'].string() # Collect number of unbinned, binned and On/Off observations in # observation container n_unbinned = 0 n_binned = 0 n_onoff = 0 for obs in self.obs(): if obs.classname() == 'GCTAObservation': if obs.eventtype() == 'CountsCube': n_binned += 1 else: n_unbinned += 1 elif obs.classname() == 'GCTAOnOffObservation': n_onoff += 1 n_cta = n_unbinned + n_binned + n_onoff n_other = self.obs().size() - n_cta # If spectrum method is not "NODES" then set spectrum method and # script mode according to type of observations if self._method != 'NODES': if n_other > 0: self._method = 'NODES' else: if n_unbinned == 0 and n_binned != 0 and n_onoff == 0: self._binned_mode = True self._method = 'SLICE' elif n_unbinned == 0 and n_binned == 0 and n_onoff != 0: self._onoff_mode = True self._method = 'SLICE' elif n_unbinned == 0 and n_binned != 0 and n_onoff != 0: msg = 'Mix of binned and On/Off CTA observations found ' \ 'in observation container. csscript does not support ' \ 'this mix.' raise RuntimeError(msg) elif n_unbinned != 0 and (n_binned != 0 or n_onoff != 0): msg = 'Mix of unbinned and binned or On/Off CTA observations ' \ 'found in observation container. csscript does not ' \ 'support this mix.' raise RuntimeError(msg) elif n_unbinned != 0: self._method = 'SLICE' # Set ebounds self._set_ebounds() # Query other parameeters self['edisp'].boolean() self['calc_ulim'].boolean() self['calc_ts'].boolean() self['fix_bkg'].boolean() self['fix_srcs'].boolean() # Read ahead output parameters if self._read_ahead(): self['outfile'].filename() # Write input parameters into logger self._log_parameters(gammalib.TERSE) # Set number of processes for multiprocessing self._nthreads = mputils.nthreads(self) # Write spectrum method header and parameters self._log_header1(gammalib.TERSE, 'Spectrum method') self._log_value(gammalib.TERSE, 'Unbinned CTA observations', n_unbinned) self._log_value(gammalib.TERSE, 'Binned CTA observations', n_binned) self._log_value(gammalib.TERSE, 'On/off CTA observations', n_onoff) self._log_value(gammalib.TERSE, 'Other observations', n_other) # If there are a mix of CTA and non-CTA observations and the method # is 'SLICE' then log a warning that non-CTA observations will be # ignored warning = False if n_cta > 0 and n_other > 0 and self._method == 'SLICE': warning = True # If there are only non-CTA observations and the method is 'SLICE' # then stop now elif n_other > 0: if self._method == 'SLICE': msg = 'Selected "SLICE" method but none of the observations ' \ 'is a CTA observation. Please select "AUTO" or "NODES" ' \ 'if no CTA observation is provided.' raise RuntimeError(msg) else: self._method = 'NODES' # Log selected spectrum method self._log_value(gammalib.TERSE, 'Selected spectrum method', self._method) # Signal warning if warning: self._log_string( gammalib.TERSE, ' WARNING: Only CTA observation ' 'can be handled with the "SLICE" method, all ' 'non-CTA observation will be ignored.') # Return return
def _get_parameters(self): """ Get parameters and setup the observation """ # Set observation if not done before if self.obs().is_empty(): self._require_inobs('csdmatter::get_parameters') self.obs(self._get_observations()) # Set Obs statistic self._set_obs_statistic(gammalib.toupper(self['statistic'].string())) # Set Models if self.obs().models().is_empty(): self.obs().models(self['inmodel'].filename()) # Query source name self['srcname'].string() # Collect number of unbinned, binned and OnOff obs # in observation container n_unbinned = 0 n_binned = 0 n_onoff = 0 for obs in self.obs(): if obs.classname() == 'GCTAObservation': if obs.eventtype() == 'CountsCube': n_binned += 1 else: n_unbinned += 1 elif obs.classname() == 'GCTAOnOffObservation': n_onoff += 1 n_cta = n_unbinned + n_binned + n_onoff n_other = self.obs().size() - n_cta # Set energy bounds self._set_ebounds() # Query other parameters self['edisp'].boolean() self['calc_ulim'].boolean() self['calc_ts'].boolean() self['fix_bkg'].boolean() self['fix_srcs'].boolean() # self[ 'dmass' ].real() # self[ 'sigmav' ].real() # Read ahead output parameters if self._read_ahead(): self['outfile'].filename() # Write into logger self._log_parameters(gammalib.TERSE) # Set number of processes for multiprocessing self._nthreads = mputils.nthreads(self) self._log_header1(gammalib.TERSE, 'DM analysis') self._log_value(gammalib.TERSE, 'Unbinned observations', n_unbinned) self._log_value(gammalib.TERSE, 'Binned observations', n_binned) self._log_value(gammalib.TERSE, 'OnOff Observations', n_onoff) self._log_value(gammalib.TERSE, 'NonCTA Observations', n_other) if n_other == 0: if n_unbinned == 0 and n_binned != 0 and n_onoff == 0: self._binned_mode = True elif n_unbinned == 0 and n_binned == 0 and n_onoff != 0: self._onoff_mode = True elif n_unbinned == 0 and n_binned != 0 and n_onoff != 0: msg = 'Mixing of binned and OnOff Observations' raise RuntimeError(msg) elif n_unbinned != 0 and (n_binned != 0 or n_onoff != 0): msg = 'Mixing of different CTA Observations' raise RuntimeError(msg) else: msg = 'csdmatter only supports CTA-observations' raise RuntimeError(msg) return
def _get_parameters(self): """ Get parameters from parfile and setup observations """ # Clear source models self._models.clear() # Setup observations (require response and allow event list, don't # allow counts cube) self._setup_observations(self.obs(), True, True, False) # Get source model and source name. First try to extract models from # observation container. If this does not work then try creating # model from the inmodel parameter if self.obs().models().size() > 0: self._models = self.obs().models().clone() self._srcname = self['srcname'].string() elif self['inmodel'].is_valid(): inmodel = self['inmodel'].filename() self._models = gammalib.GModels(inmodel) self._srcname = self['srcname'].string() # Set energy bounds self._ebounds = self._create_ebounds() # Initialize empty src regions container self._src_reg = gammalib.GSkyRegions() # Exclusion map if self['inexclusion'].is_valid(): inexclusion = self['inexclusion'].filename() self._excl_reg = gammalib.GSkyRegionMap(inexclusion) self._has_exclusion = True else: self._has_exclusion = False # Query remaining parameters self['use_model_bkg'].boolean() self['stack'].boolean() # Query ahead output parameters if (self._read_ahead()): self['outobs'].filename() self['outmodel'].filename() self['prefix'].string() # If there are no observations in container then get them from the # parameter file if self.obs().is_empty(): self.obs(self._get_observations(False)) # Get background method parameters (have to come after setting up of # observations) self._get_parameters_bkgmethod() # Write input parameters into logger self._log_parameters(gammalib.TERSE) # Set number of processes for multiprocessing self._nthreads = mputils.nthreads(self) # If we have no model then create now a dummy model if self._models.is_empty(): spatial = gammalib.GModelSpatialPointSource(self._src_dir) spectral = gammalib.GModelSpectralPlaw( 1.0e-18, -2.0, gammalib.GEnergy(1.0, 'TeV')) model = gammalib.GModelSky(spatial, spectral) model.name('Dummy') self._models.append(model) self._srcname = 'Dummy' self['use_model_bkg'].boolean(False) # Return return