你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 15:27:57 +08:00
More docstring cleaning.
这个提交包含在:
@@ -24,8 +24,7 @@ import gprMax
|
||||
import h5py
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from colorama import Fore, Style, init
|
||||
init()
|
||||
|
||||
from tests.analytical_solutions import hertzian_dipole_fs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -50,7 +49,9 @@ basepath = Path(__file__).parents[0] / modelset
|
||||
|
||||
|
||||
# List of available basic test models
|
||||
testmodels = ['hertzian_dipole_fs_analytical', '2D_ExHyHz', '2D_EyHxHz', '2D_EzHxHy', 'cylinder_Ascan_2D', 'hertzian_dipole_fs', 'hertzian_dipole_hs', 'hertzian_dipole_dispersive', 'magnetic_dipole_fs']
|
||||
testmodels = ['hertzian_dipole_fs_analytical', '2D_ExHyHz', '2D_EyHxHz', '2D_EzHxHy',
|
||||
'cylinder_Ascan_2D', 'hertzian_dipole_fs', 'hertzian_dipole_hs',
|
||||
'hertzian_dipole_dispersive', 'magnetic_dipole_fs']
|
||||
|
||||
# List of available advanced test models
|
||||
# testmodels = ['antenna_GSSI_1500_fs', 'antenna_MALA_1200_fs']
|
||||
@@ -86,11 +87,13 @@ for i, model in enumerate(testmodels):
|
||||
|
||||
# Arrays for storing time
|
||||
float_or_double = filetest[path + outputstest[0]].dtype
|
||||
timetest = np.linspace(0, (filetest.attrs['Iterations'] - 1) * filetest.attrs['dt'], num=filetest.attrs['Iterations']) / 1e-9
|
||||
timetest = np.linspace(0, (filetest.attrs['Iterations'] - 1) * filetest.attrs['dt'],
|
||||
num=filetest.attrs['Iterations']) / 1e-9
|
||||
timeref = timetest
|
||||
|
||||
# Arrays for storing field data
|
||||
datatest = np.zeros((filetest.attrs['Iterations'], len(outputstest)), dtype=float_or_double)
|
||||
datatest = np.zeros((filetest.attrs['Iterations'], len(outputstest)),
|
||||
dtype=float_or_double)
|
||||
for ID, name in enumerate(outputstest):
|
||||
datatest[:, ID] = filetest[path + str(name)][:]
|
||||
if np.any(np.isnan(datatest[:, ID])):
|
||||
@@ -100,10 +103,14 @@ for i, model in enumerate(testmodels):
|
||||
# Tx/Rx position to feed to analytical solution
|
||||
rxpos = filetest[path].attrs['Position']
|
||||
txpos = filetest['/srcs/src1/'].attrs['Position']
|
||||
rxposrelative = ((rxpos[0] - txpos[0]), (rxpos[1] - txpos[1]), (rxpos[2] - txpos[2]))
|
||||
rxposrelative = ((rxpos[0] - txpos[0]),
|
||||
(rxpos[1] - txpos[1]),
|
||||
(rxpos[2] - txpos[2]))
|
||||
|
||||
# Analytical solution of a dipole in free space
|
||||
dataref = hertzian_dipole_fs(filetest.attrs['Iterations'], filetest.attrs['dt'], filetest.attrs['dx_dy_dz'], rxposrelative)
|
||||
dataref = hertzian_dipole_fs(filetest.attrs['Iterations'],
|
||||
filetest.attrs['dt'],
|
||||
filetest.attrs['dx_dy_dz'], rxposrelative)
|
||||
|
||||
filetest.close()
|
||||
|
||||
@@ -125,19 +132,25 @@ for i, model in enumerate(testmodels):
|
||||
|
||||
# Check that type of float used to store fields matches
|
||||
if filetest[path + outputstest[0]].dtype != fileref[path + outputsref[0]].dtype:
|
||||
print(Fore.RED + f'WARNING: Type of floating point number in test model ({filetest[path + outputstest[0]].dtype}) does not match type in reference solution ({fileref[path + outputsref[0]].dtype})\n' + Style.RESET_ALL)
|
||||
logger.warning(f'Type of floating point number in test model ' +
|
||||
f'({filetest[path + outputstest[0]].dtype}) does not ' +
|
||||
f'match type in reference solution ({fileref[path + outputsref[0]].dtype})\n')
|
||||
float_or_doubleref = fileref[path + outputsref[0]].dtype
|
||||
float_or_doubletest = filetest[path + outputstest[0]].dtype
|
||||
|
||||
# Arrays for storing time
|
||||
timeref = np.zeros((fileref.attrs['Iterations']), dtype=float_or_doubleref)
|
||||
timeref = np.linspace(0, (fileref.attrs['Iterations'] - 1) * fileref.attrs['dt'], num=fileref.attrs['Iterations']) / 1e-9
|
||||
timeref = np.linspace(0, (fileref.attrs['Iterations'] - 1) * fileref.attrs['dt'],
|
||||
num=fileref.attrs['Iterations']) / 1e-9
|
||||
timetest = np.zeros((filetest.attrs['Iterations']), dtype=float_or_doubletest)
|
||||
timetest = np.linspace(0, (filetest.attrs['Iterations'] - 1) * filetest.attrs['dt'], num=filetest.attrs['Iterations']) / 1e-9
|
||||
timetest = np.linspace(0, (filetest.attrs['Iterations'] - 1) * filetest.attrs['dt'],
|
||||
num=filetest.attrs['Iterations']) / 1e-9
|
||||
|
||||
# Arrays for storing field data
|
||||
dataref = np.zeros((fileref.attrs['Iterations'], len(outputsref)), dtype=float_or_doubleref)
|
||||
datatest = np.zeros((filetest.attrs['Iterations'], len(outputstest)), dtype=float_or_doubletest)
|
||||
dataref = np.zeros((fileref.attrs['Iterations'], len(outputsref)),
|
||||
dtype=float_or_doubleref)
|
||||
datatest = np.zeros((filetest.attrs['Iterations'], len(outputstest)),
|
||||
dtype=float_or_doubletest)
|
||||
for ID, name in enumerate(outputsref):
|
||||
dataref[:, ID] = fileref[path + str(name)][:]
|
||||
datatest[:, ID] = filetest[path + str(name)][:]
|
||||
@@ -152,7 +165,9 @@ for i, model in enumerate(testmodels):
|
||||
datadiffs = np.zeros(datatest.shape, dtype=np.float64)
|
||||
for i in range(len(outputstest)):
|
||||
max = np.amax(np.abs(dataref[:, i]))
|
||||
datadiffs[:, i] = np.divide(np.abs(dataref[:, i] - datatest[:, i]), max, out=np.zeros_like(dataref[:, i]), where=max != 0) # Replace any division by zero with zero
|
||||
datadiffs[:, i] = np.divide(np.abs(dataref[:, i] - datatest[:, i]), max,
|
||||
out=np.zeros_like(dataref[:, i]),
|
||||
where=max != 0) # Replace any division by zero with zero
|
||||
|
||||
# Calculate power (ignore warning from taking a log of any zero values)
|
||||
with np.errstate(divide='ignore'):
|
||||
@@ -165,7 +180,13 @@ for i, model in enumerate(testmodels):
|
||||
testresults[model]['Max diff'] = maxdiff
|
||||
|
||||
# Plot datasets
|
||||
fig1, ((ex1, hx1), (ey1, hy1), (ez1, hz1)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num=model + '.in', figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
fig1, ((ex1, hx1), (ey1, hy1), (ez1, hz1)) = plt.subplots(nrows=3, ncols=2,
|
||||
sharex=False, sharey='col',
|
||||
subplot_kw=dict(xlabel='Time [ns]'),
|
||||
num=model + '.in',
|
||||
figsize=(20, 10),
|
||||
facecolor='w',
|
||||
edgecolor='w')
|
||||
ex1.plot(timetest, datatest[:, 0], 'r', lw=2, label=model)
|
||||
ex1.plot(timeref, dataref[:, 0], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
ey1.plot(timetest, datatest[:, 1], 'r', lw=2, label=model)
|
||||
@@ -178,7 +199,9 @@ for i, model in enumerate(testmodels):
|
||||
hy1.plot(timeref, dataref[:, 4], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
hz1.plot(timetest, datatest[:, 5], 'r', lw=2, label=model)
|
||||
hz1.plot(timeref, dataref[:, 5], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
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]']
|
||||
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]']
|
||||
for i, ax in enumerate(fig1.axes):
|
||||
ax.set_ylabel(ylabels[i])
|
||||
ax.set_xlim(0, np.amax(timetest))
|
||||
@@ -186,14 +209,22 @@ for i, model in enumerate(testmodels):
|
||||
ax.legend()
|
||||
|
||||
# Plot diffs
|
||||
fig2, ((ex2, hx2), (ey2, hy2), (ez2, hz2)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num='Diffs: ' + model + '.in', figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
fig2, ((ex2, hx2), (ey2, hy2), (ez2, hz2)) = plt.subplots(nrows=3, ncols=2,
|
||||
sharex=False, sharey='col',
|
||||
subplot_kw=dict(xlabel='Time [ns]'),
|
||||
num='Diffs: ' + model + '.in',
|
||||
figsize=(20, 10),
|
||||
facecolor='w',
|
||||
edgecolor='w')
|
||||
ex2.plot(timeref, datadiffs[:, 0], 'r', lw=2, label='Ex')
|
||||
ey2.plot(timeref, datadiffs[:, 1], 'r', lw=2, label='Ey')
|
||||
ez2.plot(timeref, datadiffs[:, 2], 'r', lw=2, label='Ez')
|
||||
hx2.plot(timeref, datadiffs[:, 3], 'r', lw=2, label='Hx')
|
||||
hy2.plot(timeref, datadiffs[:, 4], 'r', lw=2, label='Hy')
|
||||
hz2.plot(timeref, datadiffs[:, 5], 'r', lw=2, label='Hz')
|
||||
ylabels = ['$E_x$, difference [dB]', '$H_x$, difference [dB]', '$E_y$, difference [dB]', '$H_y$, difference [dB]', '$E_z$, difference [dB]', '$H_z$, difference [dB]']
|
||||
ylabels = ['$E_x$, difference [dB]', '$H_x$, difference [dB]',
|
||||
'$E_y$, difference [dB]', '$H_y$, difference [dB]',
|
||||
'$E_z$, difference [dB]', '$H_z$, difference [dB]']
|
||||
for i, ax in enumerate(fig2.axes):
|
||||
ax.set_ylabel(ylabels[i])
|
||||
ax.set_xlim(0, np.amax(timetest))
|
||||
@@ -203,14 +234,21 @@ for i, model in enumerate(testmodels):
|
||||
# Save a PDF/PNG of the figure
|
||||
filediffs = file.stem + '_diffs'
|
||||
filediffs = file.parent / Path(filediffs)
|
||||
# fig1.savefig(file.with_suffix('.pdf'), dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
|
||||
# fig2.savefig(savediffs.with_suffix('.pdf'), dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
|
||||
fig1.savefig(file.with_suffix('.png'), dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
|
||||
fig2.savefig(filediffs.with_suffix('.png'), dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
|
||||
# fig1.savefig(file.with_suffix('.pdf'), dpi=None, format='pdf',
|
||||
# bbox_inches='tight', pad_inches=0.1)
|
||||
# fig2.savefig(savediffs.with_suffix('.pdf'), dpi=None, format='pdf',
|
||||
# bbox_inches='tight', pad_inches=0.1)
|
||||
fig1.savefig(file.with_suffix('.png'), dpi=150, format='png',
|
||||
bbox_inches='tight', pad_inches=0.1)
|
||||
fig2.savefig(filediffs.with_suffix('.png'), dpi=150, format='png',
|
||||
bbox_inches='tight', pad_inches=0.1)
|
||||
|
||||
# Summary of results
|
||||
for name, data in sorted(testresults.items()):
|
||||
if 'analytical' in name:
|
||||
print(Fore.CYAN + f"Test '{name}.in' using v.{data['Test version']} compared to analytical solution. Max difference {data['Max diff']:.2f}dB." + Style.RESET_ALL)
|
||||
logger.info(f"Test '{name}.in' using v.{data['Test version']} compared " +
|
||||
f"to analytical solution. Max difference {data['Max diff']:.2f}dB.")
|
||||
else:
|
||||
print(Fore.CYAN + f"Test '{name}.in' using v.{data['Test version']} compared to reference solution using v.{data['Ref version']}. Max difference {data['Max diff']:.2f}dB." + Style.RESET_ALL)
|
||||
logger.info(f"Test '{name}.in' using v.{data['Test version']} compared to " +
|
||||
f"reference solution using v.{data['Ref version']}. Max difference " +
|
||||
f"{data['Max diff']:.2f}dB.")
|
||||
|
在新工单中引用
屏蔽一个用户