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
|
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Overview\n",
"\n",
"This a notebook that inspects the results of a WarpX simulation.\n",
"\n",
"# Instruction\n",
"\n",
"Enter the path of the data you wish to visualize below. Then execute the cells one by one, by selecting them with your mouse and typing `Shift + Enter`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import statements\n",
"import yt ; yt.funcs.mylog.setLevel(50)\n",
"import numpy as np\n",
"import scipy.constants as scc\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read data in the simulation frame"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot data with yt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = yt.load( '../Examples/Modules/RigidInjection/diags/plotfiles/plt00318/' ) # Create a dataset object\n",
"sl = yt.SlicePlot(ds, 2, 'Ex', aspect=.2) # Create a sliceplot object\n",
"sl.annotate_particles(width=(10.e-6, 'm'), p_size=2, ptype='beam', col='black')\n",
"sl.annotate_grids() # Show grids\n",
"sl.show() # Show the plot\n",
"# sl.save('./toto.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Store quantities in numpy arrays, and plot with matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Get field quantities\n",
"all_data_level_0 = ds.covering_grid(level=0,left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)\n",
"Bx = all_data_level_0['boxlib', 'Ex'].v.squeeze()\n",
"Dx = ds.domain_width/ds.domain_dimensions\n",
"extent = [ds.domain_left_edge[ds.dimensionality-1], ds.domain_right_edge[ds.dimensionality-1],\n",
" ds.domain_left_edge[0], ds.domain_right_edge[0] ]\n",
"\n",
"# Get particle quantities\n",
"ad = ds.all_data()\n",
"x = ad['beam', 'particle_position_x'].v\n",
"z = ad['beam', 'particle_position_y'].v\n",
"\n",
"# Plot image\n",
"plt.figure()\n",
"plt.imshow(Bx, extent=extent)\n",
"plt.scatter(z,x,s=.1,c='k')\n",
"\n",
"# Print all available quantities\n",
"ds.field_list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read data back-transformed to the lab frame when the simulation runs in the boosted frame (example: 2D run)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# read_raw_data.py is located in warpx/Tools.\n",
"import os, glob\n",
"import read_raw_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"species = 'beam'\n",
"iteration = 1\n",
"field = 'Ex'\n",
"\n",
"snapshot = './lab_frame_data/' + 'snapshot' + str(iteration).zfill(5)\n",
"header = './lab_frame_data/Header'\n",
"allrd, info = read_raw_data.read_lab_snapshot(snapshot, header) # Read field data\n",
"F = allrd[field]\n",
"print( \"Available info: \", *list(info.keys()) )\n",
"print(\"Available fields: \", info['field_names'])\n",
"nx = info['nx']\n",
"nz = info['nz']\n",
"x = info['x']\n",
"z = info['z']\n",
"xbo = read_raw_data.get_particle_field(snapshot, species, 'x') # Read particle data\n",
"ybo = read_raw_data.get_particle_field(snapshot, species, 'y')\n",
"zbo = read_raw_data.get_particle_field(snapshot, species, 'z')\n",
"uzbo = read_raw_data.get_particle_field(snapshot, species, 'uz')\n",
"\n",
"plt.figure(figsize=(6, 3))\n",
"extent = np.array([info['zmin'], info['zmax'], info['xmin'], info['xmax']])\n",
"plt.imshow(F, aspect='auto', extent=extent, cmap='seismic')\n",
"plt.colorbar()\n",
"plt.plot(zbo, xbo, 'g.', markersize=1.)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read back-transformed data with hdf5 format (example: 3D run)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import h5py\n",
"import matplotlib.pyplot as plt\n",
"f = h5py.File('HDF5_lab_frame_data/snapshot00003', 'r')\n",
"print( list(f.keys()) )\n",
"# plt.figure()\n",
"plt.imshow(f['Ey'][:,,:])"
]
}
],
"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.7.1"
},
"widgets": {
"state": {
"11d243e9f5074fe1b115949d174d59de": {
"views": [
{
"cell_index": 6
}
]
}
},
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
|