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
|
{
"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
}
|