{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Speckle Tracking" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "from pathlib import Path\n", "# from project_heart.lv import LV\n", "from project_heart.utils import set_jupyter_backend\n", "from project_heart.enums import *\n", "set_jupyter_backend(\"pythreejs\")\n", "import logging\n", "import numpy as np\n", "float_formatter = \"{:.5f}\".format\n", "np.set_printoptions(formatter={'float_kind':float_formatter})\n", "\n", "from project_heart.examples import get_lv_ideal\n", "from project_heart.examples import get_lv_typeA\n", "\n", "lv_ideal = get_lv_ideal(Path(\"../../_static/sample_files/ideal_linear_pressure_increase copy.xplt\"))\n", "lv_typeA = get_lv_typeA(\n", " Path(\"../../_static/sample_files/lv_typeA_hex.vtk\"),\n", " Path(\"../../_static/sample_files/sample_displacement_lv_typeA_hex_states_linear_press_incr.pbz2\"),\n", " save_spk_dict=False\n", " )\n", "\n", "sample_spk_typeA_endo = lv_typeA.get_speckles(spk_name=\"SAMPLE\", spk_group=\"endo\", spk_collection=\"SAMPLE\")[0]\n", "sample_spk_typeA_epi = lv_typeA.get_speckles(spk_name=\"SAMPLE\", spk_group=\"epi\", spk_collection=\"SAMPLE\")[0]\n", "\n", "\n", "import ipywidgets as widgets\n", "from ipywidgets import interactive\n", "from ipywidgets import Button, HBox, VBox\n", "from IPython.display import display, clear_output\n", "\n", "plot_clusters_wdg = widgets.Dropdown(options=[\"subsets\", \"clusters\"], description=\"categories\")\n", "\n", "mode_wdg = widgets.Dropdown(options=[\"longitudinal\", \"transversal\"], description=\"mode\")\n", "nodeset_wdg = widgets.Dropdown(options=[\"endo\", \"epi\"], description=\"nodeset\")\n", "\n", "d_wdg = widgets.FloatSlider(value=2.5, min=0.0, max=8.0, description=\"d\", continuous_update=False)\n", "k_wdg = widgets.FloatSlider(value=0.5, min=0.0, max=1.0, step=0.05, description=\"k\", continuous_update=False)\n", "\n", "k_min_wdg = widgets.FloatSlider(value=-1, min=-1.0, max=1.0, step=0.05, description=\"k_min\", continuous_update=False)\n", "k_max_wdg = widgets.FloatSlider(value=-1, min=-1.0, max=1.0, step=0.05, description=\"k_max\", continuous_update=False)\n", "\n", "normal_a_wdg = widgets.FloatSlider(value=0.0, min=0.0, max=180.0, description=\"a\", continuous_update=False)\n", "\n", "n_subsets_wdg = widgets.IntSlider(value=6, min=0, max=15, description=\"n_subsets\", continuous_update=False)\n", "subset_criteria_wdg = widgets.Dropdown(value=\"z2\", options=[\"z\", \"z2\", 'angles', 'angles2', 'angles3'], description=\"subset_criteria\")\n", "\n", "n_clusters_wdg = widgets.IntSlider(value=6, min=0, max=60, description=\"n_clusters\", continuous_update=False)\n", "cluster_criteria_wdg = widgets.Dropdown(value=\"angles3\", options=[\"z\", \"z2\", 'angles', 'angles2', 'angles3'], description=\"cluster_criteria\")\n", "\n", "a = VBox([plot_clusters_wdg, mode_wdg, nodeset_wdg])\n", "b = VBox([d_wdg, k_wdg, normal_a_wdg])\n", "c = VBox([n_subsets_wdg, subset_criteria_wdg, k_min_wdg])\n", "d = VBox([n_clusters_wdg, cluster_criteria_wdg, k_max_wdg])\n", "\n", "controls = HBox([a, b, c, d])\n", "\n", "def create_and_show_speckles(plot_mode, mode, nodeset, normal_a, d, k, \n", " n_subsets, subset_criteria,\n", " n_clusters, cluster_criteria,\n", " k_min, k_max\n", " ):\n", " # clear_output()\n", " \n", " if mode == \"longitudinal\":\n", " a = np.radians(normal_a)\n", " normal = [np.cos(a),np.sin(a),0.0]\n", " else:\n", " normal = [0.,0.,1.]\n", " \n", " if nodeset == \"endo\":\n", " nodeset = LV_SURFS.ENDO\n", " else:\n", " nodeset = LV_SURFS.EPI\n", " \n", " # plot spkes on ideal case\n", " spk_name = \"SAMPLE-INTERACT-\" + str(nodeset) \n", " spk_name = \"-\" + str(normal)\n", " spk_name += \"-\" + str(n_subsets) + str(subset_criteria)\n", " spk_name += \"-\" +str(n_clusters) + str(cluster_criteria)\n", " \n", " spk1 = lv_ideal.create_speckles(\n", " collection=spk_name,\n", " group=spk_name,\n", " name=spk_name,\n", " from_nodeset=nodeset,\n", " # exclude_nodeset=[LV_SURFS.BASE, LV_SURFS.ENDO],\n", " d=d,\n", " k=k,\n", " normal_to=normal,\n", " n_subsets=n_subsets,\n", " subsets_criteria=subset_criteria,\n", " n_clusters=n_clusters,\n", " cluster_criteria=cluster_criteria,\n", " t=0.0,\n", " kmin=k_min,\n", " kmax=k_max,\n", " log_level=logging.WARN,\n", " )\n", " \n", " if plot_mode == \"subsets\":\n", " lv_ideal.plot_speckles(spk1, \n", " cmap=\"tab20\",\n", " point_size=300,\n", " add_k_centers=True, \n", " k_centers_as_line=False, \n", " k_bins=False,\n", " plot_kwargs=dict(notebook=True)\n", " )\n", " else:\n", " lv_ideal.plot_speckles(spk1, \n", " cmap=\"hot\",\n", " point_size=300,\n", " add_k_centers=True, \n", " k_centers_as_line=True, \n", " k_bins=True,\n", " plot_kwargs=dict(notebook=True)\n", " )\n", " \n", " # plot speckles on non-ideal case.\n", " spk2 = lv_typeA.create_speckles(\n", " collection=spk_name,\n", " group=spk_name,\n", " name=spk_name,\n", " from_nodeset=nodeset,\n", " # exclude_nodeset=[LV_SURFS.BASE, LV_SURFS.ENDO],\n", " d=d,\n", " k=k,\n", " normal_to=normal,\n", " n_subsets=n_subsets,\n", " subsets_criteria=subset_criteria,\n", " n_clusters=n_clusters,\n", " cluster_criteria=cluster_criteria,\n", " t=0.0,\n", " kmin=k_min,\n", " kmax=k_max,\n", " log_level=logging.WARN,\n", " )\n", " \n", " if plot_mode == \"subsets\":\n", " lv_typeA.plot_speckles(spk2, \n", " cmap=\"tab20\",\n", " point_size=300,\n", " add_k_centers=True, \n", " k_centers_as_line=False, \n", " k_bins=False,\n", " plot_kwargs=dict(notebook=True)\n", " )\n", " else:\n", " lv_typeA.plot_speckles(spk2, \n", " cmap=\"hot\",\n", " point_size=300,\n", " add_k_centers=True, \n", " k_centers_as_line=True, \n", " k_bins=True,\n", " plot_kwargs=dict(notebook=True)\n", " )\n", " \n", "def interactive_speckles():\n", " out = widgets.interactive_output(create_and_show_speckles, \n", " dict(\n", " plot_mode=plot_clusters_wdg,\n", " mode=mode_wdg, \n", " nodeset=nodeset_wdg, \n", " normal_a=normal_a_wdg,\n", " d=d_wdg, k=k_wdg, \n", " n_subsets=n_subsets_wdg, \n", " subset_criteria=subset_criteria_wdg,\n", " n_clusters=n_clusters_wdg, \n", " cluster_criteria=cluster_criteria_wdg,\n", " k_min=k_min_wdg,\n", " k_max=k_max_wdg,\n", " ))\n", " display(controls, out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What are Speckles?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "DOC PENDING..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "interactive_speckles()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sample Speckles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Longitudinal Speckles" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# lv_ideal.plot_speckles(endo_long[1], add_centers=True, cmap=\"tab10\", categories=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# lv_ideal.plot_speckles(epi_long[0], cmap=\"jet\", add_k_centers=True, k_centers_as_line=True, k_bins=True, categories=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Circumferential Speckles" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# lv_ideal.plot_speckles(endo_circ[7], add_centers=True, cmap=\"tab10\", categories=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# lv_ideal.plot_speckles(epi_circ[7], cmap=\"jet\", add_k_centers=True, k_centers_as_line=True, k_bins=True, categories=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "a4b270fe5129ef310552b5197d637a230d47119f1e46f0b92ff32b1c5f5c5425" }, "kernelspec": { "display_name": "Python 3.9.7 ('project_heart')", "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.9.7" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }