From bc1b8ed36600b36e85533ef64c51a3283c8ba290 Mon Sep 17 00:00:00 2001 From: craig-warren Date: Wed, 25 Nov 2015 18:00:05 +0000 Subject: [PATCH] Reorganised and changed some of the naming of the tools scripts. --- tests/test_compare_analytical.py | 35 ++++++++++++++---- tests/test_compare_numerical.py | 36 +++++++++++++++---- ...iles_mergehdf5.py => outputfiles_merge.py} | 2 +- tools/{plot_Ascan_hdf5.py => plot_Ascan.py} | 22 ++++++++++-- tools/{plot_Bscan_hdf5.py => plot_Bscan.py} | 2 +- 5 files changed, 79 insertions(+), 18 deletions(-) rename tools/{outputfiles_mergehdf5.py => outputfiles_merge.py} (98%) rename tools/{plot_Ascan_hdf5.py => plot_Ascan.py} (65%) rename tools/{plot_Bscan_hdf5.py => plot_Bscan.py} (96%) diff --git a/tests/test_compare_analytical.py b/tests/test_compare_analytical.py index bdffb94e..7884b766 100644 --- a/tests/test_compare_analytical.py +++ b/tests/test_compare_analytical.py @@ -55,7 +55,20 @@ for ID, name in fields.items(): print('Total differences in field component {}: {:.1f}%'.format(name, diffsum)) # Plot model -fig1, plt1 = plot_Ascan(modelfile + ' versus analytical solution', time, model[:,0], model[:,1], model[:,2], model[:,3], model[:,4], model[:,5]) +fig1, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num=modelfile + ' versus analytical solution', figsize=(20, 10), facecolor='w', edgecolor='w') + ax1.plot(time, model[:,0],'r', lw=2, label='Ex') + ax3.plot(time, model[:,1],'r', lw=2, label='Ey') + ax5.plot(time, model[:,2],'r', lw=2, label='Ez') + ax2.plot(time, model[:,3],'b', lw=2, label='Hx') + ax4.plot(time, model[:,4],'b', lw=2, label='Hy') + ax6.plot(time, model[:,5],'b', lw=2, label='Hz') + +# Set ylabels +ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]', '$E_y$, field strength [V/m]', '$H_y$, field strength [A/m]', '$E_z$, field strength [V/m]', '$H_z$, field strength [A/m]'] +[ax.set_ylabel(ylabels[index]) for index, ax in enumerate(fig1.axes)] + +# Turn on grid +[ax.grid() for ax in fig1.axes] # Add analytical solution and set legend for index, ax in enumerate(fig1.axes): @@ -68,16 +81,26 @@ for index, ax in enumerate(fig1.axes): ax.legend(handles, ['Model', 'Analytical']) # Plots of differences -fig2, plt2 = plot_Ascan('Deltas: ' + modelfile + ' versus analytical solution', time, diffs[:,0], diffs[:,1], diffs[:,2], diffs[:,3], diffs[:,4], diffs[:,5]) -[ax.set_xlim(0, time[-1]) for ax in fig2.axes] -[ax.set_ylim(0, np.ceil(np.amax(np.abs(diffs)))) for ax in fig2.axes] +fig2, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num='Deltas: ' + modelfile + ' versus analytical solution', figsize=(20, 10), facecolor='w', edgecolor='w') + ax1.plot(time, diffs[:,0],'r', lw=2, label='Ex') + ax3.plot(time, diffs[:,1],'r', lw=2, label='Ey') + ax5.plot(time, diffs[:,2],'r', lw=2, label='Ez') + ax2.plot(time, diffs[:,3],'b', lw=2, label='Hx') + ax4.plot(time, diffs[:,4],'b', lw=2, label='Hy') + ax6.plot(time, diffs[:,5],'b', lw=2, label='Hz') + +# Set ylabels ylabels = ['$E_x$', '$H_x$', '$E_y$', '$H_y$', '$E_z$', '$H_z$'] ylabels = [ylabel + ', percentage difference [%]' for ylabel in ylabels] [ax.set_ylabel(ylabels[index]) for index, ax in enumerate(fig2.axes)] +# Set axes limits and turn on grid +[ax.grid() for ax in fig2.axes] +[ax.set_xlim(0, time[-1]) for ax in fig2.axes] +[ax.set_ylim(0, np.ceil(np.amax(np.abs(diffs)))) for ax in fig2.axes] + # Show/print plots savename = os.path.abspath(os.path.dirname(modelfile)) + os.sep + os.path.splitext(os.path.split(modelfile)[1])[0] + '_vs_analytical' #fig1.savefig(savename + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #fig2.savefig(savename + '_diffs.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) -plt1.show() -plt2.show() \ No newline at end of file +plt.show() diff --git a/tests/test_compare_numerical.py b/tests/test_compare_numerical.py index dec37a24..63248f1d 100644 --- a/tests/test_compare_numerical.py +++ b/tests/test_compare_numerical.py @@ -58,7 +58,20 @@ for ID, name in fields.items(): print('Total differences in field component {}: {:.1f}%'.format(name, diffsum)) # Plot new -fig1, plt1 = plot_Ascan(newfile + ' versus ' + oldfile, timenew, new[:,0], new[:,2], new[:,4], new[:,1], new[:,3], new[:,5]) +fig1, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num=newfile + ' versus ' + oldfile, figsize=(20, 10), facecolor='w', edgecolor='w') + ax1.plot(timenew, new[:,0],'r', lw=2, label='Ex') + ax3.plot(timenew, new[:,2],'r', lw=2, label='Ey') + ax5.plot(timenew, new[:,4],'r', lw=2, label='Ez') + ax2.plot(timenew, new[:,1],'b', lw=2, label='Hx') + ax4.plot(timenew, new[:,3],'b', lw=2, label='Hy') + ax6.plot(timenew, new[:,5],'b', lw=2, label='Hz') + +# Set ylabels +ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]', '$E_y$, field strength [V/m]', '$H_y$, field strength [A/m]', '$E_z$, field strength [V/m]', '$H_z$, field strength [A/m]'] +[ax.set_ylabel(ylabels[index]) for index, ax in enumerate(fig1.axes)] + +# Turn on grid +[ax.grid() for ax in fig1.axes] # Add old and set legend for index, ax in enumerate(fig1.axes): @@ -71,18 +84,27 @@ for index, ax in enumerate(fig1.axes): ax.legend(handles, ['Model (new code)', 'Model (old C code)']) # Plots of differences -fig2, plt2 = plot_Ascan('Deltas: ' + newfile + ' versus ' + oldfile, timenew[:timesmallest], diffs[:,0], diffs[:,2], diffs[:,4], diffs[:,1], diffs[:,3], diffs[:,5]) -[ax.set_xlim(0, timenew[timesmallest - 1]) for ax in fig2.axes] -[ax.set_ylim(0, np.ceil(np.amax(np.abs(diffs)))) for ax in fig2.axes] +fig2, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num='Deltas: ' + newfile + ' versus ' + oldfile, figsize=(20, 10), facecolor='w', edgecolor='w') + ax1.plot(timenew[:timesmallest], diffs[:,0],'r', lw=2, label='Ex') + ax3.plot(timenew[:timesmallest], diffs[:,2],'r', lw=2, label='Ey') + ax5.plot(timenew[:timesmallest], diffs[:,4],'r', lw=2, label='Ez') + ax2.plot(timenew[:timesmallest], diffs[:,1],'b', lw=2, label='Hx') + ax4.plot(timenew[:timesmallest], diffs[:,3],'b', lw=2, label='Hy') + ax6.plot(timenew[:timesmallest], diffs[:,5],'b', lw=2, label='Hz') + +# Set ylabels ylabels = ['$E_x$', '$H_x$', '$E_y$', '$H_y$', '$E_z$', '$H_z$'] ylabels = [ylabel + ', percentage difference [%]' for ylabel in ylabels] [ax.set_ylabel(ylabels[index]) for index, ax in enumerate(fig2.axes)] +# Set axes limits and turn on grid +[ax.grid() for ax in fig2.axes] +[ax.set_xlim(0, timenew[timesmallest - 1]) for ax in fig2.axes] +[ax.set_ylim(0, np.ceil(np.amax(np.abs(diffs)))) for ax in fig2.axes] + # Show/print plots savename = os.path.abspath(os.path.dirname(newfile)) + os.sep + os.path.splitext(os.path.split(newfile)[1])[0] + '_vs_' + os.path.splitext(os.path.split(oldfile)[1])[0] #fig1.savefig(savename + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #fig2.savefig(savename + '_diffs.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) -plt1.show() -plt2.show() - +plt.show() diff --git a/tools/outputfiles_mergehdf5.py b/tools/outputfiles_merge.py similarity index 98% rename from tools/outputfiles_mergehdf5.py rename to tools/outputfiles_merge.py index 6634a9d9..1e0363de 100644 --- a/tools/outputfiles_mergehdf5.py +++ b/tools/outputfiles_merge.py @@ -23,7 +23,7 @@ import numpy as np """Merges traces (A-scans) from multiple output files into one new file, then removes the series of output files.""" # Parse command line arguments -parser = argparse.ArgumentParser(description='Merges traces (A-scans) from multiple output files into one new file, then removes the series of output files.', usage='cd gprMax; python -m tools.outputfiles_mergehdf5 basefilename modelruns') +parser = argparse.ArgumentParser(description='Merges traces (A-scans) from multiple output files into one new file, then removes the series of output files.', usage='cd gprMax; python -m tools.outputfiles_merge basefilename modelruns') parser.add_argument('basefilename', help='base name of output file series including path') parser.add_argument('modelruns', type=int, help='number of model runs, i.e. number of output files to merge') args = parser.parse_args() diff --git a/tools/plot_Ascan_hdf5.py b/tools/plot_Ascan.py similarity index 65% rename from tools/plot_Ascan_hdf5.py rename to tools/plot_Ascan.py index b00cea74..434b4b33 100644 --- a/tools/plot_Ascan_hdf5.py +++ b/tools/plot_Ascan.py @@ -19,12 +19,12 @@ import os, argparse import h5py import numpy as np -from .plot_fields import plot_Ascan +import matplotlib.pyplot as plt """Plots electric and magnetic fields from all receiver points in the given output file. Each receiver point is plotted in a new figure window.""" # Parse command line arguments -parser = argparse.ArgumentParser(description='Plots electric and magnetic fields from all receiver points in the given output file. Each receiver point is plotted in a new figure window.', usage='cd gprMax; python -m tools.plot_Ascan_hdf5 outputfile') +parser = argparse.ArgumentParser(description='Plots electric and magnetic fields from all receiver points in the given output file. Each receiver point is plotted in a new figure window.', usage='cd gprMax; python -m tools.plot_Ascan outputfile') parser.add_argument('outputfile', help='name of output file including path') args = parser.parse_args() @@ -42,7 +42,23 @@ for rx in range(1, nrx + 1): Hx = f[path + 'Hx'][:] Hy = f[path + 'Hy'][:] Hz = f[path + 'Hz'][:] - fig, plt = plot_Ascan('rx' + str(rx), time, Ex, Ey, Ez, Hx, Hy, Hz) + + fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num='rx' + str(rx), figsize=(20, 10), facecolor='w', edgecolor='w') + ax1.plot(time, Ex,'r', lw=2, label='Ex') + ax3.plot(time, Ey,'r', lw=2, label='Ey') + ax5.plot(time, Ez,'r', lw=2, label='Ez') + ax2.plot(time, Hx,'b', lw=2, label='Hx') + ax4.plot(time, Hy,'b', lw=2, label='Hy') + ax6.plot(time, Hz,'b', lw=2, label='Hz') + + # Set ylabels + ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]', '$E_y$, field strength [V/m]', '$H_y$, field strength [A/m]', '$E_z$, field strength [V/m]', '$H_z$, field strength [A/m]'] + [ax.set_ylabel(ylabels[index]) for index, ax in enumerate(fig.axes)] + + # Turn on grid + [ax.grid() for ax in fig.axes] + + # Save a PDF of the figure #fig.savefig(os.path.splitext(os.path.abspath(file))[0] + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) plt.show() diff --git a/tools/plot_Bscan_hdf5.py b/tools/plot_Bscan.py similarity index 96% rename from tools/plot_Bscan_hdf5.py rename to tools/plot_Bscan.py index b4ac45d4..cb0dd424 100644 --- a/tools/plot_Bscan_hdf5.py +++ b/tools/plot_Bscan.py @@ -26,7 +26,7 @@ from gprMax.exceptions import CmdInputError """Plots B-scan.""" # Parse command line arguments -parser = argparse.ArgumentParser(description='Plots B-scan.', usage='cd gprMax; python -m tools.plot_Bscan_hdf5 outputfile field') +parser = argparse.ArgumentParser(description='Plots B-scan.', usage='cd gprMax; python -m tools.plot_Bscan outputfile field') parser.add_argument('outputfile', help='name of output file including path') parser.add_argument('field', help='name of field to be plotted, i.e. Ex, Ey, Ez') args = parser.parse_args()