def do_analysis(minuit_new=False):
    global emin,emax
    if method=='polychord':
        polychord=True
    else:
        polychord=False
    b.run_tag = run_tag_energy
    tri = fa.make_triangle(b,run_tag_energy,edep=True,polychord=polychord,minuit_new=minuit_new)
    tri.make_triangle()

    sle = fa.save_log_evidence(b,edep=True,polychord=polychord)


    spect_dir = work_dir + 'data/spect/'
    if not os.path.exists(spect_dir):
        os.mkdir(spect_dir)
    if save_norm_label != 'False' and save_norm_label != 'false':
        cs = fa.compute_spectra(b,run_tag_energy,f.CTB_en_bins[0],f.CTB_en_bins[-1],edep=True,plane_mask=plot_plane_mask,band_mask_range = [-plot_pmval,plot_pmval],lcut=plot_lcut,lmin=plot_lmin,lmax=plot_lmax,bcut=plot_bcut,bmin=plot_bmin,bmax=plot_bmax,mask_ring=plot_mask_ring,outer=plot_outer,inner=plot_inner,minuit_new = minuit_new,input_mask=force_ps_mask,the_input_mask=b.mask_total) # spectra over the whole energy range
        cs.mask_total_dict['bubs']=np.logical_not(b.templates_dict_nested['bubs']['summed_templates_not_compressed'])
        cs.make_spectra_dict()
        cs.make_norm_dict()
        cs.save_spectra_dict(spect_dir + save_spect_label,emin,emax,over_write= False)
        cs.save_norm_dict(spect_dir + save_norm_label,emin,emax,over_write= False)
    else:
        cs = fa.compute_edep_spectra(b,run_tag_energy,b.CTB_en_bins,polychord=polychord,plane_mask=plot_plane_mask,band_mask_range = [-plot_pmval,plot_pmval],lcut=plot_lcut,lmin=plot_lmin,lmax=plot_lmax,bcut=plot_bcut,bmin=plot_bmin,bmax=plot_bmax,mask_ring=plot_mask_ring,outer=plot_outer,inner=plot_inner,minuit_new = minuit_new,input_mask=force_ps_mask,the_input_mask=b.mask_total) #,edep=True)
        cs.make_spectra_dict()
        cs.save_spectra_dict(spect_dir + save_spect_label)

    if n_ebins>1:
        ##plot spectrum
        msp_inst = msp.make_spectra_plot(spect_dir + save_spect_label + '.npy')
        if not fixed_background:
            msp_inst.plot_spectra_median('back',color='Orange',label='back',linestyle='-')
        if nfw_dm:
            msp_inst.plot_spectra_median('nfw',color='Chartreuse',label='nfw',linestyle='-')
        if not fixed_background:
            msp_inst.plot_spectra_band('back',interpolate=True, alpha=0.5,linewidth=0,facecolor='Orange')
        if nfw_dm:
            msp_inst.plot_spectra_band('nfw',interpolate=True, alpha=0.5,linewidth=0,facecolor='Chartreuse')
        if not poiss:
            colors=['Blue','Green','Purple'][0:len(ps_list)]
            for mod,color in map(None,ps_list,colors):
                msp_inst.plot_spectra_median(mod + '-np',color=color,label=mod+'-np',linestyle='--')
                msp_inst.plot_spectra_band(mod + '-np',interpolate=True, alpha=0.5,linewidth=0,facecolor=color)

        plt.axhline(y=0.,color='k',ls='dashed')
        plt.xscale('log')
        plt.xlabel('E [GeV]', fontsize=14)
        plt.ylabel('$E^2 dN / dE$  [GeV / cm$^2$ / s / sr]', fontsize=18)
        plt.title('Spectrum',fontsize=14)
        plt.legend(fontsize=12,loc=3)
        plt.savefig(b.plots_dir_for_run + save_spect_label + '.pdf',bbox_inches='tight')
        plt.close()
    if not poiss:
        print 'medians: ', b.medians_not_log
        print 'norm_non_poiss: ', b.norms_non_poiss
        ##save PS templates/medians
        if len(ps_save_list)>0:
            for comp, filename in map(None,ps_save_list,ps_save_filename_list):
                spti=fa.save_ps_template_info(b,run_tag_energy,edep=True,polychord=polychord,minuit_new = minuit_new)
                spti.save_ps_template(comp,filename)
        ##plot dn/ds across energies
        for ebin_num in range(b.number_energy_bins):
            p3FGL = fa.plot_3FGL(f,CTB_en_min=b.CTB_en_bins[ebin_num],CTB_en_max=b.CTB_en_bins[ebin_num+1],plane_mask=plot_plane_mask,band_mask_range = [-plot_pmval,plot_pmval],lcut=plot_lcut,lmin=plot_lmin,lmax=plot_lmax,bcut=plot_bcut,bmin=plot_bmin,bmax=plot_bmax,mask_ring=plot_mask_ring,outer=plot_outer,inner=plot_inner,input_mask=force_ps_mask,the_input_mask=b.mask_total)
            p3FGL.configure_3FGL(flux_min=10**-12,flux_max=10**-8,n_flux_bins = 25,only_gal = not(high_lat),error_range = 0.68) 
            pdnds = fa.plot_dnds(b,plane_mask=plot_plane_mask,band_mask_range = [-plot_pmval,plot_pmval],lcut=plot_lcut,lmin=plot_lmin,lmax=plot_lmax,bcut=plot_bcut,bmin=plot_bmin,bmax=plot_bmax,mask_ring=plot_mask_ring,outer=plot_outer,inner=plot_inner,input_mask=force_ps_mask,the_input_mask=b.mask_total)
            plt.figure(figsize=(8,6))
            p3FGL.plot_3FGL(fmt = 'o', color='black',markersize=7,label='3FGL PS')
            colors=['Orange','Chartreuse','Blue'][0:len(ps_list)]
            line_colors=['Red','Green','Purple'][0:len(ps_list)]
            alpha_list=[1,0.75,0.5][0:len(ps_list)]
            for mod,color,line_color,alpha in map(None,ps_list,colors,line_colors,alpha_list):
                print 'plotting source-count function for ', mod
                pdnds.plot_source_count_band(mod,edep=True,ebin=ebin_num,nsteps=100,calculate_dnds=True,facecolor=color,interpolate=True, alpha=alpha,linewidth=0)
                pdnds.plot_source_count_median(mod,edep=True,ebin=ebin_num,color=line_color,linestyle='--',label=mod + ' (median)')
            if len(ps_fixed_filename_list) > 0:
                for comp in map(None,ps_fixed_list):
                    pdnds.plot_fixed_source_count(comp,ebin=ebin_num,linestyle='-',label=comp + ' (fixed)')
            plt.xscale('log')
            plt.yscale('log')
            plt.ylim((2*10**(5),10**12))
            plt.xlim(10**-12., 10**-8.)
            plt.tick_params(axis='x', length=5,width=2,labelsize=18)
            plt.tick_params(axis='y',length=5,width=2,labelsize=18)
            plt.xlabel('$F$  [photons / cm$^2$ / s]', fontsize=18)
            plt.ylabel('$dN/dF$  [photons$^{-1}$ cm$^2$ s deg$^{-2}$]', fontsize=18)
            plt.legend(fontsize=15)
            plt.title('Energy: '+str(np.round(b.CTB_en_bins[ebin_num],3)) + '-'+str(np.round(b.CTB_en_bins[ebin_num+1],3)),fontsize=15)
            plt.savefig(b.plots_dir_for_run + 'dnds_plot_en_'+str(np.round(b.CTB_en_bins[ebin_num],3)) + '-'+str(np.round(b.CTB_en_bins[ebin_num+1],3)) + '.pdf',bbox_inches='tight')
            plt.close()
Esempio n. 2
0
# Set plot range and name
y_min=-0.00000006
y_max=0.0000001
x_min=0.3
x_max=15
plot_name="Top2_test"

# Load the TS values - not using at present but may want later
loadts = pkl.load(open("/zfs/nrodd/NPTFWorking/data/ps_output/ts/TS_3FGL_tiny_eachts_E_0_15.p", "rb"))

print "TS of ps1:",loadts['ps_1']
print "TS of ps2:",loadts['ps_2']

# Feed the spectra into 
msp_inst = msp.make_spectra_plot('/zfs/nrodd/NPTFWorking/data/ps_output/spect/spectra_IG_p6_NSIDE256_bubs_iso_3FGL_tiny_eachps_E_0_15.npy')

# Add in the first 5 components to plot
msp_inst.plot_spectra_median_ps('ps_1',label='ps$_1$',color='steelblue',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_2',label='ps$_2$',color='tomato',linestyle='-')
#msp_inst.plot_spectra_median_ps('ps_3',label='ps$_3$',color='Green',linestyle='-')
#msp_inst.plot_spectra_median_ps('ps_4',label='ps$_4$',color='Purple',linestyle='-')
#msp_inst.plot_spectra_median_ps('ps_5',label='ps$_5$',color='Chartreuse',linestyle='-')
msp_inst.plot_spectra_band_ps('ps_1',interpolate=True, alpha=0.5,linewidth=0,facecolor='steelblue')
msp_inst.plot_spectra_band_ps('ps_2',interpolate=True, alpha=0.5,linewidth=0,facecolor='tomato')
#msp_inst.plot_spectra_band_ps('ps_3',interpolate=True, alpha=0.5,linewidth=0,facecolor='Green')
#msp_inst.plot_spectra_band_ps('ps_4',interpolate=True, alpha=0.5,linewidth=0,facecolor='Purple')
#msp_inst.plot_spectra_band_ps('ps_5',interpolate=True, alpha=0.5,linewidth=0,facecolor='Chartreuse')

# Now add in the 3FGL prediction
en_linear = np.linspace(np.log10(0.3),np.log10(300),31)
Esempio n. 3
0
import sys, os
import numpy as np
import pickle as pkl
import analysis_classes.make_spectra_plot as msp
import matplotlib.pyplot as plt
import matplotlib as mpl

# Set plot range and name
y_min=-0.000012
y_max=0.000015
x_min=0.3
x_max=3
plot_name="NFWps"

# Feed the spectra into 
msp_inst = msp.make_spectra_plot('/zfs/nrodd/NPTFWorking/data/ps_output/spect/3FGL_nfw_nfwps_E_0_9.npy')

# Add in the first 5 components to plot
msp_inst.plot_spectra_median_ps('nfw_ps_0',label='NFW + ps$_0$',color='lightsalmon',linestyle='-')
msp_inst.plot_spectra_median_ps('nfw_ps_10',label='NFW + ps$_{10}$',color='tomato',linestyle='-')
msp_inst.plot_spectra_median_ps('nfw_ps_100',label='NFW + ps$_{100}$',color='red',linestyle='-')
msp_inst.plot_spectra_median_ps('nfw_ps_251',label='NFW + ps$_{251}$',color='firebrick',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_comb_10',label='ps$_{10}$',color='lightblue',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_comb_100',label='ps$_{100}$',color='cornflowerblue',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_comb_251',label='ps$_{251}$',color='blue',linestyle='-')
msp_inst.plot_spectra_band_ps('nfw_ps_0',interpolate=True, alpha=0.5,linewidth=0,facecolor='lightsalmon')
msp_inst.plot_spectra_band_ps('nfw_ps_10',interpolate=True, alpha=0.5,linewidth=0,facecolor='tomato')
msp_inst.plot_spectra_band_ps('nfw_ps_100',interpolate=True, alpha=0.5,linewidth=0,facecolor='red')
msp_inst.plot_spectra_band_ps('nfw_ps_251',interpolate=True, alpha=0.5,linewidth=0,facecolor='firebrick')
msp_inst.plot_spectra_band_ps('ps_comb_10',interpolate=True, alpha=0.5,linewidth=0,facecolor='lightblue')
msp_inst.plot_spectra_band_ps('ps_comb_100',interpolate=True, alpha=0.5,linewidth=0,facecolor='cornflowerblue')
Esempio n. 4
0
y_max=0.000000001
x_min=2
x_max=20
plot_name="Top5"

# Load the TS values - not using at present but may want later
loadts = pkl.load(open("/zfs/nrodd/NPTFWorking/data/ps_output/ts/TS_fake_test_eachts_E_8_15.p", "rb"))

print "TS of ps1:",loadts['ps_1']
print "TS of ps2:",loadts['ps_2']
print "TS of ps3:",loadts['ps_3']
print "TS of ps4:",loadts['ps_4']
print "TS of ps5:",loadts['ps_5']

# Feed the spectra into 
msp_inst = msp.make_spectra_plot('/zfs/nrodd/NPTFWorking/data/ps_output/spect/spectra_IG_p6_NSIDE128_bubs_iso_fake_test_eachps_E_8_15.npy')

# Add in the first 5 components to plot
msp_inst.plot_spectra_median_ps('ps_1',label='ps$_1$',color='steelblue',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_2',label='ps$_2$',color='tomato',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_3',label='ps$_3$',color='lime',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_4',label='ps$_4$',color='violet',linestyle='-')
msp_inst.plot_spectra_median_ps('ps_5',label='ps$_5$',color='Orange',linestyle='-')
msp_inst.plot_spectra_band_ps('ps_1',interpolate=True, alpha=0.5,linewidth=0,facecolor='steelblue')
msp_inst.plot_spectra_band_ps('ps_2',interpolate=True, alpha=0.5,linewidth=0,facecolor='tomato')
msp_inst.plot_spectra_band_ps('ps_3',interpolate=True, alpha=0.5,linewidth=0,facecolor='lime')
msp_inst.plot_spectra_band_ps('ps_4',interpolate=True, alpha=0.5,linewidth=0,facecolor='violet')
msp_inst.plot_spectra_band_ps('ps_5',interpolate=True, alpha=0.5,linewidth=0,facecolor='Orange')

# Make plot
plt.axhline(y=0.,color='k',ls='dashed')
Esempio n. 5
0

ps_list = np.array(np.loadtxt(ps_list_string))
ell_0 = ps_list[::,0]
b_0 = ps_list[::,1]

ps_string = ['ps-l-'+str(round(ell_i,3)) + '-b-'+str(round(b_i,3)) for ell_i,b_i in map(None,ell_0,b_0)]

if not os.path.exists(plot_dir):
    os.mkdir(plot_dir)



#make the plot
print spectra_file + '.npy'
msp_inst = msp.make_spectra_plot(spectra_file + '.npy')

#print 'ps model is ', ps_model

the_fig = plt.figure(figsize=(8,6))
colors_ = list(six.iteritems(colors.cnames))[0:len(ps_string)]

for ps_string_i,color in map(None,ps_string,colors_):
	msp_inst.plot_spectra_median_ps(ps_string_i,label=ps_string_i,linestyle='-',color = color[0])
	msp_inst.plot_spectra_band_ps(ps_string_i,interpolate=True, alpha=0.5,linewidth=0,facecolor=color[0])
plt.axhline(y=0.,color='k',ls='dashed')
plt.xscale('log')
plt.yscale('log')
plt.xlabel('E [GeV]', fontsize=14)
plt.ylabel('$E^2 dN / dE$  [GeV / cm$^2$ / s]', fontsize=18)
plt.ylim(ylim)
        #(self,b,run_tag,En_min,En_max,edep=False,ebin=0,*args,**kwargs)
        cs = fa.compute_spectra(b,run_tag_energy,b.CTB_en_bins[0],b.CTB_en_bins[-1], band_mask_range = [-mask_b_plot,mask_b_plot],mask_ring = False) 
        cs.mask_total_dict['bubs']=np.logical_not(b.templates_dict_nested['bubs']['summed_templates_not_compressed'])
        cs.make_spectra_dict()
        cs.make_norm_dict()
        if save_spect_label != 'False' or save_spect_label != 'false':
            cs.save_spectra_dict(spect_dir + save_spect_label,emin,emax,over_write= False)
        if save_norm_label != 'False' or save_norm_label != 'false':
            cs.save_norm_dict(spect_dir + save_norm_label,emin,emax,over_write= False)
    else:
        cs = fa.compute_edep_spectra(b,run_tag_energy,b.CTB_en_bins,band_mask_range = [-mask_b_plot,mask_b_plot],mask_ring=False) #spectra over whole energy range
        cs.make_spectra_dict()
        cs.save_spectra_dict(spect_dir + save_spect_label)

        ##plot spectrum
        msp_inst = msp.make_spectra_plot(spect_dir + save_spect_label + '.npy')
        print np.load(spect_dir + save_spect_label + '.npy')
        msp_inst.plot_spectra_median('back',color='Orange',label='back',linestyle='-')
        msp_inst.plot_spectra_median('iso',color='Chartreuse',label='iso',linestyle='-')
        msp_inst.plot_spectra_band('back',interpolate=True, alpha=0.5,linewidth=0,facecolor='Orange')
        msp_inst.plot_spectra_band('iso',interpolate=True, alpha=0.5,linewidth=0,facecolor='Chartreuse')
        if not poiss:
            msp_inst.plot_spectra_median('iso-np',color='Blue',label='iso-np',linestyle='--')
            msp_inst.plot_spectra_band('iso-np',interpolate=True, alpha=0.5,linewidth=0,facecolor='Blue')
        #plt.show()

        plt.axhline(y=0.,color='k',ls='dashed')
        plt.xscale('log')
        plt.yscale('log')
        plt.xlabel('E [GeV]', fontsize=14)
        plt.ylabel('$E^2 dN / dE$  [GeV / cm$^2$ / s / sr]', fontsize=18)