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
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()
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()
np.sqrt(len(cls_tocompare[j][i][_index])) _cls_rebin.append(clmean) _clerrs_rebin.append(clmeanerr) _l_rebin = np.array(_l_rebin) l_range_fit = np.where(np.logical_and(_l_rebin>=l_min, _l_rebin<l_max)) _cls_rebin = np.array(_cls_rebin) _clerrs_rebin = np.array(_clerrs_rebin) cp = np.polyfit(_l_rebin[l_range_fit], _cls_rebin[l_range_fit], 0, w=1/_clerrs_rebin[l_range_fit]) lab = os.path.basename(f).replace('_13bins_cls.txt', '') plt.errorbar(_l_rebin, _cls_rebin, fmt='o', markersize=3, \ elinewidth=1, xerr=[xerrL, xerrR], \ yerr=_clerrs_rebin, label=lab ) plt.plot([1, 1000], [cp[0], cp[0]], '-', linewidth=1, label='Fit '+lab) plt.plot([l_max, l_max], [-5e-15, 5e-15], '--', color='silver') plt.plot([l_min, l_min], [-5e-15, 5e-15], '--', color='silver') plt.xlim(1, _l[-1]) plt.ylim(ymin, ymax) plt.xscale('log') #plt.yscale('log', nonposy='clip') plt.xlabel('$l$') plt.ylabel('$C_{sig,l}$') plt.title('%.2f - %.2f MeV'%(emin[i], emax[i])) plt.legend(loc=4, fontsize=10) save_current_figure(OUT_LABEL+'_%i-%i.png'%(emin[i], emax[i])) ymin = ymin + abs(ymin/(1.5+0.01*i)) ymax = ymax - abs(ymax/(1.5+0.01*i))
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')
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],
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')
#OUT_LABEL = 'Cp_t56_all-north-south' #OUT_LABEL = 'Cp_t56_all-east-west' #OUT_LABEL = 'Cp_types_srmask2' plt.figure(figsize=(10, 7), dpi=80) emin, emax, emean, cps_ref, cperrs_ref = cp_parse(FLUX_REF) plt.plot((emin[0], emax[-1]), (0, 0), '--', color='gray') plt.plot((0.1, 1000), (0.1, 0.1), '-', color='silver', linewidth=1.0) plt.plot((0.1, 1000), (-0.1, -0.1), '-', color='silver', linewidth=1.0) spec, spec_label = [], [] plt.title('Flux Residuals - Ref.: %s' % FLUX_REF_LABEL) for f in FLUX_FILES: emin, emax, emean, cps, cperrs = cp_parse(f) _res = (cps_ref - cps) / cps_ref _res_err = np.sqrt(((cps / cps_ref**2) * cperrs_ref)**2 + (cperrs / cps_ref)**2) cp_plot = plt.errorbar(emean, _res, fmt='o', markersize=3, elinewidth=1, xerr=[(emean - emin), (emax - emean)], yerr=_res_err) spec.append(cp_plot) plt.xscale("log") plt.ylim(-1, 1) plt.xlabel('Energy [GeV]') plt.ylabel('(C$_{P,ref}$ - C$_{P}$) / C$_{P,ref}$') plt.legend(spec, FLUX_LABELS, loc=3) save_current_figure(OUT_LABEL + '_residuals.png')
# 'UCV-PSF1+2+3 srcmask2'] OUT_LABEL = 'Cp_t56_srcmask2-1p5-weight' #OUT_LABEL = 'Cp_t56_maskweight_all-north-south' #OUT_LABEL = 'Cp_t56_maskweight_all-east-west' #OUT_LABEL = 'Cp_t56_all-north-south' #OUT_LABEL = 'Cp_t56_all-east-west' #OUT_LABEL = 'Cp_types_srmask2' plt.figure(figsize=(10, 7), dpi=80) emin, emax, emean, cps_ref, cperrs_ref = cp_parse(FLUX_REF) plt.plot((emin[0], emax[-1]), (0, 0), '--', color='gray') plt.plot((0.1, 1000), (0.1, 0.1), '-', color='silver', linewidth=1.0) plt.plot((0.1, 1000), (-0.1, -0.1), '-', color='silver', linewidth=1.0) spec, spec_label = [], [] plt.title('Flux Residuals - Ref.: %s'%FLUX_REF_LABEL) for f in FLUX_FILES: emin, emax, emean, cps, cperrs = cp_parse(f) _res = (cps_ref - cps)/cps_ref _res_err = np.sqrt(((cps/cps_ref**2)*cperrs_ref)**2+(cperrs/cps_ref)**2) cp_plot = plt.errorbar(emean, _res, fmt='o', markersize=3, elinewidth=1, xerr=[(emean-emin), (emax-emean)], yerr=_res_err) spec.append(cp_plot) plt.xscale("log") plt.ylim(-1, 1) plt.xlabel('Energy [GeV]') plt.ylabel('(C$_{P,ref}$ - C$_{P}$) / C$_{P,ref}$') plt.legend(spec, FLUX_LABELS, loc=3) save_current_figure(OUT_LABEL+'_residuals.png')
cperrs_tocompare.append(np.array(cperrs)) logger.info('Created %s' %f.replace('_cls.txt', '_cps.txt')) txt.close() print cps_tocompare[0]*(emeans[0]/1000)**4/((emaxs[0]-emins[0])/1000)**2 print emeans[0]/1000 from GRATools.utils.gDrawRef import ref_cp_band plt.figure(figsize=(10, 7), dpi=80) lab = [] leg = [] leg_ref, lab_ref = ref_cp_band() for i, f in enumerate(Cl_FILES): #print cps_tocompare[i] lab.append(os.path.basename(f).replace('_13bins_cls.txt', '')) 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=3) save_current_figure(OUT_LABEL+'.png') #plt.show()
os.path.join(GRATOOLS_OUT, 'Allyrs_UCV_t1_srcmask2_13bins_parameters.txt'), os.path.join(GRATOOLS_OUT, 'Allyrs_UCV_t2_srcmask2_13bins_parameters.txt') ] FLUX_LABELS = ['UCV (t56) PSF0', 'UCV (t56) PSF3', 'UCV (t56) FRONT', 'UCV (t56) BACK'] #OUT_LABEL = 'Flux_evtypes' plt.figure(figsize=(10, 7), dpi=80) from GRATools.utils.gFTools import get_cl_param _emin, _emax, _emean, _f_ref, _ferr_ref, _cn_ref, fsky_ref = get_cl_param(FLUX_REF) plt.plot((_emin[0], _emax[-1]), (0, 0), '--', color='gray') plt.plot((100, 1000000), (0.1, 0.1), '-', color='silver', linewidth=1.0) plt.plot((100, 1000000), (-0.1, -0.1), '-', color='silver', linewidth=1.0) flux, flux_label = [], [] plt.title('Flux Residuals - Ref.: %s'%FLUX_REF_LABEL) for f in FLUX_FILES: _emin, _emax, _emean, _f, _ferr, _cn, fsky = get_cl_param(f) #print _ferr _res = (_f_ref - _f)/_f_ref _res_err = np.sqrt(((_f/_f_ref**2)*_ferr_ref)**2+(_ferr/_f_ref)**2) spec = plt.errorbar(_emean, _res, fmt='o', markersize=3, \ elinewidth=1, xerr=(_emax-_emin)/2, yerr=_res_err) flux.append(spec) plt.xscale("log") #plt.yscale("log") plt.ylim(-1, 1) plt.xlabel('Energy [MeV]') plt.ylabel('($\Phi_{fef}$ - $\Phi$) / $\Phi_{fef}$') plt.legend(flux, FLUX_LABELS, loc=3) #overlay_tag() save_current_figure(OUT_LABEL+'_ESpecRes.png')
def main(): """Test module """ """ plt.figure(figsize=(10, 7), dpi=80) _l = np.arange(0, 10, 2) for l in _l: pl_th = get_pl_vs_th(l, np.arange(-1, 1, 0.00001)) plt.plot(np.arange(-1, 1, 0.00001), pl_th, '.', label='l = %i'%l) plt.legend() #plt.show() """ #out_wbeam_txt = 'output/Wbeam_P8R2_ULTRACLEANVETO_V6_56.txt' #wb = get_wbeam(out_wbeam_txt) #wb.plot() """ NSIDE = 1 NPIX = hp.nside2npix(NSIDE) iii = np.arange(NPIX) dec, ra = IndexToDeclRa(NSIDE, iii) index = np.where(abs(dec)>10) ra = ra[index] dec = dec[index] #ra = ra #dec = dec plt.figure(figsize=(10, 7), dpi=80) hp.mollview(iii, title="Mollview image RING") plt.figure(figsize=(10, 7), dpi=80) lab, plots = [], [] for i in range(0, len(ra)): print ra[i], dec[i] out_wbeam_txt = 'output/%i_prova.txt'%i psf_file = 'output/%i_prova.fits'%i dict_gtpsf = {'expcube':'/data1/data/FT-files/output/output_gtltcube'+\ '/Allyrs_filtered_gti_ltcube.fits', 'outfile': psf_file, 'irfs': 'P8R2_ULTRACLEANVETO_V6', 'evtype': 3, 'ra': ra[i], 'dec': dec[i], 'emin': 500, 'emax': 600000, 'nenergies': 10, 'thetamax': 30, 'ntheta': 300} from GRATools.utils.ScienceTools_ import gtpsf gtpsf(dict_gtpsf) _l = np.arange(0, 1000, 4) psf = get_psf(psf_file) if not os.path.exists(out_wbeam_txt): wb = build_wbeam(psf, _l, out_wbeam_txt) else: wb = get_wbeam(out_wbeam_txt) wb_1GeV = wb.hslice(1000) wl = wb_1GeV.plot(show=False, label='RA:%i, Dec:%i'%(ra[i],dec[i])) #lab.append('%i-%i'%(ra[i],dec[i])) #plots.append(wl) """ out_wbeam_txt = 'output/Wbeam_P8R2_ULTRACLEANVETO_V6_56.txt' wb = get_wbeam(out_wbeam_txt) plt.figure(figsize=(10, 7), dpi=80) _l = np.arange(0, 1000, 4) wb_500MeV = wb.hslice(500) plt.plot(wb_500MeV.x, wb_500MeV.y**2, label='0.5 GeV') wb_5GeV = wb.hslice(5000) plt.plot(wb_5GeV.x, wb_5GeV.y**2, label='5 GeV') wb_50GeV = wb.hslice(50000) plt.plot(wb_50GeV.x, wb_50GeV.y**2, label='50 GeV') wb_100GeV = wb.hslice(100000) plt.plot(wb_100GeV.x, wb_100GeV.y**2, label='100 GeV') wb_300GeV = wb.hslice(300000) plt.plot(wb_300GeV.x, wb_300GeV.y**2, label='300 GeV') plt.legend() plt.xlabel('Energy [MeV]') plt.ylabel('W$^{2}$$_{beam}$') plt.show()
plt.figure(figsize=(10, 7), dpi=80) lab = [] leg = [] leg_ref, lab_ref = ref_cp_band() for i, f in enumerate(Cl_FILES): lab.append(os.path.basename(f).replace('_13bins_cross.txt', '')) 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')