コード例 #1
0
ファイル: k-dist.py プロジェクト: aajarven/gradu-yde
			centre = d['cop1']
		else:
			centre = d['cop2']

		cop = d['cops']
		distances = np.array([physUtils.distance(centre, pos) for pos in cop])
		if max(distances) < 5.0:
			print("distance criteria failed")
			continue
		distmask = np.array([distance < 5.0 and distance > 1.5 for distance in
						  distances])

		distances = distances[distmask]
		cop = cop[distmask]

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

		fitdata = clustering.precomputeDistances(directions)
		meansep = np.mean([min(x[x>0]) for x in fitdata])
		
		neighbours= NearestNeighbors(n_neighbors=5,
											metric='precomputed').fit(fitdata)
#		neighbours= NearestNeighbors(n_neighbors=5,
#											metric='precomputed').fit(np.divide(fitdata,
#											  meansep))
		k_distances, indices = neighbours.kneighbors(n_neighbors=4, return_distance=True)
		four_distances = k_distances[:,3]

		plt.plot(range(0, len(four_distances)), sorted(four_distances,
												reverse=True), alpha=0.1, c='k')
コード例 #2
0
        centre = bestLG['cop1']
    else:
        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)
コード例 #3
0
    if d['mass1'] < d['mass2']:
        centre = d['cop1']
    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)