コード例 #1
0
ファイル: plots.py プロジェクト: pdh21/XID_plus
def replicated_map_movie(priors,posterior, frames):
    """

    :param priors: list of xidplus.prior classes
    :param posterior: xidplus.posterior class
    :param frames: number of frames
    :return: Movie of replicated maps. Each frame is a sample from the posterior
    """
    figs,fig=plot_map(priors)
    mod_map_array=postmaps.replicated_maps(priors,posterior,frames)
    cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,as_cmap=True)

    def animate(i):
        for b in range(0,len(priors)):
            figs[b]._data[priors[b].sy_pix-np.min(priors[b].sy_pix)-1,priors[b].sx_pix-np.min(priors[b].sx_pix)-1]=mod_map_array[b][:,i]
            figs[b].show_colorscale(vmin=np.min(priors[b].sim),vmax=np.max(priors[b].sim),cmap=cmap)


        return figs
    # call the animator.  blit=True means only re-draw the parts that have changed.
    anim = animation.FuncAnimation(fig, animate,
                               frames=frames, interval=1000)


    # call our new function to display the animation
    return display_animation(anim)
コード例 #2
0
ファイル: plots.py プロジェクト: ivvv/XID_plus
def replicated_map_movie(priors, posterior, frames):
    """

    :param priors: list of xidplus.prior classes
    :param posterior: xidplus.posterior class
    :param frames: number of frames
    :return: Movie of replicated maps. Each frame is a sample from the posterior
    """
    figs, fig = plot_map(priors)
    mod_map_array = postmaps.replicated_maps(priors, posterior, frames)
    cmap = sns.cubehelix_palette(8, start=.5, rot=-.75, as_cmap=True)

    def animate(i):
        for b in range(0, len(priors)):
            figs[b]._data[priors[b].sy_pix - np.min(priors[b].sy_pix) - 1,
                          priors[b].sx_pix - np.min(priors[b].sx_pix) -
                          1] = mod_map_array[b][:, i]
            figs[b].show_colorscale(vmin=np.min(priors[b].sim),
                                    vmax=np.max(priors[b].sim),
                                    cmap=cmap)

        return figs

    # call the animator.  blit=True means only re-draw the parts that have changed.
    anim = animation.FuncAnimation(fig, animate, frames=frames, interval=1000)

    # call our new function to display the animation
    return display_animation(anim)
コード例 #3
0
ファイル: plots.py プロジェクト: pdh21/XID_plus
def plot_Bayes_pval_map(priors, posterior):

    """

    :param priors: list of xidplus.prior classes
    :param posterior: xidplus.posterior class
    :return: the default xidplus Bayesian P value map plot
    """
    sns.set_style("white")
    mod_map_array = postmaps.replicated_maps(priors, posterior, posterior.samples['lp__'].size)
    Bayes_pvals = []

    cmap = sns.diverging_palette(220, 20, as_cmap=True)

    hdulists = list(map(lambda prior: postmaps.make_fits_image(prior, prior.sim), priors))
    fig = plt.figure(figsize=(10 * len(priors), 10))
    figs = []
    for i in range(0, len(priors)):
        figs.append(aplpy.FITSFigure(hdulists[i][1], figure=fig, subplot=(1, len(priors), i + 1)))
        Bayes_pvals.append(postmaps.make_Bayesian_pval_maps(priors[i], mod_map_array[i]))

    for i in range(0, len(priors)):
        figs[i].show_markers(priors[i].sra, priors[i].sdec, edgecolor='black', facecolor='black',
                             marker='o', s=20, alpha=0.5)
        figs[i].tick_labels.set_xformat('dd.dd')
        figs[i].tick_labels.set_yformat('dd.dd')
        figs[i]._data[
            priors[i].sy_pix - np.min(priors[i].sy_pix) - 1, priors[i].sx_pix - np.min(priors[i].sx_pix) - 1] = \
        Bayes_pvals[i]
        figs[i].show_colorscale(vmin=-6, vmax=6, cmap=cmap)
        figs[i].add_colorbar()
        figs[i].colorbar.set_location('top')
    return figs, fig
コード例 #4
0
ファイル: plots.py プロジェクト: MCarmenCampos/XID_plus
def replicated_map_movie(priors, posterior, frames):
    """

    :param priors: list of xidplus.prior classes
    :param posterior: xidplus.posterior class
    :param frames: number of frames
    :return: Movie of replicated maps. Each frame is a sample from the posterior
    """
    mod_map_array = postmaps.replicated_maps(priors, posterior, frames)
    # call our new function to display the animation
    return make_map_animation(priors, mod_map_array, frames)
