184 algorithm = self[
'phbinalg'].string()
188 if algorithm ==
'FILE':
191 filename = self[
'phbinfile'].filename()
197 csv = gammalib.GCsv(filename)
198 for i
in range(csv.nrows()):
199 phmin = csv.real(i,0)
200 phmax = csv.real(i,1)
201 phbins.append([phmin,phmax])
205 elif algorithm ==
'LIN':
208 nbins = self[
'phbins'].integer()
211 ph_step = 1.0 / float(nbins)
212 for i
in range(nbins):
214 phmax = (i+1) * ph_step
215 phbins.append([phmin,phmax])
242 Creates FITS binary table containing phase curve results
246 results : list of dict
247 List of result dictionaries
251 table : `~gammalib.GFitsBinTable`
252 FITS binary table containing phase curve
258 table = gammalib.GFitsBinTable(nrows)
259 table.extname(
'PHASECURVE')
262 ioutils.append_result_column(table, results,
'PHASE_MIN',
'',
'phmin')
263 ioutils.append_result_column(table, results,
'PHASE_MAX',
'',
'phmax')
266 ioutils.append_model_par_column(table, self.obs().models()[self.
_srcname],
351 Save phase fit results into one XML model each bin
354 self._log_header1(gammalib.TERSE,
'Save phase XML files')
357 outname = self[
'outfile'].filename()
363 phname = str(phbin[0])+
'-'+str(phbin[1])
364 replace_name =
'_phase_'+phname+
'.xml'
365 outname_phase = (outname.file()).replace(
'.fits', replace_name)
366 outfile = outname.path() + outname_phase
372 name =
'Phase [%s] file' % phname
373 self._log_value(gammalib.NORMAL, name, outfile)
380 Analyse one phase bin
384 phbin : list of float
389 self._log_header2(gammalib.TERSE,
'PHASE %f - %f' %
390 (phbin[0], phbin[1]))
393 select = ctools.ctselect(self.obs())
394 select[
'emin'] = self[
'emin'].real()
395 select[
'emax'] = self[
'emax'].real()
396 select[
'tmin'] =
'UNDEFINED'
397 select[
'tmax'] =
'UNDEFINED'
398 select[
'rad'] =
'UNDEFINED'
399 select[
'ra'] =
'UNDEFINED'
400 select[
'dec'] =
'UNDEFINED'
401 select[
'expr'] =
'PHASE>' + str(phbin[0]) +
' && PHASE<' + str(phbin[1])
405 phstr = str(phbin[0]) +
'-' + str(phbin[1])
408 for i
in range(0, select.obs().size()):
409 oldid = select.obs()[i].id()
410 select.obs()[i].id(oldid +
'_' + phstr)
415 obs = obsutils.get_onoff_obs(self, select.obs(), nthreads=1)
421 obs = obsutils.get_stacked_obs(self, select.obs())
424 self._log_header3(gammalib.EXPLICIT,
'Fitting the data')
433 like = ctools.ctlike(obs)
434 like[
'edisp'] = self[
'edisp'].boolean()
440 for model
in like.obs().models():
441 scaled_norm = model[
'Normalization'].value() / (phbin[1] - phbin[0])
442 model[
'Normalization'].value(scaled_norm)
445 fitmodels = like.obs().models().copy()
449 self._log_string(gammalib.TERSE,
450 'PHASE %f - %f: no observations available'
451 ' for fitting' % (phbin[0], phbin[1]))
454 fitmodels = gammalib.GModels()
457 result = {
'phstr': phstr,
'fitmodels': fitmodels}
472 self._log_observations(gammalib.NORMAL, self.obs(),
'Observation')
478 self._log_header1(gammalib.TERSE,
'Generate phase curve')
484 args = [(self,
'_phase_bin', phbin)
for phbin
in self.
_phbins]
485 poolresults = mputils.process(self.
_nthreads, mputils.mpfunc, args)
488 for i
in range(len(self.
_phbins)):
489 self.
_fitmodels[poolresults[i][0][
'phstr']] = poolresults[i][0][
'fitmodels']
490 self._log_string(gammalib.TERSE, poolresults[i][1][
'log'],
False)
496 self.
_fitmodels[result[
'phstr']] = result[
'fitmodels']
502 if self[
'publish'].boolean():