Added functionality to better handle divide by zero error when taking log10.

这个提交包含在:
Craig Warren
2017-10-11 10:24:51 +01:00
父节点 e346b17cec
当前提交 e351a5fde8
共有 7 个文件被更改,包括 75 次插入29 次删除

查看文件

@@ -83,7 +83,14 @@ ax.annotate('Ground', xy=(np.deg2rad(270), 0), xytext=(8, -15), textcoords='offs
for patt in range(0, len(radii)):
pattplot = np.append(patterns[patt, :], patterns[patt, 0]) # Append start value to close circle
pattplot = pattplot / np.max(np.max(patterns)) # Normalise, based on set of patterns
ax.plot(theta, 10 * np.log10(pattplot), label='{:.2f}m'.format(radii[patt]), marker='.', ms=6, lw=1.5)
# Calculate power (ignore warning from taking a log of any zero values)
with np.errstate(divide='ignore'):
power = 10 * np.log10(pattplot)
# Replace any NaNs or Infs from zero division
power[np.invert(np.isfinite(power))] = 0
ax.plot(theta, power, label='{:.2f}m'.format(radii[patt]), marker='.', ms=6, lw=1.5)
# Add Hertzian dipole plot
# hertzplot1 = np.append(hertzian[0, :], hertzian[0, 0]) # Append start value to close circle

查看文件

@@ -13,8 +13,6 @@ import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
np.seterr(divide='ignore')
from gprMax.exceptions import GeneralError
"""This module contains fitness metric functions that can be used with the Taguchi optimisation method.
@@ -183,9 +181,14 @@ def min_sum_diffs(filename, args):
if output.attrs['Name'] in args['outputs']:
outputname = list(output.keys())[0]
modelresp = np.array(output[outputname])
# Calculate sum of differences
tmp = 20 * np.log10(np.abs(modelresp - refresp) / np.amax(np.abs(refresp)))
tmp = np.abs(np.sum(tmp[-np.isneginf(tmp)])) / len(tmp[-np.isneginf(tmp)])
with np.errstate(divide='ignore'): # Ignore warning from taking a log of any zero values
tmp = 20 * np.log10(np.abs(modelresp - refresp) / np.amax(np.abs(refresp)))
# Replace any NaNs or Infs from zero division
tmp[np.invert(np.isfinite(tmp))] = 0
tmp = np.abs(np.sum(tmp)) / len(tmp)
diffdB += tmp
outputs += 1