Simplified and added option to invert plotted outputs.

这个提交包含在:
Craig Warren
2016-01-27 16:08:42 +00:00
父节点 f1063856a2
当前提交 0d26cb56ff

查看文件

@@ -19,7 +19,6 @@
import sys, os, argparse import sys, os, argparse
import h5py import h5py
import numpy as np import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from gprMax.exceptions import CmdInputError from gprMax.exceptions import CmdInputError
@@ -38,16 +37,24 @@ f = h5py.File(args.modelfile, 'r')
path = '/rxs/rx1/' path = '/rxs/rx1/'
availablecomponents = list(f[path].keys()) availablecomponents = list(f[path].keys())
# Check if requested output is in file # Check for polarity of output and if requested output is in file
if args.output[0][0] == 'm':
polarity = -1
args.outputs[0] = args.output[0][1:]
else:
polarity = 1
if args.output[0] not in availablecomponents: if args.output[0] not in availablecomponents:
raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(args.output[0], ', '.join(availablecomponents))) raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(args.output[0], ', '.join(availablecomponents)))
floattype = f[path + args.output[0]].dtype floattype = f[path + args.output[0]].dtype
model = np.zeros((f.attrs['Iterations']), dtype=floattype) iterations = f.attrs['Iterations']
timemodel = np.zeros((f.attrs['Iterations']), dtype=floattype) dt = f.attrs['dt']
timemodel = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt']) / 1e-9 model = np.zeros(iterations, dtype=floattype)
model = f[path + args.output[0]][:] * -1 model = f[path + args.output[0]][:] * polarity
model /= np.amax(np.abs(model)) model /= np.amax(np.abs(model))
timemodel = np.linspace(0, 1, iterations)
timemodel *= (iterations * dt)
f.close() f.close()
# Find location of maximum value from model # Find location of maximum value from model
@@ -65,14 +72,16 @@ difftime = - (timemodel[modelmax] - real[realmax,0])
fig, ax = plt.subplots(num=args.modelfile + ' versus ' + args.realfile, figsize=(20, 10), facecolor='w', edgecolor='w') fig, ax = plt.subplots(num=args.modelfile + ' versus ' + args.realfile, figsize=(20, 10), facecolor='w', edgecolor='w')
ax.plot(timemodel + difftime, model, 'r', lw=2, label='Model') ax.plot(timemodel + difftime, model, 'r', lw=2, label='Model')
ax.plot(real[:,0], real[:,1], 'r', ls='--', lw=2, label='Experiment') ax.plot(real[:,0], real[:,1], 'r', ls='--', lw=2, label='Experiment')
ax.set_xlabel('Time [ns]') ax.set_xlabel('Time [s]')
ax.set_ylabel('Amplitude') ax.set_ylabel('Amplitude')
ax.set_xlim([0, timemodel[-1]]) ax.set_xlim([0, timemodel[-1]])
ax.set_ylim([-1, 1]) ax.set_ylim([-1, 1])
ax.legend() ax.legend()
ax.grid() ax.grid()
# Show/print plots # Save a PDF/PNG of the figure
savename = os.path.abspath(os.path.dirname(args.modelfile)) + os.sep + os.path.splitext(os.path.split(args.modelfile)[1])[0] + '_vs_' + os.path.splitext(os.path.split(args.realfile)[1])[0] savename = os.path.abspath(os.path.dirname(args.modelfile)) + os.sep + os.path.splitext(os.path.split(args.modelfile)[1])[0] + '_vs_' + os.path.splitext(os.path.split(args.realfile)[1])[0]
#fig.savefig(savename + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #fig.savefig(savename + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
#fig.savefig((savename + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
plt.show() plt.show()