Ejemplo n.º 1
0
def plot_distance_matrix(param_dir: str, names: List[str], ages: List[float],
                         n_layers: int):
    assert len(names) == len(ages)
    roots = []
    for name, age in zip(names, ages):
        rs = RootSystem()
        rs.readParameters(join(param_dir, f"{name}.xml"))
        rs.initialize()
        rs.simulate(age)
        pyroot = Root(rs)
        pyroot.rescale()
        roots.append(pyroot)

    n = len(roots)
    dist_matrix = np.zeros((n, n))
    for i, root_i in enumerate(roots):
        for j, root_j in enumerate(roots[:i + 1]):
            dist_matrix[i, j] = lw_wasserstein(root_i, root_j, n_layers)

    cleaned_names = [" ".join(name.split("_")[:-2]) for name in names]
    #cleaned_names = ages

    heatmap = pd.DataFrame(dist_matrix,
                           columns=cleaned_names,
                           index=cleaned_names)
    ax = sns.heatmap(heatmap, square=True, cmap="Greens")
    ax.tick_params(axis='both', which='both', length=0)
    ax.xaxis.set_ticks_position('bottom')
    plt.xticks(rotation=45)
    plt.yticks(rotation=0)
    bottom, top = ax.get_ylim()
    ax.set_ylim(bottom + 0.5, top - 0.5)
    plt.savefig(join(os.environ["HOME"], "reportOTDendrit", "images",
                     f"distance_matrix_Anagallis.pdf"),
                bbox_inches="tight")
Ejemplo n.º 2
0
def plot_barycenters(param_dir: str, names: List[str], ages: List[float]):
    roots = []
    for name, age in zip(names, ages):
        rs = RootSystem()
        rs.readParameters(join(param_dir, f"{name}.xml"))
        rs.initialize()
        rs.simulate(age)
        pyroot = Root(rs)
        pyroot.rescale()
        roots.append(pyroot)
    for root in roots:
        print(root.n_nodes)

    pt_bar = point_cloud_barycenter(roots)
    fig = plot_barycenter_nodes(pt_bar)
    fig.write_image(
        join(os.environ["HOME"], "reportOTDendrit", "images",
             f"ptbar_{names[0]}_{names[1]}.pdf"))

    _, _, bar_nodes = lw_barycenter(roots, n_layers=100, reg=1e-1)
    fig = plot_barycenter_nodes(bar_nodes)
    fig.write_image(
        join(os.environ["HOME"], "reportOTDendrit", "images",
             f"lwbar_{names[0]}_{names[1]}.pdf"))