コード例 #5
0
ファイル: plots.py プロジェクト: ivvv/XID_plus
def plot_Bayes_pval_map(priors, posterior):
    """

    :param priors: list of xidplus.prior classes
    :param posterior: xidplus.posterior class
    :return: the default xidplus Bayesian P value map plot
    """
    sns.set_style("white")
    mod_map_array = postmaps.replicated_maps(priors, posterior,
                                             posterior.samples['lp__'].size)
    Bayes_pvals = []

    cmap = sns.diverging_palette(220, 20, as_cmap=True)

    hdulists = list(
        map(lambda prior: postmaps.make_fits_image(prior, prior.sim), priors))
    fig = plt.figure(figsize=(10 * len(priors), 10))
    figs = []
    for i in range(0, len(priors)):
        figs.append(
            aplpy.FITSFigure(hdulists[i][1],
                             figure=fig,
                             subplot=(1, len(priors), i + 1)))
        Bayes_pvals.append(
            postmaps.make_Bayesian_pval_maps(priors[i], mod_map_array[i]))

    for i in range(0, len(priors)):
        figs[i].show_markers(priors[i].sra,
                             priors[i].sdec,
                             edgecolor='black',
                             facecolor='black',
                             marker='o',
                             s=20,
                             alpha=0.5)
        figs[i].tick_labels.set_xformat('dd.dd')
        figs[i].tick_labels.set_yformat('dd.dd')
        figs[i]._data[
            priors[i].sy_pix - np.min(priors[i].sy_pix) - 1, priors[i].sx_pix - np.min(priors[i].sx_pix) - 1] = \
        Bayes_pvals[i]
        figs[i].show_colorscale(vmin=-6, vmax=6, cmap=cmap)
        figs[i].add_colorbar()
        figs[i].colorbar.set_location('top')
    return figs, fig
コード例 #6
0
priors[0].prior_bkg(0.0,1)
priors[0].get_pointing_matrix()
#priors[0].upper_lim_map()

#priors[0].prior_flux_upper=(priors[0].prior_flux_upper-10.0+0.02)/np.max(priors[0].prf)

fit=MIPS.MIPS_24(priors[0],iter=1000)

posterior=xidplus.posterior_stan(fit,priors)

outfile=output_folder+'Tile_'+str(tiles[taskid-1])+'_'+str(order)

posterior=xidplus.posterior_stan(fit,priors)
xidplus.save(priors,posterior,outfile)
      
post_rep_map=postmaps.replicated_maps(priors,posterior,nrep=2000)
Bayes_P24=postmaps.Bayes_Pval_res(priors[0],post_rep_map[0])
cat=catalogue.create_MIPS_cat(posterior, priors[0], Bayes_P24)
kept_sources=moc_routines.sources_in_tile([tiles[taskid-1]],order,priors[0].sra,priors[0].sdec)
kept_sources=np.array(kept_sources)
cat[1].data=cat[1].data[kept_sources]
outfile=output_folder+'Tile_'+str(tiles[taskid-1])+'_'+str(order)

cat.writeto(outfile+'_MIPS24_cat.fits',overwrite=True)

Bayesian_Pval=postmaps.make_Bayesian_pval_maps(priors[0],post_rep_map[0])
wcs_temp=wcs.WCS(priors[0].imhdu)
ra,dec=wcs_temp.wcs_pix2world(priors[0].sx_pix,priors[0].sy_pix,0)
kept_pixels=np.array(moc_routines.sources_in_tile([tiles[taskid-1]],order,ra,dec))
Bayesian_Pval[np.invert(kept_pixels)]=np.nan
コード例 #7
0
ファイル: catalogue.py プロジェクト: ivvv/XID_plus
def create_PACS_cat(posterior, prior100, prior160):
    """
    Create PACS catalogue from posterior
    
    :param posterior: PACS xidplus.posterior class
    :param prior100:  PACS 100 xidplus.prior class
    :param prior160:  PACS 160 xidplus.prior class
    :return: fits hdulist
    """
    import datetime
    nsrc = prior100.nsrc
    rep_maps = postmaps.replicated_maps([prior100, prior160], posterior)
    Bayes_P100 = postmaps.Bayes_Pval_res(prior100, rep_maps[0])
    Bayes_P160 = postmaps.Bayes_Pval_res(prior160, rep_maps[1])

    # ----table info-----------------------
    # first define columns
    c1 = fits.Column(name='help_id', format='27A', array=prior100.ID)
    c2 = fits.Column(name='RA', format='D', unit='degrees', array=prior100.sra)
    c3 = fits.Column(name='Dec',
                     format='D',
                     unit='degrees',
                     array=prior100.sdec)
    c4 = fits.Column(name='F_PACS_100',
                     format='E',
                     unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:, 0, :],
                                         50.0,
                                         axis=0))
    c5 = fits.Column(name='FErr_PACS_100_u',
                     format='E',
                     unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:, 0, :],
                                         84.1,
                                         axis=0))
    c6 = fits.Column(name='FErr_PACS_100_l',
                     format='E',
                     unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:, 0, :],
                                         15.9,
                                         axis=0))
    c7 = fits.Column(name='F_PACS_160',
                     format='E',
                     unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:, 1, :],
                                         50.0,
                                         axis=0))
    c8 = fits.Column(name='FErr_PACS_160_u',
                     format='E',
                     unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:, 1, :],
                                         84.1,
                                         axis=0))
    c9 = fits.Column(name='FErr_PACS_160_l',
                     format='E',
                     unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:, 1, :],
                                         15.9,
                                         axis=0))
    c10 = fits.Column(name='Bkg_PACS_100',
                      format='E',
                      unit='mJy/Beam',
                      array=np.full(
                          nsrc,
                          np.percentile(posterior.samples['bkg'][:, 0],
                                        50.0,
                                        axis=0)))
    c11 = fits.Column(name='Bkg_PACS_160',
                      format='E',
                      unit='mJy/Beam',
                      array=np.full(
                          nsrc,
                          np.percentile(posterior.samples['bkg'][:, 1],
                                        50.0,
                                        axis=0)))
    c12 = fits.Column(name='Sig_conf_PACS_100',
                      format='E',
                      unit='mJy/Beam',
                      array=np.full(
                          nsrc,
                          np.percentile(posterior.samples['sigma_conf'][:, 0],
                                        50.0,
                                        axis=0)))
    c13 = fits.Column(name='Sig_conf_PACS_160',
                      format='E',
                      unit='mJy/Beam',
                      array=np.full(
                          nsrc,
                          np.percentile(posterior.samples['sigma_conf'][:, 1],
                                        50.0,
                                        axis=0)))
    c14 = fits.Column(name='Rhat_PACS_100',
                      format='E',
                      array=posterior.Rhat['src_f'][:, 0])
    c15 = fits.Column(name='Rhat_PACS_160',
                      format='E',
                      array=posterior.Rhat['src_f'][:, 1])
    c16 = fits.Column(name='n_eff_PACS_100',
                      format='E',
                      array=posterior.n_eff['src_f'][:, 0])
    c17 = fits.Column(name='n_eff_PACS_160',
                      format='E',
                      array=posterior.n_eff['src_f'][:, 1])
    c18 = fits.Column(name='Pval_res_100', format='E', array=Bayes_P100)
    c19 = fits.Column(name='Pval_res_160', format='E', array=Bayes_P160)

    tbhdu = fits.BinTableHDU.from_columns([
        c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16,
        c17, c18, c19
    ])

    tbhdu.header.set('TUCD1', 'ID', after='TFORM1')
    tbhdu.header.set('TDESC1', 'ID of source', after='TUCD1')

    tbhdu.header.set('TUCD2', 'pos.eq.RA', after='TUNIT2')
    tbhdu.header.set('TDESC2', 'R.A. of object J2000', after='TUCD2')

    tbhdu.header.set('TUCD3', 'pos.eq.DEC', after='TUNIT3')
    tbhdu.header.set('TDESC3', 'Dec. of object J2000', after='TUCD3')

    tbhdu.header.set('TUCD4', 'phot.flux.density', after='TUNIT4')
    tbhdu.header.set('TDESC4', '100 Flux (at 50th percentile)', after='TUCD4')

    tbhdu.header.set('TUCD5', 'phot.flux.density', after='TUNIT5')
    tbhdu.header.set('TDESC5', '100 Flux (at 84.1 percentile) ', after='TUCD5')

    tbhdu.header.set('TUCD6', 'phot.flux.density', after='TUNIT6')
    tbhdu.header.set('TDESC6', '100 Flux (at 15.9 percentile)', after='TUCD6')

    tbhdu.header.set('TUCD7', 'phot.flux.density', after='TUNIT7')
    tbhdu.header.set('TDESC7', '160 Flux (at 50th percentile)', after='TUCD7')

    tbhdu.header.set('TUCD8', 'phot.flux.density', after='TUNIT8')
    tbhdu.header.set('TDESC8', '160 Flux (at 84.1 percentile) ', after='TUCD8')

    tbhdu.header.set('TUCD9', 'phot.flux.density', after='TUNIT9')
    tbhdu.header.set('TDESC9', '160 Flux (at 15.9 percentile)', after='TUCD9')

    tbhdu.header.set('TUCD10', 'phot.flux.density', after='TUNIT10')
    tbhdu.header.set('TDESC10', '100 background', after='TUCD10')

    tbhdu.header.set('TUCD11', 'phot.flux.density', after='TUNIT11')
    tbhdu.header.set('TDESC11', '160 background', after='TUCD11')

    tbhdu.header.set('TUCD12', 'phot.flux.density', after='TUNIT12')
    tbhdu.header.set('TDESC12', '100 residual confusion noise', after='TUCD12')

    tbhdu.header.set('TUCD13', 'phot.flux.density', after='TUNIT13')
    tbhdu.header.set('TDESC13', '160 residual confusion noise', after='TUCD13')

    tbhdu.header.set('TUCD14', 'stat.value', after='TFORM14')
    tbhdu.header.set('TDESC14',
                     '100 MCMC Convergence statistic',
                     after='TUCD14')

    tbhdu.header.set('TUCD15', 'stat.value', after='TFORM15')
    tbhdu.header.set('TDESC15',
                     '160 MCMC Convergence statistic',
                     after='TUCD15')

    tbhdu.header.set('TUCD16', 'stat.value', after='TFORM16')
    tbhdu.header.set('TDESC16',
                     '100 MCMC independence statistic',
                     after='TUCD16')

    tbhdu.header.set('TUCD17', 'stat.value', after='TFORM17')
    tbhdu.header.set('TDESC17',
                     '160 MCMC independence statistic',
                     after='TUCD17')

    tbhdu.header.set('TUCD18', 'stat.value', after='TFORM18')
    tbhdu.header.set('TDESC18',
                     '100 Bayes Pval residual statistic',
                     after='TUCD18')

    tbhdu.header.set('TUCD19', 'stat.value', after='TFORM19')
    tbhdu.header.set('TDESC19',
                     '160 Bayes Pval residual statistic',
                     after='TUCD19')
    # ----Primary header-----------------------------------
    prihdr = fits.Header()
    prihdr['Prior_Cat'] = prior100.prior_cat
    prihdr['TITLE'] = 'PACS XID+ catalogue'
    # prihdr['OBJECT']  = prior250.imphdu['OBJECT'] #I need to think if this needs to change
    prihdr['CREATOR'] = 'WP5'
    prihdr['XIDplus'] = io.git_version()
    prihdr['DATE'] = datetime.datetime.now().isoformat()
    prihdu = fits.PrimaryHDU(header=prihdr)
    thdulist = fits.HDUList([prihdu, tbhdu])
    return thdulist
