def Print(indices,config,ra,dec,proba,energy,time): mes = Loggin.Message() mes.info("Energy\tAngular Sep\tProba\tTime") mes.info("[MeV] \t[Degrees]") for i in xrange(min(config['srcprob']['numberPhoton'],indices.size)): angSep = calcAngSepDeg(config['target']["ra"],config['target']["dec"],ra[indices[indices.size-1-i]],dec[indices[indices.size-1-i]]) print "%2.3e\t%2.3f\t\t%2.5f\t%2.1f"%(energy[indices[indices.size-1-i]],angSep,proba[indices[indices.size-1-i]],time[indices[indices.size-1-i]])
def GetlistFromFits(config, catalog): from enrico import Loggin mes = Loggin.Message() """Read the config and catalog file and generate the list of sources to include""" #Get the informations for the config file srcname = config['target']['name'] ra_src = config['target']['ra'] dec_src = config['target']['dec'] ra_space = config['space']['xref'] dec_space = config['space']['yref'] emin = config['energy']['emin'] roi = config['space']['rad'] + 2 max_radius = config['model']['max_radius'] min_significance = config['model']['min_significance'] model = config['target']['spectrum'] if model == "Generic": mes.warning("Generic model found. Will turn it to PowerLaw") model = "PowerLaw" #read the catalog file cfile = pyfits.open(catalog) data = cfile[1].data names = data.field('Source_Name') ra = data.field('RAJ2000') dec = data.field('DEJ2000') flux = data.field('Flux_Density') pivot = data.field('Pivot_Energy') index = data.field('Spectral_Index') try: # valid for the 2FGH, not for the 1FHL cutoff = data.field('Cutoff') beta = data.field('beta') spectype = data.field('SpectrumType') except: cutoff = np.zeros(names.size) beta = np.zeros(names.size) spectype = np.array(names.size * ["PowerLaw"]) pivot *= 1e3 ## energy in the 1FHL are in GeV flux *= 1e3 try: extendedName = data.field('Extended_Source_Name') extendedfits = cfile[5].data.field('Spatial_Filename') extendedsrcname = cfile[5].data.field('Source_Name') except: mes.warning( "Cannot find the extended source list: please check the xml") extendedName = np.array(names.size * [""]) extendedsrcname = [] sigma = data.field('Signif_Avg') sources = [] Nfree = 0 Nextended = 0 #loop over all the sources of the catalog for i in xrange(len(names)): #distance from the center of the maps rspace = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_space, dec_space) #distance for the target rsrc = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_src, dec_src) j = 0 extended_fitsfilename = "" for extname in extendedsrcname: if extname == extendedName[i]: extended_fitsfilename = extendedfits[j] j += 1 # if the source has a separation less than 0.1deg to the target and has # the same model type as the one we want to use, insert as our target # with our given coordinates if rsrc < .1 and sigma[i] > min_significance and spectype[ i] == model and extended_fitsfilename == "": Nfree += 1 sources.insert( 0, { 'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename }) elif rsrc < max_radius and rsrc > .1 and sigma[i] > min_significance: # if the source is close to the target : add it as a free source Nfree += 1 sources.append({ 'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename }) if not (extended_fitsfilename == ""): mes.info("Adding extended source " + extendedName[i] + ", Catalogue name is " + names[i]) Nextended += 1 else: # if the source is inside the ROI: add it as a frozen source if rspace < roi and rsrc > .1 and sigma[i] > min_significance: sources.append({ 'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename }) if not (extended_fitsfilename == ""): mes.info("Adding extended source " + extendedName[i] + ", Catalogue name is " + names[i]) Nextended += 1 # if the target has not been added from catalog, add it now if sources[0]['name'] != srcname: Nfree += 1 #add the target to the list of sources in first position sources.insert( 0, { 'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': 1e-9, 'index': -2, 'scale': emin, 'cutoff': 1e4, 'beta': 0.1, 'IsFree': 1, 'SpectrumType': model, 'ExtendedName': "" }) mes.info("Summary of the XML model generation") print "Add ", len(sources), " sources in the ROI of ", roi, "(", config[ 'space']['rad'], "+ 2 ) degrees" print Nfree, " sources have free parameters inside ", max_radius, " degrees" print Nextended, " source(s) is (are) extended" #save log of the genration of the xml save = "catalog: " + catalog + "\n" save += "Add " + str( len(sources)) + " sources in the ROI of " + str(roi) + "(" + str( config['space']['rad']) + "+ 2 ) degrees\n" save += " sources have free parameters inside " + str( max_radius) + " degrees\n" save += str(Nextended) + " source(s) is (are) extended\n" savexml = open( config['out'] + '/' + config['target']['name'] + "_" + config['target']['spectrum'] + "_generation.log", "w") savexml.write(save) savexml.close() return sources
def GetlistFromFits(config, catalog): from enrico import Loggin mes = Loggin.Message() """Read the config and catalog file and generate the list of sources to include""" #Get the informations for the config file srcname = config['target']['name'] ra_src = config['target']['ra'] dec_src = config['target']['dec'] redshift = config['target']['redshift'] ebl_model = config['target']['ebl_model'] ra_space = config['space']['xref'] dec_space = config['space']['yref'] emin = config['energy']['emin'] roi = config['space']['rad']+2 max_radius = config['model']['max_radius'] min_significance = config['model']['min_significance'] model = config['target']['spectrum'] if model == "Generic": mes.warning("Generic model found. Will turn it to PowerLaw") model = "PowerLaw" #read the catalog file cfile = fits.open(catalog) data = cfile[1].data names = data.field('Source_Name') ra = data.field('RAJ2000') dec = data.field('DEJ2000') flux = data.field('Flux_Density') pivot = data.field('Pivot_Energy') spectype = data.field('SpectrumType') is8yr = 'FL8Y' in cfile[1].header['CDS-NAME'] try : # valid for the 2FGH, not for the 1FHL if is8yr: spectype = data.field('SpectrumType') index = np.zeros(names.size) cutoff = np.zeros(names.size) expfac = np.zeros(names.size) beta = np.zeros(names.size) for k,spec in enumerate(spectype): if spec == 'PowerLaw': index[k] = data.field('PL_Index')[k] if spec == 'LogParabola': index[k] = data.field('LP_Index')[k] beta[k] = data.field('LP_beta')[k] if spec == 'PLSuperExpCutoff2': # From the makeFL8Yxml.py script index[k] = data.field('PLEC_Index')[k] expfac = data.field('PLEC_Expfactor')[k] expind = data.field('PLEC_Exp_Index')[k] cutoff[k] =(1./expfac)**(1./expind) #cutoff = data.field('Cutoff') #beta = data.field('LP_beta') else: index = data.field('Spectral_Index') cutoff = data.field('Cutoff') beta = data.field('beta') except : raise index = data.field('Spectral_Index') cutoff = np.zeros(names.size) beta = np.zeros(names.size) spectype = np.array(names.size*["PowerLaw"]) pivot *= 1e3 ## energy in the 1FHL are in GeV flux *= 1e3 try : extendedName = data.field('Extended_Source_Name') if is8yr: extendedfits = cfile[2].data.field('Spatial_Filename') extendedsrcname = cfile[2].data.field('Source_Name') else: extendedfits = cfile[5].data.field('Spatial_Filename') extendedsrcname = cfile[5].data.field('Source_Name') except: raise mes.warning("Cannot find the extended source list: please check the xml") extendedName = np.array(names.size*[""]) extendedsrcname = [] sigma = data.field('Signif_Avg') sources = [] Nfree = 0 Nextended = 0 #loop over all the sources of the catalog for i in xrange(len(names)): #distance from the center of the maps rspace = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_space, dec_space) #distance for the target rsrc = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_src, dec_src) j=0 extended_fitsfilename = "" for extname in extendedsrcname: if extname == extendedName[i]: extended_fitsfilename = extendedfits[j] j+=1 # if the source has a separation less than 0.1deg to the target and has # the same model type as the one we want to use, insert as our target # with our given coordinates if rsrc < .1 and sigma[i] > min_significance and spectype[i] == model and extended_fitsfilename=="": Nfree += 1 mes.info("Adding [free] target source, Catalog name is %s, dist is %.2f and TS is %.2f" %(names[i],rsrc,sigma[i]) ) sources.insert(0,{'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename}) elif rsrc < max_radius and rsrc > .1 and sigma[i] > min_significance: # if the source is close to the target : add it as a free source Nfree += 1 mes.info("Adding [free] source, Catalog name is %s, dist is %.2f and TS is %.2f" %(names[i],rsrc,sigma[i]) ) if not(extended_fitsfilename==""): if not os.path.isfile(extended_fitsfilename): mes.warning("Filename %s for extended source %s does not exist. Skipping." %(extended_fitsfilename,extendedName[i])) continue mes.info("Adding extended source "+extendedName[i]+", Catalogue name is "+names[i]) Nextended+=1 sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename}) # srcs that were kept fixed in the 3FGL: add them as fixed srcs elif rspace < roi and sigma[i] == -np.inf: mes.info("Adding [fixed in 3FGL] source, Catalog name is %s, dist is %.2f and TS is %.2f" %(names[i],rspace,sigma[i]) ) if not(extended_fitsfilename==""): if not os.path.isfile(extended_fitsfilename): mes.warning("Filename %s for extended source %s does not exist. Skipping." %(extended_fitsfilename,extendedName[i])) continue mes.info("Adding extended source "+extendedName[i]+", Catalogue name is "+names[i]) Nextended+=1 sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i],'ExtendedName': extended_fitsfilename}) else: # if the source is inside the ROI: add it as a frozen source if rspace < roi and rsrc > .1 and sigma[i] > min_significance: mes.info("Adding [fixed] source, Catalog name is %s, dist is %.2f and TS is %.2f" %(names[i],rsrc,sigma[i]) ) if not(extended_fitsfilename==""): if not os.path.isfile(extended_fitsfilename): mes.warning("Filename %s for extended source %s does not exist. Skipping." %(extended_fitsfilename,extendedName[i])) continue mes.info("Adding extended source "+extendedName[i]+", Catalogue name is "+names[i]) Nextended+=1 sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i],'ExtendedName': extended_fitsfilename}) # if the target has not been added from catalog, add it now if sources[0]['name']!=srcname: Nfree += 1 #add the target to the list of sources in first position sources.insert(0,{'name':srcname, 'ra': ra_src, 'dec': dec_src, 'flux': 1e-9, 'index':-2, 'scale': emin, 'cutoff': 1e4, 'beta': 0.1, 'IsFree': 1, 'SpectrumType': model,'ExtendedName': ""}) mes.info("Summary of the XML model generation") print "Add ", len(sources), " sources in the ROI of ", roi, "(",config['space']['rad'],"+ 2 ) degrees" print Nfree, " sources have free parameters inside ", max_radius, " degrees" print Nextended, " source(s) is (are) extended" #save log of the generation of the xml save = "catalog: "+catalog+"\n" save += "Add "+str(len(sources))+" sources in the ROI of "+str(roi)+ "("+str(config['space']['rad'])+"+ 2 ) degrees\n" save += " sources have free parameters inside "+str(max_radius)+" degrees\n" save += str(Nextended)+" source(s) is (are) extended\n" savexml = open(config['out']+'/'+ config['target']['name']+"_"+config['target']['spectrum']+"_generation.log","w") savexml.write(save) savexml.close() return sources
def GetlistFromFits(config, catalog): from enrico import Loggin mes = Loggin.Message() """Read the config and catalog file and generate the list of sources to include""" #Get the informations for the config file srcname = config['target']['name'] ra_src = config['target']['ra'] dec_src = config['target']['dec'] ra_space = config['space']['xref'] dec_space = config['space']['yref'] emin = config['energy']['emin'] roi = config['space']['rad']+2 max_radius = config['model']['max_radius'] min_significance = config['model']['min_significance'] model = config['target']['spectrum'] if model == "Generic": mes.warning("Generic model found. Will turn it to PowerLaw") model = "PowerLaw" #read the catalog file cfile = pyfits.open(catalog) data = cfile[1].data names = data.field('Source_Name') ra = data.field('RAJ2000') dec = data.field('DEJ2000') flux = data.field('Flux_Density') pivot = data.field('Pivot_Energy') index = data.field('Spectral_Index') try : # valid for the 2FGH, not for the 1FHL cutoff = data.field('Cutoff') beta = data.field('beta') spectype = data.field('SpectrumType') except : cutoff = np.zeros(names.size) beta = np.zeros(names.size) spectype = np.array(names.size*["PowerLaw"]) pivot *= 1e3 ## energy in the 1FHL are in GeV flux *= 1e3 try : extendedName = data.field('Extended_Source_Name') extendedfits = cfile[5].data.field('Spatial_Filename') extendedsrcname = cfile[5].data.field('Source_Name') except: mes.warning("Cannot find the extended source list: please check the xml") extendedName = np.array(names.size*[""]) extendedsrcname = [] sigma = data.field('Signif_Avg') sources = [] Nfree = 0 Nextended = 0 #loop over all the sources of the catalog for i in xrange(len(names)): #distance from the center of the maps rspace = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_space, dec_space) #distance for the target rsrc = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_src, dec_src) j=0 extended_fitsfilename = "" for extname in extendedsrcname: if extname == extendedName[i]: extended_fitsfilename = extendedfits[j] j+=1 # if the source has a separation less than 0.1deg to the target and has # the same model type as the one we want to use, insert as our target # with our given coordinates if rsrc < .1 and sigma[i] > min_significance and spectype[i] == model and extended_fitsfilename=="": Nfree += 1 sources.insert(0,{'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename}) elif rsrc < max_radius and rsrc > .1 and sigma[i] > min_significance: # if the source is close to the target : add it as a free source Nfree += 1 sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extended_fitsfilename}) if not(extended_fitsfilename==""): mes.info("Adding extended source "+extendedName[i]+", Catalogue name is "+names[i]) Nextended+=1 # srcs that were kept fixed in the 3FGL: add them as fixed srcs elif rspace < roi and sigma[i] == -np.inf: sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i],'ExtendedName': extended_fitsfilename}) if not(extended_fitsfilename==""): mes.info("Adding extended source "+extendedName[i]+", Catalogue name is "+names[i]) Nextended+=1 else: # if the source is inside the ROI: add it as a frozen source if rspace < roi and rsrc > .1 and sigma[i] > min_significance: sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i],'ExtendedName': extended_fitsfilename}) if not(extended_fitsfilename==""): mes.info("Adding extended source "+extendedName[i]+", Catalogue name is "+names[i]) Nextended+=1 # if the target has not been added from catalog, add it now if sources[0]['name']!=srcname: Nfree += 1 #add the target to the list of sources in first position sources.insert(0,{'name':srcname, 'ra': ra_src, 'dec': dec_src, 'flux': 1e-9, 'index':-2, 'scale': emin, 'cutoff': 1e4, 'beta': 0.1, 'IsFree': 1, 'SpectrumType': model,'ExtendedName': ""}) mes.info("Summary of the XML model generation") print "Add ", len(sources), " sources in the ROI of ", roi, "(",config['space']['rad'],"+ 2 ) degrees" print Nfree, " sources have free parameters inside ", max_radius, " degrees" print Nextended, " source(s) is (are) extended" #save log of the genration of the xml save = "catalog: "+catalog+"\n" save += "Add "+str(len(sources))+" sources in the ROI of "+str(roi)+ "("+str(config['space']['rad'])+"+ 2 ) degrees\n" save += " sources have free parameters inside "+str(max_radius)+" degrees\n" save += str(Nextended)+" source(s) is (are) extended\n" savexml = open(config['out']+'/'+ config['target']['name']+"_"+config['target']['spectrum']+"_generation.log","w") savexml.write(save) savexml.close() return sources
def GetlistFromFits(config, catalog): """Read the config and catalog file and generate the list of sources to include""" #Get the informations for the config file srcname = config['target']['name'] ra_src = config['target']['ra'] dec_src = config['target']['dec'] ra_space = config['space']['xref'] dec_space = config['space']['yref'] emin = config['energy']['emin'] roi = config['space']['rad'] max_radius = config['model']['max_radius'] min_significance = config['model']['min_significance'] model = config['target']['spectrum'] if model == "Generic": log.warning("Generic model found. Will turn it to PowerLaw") model = "PowerLaw" #read the catalog file cfile = pyfits.open(catalog) data = cfile[1].data names = data.field('Source_Name') ra = data.field('RAJ2000') dec = data.field('DEJ2000') flux = data.field('Flux_Density') pivot = data.field('Pivot_Energy') index = data.field('Spectral_Index') try : # valid for the 2FGH, not for the 1FHL cutoff = data.field('Cutoff') beta = data.field('beta') spectype = data.field('SpectrumType') except : cutoff = np.zeros(names.size) beta = np.zeros(names.size) spectype = np.array(names.size*["PowerLaw"]) pivot *= 1e3 ## energy in the 1FHL are in GeV flux *= 1e3 try : extendedName = data.field('Extended_Source_Name') except: logging.warning("Cannot find th extended source list: please check the xml") extendedName = np.array(names.size*[""]) sigma = data.field('Signif_Avg') sources = [] Nfree = 0 Nextended = 0 #loop over all the sources of the catalog for i in xrange(len(names)): #distance from the center of the maps rspace = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_space, dec_space) #distance for the target rsrc = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_src, dec_src) # if the source has a separation less than 0.1deg to the target and has # the same model type as the one we want to use, insert as our target # with our given coordinates if rsrc < .1 and sigma[i] > min_significance and spectype[i] == model and extendedName[i]=="": Nfree += 1 sources.insert(0,{'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extendedName[i]}) elif rsrc < max_radius and rsrc > .1 and sigma[i] > min_significance: # if the source is close to the target : add it as a free source Nfree += 1 sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extendedName[i]}) if not(extendedName[i]==""): print "Adding extended source ",extendedName[i]," 2FGL name is ",names[i] Nextended=+1 else: # if the source is inside the ROI: add it as a frozen source if rspace < roi and rsrc > .1 and sigma[i] > min_significance: sources.append({'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i],'ExtendedName': extendedName[i]}) if not(extendedName[i]==""): print "Adding extended source ",extendedName[i]," 2FGL name is ",names[i] Nextended=+1 # if the target has not been added from catalog, add it now if sources[0]['name']!=srcname: Nfree += 1 #add the target to the list of sources in first position sources.insert(0,{'name':srcname, 'ra': ra_src, 'dec': dec_src, 'flux': 1e-9, 'index':-2, 'scale': emin, 'cutoff': 1e4, 'beta': 0.1, 'IsFree': 1, 'SpectrumType': model,'ExtendedName': ""}) print "Add ", len(sources), " sources in the ROI of ", roi, " degrees" print Nfree, " sources have free parameters inside ", max_radius, " degrees" print Nextended, " source(s) is (are) extended" return sources
def GetlistFromFits(config, catalog): """Read the config and catalog file and generate the list of sources to include""" #Get the informations for the config file srcname = config['target']['name'] ra_src = config['target']['ra'] dec_src = config['target']['dec'] ra_space = config['space']['xref'] dec_space = config['space']['yref'] emin = config['energy']['emin'] roi = config['space']['rad'] max_radius = config['model']['max_radius'] min_significance = config['model']['min_significance'] model = config['target']['spectrum'] if model == "Generic": log.warning("Generic model found. Will turn it to PowerLaw") model = "PowerLaw" #read the catalog file cfile = pyfits.open(catalog) data = cfile[1].data names = data.field('Source_Name') ra = data.field('RAJ2000') dec = data.field('DEJ2000') flux = data.field('Flux_Density') pivot = data.field('Pivot_Energy') index = data.field('Spectral_Index') try: # valid for the 2FGH, not for the 1FHL cutoff = data.field('Cutoff') beta = data.field('beta') spectype = data.field('SpectrumType') except: cutoff = np.zeros(names.size) beta = np.zeros(names.size) spectype = np.array(names.size * ["PowerLaw"]) pivot *= 1e3 ## energy in the 1FHL are in GeV flux *= 1e3 try: extendedName = data.field('Extended_Source_Name') except: logging.warning( "Cannot find th extended source list: please check the xml") extendedName = np.array(names.size * [""]) sigma = data.field('Signif_Avg') sources = [] Nfree = 0 Nextended = 0 #loop over all the sources of the catalog for i in xrange(len(names)): #distance from the center of the maps rspace = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_space, dec_space) #distance for the target rsrc = utils.calcAngSepDeg(float(ra[i]), float(dec[i]), ra_src, dec_src) # if the source has a separation less than 0.1deg to the target and has # the same model type as the one we want to use, insert as our target # with our given coordinates if rsrc < .1 and sigma[i] > min_significance and spectype[ i] == model and extendedName[i] == "": Nfree += 1 sources.insert( 0, { 'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extendedName[i] }) elif rsrc < max_radius and rsrc > .1 and sigma[i] > min_significance: # if the source is close to the target : add it as a free source Nfree += 1 sources.append({ 'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 1, 'SpectrumType': spectype[i], 'ExtendedName': extendedName[i] }) if not (extendedName[i] == ""): print "Adding extended source ", extendedName[ i], " 2FGL name is ", names[i] Nextended = +1 else: # if the source is inside the ROI: add it as a frozen source if rspace < roi and rsrc > .1 and sigma[i] > min_significance: sources.append({ 'name': names[i], 'ra': ra[i], 'dec': dec[i], 'flux': flux[i], 'index': -index[i], 'scale': pivot[i], 'cutoff': cutoff[i], 'beta': beta[i], 'IsFree': 0, 'SpectrumType': spectype[i], 'ExtendedName': extendedName[i] }) if not (extendedName[i] == ""): print "Adding extended source ", extendedName[ i], " 2FGL name is ", names[i] Nextended = +1 # if the target has not been added from catalog, add it now if sources[0]['name'] != srcname: Nfree += 1 #add the target to the list of sources in first position sources.insert( 0, { 'name': srcname, 'ra': ra_src, 'dec': dec_src, 'flux': 1e-9, 'index': -2, 'scale': emin, 'cutoff': 1e4, 'beta': 0.1, 'IsFree': 1, 'SpectrumType': model, 'ExtendedName': "" }) print "Add ", len(sources), " sources in the ROI of ", roi, " degrees" print Nfree, " sources have free parameters inside ", max_radius, " degrees" print Nextended, " source(s) is (are) extended" return sources