Ejemplo n.º 1
0
def makeMDPComparisonPlot(imaging_file_path):
    
    non_imaging_file_path = imaging_file_path.replace('_imaging.txt','_non_imaging.txt')
    print "Using %s for non imaging file path"%non_imaging_file_path
    
    _phase_ave, _phase_err, mdp_imaging = numpy.loadtxt(imaging_file_path, unpack=True)
    _phase_ave, _phase_err, mdp_nonimaging = numpy.loadtxt(non_imaging_file_path, unpack=True)
    scale_factor = 10.
    print "Improvement with imaging"
    for i, phase in enumerate(_phase_ave):
        imaging = 100*mdp_imaging[i]*(1/numpy.sqrt(scale_factor))
        non_imaging = 100*mdp_nonimaging[i]*(1/numpy.sqrt(scale_factor))
        print "%s\t Imaging (non):%s (%s) %s"%(phase,imaging,non_imaging,non_imaging/imaging)
        
   
    sim_label_imaging = 'XIPE %s ks\n Imaging 15"' % (SIM_DURATION*scale_factor/1000.)
    sim_label_nonimaging = 'Non imaging'
    lc_label = 'Light curve'
    plt.errorbar(_phase_ave, 100*mdp_imaging*(1/numpy.sqrt(scale_factor)),xerr=_phase_err, label=sim_label_imaging,fmt='o',markersize=6)
    
    plt.errorbar(_phase_ave, 100*mdp_nonimaging*(1/numpy.sqrt(scale_factor)),xerr=_phase_err, label=sim_label_nonimaging,fmt='v',markersize=6)
    
    pl_normalization_spline.plot(scale=10., show=False,
                                color='darkgray',label=lc_label)
    #on_phase = 0.25, 0.45
    #off_phase = 0.45,0.9
    plt.axvspan(0.25, 0.45, color='r', alpha=0.45, lw=0)
    plt.axvspan(0.45, 0.9, color='gray', alpha=0.25, lw=0)
    
    plt.ylabel('MDP 99\%')
    plt.legend()
    plt.savefig('crab_complex_mdp_imaging_vs_nonimaging_%i_shaded.png'%(SIM_DURATION*scale_factor/1000.))
    plt.show()
Ejemplo n.º 2
0
def plot(save=False):
    """Plot the stuff in the analysis file.
    """
    sim_label = 'XIPE %s ks' % (SIM_DURATION/1000.)
    sim_label = 'OBS: %s ks' % (SIM_DURATION/1000.)
    mod_label = 'Input model'
    lc_label = 'Light curve'
    _phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err, _index, _index_err, _norm,\
        _norm_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    plt.figure('Polarization degree')
    pl_normalization_spline.plot(scale=0.12, show=False, color='lightgray',
                                 label=lc_label)

    _pol_deg_err_p=numpy.where((_pol_deg+_pol_deg_err)<1.0,_pol_deg_err,1.0-_pol_deg)
    _pol_deg_err_m=numpy.where((_pol_deg-_pol_deg_err)>0.0,_pol_deg_err,_pol_deg)
    #if (_pol_deg+_pol_deg_err)>1.0: _pol_deg_err=1.0-yerr_p
    
    plt.errorbar(_phase, _pol_deg, xerr=_phase_err, yerr=[_pol_deg_err_m,_pol_deg_err_p], fmt='o',
                 label=sim_label)
    pol_degree_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 0., 0.5])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_polarization_degree', OUTPUT_FOLDER, False)
    plt.figure('Polarization angle')
    pl_normalization_spline.plot(scale=0.4, offset=1.25, show=False,
                                 color='lightgray', label=lc_label)
    plt.errorbar(_phase, _pol_angle, xerr=_phase_err, yerr=_pol_angle_err,
                 fmt='o', label=sim_label)
    pol_angle_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 1.25, 3.])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_polarization_angle', OUTPUT_FOLDER, False)
    plt.figure('PL normalization')
    plt.errorbar(_phase, _norm, xerr=_phase_err, yerr=_norm_err, fmt='o',
                 label=sim_label)
    pl_normalization_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., None, None])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_pl_norm', OUTPUT_FOLDER, False)
    plt.figure('PL index')
    pl_normalization_spline.plot(scale=0.18, offset=1.3, show=False,
                                 color='lightgray', label=lc_label)
    plt.errorbar(_phase, _index, xerr=_phase_err, yerr=_index_err, fmt='o',
                 label=sim_label)
    pl_index_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 1.3, 2.1])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_pl_index', OUTPUT_FOLDER, False)
    plt.show()