コード例 #8
0
ファイル: catalogue.py プロジェクト: ivvv/XID_plus
def create_MIPS_cat(posterior, prior24, Bayes_P24):
    """
    Create MIPS catalogue from posterior
    
    :param posterior: MIPS xidplus.posterior class
    :param prior24: MIPS xidplus.prior class
    :param Bayes_P24:  Bayes Pvalue residual statistic for MIPS 24
    :return: fits hdulist
    """
    import datetime
    nsrc = prior24.nsrc
    rep_maps = postmaps.replicated_maps([prior24], posterior)
    Bayes_P24 = postmaps.Bayes_Pval_res(prior24, rep_maps[0])
    # ----table info-----------------------
    # first define columns
    c1 = fits.Column(name='help_id', format='27A', array=prior24.ID)
    c2 = fits.Column(name='RA', format='D', unit='degrees', array=prior24.sra)
    c3 = fits.Column(name='Dec',
                     format='D',
                     unit='degrees',
                     array=prior24.sdec)
    c4 = fits.Column(name='F_MIPS_24',
                     format='E',
                     unit='muJy',
                     array=np.percentile(posterior.samples['src_f'][:, 0, :],
                                         50.0,
                                         axis=0))
    c5 = fits.Column(name='FErr_MIPS_24_u',
                     format='E',
                     unit='muJy',
                     array=np.percentile(posterior.samples['src_f'][:, 0, :],
                                         84.1,
                                         axis=0))
    c6 = fits.Column(name='FErr_MIPS_24_l',
                     format='E',
                     unit='muJy',
                     array=np.percentile(posterior.samples['src_f'][:, 0, :],
                                         15.9,
                                         axis=0))
    c7 = fits.Column(name='Bkg_MIPS_24',
                     format='E',
                     unit='MJy/sr',
                     array=np.full(
                         nsrc,
                         np.percentile(posterior.samples['bkg'][:, 0],
                                       50.0,
                                       axis=0)))
    c8 = fits.Column(name='Sig_conf_MIPS_24',
                     format='E',
                     unit='MJy/sr',
                     array=np.full(
                         nsrc,
                         np.percentile(posterior.samples['sigma_conf'][:, 0],
                                       50.0,
                                       axis=0)))
    c9 = fits.Column(name='Rhat_MIPS_24',
                     format='E',
                     array=posterior.Rhat['src_f'][:, 0])
    c10 = fits.Column(name='n_eff_MIPS_24',
                      format='E',
                      array=posterior.n_eff['src_f'][:, 0])
    c11 = fits.Column(name='Pval_res_24', format='E', array=Bayes_P24)

    tbhdu = fits.BinTableHDU.from_columns(
        [c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11])

    tbhdu.header.set('TUCD1', 'ID', after='TFORM1')
    tbhdu.header.set('TDESC1', 'ID of source', after='TUCD1')

    tbhdu.header.set('TUCD2', 'pos.eq.RA', after='TUNIT2')
    tbhdu.header.set('TDESC2', 'R.A. of object J2000', after='TUCD2')

    tbhdu.header.set('TUCD3', 'pos.eq.DEC', after='TUNIT3')
    tbhdu.header.set('TDESC3', 'Dec. of object J2000', after='TUCD3')

    tbhdu.header.set('TUCD4', 'phot.flux.density', after='TUNIT4')
    tbhdu.header.set('TDESC4', '24 Flux (at 50th percentile)', after='TUCD4')

    tbhdu.header.set('TUCD5', 'phot.flux.density', after='TUNIT5')
    tbhdu.header.set('TDESC5', '24 Flux (at 84.1 percentile) ', after='TUCD5')

    tbhdu.header.set('TUCD6', 'phot.flux.density', after='TUNIT6')
    tbhdu.header.set('TDESC6', '24 Flux (at 15.9 percentile)', after='TUCD6')

    tbhdu.header.set('TUCD7', 'phot.flux.density', after='TUNIT7')
    tbhdu.header.set('TDESC7', '24 background', after='TUCD7')

    tbhdu.header.set('TUCD8', 'phot.flux.density', after='TUNIT8')
    tbhdu.header.set('TDESC8', '24 residual confusion noise', after='TUCD8')

    tbhdu.header.set('TUCD9', 'stat.value', after='TFORM9')
    tbhdu.header.set('TDESC9', '24 MCMC Convergence statistic', after='TUCD9')

    tbhdu.header.set('TUCD10', 'stat.value', after='TFORM10')
    tbhdu.header.set('TDESC10',
                     '24 MCMC independence statistic',
                     after='TUCD10')

    tbhdu.header.set('TUCD11', 'stat.value', after='TFORM11')
    tbhdu.header.set('TDESC11',
                     '24 Bayes Pval residual statistic',
                     after='TUCD11')

    #----Primary header-----------------------------------
    prihdr = fits.Header()
    prihdr['Prior_Cat'] = prior24.prior_cat
    prihdr['TITLE'] = 'XID+MIPS catalogue'
    #prihdr['OBJECT']  = prior250.imphdu['OBJECT'] #I need to think if this needs to change
    prihdr['CREATOR'] = 'WP5'
    prihdr['XIDplus'] = io.git_version()
    prihdr['DATE'] = datetime.datetime.now().isoformat()
    prihdu = fits.PrimaryHDU(header=prihdr)
    thdulist = fits.HDUList([prihdu, tbhdu])
    return thdulist
