Пример #1
0
    def test_sheet_view_homogenous_color(self):
        with pytest.warns(UserWarning):
            self.draw_specs["face"]["color"] = np.ones(3)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

        with pytest.warns(UserWarning):
            self.draw_specs["edge"]["color"] = np.ones(self.sheet.Ne)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)

        with pytest.warns(UserWarning):
            self.draw_specs["edge"]["color"] = np.ones(self.sheet.Nv)
            fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
Пример #2
0
def print_tensions(exp_organo, th_organo, to_save=False, path=None):
    """Print the tensions of an experimental organoid and the theoritical
    organoid on the same plot and save it in a PNG image.

    Parameters
    ----------
    exp_organo : class AnnularSheet
      the experimental organoid whose tensions will be ploted
    th_organo : class AnnularSheet
      the theoritical organoid which will be ploted behind exp_organo tensions
    to_save : bool
      if True the plot must be saved
    path : string
     path to the saved image.
    Returns
    ----------
    """
    draw_specs = sheet_spec()
    tension_max = np.max(exp_organo.edge_df.line_tension.values.copy())
    edge_color = 1/tension_max*exp_organo.edge_df.line_tension.values.copy()
    cmap = plt.cm.get_cmap('viridis')
    edge_cmap = cmap(edge_color)
    draw_specs['vert']['visible'] = False
    draw_specs['edge']['color'] = edge_cmap
    draw_specs['edge']['width'] = 0.25+3*edge_color
    fig, ax = quick_edge_draw(th_organo, lw=5, c='k', alpha=0.2)
    fig, ax = sheet_view(exp_organo, ax=ax, **draw_specs)
    fig.set_size_inches(12, 12)
    plt.xlabel('Size in µm')
    plt.ylabel('Size in µm')
    if to_save:
        plt.savefig(path)
Пример #3
0
    def test_sheet_view(self):
        self.sheet = Sheet("test", *three_faces_sheet())
        self.sheet.vert_df["rand"] = np.linspace(
            0.0, 1.0, num=self.sheet.vert_df.shape[0])
        cmap = plt.cm.get_cmap("viridis")
        color_cmap = cmap(self.sheet.vert_df.rand)
        self.draw_specs["vert"]["color"] = color_cmap
        self.draw_specs["vert"]["alpha"] = 0.5
        self.draw_specs["vert"]["s"] = 500
        self.sheet.face_df["col"] = np.linspace(
            0.0, 1.0, num=self.sheet.face_df.shape[0])
        self.draw_specs["face"]["color"] = self.sheet.face_df["col"]

        self.draw_specs["face"]["visible"] = True
        self.draw_specs["face"]["alpha"] = 0.5

        self.sheet.edge_df["rand"] = np.linspace(
            0.0, 1.0, num=self.sheet.edge_df.shape[0])[::-1]

        self.draw_specs["edge"]["visible"] = True
        self.draw_specs["edge"]["color"] = self.sheet.edge_df[
            "rand"]  # [0, 0, 0, 1]
        self.draw_specs["edge"]["alpha"] = 1.0
        self.draw_specs["edge"]["color_range"] = 0, 3
        self.draw_specs["edge"]["width"] = 1.0 * np.linspace(
            0.0, 1.0, num=self.sheet.edge_df.shape[0])

        fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
        assert len(ax.collections) == 3
        assert ax.collections[0].get_edgecolors().shape == (13, 4)
        assert ax.collections[1].get_edgecolors().shape == (18, 4)
        assert ax.collections[2].get_edgecolors().shape == (0, 4)
        assert ax.collections[2].get_facecolors().shape == (3, 4)
