def quickrun_get_membership(): # This is for AlphaCluster and should be cleaner # Should easily support the MAIN_CLUSTER_THRESHOLD option data = get_carina() apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() colors, color_list, recs, base_width, lim = apy.dendrogram(a_x) lim_alpha_lo, lim_alpha_hi = lim plt.figure() ax = plt.subplot(122) for i, r_list in enumerate(recs): for r in r_list: r.set_facecolor(color_list[i]) ax.add_artist(r) ax.set_xlim([-0.05 * base_width, 1.05 * base_width]) ax.set_ylim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) ax.set_yscale("log") ax.set_xlabel("# triangles") ax.set_ylabel("$\\alpha$") ax.invert_yaxis() ax = plt.subplot(121) for c, ps in colors.items(): x, y = zip(*ps) plt.scatter(x, y, color=c, alpha=0.8, s=1) ax.invert_xaxis() ax.set_xlabel("RA") ax.set_ylabel("Dec") plt.show()
def test_simplex_node_sort(): data = get_carina()[:100, :] apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) ts = apy.KEY.simplices() for t in sorted(ts): print(t.circumradius)
def quickrun_mean_vps(): data = get_carina() apy.QUIET = False apy.ORPHAN_TOLERANCE = 100 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 1 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() stack = [a_x] mean_vpss = [] while stack: a = stack.pop() mean_vpss.append((a.alpha_range, a.mean_vps)) stack += a.subclusters colors, color_list, recs, base_width, lim = apy.dendrogram(a_x) lim_alpha_lo, lim_alpha_hi = lim plt.figure() ax = plt.subplot(223) for i, r_list in enumerate(recs): for r in r_list: r.set_facecolor(color_list[i]) ax.add_artist(r) ax.set_xlim([-0.05 * base_width, 1.05 * base_width]) ax.set_ylim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) ax.set_yscale("log") ax.set_xlabel("# triangles") ax.set_ylabel("$\\alpha$") ax.invert_yaxis() ax = plt.subplot(221) for c, ps in colors.items(): x, y = zip(*ps) plt.scatter(x, y, color=c, alpha=0.8, s=1) # ax.invert_xaxis() ax.invert_yaxis() # ax.set_xlabel("RA") # ax.set_ylabel("Dec") ax.set_xlabel("x") ax.set_ylabel("y") ax = plt.subplot(122) print() coeff = (1 + np.sin(np.pi / 6)) * np.cos(np.pi / 6) for m, c in zip(mean_vpss, color_list): a_r, m_vps = m normed_vps = [abs(x) for x, a in zip(m_vps, a_r[:-1])] plt.plot(a_r[:-1], normed_vps, '-', color=c) ax.set_xlabel("$\\alpha$") ax.set_ylabel("Mean Volume per Simplex, normed to equilateral") ax.set_xscale("log") ax.set_yscale("log") # ax.set_xlim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) # ax.set_ylim([.01, 100]) ax.invert_xaxis() plt.show()
def profiler(): data = get_carina() apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.95 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.GAP_THRESHOLD = 1 apy.initialize(data) import cProfile import re cProfile.run("apy.recurse()")
def test_compare_mst_alpha(): data = get_carina() apy.QUIET = False apy.ORPHAN_TOLERANCE = 100 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() colors, color_list, recs, base_width, lim = apy.dendrogram(a_x) lim_alpha_lo, lim_alpha_hi = lim plt.figure() ax_dend = plt.subplot(122) for i, r_list in enumerate(recs): for r in r_list: r.set_facecolor(color_list[i]) ax_dend.add_artist(r) ax_dend.set_xlim([-0.05 * base_width, 1.05 * base_width]) ax_dend.set_ylim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) ax_dend.set_yscale("log") ax_dend.set_xlabel("# triangles") ax_dend.set_ylabel("$\\alpha$") ax_dend.invert_yaxis() ax_points = plt.subplot(121) for c, ps in colors.items(): x, y = zip(*ps) plt.scatter(x, y, color=c, alpha=0.8, s=1) ax_points.invert_xaxis() ax_points.set_xlabel("RA") ax_points.set_ylabel("Dec") print("Halfway..") tri = apy.KEY.delaunay min_sp_tree = mstcluster.prepare_mst_simple(tri) cutoff_alpha = mstcluster.get_cdf_cutoff(min_sp_tree) clusters = mstcluster.reduce_mst_clusters(min_sp_tree) for c in clusters: if len(c) >= apy.ORPHAN_TOLERANCE / 2.: coords = np.array([tri.points[i, :] for i in c]) hull = ConvexHull(coords) # noinspection PyUnresolvedReferences for simplex in hull.simplices: plt.plot(coords[simplex, 0], coords[simplex, 1], '-', color='r', lw=2) ax_dend.plot([0, base_width], [cutoff_alpha, cutoff_alpha], '--', 'r') plt.show()
def quickrun_get_membership_3d(): # This is for AlphaCluster and should be cleaner # Should easily support the MAIN_CLUSTER_THRESHOLD option data = get_ScoOB() apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() colors, color_list, recs, base_width, lim = apy.dendrogram(a_x) lim_alpha_lo, lim_alpha_hi = lim plt.figure() ax = plt.subplot2grid((2, 4), (1, 3)) for i, r_list in enumerate(recs): for r in r_list: r.set_facecolor(color_list[i]) ax.add_artist(r) ax.set_xlim([-0.05 * base_width, 1.05 * base_width]) ax.set_ylim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) ax.set_yscale("log") ax.set_xlabel("# triangles") ax.set_ylabel("$\\alpha$") ax.invert_yaxis() ax = plt.subplot2grid((2, 4), (0, 0), colspan=3, rowspan=2, projection='3d') print() for c, ps in colors.items(): x, y, z = zip(*ps) ax.plot(x, y, zs=z, marker='.', color=c, alpha=0.8, linestyle='None', markersize=1) # alpha_of_interest = 0.484 #a_x.alpha_range[int(len(a_x.alpha_range)/2)] # faces = apy.alpha_surfaces(a_x, alpha_of_interest) # for f in faces: # ax.add_collection3d(f) ax.set_xlabel("$\Delta$RA off center") ax.set_ylabel("$\Delta$Dec off center") ax.set_zlabel("radial distance (kpc)") plt.show()
def test_cayley_menger_high_d(): n = 4 data = get_data_n_dim(n)[:30, :] apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) v, r = zip(*[(s.volume, s.circumradius) for s in apy.KEY.simplices()]) sr = np.array(sorted(list(r))) plt.plot(r, v, '.') plt.plot(sr, sr**n) plt.xscale('log') plt.yscale('log') plt.xlabel("Circumradius") plt.ylabel("Volume") plt.legend() plt.show()
def test_cayley_menger(): a = np.array([[0, 0], [1, 0], [0, 1]], dtype=np.float64) v, r = apy.cayley_menger_vr(a) print("Volume", v, "Circumradius", r) data = get_carina()[:100, :] apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 3 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) v, r = zip(*[(s.volume, s.circumradius) for s in apy.KEY.simplices()]) plt.plot(r, v, '.') sr = np.array(sorted(list(r))) coeff = (1 + np.sin(np.pi / 6)) * np.cos(np.pi / 6) plt.plot(sr, (sr**2) * coeff, label="Equilateral triangle volume: upper bound on $v(r)$") plt.xscale('log') plt.yscale('log') plt.xlabel("Circumradius") plt.ylabel("Volume") plt.legend() plt.show()
import numpy as np import alphax_utils as apy import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import sys import timeit def test_something(): srcfile = "../../PyAlpha_drafting/test_data/Ssets/s1.txt" points = np.genfromtxt(srcfile) return points data = test_something() apy.initialize(data) apy.KEY.alpha_step = 0.95 apy.KEY.orphan_tolerance = 80 apy.recurse()
def test_boundary_3d(): # This is for AlphaCluster and should be cleaner # Should easily support the MAIN_CLUSTER_THRESHOLD option data = get_gaia_data() apy.QUIET = False apy.ORPHAN_TOLERANCE = 50 apy.ALPHA_STEP = .97 apy.PERSISTENCE_THRESHOLD = 3 apy.GAP_THRESHOLD = 1 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() colors, color_list, recs, base_width, lim = apy.dendrogram(a_x) lim_alpha_lo, lim_alpha_hi = lim plt.figure() ax = plt.subplot2grid((2, 4), (1, 3)) for i, r_list in enumerate(recs): for r in r_list: r.set_facecolor(color_list[i]) ax.add_artist(r) ax.set_xlim([-0.05 * base_width, 1.05 * base_width]) ax.set_ylim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) ax.set_yscale("log") ax.set_xlabel("# triangles") ax.set_ylabel("$\\alpha$") ax.invert_yaxis() ax = plt.subplot2grid((2, 4), (0, 0), colspan=3, rowspan=2, projection='3d') print() stack = [a_x] while stack: a = stack.pop() for i, b_list in enumerate(a.boundary_range): if a.alpha_range[i] > 2.1: continue # We used to check if len(b_list) > 1 but I think that's counterproductive # b_list is the list of gap (set(), frozenset()) tuples for a given alpha if b_list: for b in b_list: # b is a tuple of (set(), frozenset()) # it represents a given gap at a given alpha # the set (index 0) gives the boundary edges (SimplexEdge) # the frozenset (index 1) gives the boundary volume elements (SimplexNode) verts = [] for s in b[0]: # add triangles to triangulation verts.append(s.coord_array()) tri = Poly3DCollection(verts, linewidths=1) tri.set_alpha(0.2) tri.set_facecolor('k') tri.set_edgecolor('k') ax.add_collection3d(tri) stack += a.subclusters for c, ps in colors.items(): x, y, z = zip(*ps) plt.plot(x, y, zs=z, marker='.', color=c, alpha=0.8, linestyle='None') ax.invert_xaxis() ax.set_zlim([290, 310]) ax.set_xlabel("$\Delta$RA off center") ax.set_ylabel("$\Delta$Dec off center") ax.set_zlabel("radial distance (kpc)") plt.show()
def test_boundary(): # This is for AlphaCluster and should be cleaner # Should easily support the MAIN_CLUSTER_THRESHOLD option data = get_carina() apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = .97 #0.97 apy.PERSISTENCE_THRESHOLD = 1 apy.GAP_THRESHOLD = 15 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() colors, color_list, recs, base_width, lim = apy.dendrogram(a_x) lim_alpha_lo, lim_alpha_hi = lim plt.figure() ax = plt.subplot2grid((6, 6), (3, 4), colspan=2, rowspan=3) for i, r_list in enumerate(recs): for r in r_list: r.set_facecolor(color_list[i]) ax.add_artist(r) ax.set_xlim([-0.05 * base_width, 1.05 * base_width]) ax.set_ylim([lim_alpha_lo * .9, lim_alpha_hi * 1.1]) ax.set_yscale("log") ax.set_xlabel("# triangles") ax.set_ylabel("$\\alpha$") ax.invert_yaxis() ax = plt.subplot2grid((6, 6), (0, 0), colspan=4, rowspan=5) print() stack = [a_x] while stack: a = stack.pop() for b_list in a.boundary_range: if b_list and len(b_list) > 1: # cool_colors = cycle(['k', 'b', 'g', 'y', 'orange', 'navy', 'cyan']) for b in b_list: # clr = next(cool_colors) for s in b[1]: ax.add_artist( Polygon(s.coord_array(), alpha=0.1, facecolor='k', edgecolor=None)) # x, y = [], [] # for p in e: # x.append(p[0]), y.append(p[1]) # if clr == 'r': # plt.plot(x, y, '--', color=clr) # else: # plt.plot(x, y, '-', color=clr) for c, ps in colors.items(): x, y = zip(*ps) plt.scatter(x, y, color=c, alpha=0.8, s=1) ax.invert_xaxis() ax.set_xlabel("RA") ax.set_ylabel("Dec") # ax = plt.subplot(223) # plt.scatter(apy.KEY.delaunay.points[:, 0], apy.KEY.delaunay.points[:, 1], color='k', alpha=0.6, s=1) # ax.invert_xaxis() # ax.set_xlabel("RA") # ax.set_ylabel("Dec") plt.show()
elif prefix == "STEP": apy.ALPHA_STEP = n elif prefix == "PT": apy.PERSISTENCE_THRESHOLD = n elif prefix == "MCT": apy.MAIN_CLUSTER_THRESHOLD = n return a_x scoOB_pickle_local = "../PyAlpha_drafting/test_data/ScoOB_AX.pkl" # This is for AlphaCluster and should be cleaner # Should easily support the MAIN_CLUSTER_THRESHOLD option a_x = get_pickle(scoOB_pickle_local) ax = scoOB_plt(speedplot(a_x, alpha_of_interest=0.484)) plt.show() """ data = get_ScoOB() apy.QUIET = False apy.ORPHAN_TOLERANCE = 150 apy.ALPHA_STEP = 0.97 apy.PERSISTENCE_THRESHOLD = 1 apy.MAIN_CLUSTER_THRESHOLD = 51 apy.initialize(data) a_x = apy.recurse() scoOB_plt(speedplot(a_x, alpha_of_interest=0.484)) plt.show() """