More updates to logging and handling exceptions.

这个提交包含在:
craig-warren
2020-04-09 14:23:50 +01:00
父节点 aba5e749c5
当前提交 1e64d493a2
共有 27 个文件被更改,包括 334 次插入177 次删除

查看文件

@@ -17,8 +17,10 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
logger = logging.getLogger(__name__)
from gprMax.exceptions import CmdInputError
"""Converts old to new style input files."""
@@ -40,7 +42,7 @@ except:
newfile = inputfile
newfile += '_v3syntax'
print("Attempting to convert inputfile '{}' to use new syntax...\n".format(inputfile))
logger.info("Attempting to convert inputfile '{}' to use new syntax...\n".format(inputfile))
model2D = False
txs = []
@@ -62,7 +64,7 @@ while(lindex < len(inputlines)):
model2D = True
# Syntax of old command: #dx_dy: x y
replacement = '#dx_dy_dz: {:g} {:g} {:g}'.format(float(params[0]), float(params[1]), float(params[1]))
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -90,7 +92,7 @@ while(lindex < len(inputlines)):
if model2D:
# Syntax of old command: #domain: x y
replacement = '#domain: {:g} {:g} {:g}'.format(float(params[0]), float(params[1]), dx_dy_dz[2])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
domain = (float(params[0]), float(params[1]), dx_dy_dz[2])
@@ -110,7 +112,7 @@ while(lindex < len(inputlines)):
elif cmdname == '#num_of_procs':
# Syntax of old command: #num_of_procs: nthreads
replacement = '#num_threads: {}'.format(params[0])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -139,7 +141,7 @@ while(lindex < len(inputlines)):
if model2D:
# Syntax of old command: #rx: x1 y1
replacement = '#rx: {} {} {}'.format(params[0], params[1], 0)
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -151,7 +153,7 @@ while(lindex < len(inputlines)):
else:
# Syntax of old command: #rx_box: x1 y1 z1 x2 y2 z2 dx dy dz
replacement = '#rx_array: {} {} {} {} {} {} {} {} {}'.format(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -163,7 +165,7 @@ while(lindex < len(inputlines)):
else:
# Syntax of old command: #tx_steps: dx dy dz
replacement = '#src_steps: {} {} {}'.format(params[0], params[1], params[2])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -175,7 +177,7 @@ while(lindex < len(inputlines)):
else:
# Syntax of old command: #rx_steps: dx dy dz
replacement = '#rx_steps: {} {} {}'.format(params[0], params[1], params[2])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -183,12 +185,12 @@ while(lindex < len(inputlines)):
elif cmdname == '#medium':
# Syntax of old command: #medium: e_rs e_inf tau sig_e mu_r sig_m ID
replacement = '#material: {} {} {} {} {}'.format(params[0], params[3], params[4], params[5], params[6])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
if float(params[1]) > 0:
replacement = '#add_dispersion_debye: 1 {} {} {}'.format(float(params[0]) - float(params[1]), params[2], params[6])
print("Command '{}' added.".format(replacement))
logger.info("Command '{}' added.".format(replacement))
inputlines.insert(lindex + 1, replacement)
lindex += 1
@@ -196,7 +198,7 @@ while(lindex < len(inputlines)):
if model2D:
# Syntax of old command: #box: x1 y1 x2 y2 ID
replacement = '#box: {} {} {} {} {} {} {}'.format(params[0], params[1], 0, params[2], params[3], dx_dy_dz[2], params[4])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -209,7 +211,7 @@ while(lindex < len(inputlines)):
# Syntax of old command: #triangle: x1 y1 z1 x2 y2 z2 x3 y3 z3 ID
replacement = '#triangle: {} {} {} {} {} {} {} {} {} {} {}'.format(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], 0, params[9])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -217,13 +219,13 @@ while(lindex < len(inputlines)):
elif cmdname == '#wedge':
# Syntax of old command: #wedge: x1 y1 z1 x2 y2 z2 x3 y3 z3 thickness ID
replacement = '#triangle: {} {} {} {} {} {} {} {} {} {} {}'.format(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
elif cmdname == '#bowtie':
print("Command '{}', is no longer supported. You can create the bowtie shape using two triangle commands.".format(inputlines[lindex]))
logger.info("Command '{}', is no longer supported. You can create the bowtie shape using two triangle commands.".format(inputlines[lindex]))
inputlines.pop(lindex)
elif cmdname == '#cylinder':
@@ -239,7 +241,7 @@ while(lindex < len(inputlines)):
elif params[0] == 'z':
replacement = '#cylinder: {} {} {} {} {} {} {} {}'.format(params[3], params[4], params[1], params[3], params[4], params[2], params[5], params[6])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -247,33 +249,33 @@ while(lindex < len(inputlines)):
elif cmdname == '#cylinder_new':
# Syntax of old command: #cylinder_new: x1 y1 z1 x2 y2 z2 radius ID
replacement = '#cylinder: {} {} {} {} {} {} {} {}'.format(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
elif cmdname == '#cylindrical_segment':
print("Command '{}' has been removed as it is no longer supported. You can create a cylindrical segment by using a #box to cut through a #cylinder.".format(inputlines[lindex]))
logger.info("Command '{}' has been removed as it is no longer supported. You can create a cylindrical segment by using a #box to cut through a #cylinder.".format(inputlines[lindex]))
inputlines.pop(lindex)
elif cmdname in ['#x_segment', '#y_segment']:
print("Command '{}' has been removed. A circular segment can be created by using the #cylinder command and cutting it with a #box. Alternatively the #cylindrical_sector command maybe useful.".format(inputlines[lindex]))
logger.info("Command '{}' has been removed. A circular segment can be created by using the #cylinder command and cutting it with a #box. Alternatively the #cylindrical_sector command maybe useful.".format(inputlines[lindex]))
inputlines.pop(lindex)
elif cmdname == '#media_file':
print("Command '{}' has is no longer supported. Please include your materials using the #material command directly in the input file.".format(inputlines[lindex]))
logger.info("Command '{}' has is no longer supported. Please include your materials using the #material command directly in the input file.".format(inputlines[lindex]))
inputlines.pop(lindex)
elif cmdname == '#pml_layers':
# Syntax of old command: #pml_layers: num_layers
replacement = '#pml_cells: {}'.format(params[0])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
elif cmdname in ['#abc_order', '#abc_type', 'abc_optimisation_angles', '#abc_mixing_parameters', '#abc_stability_factors']:
print("Command '{}' has been removed as Higdon Absorbing Boundary Conditions (ABC) are no longer supported. The default ABC is the (better performing) Perfectly Matched Layer (PML).".format(inputlines[lindex]))
logger.info("Command '{}' has been removed as Higdon Absorbing Boundary Conditions (ABC) are no longer supported. The default ABC is the (better performing) Perfectly Matched Layer (PML).".format(inputlines[lindex]))
inputlines.pop(lindex)
elif cmdname == '#analysis':
@@ -282,11 +284,11 @@ while(lindex < len(inputlines)):
extra = " To run a model multiple times use the command line option -n, e.g. gprMax {} -n {}".format(inputfile, int(params[0]))
else:
extra = ''
print("Command '{}' has been removed as it is no longer required.{}".format(inputlines[lindex], extra))
logger.info("Command '{}' has been removed as it is no longer required.{}".format(inputlines[lindex], extra))
inputlines.pop(lindex)
elif cmdname in ['#end_analysis', '#number_of_media', '#nips_number']:
print("Command '{}' has been removed as it is no longer required.".format(inputlines[lindex]))
logger.info("Command '{}' has been removed as it is no longer required.".format(inputlines[lindex]))
inputlines.pop(lindex)
elif cmdname == '#snapshot':
@@ -296,7 +298,7 @@ while(lindex < len(inputlines)):
else:
# Syntax of old command: #snapshot: i1 x1 y1 z1 x2 y2 z2 dx dy dz time filename type
replacement = '#snapshot: {} {} {} {} {} {} {} {} {} {} {}'.format(params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10], params[11])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -306,7 +308,7 @@ while(lindex < len(inputlines)):
if params[0].endswith('.geo'):
params = params[0].split('.')
replacement = '#geometry_view: 0 0 0 {} {} {} {} {} {} {} n'.format(domain[0], domain[1], domain[2], dx_dy_dz[0], dx_dy_dz[1], dx_dy_dz[2], params[0])
print("Command '{}', replaced with '{}'. This is a geometry view of the entire domain, sampled at the spatial resolution of the model, using the per Yee cell option (n). You may want to consider taking a smaller geometry view or using a coarser sampling. You may also want to use the per Yee cell edge option (f) to view finer details.".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'. This is a geometry view of the entire domain, sampled at the spatial resolution of the model, using the per Yee cell option (n). You may want to consider taking a smaller geometry view or using a coarser sampling. You may also want to use the per Yee cell edge option (f) to view finer details.".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
@@ -314,13 +316,14 @@ while(lindex < len(inputlines)):
elif cmdname == '#geometry_vtk':
# Syntax of old command: #geometry_vtk: x1 y1 z1 x2 y2 z2 dx dy dz filename type
replacement = '#geometry_view: {} {} {} {} {} {} {} {} {} {} {}'.format(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10])
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
logger.info("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
inputlines.pop(lindex)
inputlines.insert(lindex, replacement)
lindex += 1
elif cmdname in ['#plane_wave', '#thin_wire', '#huygens_surface']:
raise CmdInputError("Command '{}' has not yet implemented in the new version of gprMax. For now please continue to use the old version.".format(inputlines[lindex]))
logger.exception("Command '{}' has not yet implemented in the new version of gprMax. For now please continue to use the old version.".format(inputlines[lindex]))
raise ValueError
else:
lindex += 1
@@ -332,7 +335,8 @@ while(lindex < len(inputlines)):
for source in linesources:
params = source.split()
if params[3] is badwaveforms:
raise CmdInputError("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
logger.exception("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
raise ValueError
elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[4])
@@ -343,7 +347,7 @@ for source in linesources:
else:
hertzian = '#hertzian_dipole: z {} {} {} {}'.format(hertziantx[1], hertziantx[2], 0, hertziantx[3])
print("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, hertzian))
logger.info("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, hertzian))
inputlines.remove(source)
inputlines.remove(tx)
inputlines.append(waveform)
@@ -353,7 +357,8 @@ for source in linesources:
for source in hertziandipoles:
params = source.split()
if params[3] is badwaveforms:
raise CmdInputError("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
logger.exception("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
raise ValueError
elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[4])
@@ -364,7 +369,7 @@ for source in hertziandipoles:
else:
hertzian = '#hertzian_dipole: {} {} {} {} {}'.format(hertziantx[1], hertziantx[2], hertziantx[3], hertziantx[4], hertziantx[5])
print("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, hertzian))
logger.info("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, hertzian))
inputlines.remove(source)
inputlines.remove(tx)
inputlines.append(waveform)
@@ -374,7 +379,8 @@ for source in hertziandipoles:
for source in voltagesources:
params = source.split()
if params[3] is badwaveforms:
raise CmdInputError("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
logger.exception("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
raise ValueError
elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[5])
@@ -385,7 +391,7 @@ for source in voltagesources:
else:
voltagesource = '#voltage_source: {} {} {} {} {} {}'.format(voltagesourcetx[1], voltagesourcetx[2], voltagesourcetx[3], voltagesourcetx[4], params[4], voltagesourcetx[5])
print("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, voltagesource))
logger.info("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, voltagesource))
inputlines.remove(source)
inputlines.remove(tx)
inputlines.append(waveform)
@@ -395,7 +401,8 @@ for source in voltagesources:
for source in transmissionlines:
params = source.split()
if params[3] is badwaveforms:
raise CmdInputError("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
logger.exception("Waveform types {} are not compatible between new and old versions of gprMax.".format(''.join(badwaveforms)))
raise ValueError
elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[6])
@@ -406,7 +413,7 @@ for source in transmissionlines:
else:
transmissionline = '#transmission_line: {} {} {} {} {} {}'.format(transmissionlinetx[1], transmissionlinetx[2], transmissionlinetx[3], transmissionlinetx[4], params[5], transmissionlinetx[5])
print("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, transmissionline))
logger.info("Commands '{}' and '{}', replaced with '{}' and '{}'".format(source, tx, waveform, transmissionline))
inputlines.remove(source)
inputlines.remove(tx)
inputlines.append(waveform)
@@ -419,4 +426,4 @@ with open(newinputfile, 'w') as f:
for line in inputlines:
f.write('{}\n'.format(line))
print("\nWritten new input file: '{}'".format(newinputfile))
logger.info("\nWritten new input file: '{}'".format(newinputfile))

查看文件

@@ -18,13 +18,15 @@
import argparse
import glob
import logging
import os
from pathlib import Path
import h5py
import numpy as np
from gprMax._version import __version__
from gprMax.exceptions import CmdInputError
logger = logging.getLogger(__name__)
def get_output_data(filename, rxnumber, rxcomponent):
@@ -47,14 +49,16 @@ def get_output_data(filename, rxnumber, rxcomponent):
# Check there are any receivers
if nrx == 0:
raise CmdInputError(f'No receivers found in {filename}')
logger.exception(f'No receivers found in {filename}')
raise ValueError
path = '/rxs/rx' + str(rxnumber) + '/'
availableoutputs = list(f[path].keys())
# Check if requested output is in file
if rxcomponent not in availableoutputs:
raise CmdInputError(f"{rxcomponent} output requested to plot, but the available output for receiver 1 is {', '.join(availableoutputs)}")
logger.exception(f"{rxcomponent} output requested to plot, but the available output for receiver 1 is {', '.join(availableoutputs)}")
raise ValueError
outputdata = f[path + '/' + rxcomponent]
outputdata = np.array(outputdata)

查看文件

@@ -17,16 +17,18 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
from pathlib import Path
import h5py
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import numpy as np
from gprMax.exceptions import CmdInputError
from gprMax.receivers import Rx
from gprMax.utilities import fft_power
logger = logging.getLogger(__name__)
def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
"""Plots electric and magnetic fields and currents from all receiver points
@@ -65,7 +67,8 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
# Check there are any receivers
if not paths:
raise CmdInputError(f'No receivers found in {file}')
logger.exception(f'No receivers found in {file}')
raise ValueError
# Loop through all grids
for path in paths:
@@ -77,7 +80,8 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
# Check for single output component when doing a FFT
if fft:
if not len(outputs) == 1:
raise CmdInputError('A single output must be specified when using the -fft option')
logger.exception('A single output must be specified when using the -fft option')
raise ValueError
# New plot for each receiver
for rx in range(1, nrx + 1):
@@ -98,7 +102,8 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
output = outputs[0]
if output not in availableoutputs:
raise CmdInputError(f"{output} output requested to plot, but the available output for receiver 1 is {', '.join(availableoutputs)}")
logger.exception(f"{output} output requested to plot, but the available output for receiver 1 is {', '.join(availableoutputs)}")
raise ValueError
outputdata = f[rxpath + output][:] * polarity
@@ -196,7 +201,8 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
# Check if requested output is in file
if output not in availableoutputs:
raise CmdInputError(f"Output(s) requested to plot: {', '.join(outputs)}, but available output(s) for receiver {rx} in the file: {', '.join(availableoutputs)}")
logger.exception(f"Output(s) requested to plot: {', '.join(outputs)}, but available output(s) for receiver {rx} in the file: {', '.join(availableoutputs)}")
raise ValueError
outputdata = f[rxpath + output][:] * polarity

查看文件

@@ -17,15 +17,17 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
from pathlib import Path
import h5py
import matplotlib.pyplot as plt
import numpy as np
from gprMax.exceptions import CmdInputError
from .outputfiles_merge import get_output_data
logger = logging.getLogger(__name__)
def mpl_plot(filename, outputdata, dt, rxnumber, rxcomponent):
"""Creates a plot (with matplotlib) of the B-scan.
@@ -89,7 +91,8 @@ if __name__ == "__main__":
# Check there are any receivers
if nrx == 0:
raise CmdInputError(f'No receivers found in {args.outputfile}')
logger.exception(f'No receivers found in {args.outputfile}')
raise ValueError
for rx in range(1, nrx + 1):
outputdata, dt = get_output_data(args.outputfile, rx, args.rx_component)

查看文件

@@ -17,13 +17,15 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
from pathlib import Path
import h5py
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import numpy as np
from gprMax.exceptions import CmdInputError
logger = logging.getLogger(__name__)
def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=None, rxcomponent=None):
@@ -81,7 +83,8 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
availableoutputs = list(f[rxpath].keys())
if rxcomponent not in availableoutputs:
raise CmdInputError(f"{rxcomponent} output requested, but the available output for receiver {rxnumber} is {', '.join(availableoutputs)}")
logger.exception(f"{rxcomponent} output requested, but the available output for receiver {rxnumber} is {', '.join(availableoutputs)}")
raise ValueError
rxpath += rxcomponent

查看文件

@@ -17,15 +17,17 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
from pathlib import Path
import h5py
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import numpy as np
from gprMax.exceptions import CmdInputError
from scipy.io import loadmat
logger = logging.getLogger(__name__)
def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=None, rxcomponent=None):
"""Calculates antenna parameters - incident, reflected and total volatges and currents; s11, (s21) and input impedance.
@@ -81,7 +83,8 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
availableoutputs = list(f[rxpath].keys())
if rxcomponent not in availableoutputs:
raise CmdInputError(f"{rxcomponent} output requested, but the available output for receiver {rxnumber} is {', '.join(availableoutputs)}")
logger.exception(f"{rxcomponent} output requested, but the available output for receiver {rxnumber} is {', '.join(availableoutputs)}")
raise ValueError
rxpath += rxcomponent

查看文件

@@ -17,14 +17,16 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
from gprMax.exceptions import CmdInputError
from gprMax.utilities import fft_power, round_value
from gprMax.waveforms import Waveform
logger = logging.getLogger(__name__)
def check_timewindow(timewindow, dt):
"""Checks and sets time window and number of iterations.
@@ -51,7 +53,8 @@ def check_timewindow(timewindow, dt):
if timewindow > 0:
iterations = round_value((timewindow / dt)) + 1
else:
raise CmdInputError('Time window must have a value greater than zero')
logger.exception('Time window must have a value greater than zero')
raise ValueError
return timewindow, iterations
@@ -164,9 +167,11 @@ if __name__ == "__main__":
# Check waveform parameters
if args.type.lower() not in Waveform.types:
raise CmdInputError(f"The waveform must have one of the following types {', '.join(Waveform.types)}")
logger.exception(f"The waveform must have one of the following types {', '.join(Waveform.types)}")
raise ValueError
if args.freq <= 0:
raise CmdInputError('The waveform requires an excitation frequency value of greater than zero')
logger.exception('The waveform requires an excitation frequency value of greater than zero')
raise ValueError
# Create waveform instance
w = Waveform()