你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
Updated to accept optional argument of fields to plot, e.g. Ez Hx Hy
这个提交包含在:
@@ -21,11 +21,17 @@ import h5py
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
from gprMax.exceptions import CmdInputError
|
||||||
|
|
||||||
"""Plots electric and magnetic fields from all receiver points in the given output file. Each receiver point is plotted in a new figure window."""
|
"""Plots electric and magnetic fields from all receiver points in the given output file. Each receiver point is plotted in a new figure window."""
|
||||||
|
|
||||||
|
# Fields that can be plotted
|
||||||
|
fieldslist = ['Ex', 'Ey', 'Ez', 'Hx', 'Hy', 'Hz']
|
||||||
|
|
||||||
# Parse command line arguments
|
# 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 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')
|
parser.add_argument('outputfile', help='name of output file including path')
|
||||||
|
parser.add_argument('--fields', help="list of fields to be plotted, i.e. ['Ex', 'Ey', 'Ez']", default=fieldslist, nargs='+')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
file = args.outputfile
|
file = args.outputfile
|
||||||
@@ -34,27 +40,49 @@ nrx = f.attrs['nrx']
|
|||||||
time = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt'])
|
time = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt'])
|
||||||
time = time / 1e-9
|
time = time / 1e-9
|
||||||
|
|
||||||
|
# Check for valid field names
|
||||||
|
for field in args.fields:
|
||||||
|
if field not in fieldslist:
|
||||||
|
raise CmdInputError('{} not allowed. Options are: Ex, Ey, Ez, Hx, Hy, Hz'.format(field))
|
||||||
|
|
||||||
for rx in range(1, nrx + 1):
|
for rx in range(1, nrx + 1):
|
||||||
path = '/rxs/rx' + str(rx) + '/'
|
path = '/rxs/rx' + str(rx) + '/'
|
||||||
Ex = f[path + 'Ex'][:]
|
|
||||||
Ey = f[path + 'Ey'][:]
|
|
||||||
Ez = f[path + 'Ez'][:]
|
|
||||||
Hx = f[path + 'Hx'][:]
|
|
||||||
Hy = f[path + 'Hy'][:]
|
|
||||||
Hz = f[path + 'Hz'][:]
|
|
||||||
|
|
||||||
|
# If only a single field is required, create one subplot
|
||||||
|
if len(args.fields) == 1:
|
||||||
|
fielddata = f[path + args.fields[0]][:]
|
||||||
|
if 'E' in args.fields[0]:
|
||||||
|
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Time [ns]', ylabel=args.fields[0] + ', field strength [V/m]'), num='rx' + str(rx), figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||||
|
ax.plot(time, fielddata,'r', lw=2, label=args.fields[0])
|
||||||
|
ax.grid()
|
||||||
|
elif 'H' in args.fields[0]:
|
||||||
|
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Time [ns]', ylabel=args.fields[0] + ', field strength [A/m]'), num='rx' + str(rx), figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||||
|
ax.plot(time, fielddata,'b', lw=2, label=args.fields[0])
|
||||||
|
ax.grid()
|
||||||
|
|
||||||
|
# If multiple fields are required, created all six subplots and populate only the specified ones
|
||||||
|
else:
|
||||||
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')
|
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')
|
for field in args.fields:
|
||||||
ax3.plot(time, Ey,'r', lw=2, label='Ey')
|
fielddata = f[path + field][:]
|
||||||
ax5.plot(time, Ez,'r', lw=2, label='Ez')
|
if field == 'Ex':
|
||||||
ax2.plot(time, Hx,'b', lw=2, label='Hx')
|
ax1.plot(time, fielddata,'r', lw=2, label=field)
|
||||||
ax4.plot(time, Hy,'b', lw=2, label='Hy')
|
ax1.set_ylabel('$E_x$, field strength [V/m]')
|
||||||
ax6.plot(time, Hz,'b', lw=2, label='Hz')
|
elif field == 'Ey':
|
||||||
|
ax3.plot(time, fielddata,'r', lw=2, label=field)
|
||||||
# Set ylabels
|
ax3.set_ylabel('$E_y$, field strength [V/m]')
|
||||||
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]']
|
elif field == 'Ez':
|
||||||
[ax.set_ylabel(ylabels[index]) for index, ax in enumerate(fig.axes)]
|
ax5.plot(time, fielddata,'r', lw=2, label=field)
|
||||||
|
ax5.set_ylabel('$E_z$, field strength [V/m]')
|
||||||
|
elif field == 'Hx':
|
||||||
|
ax2.plot(time, fielddata,'b', lw=2, label=field)
|
||||||
|
ax2.set_ylabel('$H_x$, field strength [A/m]')
|
||||||
|
elif field == 'Hy':
|
||||||
|
ax4.plot(time, fielddata,'b', lw=2, label=field)
|
||||||
|
ax4.set_ylabel('$H_y$, field strength [A/m]')
|
||||||
|
elif field == 'Hz':
|
||||||
|
ax6.plot(time, fielddata,'b', lw=2, label=field)
|
||||||
|
ax6.set_ylabel('$H_z$, field strength [A/m]')
|
||||||
# Turn on grid
|
# Turn on grid
|
||||||
[ax.grid() for ax in fig.axes]
|
[ax.grid() for ax in fig.axes]
|
||||||
|
|
||||||
|
在新工单中引用
屏蔽一个用户