From cae1e79ad5caacbc69298f1f39d03a227da94f2b Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 6 Sep 2019 18:21:15 -0700 Subject: add parallel plotfile --- Tools/plot_parallel.py | 250 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 Tools/plot_parallel.py (limited to 'Tools/plot_parallel.py') diff --git a/Tools/plot_parallel.py b/Tools/plot_parallel.py new file mode 100644 index 000000000..db8ac0aed --- /dev/null +++ b/Tools/plot_parallel.py @@ -0,0 +1,250 @@ +import os, glob, matplotlib, sys, argparse +import yt ; yt.funcs.mylog.setLevel(50) +import numpy as np +import matplotlib.pyplot as plt +import scipy.constants as scc + +''' +This script loops over all WarpX plotfiles in a directory and, for each +plotfile, saves an image showing the field and particles. + +It can be run serial: +> python plot_parallel.py --path +or parallel +> mpirun -np 32 python plot_parallel.py --path --parallel +When running parallel, the plotfiles are distributed as evenly as possible +between MPI ranks. + +This script also proposes an option to plot one quantity over all timesteps. +The data of all plotfiles are gathered to rank 0, and the quantity evolution +is plotted and saved to file. For the illustration, this quantity is the max +of Ey. Use " --plot_Ey_max_evolution " to activate this option. + +To get help, run +> python plot_parallel --help +''' + +# Parse command line for options. +parser = argparse.ArgumentParser() +parser.add_argument('--path', dest='path', default='.', + help='path to plotfiles. Plotfiles names must be plt?????') +parser.add_argument('--plotlib', dest='plotlib', default='yt', + choices=['yt','matplotlib'], + help='Plotting library to use') +parser.add_argument('--field', dest='field', default='Ez', + help='Which field to plot, e.g., Ez, By, jx or rho. The central slice in y is plotted') +parser.add_argument('--pjump', dest='pjump', default=20, + help='When plotlib=matplotlib, we plot every pjump particle') +parser.add_argument('--use_vmax', dest='use_vmax', default=False, + help='Whether to put bounds to field colormap') +parser.add_argument('--vmax', dest='vmax', default=1.e12, + help='If use_vmax=True, the colormab will have bounds [-vamx, vmax]') +parser.add_argument('--slicewidth', dest='slicewidth', default=10.e-6, + help='Only particles with -slicewidth/2 Date: Fri, 6 Sep 2019 18:25:36 -0700 Subject: add cori submission script for postprocessing --- Tools/cori_postproc_script.sh | 15 +++++++++++++++ Tools/plot_parallel.py | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 Tools/cori_postproc_script.sh (limited to 'Tools/plot_parallel.py') diff --git a/Tools/cori_postproc_script.sh b/Tools/cori_postproc_script.sh new file mode 100644 index 000000000..0b1b82ca9 --- /dev/null +++ b/Tools/cori_postproc_script.sh @@ -0,0 +1,15 @@ +#!/bin/bash +#SBATCH --job-name=postproc +#SBATCH --time=00:20:00 +#SBATCH -C haswell +#SBATCH -N 8 +#SBATCH -q regular +#SBATCH -e postproce.txt +#SBATCH -o postproco.txt +#SBATCH --mail-type=end +#SBATCH --account=m2852 + +export OMP_NUM_THREADS=1 + +# Requires python3 and yt > 3.5 +srun -n 32 -c 16 python plot_parallel.py --path --plotlib=yt --parallel=True diff --git a/Tools/plot_parallel.py b/Tools/plot_parallel.py index db8ac0aed..e72600251 100644 --- a/Tools/plot_parallel.py +++ b/Tools/plot_parallel.py @@ -8,6 +8,8 @@ import scipy.constants as scc This script loops over all WarpX plotfiles in a directory and, for each plotfile, saves an image showing the field and particles. +Requires yt>3.5 and Python3 + It can be run serial: > python plot_parallel.py --path or parallel -- cgit v1.2.3 From cebe35838e5b55ee0918a825e1414a45cda69242 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 13 Sep 2019 12:24:32 -0700 Subject: remove EOL whitespaces (Thanks Axel) --- Tools/plot_parallel.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Tools/plot_parallel.py') diff --git a/Tools/plot_parallel.py b/Tools/plot_parallel.py index e72600251..2041e7935 100644 --- a/Tools/plot_parallel.py +++ b/Tools/plot_parallel.py @@ -30,7 +30,7 @@ To get help, run parser = argparse.ArgumentParser() parser.add_argument('--path', dest='path', default='.', help='path to plotfiles. Plotfiles names must be plt?????') -parser.add_argument('--plotlib', dest='plotlib', default='yt', +parser.add_argument('--plotlib', dest='plotlib', default='yt', choices=['yt','matplotlib'], help='Plotting library to use') parser.add_argument('--field', dest='field', default='Ez', @@ -71,7 +71,7 @@ def get_species(a_file_list): for filename in a_file_list: ds = yt.load( filename ) # get list of species in current plotfile - pslist_plotfile = list( set( [x[0] for x in ds.field_list + pslist_plotfile = list( set( [x[0] for x in ds.field_list if x[1][:9]=='particle_'] ) ) # append species in current plotfile to pslist, and uniquify pslist = list( set( pslist + pslist_plotfile ) ) @@ -93,9 +93,9 @@ def plot_snapshot(filename): F = all_data_level_0['boxlib', args.field].v.squeeze() if dim == 3: F = F[:,int(F.shape[1]+.5)//2,:] - extent = [ds.domain_left_edge[dim-1], ds.domain_right_edge[dim-1], + extent = [ds.domain_left_edge[dim-1], ds.domain_right_edge[dim-1], ds.domain_left_edge[0], ds.domain_right_edge[0]] - # Plot field quantities with matplotlib + # Plot field quantities with matplotlib plt.imshow(F, aspect='auto', extent=extent, origin='lower') plt.colorbar() plt.xlim(ds.domain_left_edge[dim-1], ds.domain_right_edge[dim-1]) @@ -103,7 +103,7 @@ def plot_snapshot(filename): if args.use_vmax: plt.clim(-args.vmax, args.vmax) if plotlib == 'yt': - # Directly plot with yt + # Directly plot with yt sl = yt.SlicePlot(ds, yt_slicedir[dim], args.field, aspect=yt_aspect[dim]) # Plot particle quantities @@ -128,7 +128,7 @@ def plot_snapshot(filename): plt.scatter(zp,xp,c=pscolor[ispecies],s=pssize, linewidth=pssize,marker=',') if plotlib == 'yt': # Directly plot particles with yt - sl.annotate_particles(width=(args.slicewidth, 'm'), p_size=pssize, + sl.annotate_particles(width=(args.slicewidth, 'm'), p_size=pssize, ptype=pspecies, col=pscolor[ispecies]) # Add labels to plot and save iteration = int(filename[-5:]) @@ -200,8 +200,8 @@ if args.parallel: print('list of species: ', pslist) if plot_Ey_max_evolution: my_zwin = np.zeros( max_buf_size ) - my_maxF = np.zeros( max_buf_size ) - # Loop over files and + my_maxF = np.zeros( max_buf_size ) + # Loop over files and # - plot field snapshot # - store window position and field max in arrays for count, filename in enumerate(my_list): @@ -240,10 +240,10 @@ else: if plot_Ey_max_evolution: zwin_arr = np.zeros( nfiles ) maxF_arr = np.zeros( nfiles ) - # Loop over files and + # Loop over files and # - plot field snapshot # - store window position and field max in arrays - for count, filename in enumerate(file_list): + for count, filename in enumerate(file_list): plot_snapshot( filename ) if plot_Ey_max_evolution: zwin_arr[count], maxF_arr[count] = get_field_max( filename, 'Ey' ) -- cgit v1.2.3