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()
def main(interactive=False): """Test the script plotting the light curve og GRB 130427A """ #If you want all the GRBs use the following line: grb_list = get_all_swift_grb_names() #grb_list = ['GRB 130427A','GRB 050124'] plot_swift_lc(grb_list,show=False) overlay_tag() save_current_figure('Swift_XRT_light_curves', clear=False) if interactive: plt.show()
def process_grb_list(tstart=21600., duration=30000., prompt_duration=600): """ """ name = numpy.array([], dtype=str) e_low = numpy.array([]) e_high = numpy.array([]) ra = numpy.array([]) dec = numpy.array([]) index = numpy.array([]) start = numpy.array([]) stop = numpy.array([]) prompt_start = numpy.array([]) prompt_stop = numpy.array([]) prompt_flux = numpy.array([]) grb_start = numpy.array([]) grb_stop = numpy.array([]) eff_mu = numpy.array([]) counts = numpy.array([], dtype=numpy.int64) mdp = numpy.array([]) for grb_name in get_all_swift_grb_names(): logger.info('Processing %s...' % grb_name) grb_values = process_grb(grb_name,tstart=tstart,duration=duration,\ prompt_duration=prompt_duration) if grb_values is None: continue name = numpy.append(name,[grb_name]) e_low = numpy.append(e_low,[MIN_ENERGY]) e_high = numpy.append(e_high,[MAX_ENERGY]) ra = numpy.append(ra,[grb_values[0]]) dec = numpy.append(dec,[grb_values[1]]) index = numpy.append(index,[grb_values[2]]) start = numpy.append(start,[grb_values[3]]) stop = numpy.append(stop,[grb_values[4]]) prompt_flux = numpy.append(prompt_flux,[grb_values[5]]) prompt_start = numpy.append(prompt_start,[grb_values[6]]) prompt_stop = numpy.append(prompt_stop,[grb_values[7]]) grb_start = numpy.append(grb_start,[grb_values[8]]) grb_stop = numpy.append(grb_stop,[grb_values[9]]) eff_mu = numpy.append(eff_mu,[grb_values[10]]) counts = numpy.append(counts,[grb_values[11]]) mdp = numpy.append(mdp,[grb_values[12]]) grb_values_array = [name,e_low,e_high,ra,dec,index,start,stop,prompt_flux,\ prompt_start,prompt_stop,grb_start,grb_stop,eff_mu,\ counts,mdp] return grb_values_array
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()