Beispiel #1
0
def plot_swift_lc(grb_list,show=True):
    """Plots Swift GRB light curves.
    """
    plt.figure(figsize=(10, 8), dpi=80)
    plt.title('Swift XRT light curves')
    num_grb = 0
    for grb_name in grb_list:
        flux_outfile = download_swift_grb_lc_file(grb_name, min_obs_time=21600)
        if flux_outfile is not None:
            integral_flux_spline = parse_light_curve(flux_outfile)
            if integral_flux_spline is not None:
                if grb_name == 'GRB 130427A':
                    integral_flux_spline.plot(num_points=1000,logx=True,\
                                              logy=True,show=False,\
                                              color="red",linewidth=1.0)
                    num_grb += 1
                else:
                    c = random.uniform(0.4,0.8)
                    integral_flux_spline.plot(num_points=1000,logx=True,\
                                              logy=True,show=False,\
                                              color='%f'%c,linewidth=1.0)
                    num_grb += 1
        else:
            continue
    logger.info('%i GRBs included in the plot.'%num_grb)
    if show:
        plt.show()
Beispiel #2
0
def main():
    """
    """
    plt.figure(figsize=(10, 6), dpi=80)
    plt.title('Swift XRT light curves of GRBs up to 130427A')
    #get_all_swift_grb_names = ['GRB 130427A','GRB 041223']
    num_grb = 0
    for i,grb_name in enumerate(get_all_swift_grb_names()):
        flux_outfile = download_swift_grb_lc_file(grb_name)
        if type(flux_outfile) is str:
            integral_flux_spline = parse_light_curve(flux_outfile)
            if integral_flux_spline != 0:
                if grb_name == 'GRB 130427A':
                    integral_flux_spline.plot(num_points=1000,logx=True,\
                                              logy=True,show=False,\
                                              color="red",linewidth=1.0)
                    num_grb += 1
                    break
                    plt.title('Swift XRT light curves of GRBs up to now')
                else:
                    c = random.uniform(0.4,0.8)
                    integral_flux_spline.plot(num_points=1000,logx=True,\
                                              logy=True,show=False,\
                                              color='%f'%c,linewidth=1.0)
                    num_grb += 1
    print num_grb
    plt.show()
Beispiel #3
0
def plot_grb_mdp_vs_obstime(grb_name, _t_obs, t_repoint=21600, \
                            color='black', show=True):
    """Plot all the MDP (changing the repointing elapsed time defined in *arg) 
       for a given GRB.
    """
    mdp_list = []
    for obs in _t_obs:
        mdp = get_grb_mdp(grb_name,repointing=t_repoint,obs_time=obs)
        if mdp is not None:
            mdp_list.append(mdp)
        else:
            mdp_list.append(0.)
    _mdp = numpy.array(mdp_list)*100
    plt.plot(_t_obs,_mdp, marker='.',linestyle='-', lw=0.5, color=color,\
             label=grb_name)
    plt.xlabel('$\Delta t_{obs}$ [s]')
    plt.ylabel('2.-10. keV MDP (%)')
    plt.title('MDP vs $\Delta t_{obs}$, $ t_{repoint} =$ %i s'\
              %(t_repoint))
    if show:
        plt.show()
    return _mdp, _t_obs
Beispiel #4
0
def plot_grb_mdp_vs_repoint(grb_name, _t_repoint, t_obs=50000, \
                            color='black', show=True):
    """Plot all the MDP (changing the repointing elapsed time defined in *arg)
       for a given GRB.
    """
    mdp_list = []
    for repoint in _t_repoint:
        mdp = process_grb(grb_name,tstart=repoint,duration=t_obs)[-1]
        if mdp is not None:
            mdp_list.append(mdp)
        else:
            mdp_list.append(0.)
    _mdp = numpy.array(mdp_list)*100
    plt.plot(_t_repoint, _mdp, marker='.',linestyle='-', lw=0.5, color=color,\
             label=grb_name)
    plt.xlabel('$t_{repoint}$ [s]')
    plt.ylabel('2.-10. keV MDP (%)')
    plt.title('MDP vs $t_{repoint}$, $\Delta t_{obs} =$ %i s'\
              %(t_obs))
    if show:
        plt.show()
    return _mdp, _t_repoint
def plot(save=False):
    """Plot the stuff in the analysis file.
    """
    for j in range(len(E_BINNING)):
        if (j==len(E_BINNING)-1):
            analysis_file = ANALYSIS_FILE_PATH
            emin=E_BINNING[0]
            emax=E_BINNING[-1]
        else:
            analysis_file = '%s_%d' % (ANALYSIS_FILE_PATH,j)
            emin=E_BINNING[j]
            emax=E_BINNING[j+1]
            
        sim_label = 'XIPE %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 (%g-%g keV)' % (emin,emax))
        plt.title('Her X-1 (%g-%g keV)' % (emin,emax))
        pl_normalization_spline.plot(scale=20, show=False, color='lightgray',
                                     label=lc_label)
        plt.errorbar(_phase, _pol_deg, xerr=_phase_err, yerr=_pol_deg_err, fmt='o',
                     label=sim_label)
        pol_degree_spline.plot(show=False, label=mod_label)
