def deltaH(SNered, SNedist): return (fun.D(fun.HubbleIntegrate(float(SNered))) - (float(SNedist))) / fun.D(fun.HubbleIntegrate(float(SNered)))
from scipy.stats import norm, ks_2samp from scipy.integrate import quad ##import functions import sys sys.path.insert(0, 'C:\Python34\masters\graphs') import functions as fun def HubbleCalculate(z, dist): ##Calculates the distance modulus to an object at z redshift. Assesses the integral ##between 0 and z ##To find the value in MPc, use fun.D(fun.HubbleIntegrate(0.2)) def integrand(z, m, de): return 1/np.sqrt((m*(1+z)**3)+de) m=0.22 de=0.7205 H0 = 69.79 a = 3*10**5/dist I = quad(integrand, 0, z, args=(m,de)) H = I[0]*a*(1+z) return H d = fun.D(fun.HubbleIntegrate(0.06)) #d = 260.90498780322844 x=HubbleCalculate(0.06, d) print(x)
SNein = [] SNeout = [] i = 0 while i < len(distancesMpc): if distancesMpc[i] < besti: cin.append(dH[i]) SNein.append([SNedist[i], SNedisterror[i], SNered[i]]) else: cout.append(dH[i]) SNeout.append([SNedist[i], SNedisterror[i], SNered[i]]) i += 1 print(ks_2samp(cin, cout)) ####H values Hin = [fun.HubbleLCDM(x[2], fun.D(x[0])) for x in SNein] Hinmean = sum(Hin) / len(Hin) Hinerror = fun.stdev(Hin, Hinmean) / np.sqrt(len(Hin)) print('Hubble Constant within distance to cluster: ', Hinmean, ' pm ', Hinerror) Hout = [fun.HubbleLCDM(x[2], fun.D(x[0])) for x in SNeout] Houtmean = sum(Hout) / len(Hout) Houterror = fun.stdev(Hout, Houtmean) / np.sqrt(len(Hout)) print('Hubble Constant within distance to cluster: ', Houtmean, ' pm ', Houterror) ####CUMFREQ cin.sort() cout.sort() plt.plot(cin,
voidRA = fun.minvoidRA + fun.isovoidRA voiddec = fun.minvoiddec + fun.isovoiddec voidz = fun.minvoidz + fun.isovoidz voidRadii = fun.minvoidradius + fun.isovoidradius scin = [] scout = [] i = 0 k = 0 j = 0 while k < len(SNered): ##Find the nearest sc for each k Supernova while i < len(clusterz): distancesNew = fun.polar_dist_comp( SNeRA[k], clusterRA[i], SNedec[k], clusterdec[i], SNered[k], clusterz[i]) ##Keep SN constant, loop over supercluster if fun.D(fun.HubbleIntegrate(distancesNew)) < clusterRadii[i]: scin.append([ SNedist[k], SNedisterror[k], SNered[k], clusterRadii[i], fun.D(fun.HubbleIntegrate(distancesNew)) - clusterRadii[i] ]) i = len(clusterz) + 1 j = len(voidRA) + 1 i += 1 while j < len(voidRA): distancesNew = fun.polar_dist_comp(SNeRA[k], voidRA[j], SNedec[k], voiddec[j], SNered[k], voidz[j]) if fun.D(fun.HubbleIntegrate(distancesNew)) < voidRadii[j]: scout.append([ SNedist[k], SNedisterror[k], SNered[k], voidRadii[j], fun.D(fun.HubbleIntegrate(distancesNew)) - voidRadii[j] ])
scName = fun.scName scRadius = [float(x) for x in fun.R] confirmedSC = [] ##[0] is SNe number, [1] is corresponding SC unconfirmedSC = [] i = 0 z = 0 k = 0 while k < len(SNered): ##Find the nearest sc for each k Supernova if SNered[k] < max(scz) + 0.02 and SNedec[k] < max(scdec) + 5: while i < len(scz): distancesNew = fun.polar_dist_comp( SNeRA[k], scRA[i], SNedec[k], scdec[i], SNered[k], scz[i]) ##Keep SN constant, loop over supercluster if fun.D(fun.HubbleIntegrate(distancesNew)) < scRadius[i]: print(SNeRA[k], scRA[i], SNedec[k], scdec[i], SNered[k], scz[i], i, k) confirmedSC.append(k) i = len(scz) if i == len(scz) - 1: unconfirmedSC.append(k) i += 1 i = 0 k += 1 else: if SNered[k] < max(scz) + 0.02 and SNedec[k] > max(scdec) + 5: z += 1 del SNered[k] del SNeRA[k] del SNedec[k]
plt.axis([ min(np.append(largered, smallred)) * 0.9, max(np.append(largered, smallred)) * 1.1, min(np.append(large_H, small_H)) * 0.9, max(np.append(large_H, small_H)) * 1.1 ]) plt.legend() plt.show() ##Histogram of dH large_dH = [] small_dH = [] i = 0 while i < len(largered): large_dH.append((fun.D(fun.HubbleIntegrate(largered[i])) - largedist[i]) / fun.D(fun.HubbleIntegrate(largered[i]))) i += 1 i = 0 while i < len(smallred): small_dH.append((fun.D(fun.HubbleIntegrate(smallred[i])) - smalldist[i]) / fun.D(fun.HubbleIntegrate(smallred[i]))) i += 1 print(ks_2samp(large_dH, small_dH)) largehist = plt.hist(large_dH, bins=binno, alpha=0.5, label='large', color='blue')
ascRadius = fun.abelscradii ##Combine Clusters clusterRA = scRA + ascRA clusterdec = scdec + ascdec clusterz = scz + ascz clusterRadii = scRadius + ascRadius scin = [] scout = [] i=0 k=0 while k < len(SNered): ##Find the nearest sc for each k Supernova while i < len(clusterz): distancesNew = fun.polar_dist_comp(SNeRA[k], clusterRA[i], SNedec[k], clusterdec[i], SNered[k], clusterz[i]) ##Keep SN constant, loop over supercluster if fun.D(fun.HubbleIntegrate(distancesNew)) < clusterRadii[i]: scin.append([SNedist[k], SNedisterror[k], SNered[k], clusterRadii[i], fun.D(fun.HubbleIntegrate(distancesNew)) - clusterRadii[i]]) i = len(clusterz)+1 if i == len(clusterz) - 1: scout.append([SNedist[k], SNedisterror[k], SNered[k]]) i+=1 i=0 k+=1 ##Calculate dH for each supernovae dHin = [] i=0 while i < len(scin): dHin.append(deltaH(scin[i][2], scin[i][0])) i+=1
while i < 200: h = 60 + i/10 ##H_0 known to be between 68 and 72 from previous tests k = 0 res = residual(scindist, scindisterror, scinz, h, 0.2795, 0.7205) if res < minresidual: minresidual = res bestH = h i+=1 i+=1 ###((3*10^5)/a)*(x + (0.5*(1 + 0.7205 - (0.2795/2)))*x^2 + (1/6)*(1+0.7205 - (0.2795/2) - (3*((0.2795/2)-0.7205)^2+1))*x^3) ###gives H0 = 72.76 redshiftrange = np.linspace(min(scinz), max(scinz), 100) H = [fun.D(fun.HubbleIntegrateVarH(x, bestH)) for x in redshiftrange] Hglobal = [fun.D(fun.HubbleIntegrateVarH(x, 69.79)) for x in redshiftrange] ##Graph for redshift vs distance plt.figure() plt.errorbar(scinz, scindist, yerr=scindisterror, fmt='.', markersize=5, color="blue", label='SNe in superclusters') plt.plot(redshiftrange, H, '-', color="blue", label='H0 = 71.6') plt.plot(redshiftrange, Hglobal, '-', color="grey", label='H0 = 69.79') plt.legend(loc="upper left") plt.xlabel('Redshift') plt.ylabel('Distance (Mpc)') plt.title('Hubble Diagrams for SGC and its corresponding dipole') plt.axis([0, max(scinz)*1.1, 0, max(scindist)*1.1]) plt.legend() plt.show()
while i < len(clusterz): distancesNew = fun.polar_dist_comp( SNeRA[k], clusterRA[i], SNedec[k], clusterdec[i], SNered[k], clusterz[i]) ##Keep SN constant, loop over supercluster if distancesNew < distancescluster[k]: distancescluster[k] = fun.polar_dist_comp(SNeRA[k], clusterRA[i], SNedec[k], clusterdec[i], SNered[k], clusterz[i]) i += 1 i = 0 k += 1 distancesMpc = [] i = 0 while i < len(distancescluster): distancesMpc.append(fun.D(fun.HubbleIntegrate(distancescluster[i]))) i += 1 ##Supernovae numbers 566, 567, 569, 571, 576 confirmed to reside in cluster distancesMpc[566] = 1 distancesMpc[567] = 1.1 distancesMpc[569] = 1.2 distancesMpc[571] = 1.3 distancesMpc[576] = 1.4 ##Calculate dH for each supernovae dH = [] i = 0 while i < len(SNeRA): dH.append(deltaH(SNered[i], SNedist[i])) i += 1
voiddec = fun.minvoiddec + fun.isovoiddec voidz = fun.minvoidz + fun.isovoidz voidRadii = fun.minvoidradius + fun.isovoidradius distancescluster = len(SNered) * [1000000] distancevoid = len(SNered) * [1000000] SNSC = len(SNered) * [0] SNVoid = len(SNered) * [0] i = 0 j = 0 k = 0 while k < len(SNered): ##Find the nearest sc for each k Supernova while i < len(clusterz): distancesNew = fun.D( fun.HubbleIntegrate( fun.polar_dist_comp( SNeRA[k], clusterRA[i], SNedec[k], clusterdec[i], SNered[k], clusterz[i]))) ##Keep SN constant, loop over supercluster if distancesNew < clusterRadii[i]: SNSC[k] = 1 if distancesNew < distancescluster[k]: distancescluster[k] = distancesNew i += 1 while j < len(voidRA): distancesNew = fun.D( fun.HubbleIntegrate( fun.polar_dist_comp( SNeRA[k], voidRA[j], SNedec[k], voiddec[j], SNered[k], voidz[j]))) ##Keep SN constant, loop over supercluster if distancesNew < voidRA[j]: SNVoid[k] = 1
plt.plot(redshiftrange, 10 * [66.9 - 1.6], ':', color="red", alpha=0.3) plt.legend(loc="upper left") plt.xlabel('Redshift') plt.ylabel('Hubble constant (km s$^{-1}$ Mpc$^{-1}$)') plt.title('Hubble values for SGC and its corresponding dipole') plt.legend() plt.show() ##Histogram of dH NGC_dH = [] SGC_dH = [] i = 0 while i < len(NGCred): NGC_dH.append((fun.D(fun.HubbleIntegrate(NGCred[i])) - NGCdist[i]) / fun.D(fun.HubbleIntegrate(NGCred[i]))) i += 1 i = 0 while i < len(SGCred): SGC_dH.append((fun.D(fun.HubbleIntegrate(SGCred[i])) - SGCdist[i]) / fun.D(fun.HubbleIntegrate(SGCred[i]))) i += 1 print(ks_2samp(NGC_dH, SGC_dH)) plt.plot(SGCred, SGC_dH, '.') plt.plot([min(SGCred), max(SGCred)], [0, 0]) plt.show() NGChist = plt.hist(NGC_dH, bins=binno, alpha=0.5, label='NGC', color='blue')
Alldec = [x[4] for x in All] minres = 100000 NGCH = 0 i = 0 while i < 1000: h = 65 + i / 100 res = fun.residual(fun.dmod(NGCdist), fun.dmod(NGCdisterror), NGCred, h, 0.2807, 0.7193) if res < minres: minres = res NGCH = h i += 1 redshiftrange = np.linspace(minredshift, maxredshift, 10) expectedH = [fun.D(fun.HubbleIntegrate(x)) for x in redshiftrange] ##Graph for redshift vs distance plt.figure() plt.errorbar(NGCred, NGCdist, yerr=NGCdisterror, fmt='.', markersize=5, color="blue", label='Maximal Acceleration') plt.errorbar(SGCred, SGCdist, yerr=SGCdisterror, fmt='.', markersize=5,
SNeRA = fun.RA SNedec = fun.dec SNedist = fun.dist SNedisterror = fun.disterror SNedistMpc = fun.distMpc SNered = fun.redshifts degtorad = 0.0174533 SNeSC = eval( open("C:\\Python34\\masters\\graphs\\newsupercluster\\SNSC.txt", "r").read()) SNevoid = eval( open("C:\\Python34\\masters\\graphs\\newsupercluster\\SNvoid.txt", "r").read()) SCdist = [fun.D(x[0]) for x in SNeSC] SCdisterror = [fun.errorD(x[0], x[1]) for x in SNeSC] SCred = [x[2] for x in SNeSC] Voiddist = [fun.D(x[0]) for x in SNevoid] Voiddisterror = [fun.errorD(x[0], x[1]) for x in SNevoid] Voidred = [x[2] for x in SNevoid] ##Calculate dH for each supernovae dHin = [] i = 0 while i < len(SCdist): dHin.append(deltaH(SCred[i], SCdist[i])) i += 1 ##Calculate dH for each supernovae
sumsq = 0 i = 0 while i < N: sumsq = sumsq + (x[i] - mu)**2 i += 1 return np.sqrt((1 / (N - 1)) * sumsq) ##Test against H0 lowZdeviation = [] midZdeviation = [] highZdeviation = [] i = 0 while i < len(lowZ): lowZdeviation.append((fun.D(fun.HubbleIntegrate(fun.extract(lowZ, 4)[i])) - fun.extract(lowZ, 5)[i]) / fun.D(fun.HubbleIntegrate(fun.extract(lowZ, 4)[i]))) i += 1 i = 0 while i < len(midZ): midZdeviation.append((fun.D(fun.HubbleIntegrate(fun.extract(midZ, 4)[i])) - fun.extract(midZ, 5)[i]) / fun.D(fun.HubbleIntegrate(fun.extract(midZ, 4)[i]))) i += 1 ##(D_L(z) - D_L) / D_L(z) i = 0 while i < len(highZ): highZdeviation.append( (fun.D(fun.HubbleIntegrate(fun.extract(highZ, 4)[i])) -