{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Map data on mesh" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from vedo import *\n", "\n", "settings.default_backend = \"vtk\" # or k3d, ipyvtk, or 2d" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "# Gene expression data\n", "gene_path = '../data/gene_data.npy'\n", "\n", "# Mesh data\n", "faces_path = '../data/mesh_faces.npy'\n", "verts_path = '../data/mesh_nodes.npy'" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "# Read data\n", "faces = np.load(faces_path)\n", "verts = np.load(verts_path)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n", "
\n", "vedo.mesh.Mesh\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
bounds
(x/y/z)
-450.0 ... 1998
-930.0 ... 900.0
0 ... 0
center of mass (693, -12.5, 0)
average size 785.066
nr. points / faces 3881 / 7021
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create the mesh \n", "msh = Mesh([verts, faces]).linewidth(1)\n", "msh" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "show(msh, bg=\"#282a36\").close()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n", "
\n", "vedo.mesh.Mesh\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
bounds
(x/y/z)
-450.0 ... 1998
-930.0 ... 900.0
0 ... 0
center of mass (693, -12.5, 0)
average size 785.066
nr. points / faces 3881 / 7021
cell data array fake_data
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Adding scalar values\n", "n = faces.shape[0] # number of faces\n", "values = np.random.random(n)\n", "msh.celldata[\"fake_data\"] = values\n", "msh.cmap(\"viridis\")\n", "msh.linewidth(0)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "show(msh, bg=\"#282a36\").close()" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n", "
\n", "vedo.mesh.Mesh\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
bounds
(x/y/z)
-450.0 ... 1998
-930.0 ... 900.0
0 ... 0
center of mass (693, -12.5, 0)
average size 785.066
nr. points / faces 3881 / 7021
cell data array gene_data
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values = np.load(gene_path)\n", "msh.celldata[\"gene_data\"] = values\n", "msh.cmap(\"viridis\")" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "show(msh, bg=\"#282a36\", zoom='tight').close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.10" } }, "nbformat": 4, "nbformat_minor": 2 }