Esempio n. 1
0
def plot_distribution(pseudo_redshifts):

    z_min = 1e-5
    z_max = 1e1
    z_bin = 1e0
    width = 1.0
    ymin = 00
    ymax = 40
    x, y = mf.my_histogram_according_to_given_boundaries(
        pseudo_redshifts, z_bin, z_min, z_max)
    plt.ylim(ymin, ymax)
    plt.bar(x,
            y,
            width=width,
            color='w',
            edgecolor='k',
            hatch='//',
            label=r'$ \rm{ pseudo } $')
    x, y = mf.my_histogram_according_to_given_boundaries(
        common_redshift, z_bin, z_min, z_max)
    plt.bar(x,
            y,
            width=width,
            color='c',
            alpha=0.5,
            label=r'$ \rm{ observed } $')
    plt.xlabel(r'$ z $', fontsize=size_font + 2)
    plt.legend()
def discrepancy_and_redchisqrd(A, eta):

    numerator__delta_pseudo_z = numerator__delta_pseudo_GRB__first_term + eta * numerator__delta_pseudo_GRB__second_term  #	defined for each GRB
    denominator__delta_pseudo_z = denominator__delta_pseudo_zsim__first_term + (
        (eta + 2) / (1 + z_sim))  #	defined for each simulated redshift

    denominator__F = (1 + z_sim)**eta
    F_Fermi_sim = numerator__F / denominator__F
    F_Fermi_sim = F_Fermi_sim * (cm_per_Mpc**2) / L_norm
    RHSs = (A / common_Fermi_flux) * (common_Epeak_in_MeV**eta)

    pseudo_redshifts = np.zeros(RHSs.size)
    pseudo_redshifts_error = np.zeros(RHSs.size)
    for j, RHS in enumerate(RHSs):

        array = np.abs(F_Fermi_sim - RHS)
        ind = np.where(array == array.min())[0][0]
        pseudo_redshift = z_sim[ind]
        pseudo_redshift_error = numerator__delta_pseudo_z[
            j] / denominator__delta_pseudo_z[ind]

        pseudo_redshifts[j] = pseudo_redshift
        pseudo_redshifts_error[j] = pseudo_redshift_error

    z_min = 1e-5
    z_max = 1e1
    x1, y_pseudo = mf.my_histogram_according_to_given_boundaries(
        pseudo_redshifts, z_bin, z_min, z_max)
    x2, y_common = mf.my_histogram_according_to_given_boundaries(
        common_redshift, z_bin, z_min, z_max)
    #	print ( x1 - x2 == 0 ).all()
    discrepancy = np.sum((y_pseudo - y_common)**2)

    chisquared, dof, redchisqrd = mf.reduced_chisquared(
        common_redshift, pseudo_redshifts, pseudo_redshifts_error, 2)

    return pseudo_redshifts, pseudo_redshifts_error, discrepancy, chisquared, dof, redchisqrd
	
	
	
	####################### CO-ADDED LIGHTCURVES #######################
	lc	=	np.zeros( int(t_max // time_res) )
	lt	=	np.zeros( int(t_max // time_res) )
	
	start_time	=	t.time()
	for j, end in enumerate( bunch_ends[:-1] ):
		#	To loop over the bunches.
		start	=	bunch_starts[j+1]
		if ( start - end > 0 ):
			times, []	=	mf.window( end, start, time, [] )
			if times.size > 0:
				#	To make the light-curve from the data within the bunches.
				x, y	=	mf.my_histogram_according_to_given_boundaries( times-end, time_res, 0, t_max )
				lc	=	lc + y
				
				ind	=	np.where( y > 0 )[0]
				z	=	np.zeros( int(t_max // time_res) )
				z[ind]	=	1
				lt		=	lt + z
	print '\n{:.3f} mins elapsed to make co-added LCs from raw data.'.format( (t.time() - start_time) / 60 )
	
	non_zero	=	np.where( lc != 0 )[0]
	plt.xlabel( r'$ \rm{ \tau \; [20 \, \mu s] } $', fontsize = size_font )
	plt.ylabel( r'$ \rm{ Coadded \; Data } $', fontsize = size_font )
	plt.xticks( range(10, 100, 10) )
	plt.plot( x[non_zero]/time_res, lc[non_zero]/lt[non_zero], color = 'k' )
	plt.savefig( path_save + 'Q{:d}--LC--raw_data.png'.format(i) )
	plt.savefig( path_save + 'Q{:d}--LC--raw_data.pdf'.format(i) )
Esempio n. 4
0
common_Epeak_error = common_GRBs_table['Epeak_error'].data  #	in keV.
common_alpha = common_GRBs_table['alpha'].data
common_alpha_error = common_GRBs_table['alpha_error'].data
common_beta = common_GRBs_table['beta'].data
common_beta_error = common_GRBs_table['beta_error'].data
common_Luminosity = common_GRBs_table['Luminosity'].data
common_Luminosity_error = common_GRBs_table['Luminosity_error'].data
common_num = common_ID.size

####################################################################################################################################################

####################################################################################################################################################

##	To extract the average parameters of the Fermi GRBs.

hist = mf.my_histogram_according_to_given_boundaries(np.log10(Fermi_Epeak),
                                                     0.125, 1, 4)
hxF = hist[0]
hyF = hist[1]
fits = mf.fit_a_gaussian(hxF, hyF)
f0 = fits[0]
f1 = fits[1]
f2 = fits[2]
print 'Fermi spectral parameters -- statistics :'
print 'Epeak					:	', np.median(Fermi_Epeak), mf.std_via_mad(Fermi_Epeak)
print 'alpha					:	', np.median(Fermi_alpha), mf.std_via_mad(Fermi_alpha)
print 'beta 					:	', np.median(Fermi_beta), mf.std_via_mad(Fermi_beta)
print 'Epeak, fit				:	', 10**f0, 10**f1
print '\n\n\n\n'

####################################################################################################################################################
Esempio n. 5
0
	#	To loop over the Quadrants.
	print '##########################################################\n'
	print 'Quadrant {:d}...'.format(i), '\n\n'
	
	Q_data	=	ascii.read( path_read + 'data_before_DPHclean--Q{:d}.txt'.format(i), format = 'fixed_width' )
	time	=	Q_data['Time'].data
	detx	=	Q_data['detx'].data
	dety	=	Q_data['dety'].data
	energy	=	Q_data['Energy'].data
	veto	=	Q_data['Veto'].data
	
	########################### DPHclean ###############################
	print '..........................................................\n'
	print 'DPHclean...', '\n'
	
	x_t, y_c	=	mf.my_histogram_according_to_given_boundaries( time, t_look, t_start, t_stop )
	y_c			=	y_c / t_look
	
	#	To find the n-sigma peaks in the light-curve at defined time-bin.	
	peaks_index, peaks_time, peaks_countrate, peaks_significance	=	mf.detect_peaks( x_t, y_c, T_search, cutoff )
	how_many_outliers	=	peaks_time.size
	print '\nThese many outliers:	',	how_many_outliers
	
	total_flaginds	=	np.array( [] )
	flag_indices	=	np.array( [] )
	times_to_flag	=	np.array( [] )
	check_flagged	=	np.array( [] )
	check_unflagged	=	np.array( [] )
	#	To make dph-investigation of the peaks in the light-curve.
	for j, ind_peaks in enumerate( peaks_index ):
		#	The j-th peak found in the light-curve.