Exemple #1
0
        MWindex = bestLG['ind2']
        centre = bestLG['cop2']

    cop = bestLG['cops']

    distances = np.array([physUtils.distance(centre, pos) for pos in cop])
    distmask = np.array(
        [distance < maxdist and distance > mindist for distance in distances])

    distances = distances[distmask]
    relvel = (bestLG['vels'] - bestLG['vels'][MWindex])[distmask]
    cop = cop[distmask]
    directions = np.array(
        [physUtils.sphericalCoordinates(pos - centre) for pos in cop])
    radvel = np.array([
        physUtils.velocityComponents(relvel[j], cop[j] - centre)[0]
        for j in range(len(cop))
    ])

    fitdata = clustering.precomputeDistances(directions)
    db = DBSCAN(
        eps=eps,
        min_samples=ms,
        metric='precomputed',
    ).fit(fitdata)
    labels = db.labels_
    unique_labels = set(labels)
    clusters = len(unique_labels) - (1 if -1 in labels else 0)

    colours = plt.cm.tab20(np.linspace(0, 1, 20))
Exemple #2
0
    vel = physUtils.addExpansion(staticVel, cop, centre)

    # LG mass from MW and andromeda
    M_big2 = mass[LG[0]] + mass[LG[1]]

    originalDistances = list(distances)

    # contamination cut
    distmask = distances < closestContDist
    cop = cop[distmask]
    vel = vel[distmask]
    distances = distances[distmask]

    # radial velocities
    radvel = np.array([
        physUtils.velocityComponents(vel[j] - centreVel, cop[j] - centre)[0]
        for j in range(len(vel))
    ])

    (fit,
     flowstartdist) = transitiondistance.findBestHubbleflow(distances, radvel)
    print("HF slope: " + str(fit[0]))
    print("Fitting start distance: " + str(flowstartdist))

    rc('font', **{'family': 'serif', 'serif': ['Palatino']})
    rc('text', usetex=True)

    fig, ax = plt.subplots()

    ax.scatter(distances[distances < flowstartdist],
               radvel[distances < flowstartdist],
Exemple #3
0
def readAndSave(simulationfiles, datafile, mindist=1.5, maxdist=5.0, eps=1.6,
				ms=4, scale_eps=False):
	masses = []
	H0s = []
	inClusterH0s = []
	outClusterH0s = []
	zeropoints = []
	inClusterZeros = []
	outClusterZeros = []
	allDispersions = []
	clusterDispersions = []
	unclusteredDispersions = []
	radialVelocities = []
	tangentialVelocities = []
	LGdistances = []
	timingArgumentMasses = []

	f = open(simulationfiles, 'r')
	for simdir in f.readlines():

		dirname = simdir.strip()
		staticVel = filereader.readAllFiles(dirname, "Subhalo/Velocity", 3)
		mass = filereader.readAllFiles(dirname, "Subhalo/Mass", 1)
		fullCOP = filereader.readAllFiles(dirname, "Subhalo/CentreOfPotential", 3)
		FoFcontamination = filereader.readAllFiles(dirname, "FOF/ContaminationCount",
										  1)
		groupNumbers = filereader.readAllFiles(dirname, "Subhalo/GroupNumber", 1)

		fullCOP = fullCOP/h0 # to Mpc

		# creation of mask with True if there is no contamination in Subhalo
		contaminationMask = np.asarray([FoFcontamination[int(group)-1]<1 for group in
							   groupNumbers])

		# save contaminated haloes for finding closest one
		contaminatedPositions = fullCOP[contaminationMask==False, :]

		# elimination of contaminated haloes
		staticVel = staticVel[contaminationMask,:]
		mass = mass[contaminationMask]
		cop = fullCOP[contaminationMask, :]
		groupNumbers = groupNumbers[contaminationMask]

		# to physical units
		mass = mass/h0*1e10 # to M_☉

		LGs = LGfinder.findLocalGroup(staticVel, mass, cop, quiet=True,
							 outputAll=True)
		unmaskedLGs = LGfinder.maskedToUnmasked(LGs, cop, fullCOP)
		bestLGindex = LGfinder.chooseClosestToCentre(unmaskedLGs, contaminationMask, fullCOP)
		LG = LGs[bestLGindex]

		if mass[LG[0]] > mass[LG[1]]:
			centreIndex = LG[1]
		else:
			centreIndex = LG[0]

		massCentre = physUtils.massCentre(cop[LG[0]], cop[LG[1]], mass[LG[0]],
									mass[LG[1]])
		closestContDist = physUtils.findClosestDistance(massCentre,
												  contaminatedPositions)
		
		if closestContDist < maxdist:
			print("Warning: closest contaminated halo closer than the edge of\
	  Hubble flow fitting range in simulation " + dirname + 
	  ".\nExcluding simulation from analysis.")
			continue


		centre = cop[centreIndex]
		centreVel = staticVel[centreIndex]
		closestContDist = physUtils.findClosestDistance(centre,
											   contaminatedPositions)

		distances = np.array([physUtils.distance(centre, c) for c in
					 cop])
		vel = physUtils.addExpansion(staticVel, cop, centre)

		LGrelVel = vel[LG[0]] - vel[LG[1]]
		LGrelVelComponents = physUtils.velocityComponents(LGrelVel, cop[LG[1]]-cop[LG[0]])
		LGdistance = physUtils.distance(cop[LG[0]], cop[LG[1]])

		closestContMask = distances < closestContDist
		distRangeMask = np.array([d < maxdist and d > mindist for d in
						 distances])


		# contamination and distance range cut
		mask = np.logical_and(closestContMask, distRangeMask)
		cop = cop[mask]
		vel = vel[mask]
		distances = distances[mask]

		# radial velocities
		radvel = np.array([physUtils.velocityComponents(vel[j] - centreVel,
											   cop[j] - centre)[0]
				  for j in range(len(vel))])


		##### extracting clustering data #####

		clusteringDB = clustering.runClustering(cop, centre, ms, eps,
										  meansep=scale_eps)
		labels = clusteringDB.labels_
		uniqueLabels = set(labels)
		clusterMemberMask = labels != -1 # True for haloes in cluster

		## all haloes ##
		(H0, zero) = simpleFit(distances, radvel)
		radvelResiduals = np.empty(radvel.shape)
		for i in range(len(radvel)):
			radvelResiduals[i] = radvel[i] - (distances[i] - zero) * H0
		zeropoints.append(zero)
		H0s.append(H0)
		allDispersions.append(np.std(radvelResiduals, ddof=1))

		## outside clusters ##
		(H0, zero, dispersion) = outClusterFit(clusteringDB, radvel, distances,
										 minHaloes=10)
		outClusterH0s.append(H0)
		outClusterZeros.append(zero)
		unclusteredDispersions.append(dispersion)

		## inside clusters ##
		(H0, zero, dispersion) = inClusterFit(clusteringDB, radvel, distances,
										minSize=10)
		inClusterH0s.append(H0)
		inClusterZeros.append(zero)
		clusterDispersions.append(dispersion)

		# LG mass from MW and andromeda
		M_big2 = mass[LG[0]] + mass[LG[1]]

		masses.append(M_big2)
		radialVelocities.append(LGrelVelComponents[0])
		tangentialVelocities.append(LGrelVelComponents[1])
		LGdistances.append(LGdistance)
		timingArgumentMass = timingargument.timingArgumentMass(-1 *
													  LGrelVelComponents[0],
													  LGdistance*1000.0,
													  13.815, G)
		timingArgumentMasses.append(timingArgumentMass)

	##### finalizing data #####

	masses = np.array(masses)
	H0s = np.array(H0s)
	inClusterH0s = np.array(inClusterH0s)
	outClusterH0s = np.array(outClusterH0s)
	zeropoints = np.array(zeropoints)
	inClusterZeros = np.array(inClusterZeros)
	outClusterZeros = np.array(outClusterZeros)
	allDispersions = np.array(allDispersions)
	clusterDispersions = np.array(clusterDispersions)
	unclusteredDispersions = np.array(unclusteredDispersions)
	radialVelocities = np.array(radialVelocities)
	tangentialVelocities = np.array(tangentialVelocities)
	LGdistances = np.array(LGdistances)
	timingArgumentMasses = np.array(timingArgumentMasses)

	data = np.array([masses, timingArgumentMasses, H0s, inClusterH0s,
				  outClusterH0s, zeropoints, inClusterZeros, outClusterZeros,
				  allDispersions,  unclusteredDispersions, clusterDispersions,
				  radialVelocities, tangentialVelocities, LGdistances]).T


	np.savetxt(datafile, data)

	return data
Exemple #4
0
            centreIndex = LG[0]

        centre = cop[centreIndex]
        centreVel = staticVel[centreIndex]
        massCentre = physUtils.massCentre(cop[LG[0]], cop[LG[1]], mass[LG[0]],
                                          mass[LG[1]])
        closestContDist = physUtils.findClosestDistance(
            massCentre, contaminatedPositions)
        if closestContDist < maxdist:
            continue

        distances = np.array([physUtils.distance(centre, c) for c in cop])
        vel = physUtils.addExpansion(staticVel, cop, centre)

        LGrelVel = vel[LG[0]] - vel[LG[1]]
        LGrelVelComponents = physUtils.velocityComponents(
            LGrelVel, cop[LG[1]] - cop[LG[0]])
        LGdistance = physUtils.distance(cop[LG[0]], cop[LG[1]])

        mask = np.array([d < maxdist and d > mindist for d in distances])
        cop = cop[mask]
        vel = vel[mask]
        distances = distances[mask]
        mass = mass[mask]

        # radial velocities
        radvel = np.array([
            physUtils.velocityComponents(vel[j] - centreVel,
                                         cop[j] - centre)[0]
            for j in range(len(vel))
        ])
Exemple #5
0
def readAndSave(simulationfiles,
                datafile,
                mindist=1.5,
                maxdist=5.0,
                eps=1.6,
                ms=4,
                scale_eps=False):
    masses = []
    H0s = []
    inClusterH0s = []
    outClusterH0s = []
    zeropoints = []
    inClusterZeros = []
    outClusterZeros = []
    allDispersions = []
    clusterDispersions = []
    unclusteredDispersions = []
    radialVelocities = []
    tangentialVelocities = []
    LGdistances = []
    timingArgumentMasses = []

    f = open(simulationfiles, 'r')
    for simdir in f.readlines():

        dirname = simdir.strip()
        staticVel = filereader.readAllFiles(dirname, "Subhalo/Velocity", 3)
        mass = filereader.readAllFiles(dirname, "Subhalo/Mass", 1)
        fullCOP = filereader.readAllFiles(dirname, "Subhalo/CentreOfPotential",
                                          3)
        FoFcontamination = filereader.readAllFiles(dirname,
                                                   "FOF/ContaminationCount", 1)
        groupNumbers = filereader.readAllFiles(dirname, "Subhalo/GroupNumber",
                                               1)

        fullCOP = fullCOP / h0  # to Mpc

        # creation of mask with True if there is no contamination in Subhalo
        contaminationMask = np.asarray(
            [FoFcontamination[int(group) - 1] < 1 for group in groupNumbers])

        # save contaminated haloes for finding closest one
        contaminatedPositions = fullCOP[contaminationMask == False, :]

        # elimination of contaminated haloes
        staticVel = staticVel[contaminationMask, :]
        mass = mass[contaminationMask]
        cop = fullCOP[contaminationMask, :]
        groupNumbers = groupNumbers[contaminationMask]

        # to physical units
        mass = mass / h0 * 1e10  # to M_☉

        LGs = LGfinder.findLocalGroup(staticVel,
                                      mass,
                                      cop,
                                      quiet=True,
                                      outputAll=True)
        unmaskedLGs = LGfinder.maskedToUnmasked(LGs, cop, fullCOP)
        bestLGindex = LGfinder.chooseClosestToCentre(unmaskedLGs,
                                                     contaminationMask,
                                                     fullCOP)
        LG = LGs[bestLGindex]

        if mass[LG[0]] > mass[LG[1]]:
            centreIndex = LG[1]
        else:
            centreIndex = LG[0]

        massCentre = physUtils.massCentre(cop[LG[0]], cop[LG[1]], mass[LG[0]],
                                          mass[LG[1]])
        closestContDist = physUtils.findClosestDistance(
            massCentre, contaminatedPositions)

        if closestContDist < maxdist:
            print("Warning: closest contaminated halo closer than the edge of\
	  Hubble flow fitting range in simulation " + dirname +
                  ".\nExcluding simulation from analysis.")
            continue

        centre = cop[centreIndex]
        centreVel = staticVel[centreIndex]
        closestContDist = physUtils.findClosestDistance(
            centre, contaminatedPositions)

        distances = np.array([physUtils.distance(centre, c) for c in cop])
        vel = physUtils.addExpansion(staticVel, cop, centre)

        LGrelVel = vel[LG[0]] - vel[LG[1]]
        LGrelVelComponents = physUtils.velocityComponents(
            LGrelVel, cop[LG[1]] - cop[LG[0]])
        LGdistance = physUtils.distance(cop[LG[0]], cop[LG[1]])

        closestContMask = distances < closestContDist
        distRangeMask = np.array(
            [d < maxdist and d > mindist for d in distances])

        # contamination and distance range cut
        mask = np.logical_and(closestContMask, distRangeMask)
        cop = cop[mask]
        vel = vel[mask]
        distances = distances[mask]

        # radial velocities
        radvel = np.array([
            physUtils.velocityComponents(vel[j] - centreVel,
                                         cop[j] - centre)[0]
            for j in range(len(vel))
        ])

        ##### extracting clustering data #####

        clusteringDB = clustering.runClustering(cop,
                                                centre,
                                                ms,
                                                eps,
                                                meansep=scale_eps)
        labels = clusteringDB.labels_
        uniqueLabels = set(labels)
        clusterMemberMask = labels != -1  # True for haloes in cluster

        ## all haloes ##
        (H0, zero) = simpleFit(distances, radvel)
        radvelResiduals = np.empty(radvel.shape)
        for i in range(len(radvel)):
            radvelResiduals[i] = radvel[i] - (distances[i] - zero) * H0
        zeropoints.append(zero)
        H0s.append(H0)
        allDispersions.append(np.std(radvelResiduals, ddof=1))

        ## outside clusters ##
        (H0, zero, dispersion) = outClusterFit(clusteringDB,
                                               radvel,
                                               distances,
                                               minHaloes=10)
        outClusterH0s.append(H0)
        outClusterZeros.append(zero)
        unclusteredDispersions.append(dispersion)

        ## inside clusters ##
        (H0, zero, dispersion) = inClusterFit(clusteringDB,
                                              radvel,
                                              distances,
                                              minSize=10)
        inClusterH0s.append(H0)
        inClusterZeros.append(zero)
        clusterDispersions.append(dispersion)

        # LG mass from MW and andromeda
        M_big2 = mass[LG[0]] + mass[LG[1]]

        masses.append(M_big2)
        radialVelocities.append(LGrelVelComponents[0])
        tangentialVelocities.append(LGrelVelComponents[1])
        LGdistances.append(LGdistance)
        timingArgumentMass = timingargument.timingArgumentMass(
            -1 * LGrelVelComponents[0], LGdistance * 1000.0, 13.815, G)
        timingArgumentMasses.append(timingArgumentMass)

    ##### finalizing data #####

    masses = np.array(masses)
    H0s = np.array(H0s)
    inClusterH0s = np.array(inClusterH0s)
    outClusterH0s = np.array(outClusterH0s)
    zeropoints = np.array(zeropoints)
    inClusterZeros = np.array(inClusterZeros)
    outClusterZeros = np.array(outClusterZeros)
    allDispersions = np.array(allDispersions)
    clusterDispersions = np.array(clusterDispersions)
    unclusteredDispersions = np.array(unclusteredDispersions)
    radialVelocities = np.array(radialVelocities)
    tangentialVelocities = np.array(tangentialVelocities)
    LGdistances = np.array(LGdistances)
    timingArgumentMasses = np.array(timingArgumentMasses)

    data = np.array([
        masses, timingArgumentMasses, H0s, inClusterH0s, outClusterH0s,
        zeropoints, inClusterZeros, outClusterZeros, allDispersions,
        unclusteredDispersions, clusterDispersions, radialVelocities,
        tangentialVelocities, LGdistances
    ]).T

    np.savetxt(datafile, data)

    return data
Exemple #6
0
		closestContDist = physUtils.findClosestDistance(MWcop,
												  contaminatedPositions)
		if closestContDist < maxdist:
			excludedSims += 1
			print("excluding " + simdir)
			continue

		LGvector = cop[andromedaIndex] - cop[MWindex]

		centreVel = staticVel[MWindex]
		distances = np.array([physUtils.distance(MWcop, c) for c in
						cop])
		vel = physUtils.addExpansion(staticVel, cop, MWcop)

		LGrelVel = vel[LG[0]] - vel[LG[1]]
		LGrelVelComponents = physUtils.velocityComponents(LGrelVel, cop[LG[1]]-cop[LG[0]])
		LGdistance = physUtils.distance(cop[LG[0]], cop[LG[1]])

		mask = np.array([d < maxdist and d >= mindist for d in
				   distances])
		cop = cop[mask]
		vel = vel[mask]
		distances = distances[mask]

		radvel = np.array([physUtils.velocityComponents(vel[j] - centreVel,
												  cop[j] - MWcop)[0]
					 for j in range(len(vel))])

		directions = np.array([physUtils.angleBetween(LGvector, pos-MWcop) for pos in
						 cop])
	else:
		centre = d['cop2']

	cop = d['cops']
	relvel = d['vels'] - d['centrevel']
	distances = np.array([physUtils.distance(centre, pos) for pos in cop])

	distmask = np.array([distance > 1.5 and distance < 5.0 for distance in distances])
	distances = distances[distmask]

	directions = np.array([physUtils.sphericalCoordinates(pos - centre) for
						   pos in cop[distmask]])

	mass = d['masses'][distmask]

	radvel = np.array([physUtils.velocityComponents(relvel[j], cop[j] -
													centre)[0] for j in
													range(len(cop[distmask]))])

	fit = findBestHubbleflow(distances, radvel)[0]
	for j in range(len(radvel)):
		radvel[j] = radvel[j] - (fit[0]*distances[j] + fit[1])

	rc('font', **{'family':'serif','serif':['Palatino']})
	rc('text', usetex=True)
	#matplotlib.rcParams['axes.unicode_minus'] = False
	
	plt.subplot(111, projection="mollweide")
	plt.grid(True)
	fig = plt.gcf()
	ax = plt.gca()
	ax.set_xticklabels([])
Exemple #8
0
	distances = np.array([physUtils.distance(centre, c) for c in cop])
	vel = physUtils.addExpansion(staticVel, cop, centre)

	# LG mass from MW and andromeda
	M_big2 = mass[LG[0]] + mass[LG[1]]
	
	originalDistances = list(distances)
	
	# contamination cut
	distmask = distances < closestContDist
	cop = cop[distmask]
	vel = vel[distmask]
	distances = distances[distmask]

	# radial velocities
	radvel = np.array([physUtils.velocityComponents(vel[j] - centreVel,
													cop[j] - centre)[0]
					   for j in range(len(vel))])
	
	(fit, flowstartdist) = transitiondistance.findBestHubbleflow(distances, radvel)
	print("HF slope: " + str(fit[0]))
	print("Fitting start distance: " + str(flowstartdist))

	rc('font', **{'family':'serif','serif':['Palatino']})
	rc('text', usetex=True)

	fig, ax = plt.subplots()
	
	ax.scatter(distances[distances < flowstartdist],
			   radvel[distances < flowstartdist], s=1, color=[0.6, 0.6,
															  0.6])
	ax.scatter(distances[distances >= flowstartdist],
Exemple #9
0
		# expansion
		vel = physUtils.addExpansion(vel, cop, massCentre)

		dist = np.zeros(len(vel))
		speed = np.zeros(len(vel))

		# find most distant contaminated
		closestContDistance = physUtils.findClosestDistance(massCentre,
													  contaminatedPositions)

		# distances and velocities relative to centre
		for i in range(len(vel)):
			dist[i] = physUtils.distance(cop[i], massCentre)
			relVel = vel[i]-massCentreVel # velocity relative to movement of the mass CentreOfPotential
			diffInLocation = cop[i]-massCentre # vector defining difference in position 
			speed[i] = physUtils.velocityComponents(relVel, diffInLocation)[0] # radial velocity

		colours = np.zeros((len(vel), 4))
		colours[:, 3] = 1

		ax.scatter(dist[dist<closestContDistance],
			  speed[dist<closestContDistance],
			  color=colours[dist<closestContDistance], s=1)

		#ax.set_xlim([0,closestContDistance])
		ax.set_xlim([0, 6.1])
		ax.set_ylim([-700, 900])
		
		ax.tick_params(which="major", length=6)
		ax.tick_params(which="minor", length=3.5)
		ax.xaxis.set_ticks([])
Exemple #10
0
                                                     contaminationMask,
                                                     fullCOP)
        LG = LGs[bestLGindex]

        if masses[LG[0]] > masses[LG[1]]:
            centreIndex = LG[1]
        else:
            centreIndex = LG[0]

        centre = cop[centreIndex]
        centreVel = staticVel[centreIndex]

        vel = physUtils.addExpansion(staticVel, cop, centre)

        LGrelVel = vel[LG[0]] - vel[LG[1]]
        (rad, tan) = physUtils.velocityComponents(LGrelVel,
                                                  cop[LG[1]] - cop[LG[0]])

        radvel[sim] = rad
        tanvel[sim] = tan
        distance[sim] = physUtils.distance(cop[LG[0]], cop[LG[1]])
        totalmass[sim] = masses[LG[0]] + masses[LG[1]]
        massdifference[sim] = math.fabs(masses[LG[0]] - masses[LG[1]])
        bighalomasses[sim] = max(masses[LG[0]], masses[LG[1]])
        smallhalomasses[sim] = min(masses[LG[0]], masses[LG[1]])

        distances = np.array([physUtils.distance(centre, pos) for pos in cop])
        mass2mpc = sum(masses[np.where(distances <= 2)])
        overdensity2mpc[sim] = (mass2mpc / (4.0 / 3.0 * math.pi *
                                            (2**3))) / critical_density

    #### plotting #####