Esempio n. 1
0
def get_psf(psf_file, show=False):
    """Get the PSF from the fits file created by gtpsf
    """
    hdu_list = pf.open(psf_file)
    _th = np.radians(hdu_list['THETA'].data.field('Theta'))
    _en = hdu_list['PSF'].data.field('ENERGY')
    _psf = hdu_list['PSF'].data.field('PSF')
    fmt = dict(yname='Theta', yunits='rad', xname='Energy',
               xunits='MeV', zname='PSF')
    psf_th_e = xInterpolatedBivariateSplineLinear(_en, _th, _psf, **fmt)
    hdu_list.close()
    if show == True:
        for e in _en:
            psf_th = psf_th_e.vslice(e)
            fmt = dict(xname='cos(th)', xunits='', yname='psf[cos(th)]',\
                           yunits='')
            _psfxsin = xInterpolatedUnivariateSplineLinear(psf_th.x, \
                                       psf_th.y*np.sin(psf_th.x), **fmt)
            plt.plot(np.degrees(psf_th.x), psf_th.y, label='%.2f'%e)
            print 'INT(E=%.2f) ='%e, 2*np.pi*_psfxsin.integral(0, \
                                                      np.amax(psf_th.x[:-2]))
        plt.yscale('log')
        plt.legend()
        plt.show()
    return psf_th_e
Esempio n. 2
0
def main():
    """Test module
    """
    plt.figure()
    leg, lab = ref_igrb_band()
    igrb, lab2 = ref_igrb_noFGsub()
    plt.xscale('log')
    plt.yscale('log')
    plt.legend([leg, igrb], [lab, lab2])
    plt.show()
Esempio n. 3
0
def main():
    """
    """
    cl_f = 'output/output_pol/mask_check_cl.txt'
    cov_f = 'output/output_pol/mask_check_cov.fits'
    l, cl = pol_cl_parse(cl_f)
    clerr = pol_cov_parse(cov_f)
    #plt.errorbar(l, cl, fmt='o', markersize=3, elinewidth=1, yerr=clerr)
    plt.plot(l, cl, 'o', markersize=3)
    plt.xscale('log')
    plt.yscale('log')
    #plt.ylim(-1e-15, 1e-15)
    plt.show()
Esempio n. 4
0
def main():
    """
    crbkg_PSF1_file =  os.path.join(GRATOOLS_CONFIG, 
                                    'ascii/p8r2_bkg_flux_t8.txt')
    crbkg_PSF1 = get_crbkg(crbkg_PSF1_file)
    crbkg_PSF1.plot(show=False)
    x = crbkg_PSF1.x
    xx = x**2
    print x
    y1 =  crbkg_PSF1.y
    crbkg_PSF2_file =  os.path.join(GRATOOLS_CONFIG, 
                                    'ascii/p8r2_bkg_flux_t16.txt')
    crbkg_PSF2 = get_crbkg(crbkg_PSF2_file)
    crbkg_PSF2.plot(show=False)
    y2 =  crbkg_PSF2(x)
    crbkg_PSF3_file =  os.path.join(GRATOOLS_CONFIG, 
                                    'ascii/p8r2_bkg_flux_t32.txt')
    crbkg_PSF3 = get_crbkg(crbkg_PSF3_file)
    crbkg_PSF3.plot(show=False)
    y3 =  crbkg_PSF2(x)
    y = (y1/x+y2/x+y3/x)*x
    print y
    plt.yscale('log')
    plt.xscale('log')
    plt.show()
    
    fore_files_list = [os.path.join(GRATOOLS_CONFIG, \
                                        'fits/gll_iem_v06_hp512_146647.fits'),
                       os.path.join(GRATOOLS_CONFIG, \
                                        'fits/gll_iem_v06_hp512_200561.fits'),
                       os.path.join(GRATOOLS_CONFIG, \
                                        'fits/gll_iem_v06_hp512_274296.fits'),
                       os.path.join(GRATOOLS_CONFIG, \
                                        'fits/gll_iem_v06_hp512_375138.fits'),
                       os.path.join(GRATOOLS_CONFIG, \
                                        'fits/gll_iem_v06_hp512_513056.fits'),
                       ]
    e_min, e_max = 524807.00, 575439.00
    get_foreground_integral_flux_map(fore_files_list, e_min, e_max)"""
    from scipy.optimize import curve_fit
    ClFORE_FILE = os.path.join(GRATOOLS_OUT, 'fore_polspicecls.txt')
    min1, emax1, clsfore = clfore_parse(ClFORE_FILE)
    l = np.arange(len(clsfore[0]))
    clsfore_spline = xInterpolatedUnivariateSplineLinear(l, clsfore[0])
    clsfore_spline.plot(show=False)
    plt.xscale('log')
    plt.yscale('log')
    plt.show()
Esempio n. 5
0
def main():
    """Test module
    """
    leg, lab = ref_cp_band()
    plt.legend()
    plt.xscale('log')
    plt.yscale('log')
    plt.show()
    
    plt.figure()
    leg, lab = ref_igrb_band()
    igrb, lab2 = ref_igrb_noFGsub()
    plt.xscale('log')       
    plt.yscale('log')
    plt.legend([leg, igrb], [lab, lab2])
    plt.show()
Esempio n. 6
0
def main():
    """Simple test unit
    """
    from GRATools.utils.gWindowFunc import get_psf_ref
    psf_ref_file = os.path.join(GRATOOLS_CONFIG, 'ascii/PSF_UCV_PSF1.txt')
    psf_ref = get_psf_ref(psf_ref_file)
    energy = np.array([
        743.73, 1340.69, 2208.67, 3692.56, 6416.93, 11151.34, 18370.95,
        30713.33, 53373.66, 92752.78, 152802.88, 255462.38, 443942.75
    ])
    psf_en = psf_ref(energy)
    psf_min, psf_max = psf_ref.y[5], psf_ref.y[-1]
    norm_min, norm_max = 1, 0.3
    norm = norm_min + psf_en*((norm_max - norm_min)/(psf_max - psf_min)) -\
        psf_min*((norm_max - norm_min)/(psf_max - psf_min))
    plt.title('Normalization Factor')
    plt.plot(energy, norm, 'ro--', ms=5, alpha=0.75)
    #plt.plot((1e-12, 1e-5), (2, 2), '-', color='silver', linewidth=1.0)
    plt.xlabel('Energy [MeV]')
    plt.ylabel('Normalization factor')
    plt.yscale('log')
    plt.xscale('log')
    plt.ylim(0.09, 2)
    plt.show()

    nside = 512
    SRC_CATALOG_FILE = os.path.join(FT_DATA_FOLDER, 'catalogs/gll_psc_v16.fit')
    bad_pix = mask_src_weighted(SRC_CATALOG_FILE, 10000, nside)
    bad_pix += mask_gp(30, nside)
    npix = hp.nside2npix(nside)
    mask = np.ones(npix)
    for bpix in np.unique(bad_pix):
        mask[bpix] = 0
    fsky = 1 - (len(np.unique(bad_pix)) / float(npix))
    title = 'f$_{sky}$ = %.3f' % fsky
    hp.mollview(mask, title=title, coord='G')
    plt.show()
Esempio n. 7
0
FLUX_LABELS = ['UCV (t56) w/o Foreground sub', 'UCV (t56) w/ Foreground sub']
#OUT_LABEL = 'Flux_t56_srcmask2_Rm-Rp'
#OUT_LABEL = 'Flux_types_srcmask2'
#OUT_LABEL = 'Flux_t56_srcmask2-1p5-weighted'
#OUT_LABEL = 'Flux_t56_maskweight_north-south'
#OUT_LABEL = 'Flux_t56_maskweight_east-west'
OUT_LABEL = 'Flux_t56_maskweight'

plt.figure(figsize=(10, 7), dpi=80)
from GRATools.utils.gDrawRef import ref_igrb_band
from GRATools.utils.gDrawRef import ref_igrb_noFGsub
leg, lab = ref_igrb_band()
igrb, lab_igrb = ref_igrb_noFGsub()
flux = []
for f in FLUX_FILES:
    from GRATools.utils.gFTools import get_cl_param
    _emin, _emax, _emean, _f, _ferr, _cn, fsky = get_cl_param(f)
    
    spec = plt.errorbar(_emean, _f*_emean, fmt='o', markersize=3, \
                     elinewidth=1, xerr=(_emax-_emin)/2, yerr=_ferr*_emean)
    label = os.path.basename(f).replace('_parameters.txt', '')
    flux.append(spec)
plt.xscale("log")
plt.yscale("log")
plt.xlabel('Energy [MeV]')
plt.ylabel('E$^{2}$ $\cdot$ Flux [MeV cm$^{-2}$ s$^{-1}$ sr$^{-1}$]')
plt.title(' Energy Spectrum')
plt.legend([igrb, leg]+flux, [lab_igrb, lab]+FLUX_LABELS, loc=3)
#overlay_tag()
save_current_figure(OUT_LABEL+'_ESpec.png')
Esempio n. 8
0
                           (emaxs[i] - emeans[i]) / 1000],
                     yerr=cperrs_tocompare[i] * (emeans[i] / 1000)**4 /
                     ((emaxs[i] - emins[i]) / 1000)**2))
