{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Overview\n", "\n", "This a notebook that inspects the results of a WarpX simulation.\n", "\n", "# Instructions\n", "\n", "Execute the cells below one by one, by selecting them with your mouse and typing `Shift + Enter`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Import statements\n", "import sys\n", "from tqdm import tqdm\n", "import yt, glob\n", "yt.funcs.mylog.setLevel(50)\n", "from IPython.display import clear_output\n", "import numpy as np\n", "from ipywidgets import interact, RadioButtons, IntSlider\n", "import matplotlib.pyplot as plt\n", "%matplotlib\n", "\n", "# Find iterations\n", "file_list = glob.glob('plt?????')\n", "iterations = [ int(file_name[3:]) for file_name in file_list ]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Functions to plot the fields" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def plot_field( iteration, field, slicing_direction='y', plotter='matplotlib' ):\n", " ds = yt.load( './plt%05d/' %iteration )\n", " all_data_level_0 = ds.covering_grid(level=0, \n", " left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)\n", " \n", " if plotter == 'yt':\n", " sl = yt.SlicePlot(ds, slicing_direction, field)\n", " sl.set_log( field, False)\n", " sl.annotate_grids()\n", " # Show the new plot\n", " clear_output()\n", " sl.show()\n", "\n", " elif plotter == 'matplotlib':\n", "\n", " left_edge = ds.domain_left_edge.convert_to_mks()*1.e6\n", " right_edge = ds.domain_right_edge.convert_to_mks()*1.e6\n", " \n", " if slicing_direction == 'x':\n", " n = int( ds.domain_dimensions[0]//2 )\n", " data2d = all_data_level_0[field][n, :, :]\n", " extent = [ left_edge[2], right_edge[2], left_edge[1], right_edge[1] ]\n", " elif slicing_direction == 'y':\n", " n = int( ds.domain_dimensions[1]//2 )\n", " data2d = all_data_level_0[field][:, n, :]\n", " extent = [ left_edge[2], right_edge[2], left_edge[0], right_edge[0] ]\n", " elif slicing_direction == 'z':\n", " n = int( ds.domain_dimensions[2]//2 )\n", " data2d = all_data_level_0[field][:, :, n]\n", " extent = [ left_edge[1], right_edge[1], left_edge[0], right_edge[0] ]\n", " plt.clf()\n", " plt.title(\"%s at iteration %d\" %(field, iteration) )\n", " plt.imshow( data2d, interpolation='nearest', cmap='viridis',\n", " origin='lower', extent=extent, aspect='auto' )\n", " plt.colorbar()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Interactive viewer" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "interact(plot_field, \n", " iteration = IntSlider(min=min(iterations), max=max(iterations), step=iterations[1]-iterations[0]),\n", " field = RadioButtons( options=['jx', 'jy', 'jz', 'Ex', 'Ey', 'Ez'], value='jz'),\n", " slicing_direction = RadioButtons( options=[ 'x', 'y', 'z'], value='y'),\n", " plotter = RadioButtons( options=['matplotlib', 'yt'] ) )" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [default]", "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.5.2" } }, "nbformat": 4, "nbformat_minor": 1 }