def plot(angle=False):
    spin05_pol_degree_spline, spin05_pol_angle_spline = buildspline(0.5)
    spin05_mcube =  xBinnedModulationCube(fetch_mcubepath(0.5))

    spin09_pol_degree_spline, spin09_pol_angle_spline = buildspline(0.9)
    spin09_mcube =  xBinnedModulationCube(fetch_mcubepath(0.9))

    spin998_pol_degree_spline, spin998_pol_angle_spline = buildspline(0.998)
    spin998_mcube =  xBinnedModulationCube(fetch_mcubepath(0.998))

    spin05_mcube.fit()
    spin09_mcube.fit()
    spin998_mcube.fit()
    
    spin05_fit_results = spin05_mcube.fit_results[0]
    spin09_fit_results = spin09_mcube.fit_results[0]
    spin998_fit_results = spin998_mcube.fit_results[0]

    
    plt.figure('Polarization degree')
    
    spin05_mcube.plot_polarization_degree(show=False, color='blue')
    
    spin05_pol_degree_spline.plot(color='lightblue',label='Spin 0.5', show=False)

    spin998_mcube.plot_polarization_degree(show=False, color='red')
    spin998_pol_degree_spline.plot(color='lightsalmon',label='Spin 0.998', show=False)
    
    plt.figtext(0.2, 0.85,'XIPE %s ks'%((SIM_DURATION*NUM_RUNS)/1000.),size=18)
    plt.ylim([0.00,0.045])
    plt.xlim([1,10])
    plt.legend()
    plt.show()

    if angle:
        plt.figure('Polarization angle')
    
        spin05_mcube.plot_polarization_angle(show=False, degree=True, color='blue')
        #Converting to degrees
        spin05_y = numpy.degrees(spin05_pol_angle_spline.y)
        energy = spin05_pol_angle_spline.x
        
        plt.plot(energy, spin05_y, color='lightblue',label='Spin 0.5')


        spin09_mcube.plot_polarization_angle(show=False, degree=True, color='gray')
        #Converting to degrees
        spin09_y = numpy.degrees(spin09_pol_angle_spline.y)
        energy = spin09_pol_angle_spline.x
        
        plt.plot(energy, spin09_y, color='lightgray',label='Spin 0.9')
    

        spin998_mcube.plot_polarization_angle(show=False, degree=True, color='red')
        spin998_y = numpy.degrees(spin998_pol_angle_spline.y)
        energy = spin998_pol_angle_spline.x
        
        plt.plot(energy, spin998_y, color='lightsalmon',label='Spin 0.998')
        #spin998_pol_angle_spline.plot(color='lightsalmon',label='Spin 0.998', show=False)
    
        plt.figtext(0.2, 0.85,'XIPE %s ks'%((SIM_DURATION*NUM_RUNS)/1000.),size=18)
        plt.xlim([1,10])
        plt.ylim([40,200])
        plt.legend()
        plt.show()
