From 9f5ba971a349791eec820ab3415f0dd068176b5b Mon Sep 17 00:00:00 2001 From: Nicole Date: Mon, 30 Oct 2023 17:18:37 -0600 Subject: [PATCH] add extra Ascent examples --- .../notebooks/10_ascent_extra_examples.ipynb | 737 ++++++++++++++++++ 1 file changed, 737 insertions(+) create mode 100644 src/examples/tutorial/ascent_intro/notebooks/10_ascent_extra_examples.ipynb diff --git a/src/examples/tutorial/ascent_intro/notebooks/10_ascent_extra_examples.ipynb b/src/examples/tutorial/ascent_intro/notebooks/10_ascent_extra_examples.ipynb new file mode 100644 index 000000000..588859d72 --- /dev/null +++ b/src/examples/tutorial/ascent_intro/notebooks/10_ascent_extra_examples.ipynb @@ -0,0 +1,737 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Extra Ascent Action Examples\n", + "Extra Ascent action examples to showcase different capabilities. See Ascent's [Pipelines](https://ascent.readthedocs.io/en/latest/Actions/Pipelines.html) docs for deeper details on Pipelines." + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [], + "source": [ + "# ascent + conduit imports\n", + "import conduit\n", + "import conduit.blueprint\n", + "import ascent\n", + "\n", + "import numpy as np\n", + "\n", + "# cleanup any old results\n", + "!./cleanup.sh" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create an example mesh to feed to Ascent" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [], + "source": [ + "# create example mesh using the conduit blueprint braid helper\n", + "mesh = conduit.Node()\n", + "conduit.blueprint.mesh.examples.braid(\"hexs\",\n", + " 25,\n", + " 25,\n", + " 25,\n", + " mesh)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extra Example 1:\n", + "### Vector Component filter to extract scalar component of a vector field" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "- \n", + " action: \"add_pipelines\"\n", + " pipelines: \n", + " pl1: \n", + " f1: \n", + " type: \"vector_component\"\n", + " params: \n", + " field: \"vel\"\n", + " component: 0\n", + " output_name: \"my_comp_vec\"\n", + "- \n", + " action: \"add_scenes\"\n", + " scenes: \n", + " s1: \n", + " plots: \n", + " p1: \n", + " type: \"pseudocolor\"\n", + " pipeline: \"pl1\"\n", + " field: \"my_comp_vec\"\n", + " image_name: \"out_pipeline_vec_comp_0\"\n", + "\n" + ] + } + ], + "source": [ + "a = ascent.Ascent()\n", + "a.open()\n", + "\n", + "# publish our mesh to ascent\n", + "a.publish(mesh);\n", + "\n", + "# setup actions\n", + "actions = conduit.Node()\n", + "add_act = actions.append()\n", + "add_act[\"action\"] = \"add_pipelines\"\n", + "pipelines = add_act[\"pipelines\"]\n", + "\n", + "# create a pipeline (pl1) with a vector component filter (f1)\n", + "pipelines[\"pl1/f1/type\"] = \"vector_component\"\n", + "\n", + "# extract vector component params\n", + "vec_comp_params = pipelines[\"pl1/f1/params\"]\n", + "vec_comp_params[\"field\"] = \"vel\"\n", + "vec_comp_params[\"component\"] = 0\n", + "vec_comp_params[\"output_name\"] = \"my_comp_vec\"\n", + "\n", + "# declare a scene to render the pipeline result\n", + "\n", + "add_act2 = actions.append()\n", + "add_act2[\"action\"] = \"add_scenes\"\n", + "scenes = add_act2[\"scenes\"]\n", + "\n", + "# add a scene (s1) with one pseudocolor plot (p1) that \n", + "# will render the result of our pipeline (pl1)\n", + "scenes[\"s1/plots/p1/type\"] = \"pseudocolor\"\n", + "scenes[\"s1/plots/p1/pipeline\"] = \"pl1\"\n", + "scenes[\"s1/plots/p1/field\"] = \"my_comp_vec\"\n", + "# set the output file name (ascent will add \".png\")\n", + "scenes[\"s1/image_name\"] = \"out_pipeline_vec_comp_0\"\n", + "\n", + "# print our full actions tree\n", + "print(actions.to_yaml())\n", + "\n", + "# execute the actions\n", + "a.execute(actions)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ee809d1efed242b299d803611aea382d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Tab(children=(VBox(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x04\\x00\\…" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# show the resulting image\n", + "ascent.jupyter.AscentViewer(a).show()" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [], + "source": [ + "#close ascent\n", + "a.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extra Example 2:\n", + "### Create two renders for one scene, one of them specifying all camera parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "- \n", + " action: \"add_scenes\"\n", + " scenes: \n", + " s1: \n", + " plots: \n", + " p1: \n", + " type: \"volume\"\n", + " field: \"braid\"\n", + " color_table: \n", + " name: \"blue\"\n", + " control_points: \n", + " - \n", + " type: \"rgb\"\n", + " position: 0.0\n", + " color: [1.0, 0.0, 0.0]\n", + " - \n", + " type: \"rgb\"\n", + " position: 0.5\n", + " color: [0.0, 1.0, 0.0]\n", + " - \n", + " type: \"rgb\"\n", + " position: 1.0\n", + " color: [1.0, 1.0, 1.0]\n", + " - \n", + " type: \"alpha\"\n", + " position: 0.0\n", + " alpha: 0.0\n", + " - \n", + " type: \"alpha\"\n", + " position: 1.0\n", + " alpha: 1.0\n", + " image_name: \"out_pipeline_color_test\"\n", + " renders: \n", + " r1: \n", + " image_width: 512\n", + " image_height: 512\n", + " image_prefix: \"out_extra_renders_r1_simple\"\n", + " r2: \n", + " image_width: 400\n", + " image_height: 400\n", + " image_prefix: \"out_extra_renders_r2_cam_params\"\n", + " camera: \n", + " look_at: [1.0, 1.0, 1.0]\n", + " position: [0.0, 25.0, 15.0]\n", + " up: [0.0, -1.0, 0.0]\n", + " fov: 60.0\n", + " xpan: 0.0\n", + " ypan: 0.0\n", + " zoom: 1.0\n", + " azimuth: 10.0\n", + " elevation: -10.0\n", + " near_plane: 0.1\n", + " far_plane: 100.1\n", + "\n" + ] + } + ], + "source": [ + "a = ascent.Ascent()\n", + "a.open()\n", + "\n", + "# publish mesh to ascent\n", + "a.publish(mesh);\n", + "\n", + "# setup actions\n", + "actions = conduit.Node()\n", + "\n", + "# declare a scene to render \n", + "add_act = actions.append()\n", + "add_act[\"action\"] = \"add_scenes\"\n", + "scenes = add_act[\"scenes\"]\n", + "\n", + "# add a scene (s1) with one volume plot (p1) \n", + "scenes[\"s1/plots/p1/type\"] = \"volume\"\n", + "scenes[\"s1/plots/p1/field\"] = \"braid\"\n", + "# change color table\n", + "scenes[\"s1/plots/p1/color_table/name\"] = \"blue\"\n", + "# add color table control points \n", + "control_points = scenes[\"s1/plots/p1/color_table/control_points\"]\n", + "# control point 1\n", + "control_points1 = control_points.append()\n", + "control_points1[\"type\"] = \"rgb\"\n", + "control_points1[\"position\"] = 0.0\n", + "color1 = np.array([1.0,0.0,0.0],dtype=np.float32)\n", + "control_points1[\"color\"].set(color1)\n", + "# control point 2\n", + "control_points2 = control_points.append()\n", + "control_points2[\"type\"] = \"rgb\"\n", + "control_points2[\"position\"] = 0.5\n", + "color2 = np.array([0.0,1.0,0.0],dtype=np.float32)\n", + "control_points2[\"color\"].set(color2)\n", + "# control point 3\n", + "control_points3 = control_points.append()\n", + "control_points3[\"type\"] = \"rgb\"\n", + "control_points3[\"position\"] = 1.0\n", + "color3 = np.array([1.0,1.0,1.0],dtype=np.float32)\n", + "control_points3[\"color\"].set(color3)\n", + "# set alpha control point 1\n", + "control_points4 = control_points.append()\n", + "control_points4[\"type\"] = \"alpha\"\n", + "control_points4[\"position\"] = 0.0\n", + "control_points4[\"alpha\"] = 0.0\n", + "# set alpha control point 2\n", + "control_points5 = control_points.append()\n", + "control_points5[\"type\"] = \"alpha\"\n", + "control_points5[\"position\"] = 1.0\n", + "control_points5[\"alpha\"] = 1.0\n", + "\n", + "# set the output file name -- ignored due to specifying renders\n", + "scenes[\"s1/image_name\"] = \"out_pipeline_color_test\"\n", + "# add renders to specify params\n", + "renders = scenes[\"s1/renders\"]\n", + "# set render 1 (r1) simple\n", + "renders[\"r1/image_width\"] = 512 \n", + "renders[\"r1/image_height\"] = 512 \n", + "renders[\"r1/image_prefix\"] = \"out_extra_renders_r1_simple\"\n", + "# set render 2 (r2) with all camera params\n", + "renders[\"r2/image_width\"] = 400 \n", + "renders[\"r2/image_height\"] = 400 \n", + "renders[\"r2/image_prefix\"] = \"out_extra_renders_r2_cam_params\"\n", + "# set camera params for r2\n", + "r2_camera = renders[\"r2/camera\"]\n", + "look_at = np.array([1.0,1.0,1.0],dtype=np.float64)\n", + "r2_camera[\"look_at\"].set(look_at)\n", + "pos = np.array([0.0,25.0,15.0],dtype=np.float64)\n", + "r2_camera[\"position\"].set(pos)\n", + "up = np.array([0.0,-1.0,0.0],dtype=np.float64)\n", + "r2_camera[\"up\"].set(up)\n", + "r2_camera[\"fov\"] = 60.0\n", + "r2_camera[\"xpan\"] = 0.0\n", + "r2_camera[\"ypan\"] = 0.0\n", + "r2_camera[\"zoom\"] = 1.0\n", + "r2_camera[\"azimuth\"] = 10.0\n", + "r2_camera[\"elevation\"] = -10.0\n", + "r2_camera[\"near_plane\"] = 0.1\n", + "r2_camera[\"far_plane\"] = 100.1\n", + "\n", + "# print our full actions tree\n", + "print(actions.to_yaml())\n", + "\n", + "# execute\n", + "a.execute(actions)" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f9278fe369ba447e9f2cd1b034dee67e", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Tab(children=(VBox(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x02\\x00\\…" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# show the resulting image\n", + "ascent.jupyter.AscentViewer(a).show()" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [], + "source": [ + "# close ascent\n", + "a.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extra Example 3:\n", + "### Apply and render a histrogram-based sampling filter" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "- \n", + " action: \"add_pipelines\"\n", + " pipelines: \n", + " pl1: \n", + " f1: \n", + " type: \"histsampling\"\n", + " params: \n", + " field: \"radial\"\n", + " sample_rate: 0.1\n", + " bins: 32\n", + "- \n", + " action: \"add_scenes\"\n", + " scenes: \n", + " s1: \n", + " plots: \n", + " p1: \n", + " type: \"pseudocolor\"\n", + " pipeline: \"pl1\"\n", + " field: \"braid\"\n", + " image_name: \"out_extra_histsampling\"\n", + "\n" + ] + } + ], + "source": [ + "a = ascent.Ascent()\n", + "a.open()\n", + "\n", + "# publish mesh to ascent\n", + "a.publish(mesh);\n", + "\n", + "# setup actions\n", + "actions = conduit.Node()\n", + "add_act = actions.append()\n", + "add_act[\"action\"] = \"add_pipelines\"\n", + "pipelines = add_act[\"pipelines\"]\n", + "\n", + "# create our first pipeline (pl1) \n", + "# with a histsampling filter (f1)\n", + "pipelines[\"pl1/f1/type\"] = \"histsampling\"\n", + "# sample the braid field values\n", + "# using 32 bins and sample rate of 0.1\n", + "histsamp_params = pipelines[\"pl1/f1/params\"]\n", + "#histsamp_params[\"field\"] = \"braid\"\n", + "histsamp_params[\"field\"] = \"radial\"\n", + "histsamp_params[\"sample_rate\"] = 0.1\n", + "histsamp_params[\"bins\"] = 32\n", + "\n", + "# declare a scene to render our pipeline results\n", + "add_act2 = actions.append()\n", + "add_act2[\"action\"] = \"add_scenes\"\n", + "scenes = add_act2[\"scenes\"]\n", + "\n", + "# plot (p1) to render our first pipeline (pl1)\n", + "scenes[\"s1/plots/p1/type\"] = \"pseudocolor\"\n", + "scenes[\"s1/plots/p1/pipeline\"] = \"pl1\"\n", + "#scenes[\"s1/plots/p1/field\"] = \"radial\"\n", + "scenes[\"s1/plots/p1/field\"] = \"braid\"\n", + "\n", + "# set the output file name (ascent will add \".png\")\n", + "scenes[\"s1/image_name\"] = \"out_extra_histsampling\"\n", + "\n", + "# print our full actions tree\n", + "print(actions.to_yaml())\n", + "\n", + "# execute\n", + "a.execute(actions)" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b69538a4fcc449a0b9b2b9bbaea241dc", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Tab(children=(VBox(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x04\\x00\\…" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# show the resulting image\n", + "ascent.jupyter.AscentViewer(a).show()" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [], + "source": [ + "# close ascent\n", + "a.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extra Example 3:\n", + "### Custom render background and foreground colors" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "- \n", + " action: \"add_scenes\"\n", + " scenes: \n", + " s1: \n", + " plots: \n", + " p1: \n", + " type: \"pseudocolor\"\n", + " field: \"braid\"\n", + " renders: \n", + " r1: \n", + " image_prefix: \"out_extra_bg_fg_color\"\n", + " bg_color: [1.0, 1.0, 1.0]\n", + " fg_color: [0.0, 0.0, 0.0]\n", + "\n" + ] + } + ], + "source": [ + "# Add custom background and foreground colors\n", + "a = ascent.Ascent()\n", + "a.open()\n", + "\n", + "# publish mesh to ascent\n", + "a.publish(mesh);\n", + "\n", + "# setup actions\n", + "actions = conduit.Node()\n", + "\n", + "# add scene\n", + "add_act = actions.append()\n", + "add_act[\"action\"] = \"add_scenes\"\n", + "scenes = add_act[\"scenes\"]\n", + "\n", + "scenes[\"s1/plots/p1/type\"] = \"pseudocolor\"\n", + "#scenes[\"s1/plots/p1/field\"] = \"radial\"\n", + "scenes[\"s1/plots/p1/field\"] = \"braid\"\n", + "# specify background and foreground colors in renders\n", + "renders = scenes[\"s1/renders\"]\n", + "renders[\"r1/image_prefix\"] = \"out_extra_bg_fg_color\"\n", + "# background color\n", + "bg = np.array([1.0,1.0,1.0],dtype=np.float32)\n", + "renders[\"r1/bg_color\"].set(bg)\n", + "# foreground color\n", + "fg = np.array([0.0,0.0,0.0],dtype=np.float32)\n", + "renders[\"r1/fg_color\"].set(fg)\n", + "\n", + "# print our full actions tree\n", + "print(actions.to_yaml())\n", + "\n", + "# execute\n", + "a.execute(actions)" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "dd513d94ea3c4538b48a4c057e057072", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Tab(children=(VBox(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x04\\x00\\…" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# show the resulting image\n", + "ascent.jupyter.AscentViewer(a).show()" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "# close ascent\n", + "a.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extra Example 4:\n", + "### Trigger with no trigger actions file" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "- \n", + " action: \"add_triggers\"\n", + " triggers: \n", + " t1: \n", + " params: \n", + " condition: \"magnitude(max(field('braid')).position - vector(0,0,0)) > 0\"\n", + " actions: \n", + " - \n", + " action: \"add_scenes\"\n", + " scenes: \n", + " s1: \n", + " plots: \n", + " p1: \n", + " type: \"pseudocolor\"\n", + " field: \"braid\"\n", + " image_name: \"out_extra_inplace_trigger\"\n", + "\n" + ] + } + ], + "source": [ + "# Use triggers to render when conditions occur without actions file\n", + "a = ascent.Ascent()\n", + "a.open()\n", + "\n", + "# publish mesh to ascent\n", + "a.publish(mesh);\n", + "\n", + "# set up actions\n", + "actions = conduit.Node()\n", + "\n", + "# declare triggers \n", + "add_triggers = actions.append()\n", + "add_triggers[\"action\"] = \"add_triggers\"\n", + "triggers = add_triggers[\"triggers\"] \n", + "triggers[\"t1/params/condition\"] = \"magnitude(max(field('braid')).position - vector(0,0,0)) > 0\"\n", + "# create in-place trigger action\n", + "trigger_actions = triggers[\"t1/params/actions\"].append()\n", + "# plot when trigger fires\n", + "trigger_actions[\"action\"] = \"add_scenes\"\n", + "scenes = trigger_actions[\"scenes\"]\n", + "scenes[\"s1/plots/p1/type\"] = \"pseudocolor\"\n", + "#scenes[\"s1/plots/p1/field\"] = \"radial\"\n", + "scenes[\"s1/plots/p1/field\"] = \"braid\"\n", + "\n", + "# set the output file name (ascent will add \".png\")\n", + "scenes[\"s1/image_name\"] = \"out_extra_inplace_trigger\"\n", + "\n", + "# print our full actions tree\n", + "print(actions.to_yaml())\n", + "\n", + "# execute\n", + "a.execute(actions)" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "98fa2df99106416d89fb58bc6d021d4b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Tab(children=(HTML(value='
\\nmagnitude(max(field(\\'braid\\')).position - vector(0,0,0)) > 0:…"
+      ]
+     },
+     "execution_count": 89,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# show the resulting trigger info\n",
+    "ascent.jupyter.AscentViewer(a).show()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 54,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# close ascent\n",
+    "a.close()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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.9.13"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}