你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
Added a pre-commit config file and reformatted all the files accordingly by using it.
这个提交包含在:
@@ -26,80 +26,85 @@ import numpy as np
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
"""Plots a comparison of fields between given simulation output and experimental
|
||||
"""Plots a comparison of fields between given simulation output and experimental
|
||||
data files.
|
||||
"""
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Plots a comparison of fields between ' +
|
||||
'given simulation output and experimental data files.',
|
||||
usage='cd gprMax; python -m testing.test_experimental modelfile realfile output')
|
||||
parser.add_argument('modelfile', help='name of model output file including path')
|
||||
parser.add_argument('realfile', help='name of file containing experimental data including path')
|
||||
parser.add_argument('output', help='output to be plotted, i.e. Ex Ey Ez', nargs='+')
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Plots a comparison of fields between " + "given simulation output and experimental data files.",
|
||||
usage="cd gprMax; python -m testing.test_experimental modelfile realfile output",
|
||||
)
|
||||
parser.add_argument("modelfile", help="name of model output file including path")
|
||||
parser.add_argument("realfile", help="name of file containing experimental data including path")
|
||||
parser.add_argument("output", help="output to be plotted, i.e. Ex Ey Ez", nargs="+")
|
||||
args = parser.parse_args()
|
||||
|
||||
modelfile = Path(args.modelfile)
|
||||
realfile = Path(args.realfile)
|
||||
|
||||
# Model results
|
||||
f = h5py.File(Path(modelfile), 'r')
|
||||
path = '/rxs/rx1/'
|
||||
f = h5py.File(Path(modelfile), "r")
|
||||
path = "/rxs/rx1/"
|
||||
availablecomponents = list(f[path].keys())
|
||||
|
||||
# Check for polarity of output and if requested output is in file
|
||||
if args.output[0][0] == 'm':
|
||||
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:
|
||||
logger.exception(f"{args.output[0]} output requested to plot, but the " +
|
||||
f"available output for receiver 1 is {', '.join(availablecomponents)}")
|
||||
logger.exception(
|
||||
f"{args.output[0]} output requested to plot, but the "
|
||||
+ f"available output for receiver 1 is {', '.join(availablecomponents)}"
|
||||
)
|
||||
raise ValueError
|
||||
|
||||
floattype = f[path + args.output[0]].dtype
|
||||
iterations = f.attrs['Iterations']
|
||||
dt = f.attrs['dt']
|
||||
iterations = f.attrs["Iterations"]
|
||||
dt = f.attrs["dt"]
|
||||
model = np.zeros(iterations, dtype=floattype)
|
||||
model = f[path + args.output[0]][:] * polarity
|
||||
model /= np.amax(np.abs(model))
|
||||
timemodel = np.linspace(0, 1, iterations)
|
||||
timemodel *= (iterations * dt)
|
||||
timemodel *= iterations * dt
|
||||
f.close()
|
||||
|
||||
# Find location of maximum value from model
|
||||
modelmax = np.where(np.abs(model) == 1)[0][0]
|
||||
|
||||
# Real results
|
||||
with open(realfile, 'r') as f:
|
||||
with open(realfile, "r") as f:
|
||||
real = np.loadtxt(f)
|
||||
real[:, 1] = real[:, 1] / np.amax(np.abs(real[:, 1]))
|
||||
realmax = np.where(np.abs(real[:, 1]) == 1)[0][0]
|
||||
|
||||
difftime = - (timemodel[modelmax] - real[realmax, 0])
|
||||
difftime = -(timemodel[modelmax] - real[realmax, 0])
|
||||
|
||||
# Plot modelled and real data
|
||||
fig, ax = plt.subplots(num=f'{modelfile.stem}_vs_{realfile.stem}',
|
||||
figsize=(20, 10),
|
||||
facecolor='w',
|
||||
edgecolor='w',)
|
||||
ax.plot(timemodel + difftime, model, 'r', lw=2, label='Model')
|
||||
ax.plot(real[:, 0], real[:, 1], 'r', ls='--', lw=2, label='Experiment')
|
||||
ax.set_xlabel('Time [s]')
|
||||
ax.set_ylabel('Amplitude')
|
||||
fig, ax = plt.subplots(
|
||||
num=f"{modelfile.stem}_vs_{realfile.stem}",
|
||||
figsize=(20, 10),
|
||||
facecolor="w",
|
||||
edgecolor="w",
|
||||
)
|
||||
ax.plot(timemodel + difftime, model, "r", lw=2, label="Model")
|
||||
ax.plot(real[:, 0], real[:, 1], "r", ls="--", lw=2, label="Experiment")
|
||||
ax.set_xlabel("Time [s]")
|
||||
ax.set_ylabel("Amplitude")
|
||||
ax.set_xlim([0, timemodel[-1]])
|
||||
# ax.set_ylim([-1, 1])
|
||||
ax.legend()
|
||||
ax.grid()
|
||||
|
||||
# Save a PDF/PNG of the figure
|
||||
savename = f'{modelfile.stem}_vs_{realfile.stem}'
|
||||
savename = f"{modelfile.stem}_vs_{realfile.stem}"
|
||||
savename = modelfile.parent / savename
|
||||
# fig.savefig(savename.with_suffix('.pdf'), dpi=None, format='pdf',
|
||||
# fig.savefig(savename.with_suffix('.pdf'), dpi=None, format='pdf',
|
||||
# bbox_inches='tight', pad_inches=0.1)
|
||||
# fig.savefig(savename.with_suffix('.png'), dpi=150, format='png',
|
||||
# fig.savefig(savename.with_suffix('.png'), dpi=150, format='png',
|
||||
# bbox_inches='tight', pad_inches=0.1)
|
||||
|
||||
plt.show()
|
||||
|
在新工单中引用
屏蔽一个用户