#        pol_degree_spline_noqed.plot(show=False, label='No QED')
        plt.axis([0., 1., 0., 1.1])
        plt.legend(bbox_to_anchor=(0.4, 0.5))
        if save:
            save_current_figure('herx1_polarization_degree_%d' % j, OUTPUT_FOLDER, False)
        plt.figure('Polarization angle (%g-%g keV)' % (emin,emax))
        plt.title('Her X-1 (%g-%g keV)' % (emin,emax))
        pl_normalization_spline.plot(scale=60, offset=0, 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., 0, 3.15])
        plt.legend(bbox_to_anchor=(0.4, 0.3))
        if save:
            save_current_figure('herx1_polarization_angle_%d' %j, OUTPUT_FOLDER, False)
        plt.figure('Flux (%g-%g keV)' % (emin,emax))
        plt.title('Her X-1 (%g-%g keV)' % (emin,emax))
        plt.errorbar(_phase,
                     0.21*_norm/(2-_index)*(10.**(2.0-_index)-2.**(2.-_index)), xerr=_phase_err,
                     yerr=0.21*_norm_err/(2-_index)*(10.**(2-_index)-2.**(2.-_index)), fmt='o',
                     label=sim_label)
        pl_normalization_spline.plot(scale=1,show=False, label=mod_label)
        plt.axis([0., 1., None, None])
        plt.legend(bbox_to_anchor=(0.75, 0.95))
        if save:
            save_current_figure('herx1_flux_%d' % j, OUTPUT_FOLDER, False)
        plt.show()
Beispiel #6
0
def main():
    """Produce some plots
    """
    # If all_mdp = True, produces: 
    # 1) the plot of the MDP for all the Swift GRBs 
    #    and a given repointing time
    # 2) 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
    all_mdp = True
    if all_mdp == True:
        grb_list = get_all_swift_grb_names()
        t_rep = 21600
        t_obs = 100000
        promt_time = 600
        mdp_list1,mdp_list2, flux_list, t0_list = [], [], [], []
        c, good_grb = [], []
        for grb in grb_list:
            mdp = get_grb_mdp(grb,repointing=t_rep,obs_time=t_obs)
            flux, t0 = get_integral_flux(grb,delta_t=promt_time)
            if mdp is not None and flux is not None:
                mdp_list1.append(mdp*100)
                if t0 < 350:
                    if mdp*100 <= 15:
                        c.append('red')
                    else:
                        c.append('blue')
                    mdp_list2.append(mdp*100)
                    flux_list.append(flux)
                    t0_list.append(t0)
                else:
                    continue
        _mdp1 = numpy.array(mdp_list1)
        _mdp2 = numpy.array(mdp_list2)
        _flux = numpy.array(flux_list)
        _t0 = numpy.array(t0_list)
        # 1)------------------------------------------------------
        histo = plt.figure(figsize=(10, 6), dpi=80)
        bins = numpy.linspace(0, 100, 100)
        plt.title('%i GRBs, $\Delta t_{obs}=%i s,$ $t_{repoint}=%i s$'\
                  %(len(_mdp1),t_obs,t_rep))
        plt.hist(_mdp1, 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)
        plt.show()
        # 1.1)----------------------------------------------------
        histo = plt.figure(figsize=(10, 6), dpi=80)
        bins = numpy.linspace(0, 100, 100)
        plt.title('%i GRBs, $\Delta t_{obs}=%i s,$ $t_{repoint}=%i s$'\
                  %(len(_mdp1),t_obs,t_rep))
        (n, bins, patches) = plt.hist(_mdp1, bins, histtype='step', cumulative=True)
        plt.xlabel('2.-10. keV MDP (%)')
        plt.ylabel('Cumulative number of GRBs')
        for i in range(0,len(bins)):
            print 'MDP %.2f%%: %i GRBs'%(i,n[i])
        overlay_tag()
        save_current_figure('all_grbs_MDP_cumulative', clear=False)
        plt.show()
        # 2)------------------------------------------------------
        plt.figure(figsize=(10, 6), dpi=80)
        ax = plt.gca()
        plt.scatter(_mdp2, _flux, s=30, marker='.', color=c)
        plt.xlabel('2.-10. keV MDP (%)')
        plt.ylabel('[keV$^{-1}$ cm$^{-2}$]')
        plt.title('$\Delta t_{obs}=%i s,$ $t_{repoint}=%i s$'%(t_obs,t_rep))
        plt.xlim(1, 100)
        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
    mdp_vs_time = False
    color_list = []
    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 grb in grb_list:
            c = [random.uniform(0,1),random.uniform(0,1),random.uniform(0,1)]
            color_list.append(c)
            repointing_time = numpy.logspace(2,4.8,30)
            plot_grb_mdp_vs_repoint(grb,repointing_time,show=False,color=c)
        ax.legend(loc='upper left', shadow=False, fontsize='small')
        plt.plot([21600, 21600], [0, 30], 'k--', lw=1, color='green')
        plt.plot([43200, 43200], [0, 30], 'k--', lw=1,color='green')
        ax.set_yscale('log')
        ax.set_xscale('log')
        overlay_tag()
        save_current_figure('grb_MDP_vs_repoint',clear=False)
        plt.show()
        #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')
        plt.plot([50000, 50000], [0, 50], 'k--', lw=1, color='green')
        ax.set_yscale('log')
        ax.set_xscale('log')
        overlay_tag(x=0.5)
        save_current_figure('grb_MDP_vs_obstime',clear=False)
        plt.show()
Beispiel #7
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()