{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import pandas as pd\n", "import numpy as np\n", "\n", "\n", "from tyssue import config\n", "from tyssue.draw import sheet_view" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Geometry classes\n", "\n", "A `Geometry` class is a stateless class holding functions to compute geometrical aspects of an epithelium,\n", "such as the edge lengths or the cells volume. As they are classes, inheritance can be used to define more and more specialized geometries.\n", "\n", "For the user, a geomtry class is expected to have an `update_all` method that takes an `Epithelium` instance as sole argument.\n", "\n", "\n", "## Planar Geometries \n", "\n", "It's simple to create hexagonal apical junction meshes with the `Sheet` class method `planar_sheet_2d()`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tyssue import Sheet\n", "from tyssue import PlanarGeometry\n", "from tyssue.generation import generate_ring\n", "\n", "sheet_2d = Sheet.planar_sheet_2d('planar', nx=6, ny=6, \n", " distx=1, disty=1)\n", "sheet_2d.sanitize(trim_borders=True, order_edges=True)\n", "\n", "PlanarGeometry.update_all(sheet_2d)\n", "\n", "ring = generate_ring(24, 12, 14)\n", "PlanarGeometry.update_all(ring)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, (ax, ax2) = plt.subplots(1, 2)\n", "fig, ax = sheet_view(sheet_2d, ax=ax)\n", "fig, ax2 = sheet_view(ring, ax=ax2)\n", "fig.set_size_inches(12, 6)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sheet geometry in 3D" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tyssue import SheetGeometry\n", "from tyssue.geometry.sheet_geometry import EllipsoidGeometry\n", "from tyssue.generation import ellipsoid_sheet\n", "\n", "sheet_3d = Sheet.planar_sheet_3d('sheet', nx=6, ny=6, \n", " distx=1, disty=1)\n", "sheet_3d.sanitize(trim_borders=True)\n", "\n", "SheetGeometry.update_all(sheet_3d)\n", "\n", "ellipso = ellipsoid_sheet(a=12, b=12, c=21, n_zs=12)\n", "EllipsoidGeometry.update_all(ellipso)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sheet_3d.vert_df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`EllipsoidGeometry` inherits from `SheetGeometry` through `ClosedSheetGeometry`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import inspect\n", "print(*(cls.__name__ for cls in \n", " inspect.getmro(EllipsoidGeometry)), sep=\"\\n\\t|_ \")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i, cls in enumerate(inspect.getmro(EllipsoidGeometry)):\n", " print(cls.__name__, \"which defines:\")\n", " \n", " for method, _ in inspect.getmembers(cls, inspect.ismethod):\n", " print(\"\\t\", method)\n", " if cls.__name__ == \"BaseGeometry\":\n", " break\n", " print(\"inherits from\", end=\" \")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = sheet_view(sheet_3d, [\"x\", \"y\"], \n", " mode=\"quick\", edge={\"color\": 'k'})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tyssue.draw.ipv_draw import view_ipv\n", "import ipyvolume as ipv\n", "ipv.clear()\n", "\n", "fig, mesh = sheet_view(ellipso, mode=\"3D\")\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Monolayer " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tyssue import Monolayer\n", "from tyssue.generation import extrude\n", "\n", "extruded = extrude(sheet_3d.datasets, method='translation')\n", "specs = config.geometry.bulk_spec()\n", "monolayer = Monolayer('mono', extruded, specs)\n", "\n", "mono_ellipso = Monolayer('ell', extrude(ellipso.datasets, method='homotecy', scale=0.9))\n", "mono_ellipso.vert_df['z'] += 5\n", "from tyssue.draw.ipv_draw import view_ipv\n", "import ipyvolume as ipv\n", "ipv.clear()\n", "fig2, mesh = sheet_view(monolayer, mode=\"3D\")\n", "fig2, mesh = sheet_view(mono_ellipso, mode=\"3D\")\n", "\n", "fig2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bulk tissue " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tyssue import Epithelium, BulkGeometry\n", "from tyssue.generation import from_3d_voronoi, hexa_grid3d\n", "from tyssue.draw import highlight_cells\n", "from scipy.spatial import Voronoi\n", "\n", "cells = hexa_grid3d(4, 4, 6)\n", "datasets = from_3d_voronoi(Voronoi(cells))\n", "specs = config.geometry.bulk_spec()\n", "bulk = Epithelium('bulk', datasets, specs)\n", "bulk.reset_topo()\n", "bulk.reset_index()\n", "bulk.sanitize()\n", "bulk.reset_topo()\n", "bulk.reset_index()\n", "\n", "\n", "BulkGeometry.update_all(bulk)\n", "\n", "bulk.face_df['visible'] = False\n", "\n", "highlight_cells(bulk, [12, 4])\n", "ipv.clear()\n", "fig2, mesh = sheet_view(bulk, mode=\"3D\",\n", " face={\"visible\":True})\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 }