コード例 #9
0
if taskid in num_done:
    sys.exit()

sources_done = []
both_result = []
lofar_result = []
help_result = []

for n,name in enumerate(ids_centre):
    
    if n%10==0:
        print(n)
        #print('loading new lofar and HELP posterior')
        lofar_file = 'data/fir/SPIRE_no_help/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.pkl'.format(int(n/10),int(n/10))
        priors_lofar,posterior_lofar = xidplus.load(lofar_file)
        rep_map_lofar = postmaps.replicated_maps(priors_lofar,posterior_lofar)
        
        help_file = 'data/fir/SPIRE_no_lofar/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.pkl'.format(int(n/10),int(n/10))
        priors_help,posterior_help = xidplus.load(help_file)
        rep_map_help = postmaps.replicated_maps(priors_help,posterior_help)
    if n%20==0:
        #print('loading new both posterior')
        both_file = 'data/fir/SPIRE/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.pkl'.format(int(n/20),int(n/20))
        priors_both,posterior_both = xidplus.load(both_file)
        rep_map_both = postmaps.replicated_maps(priors_both,posterior_both)
        
    ra_target = ras[n]
    dec_target = decs[n]
    
    pixels_both = find_pixels([ra_target],[dec_target],18/3600,priors_both,posterior_both)
    pixels_lofar = find_pixels([ra_target],[dec_target],18/3600,priors_lofar,posterior_lofar)