Ejemplo n.º 3
0
def calcMDP(plot=False):
    mdp_file = open(MDP_OUTPUT_FILE,'w')
    mdp_file.write('#Simulation time %s sec \n'%SIM_DURATION)
    mdp_file.write('#Phase Ave delta phase Mean energy  delta energy mdp99\n')
    nebula_mcube_file = xBinnedModulationCube(NEBULA_MCUBE_FILE_PATH)
    nebula_counts = nebula_mcube_file.counts
    nebula_mdp =  nebula_mcube_file.mdp99
    txt = "Pulsar phase\t Emin - Emax\t Pulsar counts\t Nebula counts\t MDP\n"
    MDP99_PULSAR = []
    phase = []
    phase_err = [] 
    for i, (_min, _max) in enumerate(PHASE_BINS):
            #zip(PHASE_BINS[:-1],PHASE_BINS[1:])):

        pulse_diff = numpy.fabs(_max -_min)
        _phase_ave = 0.5*(_min + _max)
        phase.append(_phase_ave)
        _phase_err = 0.5*(_max - _min)
        phase_err.append(_phase_err)
        
        pulsar_phase_mcube_file = xBinnedModulationCube(_mcube_file_path(i))
        
        
        pulsar_emean = pulsar_phase_mcube_file.emean
        for j, _energy_mean in enumerate(pulsar_emean):
            pulsar_emin = pulsar_phase_mcube_file.emin[j]
            pulsar_emax = pulsar_phase_mcube_file.emax[j]
            pulsar_e_err = 0.5*(pulsar_emax-pulsar_emin)
            
            pulsar_phase_counts = pulsar_phase_mcube_file.counts[j]
            pulsar_mdp = pulsar_phase_mcube_file.mdp99[j]
            #scale the nebula counts for the time used for the pulsar phase
            scaled_nebula_counts = pulse_diff*nebula_counts[j]
        
            count_sqrt = numpy.sqrt(pulsar_phase_counts + scaled_nebula_counts)
       
            eff_mu_pulsar =  pulsar_phase_mcube_file.effective_mu[j]
            
            mdp = 4.292/eff_mu_pulsar*count_sqrt/pulsar_phase_counts
            MDP99_PULSAR.append(100*mdp)
            _data = (_phase_ave, _phase_err, _energy_mean, pulsar_e_err, pulsar_e_err, mdp)
            
            _fmt = ('%.4e   ' * len(_data)).strip()
            _fmt = '%s\n' % _fmt
            _line = _fmt % _data
            mdp_file.write(_line)
           
            #txt += "%s\t %s - %s\t %s\t %s\t %.3f\n"%(PHASE_BINS[i], pulsar_emin[0], pulsar_emax[0], pulsar_phase_counts[0], scaled_nebula_counts[0], 100*mdp)
        
    MDP99_PULSAR = numpy.array(MDP99_PULSAR)
    PHASE = numpy.array(phase)
    mdp_file.close()
    if plot:
        scale_factor = 10
        sim_label = 'XIPE %s ks' % (SIM_DURATION*scale_factor/1000.)
        lc_label = 'Light curve'
        plt.errorbar(PHASE, MDP99_PULSAR*(1/numpy.sqrt(10)),xerr=phase_err, label=sim_label,fmt='o')
        pl_normalization_spline.plot(scale=10., show=False,
                                color='lightgray',label=lc_label)
        plt.ylabel('MDP 99\%')
        plt.legend()
        plt.savefig('crab_complex_mdp_nonimaging_%i.png'%(SIM_DURATION*scale_factor/1000.))
      
        #plt.show()
    print txt