33 Generates commands to split TS map computation
35 This class implements the creation of file containing commands to split
36 the computation of a TS map into several machines. It derives from
37 the ctools.cscript class which provides support for parameter files,
38 command line arguments, and logging. In that way the Python script
39 behaves just as a regular ctool.
48 self._init_cslikelihood(self.__class__.__name__, ctools.__version__, argv)
55 self.
_map = gammalib.GSkyMap()
66 Get parameters from parfile and setup the observation
69 if self.obs().size() == 0:
70 self.obs(self._get_observations())
73 if self.obs().models().size() == 0:
74 self.obs().models(self[
'inmodel'].filename())
77 self.
_map = self._create_map(self.obs())
78 self.
_srcname = self[
'srcname'].string()
79 self.
_outmap = self[
'outmap'].filename()
84 self.
_outfile = self[
'outfile'].filename()
87 self._log_parameters(gammalib.TERSE)
94 Compute null hypothesis
99 Log-likelihood of null hypothesis
102 models_orig = self.obs().models()
105 models0 = self.obs().models()
111 self.obs().models(models0)
114 self.obs().optimize(self.opt())
117 self.obs().models(models_orig)
120 return -(self.opt().value())
132 self._log_header1(gammalib.TERSE,
'Test source')
133 self._log_string(gammalib.TERSE, str(self.obs().models()[self.
_srcname]))
142 self._log_header1(gammalib.TERSE,
'Compute null hypothesis')
148 self._log_value(gammalib.TERSE,
'Source removed', self.
_srcname)
149 self._log_value(gammalib.TERSE,
'Log-likelihood', repr(logL0))
152 pars = gammalib.GApplicationPars(
'cttsmap.par')
155 nbins = self._map.npix()
156 njobs = int(math.ceil(float(nbins) / float(self.
_bins_per_job)) + 0.1)
159 skip_pars = [
'binmin',
'binmax',
'logL0',
'outmap',
'logfile']
162 base_command =
'cttsmap'
165 self._log_header1(gammalib.TERSE,
'Create commands')
166 self._log_value(gammalib.TERSE,
'Number of cttsmap calls', njobs)
172 if par.name()
in skip_pars:
176 if not self[par.name()].was_queried():
181 par.value(self[par.name()].value())
184 base_command +=
' ' + par.name() +
'=' + par.value()
187 base_command +=
' logL0=' + repr(logL0)
197 for job
in range(njobs):
200 outmap = self._outmap.url().replace(
'.fits',
'_'+str(job)+
'.fits')
209 sliced_command =
'%s binmin=%s binmax=%s outmap=%s logfile=%s' % \
210 (base_command, str(binmin), str(binmax),
211 outmap, outmap.replace(
'.fits',
'.log'))
214 if self[
'run_in_bkg'].boolean():
215 sliced_command +=
' &'
218 self._cmd.append(sliced_command)
221 if self._logExplicit():
223 self._log.header2(
'Commands')
224 for cmd
in self.
_cmd:
234 Save commands to ASCII file
237 filename = self._outfile.url()
240 f = open(filename,
'w')
243 for cmd
in self.
_cmd:
253 os.system(
'chmod +x %s' % filename)
262 if __name__ ==
'__main__':
def _compute_null_hypothesis