{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "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, "deletable": true, "editable": true }, "outputs": [], "source": [ "# General imports\n", "import glob, sys\n", "# Import numpy and matplotlib\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib\n", "# Import yt\n", "import yt\n", "yt.funcs.mylog.setLevel(50) # Deactivate yt verbose\n", "\n", "# Import interactive notebook feature\n", "#from IPython.display import clear_output\n", "from ipywidgets import interact, IntSlider, RadioButtons\n", "\n", "# Find output iterations\n", "file_list = glob.glob('plt?????')\n", "iterations = [ int(file_name[3:]) for file_name in file_list ]" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Functions to extract and plot the fields" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def extra_data( field, iteration ):\n", " \"\"\"\n", " Extract the 3D array that corresponds to `field` at the \n", " requested iteration, and returns as a `YTarray`, which \n", " can be used exactly like a numpy array.\n", " \"\"\"\n", " ds = yt.load( './plt%05d/' %iteration )\n", " data = ds.covering_grid(level=0, \n", " left_edge=ds.domain_left_edge, \n", " dims=ds.domain_dimensions)\n", " return( data[field] ) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "def plot_field( iteration, field, slicing_direction='y' ):\n", " # Get the data\n", " field_array = extra_data( field, iteration )\n", " \n", " # Get the position of the edges\n", " ds = yt.load( './plt%05d/' %iteration )\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 = field_array[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 = field_array[:, 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 = field_array[:, :, n]\n", " extent = [ left_edge[1], right_edge[1], left_edge[0], right_edge[0] ]\n", " plt.clf()\n", " plt.imshow( data2d, interpolation='nearest', cmap='viridis',\n", " origin='lower', extent=extent )\n", " plt.colorbar()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Interactive viewer" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "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') )" ] } ], "metadata": { "anaconda-cloud": {}, "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.0" }, "widgets": { "state": { "5ca3ffc563434f7487da7b1bd657761b": { "views": [ { "cell_index": 5 } ] } }, "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 1 }