コード例 #10
0
lofar_runs = glob.glob('data/fir/SPIRE/*/*.pkl')

lofar = Table.read('data/data_release/final_cross_match_catalogue-v0.5.fits')
mask = (~np.isnan(lofar['F_SPIRE_250'])) | (
    ~np.isnan(lofar['F_SPIRE_350'])) | (~np.isnan(lofar['F_SPIRE_500']))
lofar = lofar[~mask]

batch_size = 20

sources_done = []
ks_test = []
sign = []
for file in lofar_runs:
    print(file)
    priors, posterior = xidplus.load(file)
    rep_map_lofar = postmaps.replicated_maps(priors, posterior)

    filename = file

    taskid = int(filename.split('_')[-2])
    ind_low = taskid * batch_size
    if taskid * batch_size + batch_size > len(lofar):
        ind_up = len(lofar)
    else:
        ind_up = taskid * batch_size + batch_size
    ras = lofar['optRA'][ind_low:ind_up]
    mask = np.isnan(ras)
    ras[mask] = lofar['RA'][ind_low:ind_up][mask]

    decs = lofar['optDec'][ind_low:ind_up]
    mask = np.isnan(decs)
コード例 #11
0
ファイル: catalogue.py プロジェクト: pdh21/XID_plus
def create_PACS_cat(posterior, prior100, prior160):

    """
    Create PACS catalogue from posterior
    
    :param posterior: PACS xidplus.posterior class
    :param prior100:  PACS 100 xidplus.prior class
    :param prior160:  PACS 160 xidplus.prior class
    :return: fits hdulist
    """
    import datetime
    nsrc=prior100.nsrc
    rep_maps=postmaps.replicated_maps([prior100,prior160],posterior)
    Bayes_P100=postmaps.Bayes_Pval_res(prior100,rep_maps[0])
    Bayes_P160=postmaps.Bayes_Pval_res(prior160,rep_maps[1])


    # ----table info-----------------------
    # first define columns
    c1 = fits.Column(name='help_id', format='27A', array=prior100.ID)
    c2 = fits.Column(name='RA', format='D', unit='degrees', array=prior100.sra)
    c3 = fits.Column(name='Dec', format='D', unit='degrees', array=prior100.sdec)
    c4 = fits.Column(name='F_PACS_100', format='E', unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:,0,:],50.0,axis=0))
    c5 = fits.Column(name='FErr_PACS_100_u', format='E', unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:,0,:],84.1,axis=0))
    c6 = fits.Column(name='FErr_PACS_100_l', format='E', unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:,0,:],15.9,axis=0))
    c7 = fits.Column(name='F_PACS_160', format='E', unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:,1,:],50.0,axis=0))
    c8 = fits.Column(name='FErr_PACS_160_u', format='E', unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:,1,:],84.1,axis=0))
    c9 = fits.Column(name='FErr_PACS_160_l', format='E', unit='mJy',
                     array=np.percentile(posterior.samples['src_f'][:,1,:],15.9,axis=0))
    c10 = fits.Column(name='Bkg_PACS_100', format='E', unit='mJy/Beam',
                      array=np.full(nsrc,np.percentile(posterior.samples['bkg'][:,0],50.0,axis=0)))
    c11 = fits.Column(name='Bkg_PACS_160', format='E', unit='mJy/Beam',
                      array=np.full(nsrc,np.percentile(posterior.samples['bkg'][:,1],50.0,axis=0)))
    c12 = fits.Column(name='Sig_conf_PACS_100', format='E', unit='mJy/Beam',
                      array=np.full(nsrc,np.percentile(posterior.samples['sigma_conf'][:,0],50.0,axis=0)))
    c13 = fits.Column(name='Sig_conf_PACS_160', format='E', unit='mJy/Beam',
                      array=np.full(nsrc, np.percentile(posterior.samples['sigma_conf'][:,1],50.0,axis=0)))
    c14 = fits.Column(name='Rhat_PACS_100', format='E', array=posterior.Rhat['src_f'][:,0])
    c15 = fits.Column(name='Rhat_PACS_160', format='E', array=posterior.Rhat['src_f'][:,1])
    c16 = fits.Column(name='n_eff_PACS_100', format='E', array=posterior.n_eff['src_f'][:,0])
    c17 = fits.Column(name='n_eff_PACS_160', format='E', array=posterior.n_eff['src_f'][:,1])
    c18 = fits.Column(name='Pval_res_100', format='E', array=Bayes_P100)
    c19 = fits.Column(name='Pval_res_160', format='E', array=Bayes_P160)


    tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19])

    tbhdu.header.set('TUCD1', 'ID', after='TFORM1')
    tbhdu.header.set('TDESC1', 'ID of source', after='TUCD1')

    tbhdu.header.set('TUCD2', 'pos.eq.RA', after='TUNIT2')
    tbhdu.header.set('TDESC2', 'R.A. of object J2000', after='TUCD2')

    tbhdu.header.set('TUCD3', 'pos.eq.DEC', after='TUNIT3')
    tbhdu.header.set('TDESC3', 'Dec. of object J2000', after='TUCD3')

    tbhdu.header.set('TUCD4', 'phot.flux.density', after='TUNIT4')
    tbhdu.header.set('TDESC4', '100 Flux (at 50th percentile)', after='TUCD4')

    tbhdu.header.set('TUCD5', 'phot.flux.density', after='TUNIT5')
    tbhdu.header.set('TDESC5', '100 Flux (at 84.1 percentile) ', after='TUCD5')

    tbhdu.header.set('TUCD6', 'phot.flux.density', after='TUNIT6')
    tbhdu.header.set('TDESC6', '100 Flux (at 15.9 percentile)', after='TUCD6')

    tbhdu.header.set('TUCD7', 'phot.flux.density', after='TUNIT7')
    tbhdu.header.set('TDESC7', '160 Flux (at 50th percentile)', after='TUCD7')

    tbhdu.header.set('TUCD8', 'phot.flux.density', after='TUNIT8')
    tbhdu.header.set('TDESC8', '160 Flux (at 84.1 percentile) ', after='TUCD8')

    tbhdu.header.set('TUCD9', 'phot.flux.density', after='TUNIT9')
    tbhdu.header.set('TDESC9', '160 Flux (at 15.9 percentile)', after='TUCD9')

    tbhdu.header.set('TUCD10', 'phot.flux.density', after='TUNIT10')
    tbhdu.header.set('TDESC10', '100 background', after='TUCD10')

    tbhdu.header.set('TUCD11', 'phot.flux.density', after='TUNIT11')
    tbhdu.header.set('TDESC11', '160 background', after='TUCD11')

    tbhdu.header.set('TUCD12', 'phot.flux.density', after='TUNIT12')
    tbhdu.header.set('TDESC12', '100 residual confusion noise', after='TUCD12')

    tbhdu.header.set('TUCD13', 'phot.flux.density', after='TUNIT13')
    tbhdu.header.set('TDESC13', '160 residual confusion noise', after='TUCD13')

    tbhdu.header.set('TUCD14', 'stat.value', after='TFORM14')
    tbhdu.header.set('TDESC14', '100 MCMC Convergence statistic', after='TUCD14')

    tbhdu.header.set('TUCD15', 'stat.value', after='TFORM15')
    tbhdu.header.set('TDESC15', '160 MCMC Convergence statistic', after='TUCD15')

    tbhdu.header.set('TUCD16', 'stat.value', after='TFORM16')
    tbhdu.header.set('TDESC16', '100 MCMC independence statistic', after='TUCD16')

    tbhdu.header.set('TUCD17', 'stat.value', after='TFORM17')
    tbhdu.header.set('TDESC17', '160 MCMC independence statistic', after='TUCD17')
    
    tbhdu.header.set('TUCD18','stat.value',after='TFORM18')
    tbhdu.header.set('TDESC18','100 Bayes Pval residual statistic',after='TUCD18')

    tbhdu.header.set('TUCD19','stat.value',after='TFORM19')
    tbhdu.header.set('TDESC19','160 Bayes Pval residual statistic',after='TUCD19')
    # ----Primary header-----------------------------------
    prihdr = fits.Header()
    prihdr['Prior_Cat'] = prior100.prior_cat
    prihdr['TITLE'] = 'PACS XID+ catalogue'
    # prihdr['OBJECT']  = prior250.imphdu['OBJECT'] #I need to think if this needs to change
    prihdr['CREATOR'] = 'WP5'
    prihdr['XIDplus'] = io.git_version()
    prihdr['DATE'] = datetime.datetime.now().isoformat()
    prihdu = fits.PrimaryHDU(header=prihdr)
    thdulist = fits.HDUList([prihdu, tbhdu])
    return thdulist