def leg_joint_view(sheet, coords=['z', 'x', 'y']):

    x, y, z = coords
    datasets = {}

    datasets['face'] = sheet.face_df.sort_values(z)
    datasets['vert'] = sheet.vert_df.sort_values(z)
    edge_z = 0.5 * (sheet.upcast_srce(sheet.vert_df[z]) +
                    sheet.upcast_trgt(sheet.vert_df[z]))
    datasets['edge'] = sheet.edge_df.copy()
    datasets['edge'][z] = edge_z
    datasets['edge'] = datasets['edge'].sort_values(z)

    tmp_sheet = Sheet('tmp', datasets, sheet.specs)
    tmp_sheet.reset_index()
    cmap = plt.cm.get_cmap('viridis')

    e_depth = (tmp_sheet.edge_df[z] -
               tmp_sheet.edge_df[z].min()) / tmp_sheet.edge_df[z].ptp()
    depth_cmap = cmap(e_depth)
    draw_specs = {'vert': {'visible': False}, 'edge': {'color': depth_cmap}}

    fig, ax = sheet_view(tmp_sheet, coords[:2], **draw_specs)
    ax.set_xlim(-80, 80)
    ax.set_ylim(-50, 50)
    ax.set_axis_bgcolor('#404040')
    ax.set_xticks([])
    ax.set_yticks([])
    fig.set_size_inches((16, 9))
    fig.set_frameon(False)
    fig.set_clip_box(ax.bbox)
    return fig, ax
Пример #5
0
def plot_force_inference(organo, coefs, cmap='tab20'):
    draw_specs = sheet_spec()
    edge_color = np.ones(organo.Nf * 3)
    cmap = plt.cm.get_cmap(cmap)
    edge_cmap = cmap(edge_color)
    draw_specs['vert']['visible'] = False
    draw_specs['edge']['color'] = edge_cmap
    draw_specs['edge']['width'] = edge_cmap
    fig, ax = sheet_view(organo, **draw_specs)
    U = np.concatenate([coefs[i][coefs[i] != 0] for i in range(organo.Nv)])
    V = np.concatenate(
        [coefs[i + 6][coefs[i + 6] != 0] for i in range(organo.Nv)])
    X = np.concatenate([[organo.vert_df.x[i]] * len(coefs[i][coefs[i] != 0])
                        for i in range(organo.Nv)])
    Y = np.concatenate([[organo.vert_df.y[i]] * len(coefs[i][coefs[i] != 0])
                        for i in range(organo.Nv)])
    C = np.concatenate([np.argwhere(coefs[i] != 0) for i in range(organo.Nv)])
    for i in range(organo.Nv):
        q = ax.quiver(X, Y, U, V, C, cmap=cmap)
        ax.quiverkey(q,
                     X=0.3,
                     Y=1.1,
                     U=10,
                     label='Quiver key, length = 10',
                     labelpos='E')
    fig.set_size_inches(12, 12)
    plt.xlabel('Size in µm')
    plt.ylabel('Size in µm')
Пример #6
0
def print_tensions(exp_organo, th_organo):
    draw_specs = sheet_spec()
    tension_max = np.max(exp_organo.edge_df.line_tension.values.copy())
    edge_color = 1 / tension_max * exp_organo.edge_df.line_tension.values.copy(
    )
    cmap = plt.cm.get_cmap('viridis')
    edge_cmap = cmap(edge_color)
    draw_specs['vert']['visible'] = False
    draw_specs['edge']['color'] = edge_cmap
    draw_specs['edge']['width'] = 0.25 + 3 * edge_color
    fig, ax = quick_edge_draw(th_organo, lw=5, c='k', alpha=0.2)
    fig, ax = sheet_view(exp_organo, ax=ax, **draw_specs)
    fig.set_size_inches(12, 12)
    plt.xlabel('Size in µm')
    plt.ylabel('Size in µm')
Пример #7
0
def color_plot_silico(sheet, centers, col, ax=None, coords=['x', 'y']):
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = ax.get_figure()

    normed = (centers[col] - ranges[col][0]) / (ranges[col][1] -
                                                ranges[col][0])
    face_colors = plt.cm.viridis(normed)

    fig, ax = sheet_view(sheet,
                         coords=coords,
                         ax=ax,
                         face={
                             'visible': True,
                             'color': face_colors
                         },
                         vert={'visible': False})
    ax.grid()
    return fig, ax