Example #2
0
def main():
    """Produce some plots
    """
    # If process_grb_mdp = True, produces a fits file with all the 
    # main infos on each grb
    if process_grb_mdp == True:
        data = process_grb_list(duration=50000.)
        build_grb_fits_file(data,OUTFILE)
    
    # 1) the plot of the MDP for all the Swift GRBs
    #    and a given repointing time
    # 2) the cumulative of the previous histogram
    # 3) the plot of the correlation between MDP for all the Swift
    #    GRBs and a given repointing time and the integral prompt
    #    (first 10 min) flux

    # 1)------------------------------------------------------
    plt.figure(figsize=(10, 6), dpi=80)
    bins = numpy.linspace(0, 100, 100)
    hdulist = fits.open(OUTFILE)
    grbdata = hdulist[1].data
    _mdp = grbdata['MDP 99%']
    t_obs = '50000'
    t_rep = '21600'
    plt.title('%i GRBs, $\Delta t_{obs}=%s s,$ $t_{repoint}=%s s$'\
              %(len(_mdp),t_obs,t_rep))
    plt.hist(_mdp*100, bins, alpha=0.5)
    plt.xlabel('2.-10. keV MDP (%)')
    plt.ylabel('Number of GRBs')
    overlay_tag()
    save_current_figure('all_grbs_MDP_histo', clear=False)

    # 2)----------------------------------------------------
    plt.figure(figsize=(10, 6), dpi=80)
    plt.title('%i GRBs, $\Delta t_{obs}=%s s,$ $t_{repoint}=%s s$'\
              %(len(_mdp),t_obs,t_rep))
    (n, bins, patches) = plt.hist(_mdp*100, bins, histtype='step', \
                                  cumulative=True)
    plt.xlabel('2.-10. keV MDP (%)')
    plt.ylabel('Cumulative number of GRBs')
    for i in range(0,30):
        print 'MDP %.2f%%: %i GRBs'%(i,n[i])
    overlay_tag()
    save_current_figure('all_grbs_MDP_cumulative', clear=False)

    # 3)------------------------------------------------------
    plt.figure(figsize=(10, 6), dpi=80)
    ax = plt.gca()
    _prompt_tstart = grbdata['PROMPT_START']
    _flux = grbdata['PROMPT_FLUX']
    _good_indexes = numpy.where(_prompt_tstart>350)
    _flux = numpy.delete(_flux,_good_indexes)
    _mdp = numpy.delete(_mdp,_good_indexes)
    plt.scatter(_mdp*100, _flux, s=30, marker='.', color='blue')
    plt.xlabel('2.-10. keV MDP (%)')
    plt.ylabel('[erg $\cdot$ cm$^{-2}$]')
    plt.title('%i GRBs, $\Delta t_{obs}=%s s,$ $t_{repoint}=%s s$'%(len(_flux),\
                                                                    t_obs,t_rep))
    plt.xlim(1, 100)
    plt.ylim(1e-9,1e-4)
    plt.plot([20, 20], [1e-9,1e-4], 'k--', lw=1, color='green')
    ax.set_yscale('log')
    ax.set_xscale('log')
    overlay_tag()
    save_current_figure('grb_MDP_prompt',clear=False)
    plt.show()



    # If mdp_vs_time = True Produces:
    # 1) the plot of the MDP for a given GRB
    #    as a function of the repointing time
    # 2) the plot of the MDP for a given GRB
    #    as a function of the observation duration
    color_list = ['red','salmon','goldenrod','darkgreen','limegreen',\
                  'royalblue','mediumpurple','darkviolet','deeppink']\
                  #'yellow','darkcyan'] 
    if mdp_vs_time == True:
        grb_list = ['GRB 060729', 'GRB 080411', 'GRB 091127', 'GRB 111209A',\
                    'GRB 120711A', 'GRB 130427A', 'GRB 130505A', 'GRB 130907A',\
                    'GRB 150403A']

        #1)------------------------------------------------------
        plt.figure(figsize=(10, 6), dpi=80)
        ax = plt.gca()
        for i,grb in enumerate(grb_list):
            repointing_time = numpy.logspace(2,4.8,20)
            plot_grb_mdp_vs_repoint(grb,repointing_time,show=False,\
                                    color=color_list[i])
        ax.legend(loc='upper left', shadow=False, fontsize='small')
        #plt.ylim(0,100)
        plt.plot([21600, 21600], [0, 100], 'k--', lw=1, color='green')
        plt.plot([43200, 43200], [0, 100], 'k--', lw=1,color='green')
        ax.set_yscale('log')
        ax.set_xscale('log')
        overlay_tag()
        save_current_figure('grb_MDP_vs_repoint',clear=False)

        #2)------------------------------------------------------
        plt.figure(figsize=(10, 6), dpi=80)
        ax = plt.gca()
        for i,grb in enumerate(grb_list):
            obs_time = numpy.logspace(3,5,30)
            plot_grb_mdp_vs_obstime(grb,obs_time,show=False,color=color_list[i])
        ax.legend(loc='upper right', shadow=False, fontsize='small')
        ax.set_yscale('log')
        ax.set_xscale('log')
        overlay_tag(x=0.5)
        save_current_figure('grb_MDP_vs_obstime',clear=False)
        plt.show()