コード例 #12
0
ファイル: catalogue.py プロジェクト: pdh21/XID_plus
def create_MIPS_cat(posterior, prior24, Bayes_P24):

    """
    Create MIPS catalogue from posterior
    
    :param posterior: MIPS xidplus.posterior class
    :param prior24: MIPS xidplus.prior class
    :param Bayes_P24:  Bayes Pvalue residual statistic for MIPS 24
    :return: fits hdulist
    """
    import datetime
    nsrc=prior24.nsrc
    rep_maps = postmaps.replicated_maps([prior24], posterior)
    Bayes_P24 = postmaps.Bayes_Pval_res(prior24, rep_maps[0])
    # ----table info-----------------------
    # first define columns
    c1 = fits.Column(name='help_id', format='27A', array=prior24.ID)
    c2 = fits.Column(name='RA', format='D', unit='degrees', array=prior24.sra)
    c3 = fits.Column(name='Dec', format='D', unit='degrees', array=prior24.sdec)
    c4 = fits.Column(name='F_MIPS_24', format='E', unit='muJy',
                     array=np.percentile(posterior.samples['src_f'][:,0,:],50.0,axis=0))
    c5 = fits.Column(name='FErr_MIPS_24_u', format='E', unit='muJy',
                     array=np.percentile(posterior.samples['src_f'][:,0,:],84.1,axis=0))
    c6 = fits.Column(name='FErr_MIPS_24_l', format='E', unit='muJy',
                     array=np.percentile(posterior.samples['src_f'][:,0,:],15.9,axis=0))
    c7 = fits.Column(name='Bkg_MIPS_24', format='E', unit='MJy/sr',
                     array=np.full(nsrc,np.percentile(posterior.samples['bkg'][:,0],50.0,axis=0)))
    c8 = fits.Column(name='Sig_conf_MIPS_24', format='E', unit='MJy/sr',
                     array=np.full(nsrc, np.percentile(posterior.samples['sigma_conf'][:,0],50.0,axis=0)))
    c9 = fits.Column(name='Rhat_MIPS_24', format='E', array=posterior.Rhat['src_f'][:,0])
    c10 = fits.Column(name='n_eff_MIPS_24', format='E', array=posterior.n_eff['src_f'][:,0])
    c11 = fits.Column(name='Pval_res_24', format='E', array=Bayes_P24)
    
    tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11])

    tbhdu.header.set('TUCD1', 'ID', after='TFORM1')
    tbhdu.header.set('TDESC1', 'ID of source', after='TUCD1')

    tbhdu.header.set('TUCD2', 'pos.eq.RA', after='TUNIT2')
    tbhdu.header.set('TDESC2', 'R.A. of object J2000', after='TUCD2')

    tbhdu.header.set('TUCD3', 'pos.eq.DEC', after='TUNIT3')
    tbhdu.header.set('TDESC3', 'Dec. of object J2000', after='TUCD3')

    tbhdu.header.set('TUCD4', 'phot.flux.density', after='TUNIT4')
    tbhdu.header.set('TDESC4', '24 Flux (at 50th percentile)', after='TUCD4')

    tbhdu.header.set('TUCD5','phot.flux.density',after='TUNIT5')
    tbhdu.header.set('TDESC5','24 Flux (at 84.1 percentile) ',after='TUCD5')

    tbhdu.header.set('TUCD6','phot.flux.density',after='TUNIT6')
    tbhdu.header.set('TDESC6','24 Flux (at 15.9 percentile)',after='TUCD6')

    tbhdu.header.set('TUCD7','phot.flux.density',after='TUNIT7')
    tbhdu.header.set('TDESC7','24 background',after='TUCD7')

    tbhdu.header.set('TUCD8','phot.flux.density',after='TUNIT8')
    tbhdu.header.set('TDESC8','24 residual confusion noise',after='TUCD8')

    tbhdu.header.set('TUCD9','stat.value',after='TFORM9')
    tbhdu.header.set('TDESC9','24 MCMC Convergence statistic',after='TUCD9')

    tbhdu.header.set('TUCD10','stat.value',after='TFORM10')
    tbhdu.header.set('TDESC10','24 MCMC independence statistic',after='TUCD10')

    tbhdu.header.set('TUCD11','stat.value',after='TFORM11')
    tbhdu.header.set('TDESC11','24 Bayes Pval residual statistic',after='TUCD11')

    #----Primary header-----------------------------------
    prihdr = fits.Header()
    prihdr['Prior_Cat'] = prior24.prior_cat
    prihdr['TITLE']   = 'XID+MIPS catalogue'
    #prihdr['OBJECT']  = prior250.imphdu['OBJECT'] #I need to think if this needs to change
    prihdr['CREATOR'] = 'WP5'
    prihdr['XIDplus'] = io.git_version()
    prihdr['DATE']    = datetime.datetime.now().isoformat()
    prihdu = fits.PrimaryHDU(header=prihdr)
    thdulist = fits.HDUList([prihdu, tbhdu])
    return thdulist