예제 #1
0
def make_triangle():
    if just_disk:
        mt=fa.make_triangle(b_disk,run_tag_disk_only,edep=True)
        mt.make_triangle(return_fig=False,save_fig=True)
    if poiss:
        mt=fa.make_triangle(b_poiss,run_tag_poiss,edep=True)
        mt.make_triangle(return_fig=False,save_fig=True,the_range=range_poiss)
    if plus_IPS:
        mt=fa.make_triangle(b_plus_IPS,run_tag_plus_iso,edep=True)
        mt.make_triangle(return_fig=False,save_fig=True,the_range=range_NDI)
예제 #2
0
def do_analysis(minuit_new=False,add_group_ps=False,ps_number=0,fdn=True,fdrun=False):
    global emin,emax, eachps_En_center, ps_norms, diffnormfix
    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)
    plot_name='triangle_ps_' + str(ps_number) + '.pdf'
    tri.make_triangle(plot_name=plot_name)

    if not minuit_new:
        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)
    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'])
    eachps_En_center = cs.En_center
    cs.make_norm_dict()
    cs.make_spectra_dict()

    if not fdrun:
        full_dict['nfw_ps_'+str(ps_number)] = cs.spectra_dict['nfw-0'] 
        if add_group_ps:
            full_dict['ps_comb_'+str(ps_number)] = cs.spectra_dict['ps_comb-0']
    else:
        diffnormfix = cs.norm_dict[diff + '-0']
예제 #3
0
def do_analysis(i=0,n_ps_groupi=0,psloop1=False,pscomball=False,psloop2bkg=False,psloop2=False,minuit_new=False):
    global emin,emax, eachps_dict, eachps_En_center, TSbkg, TS, ps_norms_loop1, ps_norms
    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)
    if psloop1:
        plot_name='triangle_psloop1_i' + str(i+1) + '.pdf'
    if pscomball:
        plot_name='triangle_pscomball.pdf'
    if psloop2bkg:
        plot_name='triangle_psloop2bkg_i' + str(i+1) + '.pdf'
    if psloop2:
        plot_name='triangle_psloop2_i' + str(i+1) + '.pdf'
    tri.make_triangle(plot_name=plot_name)

    if not minuit_new:
        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 not pscomball:
        cs = fa.compute_spectra(b,run_tag_energy,f.CTB_en_bins[0],f.CTB_en_bins[-1],edep=True,band_mask_range=[0,0])
    else:
        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'])
    eachps_En_center = cs.En_center
    if psloop1 or pscomball or psloop2:
        cs.make_norm_dict()
    if psloop2 or psloop2bkg or pscomball:
        cs.make_spectra_dict()
    if pscomball:
        cs.save_spectra_dict(spect_dir + save_spect_label,emin,emax,over_write=True)
        cs.save_norm_dict(spect_dir + save_norm_label,emin,emax,over_write=True)

    if psloop1:
        # Add in new norm values
        for j in range(n_ps_groupi):
            ps_norms_loop1[i*n_ps_run+j] *= cs.norm_dict['ps_' + str(i*n_ps_run+j+1) + '-0']
        # Update existing norm values if not the first loop
        if i != 0:
            for k in range(i*n_ps_run):
                ps_norms_loop1[k] *= cs.norm_dict['ps_comb-0']

    if psloop2bkg:
        TSbkg = 2*b.s['nested sampling global log-evidence']

    # Add norms to eachps_dict dictionary
    if psloop2:
        TS = 2*b.s['nested sampling global log-evidence'] - TSbkg
        eachts_dict['ps_' + str(i+1)] = TS
        eachps_dict['ps_' + str(i+1)] = cs.spectra_dict['ps_' + str(i+1) + '-0']
        ps_norms[i] *= cs.norm_dict['ps_' + str(i+1) + '-0']
예제 #4
0
    def calc_flux_array(self):
        """ Function to calculate the LL for an array of fluxes in a given energy bin """

        # First determine the associated spectrum
        self.compute_template_spectrum()

        # Calculate baseline counts to normalise fluxes we scan over
        # Go from 10**(bin_min)*mean up to 10**(bin_max)*mean in nbins steps
        b = self.setup_b_instance(0, add_ps_mask=True)
        mean = np.sum(b.CTB_masked_compressed[0]) / len(
            b.CTB_masked_compressed[0])
        A_array = mean * 10**np.linspace(self.bin_min, self.bin_max,
                                         self.nbins)

        # Now setup and compute the arrays
        LL_array = np.array([])
        A_array_short = np.array([])
        spect_array = np.array([])

        for i in range(len(A_array)):
            print "on i =", i
            # Calculate LL
            if i == 0:
                b1 = self.setup_b_instance(A_array[i], add_ps_mask=True)
            else:
                for key in b1.fixed_template_dict_nested.keys():
                    b1.fixed_template_dict_nested[
                        key] = b1.fixed_template_dict_nested[key] * A_array[
                            i] / A_array[i - 1]
            b1.perform_scan(run_tag=b1.tag + '_F' + str(i))
            b1.load_scan(run_tag=b1.run_tag, edep=True, no_analyzer=True)
            ll_val = b1.ll(b1.medians, 4, 4)
            # Make triangle
            mt = fa.make_triangle(b1, b1.run_tag, edep=True)
            #mt.make_triangle(plot_name='triangle-E'+str(self.flux_array_ebin)+'-F'+str(i)+'.pdf')

            # Append to arrays
            LL_array = np.append(LL_array, ll_val)
            A_array_short = np.append(A_array_short, A_array[i])
            spect_array = self.spectrum * np.array(A_array_short)

        # Save output
        np.save(
            work_dir + 'ScanOutput/' + self.tag + '/En_array-' +
            str(self.flux_array_ebin) + '.npy', self.En_center)
        np.save(
            work_dir + 'ScanOutput/' + self.tag + '/LL_array-' +
            str(self.flux_array_ebin) + '.npy', LL_array)
        np.save(
            work_dir + 'ScanOutput/' + self.tag + '/Flux_array-' +
            str(self.flux_array_ebin) + '.npy', spect_array)
