Example #1
0
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']

    #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')
    cutoff = data.field('Cutoff')
    spectype = data.field('SpectrumType')
    beta = data.field('beta')
    sigma = data.field('Signif_Avg')

    #add the target to the list of sources
    sources = [{'name':srcname, 'ra': ra_src, 'dec': dec_src,
                   'flux': 1e-9, 'index':-2, 'scale': emin,
                   'cutoff': 1e4, 'beta': 0.1, 'IsFree': 1,
                   'SpectrumType': model}]

    Nfree = 1
    #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)

        # sources with angular separation less than 0.1 degree
        # from the target are not added
        # if the source is close to the target : add it as a free source
        if  rsrc < max_radius and rsrc > .1 and  sigma[i] > min_significance:
            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]})
        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]})

    print "Add ", len(sources), " sources in the ROI of ", roi, " degrees"
    print Nfree, " sources have free parameters inside ", max_radius, " degrees"
    return sources
Example #2
0
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

    extendedName = data.field('Extended_Source_Name')
    sigma = data.field('Signif_Avg')

    #add the target to the list of sources
    sources = [{'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': ''}]

    Nextended = 0
    Nfree = 1
    #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)

        # sources with angular separation less than 0.1 degree
        # from the target are not added
        # if the source is close to the target : add it as a free source
        if  rsrc < max_radius and rsrc > .1 and  sigma[i] > min_significance:
            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
    print "Add ", len(sources), " source(s) in the ROI of ", roi, " degrees"
    print Nfree, " source(s) have free parameters inside ", max_radius, " degrees"
    print Nextended, " source(s) is (are) extended"

    return sources