Пример #8
0
 def test_sheet_view_color_null_visibility(self):
     self.draw_specs["face"]["color"] = np.random.rand(3, 4)
     self.sheet.face_df["visible"] = False
     with pytest.warns(UserWarning):
         fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
     assert ax.collections[2].get_facecolors().shape == (3, 4)
Пример #9
0
 def test_sheet_view_color_partial_visibility(self):
     self.draw_specs["face"]["color"] = np.random.rand(3, 4)
     self.sheet.face_df["visible"] = False
     self.sheet.face_df.loc[0, "visible"] = True
     fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
     assert ax.collections[2].get_facecolors().shape == (1, 4)
Пример #10
0
 def test_sheet_view_color_string(self):
     self.draw_specs["edge"]["color"] = "k"
     self.draw_specs["face"]["color"] = "red"
     fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
     assert ax.collections[1].get_edgecolors().shape == (1, 4)
     assert ax.collections[2].get_facecolors().shape == (1, 4)
Пример #11
0
 def test_sheet_view_callable(self):
     with pytest.raises(ValueError):
         self.draw_specs["face"]["color"] = lambda sheet: np.ones(5)
         self.draw_specs["edge"]["color"] = lambda sheet: np.ones(5)
         fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
Пример #12
0
    def test_per_vertex_edge_colors(self):

        self.draw_specs["face"]["color"] = "red"
        self.sheet.face_df["visible"] = True
        self.draw_specs["edge"]["color"] = np.random.random(self.sheet.Nv)
        fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
Пример #13
0
 def test_sheet_view_invalid_color_array(self):
     with pytest.raises(ValueError):
         self.draw_specs["face"]["color"] = np.arange(5)
         self.draw_specs["edge"]["color"] = np.arange(self.sheet.Nv)
         fig, ax = sheet_view(self.sheet, ["x", "y"], **self.draw_specs)
Пример #14
0
def color_info_view(sheet, face_information, color_map,
                    max_face_information=None, edge_mask=None,
                    edge_mask_color_map='hot', coords=['x', 'y'],
                    ax=None, normalization=1):
    """
    plot view sheet with :
    face color map according to face information
    and/or edge color map according to edge mask

    Parameters
    ----------
    sheet : a :class:`tyssue.sheet` object
    face_information : string
    color_map : string
    max_face_information : float
        max_value for the color map
    edge_mask : string
    edge_mask_color_map : string
    coords : list
        axis orientation of the plot

    """

    draw_specs = sheet_spec()
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = ax.get_figure()

    perso_cmap = np.linspace(1.0, 1.0, num=sheet.face_df.shape[
        0]) * sheet.face_df[face_information]
    if max_face_information is None:
        max_face_information = max(perso_cmap)
    sheet.face_df['col'] = perso_cmap / max_face_information

    cmap_face = plt.cm.get_cmap(color_map)
    face_color_cmap = cmap_face(sheet.face_df.col)

    if edge_mask is not None:
        list_edge_in_mesoderm = sheet.edge_df['face'].isin(
            sheet.face_df[sheet.face_df[edge_mask]].index)

        cmap_edge = np.ones(sheet.edge_df.shape[
                            0]) * list_edge_in_mesoderm / normalization
        sheet.edge_df['col'] = cmap_edge / (max(cmap_edge)) / normalization

        if normalization == 1:
            cmap_edge = plt.cm.get_cmap(edge_mask_color_map)
        else:
            cmap_edge = plt.cm.get_cmap(edge_mask_color_map, normalization)

        edge_color_cmap = cmap_edge(sheet.edge_df.col)

        draw_specs['edge']['color'] = edge_color_cmap

    draw_specs['edge']['visible'] = True
    draw_specs['edge']['alpha'] = 0.7
    draw_specs['vert']['visible'] = False
    draw_specs['face']['visible'] = True
    draw_specs['face']['color'] = face_color_cmap
    draw_specs['face']['alpha'] = 0.6

    fig, ax = sheet_view(sheet, coords=coords, ax=ax, **draw_specs)
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)
    ax.axis('off')
    ax.set_xlabel(coords[0])
    ax.set_ylabel(coords[1])

    return fig, ax