PEP8 code cleanups.

这个提交包含在:
Craig Warren
2018-01-02 18:14:20 +00:00
父节点 f83ec97fa9
当前提交 4848a8d4d7
共有 15 个文件被更改,包括 83 次插入90 次删除

查看文件

@@ -29,7 +29,7 @@ kernels_template_fields = Template("""
#define INDEX4D_ID(p, i, j, k) (p)*($NX_ID)*($NY_ID)*($NZ_ID)+(i)*($NY_ID)*($NZ_ID)+(j)*($NZ_ID)+(k)
#define INDEX4D_T(p, i, j, k) (p)*($NX_T)*($NY_T)*($NZ_T)+(i)*($NY_T)*($NZ_T)+(j)*($NZ_T)+(k)
// Material coefficients (read-only) in constant memory (64KB)
// Material coefficients (read-only) in constant memory (64KB)_
__device__ __constant__ $REAL updatecoeffsE[$N_updatecoeffsE];
__device__ __constant__ $REAL updatecoeffsH[$N_updatecoeffsH];

查看文件

@@ -100,7 +100,7 @@ class FractalSurface(object):
fractalmax = np.amax(self.fractalsurface)
fractalrange = fractalmax - fractalmin
self.fractalsurface = self.fractalsurface * ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) \
+ self.fractalrange[0] - ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) * fractalmin
+ self.fractalrange[0] - ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) * fractalmin
class FractalVolume(object):

查看文件

@@ -218,25 +218,25 @@ class GeometryView(object):
z_materials = np.zeros((n_z_lines), dtype=np.uint32)
define_fine_geometry(self.nx,
self.ny,
self.nz,
self.xs,
self.xf,
self.ys,
self.yf,
self.zs,
self.zf,
G.dx,
G.dy,
G.dz,
G.ID,
points,
x_lines,
x_materials,
y_lines,
y_materials,
z_lines,
z_materials)
self.ny,
self.nz,
self.xs,
self.xf,
self.ys,
self.yf,
self.zs,
self.zf,
G.dx,
G.dy,
G.dz,
G.ID,
points,
x_lines,
x_materials,
y_lines,
y_materials,
z_lines,
z_materials)
# Write point data
datasize = points.nbytes

查看文件

@@ -70,18 +70,18 @@ def main():
def api(
inputfile,
n=1,
task=None,
restart=None,
mpi=False,
gpu=None,
benchmark=False,
geometry_only=False,
geometry_fixed=False,
write_processed=False,
opt_taguchi=False
):
inputfile,
n=1,
task=None,
restart=None,
mpi=False,
gpu=None,
benchmark=False,
geometry_only=False,
geometry_fixed=False,
write_processed=False,
opt_taguchi=False
):
"""If installed as a module this is the entry point."""
# Print gprMax logo, version, and licencing/copyright information
@@ -165,7 +165,7 @@ def run_main(args):
# Process for simulation with Taguchi optimisation #
####################################################
elif args.opt_taguchi:
if args.mpi_worker: # Special case for MPI spawned workers - they do not need to enter the Taguchi optimisation mode
if args.mpi_worker: # Special case for MPI spawned workers - they do not need to enter the Taguchi optimisation mode
run_mpi_sim(args, inputfile, usernamespace)
else:
from gprMax.optimisation_taguchi import run_opt_sim
@@ -396,9 +396,9 @@ def run_mpi_sim(args, inputfile, usernamespace, optparams=None):
# Connect to parent
try:
comm = MPI.Comm.Get_parent() # get MPI communicator object
comm = MPI.Comm.Get_parent() # get MPI communicator object
rank = comm.Get_rank() # rank of this process
except:
except ValueError:
raise ValueError('Could not connect to parent')
# Ask for work until stop sentinel

查看文件

@@ -50,10 +50,10 @@ class Grid(object):
self.grid = grid
def n_edges(self):
l = self.nx
m = self.ny
n = self.nz
e = (l * m * (n - 1)) + (m * n * (l - 1)) + (l * n * (m - 1))
i = self.nx
j = self.ny
k = self.nz
e = (i * j * (k - 1)) + (j * k * (i - 1)) + (i * k * (j - 1))
return e
def n_nodes(self):
@@ -239,8 +239,8 @@ def dispersion_analysis(G):
# Built-in waveform
else:
# Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT
# Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT
waveform.calculate_coefficients()
iterations = round_value(4 * waveform.chi / G.dt)
if iterations > G.iterations:
@@ -261,7 +261,7 @@ def dispersion_analysis(G):
try:
freqthres = np.where(power[freqmaxpower:] < -G.highestfreqthres)[0][0] + freqmaxpower
results['maxfreq'].append(freqs[freqthres])
except:
except ValueError:
results['error'] = 'unable to calculate maximum power from waveform, most likely due to undersampling.'
# If waveform is truncated don't do any further analysis

查看文件

@@ -413,7 +413,7 @@ def cylinder(x1, y1, z1, x2, y2, z2, radius, material, averaging='', rotate90ori
def cylindrical_sector(axis, ctr1, ctr2, t1, t2, radius,
startingangle, sweptangle, material, averaging=''):
startingangle, sweptangle, material, averaging=''):
"""Prints the gprMax #cylindrical_sector command.
Args:
@@ -471,7 +471,7 @@ def waveform(shape, amplitude, frequency, identifier):
def hertzian_dipole(polarisation, f1, f2, f3, identifier,
t0=None, t_remove=None, dxdy=None, rotate90origin=()):
t0=None, t_remove=None, dxdy=None, rotate90origin=()):
"""Prints the #hertzian_dipole: polarisation, f1, f2, f3, identifier, [t0, t_remove]
Args:
@@ -545,7 +545,7 @@ def magnetic_dipole(polarisation, f1, f2, f3, identifier,
def voltage_source(polarisation, f1, f2, f3, resistance, identifier,
t0=None, t_remove=None, dxdy=None, rotate90origin=()):
t0=None, t_remove=None, dxdy=None, rotate90origin=()):
"""Prints the #voltage_source: polarisation, f1, f2, f3, resistance, identifier, [t0, t_remove]
Args:
@@ -583,7 +583,7 @@ def voltage_source(polarisation, f1, f2, f3, resistance, identifier,
def transmission_line(polarisation, f1, f2, f3, resistance, identifier,
t0=None, t_remove=None, dxdy=None, rotate90origin=()):
t0=None, t_remove=None, dxdy=None, rotate90origin=()):
"""Prints the #transmission_line: polarisation, f1, f2, f3, resistance, identifier, [t0, t_remove]
Args:

查看文件

@@ -877,10 +877,7 @@ def process_geometrycmds(geometry, G):
volume.nbins = nbins
volume.seed = seed
volume.weighting = np.array([float(tmp[8]), float(tmp[9]), float(tmp[10])])
try:
volume.averaging = averagefractalbox
except:
pass
volume.averaging = averagefractalbox
if G.messages:
if volume.averaging:

查看文件

@@ -499,7 +499,7 @@ def process_multicmds(multicmds, G):
try:
time = int(tmp[9])
# If real floating point value given
except:
except ValueError:
time = float(tmp[9])
if time > 0:
time = round_value((time / G.dt)) + 1
@@ -587,13 +587,8 @@ def process_multicmds(multicmds, G):
material.type = 'debye'
material.poles = poles
material.averagable = False
# for pole in range(1, 2 * poles, 2):
# if float(tmp[pole]) > 0 and float(tmp[pole + 1]) > G.dt:
# material.deltaer.append(float(tmp[pole]))
# material.tau.append(float(tmp[pole + 1]))
# else:
# raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires positive values for the permittivity difference, and relaxation times that are greater than the time step for the model.')
for pole in range(1, 2 * poles, 2):
# N.B Not checking if relaxation times are greater than time-step
if float(tmp[pole]) > 0:
material.deltaer.append(float(tmp[pole]))
material.tau.append(float(tmp[pole + 1]))

查看文件

@@ -203,7 +203,7 @@ def process_singlecmds(singlecmds, G):
G.timewindow = (tmp - 1) * G.dt
G.iterations = tmp
# If real floating point value given
except:
except ValueError:
tmp = float(tmp)
if tmp > 0:
G.timewindow = tmp
@@ -312,7 +312,7 @@ def process_singlecmds(singlecmds, G):
waveformvalues = waveformvalues[:len(waveformtime)]
# Zero-pad end of waveform array if it is shorter than time array
elif len(waveformvalues) < len(waveformtime):
waveformvalues = np.lib.pad(waveformvalues, (0,len(waveformtime)-len(waveformvalues)), 'constant', constant_values=0)
waveformvalues = np.lib.pad(waveformvalues, (0, len(waveformtime) - len(waveformvalues)), 'constant', constant_values=0)
# Interpolate waveform values
w.userfunc = interpolate.interp1d(waveformtime, waveformvalues, **kwargs)

查看文件

@@ -153,7 +153,7 @@ class Material(object):
er (float): Complex relative permittivity.
"""
# This will be permittivity at infinite frequency if the material is dispersive
# Permittivity at infinite frequency if the material is dispersive
er = self.er
if self.poles > 0:
@@ -166,6 +166,7 @@ class Material(object):
for pole in range(self.poles):
er += (self.deltaer[pole] * self.tau[pole]**2) / (self.tau[pole]**2 + 2j * w * self.alpha[pole] - w**2)
elif 'drude' in self.type:
ersum = 0
for pole in range(self.poles):
ersum += self.tau[pole]**2 / (w**2 - 1j * w * self.alpha[pole])
er -= ersum

查看文件

@@ -152,7 +152,7 @@ def fft_power(waveform, dt):
"""
# Calculate magnitude of frequency spectra of waveform (ignore warning from taking a log of any zero values)
with np.errstate(divide='ignore'): #
with np.errstate(divide='ignore'):
power = 10 * np.log10(np.abs(np.fft.fft(waveform))**2)
# Replace any NaNs or Infs from zero division