Ejemplo n.º 1
0
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

    discrepancy = np.sum((common_redshift - pseudo_redshifts)**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
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
def plot_redshift_vs_redshift(pseudo_redshifts, pseudo_redshifts_error,
                              coefficient, coefficient_error, exponent,
                              exponent_error):

    reconciled = coefficient * (pseudo_redshifts**exponent)
    reconciled_error = exponent * (
        pseudo_redshifts_error /
        pseudo_redshifts) + coefficient_error / coefficient + np.log(
            pseudo_redshifts) * exponent_error
    reconciled_error = reconciled_error * reconciled
    ratio = reconciled / common_redshift
    ratio_error = (reconciled_error / reconciled) * ratio

    print 'Ratio min and max	:	', round(ratio.min(), 3), round(ratio.max(), 3)
    print 'Reduced chi-squared	:	', mf.reduced_chisquared(
        common_redshift, reconciled, reconciled_error, 4)[2]

    z_min = 1e-1
    z_max = 2e1

    ax = plt.subplot(111)
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.set_xlim(z_min, z_max)
    ax.set_ylim(z_min, z_max)
    ax.set_ylabel(r'$ \rm{ reconciled / measured } $', fontsize=size_font)
    ax.set_xlabel(r'$ \rm{ pseudo \; \, redshift } $', fontsize=size_font)
    ax.errorbar(pseudo_redshifts,
                ratio,
                yerr=ratio_error,
                fmt='.',
                ms=marker_size,
                color='silver',
                markerfacecolor='k',
                markeredgecolor='k')
    ax.axhline(y=1, linestyle='dashed', color='k')
Ejemplo n.º 4
0
	model_bin__Fermi	=	model_bin__Fermi * Fermi_norm
	Fermi_long_total_model	=	Fermi_long_total_model + model_bin__Fermi
	
	ax[j] = fig.add_subplot(z_binned__Fermi.size-1,1,j+1)
	ax[j].text( -3.5, 350, r'$ z : $ ' + r'$ {0:.1f} $'.format(z) + r' $ \rm{to} $ ' + r'$ {0:.1f} $'.format(z_binned__Fermi[j+1]), fontsize = size_font, ha = 'center', va = 'center' )
	ax[j].set_ylabel( r'$ \rm{ N } $', fontsize = size_font, rotation = 0, labelpad = padding+6 )
	ax[j].set_ylim( 0, 400 )
	ax[j].errorbar( Luminosity_mids, obsFermi_long[j], yerr = [ obsFermi_long_poserr[j], obsFermi_long_negerr[j] ], fmt = '-', color = 'k', label = r' $ \rm{ observed } $' )
	ax[j].plot( Luminosity_mids, model_bin__Fermi, linestyle = '--', color = 'k', label = r' $ \rm{ model } $' )
	ax[j].legend()
	ltext = plt.gca().get_legend().get_texts()
	plt.setp( ltext[0], fontsize = 11 )
	
	modeled__Fermi_long[j]			=	model_bin__Fermi
	discrepancy_over_z__Fermi[j]	=	find_discrepancy( model_bin__Fermi, obsFermi_long[j] )
	rdcdchisqrd_over_z__Fermi[j]	=	mf.reduced_chisquared( model_bin__Fermi, obsFermi_long[j], obsFermi_long_error[j], 4 )[2]
	
	#	print mf.reduced_chisquared( model_bin__Fermi, obsFermi_long[j], obsFermi_long_error[j], 4 )
print 'Done in {:.3f} mins.'.format( ( time.time()-t0 )/60 )
xticklabels	=	ax[0].get_xticklabels() + ax[1].get_xticklabels()
plt.setp( xticklabels, visible = False )
plt.xlabel( r'$ \rm{ log } $' + r'$ ( L_{iso} / L_{0} ) $', fontsize = size_font, labelpad = padding+5 )
plt.savefig( './../plots/estimated_lumfunc_models/binned_with_z/Fermi--binned.png' )
plt.clf()
plt.close()

Fermi_long_total_data_e	=	np.maximum(Fermi_long_total_data_ep, Fermi_long_total_data_en)+1
print 'reduced chisquared	:	', mf.reduced_chisquared( Fermi_long_total_model, Fermi_long_total_data, Fermi_long_total_data_e, 4 ), '\n\n'
ax	=	plt.subplot(111)
ax.set_xlabel( r'$ \rm{ log } $' + r'$ ( L_{p} / L_{0} ) $', fontsize = size_font, labelpad = padding-4 )
ax.set_ylabel( r'$ \rm{ N } $', fontsize = size_font, rotation = 0, labelpad = padding+6 )
Ejemplo n.º 5
0
                        #	ax[j] = fig.add_subplot(z_binned__Fermi.size-1,1,j+1)
                        #	ax[j].text( -3.5, 350, r'$ z : $ ' + r'$ {0:.1f} $'.format(z) + r' $ \rm{to} $ ' + r'$ {0:.1f} $'.format(z_binned__Fermi[j+1]), fontsize = size_font, ha = 'center', va = 'center' )
                        #	ax[j].set_ylabel( r'$ \rm{ N } $', fontsize = size_font, rotation = 0, labelpad = padding+6 )
                        #	ax[j].set_ylim( 0, 400 )
                        #	ax[j].errorbar( Luminosity_mids, obsFermi_long[j], yerr = [ obsFermi_long_poserr[j], obsFermi_long_negerr[j] ], fmt = '-', color = 'k', label = r' $ \rm{ observed } $' )
                        #	ax[j].plot( Luminosity_mids, model_bin__Fermi, linestyle = '--', color = 'k', label = r' $ \rm{ model } $' )
                        #	ax[j].legend()
                        #	ltext = plt.gca().get_legend().get_texts()
                        #	plt.setp( ltext[0], fontsize = 11 )

                        modeled__Fermi_long[j] = model_bin__Fermi
                        discrepancy_over_z__Fermi[j] = find_discrepancy(
                            model_bin__Fermi, obsFermi_long[j])
                        rdcdchisqrd_over_z__Fermi[j] = mf.reduced_chisquared(
                            model_bin__Fermi, obsFermi_long[j],
                            obsFermi_long_error[j], 5)[2]

                        #	print mf.reduced_chisquared( model_bin__Fermi, obsFermi_long[j], obsFermi_long_error[j], 5 )[1]

                    #	xticklabels	=	ax[0].get_xticklabels() + ax[1].get_xticklabels()
                    #	plt.setp( xticklabels, visible = False )
                    #	plt.xlabel( r'$ \rm{ log } $' + r'$ ( L_{iso} / L_{0} ) $', fontsize = size_font, labelpad = padding+5 )
                    #	plt.show()

                    grid_of_discrepancy__Fermi[c1, c2, cLb, cdel, cX] = np.sum(
                        discrepancy_over_z__Fermi)
                    grid_of_rdcdchisqrd__Fermi[c1, c2, cLb, cdel,
                                               cX] = np.mean(
                                                   rdcdchisqrd_over_z__Fermi)
print 'Fermi done in {:.3f} hrs.'.format((time.time() - t0) / 3600), '\n'
	ax[j].set_ylabel( r'$ \rm{ N } $', fontsize = size_font, rotation = 0, labelpad = padding+6 )
	ax[j].set_ylim( 0, 400 )
	ax[j].errorbar( Luminosity_mids, obsFermi_long_bin, yerr = [ obsFermi_long_poserr_bin, obsFermi_long_negerr_bin ], fmt = '-', color = 'k', label = r' $ \rm{ observed } $' )
	ax[j].plot( Luminosity_mids, model_bin__Fermi, linestyle = '--', color = 'k', label = r' $ \rm{ model } $' )
	ax[j].legend()
	ltext = plt.gca().get_legend().get_texts()
	plt.setp( ltext[0], fontsize = 11 )
xticklabels	=	ax[0].get_xticklabels() + ax[1].get_xticklabels()
plt.setp( xticklabels, visible = False )
plt.xlabel( r'$ \rm{ log } $' + r'$ ( L_{p} / L_{0} ) $', fontsize = size_font, labelpad = padding+5 )
plt.savefig( './../plots/estimated_lumfunc_models/binned_with_z/Fermi--binned.png' )
plt.clf()
plt.close()

Fermi_long_total_data_e	=	np.maximum(Fermi_long_total_data_ep, Fermi_long_total_data_en)+1
print 'reduced chisquared	:	', mf.reduced_chisquared( Fermi_long_total_model, Fermi_long_total_data, Fermi_long_total_data_e, 5 ), '\n'
ax	=	plt.subplot(111)
ax.set_xlabel( r'$ \rm{ log } $' + r'$ ( L_{p} / L_{0} ) $', fontsize = size_font, labelpad = padding-4 )
ax.set_ylabel( r'$ \rm{ N } $', fontsize = size_font, rotation = 0, labelpad = padding+6 )
ax.set_ylim( 0, 700 )
ax.errorbar( Luminosity_mids, Fermi_long_total_data, yerr = [ Fermi_long_total_data_ep, Fermi_long_total_data_en ], fmt = '-', color = 'k', label = r' $ \rm{ observed } $' )
ax.plot( Luminosity_mids, Fermi_long_total_model, linestyle = '--', color = 'k', label = r' $ \rm{ model } $' )
ax.legend()
plt.savefig( './../plots/estimated_lumfunc_models/binned_with_z/Fermi--total.png' )
plt.clf()
plt.close()



print 'Swift...'
Swift_long_L	=	known_long_Luminosity.copy()	;	Swift_long_L_error	=	Swift_long_Luminosity_error.copy()
    return pseudo_redshifts, pseudo_redshifts_error, discrepancy, chisquared, dof, redchisqrd


print '\n\n\n\n'
against = []
for i in range(5):
    if i == 0:
        returned = discrepancy_and_redchisqrd(A___Yonetoku, eta_Yonetoku)
        pseudo_redshifts = returned[0]
        pseudo_redshifts_error = returned[1]
        against.append(pseudo_redshifts)
        pseudo_redshifts___Yonetoku = pseudo_redshifts
        pseudo_redshifts___Yonetoku_error = pseudo_redshifts_error
        print i, returned[2], mf.reduced_chisquared(common_redshift,
                                                    pseudo_redshifts,
                                                    pseudo_redshifts_error, 2)

    if i == 1:
        returned = discrepancy_and_redchisqrd(A___Tanbestfit, eta_Tanbestfit)
        pseudo_redshifts = returned[0]
        pseudo_redshifts_error = returned[1]
        against.append(pseudo_redshifts)
        pseudo_redshifts___Tanbestfit = pseudo_redshifts
        pseudo_redshifts___Tanbestfit_error = pseudo_redshifts_error
        print i, returned[2], mf.reduced_chisquared(common_redshift,
                                                    pseudo_redshifts,
                                                    pseudo_redshifts_error, 2)

    if i == 2:
        returned = discrepancy_and_redchisqrd(A___Tanredshift, eta_Tanredshift)