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()
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()