예제 #5
0
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)

    cs = fa.compute_spectra(b,run_tag_energy,f.CTB_en_bins[0],f.CTB_en_bins[-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,minuit=True,input_mask=force_ps_mask,the_input_mask=b.mask_total,edep=True)
    cs.mask_total_dict['bubs']=np.logical_not(b.templates_dict_nested['bubs']['summed_templates_not_compressed'])
    cs.make_spectra_dict()
    for i in cs.spectra_dict.keys():
        print i,"has flux:",cs.spectra_dict[i]
def do_analysis(i=0,n_ps_groupi=0,psloop1=False,pscomball=False,psloop2=False,minuit_new=False):
    global emin,emax, eachps_dict, eachps_En_center
    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()

    if not minuit_new:
        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)
    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'])
    eachps_En_center = cs.En_center
    if psloop1 or pscomball:
        cs.make_norm_dict()
    if psloop2 or pscomball:
        cs.make_spectra_dict()
    if pscomball:
        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)

    if psloop1:
        # Create pslooptemp and psalltemp 
        pslooptempar = np.zeros(hp.nside2npix(nside))
        if os.path.exists(ps_temp_dir + pslooptemp):
            pslooptempar += fits.open(ps_temp_dir + pslooptemp)[0].data
        for j in range(n_ps_groupi):
            pstempj = b.templates_dict['ps_' + str(i*n_ps_run+j+1) + '-0'][0]
            psnormj = cs.norm_dict['ps_' + str(i*n_ps_run+j+1) + '-0']
            pswritej = pstempj*psnormj
            pslooptempar += pswritej
            fits.append(ps_temp_dir + psalltemp, pswritej)
        fits.writeto(ps_temp_dir + pslooptemp,pslooptempar,clobber=True)

    # Add norms to eachps_dict dictionary
    if psloop2:
        eachps_dict['ps_' + str(i+1)] = cs.spectra_dict['ps_' + str(i+1) + '-0']
예제 #7
0
def make_triangle():
    mt=fa.make_triangle(b,run_tag,edep=True)
    mt.make_triangle(return_fig=False,save_fig=True)

    mt=fa.make_triangle(b_disk,run_tag_disk_only,edep=True)
    mt.make_triangle(return_fig=False,save_fig=True)

    mt=fa.make_triangle(b_poiss,run_tag_poiss,edep=True)
    mt.make_triangle(return_fig=False,save_fig=True)

    mt=fa.make_triangle(b_just_NFW,run_tag_just_NFW,edep=True)
    mt.make_triangle(return_fig=False,save_fig=True)

    mt=fa.make_triangle(b_iso,run_tag_iso,edep=True)
    mt.make_triangle(return_fig=False,save_fig=True)

    if plus_IPS:
        mt=fa.make_triangle(b_plus_IPS,run_tag_plus_iso,edep=True)
        mt.make_triangle(return_fig=False,save_fig=True)
    print 'Performing an NPTF ...'
    print 'The PSF (sigma) is ', sigma_PSF_deg_red, ' in degrees.'
else:
    if computing_spectra:
        #b.configure_for_edep_scan() - this is already called in initiate poissonian edep
        b.initiate_poissonian_edep()
    
#########################
#perform scan / load scan
if run:
    print 'The nside for this scan is ', b.nside
    b.perform_scan(run_tag = run_tag_energy)
if analysis:
    b.run_tag = run_tag_energy
    #make triangle plot
    tri = fa.make_triangle(b,run_tag_energy,edep=True)
    tri.make_triangle()

    sle = fa.save_log_evidence(b,edep=True)
    spect_dir = work_dir + 'data/spect/' 
    if not os.path.exists(spect_dir):
        os.mkdir(spect_dir)
    if computing_spectra:
        #(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,edep=True) 
        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':
예제 #9
0
    for ell_i, b_i, ps_string_i in map(None,ell_0,b_0,ps_string):
        b.add_poiss_model(ps_string_i,'${(l10A_{ps})}_{l = '+str(round(ell_i,3))+ '}^{b = ' + str(round(b_i,3))+'}$',[-6,6],True)

