def plotmdp(): spin00_pol_degree_spline = buildspline(0.5) spin00_mcube = xBinnedModulationCube(fetch_mcubepath(0.5)) spin998_pol_degree_spline = buildspline(0.998) spin998_mcube = xBinnedModulationCube(fetch_mcubepath(0.998)) spin00_mcube.fit() spin998_mcube.fit() spin00_fit_results = spin00_mcube.fit_results[0] spin998_fit_results = spin998_mcube.fit_results[0] plt.figure('MDP') spin00_mdp = spin00_mcube.mdp99[:-1] spin998_mdp = spin998_mcube.mdp99[:-1] emean = spin00_mcube.emean[:-1] emin = spin00_mcube.emin[:-1] emax = spin00_mcube.emax[:-1] width = (emax-emin)/2. plt.errorbar(emean,spin00_mdp,xerr=width, label='Spin 0.5',marker='o',linestyle='--') plt.errorbar(emean,spin998_mdp,xerr=width, label='Spin 0.998',marker='o',linestyle='--') plt.figtext(0.2, 0.85,'XIPE %s ks'%((SIM_DURATION*NUM_RUNS)/1000.),size=18) plt.xlim([1,10]) plt.ylabel('MPD 99\%') plt.xlabel('Energy (keV)') plt.legend() plt.show()
def view(): _mcube = xBinnedModulationCube(MCUBE_FILE_PATH) _mcube.fit() _fit_results = _mcube.fit_results[0] plt.figure('Polarization degree') _mcube.plot_polarization_degree(show=False, color='blue') pol_degree_spline.plot(color='lightgray',label='Spin %s'%spindegree, show=False) plt.figtext(0.2, 0.85,'XIPE %s ks'%(SIM_DURATION/1000.),size=18) #plt.errorbar(_energy_mean, _pol_deg, yerr=_pol_deg_err, color='blue',marker='o') plt.legend() plt.figure('Polarization angle') _mcube.plot_polarization_angle(show=False, color='blue', degree=False) pol_angle_spline.plot(color='lightgray',label='Spin %s'%spindegree, show=False) plt.figtext(0.2, 0.85,'XIPE %s ks'%(SIM_DURATION/1000.),size=18) #plt.errorbar(_energy_mean,_pol_angle, yerr= _pol_angle_err,color='blue',marker='o') plt.xlim([1,10]) plt.legend() plt.figure('MDP %s'%base_name) mdp = _mcube.mdp99[:-1] emean = _mcube.emean[:-1] emin = _mcube.emin[:-1] emax = _mcube.emax[:-1] width = (emax-emin)/2. plt.errorbar(emean,mdp,xerr=width, label='MDP99',marker='o',linestyle='--') plt.figtext(0.2, 0.85,'XIPE %s ks'%(SIM_DURATION/1000.),size=18) plt.xlim([1,10]) plt.ylabel('MPD 99\%') plt.xlabel('Energy (keV)') #plt.legend() plt.show()
def view(): #_energy_mean,_emin, _emax, _pol_deg, _pol_deg_err, _pol_angle, \ # _pol_angle_err = \ # # numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True) _mcube = xBinnedModulationCube(MCUBE_FILE_PATH) _mcube.fit() _fit_results = _mcube.fit_results[0] plt.figure('Polarization degree') _mcube.plot_polarization_degree(show=False, color='blue') pol_degree_spline.plot(color='lightgray',label='Model %s corona'%model_type, show=False) plt.figtext(0.2, 0.85,'XIPE %s ks'%(SIM_DURATION/1000.),size=18) #plt.errorbar(_energy_mean, _pol_deg, yerr=_pol_deg_err, color='blue',marker='o') plt.legend() plt.figure('Polarization angle') _mcube.plot_polarization_angle(show=False, color='blue', degree=False) pol_angle_spline.plot(color='lightgray',label='Model %s corona'%model_type, show=False) plt.figtext(0.2, 0.85,'XIPE %s ks'%(SIM_DURATION/1000.),size=18) #plt.errorbar(_energy_mean,_pol_angle, yerr= _pol_angle_err,color='blue',marker='o') plt.legend() plt.figure('MDP %s'%base_name) mdp = _mcube.mdp99 emean = _mcube.emean emin = _mcube.emin emax = _mcube.emax width = (emax-emin)/2. plt.errorbar(emean,mdp,xerr=width, label='MDP99',marker='o',linestyle='--') plt.figtext(0.2, 0.85,'XIPE %s ks'%(SIM_DURATION/1000.),size=18) plt.xlim([1,10]) plt.ylabel('MPD 99 %') plt.xlabel('Energy (keV)') #plt.legend() plt.show()
def plot(): spherical_mcube = xBinnedModulationCube(SPHERICAL_MCUBE_PATH) wedge_mcube = xBinnedModulationCube(WEDGE_MCUBE_PATH) spherical_mcube.fit() wedge_mcube.fit() spherical_fit_results = spherical_mcube.fit_results[0] wedge_fit_results = wedge_mcube.fit_results[0] plt.figure('Polarization degree') spherical_mcube.plot_polarization_degree(show=False, color='blue') pol_degree_spline_spherical.plot(color='lightblue',label='Spherical corona model (40 degree inclination)', show=False) wedge_mcube.plot_polarization_degree(show=False, color='red') pol_degree_spline_wedge.plot(color='lightsalmon',label='Wedge corona model (40 degree inclination)', show=False) plt.figtext(0.2, 0.85,'XIPE %s ks'%((SIM_DURATION*NUM_RUNS)/1000.),size=18) plt.xlim([1,10]) plt.legend() plt.show()
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 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()
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()