{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Epithelium Visualization" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import tyssue\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "import matplotlib.pylab as plt\n", "%matplotlib inline\n", "import ipyvolume as ipv\n", "\n", "\n", "from tyssue import Sheet, SheetGeometry as geom\n", "from tyssue.generation import three_faces_sheet\n", "from tyssue.draw import sheet_view\n", "from tyssue import config\n", "from tyssue import Monolayer, config\n", "from tyssue.generation import extrude\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "datasets, specs = three_faces_sheet()\n", "sheet = Sheet('3cells_2D', datasets, specs)\n", "\n", "\n", "geom.update_all(sheet)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sheet.vert_df.describe().head(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Matplotlib based representation\n", "\n", "### Custom settings\n", "\n", "These might go in a config file latter on." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Ploting itself" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Epithelial sheet representation\n", "\n", "\n", "### The default" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "draw_specs = tyssue.config.draw.sheet_spec()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = sheet_view(sheet, ['x', 'y'])\n", "\n", "\n", "ax.set_xlim(-3, 2.5)\n", "ax.set_ylim(-2.75, 2.75)\n", "fig.set_size_inches((8, 8))\n", " \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Coloring" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "## Let's add a column to sheet.vert_df\n", "sheet.vert_df['rand'] = np.linspace(0.0, 1.0, num=sheet.vert_df.shape[0])\n", "\n", "cmap = plt.cm.get_cmap('viridis')\n", "color_cmap = cmap(sheet.vert_df.rand)\n", "draw_specs['vert']['visible'] = True\n", "\n", "draw_specs['vert']['color'] = color_cmap\n", "draw_specs['vert']['alpha'] = 0.5\n", "draw_specs['vert']['s'] = 500" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "coords = ['x', 'y']\n", "fig, ax = sheet_view(sheet, coords, **draw_specs)\n", "\n", "ax.set_xlim(-3, 2.5)\n", "ax.set_ylim(-2.75, 2.75)\n", "fig.set_size_inches((8, 8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Filling the cells\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sheet.face_df['col'] = np.linspace(0.0, 1.0, \n", " num=sheet.face_df.shape[0])\n", "\n", "cmap = plt.cm.get_cmap('viridis')\n", "color_cmap = cmap(sheet.face_df.col)\n", "\n", "draw_specs['edge']['visible'] = False\n", "\n", "draw_specs['face']['visible'] = True\n", "draw_specs['face']['color'] = sheet.face_df['col']\n", "draw_specs['face']['alpha'] = 0.5\n", "\n", "\n", "fig, ax = sheet_view(sheet, coords, **draw_specs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "draw_specs['edge']['visible'] = True\n", "\n", "#draw_specs['face']['visible'] = False\n", "draw_specs['face']['color'] = color_cmap\n", "draw_specs['face']['alpha'] = 0.5\n", "\n", "edge_color = np.linspace(0.0, 1.0, \n", " num=sheet.edge_df.shape[0])\n", "\n", "cmap = plt.cm.get_cmap('viridis')\n", "edge_cmap = cmap(edge_color)\n", "draw_specs['edge']['color'] = edge_cmap #[0, 0, 0, 1]\n", "#draw_specs['edge']['color'] = [0, 0, 0, 0.2]\n", "\n", "draw_specs['edge']['width'] = 8. * np.linspace(0.0, 1.0, \n", " num=sheet.edge_df.shape[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = sheet_view(sheet, coords, **draw_specs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ipyvolume based" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "extruded = extrude(sheet.datasets, method='translation')\n", "specs = config.geometry.bulk_spec()\n", "monolayer = Monolayer('mono', extruded, specs)\n", "\n", "\n", "\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, mode=\"3D\")\n", "fig2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Vertex based color" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "color = (monolayer.vert_df.x**2\n", " + monolayer.vert_df.y**2\n", " + monolayer.vert_df.z**2)\n", "\n", "\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, edge={\"color\":color}, mode=\"3D\")\n", "fig2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Edge based color" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "color = monolayer.edge_df['dy']\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, edge={\"color\":color}, mode=\"3D\")\n", "fig2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Displaying faces" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "draw_specs = config.draw.sheet_spec()\n", "\n", "draw_specs['face']['visible'] = True\n", "\n", "\n", "\n", "#draw_specs['face']['visible'] = False\n", "draw_specs['face']['color'] = np.random.random(monolayer.face_df.shape[0])\n", "\n", "draw_specs['face']['alpha'] = 0.5\n", "\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, mode=\"3D\", **draw_specs)\n", "fig2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Higlighting faces" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tyssue.draw import highlight_cells, highlight_faces" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "highlight_faces(monolayer.face_df, [0, 2, 3], reset_visible=True)\n", "\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, mode=\"3D\", **draw_specs)\n", "fig2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "highlight_cells(monolayer, 1, reset_visible=True)\n", "\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, mode=\"3D\", **draw_specs)\n", "fig2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 1 }