aboutsummaryrefslogtreecommitdiff
path: root/Tools/Ascent/ascent_replay_warpx.ipynb
blob: 636e9721c7402bdeb2988670632f426324f8fbbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Replay Data\n",
    "This notebook allows quick playing with Ascent actions on created \"conduit blueprint data\". See Ascent's [Extracts](https://ascent.readthedocs.io/en/latest/Actions/Extracts.html) docs for deeper details on Extracts."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import conduit\n",
    "import conduit.blueprint\n",
    "import conduit.relay\n",
    "import ascent\n",
    "\n",
    "from IPython.display import Image\n",
    "\n",
    "import glob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#print(conduit.about())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# show existing conduit blueprint files\n",
    "sim = \"./\"\n",
    "glob.glob(sim + \"*root\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# VisIt 2.13 or newer, when built with Conduit support, can visualize meshes from these files.\n",
    "# Look at the Blueprint HDF5 extract with VisIt\n",
    "#!visit -o conduit_blueprint.cycle_000400.root"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Prepare Data\n",
    "Initialize Ascent and Load a Blueprint File"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# this step can take a while if the simulation used high resolution\n",
    "data = conduit.Node()\n",
    "conduit.relay.io.blueprint.read_mesh(data, sim + \"conduit_blueprint.cycle_000400.root\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# we publish this data now once to visualize it in multiple ways below\n",
    "a = ascent.Ascent()\n",
    "opts = conduit.Node()\n",
    "opts[\"actions_file\"] = \"\" # work-around: ascent_actions.yaml file must not overwrite our replay action\n",
    "#opts[\"exceptions\"] = \"forward\"\n",
    "a.open(opts)\n",
    "a.publish(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rerender():\n",
    "    \"\"\"This is reads an updated Ascent Action and rerenders the image\"\"\"\n",
    "    actions = conduit.Node()\n",
    "    actions.load(\"replay_actions.yaml\")\n",
    "    a.execute(actions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Relay Example\n",
    "The next two cells are as follows:\n",
    "1. modify the Ascent action (examples: https://ascent.readthedocs.io/en/latest/Actions/Examples.html)\n",
    "2. rerender\n",
    "\n",
    "By only modifying and executing only those two cells one can quickly iterate over new visualizations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%writefile replay_actions.yaml\n",
    "\n",
    "# this block are data pipelines\n",
    "#   each entry in pipelines: executes a series of functions from top to bottom,\n",
    "#   results of prior functions can be used in later calls of the same pipeline\n",
    "-\n",
    "  action: \"add_pipelines\"\n",
    "  pipelines:\n",
    "    slice_field:\n",
    "      f1:\n",
    "        type: \"slice\"\n",
    "        params:\n",
    "          topology: topo\n",
    "          point:  {x: 0.0, y: 0.0, z: 0.0}\n",
    "          normal: {x: 1.0, y: 1.0, z: 0.0}\n",
    "                \n",
    "    sampled_particles:\n",
    "      f1:\n",
    "        type: histsampling\n",
    "        params:\n",
    "          field: particle_electrons_uz\n",
    "          bins: 64\n",
    "          sample_rate: 0.90\n",
    "      f2:\n",
    "        type: \"clip\"\n",
    "        params:\n",
    "          topology: particle_electrons # particle data\n",
    "          multi_plane:\n",
    "            point1:  {x: 0.0, y:  0.0, z: 0.0}\n",
    "            normal1: {x: 1.0, y:  0.0, z: 0.0}\n",
    "            point2:  {x: 0.0, y:  0.0, z: 0.0}\n",
    "            normal2: {x: 0.7, y: -0.7, z: 0.0}\n",
    "\n",
    "    clipped_volume:\n",
    "      f0:\n",
    "        type: \"contour\"\n",
    "        params:\n",
    "          field: \"Ez\"\n",
    "          levels: 10\n",
    "      f1:\n",
    "        type: \"clip\"\n",
    "        params:\n",
    "          topology: topo # name of the amr mesh\n",
    "          multi_plane:\n",
    "            point1:  {x: 0.0, y:  0.0, z: 0.0}\n",
    "            normal1: {x: 1.0, y:  0.0, z: 0.0}\n",
    "            point2:  {x: 0.0, y:  0.0, z: 0.0}\n",
    "            normal2: {x: 0.3, y: -0.3, z: 0.0}\n",
    "\n",
    "    mag_clipped_volume_E:\n",
    "      f0: \n",
    "        type: \"composite_vector\"\n",
    "        params: \n",
    "          field1: \"Ex\"\n",
    "          field2: \"Ey\"\n",
    "          field3: \"Ez\"\n",
    "          output_name: \"E_vec\"\n",
    "      f1: \n",
    "        type: \"vector_magnitude\"\n",
    "        params: \n",
    "          field: \"E_vec\"\n",
    "          output_name: \"E_mag\"\n",
    "      f2:\n",
    "        type: \"contour\"\n",
    "        params:\n",
    "          field: \"E_mag\"\n",
    "          levels: 4\n",
    "      f3:\n",
    "        type: \"clip\"\n",
    "        params:\n",
    "          topology: topo # name of the amr mesh\n",
    "          multi_plane:\n",
    "            point1:  {x: 0.0, y:  0.0, z: 0.0}\n",
    "            normal1: {x: 1.0, y:  0.0, z: 0.0}\n",
    "            point2:  {x: 0.0, y:  0.0, z: 0.0}\n",
    "            normal2: {x: 0.7, y: -0.7, z: 0.0}\n",
    "\n",
    "# A scene is describes the things to be rendered and how\n",
    "#   here one selects either data directly or data that goes into a data pipeline;\n",
    "#   then, the result gets represented with a visualization \"type\" and according\n",
    "#   parameters such as colorbars and color ranges (aka transfer functions)\n",
    "#   reference:    https://ascent.readthedocs.io/en/latest/Actions/Scenes.html\n",
    "#   color tables: https://ascent.readthedocs.io/en/latest/Actions/VTKmColorTables.html\n",
    "-\n",
    "  action: \"add_scenes\"\n",
    "  scenes:\n",
    "    scene1:\n",
    "      plots:\n",
    "#        p0:\n",
    "#          type: \"pseudocolor\"\n",
    "#          field: \"particle_electrons_uz\"\n",
    "#          pipeline: \"sampled_particles\"\n",
    "        p1:\n",
    "          type: \"pseudocolor\"\n",
    "          field: \"Ez\"\n",
    "          pipeline: \"clipped_volume\"\n",
    "#          color_table: \n",
    "#            name: \"plasma\"\n",
    "#            reverse: true\n",
    "#            control_points: \n",
    "#              - \n",
    "#                type: \"alpha\"\n",
    "#                position: 0.0\n",
    "#                alpha: 0.5\n",
    "#              - \n",
    "#                type: \"alpha\"\n",
    "#                position: 1.0\n",
    "#                alpha: 0.5\n",
    "#        p2:\n",
    "#          type: \"pseudocolor\"\n",
    "#          field: \"E_mag\"\n",
    "#          pipeline: \"mag_clipped_volume_E\"\n",
    "#          color_table: \n",
    "#            name: \"Black-Body Radiation\"\n",
    "#            reverse: true\n",
    "        #p3:\n",
    "        #  type: \"pseudocolor\"\n",
    "        #  field: \"Ez\"\n",
    "        #  pipeline: \"slice_field\"\n",
    "        #  min_value: -3.0e11\n",
    "        #  max_value: 3.0e11\n",
    "      renders:\n",
    "        image1:\n",
    "          image_width: 512\n",
    "          image_height: 512\n",
    "          bg_color: [1.0, 1.0, 1.0]\n",
    "          fg_color: [0.0, 0.0, 0.0]\n",
    "          image_prefix: \"./replay_%06d\"\n",
    "          camera:\n",
    "            azimuth: -70\n",
    "            elevation: 30\n",
    "            zoom: 1.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "rerender()\n",
    "ascent.jupyter.AscentViewer(a).show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!ls *png"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Image(filename=\"lwfa_Ex_e-uz_000400.png\")\n",
    "# print(conduit.about())"
   ]
  }
 ],
 "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.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}