#####perform the scan
b.configure_for_scan()
b.initiate_poissonian()
print 'Performing the scan ...'
if run:
    b.perform_scan(run_tag = run_tag_energy)


##################
###perform anaysis
if analysis:
    #make triangle plot
    tri = fa.make_triangle(b,run_tag_energy)
    tri.make_triangle()

    sle = fa.save_log_evidence(b)



    spect_dir = work_dir + 'data/spect/' 
    spect_dir_ps = spect_dir + '/ps/'
    for d in [spect_dir,spect_dir_ps]:
        if not os.path.exists(d):
            os.mkdir(d)
    # cs = fa.compute_spectra(b,run_tag_energy,f.CTB_en_bins[0],f.CTB_en_bins[-1],band_mask_range = [-0.,0.],mask_ring = True,outer=sigma_PSF_deg,lat= 90 - mask_b,lng = mask_ell) #spectra over whole energy range
    cs = fa.compute_spectra(b,run_tag_energy,f.CTB_en_bins[0],f.CTB_en_bins[-1],band_mask_range = [-0.,0.],mask_ring = False) #spectra over whole energy range
    # cs.mask_total_dict['bubs']=np.logical_not(b.templates_dict_nested['bubs']['summed_templates_not_compressed'])
    cs.make_spectra_dict()
예제 #10
0
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()
예제 #11
0
def do_triangle():
    mt=fa.make_triangle(b,run_tag,edep=True)
    mt.make_triangle(return_fig=False,save_fig=True)
예제 #12
0
        #b.configure_for_edep_scan() - this is already called in initiate poissonian edep
        b.initiate_poissonian_edep()

        #########################
        #perform scan / load scan

        if run:
            print 'The nside for this scan is ', b.nside
            if method=='multinest':
                b.perform_scan(run_tag = run_tag)
            elif method=='minuit':
                b.perform_scan_minuit(run_tag = run_tag)
                b.save_minuit()
            b.run_tag = run_tag
            #make triangle plot
            tri = fa.make_triangle(b,run_tag,edep=True,minuit_new=minuit_new)
            tri.make_triangle(plot_name='triangle_2MASS_'+str(twomass_temp)+' '+str(base_sigma_v*xsec)+".pdf")
            if not minuit_new:
                sle = fa.save_log_evidence(b,edep=True)
            
            if twomass_temp: 
                print 'logevidence with twomass '+ str(twomass_temp) + ' is ', sle.lge
                lge2 = sle.lge
            else: 
                print 'logevidence with twomass '+ str(twomass_temp) + ' is ', sle.lge
                lge1 = sle.lge
    # Get BF from the two runs
    print 'lge1 (2MASS false) is', lge1
    print 'lge2 (2MASS true) is', lge2
    BF = np.exp(lge2-lge1)
    print 'Bayes factor is', BF
예제 #13
0
        b.add_poiss_model('iso','$A_{iso}$',[0,2],False)
        if twomass_temp:
            b.add_poiss_model('2mass','$A_{2mass}$',[-9,2],True)

        #b.configure_for_edep_scan() - this is already called in initiate poissonian edep
        b.initiate_poissonian_edep()

        #########################
        #perform scan / load scan

        if run:
            print 'The nside for this scan is ', b.nside
            b.perform_scan(run_tag = run_tag)
            b.run_tag = run_tag
            #make triangle plot
            tri = fa.make_triangle(b,run_tag,edep=True)
            tri.make_triangle(plot_name='triangle_2MASS_'+str(twomass_temp)+' '+str(base_sigma_v*xsec)+".pdf")
            sle = fa.save_log_evidence(b,edep=True)
            
            if twomass_temp: 
                print 'logevidence with twomass '+ str(twomass_temp) + ' is ', sle.lge
                lge2 = sle.lge
            else: 
                print 'logevidence with twomass '+ str(twomass_temp) + ' is ', sle.lge
                lge1 = sle.lge
    # Get BF from the two runs
    print 'lge1 (2MASS false) is', lge1
    print 'lge2 (2MASS true) is', lge2
    BF = np.exp(lge2-lge1)
    print 'Bayes factor is', BF
    if BF > BF_limit:


#########################
#perform scan / load scan
if run:
    print 'The nside for this scan is ', b.nside
    #b.perform_scan(run_tag = run_tag_energy)
    if polychord:
        b.perform_scan_polychord(run_tag = run_tag_energy)
    else:
        b.perform_scan(run_tag = run_tag_energy)
if analysis:
    b.run_tag = run_tag_energy
    #make triangle plot
    tri = fa.make_triangle(b,run_tag_energy,edep=True,polychord=polychord)
    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)
    cs = fa.compute_edep_spectra(b,run_tag_energy,b.CTB_en_bins,polychord=polychord,band_mask_range = [-mask_b_plot,mask_b_plot],mask_ring = True,outer=outer_plot) #spectra over 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.save_spectra_dict(spect_dir + save_spect_label)

    ##plot spectrum
    msp_inst = msp.make_spectra_plot(spect_dir + save_spect_label + '.npy')
예제 #15
0
def do_triangle():
    mt = fa.make_triangle(b, run_tag, edep=True)
    mt.make_triangle(return_fig=False, save_fig=True)