Commit f1a87d31 authored by frey_m's avatar frey_m
Browse files

AMR test case: Update Python scripts.

- Add ability to zoom for yt plots
- Make field.py faster (?)

modified:   ippl/test/AMR/amr_plot_tools/field.py
modified:   ippl/test/AMR/amr_plot_tools/tools.py
modified:   ippl/test/AMR/amr_plot_tools/visualize.py
parent c0ad5e53
......@@ -40,9 +40,11 @@ try:
# electric field in horizontal direction
mid = int(0.5 * max(data[:, 2]))
i = np.extract(data[:, 2] == mid, data[:, 0])
j = np.extract(data[:, 2] == mid, data[:, 1])
val = np.extract(data[:, 2] == mid, data[:, 3])
condition = (data[:, 2] == mid)
i = data[condition, 0]
j = data[condition, 1]
val = data[condition, 3]
plt = doGridPlot(i, j, val, "horizontal grid", "vertical grid", r'$E_x$ [V/m]')
plt.savefig(f + '_slice_z_Ex.png')#, bbox_inches='tight')
......@@ -51,7 +53,7 @@ try:
# electric field in vertical direction
val = np.extract(data[:, 2] == mid, data[:, 4])
val = np.extract(condition, data[:, 4])
plt = doGridPlot(i, j, val, "horizontal grid", "vertical grid", r'$E_y$ [V/m]')
plt.savefig(f + '_slice_z_Ey.png')#bbox_inches='tight')
......@@ -60,9 +62,11 @@ try:
# center in z
mid = int(0.5 * max(data[:, 0]))
i = np.extract(data[:, 0] == mid, data[:, 1])
j = np.extract(data[:, 0] == mid, data[:, 2])
val = np.extract(data[:, 0] == mid, data[:, 5])
condition = (data[:, 0] == mid)
i = data[condition, 1]
j = data[condition, 2]
val = data[condition, 5]
plt = doGridPlot(i, j, val, "vertical grid", "longitudinal grid", r'$E_z$ [V/m]')
plt.savefig(f + '_slice_x_Ez.png')# bbox_inches='tight')
......@@ -80,25 +84,33 @@ try:
# center in x
mid = int(0.5 * max(data[:, 0]))
i = np.extract(data[:, 0] == mid, data[:, 1])
j = np.extract(data[:, 0] == mid, data[:, 2])
val = np.extract(data[:, 0] == mid, data[:, 3])
condition = (data[:, 0] == mid)
i = data[condition, 1]
j = data[condition, 2]
val = data[condition, 3]
plt = doGridPlot(i, j, val, "vertical grid", "longitudinal grid", clab)
plt.savefig(f + '_slice_x.png')#, bbox_inches='tight')
# center in y
mid = int(0.5 * max(data[:, 1]))
i = np.extract(data[:, 1] == mid, data[:, 0])
j = np.extract(data[:, 1] == mid, data[:, 2])
val = np.extract(data[:, 1] == mid, data[:, 3])
condition = (data[:, 1] == mid)
i = data[condition, 0]
j = data[condition, 2]
val = data[condition, 3]
plt = doGridPlot(i, j, val, "horizontal grid", "longitudinal grid", clab)
plt.savefig(f + '_slice_y.png')#bbox_inches='tight')
# center in z
mid = int(0.5 * max(data[:, 2]))
i = np.extract(data[:, 2] == mid, data[:, 0])
j = np.extract(data[:, 2] == mid, data[:, 1])
val = np.extract(data[:, 2] == mid, data[:, 3])
condition = (data[:, 2] == mid)
i = data[condition, 0]
j = data[condition, 1]
val = data[condition, 3]
plt = doGridPlot(i, j, val, "horizontal grid", "vertical grid", clab)
plt.savefig(f + '_slice_z.png')# bbox_inches='tight')
......
......@@ -19,13 +19,15 @@ import matplotlib.pyplot as plt
# @param field to plot
# @param unit the data should be converted to (otherwise it
# takes the default given by the data)
# @param zfactor is the zoom factor (default: 1, i.e. no zoom)
# @param col is the color for the time stamp and scale annotation
def doSlicePlot(ds, direct, field, unit, col = 'white'):
def doSlicePlot(ds, direct, field, unit, zfactor = 1, col = 'white'):
slc = yt.SlicePlot(ds, normal=direct, fields=field)
if unit is not None:
slc.set_unit(field, unit)
slc.zoom(zfactor)
slc.annotate_grids()
slc.annotate_timestamp(corner='upper_left', redshift=False, draw_inset_box=True)
slc.annotate_scale(corner='upper_right', size_bar_args={'color':col})
......@@ -37,13 +39,15 @@ def doSlicePlot(ds, direct, field, unit, col = 'white'):
# @param field to plot
# @param unit the data should be converted to (otherwise it
# takes the default given by the data)
# @param zfactor is the zoom factor (default: 1, i.e. no zoom)
# @param col is the color for the time stamp and scale annotation
def doProjectionPlot(ds, direct, field, unit, col = 'white'):
def doProjectionPlot(ds, direct, field, unit, zfactor = 1, col = 'white'):
slc = yt.ProjectionPlot(ds, direct, fields=field)
if unit is not None:
slc.set_unit(field, unit)
slc.zoom(zfactor)
slc.annotate_grids()
slc.annotate_timestamp(corner='upper_left', redshift=False, draw_inset_box=True)
slc.annotate_scale(corner='upper_right', size_bar_args={'color':col})
......
......@@ -4,7 +4,7 @@
# @date 14. October 2016, LBNL
# @version 1.1 (21. Dec. 2016)
#
# @pre Environment variable OPAL_BUILD has to be set.
# @pre Environment variable OPAL_BUILD has to be set. Python >= 2.7
# @details Plot the electric self-field, density and self-field
# potential using the yt framework.
# 1. mpirun -np #cores testSolver
......@@ -13,10 +13,21 @@
import os
import yt
import argparse
from tools import doSlicePlot, doProjectionPlot
try:
parser = argparse.ArgumentParser(description='Visualize BoxLib grid data.')
parser.add_argument('--zoom',
help='zoom factor of images (default: 1)',
default=1,
type=int,
nargs=1)
args = parser.parse_args()
zoom = args.zoom
opal = os.environ['OPAL_BUILD']
ds = yt.load(opal + "ippl/test/AMR/plt0000", dataset_type='opal')
......@@ -26,29 +37,29 @@ try:
print ("Derived field list:", ds.derived_field_list)
doSlicePlot(ds, 'z', 'rho', 'C/m**3', 'gray')
doSlicePlot(ds, 'z', 'rho', 'C/m**3', zoom, 'gray')
doSlicePlot(ds, 'y', 'rho', 'C/m**3', 'gray')
doSlicePlot(ds, 'y', 'rho', 'C/m**3', zoom, 'gray')
doSlicePlot(ds, 'x', 'rho', 'C/m**3', 'gray')
doSlicePlot(ds, 'x', 'rho', 'C/m**3', zoom, 'gray')
doProjectionPlot(ds, 'x', 'rho', 'C/m**2', 'gray')
doProjectionPlot(ds, 'x', 'rho', 'C/m**2', zoom, 'gray')
doProjectionPlot(ds, 'y', 'rho', 'C/m**2', 'gray')
doProjectionPlot(ds, 'y', 'rho', 'C/m**2', zoom, 'gray')
doProjectionPlot(ds, 'z', 'rho', 'C/m**2', 'gray')
doProjectionPlot(ds, 'z', 'rho', 'C/m**2', zoom, 'gray')
doSlicePlot(ds, 'z', 'Ex', 'V/m')
doSlicePlot(ds, 'z', 'Ex', 'V/m', zoom)
doSlicePlot(ds, 'z', 'Ey', 'V/m')
doSlicePlot(ds, 'z', 'Ey', 'V/m', zoom)
doSlicePlot(ds, 'x', 'Ez', 'V/m')
doSlicePlot(ds, 'x', 'Ez', 'V/m', zoom)
doSlicePlot(ds, 'z', 'potential', 'V')
doSlicePlot(ds, 'z', 'potential', 'V', zoom)
doSlicePlot(ds, 'y', 'potential', 'V')
doSlicePlot(ds, 'y', 'potential', 'V', zoom)
doSlicePlot(ds, 'x', 'potential', 'V')
doSlicePlot(ds, 'x', 'potential', 'V', zoom)
ad = ds.all_data()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment