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 makeMDP_fE_ComparisonPlot(file_path):
    scale_factor = 10.
    
    (_phase_ave, _phase_err, _energy_mean, pulsar_e_err, pulsar_e_err, mdp) =\
                                                numpy.loadtxt(file_path, unpack=True)
    print "Phase ave:",_phase_ave
    print
    print "Energy mean", _energy_mean
    #phase_values = [0.025, 0.15, 0.35, 0.675, 0.95]
    phase_values = [0.35,0.675]
    on, on_phase_color = (0.35,'r')
    off, off_phase_color = (0.675,'gray') 
    #for phase in phase_values:
        
    plt.errorbar(_energy_mean[_phase_ave==on], 100*mdp[_phase_ave==on]*(1/numpy.sqrt(scale_factor)),xerr=pulsar_e_err[_phase_ave==on], label='On Phase',fmt='o',markersize=6,ls='--',color=on_phase_color)

    plt.errorbar(_energy_mean[_phase_ave==off], 100*mdp[_phase_ave==off]*(1/numpy.sqrt(scale_factor)),xerr=pulsar_e_err[_phase_ave==off], label='Off Phase',fmt='o',markersize=6,ls='--',color=off_phase_color)
    
    plt.legend()
    plt.ylabel('MPD 99\%')
    plt.xlabel('Energy (keV)')
    plt.savefig('crab_complex_mdp_imaging_fE_%i.png'%(SIM_DURATION*scale_factor/1000.))
    plt.show()
Ejemplo n.º 3
0
def plot(save_plots=False):
    """
    """
    sim_label = 'XIPE %s ks' % (SIM_DURATION/1000.)
    mod_label = 'Input model'
    _phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    _colors = ['blue']*len(_pol_deg)
    plt.figure('Polarization degree')
    _good_fit = _pol_deg > 2*_pol_deg_err
    _bad_fit = numpy.logical_not(_good_fit)
    plt.errorbar(_phase[_good_fit], _pol_deg[_good_fit],
                 xerr=_phase_err[_good_fit], yerr=_pol_deg_err[_good_fit],
                 fmt='o', label=sim_label, color='blue')
    plt.errorbar(_phase[_bad_fit], _pol_deg[_bad_fit],
                 xerr=_phase_err[_bad_fit], yerr=_pol_deg_err[_bad_fit],
                 fmt='o', color='gray')
    pol_degree_spline.plot(show=False, label=mod_label, color='green')
    plt.axis([0., 1., 0., 0.1])
    plt.legend(bbox_to_anchor=(0.37, 0.95))
    plt.figtext(0.6, 0.8, '%.2f--%.2f keV' %\
                (E_BINNING[0], E_BINNING[-1]), size=16)
    if save_plots:
        plt.savefig('gk_per_polarization_degree.png')
    plt.figure('Polarization angle')
    plt.errorbar(_phase[_good_fit], _pol_angle[_good_fit],
                 xerr=_phase_err[_good_fit], yerr=_pol_angle_err[_good_fit],
                 fmt='o', label=sim_label, color='blue')
    plt.errorbar(_phase[_bad_fit], _pol_angle[_bad_fit],
                 xerr=_phase_err[_bad_fit], yerr=_pol_angle_err[_bad_fit],
                 fmt='o', color='gray')
    pol_angle_spline.plot(show=False, label=mod_label, color='green',
                          scale=numpy.radians(1.))
    plt.axis([0., 1., -0.1, 1.5])
    plt.xlabel('Rotational phase')
    plt.ylabel('Polarization angle [rad]')
    plt.legend(bbox_to_anchor=(0.37, 0.95))
    plt.figtext(0.6, 0.8, '%.2f--%.2f keV' %\
                (E_BINNING[0], E_BINNING[-1]), size=16)
    if save_plots:
        plt.savefig('gk_per_polarization_angle.png')
    _ebinning = zip(E_BINNING[:-1], E_BINNING[1:])
    if len(_ebinning) > 1:
        _ebinning.append((E_BINNING[0], E_BINNING[-1]))
    for i, (_emin, _emax) in enumerate(_ebinning):
        plt.figure('Phasogram %d' % i)
        phasogram = xBinnedPhasogram(_phasg_file_path(i))
        _scale = phasogram.counts.sum()/phasogram_spline.norm()/\
                 len(phasogram.counts)
        phasogram_spline.plot(show=False, label=mod_label, scale=_scale,
                              color='green')
        phasogram.plot(show=False, color='blue', label=sim_label )
        plt.legend(bbox_to_anchor=(0.37, 0.95))
        plt.figtext(0.65, 0.8, '%.2f--%.2f keV' % (_emin, _emax), size=16)
        if save_plots:
            plt.savefig('gk_per_phasogram_%d.png' % i)
    plt.show()
Ejemplo n.º 4
0
plt.ylabel("MDP 99% CL [%]")

for j, blazar in enumerate(blazar_list):
    _x_max = blazar["flux_max"]
    _x_min = blazar["flux_min"]
    _y_max = blazar["p_opt_max"]
    _y_min = blazar["p_opt_min"]
    plt.plot([_x_min, _x_max, _x_max], [_y_max, _y_max, _y_min], color=_color[:, j], lw=1.5)
    _x_text = numpy.sqrt((_x_max) * (_x_min))
    if j in mirror_list:
        _y_text = 0.88 * _y_max
    else:
        _y_text = 1.02 * _y_max
    plt.text(_x_text, _y_text, blazar["name"], color=_color[:, j], horizontalalignment="center", size="large")
plt.axis([1e-13, 1e-8, 0.5, 50])
plt.savefig("blazar_mdp_average.png")


"""
plt.figure('Average polarization degree', (14, 10))
_x = numpy.logspace(-13, -7, 100)
for obs_time in [1.e3, 10.e3, 100.e3, 1.e6]:
    _y = 100.* mdp_ref * numpy.sqrt(OBS_TIME_REF/obs_time * FLUX_REF/_x)
    plt.plot(_x, _y, color=GRID_COLOR, ls='dashed', lw=0.5)
    _i = 51
    #plt.text(_x[_i], _y[_i], '$T_{obs} =$ %d ks' % (obs_time/1000.),
    #         color=GRID_COLOR, rotation=-42., size=12)
    if obs_time is 1.e3:
        _x_text = _x[_i]
        _y_text = _y[_i]
    plt.text(_x_text, _y_text, '$T_{obs} =$ %d ks' % (obs_time/1000.),
Ejemplo n.º 5
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