def gtexpcube2(self,mode): gtexpcube2 = GtApp('gtexpcube2') if mode=='_expcube_': nx=400 ny=400 elif mode=='_allsky_': nx=1800 ny=900 gtexpcube2.run( infile=self.srcName+'_ltcube_'+self.phaseMin+'_'+self.phaseMax+'.fits', outfile=self.srcName+mode+self.phaseMin+'_'+self.phaseMax+'.fits', cmap='none', irfs=self.irfs, nxpix=nx, nypix=ny, binsz='0.2', coordsys ='CEL', xref=self.RA, yref=self.DEC, axisrot='0', proj='AIT', emin=self.EMIN, emax=self.EMAX, enumbins=self.EBIN)
def gtselect(self, phased, pulsarMode): if pulsarMode: if phased: phMin = self.phaseMin phMax = self.phaseMax outputFile = self.srcName + '_gti_' + self.phaseMin + '_' + self.phaseMax + '.fits' evfile = self.srcName + '_gti.fits' else: phMin = 0 phMax = 0 evfile = '@events.txt' outputFile = self.srcName + '_filtered.fits' else: outputFile = self.srcName + '_filtered.fits' evfile = '@events.txt' phMin = 0 phMax = 0 gtselect = GtApp('gtselect') gtselect.run(evclass=2, infile=evfile, outfile=outputFile, ra=self.RA, dec=self.DEC, rad=self.ROI, emin=self.EMIN, emax=self.EMAX, zmax=self.ZMAX, phasemin=phMin, phasemax=phMax, tmin='0', tmax='0')
class SrcModelTask(Task): default_config = { 'srcmaps' : None, 'srcmdl' : None, 'expcube' : None, 'bexpmap' : None, 'srcmdl' : None, 'chatter' : 2, 'irfs' : None, 'outtype' : 'ccube' } def __init__(self,outfile,config=None,opts=None,**kwargs): super(SrcModelTask,self).__init__(config,opts=opts,**kwargs) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtmodel') def run_task(self): outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile,**self.config)
class MkTimeTask(Task): default_config = { 'roicut': 'no', 'filter': 'IN_SAA!=T&&DATA_QUAL==1&&LAT_CONFIG==1&&ABS(ROCK_ANGLE)<52', 'evfile': None, 'scfile': None } def __init__(self, infile, outfile, config=None, **kwargs): super(MkTimeTask, self).__init__() self.update_default_config(MkTimeTask) self.configure(config, subsection='gtmktime', **kwargs) self._infile = os.path.abspath(infile) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtmktime', 'dataSubselector') def run_task(self): config = self.config outfile = os.path.basename(self._output_files[0]) self._gtapp.run(evfile=self._infile, outfile=outfile, filter=config['filter'], roicut=config['roicut'], scfile=config['scfile'])
class MkTimeTask(Task): default_config = { 'roicut' : 'no', 'filter' : 'IN_SAA!=T&&DATA_QUAL==1&&LAT_CONFIG==1&&ABS(ROCK_ANGLE)<52', 'evfile' : None, 'scfile' : None } def __init__(self,infile,outfile,config=None,**kwargs): super(MkTimeTask,self).__init__() self.update_default_config(MkTimeTask) self.configure(config,subsection='gtmktime',**kwargs) self._infile = os.path.abspath(infile) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp=GtApp('gtmktime','dataSubselector') def run_task(self): config = self.config outfile = os.path.basename(self._output_files[0]) self._gtapp.run(evfile=self._infile, outfile=outfile, filter=config['filter'], roicut=config['roicut'], scfile=config['scfile'])
class SrcMapTask(Task): default_config = { 'scfile' : None, 'expcube' : None, 'bexpmap' : None, 'cmap' : None, 'srcmdl' : None, 'chatter' : 2, 'irfs' : None, 'resample' : 'yes', 'rfactor' : 2, 'minbinsz' : 0.1 } def __init__(self,outfile,config=None,**kwargs): super(SrcMapTask,self).__init__() self.update_default_config(SrcMapTask) self.configure(config,subsection='gtsrcmaps',**kwargs) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtsrcmaps','Likelihood') def run_task(self): config = self.config outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile,emapbnds='no',**config)
class LTCubeTask(Task): default_config = { 'dcostheta': 0.025, 'binsz': 1.0, 'evfile': None, 'scfile': (None, 'spacecraft file'), 'tmin': 0.0, 'tmax': 0.0, 'zmax': (100.0, 'Set the maximum zenith angle.') } def __init__(self, outfile, config=None, opts=None, **kwargs): super(LTCubeTask, self).__init__(config, opts=opts, **kwargs) self._config['scfile'] = os.path.abspath(self._config['scfile']) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtltcube') def run_task(self): outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile, **self.config)
def cmap(roi,like,ft1,ft2,cmap=None,ccube=None,npix=100,binsz=0.1,proj="ZEA"): if like.coordsystem==SkyDir.GALACTIC: x,y,coordsys_str=roi.roi_dir.l(),roi.roi_dir.b(),'GAL' else: x,y,coordsys_str=roi.roi_dir.ra(),roi.roi_dir.dec(),'CEL' if cmap is not None : gtbin=GtApp('gtbin','evtbin') gtbin.run(algorithm='cmap', nxpix=npix, nypix=npix, binsz=binsz, evfile=ft1, outfile=cmap, scfile=ft2, xref=x, yref=y, axisrot=0, proj=proj, coordsys=coordsys_str) if ccube is not None: gtbin=GtApp('gtbin','evtbin') gtbin.run(algorithm='ccube', nxpix=npix, nypix=npix, binsz=like.binsz, evfile=ft1, outfile=ccube, scfile=ft2, xref=x, yref=y, axisrot=0, proj=proj, ebinalg='LOG', emin=like.emin, emax=like.emax, enumbins=like.enumbins, coordsys=coordsys_str)
def FindSource(self): """Run the gtfindsrc tool""" outfile = utils._dump_findsrcout(self.Configuration) if (self.clobber == "no" and os.path.isfile(outfile)): #print("File exists and clobber is False") return (0) findsrc = GtApp('gtfindsrc', 'Likelihood') findsrc['evfile'] = self.mktimefile findsrc['scfile'] = self.ft2 if self.irfs != 'CALDB': findsrc['evtype'] = self.Configuration['event']['evtype'] else: findsrc['evtype'] = 'INDEF' findsrc['irfs'] = self.irfs findsrc['expcube'] = self.Cubename findsrc['expmap'] = self.Mapname findsrc['srcmdl'] = utils._dump_xml(self.Configuration) findsrc['coordsys'] = self.Configuration['space']['coordsys'] findsrc['target'] = self.srcname findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"] findsrc['ftol'] = self.Configuration["fitting"]["ftol"] findsrc['clobber'] = self.clobber findsrc['reopt'] = self.Configuration["findsrc"]["Refit"] findsrc['outfile'] = outfile findsrc.run()
class SrcModelTask(Task): default_config = { 'srcmaps': None, 'srcmdl': None, 'expcube': None, 'bexpmap': None, 'srcmdl': None, 'chatter': 2, 'irfs': None, 'outtype': 'ccube' } def __init__(self, outfile, config=None, opts=None, **kwargs): super(SrcModelTask, self).__init__(config, opts=opts, **kwargs) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtmodel') def run_task(self): outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile, **self.config)
def FindSource(self): """Run the gtfindsrc tool""" outfile = utils._dump_findsrcout(self.Configuration) if (self.clobber=="no" and os.path.isfile(outfile)): #print("File exists and clobber is False") return(0) findsrc = GtApp('gtfindsrc', 'Likelihood') findsrc['evfile'] = self.mktimefile findsrc['scfile'] = self.ft2 if self.irfs != 'CALDB': findsrc['evtype']= self.Configuration['event']['evtype'] else : findsrc['evtype']= 'INDEF' findsrc['irfs'] = self.irfs findsrc['expcube'] = self.Cubename findsrc['expmap'] = self.Mapname findsrc['srcmdl'] = utils._dump_xml( self.Configuration) findsrc['coordsys'] = self.Configuration['space']['coordsys'] findsrc['target'] = self.srcname findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"] findsrc['ftol'] = self.Configuration["fitting"]["ftol"] findsrc['clobber'] = self.clobber findsrc['reopt'] = self.Configuration["findsrc"]["Refit"] findsrc['outfile'] = outfile findsrc.run()
class SrcMapTask(Task): default_config = { 'scfile': None, 'expcube': None, 'bexpmap': None, 'cmap': None, 'srcmdl': None, 'chatter': 2, 'irfs': None, 'resample': 'yes', 'rfactor': 2, 'minbinsz': 0.1 } def __init__(self, outfile, config=None, **kwargs): super(SrcMapTask, self).__init__() self.configure(config, **kwargs) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtsrcmaps', 'Likelihood') def run_task(self): config = self.config outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile, emapbnds='no', **config)
def gtexpcube2(self, mode): gtexpcube2 = GtApp('gtexpcube2') if mode == '_expcube_': nx = 400 ny = 400 elif mode == '_allsky_': nx = 1800 ny = 900 gtexpcube2.run(infile=self.srcName + '_ltcube_' + self.phaseMin + '_' + self.phaseMax + '.fits', outfile=self.srcName + mode + self.phaseMin + '_' + self.phaseMax + '.fits', cmap='none', irfs=self.irfs, nxpix=nx, nypix=ny, binsz='0.2', coordsys='CEL', xref=self.RA, yref=self.DEC, axisrot='0', proj='AIT', emin=self.EMIN, emax=self.EMAX, enumbins=self.EBIN)
def gtselect(self, phased, pulsarMode): if pulsarMode: if phased: phMin=self.phaseMin phMax=self.phaseMax outputFile = self.srcName+'_gti_'+self.phaseMin+'_'+self.phaseMax+'.fits' evfile=self.srcName+'_gti.fits' else: phMin=0 phMax=0 evfile='@events.txt' outputFile = self.srcName+'_filtered.fits' else: outputFile = self.srcName+'_filtered.fits' evfile='@events.txt' phMin=0 phMax=0 gtselect = GtApp('gtselect') gtselect.run( evclass=2, infile=evfile, outfile=outputFile, ra=self.RA, dec=self.DEC, rad=self.ROI, emin=self.EMIN, emax=self.EMAX, zmax=self.ZMAX, phasemin=phMin, phasemax=phMax, tmin='0', tmax='0')
class BinTask(Task): default_config = { 'nxpix': 140, 'nypix': None, 'xref': 0.0, 'yref': 0.0, 'emin': 1000.0, 'emax': 100000.0, 'scfile': None, 'chatter': 2, 'proj': 'AIT', 'hpx_order': 3, 'enumbins': 16, 'algorithm': 'ccube', 'binsz': 0.1, 'coordsys': 'CEL' } def __init__(self, infile, outfile, config=None, opts=None, **kwargs): super(BinTask, self).__init__() self.configure(config, opts=opts, **kwargs) self._infile = os.path.abspath(infile) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) if re.search('^(?!\@)(.+)(\.txt|\.lst)$', self._infile): self._infile = '@' + self._infile self._gtbin = GtApp('gtbin', 'evtbin') def run_task(self): config = copy.deepcopy(self.config) outfile = os.path.basename(self._output_files[0]) if config['nypix'] is None: config['nypix'] = config['nxpix'] self._gtbin.run(algorithm=config['algorithm'], nxpix=config['nxpix'], nypix=config['nypix'], binsz=config['binsz'], hpx_order=config['hpx_order'], evfile=self._infile, outfile=outfile, scfile=config['scfile'], xref=config['xref'], yref=config['yref'], axisrot=0, proj=config['proj'], ebinalg='LOG', emin=config['emin'], emax=config['emax'], enumbins=config['enumbins'], coordsys=config['coordsys'], chatter=config['chatter'])
def GtExposure(self): exposure = GtApp("gtexposure", "Likelihood") exposure["infile"] = self.lcfile exposure["scfile"] = self.ft2 exposure["irfs"] = self.irfs exposure["srcmdl"] = "none" exposure["specin"] = -self.Configuration["AppLC"]["index"] exposure.run()
def gtltcube(self): gtltcube = GtApp('gtltcube') gtltcube.run( evfile =self.srcName+'_gti_'+self.phaseMin+'_'+self.phaseMax+'.fits', scfile =self.scfile, outfile =self.srcName+'_ltcube_'+self.phaseMin+'_'+self.phaseMax+'.fits', dcostheta = '0.025', binsz = '1')
def GtExposure(self): exposure = GtApp('gtexposure', 'Likelihood') exposure['infile'] = self.lcfile exposure['scfile'] = self.ft2 exposure['irfs'] = self.irfs exposure['srcmdl'] = "none" exposure['specin'] = -self.Configuration['AppLC']['index'] exposure.run()
class BinTask(Task): default_config = { 'nxpix' : 140, 'nypix' : None, 'xref' : 0.0, 'yref' : 0.0, 'emin' : 1000.0, 'emax' : 100000.0, 'scfile' : None, 'chatter' : 2, 'proj' : 'AIT', 'hpx_order' : 3, 'enumbins' : 16, 'algorithm' : 'ccube', 'binsz' : 0.1, 'coordsys' : 'CEL'} def __init__(self,infile,outfile,config=None,opts=None,**kwargs): super(BinTask,self).__init__() self.configure(config,opts=opts,subsection='gtbin',**kwargs) self._infile = os.path.abspath(infile) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) if re.search('^(?!\@)(.+)(\.txt|\.lst)$',self._infile): self._infile = '@'+self._infile self._gtbin=GtApp('gtbin','evtbin') def run_task(self): config = copy.deepcopy(self.config) outfile = os.path.basename(self._output_files[0]) if config['nypix'] is None: config['nypix'] = config['nxpix'] self._gtbin.run(algorithm=config['algorithm'], nxpix=config['nxpix'], nypix=config['nypix'], binsz=config['binsz'], hpx_order=config['hpx_order'], evfile=self._infile, outfile=outfile, scfile=config['scfile'], xref=config['xref'], yref=config['yref'], axisrot=0, proj=config['proj'], ebinalg='LOG', emin=config['emin'], emax=config['emax'], enumbins=config['enumbins'], coordsys=config['coordsys'], chatter=config['chatter'])
def GtExposure(self): exposure = GtApp('gtexposure', 'Likelihood') exposure['infile'] = self.lcfile exposure['scfile'] = self.ft2 exposure['irfs'] = self.irfs exposure['srcmdl'] = "none" exposure['specin'] = -self.Configuration['AppLC']['index'] exposure['clobber'] = self.clobber exposure.run()
def GtBinDef(self, filename): if (self.clobber == "no" and os.path.isfile(self.BinDef)): #print("File exists and clobber is False") return (0) bindef = GtApp('gtbindef', 'Likelihood') bindef['bintype'] = 'T' bindef['binfile'] = filename bindef['outfile'] = self.BinDef bindef.run()
def GtBinDef(self,filename): if (self.clobber=="no" and os.path.isfile(self.BinDef)): #print("File exists and clobber is False") return(0) bindef = GtApp('gtbindef', 'Likelihood') bindef['bintype'] = 'T' bindef['binfile'] = filename bindef['outfile'] = self.BinDef bindef.run()
def gtltcube(self): gtltcube = GtApp('gtltcube') gtltcube.run(evfile=self.srcName + '_gti_' + self.phaseMin + '_' + self.phaseMax + '.fits', scfile=self.scfile, outfile=self.srcName + '_ltcube_' + self.phaseMin + '_' + self.phaseMax + '.fits', dcostheta='0.025', binsz='1')
class SelectorTask(Task): default_config = { 'ra': 0.0, 'dec': 0.0, 'radius': 180.0, 'tmin': 0.0, 'tmax': 0.0, 'zmax': 100., 'emin': 10., 'emax': 1000000., 'chatter': 2, 'evclsmin': 'INDEF', 'evclass': 'INDEF', 'evtype': 'INDEF', 'convtype': -1 } def __init__(self, infile, outfile, config=None, opts=None, **kwargs): super(SelectorTask, self).__init__() self.configure(config, opts=opts, **kwargs) self._infile = os.path.abspath(infile) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) # if re.search('^(?!\@)(.+)\.txt$',self._infile): if re.search('^(?!\@)(.+)(\.txt|\.lst)$', self._infile): self._infile = '@' + self._infile self._gtselect = GtApp('gtselect', 'dataSubselector') def run_task(self): config = self.config outfile = os.path.basename(self._output_files[0]) # print self._infile # os.system('cat ' + self._infile[1:]) self._gtselect.run( infile=self._infile, outfile=outfile, ra=config['ra'], dec=config['dec'], rad=config['radius'], tmin=config['tmin'], tmax=config['tmax'], emin=config['emin'], emax=config['emax'], zmax=config['zmax'], chatter=config['chatter'], evclass=config['evclass'], # Only for Pass7 evtype=config['evtype'], convtype=config['convtype']) # Only for Pass6
def gtpphase(self, ephemeris, srcName, pulsarMode): if pulsarMode: gtpphase = GtApp('gtpphase') gtpphase.run(chatter='4', evfile=self.srcName + '_gti.fits', scfile=self.scfile, psrdbfile=ephemeris, psrname=srcName, ephstyle='DB', solareph='JPL DE200')
def GtBinnedMap(self): """Run the gtexpcube2 tool for binned analysis""" expcube2 = GtApp('gtexpcube2', 'Likelihood') expcube2['infile'] = self.Cubename expcube2['outfile'] = self.BinnedMapfile expcube2['cmap'] = self.ccube expcube2['irfs'] = self.irfs expcube2['emin'] = self.Emin expcube2['emax'] = self.Emax expcube2.run()
def GtBinnedMap(self): """Run the gtexpcube2 tool for binned analysis""" expcube2 = GtApp("gtexpcube2", "Likelihood") expcube2["infile"] = self.Cubename expcube2["outfile"] = self.BinnedMapfile expcube2["cmap"] = self.ccube expcube2["irfs"] = self.irfs expcube2["emin"] = self.Emin expcube2["emax"] = self.Emax expcube2.run()
def gtpphase(self, ephemeris, srcName, pulsarMode): if pulsarMode: gtpphase = GtApp('gtpphase') gtpphase.run( chatter='4', evfile=self.srcName+'_gti.fits', scfile=self.scfile, psrdbfile=ephemeris, psrname=srcName, ephstyle='DB', solareph='JPL DE200')
def SrcProb(self): """Run the gtsrcprob tool""" srcprob = GtApp('gtsrcprob', 'Likelihood') srcprob['evfile'] = self.eventfile srcprob['scfile'] = self.ft2 srcprob['irfs'] = self.irfs srcprob['srcmdl'] = self.xmlfile srcprob['outfile'] = self.Probfile srcprob['srclist'] = self.Configuration['srcprob']['srclist'] srcprob['clobber'] = self.clobber srcprob.run()
def GtBinnedMap(self): """Run the gtexpcube2 tool for binned analysis""" expcube2 = GtApp('gtexpcube2', 'Likelihood') expcube2['infile'] = self.Cubename expcube2['outfile'] = self.BinnedMapfile expcube2['cmap'] = self.ccube expcube2['irfs'] = self.irfs expcube2['emin'] = self.Emin expcube2['emax'] = self.Emax expcube2['clobber'] = self.clobber expcube2.run()
def gtsrcmaps(self, model): gtsrcmaps = GtApp('gtsrcmaps') gtsrcmaps.run( scfile=self.scfile, expcube=self.srcName+'_ltcube_'+self.phaseMin+'_'+self.phaseMax+'.fits', cmap=self.srcName+'_ccube_'+self.phaseMin+'_'+self.phaseMax+'.fits', srcmdl=model, bexpmap=self.srcName+'_allsky_'+self.phaseMin+'_'+self.phaseMax+'.fits', outfile=self.srcName+'_scrmap_'+self.phaseMin+'_'+self.phaseMax+'.fits', irfs=self.irfs, chatter='4', emapbnds="no")
def GtExposure(self): exposure = GtApp('gtexposure', 'Likelihood') exposure['infile'] = self.lcfile exposure['scfile'] = self.ft2 exposure['target'] = self.srcname if self.Configuration['event']['irfs'] != 'CALDB': exposure['evtype']= self.Configuration['event']['evtype'] exposure['irfs'] = self.irfs exposure['srcmdl'] = "none" exposure['specin'] = -self.Configuration['AppLC']['index'] exposure['clobber'] = self.clobber exposure.run()
def GtBinnedMap(self): """Run the gtexpcube2 tool for binned analysis""" expcube2 = GtApp('gtexpcube2', 'Likelihood') expcube2['infile'] = self.Cubename expcube2['outfile'] = self.BinnedMapfile expcube2['cmap'] = self.ccube expcube2['irfs'] = self.irfs expcube2['emin'] = self.Emin expcube2['emax'] = self.Emax expcube2['coordsys'] = self.Configuration['space']['coordsys'] expcube2['proj'] = self.Configuration['space']['proj'] #"AIT" expcube2['clobber'] = self.clobber expcube2.run()
def merge_LAT_data(ft1s, destination_directory: str = ".", outfile: str = 'ft1_merged.fits', Emin: float = 30.0, Emax: float = 1e6) -> Path: outfile: Path = Path(destination_directory) / outfile if outfile.exists(): log.warning( f"Existing merged event file {outfile} correspond to the same selection. " "We assume you did not tamper with it, so we will return it instead of merging it again. " "If you want to redo the FT1 file again, remove it from the outdir" ) return outfile if len(ft1s) == 1: log.warning('Only one FT1 file provided. Skipping the merge...') import shutil shutil.copyfile(ft1s[0], outfile) return outfile _filelist = "_filelist.txt" infile: Path = Path(destination_directory) / _filelist infile_list = infile.open('w') for ft1 in ft1s: infile_list.write(str(ft1) + '\n') infile_list.close() from GtApp import GtApp gtselect = GtApp('gtselect') gtselect['infile'] = '@' + str(infile) gtselect['outfile'] = str(outfile) gtselect['ra'] = 'INDEF' gtselect['dec'] = 'INDEF' gtselect['rad'] = 'INDEF' gtselect['tmin'] = 'INDEF' gtselect['tmax'] = 'INDEF' gtselect['emin'] = '%.3f' % Emin gtselect['emax'] = '%.3f' % Emax gtselect['zmax'] = 180 gtselect.run() return outfile
class SelectorTask(Task): default_config = { 'ra' : 0.0, 'dec' : 0.0, 'radius' : 180.0, 'tmin' : 0.0, 'tmax' : 0.0, 'zmax' : 100., 'emin' : 10., 'emax' : 1000000., 'chatter' : 2, 'evclsmin' : 'INDEF', 'evclass' : 'INDEF', 'evtype' : 'INDEF', 'convtype' : -1 } def __init__(self,infile,outfile,config=None,opts=None,**kwargs): super(SelectorTask,self).__init__() self.configure(config,opts=opts,**kwargs) self._infile = os.path.abspath(infile) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) # if re.search('^(?!\@)(.+)\.txt$',self._infile): if re.search('^(?!\@)(.+)(\.txt|\.lst)$',self._infile): self._infile = '@'+self._infile self._gtselect=GtApp('gtselect','dataSubselector') def run_task(self): config = self.config outfile = os.path.basename(self._output_files[0]) # print self._infile # os.system('cat ' + self._infile[1:]) self._gtselect.run(infile=self._infile, outfile=outfile, ra=config['ra'], dec=config['dec'], rad=config['radius'], tmin=config['tmin'], tmax=config['tmax'], emin=config['emin'], emax=config['emax'], zmax=config['zmax'], chatter=config['chatter'], evclass=config['evclass'], # Only for Pass7 evtype=config['evtype'], convtype=config['convtype']) # Only for Pass6
def gtmktime(self, pulsarMode): if pulsarMode: outputFile=self.srcName+'_filtered.fits' else: outputFile = self.srcName+'_gti_'+self.phaseMin+'_'+self.phaseMax+'.fits' gtmktime = GtApp('gtmktime') gtmktime.run( scfile=self.scfile, evfile=self.srcName+'_filtered.fits', outfile=outputFile, filter='DATA_QUAL==1 && LAT_CONFIG==1 && ABS(ROCK_ANGLE)<52', roicut='yes')
def gtmktime(self, pulsarMode): if pulsarMode: outputFile = self.srcName + '_filtered.fits' else: outputFile = self.srcName + '_gti_' + self.phaseMin + '_' + self.phaseMax + '.fits' gtmktime = GtApp('gtmktime') gtmktime.run( scfile=self.scfile, evfile=self.srcName + '_filtered.fits', outfile=outputFile, filter='DATA_QUAL==1 && LAT_CONFIG==1 && ABS(ROCK_ANGLE)<52', roicut='yes')
def _gtbin_lc(self, dtime): from GtApp import GtApp gtbin = GtApp('gtbin') gtbin['algorithm'] = 'LC' gtbin['tbinalg'] = 'LIN' gtbin['evfile'] = self.ft1File gtbin['outfile'] = 'lc.fits' gtbin['tstart'] = self.tstart gtbin['tstop'] = self.tstop gtbin['dtime'] = dtime gtbin['chatter'] = 0 gtbin.run() lc = FitsNTuple('lc.fits', 'RATE') return lc.COUNTS
def GtPSF(self): Nbdecade = log10(self.Emax)-log10(self.Emin)#Compute the number of decade irfs,_ = utils.GetIRFS(self.Configuration['event']['evclass'],self.Configuration['event']['evtype']) psf = GtApp('gtpsf', 'Likelihood') psf["expcube"] = self.Cubename psf["outfile"] = self.psf psf["irfs"] = irfs psf["evtype"] = self.Configuration['event']['evtype'] psf["ra"] = self.ra psf["dec"] = self.dec psf["emin"] = self.Emin psf["emax"] = self.Emax psf["nenergies"] = int(Nbdecade*self.Configuration['energy']['enumbins_per_decade']) psf["thetamax"] = 5. psf.run()
def SrcProb(self): """Run the gtsrcprob tool""" srcprob = GtApp('gtsrcprob', 'Likelihood') srcprob['evfile'] = self.eventfile srcprob['scfile'] = self.ft2 if self.Configuration['event']['irfs'] != 'CALDB': srcprob['evtype'] = self.Configuration['event']['evtype'] else: srcprob['evtype'] = 'INDEF' srcprob['irfs'] = self.irfs srcprob['srcmdl'] = self.xmlfile srcprob['outfile'] = self.Probfile srcprob['srclist'] = self.Configuration['srcprob']['srclist'] srcprob['clobber'] = self.clobber srcprob.run()
def remote_gtselect(): gtsel=GtApp('gtselect') outs=[] for type_name,type_bit in evt_info: out = outbase + '_%s.fits'%type_name outs+=[out] if not os.access(out,os.F_OK): print 'Selecting %s %s events from %s, saving as %s.'%(evclass,type_name,ev,out) gtsel.run(infile=ev, outfile=out, ra=0.0,dec=0.0,\ rad=180., tmin=0., tmax=0., emin=0.,emax=0.,\ zmin=0.,zmax=0.,evclass=evclass,evtype=type_bit) else: print 'File %s already exists, skipping gtselect for %s.'%(out, ev) return
def gtsrcmaps(self, model): gtsrcmaps = GtApp('gtsrcmaps') gtsrcmaps.run(scfile=self.scfile, expcube=self.srcName + '_ltcube_' + self.phaseMin + '_' + self.phaseMax + '.fits', cmap=self.srcName + '_ccube_' + self.phaseMin + '_' + self.phaseMax + '.fits', srcmdl=model, bexpmap=self.srcName + '_allsky_' + self.phaseMin + '_' + self.phaseMax + '.fits', outfile=self.srcName + '_scrmap_' + self.phaseMin + '_' + self.phaseMax + '.fits', irfs=self.irfs, chatter='4', emapbnds="no")
class LTSumTask(Task): default_config = { 'infile1' : None } def __init__(self,outfile,config=None,**kwargs): super(LTSumTask,self).__init__(config,**kwargs) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtltsum') def run_task(self): outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile,**self.config)
def makeFT1Bands(likeIn,evmin,evmax,evclass): gtselect=GtApp('gtselect') #note, checks for existence of ft1 bands, if found won't remake Src=likeIn.source NBins=likeIn.NBins ft1=likeIn.ft1 ebins=likeIn.bins for i in range(0,likeIn.nbins): out='%s_%ibins_band%i.fits' %(Src.replace(' ','_'),NBins,i) #ft1 has name of source and number of bins to be specific about what was done if(not os.access(out,os.F_OK)): if evclass==None: gtselect.run(infile=ft1,outfile=out,ra=0,dec=0,rad=180,tmin=0,tmax=0,emin=ebins[0][i],emax=ebins[1][i],evclsmin=evmin,evclsmax=evmax,zmax=0,chatter=0) #zmax=0 makes no zenith selection else: gtselect.run(infile=ft1,outfile=out,ra=0,dec=0,rad=180,tmin=0,tmax=0,emin=ebins[0][i],emax=ebins[1][i],evclass=evclass,zmax=0,chatter=0) else: print ' -%s' %out,'already exists, skipping gtselect for this energy band.-' return
def makeExpMaps(likeIn): gtexpmap=GtApp('gtexpmap') #note, checks for existence of band expMaps, won't overwrite Src=likeIn.source NBins=likeIn.NBins IRFs=likeIn.IRFs ft2=likeIn.ft2 expCube=likeIn.expCube radius=likeIn.ft1ROI[2]+10. for i in range(0,likeIn.nbins): ev='%s_%ibins_band%i.fits' %(Src.replace(' ','_'),NBins,i) out='%s_%ibins_band%i_%s_em.fits' %(Src.replace(' ','_'),NBins,i,IRFs) #add IRFs name to file to be specific if(not os.access(out,os.F_OK)): gtexpmap.run(evfile=ev,scfile=ft2,expcube=expCube,outfile=out, irfs=IRFs,srcrad=radius,nlong=120,nlat=120,nenergies=20,chatter=0) else: print ' -%s' %out,'already exists, skipping gtexpmap for this energy band.-' return
class LTSumTask(Task): default_config = {'infile1': None} def __init__(self, outfile, config=None, **kwargs): super(LTSumTask, self).__init__(config, **kwargs) self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtltsum') def run_task(self): outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile, **self.config)
def cmap(roi, like, ft1, ft2, cmap=None, ccube=None, npix=100, binsz=0.1, proj="ZEA"): if like.coordsystem == SkyDir.GALACTIC: x, y, coordsys_str = roi.roi_dir.l(), roi.roi_dir.b(), 'GAL' else: x, y, coordsys_str = roi.roi_dir.ra(), roi.roi_dir.dec(), 'CEL' if cmap is not None: gtbin = GtApp('gtbin', 'evtbin') gtbin.run(algorithm='cmap', nxpix=npix, nypix=npix, binsz=binsz, evfile=ft1, outfile=cmap, scfile=ft2, xref=x, yref=y, axisrot=0, proj=proj, coordsys=coordsys_str) if ccube is not None: gtbin = GtApp('gtbin', 'evtbin') gtbin.run(algorithm='ccube', nxpix=npix, nypix=npix, binsz=like.binsz, evfile=ft1, outfile=ccube, scfile=ft2, xref=x, yref=y, axisrot=0, proj=proj, ebinalg='LOG', emin=like.emin, emax=like.emax, enumbins=like.enumbins, coordsys=coordsys_str)
def FindSource(self): """Run the gtfindsrc tool""" findsrc = GtApp('gtfindsrc', 'Likelihood') findsrc['evfile'] = self.eventfile findsrc['scfile'] = self.ft2 findsrc['irfs'] = self.irfs findsrc['expcube'] = self.Cubename findsrc['expmap'] = self.Mapname findsrc['srcmdl'] = utils._dump_xml( self.Configuration) findsrc['coordsys'] = self.Configuration['space']['coordsys'] findsrc['target'] = self.srcname findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"] findsrc['ftol'] = self.Configuration["fitting"]["ftol"] findsrc['clobber'] = self.clobber findsrc['reopt'] = self.Configuration["findsrc"]["Refit"] findsrc['outfile'] = utils._dump_findsrcout(self.Configuration) findsrc.run()
def GtBinnedMap(self): """Run the gtexpcube2 tool for binned analysis""" Nbdecade = log10(self.Emax)-log10(self.Emin)#Compute the number of decade expcube2 = GtApp('gtexpcube2', 'Likelihood') expcube2['infile'] = self.Cubename expcube2['outfile'] = self.BinnedMapfile expcube2['cmap'] = self.ccube if self.Configuration['event']['irfs'] != 'CALDB': expcube2['evtype']= self.Configuration['event']['evtype'] expcube2['irfs'] = self.irfs expcube2['emin'] = self.Emin expcube2['emax'] = self.Emax expcube2['enumbins'] = int(Nbdecade*self.Configuration['energy']['enumbins_per_decade']) expcube2['coordsys'] = self.Configuration['space']['coordsys'] expcube2['proj'] = self.Configuration['space']['proj'] #"AIT" expcube2['clobber'] = self.clobber expcube2.run()
def run_prepare(roi,dry=True): print 'GAL: %s\nEGAL: %s'%(os.getenv("GAL"),os.getenv("EGAL")) #only does the srcmaps part from GtApp import GtApp srcMap = GtApp('gtsrcmaps', 'Likelihood') srcMap['irfs']=roi.configuration.IRF srcMap['scfile']=roi.files['ft2file'] srcMap['expcube']=roi.files['expcube'] srcMap['srcmdl']=roi.modelxml srcMap['bexpmap']=roi.files['binnedExpMap'] srcMap['outfile']=roi.files['srcmap'] srcMap['emapbnds']='no' #srcMap['npix']=1000 # see https://confluence.slac.stanford.edu/x/8xYpC srcMap['minbinsz']=0.05 srcMap['cmap']=roi.files['ccube'] srcMap.run(dry_run=dry) return srcMap.command()
class BExpTask(Task): default_config = { 'nxpix': 360., 'nypix': 180., 'allsky': True, 'xref': 0.0, 'yref': 0.0, 'emin': 1000.0, 'emax': 100000.0, 'chatter': 2, 'proj': 'CAR', 'enumbins': 16, 'infile': None, 'irfs': None, 'evtype': None, 'cmap': 'none', 'coordsys': 'CEL', 'ebinalg': 'LOG', 'binsz': 1.0 } def __init__(self, outfile, config=None, **kwargs): super(BExpTask, self).__init__() self.configure(config, **kwargs) if self.config['allsky']: self.set_config('nxpix', 360) self.set_config('nypix', 180) self.set_config('xref', 0.0) self.set_config('yref', 0.0) self.set_config('binsz', 1.0) self.set_config('proj', 'CAR') self._outfile = os.path.abspath(outfile) self.register_output_file(self._outfile) self._gtapp = GtApp('gtexpcube2') def run_task(self): config = copy.deepcopy(self.config) del (config['allsky']) outfile = os.path.basename(self._output_files[0]) self._gtapp.run(outfile=outfile, **config)
def GtPSF(self): Nbdecade = log10(self.Emax) - log10( self.Emin) #Compute the number of decade irfs, _ = utils.GetIRFS(self.Configuration['event']['evclass'], self.Configuration['event']['evtype']) psf = GtApp('gtpsf', 'Likelihood') psf["expcube"] = self.Cubename psf["outfile"] = self.psf psf["irfs"] = irfs psf["evtype"] = self.Configuration['event']['evtype'] psf["ra"] = self.ra psf["dec"] = self.dec psf["emin"] = self.Emin psf["emax"] = self.Emax psf["nenergies"] = int( Nbdecade * self.Configuration['energy']['enumbins_per_decade']) psf["thetamax"] = 5. psf.run()
def SrcProb(self): """Run the gtsrcprob tool""" if (self.clobber == "no" and os.path.isfile(self.Probfile)): #print("File exists and clobber is False") return (0) srcprob = GtApp('gtsrcprob', 'Likelihood') srcprob['evfile'] = self.mktimefile srcprob['scfile'] = self.ft2 if self.irfs != 'CALDB': srcprob['evtype'] = self.Configuration['event']['evtype'] else: srcprob['evtype'] = 'INDEF' srcprob['irfs'] = self.irfs srcprob['srcmdl'] = self.xmlfile srcprob['outfile'] = self.Probfile srcprob['srclist'] = self.Configuration['srcprob']['srclist'] srcprob['clobber'] = self.clobber srcprob.run()
def remote_srcmaps(): # #GTSRCMAPS: # #INPUT : ltc, Expcube, ccfiles, diffuse models to scatter # #SCATTER OUTPUT: ccfiles -> srcfiles # #OTHER SCATTER? : binsz, to degrade maps with bad PSF or for BACK for type_name, type_bit in evt_info: cc = os.path.join(workdir,'cc_%s_%s.fits'%(irfclass,type_name)) expcube_out = cc.replace('cc_','expcube_') srcmap_out = cc.replace('cc_','srcmap_') if not os.access(srcmap_out,os.F_OK): srcmdl = build_xml(workdir, xml_basefile, type_name) gtsm=GtApp('gtsrcmaps') gtsm.run(expcube=ltc, cmap=cc, srcmdl=srcmdl, bexpmap=expcube_out, \ outfile=srcmap_out, irfs="CALDB") else: print 'Sourcemaps file %s already exists, skipping gtsrcmaps.'%srcmap_out
def run_gtdiffrsp(self): # Check that we have a simulated FT1 assert self._simulated_ft1 is not None, "You have to run the simulation before computing the diffuse response" # Now get the full sky XML file, update the path of the Galactic and isotropic diffuse, and # copy it here to be used in gtdiffrsp orig_file_path = os.path.join(os.path.dirname(__file__), 'fullsky_xml_gtlike.xml') with open(orig_file_path, "r") as f: tree = ElementTree.parse(f) # Fix the path of the Galactic and isotropic template self._fix_galactic_diffuse_path(tree) self._fix_isotropic_diffuse_path(tree) # Write to a temporary file xml_file = self._track_temp_file("__gw_toolkit_xml.xml") with open(xml_file, "w+") as f: f.write(ElementTree.tostring(tree.getroot())) # Run gtdiffrsp gtdiffrsp_app = GtApp('gtdiffrsp') log.info("Computing diffuse response") log.info("#### gtdiffrsp output start #####") print("\n\n") gtdiffrsp_app.run(evfile=self._simulated_ft1, scfile=self._ft2, srcmdl=xml_file, irfs=self._irfs, convert="yes") print("\n\n") log.info("#### gtdiffrsp output stop #####") self._cleanup()
def GtBinnedMap(self): """Run the gtexpcube2 tool for binned analysis""" Nbdecade = log10(self.Emax) - log10( self.Emin) #Compute the number of decade expcube2 = GtApp('gtexpcube2', 'Likelihood') expcube2['infile'] = self.Cubename expcube2['outfile'] = self.BinnedMapfile expcube2['cmap'] = self.ccube if self.Configuration['event']['irfs'] != 'CALDB': expcube2['evtype'] = self.Configuration['event']['evtype'] expcube2['irfs'] = self.irfs expcube2['emin'] = self.Emin expcube2['emax'] = self.Emax expcube2['enumbins'] = int( Nbdecade * self.Configuration['energy']['enumbins_per_decade']) expcube2['coordsys'] = self.Configuration['space']['coordsys'] expcube2['proj'] = self.Configuration['space']['proj'] #"AIT" expcube2['clobber'] = self.clobber expcube2.run()
def modelmap(like, ft2, cmap, outfile): """Fonction to generate a model map. Use : like : a pylike object (BinnedAnalysis) ft2 : a spacecraft file cmap : a 3D cmap outfile : the name of the output""" #taking the needed data expcube = like.binnedData.expCube bexpmap = like.binnedData.binnedExpMap like.srcModel = "srcmodel_%s.xml" % date.today() like.writeXml() srcModel = readXml.SourceModel("srcmodel_%s.xml" % date.today()) #creating a srcmap gtsrcmaps = GtApp('gtsrcmaps') gtsrcmaps['scfile'] = ft2 gtsrcmaps['expcube'] = expcube gtsrcmaps['bexpmap'] = bexpmap gtsrcmaps['irfs'] = IRF gtsrcmaps['cmap'] = cmap gtsrcmaps['srcmdl'] = "srcmodel_%s.xml" % date.today() gtsrcmaps['outfile'] = "srcm_%s.fits" % date.today() gtsrcmaps['ptsrc'] = 'no' gtsrcmaps['debug'] = 'yes' gtsrcmaps.run() #creating the model map gtmodel = GtApp('gtmodel') gtmodel['srcmaps'] = "srcm_%s.fits" % date.today() gtmodel['srcmdl'] = "srcmodel_%s.xml" % date.today() gtmodel['outfile'] = outfile gtmodel['irfs'] = IRF gtmodel['expcube'] = expcube gtmodel['bexpmap'] = bexpmap gtmodel.run() os.system("rm -rf srcmodel_%s.xml" % date.today()) os.system("rm -rf srcm_%s.fits" % date.today())
class ObsSimTask(Task): default_config = { 'infile': None, 'srclist': None, 'scfile': None, 'ra': None, 'dec': None, 'radius': None, 'emin': None, 'emax': None, 'irfs': None, 'simtime': None, 'evroot': 'sim', 'use_ac': False, 'seed': 1, 'rockangle': 'INDEF' } def __init__(self, config=None, opts=None, **kwargs): super(ObsSimTask, self).__init__(config, opts=opts, **kwargs) # self._outfile = os.path.abspath(outfile) # self.register_output_file(self._outfile) self._gtapp = GtApp('gtobssim') def run_task(self): config = extract_dict_by_keys(self.config, ObsSimTask.default_config.keys()) # outfile = os.path.basename(self._output_files[0]) self._gtapp.run(**config) def cleanup(self): # Copy files outfiles = glob.glob('sim*fits') for f in outfiles: print f
def gtselect(ra_center, dec_center, radius, tmin, tmax, emin, emax, simulated_ft1, output_ft1): # NOTE: we assume there is no need for a Zenith cut, because the Zenith cut has been made with # gtmktime gtselect = GtApp('gtselect') gtselect.run(print_command=False, infile=sanitize_filename(simulated_ft1), outfile=output_ft1, ra=ra_center, dec=dec_center, rad=radius, tmin=tmin, tmax=tmax, emin=emin, emax=emax, zmin=0, zmax=180, # Zenith cut must be applied with gtmktime evclass="INDEF", # Assume simulation has been made with the same evclass of the input file evtype='INDEF')
def FindSource(self): """Run the gtfindsrc tool""" findsrc = GtApp('gtfindsrc', 'Likelihood') findsrc['evfile'] = self.eventfile findsrc['scfile'] = self.ft2 if self.Configuration['event']['irfs'] != 'CALDB': findsrc['evtype'] = self.Configuration['event']['evtype'] else: findsrc['evtype'] = 'INDEF' findsrc['irfs'] = self.irfs findsrc['expcube'] = self.Cubename findsrc['expmap'] = self.Mapname findsrc['srcmdl'] = utils._dump_xml(self.Configuration) findsrc['coordsys'] = self.Configuration['space']['coordsys'] findsrc['target'] = self.srcname findsrc['optimizer'] = self.Configuration["fitting"]["optimizer"] findsrc['ftol'] = self.Configuration["fitting"]["ftol"] findsrc['clobber'] = self.clobber findsrc['reopt'] = self.Configuration["findsrc"]["Refit"] findsrc['outfile'] = utils._dump_findsrcout(self.Configuration) findsrc.run()