plt.xlabel('E [GeV]')
plt.ylabel('E$^{4}$/$\Delta$E$^{2}$ $\cdot$ C$_{P}$')
plt.xscale('log')
#plt.yscale('log', nonposy='clip')
plt.legend([leg_ref] + leg, [lab_ref] + lab, loc=2)
save_current_figure(OUT_LABEL + '.png')

plt.figure(figsize=(10, 7), dpi=80)
lab = []
leg = []
for i, f in enumerate(Cl_FILES):
    lab.append(os.path.basename(f).replace('_13bins_cross.txt', ''))
    leg.append(
        plt.errorbar(emeans[i] / 1000,
                     abs(0 - cps_tocompare[i]),
                     fmt='o',
                     markersize=3,
                     elinewidth=1,
                     xerr=[(emeans[i] - emins[i]) / 1000,
                           (emaxs[i] - emeans[i]) / 1000],
                     yerr=cperrs_tocompare[i]))
plt.xlabel('E [GeV]')
plt.ylabel('|$0$-C$_{P}$|')
plt.xscale('log')
plt.yscale('log', nonposy='clip')
plt.legend(leg, lab, loc=2)
save_current_figure(OUT_LABEL + '_residuals.png')
Esempio n. 9
0
FLUX_LABELS = ['UCV (t56) w/o Foreground sub', 'UCV (t56) w/ Foreground sub']
#OUT_LABEL = 'Flux_t56_srcmask2_Rm-Rp'
#OUT_LABEL = 'Flux_types_srcmask2'
#OUT_LABEL = 'Flux_t56_srcmask2-1p5-weighted'
#OUT_LABEL = 'Flux_t56_maskweight_north-south'
#OUT_LABEL = 'Flux_t56_maskweight_east-west'
OUT_LABEL = 'Flux_t56_maskweight'

plt.figure(figsize=(10, 7), dpi=80)
from GRATools.utils.gDrawRef import ref_igrb_band
from GRATools.utils.gDrawRef import ref_igrb_noFGsub
leg, lab = ref_igrb_band()
igrb, lab_igrb = ref_igrb_noFGsub()
flux = []
for f in FLUX_FILES:
    from GRATools.utils.gFTools import get_cl_param
    _emin, _emax, _emean, _f, _ferr, _cn, fsky = get_cl_param(f)

    spec = plt.errorbar(_emean, _f*_emean, fmt='o', markersize=3, \
                     elinewidth=1, xerr=(_emax-_emin)/2, yerr=_ferr*_emean)
    label = os.path.basename(f).replace('_parameters.txt', '')
    flux.append(spec)
plt.xscale("log")
plt.yscale("log")
plt.xlabel('Energy [MeV]')
plt.ylabel('E$^{2}$ $\cdot$ Flux [MeV cm$^{-2}$ s$^{-1}$ sr$^{-1}$]')
plt.title(' Energy Spectrum')
plt.legend([igrb, leg] + flux, [lab_igrb, lab] + FLUX_LABELS, loc=3)
#overlay_tag()
save_current_figure(OUT_LABEL + '_ESpec.png')
Esempio n. 10
0
    leg.append(plt.errorbar(emeans[i]/1000, 
             cps_tocompare[i]*(emeans[i]/1000)**4/((emaxs[i]-emins[i])/1000)**2,
             fmt='o', markersize=3, elinewidth=1,
             xerr=[(emeans[i]-emins[i])/1000, (emaxs[i]-emeans[i])/1000],
             yerr=cperrs_tocompare[i]*(emeans[i]/1000)**4/((emaxs[i]-emins[i])/1000)**2))
plt.xlabel('E [GeV]')
plt.ylabel('E$^{4}$/$\Delta$E$^{2}$ $\cdot$ C$_{P}$')
plt.xscale('log')
#plt.yscale('log', nonposy='clip')
plt.legend([leg_ref]+leg, [lab_ref]+lab, loc=2)
save_current_figure(OUT_LABEL+'.png')

plt.figure(figsize=(10, 7), dpi=80)
lab = []
leg = []
for i, f in enumerate(Cl_FILES):
    lab.append(os.path.basename(f).replace('_13bins_cross.txt', ''))
    leg.append(plt.errorbar(emeans[i]/1000, 
             abs(0-cps_tocompare[i]),
             fmt='o', markersize=3, elinewidth=1,
             xerr=[(emeans[i]-emins[i])/1000, (emaxs[i]-emeans[i])/1000],
             yerr=cperrs_tocompare[i]))
plt.xlabel('E [GeV]')
plt.ylabel('|$0$-C$_{P}$|')
plt.xscale('log')
plt.yscale('log', nonposy='clip')
plt.legend(leg, lab, loc=2)
save_current_figure(OUT_LABEL+'_residuals.png')