More updates to logging and handling exceptions.

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

查看文件

@@ -27,7 +27,6 @@ init()
from scipy import interpolate from scipy import interpolate
from scipy.constants import c from scipy.constants import c
from .exceptions import CmdInputError
from .utilities import round_value, set_omp_threads from .utilities import round_value, set_omp_threads
from .waveforms import Waveform from .waveforms import Waveform
@@ -92,10 +91,12 @@ class Domain(UserObjectSingle):
try: try:
G.nx, G.ny, G.nz = uip.discretise_point(self.kwargs['p1']) G.nx, G.ny, G.nz = uip.discretise_point(self.kwargs['p1'])
except KeyError: except KeyError:
raise CmdInputError(self.__str__() + ' please specify a point') logger.exception(self.__str__() + ' please specify a point')
raise
if G.nx == 0 or G.ny == 0 or G.nz == 0: if G.nx == 0 or G.ny == 0 or G.nz == 0:
raise CmdInputError(self.__str__() + ' requires at least one cell in every dimension') logger.exception(self.__str__() + ' requires at least one cell in every dimension')
raise ValueError
logger.info(f"Domain size: {self.kwargs['p1'][0]:g} x {self.kwargs['p1'][1]:g} x {self.kwargs['p1'][2]:g}m ({G.nx:d} x {G.ny:d} x {G.nz:d} = {(G.nx * G.ny * G.nz):g} cells)") logger.info(f"Domain size: {self.kwargs['p1'][0]:g} x {self.kwargs['p1'][1]:g} x {self.kwargs['p1'][2]:g}m ({G.nx:d} x {G.ny:d} x {G.nz:d} = {(G.nx * G.ny * G.nz):g} cells)")
@@ -137,14 +138,18 @@ class Discretisation(UserObjectSingle):
G.dl = np.array(self.kwargs['p1']) G.dl = np.array(self.kwargs['p1'])
G.dx, G.dy, G.dz = self.kwargs['p1'] G.dx, G.dy, G.dz = self.kwargs['p1']
except KeyError: except KeyError:
raise CmdInputError(self.__str__() + ' discretisation requires a point') logger.exception(self.__str__() + ' discretisation requires a point')
raise
if G.dl[0] <= 0: if G.dl[0] <= 0:
raise CmdInputError(self.__str__() + ' discretisation requires the x - direction spatial step to be greater than zero') logger.exception(self.__str__() + ' discretisation requires the x-direction spatial step to be greater than zero')
raise ValueError
if G.dl[1] <= 0: if G.dl[1] <= 0:
raise CmdInputError(self.__str__() + ' discretisation requires the y - direction spatial step to be greater than zero') logger.exception(self.__str__() + ' discretisation requires the y-direction spatial step to be greater than zero')
raise ValueError
if G.dl[2] <= 0: if G.dl[2] <= 0:
raise CmdInputError(self.__str__() + ' discretisation requires the z - direction spatial step to be greater than zero') logger.exception(self.__str__() + ' discretisation requires the z-direction spatial step to be greater than zero')
raise ValueError
logger.info(f'Spatial discretisation: {G.dl[0]:g} x {G.dl[1]:g} x {G.dl[2]:g}m') logger.info(f'Spatial discretisation: {G.dl[0]:g} x {G.dl[1]:g} x {G.dl[2]:g}m')
@@ -179,12 +184,14 @@ class TimeWindow(UserObjectSingle):
G.timewindow = tmp G.timewindow = tmp
G.iterations = int(np.ceil(tmp / G.dt)) + 1 G.iterations = int(np.ceil(tmp / G.dt)) + 1
else: else:
raise CmdInputError(self.__str__() + ' must have a value greater than zero') logger.exception(self.__str__() + ' must have a value greater than zero')
raise ValueError
except KeyError: except KeyError:
pass pass
if not G.timewindow: if not G.timewindow:
raise CmdInputError(self.__str__() + ' specify a time or number of iterations') logger.exception(self.__str__() + ' specify a time or number of iterations')
raise ValueError
logger.info(f'Time window: {G.timewindow:g} secs ({G.iterations} iterations)') logger.info(f'Time window: {G.timewindow:g} secs ({G.iterations} iterations)')
@@ -205,9 +212,11 @@ class NumThreads(UserObjectSingle):
try: try:
n = self.kwargs['n'] n = self.kwargs['n']
except KeyError: except KeyError:
raise CmdInputError(self.__str__() + ' requires exactly one parameter to specify the number of threads to use') logger.exception(self.__str__() + ' requires exactly one parameter to specify the number of threads to use')
raise
if n < 1: if n < 1:
raise CmdInputError(self.__str__() + ' requires the value to be an integer not less than one') logger.exception(self.__str__() + ' requires the value to be an integer not less than one')
raise ValueError
config.get_model_config().ompthreads = set_omp_threads(n) config.get_model_config().ompthreads = set_omp_threads(n)
@@ -227,10 +236,12 @@ class TimeStepStabilityFactor(UserObjectSingle):
try: try:
f = self.kwargs['f'] f = self.kwargs['f']
except KeyError: except KeyError:
raise CmdInputError(self.__str__() + ' requires exactly one parameter') logger.exception(self.__str__() + ' requires exactly one parameter')
raise
if f <= 0 or f > 1: if f <= 0 or f > 1:
raise CmdInputError(self.__str__() + ' requires the value of the time step stability factor to be between zero and one') logger.exception(self.__str__() + ' requires the value of the time step stability factor to be between zero and one')
raise ValueError
G.dt = G.dt * f G.dt = G.dt * f
logger.info(f'Time step (modified): {G.dt:g} secs') logger.info(f'Time step (modified): {G.dt:g} secs')
@@ -276,7 +287,8 @@ class PMLCells(UserObjectSingle):
G.pmlthickness['ymax'] = int(self.kwargs['ymax']) G.pmlthickness['ymax'] = int(self.kwargs['ymax'])
G.pmlthickness['zmax'] = int(self.kwargs['zmax']) G.pmlthickness['zmax'] = int(self.kwargs['zmax'])
except KeyError: except KeyError:
raise CmdInputError('#pml_cells: requires either one or six parameter(s)') logger.exception(self.__str__() + ' requires either one or six parameter(s)')
raise
if (2 * G.pmlthickness['x0'] >= G.nx or if (2 * G.pmlthickness['x0'] >= G.nx or
2 * G.pmlthickness['y0'] >= G.ny or 2 * G.pmlthickness['y0'] >= G.ny or
@@ -284,7 +296,8 @@ class PMLCells(UserObjectSingle):
2 * G.pmlthickness['xmax'] >= G.nx or 2 * G.pmlthickness['xmax'] >= G.nx or
2 * G.pmlthickness['ymax'] >= G.ny or 2 * G.pmlthickness['ymax'] >= G.ny or
2 * G.pmlthickness['zmax'] >= G.nz): 2 * G.pmlthickness['zmax'] >= G.nz):
raise CmdInputError('#pml_thickness: has too many cells for the domain size') logger.exception(self.__str__() + ' has too many cells for the domain size')
raise ValueError
class SrcSteps(UserObjectSingle): class SrcSteps(UserObjectSingle):
@@ -303,7 +316,8 @@ class SrcSteps(UserObjectSingle):
try: try:
G.srcsteps = uip.discretise_point(self.kwargs['p1']) G.srcsteps = uip.discretise_point(self.kwargs['p1'])
except KeyError: except KeyError:
raise CmdInputError('#src_steps: requires exactly three parameters') logger.exception(self.__str__() + ' requires exactly three parameters')
raise
logger.info(f'Simple sources will step {G.srcsteps[0] * G.dx:g}m, {G.srcsteps[1] * G.dy:g}m, {G.srcsteps[2] * G.dz:g}m for each model run.') logger.info(f'Simple sources will step {G.srcsteps[0] * G.dx:g}m, {G.srcsteps[1] * G.dy:g}m, {G.srcsteps[2] * G.dz:g}m for each model run.')
@@ -324,7 +338,8 @@ class RxSteps(UserObjectSingle):
try: try:
G.rxsteps = uip.discretise_point(self.kwargs['p1']) G.rxsteps = uip.discretise_point(self.kwargs['p1'])
except KeyError: except KeyError:
raise CmdInputError('#rx_steps: requires exactly three parameters') logger.exception(self.__str__() + ' requires exactly three parameters')
raise
logger.info(f'All receivers will step {G.rxsteps[0] * G.dx:g}m, {G.rxsteps[1] * G.dy:g}m, {G.rxsteps[2] * G.dz:g}m for each model run.') logger.info(f'All receivers will step {G.rxsteps[0] * G.dx:g}m, {G.rxsteps[1] * G.dy:g}m, {G.rxsteps[2] * G.dz:g}m for each model run.')
@@ -359,7 +374,8 @@ class ExcitationFile(UserObjectSingle):
args, varargs, keywords, defaults = inspect.getargspec(interpolate.interp1d) args, varargs, keywords, defaults = inspect.getargspec(interpolate.interp1d)
kwargs = dict(zip(reversed(args), reversed(defaults))) kwargs = dict(zip(reversed(args), reversed(defaults)))
except KeyError: except KeyError:
raise CmdInputError('#excitation_file: requires either one or three parameter(s)') logger.exception(self.__str__() + ' requires either one or three parameter(s)')
raise
# See if file exists at specified path and if not try input file directory # See if file exists at specified path and if not try input file directory
excitationfile = Path(excitationfile) excitationfile = Path(excitationfile)
@@ -387,7 +403,8 @@ class ExcitationFile(UserObjectSingle):
for waveform in range(len(waveformIDs)): for waveform in range(len(waveformIDs)):
if any(x.ID == waveformIDs[waveform] for x in G.waveforms): if any(x.ID == waveformIDs[waveform] for x in G.waveforms):
raise CmdInputError(f'Waveform with ID {waveformIDs[waveform]} already exists') logger.exception(f'Waveform with ID {waveformIDs[waveform]} already exists')
raise ValueError
w = Waveform() w = Waveform()
w.ID = waveformIDs[waveform] w.ID = waveformIDs[waveform]
w.type = 'user' w.type = 'user'
@@ -442,4 +459,5 @@ class NumberOfModelRuns(UserObjectSingle):
try: try:
grid.numberofmodelruns = self.kwargs['n'] grid.numberofmodelruns = self.kwargs['n']
except KeyError: except KeyError:
raise CmdInputError('#numberofmodelruns: requires exactly one parameter') logger.exception(self.__str__() + ' requires exactly one parameter')
raise

查看文件

@@ -23,7 +23,6 @@ import sys
import gprMax.config as config import gprMax.config as config
from ._version import __version__, codename from ._version import __version__, codename
from .exceptions import GeneralError
from .model_build_run import ModelBuildRun from .model_build_run import ModelBuildRun
from .solvers import create_G, create_solver from .solvers import create_G, create_solver
from .utilities import get_terminal_width, human_size, logo, timer from .utilities import get_terminal_width, human_size, logo, timer
@@ -150,7 +149,8 @@ class MPIContext(Context):
if executor.is_master(): if executor.is_master():
if config.sim_config.general['cuda']: if config.sim_config.general['cuda']:
if executor.size - 1 > len(config.sim_config.cuda['gpus']): if executor.size - 1 > len(config.sim_config.cuda['gpus']):
raise GeneralError(f'Not enough GPU resources for number of MPI tasks requested. Number of MPI tasks should be equal to number of GPUs + 1.') logger.exception('Not enough GPU resources for number of MPI tasks requested. Number of MPI tasks should be equal to number of GPUs + 1.')
raise ValueError
# Create job list # Create job list
jobs = [] jobs = []

查看文件

@@ -23,7 +23,6 @@ import gprMax.config as config
import numpy as np import numpy as np
from colorama import Fore, Style, init from colorama import Fore, Style, init
init() init()
from .exceptions import GeneralError
from .pml import CFS, PML from .pml import CFS, PML
from .utilities import fft_power, human_size, round_value from .utilities import fft_power, human_size, round_value

查看文件

@@ -24,7 +24,6 @@ from pathlib import Path
import gprMax.config as config import gprMax.config as config
from .exceptions import CmdInputError
from .hash_cmds_geometry import process_geometrycmds from .hash_cmds_geometry import process_geometrycmds
from .hash_cmds_multiuse import process_multicmds from .hash_cmds_multiuse import process_multicmds
from .hash_cmds_singleuse import process_singlecmds from .hash_cmds_singleuse import process_singlecmds
@@ -72,7 +71,8 @@ def process_python_include_code(inputfile, usernamespace):
pythoncode += inputlines[x] + '\n' pythoncode += inputlines[x] + '\n'
x += 1 x += 1
if x == len(inputlines): if x == len(inputlines):
raise CmdInputError('Cannot find the end of the Python code block, i.e. missing #end_python: command.') logger.exception('Cannot find the end of the Python code block, i.e. missing #end_python: command.')
raise SyntaxError
# Compile code for faster execution # Compile code for faster execution
pythoncompiledcode = compile(pythoncode, '<string>', 'exec') pythoncompiledcode = compile(pythoncode, '<string>', 'exec')
# Redirect stdout to a text stream # Redirect stdout to a text stream
@@ -136,7 +136,8 @@ def process_include_files(hashcmds, inputfile):
includefile = hashcmds[x].split() includefile = hashcmds[x].split()
if len(includefile) != 2: if len(includefile) != 2:
raise CmdInputError('#include_file requires exactly one parameter') logger.exception('#include_file requires exactly one parameter')
raise ValueError
includefile = includefile[1] includefile = includefile[1]
@@ -223,11 +224,13 @@ def check_cmd_names(processedlines, checkessential=True):
# check first character of parameter string. Ignore case when there # check first character of parameter string. Ignore case when there
# are no parameters for a command, e.g. for #taguchi: # are no parameters for a command, e.g. for #taguchi:
if ' ' not in cmdparams[0] and len(cmdparams.strip('\n')) != 0: if ' ' not in cmdparams[0] and len(cmdparams.strip('\n')) != 0:
raise CmdInputError('There must be a space between the command name and parameters in ' + processedlines[lindex]) logger.exception('There must be a space between the command name and parameters in ' + processedlines[lindex])
raise SyntaxError
# Check if command name is valid # Check if command name is valid
if cmdname not in essentialcmds and cmdname not in singlecmds and cmdname not in multiplecmds and cmdname not in geometrycmds: if cmdname not in essentialcmds and cmdname not in singlecmds and cmdname not in multiplecmds and cmdname not in geometrycmds:
raise CmdInputError('Your input file contains an invalid command: ' + cmdname) logger.exception('Your input file contains an invalid command: ' + cmdname)
raise SyntaxError
# Count essential commands # Count essential commands
if cmdname in essentialcmds: if cmdname in essentialcmds:
@@ -238,7 +241,8 @@ def check_cmd_names(processedlines, checkessential=True):
if singlecmds[cmdname] is None: if singlecmds[cmdname] is None:
singlecmds[cmdname] = cmd[1].strip(' \t\n') singlecmds[cmdname] = cmd[1].strip(' \t\n')
else: else:
raise CmdInputError('You can only have a single instance of ' + cmdname + ' in your model') logger.exception('You can only have a single instance of ' + cmdname + ' in your model')
raise SyntaxError
elif cmdname in multiplecmds: elif cmdname in multiplecmds:
multiplecmds[cmdname].append(cmd[1].strip(' \t\n')) multiplecmds[cmdname].append(cmd[1].strip(' \t\n'))
@@ -250,7 +254,8 @@ def check_cmd_names(processedlines, checkessential=True):
if checkessential: if checkessential:
if (countessentialcmds < len(essentialcmds)): if (countessentialcmds < len(essentialcmds)):
raise CmdInputError('Your input file is missing essential commands required to run a model. Essential commands are: ' + ', '.join(essentialcmds)) logger.exception('Your input file is missing essential commands required to run a model. Essential commands are: ' + ', '.join(essentialcmds))
raise SyntaxError
return singlecmds, multiplecmds, geometry return singlecmds, multiplecmds, geometry

查看文件

@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
import numpy as np import numpy as np
from .cmds_geometry.add_grass import AddGrass from .cmds_geometry.add_grass import AddGrass
@@ -29,9 +30,10 @@ from .cmds_geometry.fractal_box import FractalBox
from .cmds_geometry.plate import Plate from .cmds_geometry.plate import Plate
from .cmds_geometry.sphere import Sphere from .cmds_geometry.sphere import Sphere
from .cmds_geometry.triangle import Triangle from .cmds_geometry.triangle import Triangle
from .exceptions import CmdInputError
from .utilities import round_value from .utilities import round_value
logger = logging.getLogger(__name__)
def process_geometrycmds(geometry): def process_geometrycmds(geometry):
""" """
@@ -55,7 +57,8 @@ def process_geometrycmds(geometry):
from .cmds_geometry.geometry_objects_read import GeometryObjectsRead from .cmds_geometry.geometry_objects_read import GeometryObjectsRead
if len(tmp) != 6: if len(tmp) != 6:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires exactly five parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires exactly five parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
@@ -64,7 +67,8 @@ def process_geometrycmds(geometry):
elif tmp[0] == '#edge:': elif tmp[0] == '#edge:':
if len(tmp) != 8: if len(tmp) != 8:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires exactly seven parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires exactly seven parameters')
raise ValueError
edge = Edge(p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), edge = Edge(p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])),
p2=(float(tmp[4]), float(tmp[5]), float(tmp[6])), p2=(float(tmp[4]), float(tmp[5]), float(tmp[6])),
@@ -74,7 +78,8 @@ def process_geometrycmds(geometry):
elif tmp[0] == '#plate:': elif tmp[0] == '#plate:':
if len(tmp) < 8: if len(tmp) < 8:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least seven parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least seven parameters')
raise ValueError
# Isotropic case # Isotropic case
if len(tmp) == 8: if len(tmp) == 8:
@@ -89,13 +94,15 @@ def process_geometrycmds(geometry):
material_ids=tmp[7:]) material_ids=tmp[7:])
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(plate) scene_objects.append(plate)
elif tmp[0] == '#triangle:': elif tmp[0] == '#triangle:':
if len(tmp) < 12: if len(tmp) < 12:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least eleven parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least eleven parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -115,13 +122,15 @@ def process_geometrycmds(geometry):
triangle = Triangle(p1=p1, p2=p2, p3=p3, thickness=thickness, material_ids=tmp[11:]) triangle = Triangle(p1=p1, p2=p2, p3=p3, thickness=thickness, material_ids=tmp[11:])
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(triangle) scene_objects.append(triangle)
elif tmp[0] == '#box:': elif tmp[0] == '#box:':
if len(tmp) < 8: if len(tmp) < 8:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least seven parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least seven parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -139,13 +148,15 @@ def process_geometrycmds(geometry):
box = Box(p1=p1, p2=p2, material_ids=tmp[7:]) box = Box(p1=p1, p2=p2, material_ids=tmp[7:])
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(box) scene_objects.append(box)
elif tmp[0] == '#cylinder:': elif tmp[0] == '#cylinder:':
if len(tmp) < 9: if len(tmp) < 9:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least eight parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least eight parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -164,13 +175,15 @@ def process_geometrycmds(geometry):
cylinder = Cylinder(p1=p1, p2=p2, r=r, material_ids=tmp[8:]) cylinder = Cylinder(p1=p1, p2=p2, r=r, material_ids=tmp[8:])
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(cylinder) scene_objects.append(cylinder)
elif tmp[0] == '#cylindrical_sector:': elif tmp[0] == '#cylindrical_sector:':
if len(tmp) < 10: if len(tmp) < 10:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least nine parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least nine parameters')
raise ValueError
normal = tmp[1].lower() normal = tmp[1].lower()
ctr1 = float(tmp[2]) ctr1 = float(tmp[2])
@@ -197,13 +210,15 @@ def process_geometrycmds(geometry):
extent2=extent2, r=r, start=start, end=end, material_ids=tmp[9:]) extent2=extent2, r=r, start=start, end=end, material_ids=tmp[9:])
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(cylindrical_sector) scene_objects.append(cylindrical_sector)
elif tmp[0] == '#sphere:': elif tmp[0] == '#sphere:':
if len(tmp) < 6: if len(tmp) < 6:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least five parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least five parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
r = float(tmp[4]) r = float(tmp[4])
@@ -221,7 +236,8 @@ def process_geometrycmds(geometry):
sphere = Sphere(p1=p1, r=r, material_id=tmp[5:]) sphere = Sphere(p1=p1, r=r, material_id=tmp[5:])
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(sphere) scene_objects.append(sphere)
@@ -229,7 +245,8 @@ def process_geometrycmds(geometry):
# Default is no dielectric smoothing for a fractal box # Default is no dielectric smoothing for a fractal box
if len(tmp) < 14: if len(tmp) < 14:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least thirteen parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least thirteen parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -246,7 +263,8 @@ def process_geometrycmds(geometry):
elif len(tmp) == 16: elif len(tmp) == 16:
fb = FractalBox(p1=p1, p2=p2, frac_dim=frac_dim, weighting=weighting, mixing_model_id=mixing_model_id, id=ID, n_materials=n_materials, seed=tmp[14], averaging=tmp[15].lower()) fb = FractalBox(p1=p1, p2=p2, frac_dim=frac_dim, weighting=weighting, mixing_model_id=mixing_model_id, id=ID, n_materials=n_materials, seed=tmp[14], averaging=tmp[15].lower())
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(fb) scene_objects.append(fb)
@@ -256,7 +274,8 @@ def process_geometrycmds(geometry):
if tmp[0] == '#add_surface_roughness:': if tmp[0] == '#add_surface_roughness:':
if len(tmp) < 13: if len(tmp) < 13:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least twelve parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least twelve parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -270,13 +289,15 @@ def process_geometrycmds(geometry):
elif len(tmp) == 14: elif len(tmp) == 14:
asr = AddSurfaceRoughness(p1=p1, p2=p2, frac_dim=frac_dim, weighting=weighting, limits=limits, fractal_box_id=fractal_box_id, seed=int(tmp[13])) asr = AddSurfaceRoughness(p1=p1, p2=p2, frac_dim=frac_dim, weighting=weighting, limits=limits, fractal_box_id=fractal_box_id, seed=int(tmp[13]))
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(asr) scene_objects.append(asr)
if tmp[0] == '#add_surface_water:': if tmp[0] == '#add_surface_water:':
if len(tmp) != 9: if len(tmp) != 9:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires exactly eight parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires exactly eight parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -288,7 +309,8 @@ def process_geometrycmds(geometry):
if tmp[0] == '#add_grass:': if tmp[0] == '#add_grass:':
if len(tmp) < 12: if len(tmp) < 12:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least eleven parameters') logger.exception("'" + ' '.join(tmp) + "'" + ' requires at least eleven parameters')
raise ValueError
p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3])) p1 = (float(tmp[1]), float(tmp[2]), float(tmp[3]))
p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6])) p2 = (float(tmp[4]), float(tmp[5]), float(tmp[6]))
@@ -302,7 +324,8 @@ def process_geometrycmds(geometry):
elif len(tmp) == 13: elif len(tmp) == 13:
grass = AddGrass(p1=p1, p2=p2, frac_dim=frac_dim, limits=limits, n_blades=n_blades, fractal_box_id=fractal_box_id, seed=int(tmp[12])) grass = AddGrass(p1=p1, p2=p2, frac_dim=frac_dim, limits=limits, n_blades=n_blades, fractal_box_id=fractal_box_id, seed=int(tmp[12]))
else: else:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' too many parameters have been given') logger.exception("'" + ' '.join(tmp) + "'" + ' too many parameters have been given')
raise ValueError
scene_objects.append(grass) scene_objects.append(grass)

查看文件

@@ -16,12 +16,15 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
from .cmds_multiple import (PMLCFS, AddDebyeDispersion, AddDrudeDispersion, from .cmds_multiple import (PMLCFS, AddDebyeDispersion, AddDrudeDispersion,
AddLorentzDispersion, GeometryObjectsWrite, AddLorentzDispersion, GeometryObjectsWrite,
GeometryView, HertzianDipole, MagneticDipole, GeometryView, HertzianDipole, MagneticDipole,
Material, Rx, RxArray, Snapshot, SoilPeplinski, Material, Rx, RxArray, Snapshot, SoilPeplinski,
TransmissionLine, VoltageSource, Waveform) TransmissionLine, VoltageSource, Waveform)
from .exceptions import CmdInputError
logger = logging.getLogger(__name__)
def process_multicmds(multicmds): def process_multicmds(multicmds):
@@ -43,7 +46,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 4: if len(tmp) != 4:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly four parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly four parameters')
raise ValueError
waveform = Waveform(wave_type=tmp[0], amp=float(tmp[1]), freq=float(tmp[2]), id=tmp[3]) waveform = Waveform(wave_type=tmp[0], amp=float(tmp[1]), freq=float(tmp[2]), id=tmp[3])
scene_objects.append(waveform) scene_objects.append(waveform)
@@ -57,7 +61,8 @@ def process_multicmds(multicmds):
elif len(tmp) == 8: elif len(tmp) == 8:
voltage_source = VoltageSource(polarisation=tmp[0].lower(), p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), resistance=float(tmp[4]), waveform_id=tmp[5], start=float(tmp[6]), end=float(tmp[7])) voltage_source = VoltageSource(polarisation=tmp[0].lower(), p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), resistance=float(tmp[4]), waveform_id=tmp[5], start=float(tmp[6]), end=float(tmp[7]))
else: else:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least six parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least six parameters')
raise ValueError
scene_objects.append(voltage_source) scene_objects.append(voltage_source)
@@ -66,13 +71,15 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) < 5: if len(tmp) < 5:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters')
raise ValueError
if len(tmp) == 5: if len(tmp) == 5:
hertzian_dipole = HertzianDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4]) hertzian_dipole = HertzianDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4])
elif len(tmp) == 7: elif len(tmp) == 7:
hertzian_dipole = HertzianDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4], start=float(tmp[5]), end=float(tmp[6])) hertzian_dipole = HertzianDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4], start=float(tmp[5]), end=float(tmp[6]))
else: else:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' too many parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' too many parameters')
raise ValueError
scene_objects.append(hertzian_dipole) scene_objects.append(hertzian_dipole)
@@ -81,13 +88,15 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) < 5: if len(tmp) < 5:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters')
raise ValueError
if len(tmp) == 5: if len(tmp) == 5:
magnetic_dipole = MagneticDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4]) magnetic_dipole = MagneticDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4])
elif len(tmp) == 7: elif len(tmp) == 7:
magnetic_dipole = MagneticDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4], start=float(tmp[5]), end=float(tmp[6])) magnetic_dipole = MagneticDipole(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), waveform_id=tmp[4], start=float(tmp[5]), end=float(tmp[6]))
else: else:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' too many parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' too many parameters')
raise ValueError
scene_objects.append(magnetic_dipole) scene_objects.append(magnetic_dipole)
@@ -96,14 +105,16 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) < 6: if len(tmp) < 6:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least six parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least six parameters')
raise ValueError
if len(tmp) == 6: if len(tmp) == 6:
tl = TransmissionLine(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), resistance=float(tmp[4]), waveform_id=tmp[5]) tl = TransmissionLine(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), resistance=float(tmp[4]), waveform_id=tmp[5])
elif len(tmp) == 8: elif len(tmp) == 8:
tl = TransmissionLine(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), resistance=float(tmp[4]), waveform_id=tmp[5], start=tmp[6], end=tmp[7]) tl = TransmissionLine(polarisation=tmp[0], p1=(float(tmp[1]), float(tmp[2]), float(tmp[3])), resistance=float(tmp[4]), waveform_id=tmp[5], start=tmp[6], end=tmp[7])
else: else:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' too many parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' too many parameters')
raise ValueError
scene_objects.append(tl) scene_objects.append(tl)
@@ -112,7 +123,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 3 and len(tmp) < 5: if len(tmp) != 3 and len(tmp) < 5:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' has an incorrect number of parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' has an incorrect number of parameters')
raise ValueError
if len(tmp) == 3: if len(tmp) == 3:
rx = Rx(p1=(float(tmp[0]), float(tmp[1]), float(tmp[2]))) rx = Rx(p1=(float(tmp[0]), float(tmp[1]), float(tmp[2])))
else: else:
@@ -125,7 +137,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 9: if len(tmp) != 9:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly nine parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly nine parameters')
raise ValueError
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2])) p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
p2 = (float(tmp[3]), float(tmp[4]), float(tmp[5])) p2 = (float(tmp[3]), float(tmp[4]), float(tmp[5]))
@@ -139,7 +152,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 11: if len(tmp) != 11:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly eleven parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly eleven parameters')
raise ValueError
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2])) p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
p2 = (float(tmp[3]), float(tmp[4]), float(tmp[5])) p2 = (float(tmp[3]), float(tmp[4]), float(tmp[5]))
@@ -161,7 +175,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 5: if len(tmp) != 5:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly five parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly five parameters')
raise ValueError
material = Material(er=float(tmp[0]), se=float(tmp[1]), mr=float(tmp[2]), sm=float(tmp[3]), id=tmp[4]) material = Material(er=float(tmp[0]), se=float(tmp[1]), mr=float(tmp[2]), sm=float(tmp[3]), id=tmp[4])
scene_objects.append(material) scene_objects.append(material)
@@ -172,7 +187,8 @@ def process_multicmds(multicmds):
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) < 4: if len(tmp) < 4:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least four parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least four parameters')
raise ValueError
poles = int(tmp[0]) poles = int(tmp[0])
er_delta = [] er_delta = []
@@ -192,7 +208,8 @@ def process_multicmds(multicmds):
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) < 5: if len(tmp) < 5:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters')
raise ValueError
poles = int(tmp[0]) poles = int(tmp[0])
material_ids = tmp[(3 * poles) + 1:len(tmp)] material_ids = tmp[(3 * poles) + 1:len(tmp)]
@@ -214,7 +231,8 @@ def process_multicmds(multicmds):
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) < 5: if len(tmp) < 5:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at least five parameters')
raise ValueError
poles = int(tmp[0]) poles = int(tmp[0])
material_ids = tmp[(3 * poles) + 1:len(tmp)] material_ids = tmp[(3 * poles) + 1:len(tmp)]
@@ -234,7 +252,8 @@ def process_multicmds(multicmds):
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 7: if len(tmp) != 7:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at exactly seven parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires at exactly seven parameters')
raise ValueError
soil = SoilPeplinski(sand_fraction=float(tmp[0]), soil = SoilPeplinski(sand_fraction=float(tmp[0]),
clay_fraction=float(tmp[1]), clay_fraction=float(tmp[1]),
bulk_density=float(tmp[2]), bulk_density=float(tmp[2]),
@@ -249,7 +268,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 11: if len(tmp) != 11:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly eleven parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly eleven parameters')
raise ValueError
p1 = float(tmp[0]), float(tmp[1]), float(tmp[2]) p1 = float(tmp[0]), float(tmp[1]), float(tmp[2])
p2 = float(tmp[3]), float(tmp[4]), float(tmp[5]) p2 = float(tmp[3]), float(tmp[4]), float(tmp[5])
@@ -263,7 +283,8 @@ def process_multicmds(multicmds):
for cmdinstance in multicmds[cmdname]: for cmdinstance in multicmds[cmdname]:
tmp = cmdinstance.split() tmp = cmdinstance.split()
if len(tmp) != 7: if len(tmp) != 7:
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly seven parameters') logger.exception("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly seven parameters')
raise ValueError
p1 = float(tmp[0]), float(tmp[1]), float(tmp[2]) p1 = float(tmp[0]), float(tmp[1]), float(tmp[2])
p2 = float(tmp[3]), float(tmp[4]), float(tmp[5]) p2 = float(tmp[3]), float(tmp[4]), float(tmp[5])

查看文件

@@ -16,11 +16,14 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
from .cmds_single_use import (Discretisation, Domain, ExcitationFile, from .cmds_single_use import (Discretisation, Domain, ExcitationFile,
NumThreads, OutputDir, PMLCells, RxSteps, NumThreads, OutputDir, PMLCells, RxSteps,
SrcSteps, TimeStepStabilityFactor, TimeWindow, SrcSteps, TimeStepStabilityFactor, TimeWindow,
Title) Title)
from .exceptions import CmdInputError
logger = logging.getLogger(__name__)
def process_singlecmds(singlecmds): def process_singlecmds(singlecmds):
@@ -53,7 +56,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = tuple(int(x) for x in singlecmds[cmd].split()) tmp = tuple(int(x) for x in singlecmds[cmd].split())
if len(tmp) != 1: if len(tmp) != 1:
raise CmdInputError(cmd + ' requires exactly one parameter to specify the number of threads to use') logger.exception(cmd + ' requires exactly one parameter to specify the number of threads to use')
raise ValueError
num_thread = NumThreads(n=tmp[0]) num_thread = NumThreads(n=tmp[0])
scene_objects.append(num_thread) scene_objects.append(num_thread)
@@ -62,7 +66,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = [float(x) for x in singlecmds[cmd].split()] tmp = [float(x) for x in singlecmds[cmd].split()]
if len(tmp) != 3: if len(tmp) != 3:
raise CmdInputError(cmd + ' requires exactly three parameters') logger.exception(cmd + ' requires exactly three parameters')
raise ValueError
dl = (tmp[0], tmp[1], tmp[2]) dl = (tmp[0], tmp[1], tmp[2])
discretisation = Discretisation(p1=dl) discretisation = Discretisation(p1=dl)
@@ -72,7 +77,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = [float(x) for x in singlecmds[cmd].split()] tmp = [float(x) for x in singlecmds[cmd].split()]
if len(tmp) != 3: if len(tmp) != 3:
raise CmdInputError(cmd + ' requires exactly three parameters') logger.exception(cmd + ' requires exactly three parameters')
raise ValueError
p1 = (tmp[0], tmp[1], tmp[2]) p1 = (tmp[0], tmp[1], tmp[2])
domain = Domain(p1=p1) domain = Domain(p1=p1)
@@ -88,7 +94,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split() tmp = singlecmds[cmd].split()
if len(tmp) != 1: if len(tmp) != 1:
raise CmdInputError(cmd + ' requires exactly one parameter to specify the time window. Either in seconds or number of iterations.') logger.exception(cmd + ' requires exactly one parameter to specify the time window. Either in seconds or number of iterations.')
raise ValueError
tmp = tmp[0].lower() tmp = tmp[0].lower()
# If number of iterations given # If number of iterations given
@@ -106,7 +113,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split() tmp = singlecmds[cmd].split()
if len(tmp) != 1 and len(tmp) != 6: if len(tmp) != 1 and len(tmp) != 6:
raise CmdInputError(cmd + ' requires either one or six parameter(s)') logger.exception(cmd + ' requires either one or six parameter(s)')
raise ValueError
if len(tmp) == 1: if len(tmp) == 1:
pml_cells = PMLCells(thickness=int(tmp[0])) pml_cells = PMLCells(thickness=int(tmp[0]))
else: else:
@@ -123,7 +131,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split() tmp = singlecmds[cmd].split()
if len(tmp) != 3: if len(tmp) != 3:
raise CmdInputError(cmd + ' requires exactly three parameters') logger.exception(cmd + ' requires exactly three parameters')
raise ValueError
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2])) p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
src_steps = SrcSteps(p1=p1) src_steps = SrcSteps(p1=p1)
@@ -133,7 +142,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split() tmp = singlecmds[cmd].split()
if len(tmp) != 3: if len(tmp) != 3:
raise CmdInputError(cmd + ' requires exactly three parameters') logger.exception(cmd + ' requires exactly three parameters')
raise ValueError
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2])) p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
rx_steps = RxSteps(p1=p1) rx_steps = RxSteps(p1=p1)
@@ -144,7 +154,8 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None: if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split() tmp = singlecmds[cmd].split()
if len(tmp) != 1 and len(tmp) != 3: if len(tmp) != 1 and len(tmp) != 3:
raise CmdInputError(cmd + ' requires either one or three parameter(s)') logger.exception(cmd + ' requires either one or three parameter(s)')
raise ValueError
if len(tmp) > 1: if len(tmp) > 1:
ex_file = ExcitationFile(filepath=tmp[0], kind=tmp[1], fill_value=tmp[2]) ex_file = ExcitationFile(filepath=tmp[0], kind=tmp[1], fill_value=tmp[2])

查看文件

@@ -33,7 +33,6 @@ from tqdm import tqdm
from .cython.yee_cell_build import (build_electric_components, from .cython.yee_cell_build import (build_electric_components,
build_magnetic_components) build_magnetic_components)
from .exceptions import GeneralError
from .fields_outputs import write_hdf5_outputfile from .fields_outputs import write_hdf5_outputfile
from .grid import dispersion_analysis from .grid import dispersion_analysis
from .hash_cmds_file import parse_hash_commands from .hash_cmds_file import parse_hash_commands
@@ -85,7 +84,8 @@ class ModelBuildRun:
source.ycoord + G.srcsteps[1] * config.sim_config.model_end > G.ny or source.ycoord + G.srcsteps[1] * config.sim_config.model_end > G.ny or
source.zcoord + G.srcsteps[2] * config.sim_config.model_end < 0 or source.zcoord + G.srcsteps[2] * config.sim_config.model_end < 0 or
source.zcoord + G.srcsteps[2] * config.sim_config.model_end > G.nz): source.zcoord + G.srcsteps[2] * config.sim_config.model_end > G.nz):
raise GeneralError('Source(s) will be stepped to a position outside the domain.') logger.exception('Source(s) will be stepped to a position outside the domain.')
raise ValueError
source.xcoord = source.xcoordorigin + config.model_num * G.srcsteps[0] source.xcoord = source.xcoordorigin + config.model_num * G.srcsteps[0]
source.ycoord = source.ycoordorigin + config.model_num * G.srcsteps[1] source.ycoord = source.ycoordorigin + config.model_num * G.srcsteps[1]
source.zcoord = source.zcoordorigin + config.model_num * G.srcsteps[2] source.zcoord = source.zcoordorigin + config.model_num * G.srcsteps[2]
@@ -98,7 +98,8 @@ class ModelBuildRun:
receiver.ycoord + G.rxsteps[1] * config.sim_config.model_end > G.ny or receiver.ycoord + G.rxsteps[1] * config.sim_config.model_end > G.ny or
receiver.zcoord + G.rxsteps[2] * config.sim_config.model_end < 0 or receiver.zcoord + G.rxsteps[2] * config.sim_config.model_end < 0 or
receiver.zcoord + G.rxsteps[2] * config.sim_config.model_end > G.nz): receiver.zcoord + G.rxsteps[2] * config.sim_config.model_end > G.nz):
raise GeneralError('Receiver(s) will be stepped to a position outside the domain.') logger.exception('Receiver(s) will be stepped to a position outside the domain.')
raise ValueError
receiver.xcoord = receiver.xcoordorigin + config.model_num * G.rxsteps[0] receiver.xcoord = receiver.xcoordorigin + config.model_num * G.rxsteps[0]
receiver.ycoord = receiver.ycoordorigin + config.model_num * G.rxsteps[1] receiver.ycoord = receiver.ycoordorigin + config.model_num * G.rxsteps[1]
receiver.zcoord = receiver.zcoordorigin + config.model_num * G.rxsteps[2] receiver.zcoord = receiver.zcoordorigin + config.model_num * G.rxsteps[2]
@@ -172,7 +173,8 @@ class ModelBuildRun:
if results['error']: if results['error']:
logger.warning(Fore.RED + f"\nNumerical dispersion analysis [{gb.grid.name}] not carried out as {results['error']}" + Style.RESET_ALL) logger.warning(Fore.RED + f"\nNumerical dispersion analysis [{gb.grid.name}] not carried out as {results['error']}" + Style.RESET_ALL)
elif results['N'] < config.get_model_config().numdispersion['mingridsampling']: elif results['N'] < config.get_model_config().numdispersion['mingridsampling']:
raise GeneralError(f"\nNon-physical wave propagation in [{gb.grid.name}] detected. Material '{results['material'].ID}' has wavelength sampled by {results['N']} cells, less than required minimum for physical wave propagation. Maximum significant frequency estimated as {results['maxfreq']:g}Hz") logger.exception(f"\nNon-physical wave propagation in [{gb.grid.name}] detected. Material '{results['material'].ID}' has wavelength sampled by {results['N']} cells, less than required minimum for physical wave propagation. Maximum significant frequency estimated as {results['maxfreq']:g}Hz")
raise ValueError
elif (results['deltavp'] and np.abs(results['deltavp']) > elif (results['deltavp'] and np.abs(results['deltavp']) >
config.get_model_config().numdispersion['maxnumericaldisp']): config.get_model_config().numdispersion['maxnumericaldisp']):
logger.warning(Fore.RED + f"\n[{gb.grid.name}] has potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {results['deltavp']:.2f}% in material '{results['material'].ID}' whose wavelength sampled by {results['N']} cells. Maximum significant frequency estimated as {results['maxfreq']:g}Hz" + Style.RESET_ALL) logger.warning(Fore.RED + f"\n[{gb.grid.name}] has potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {results['deltavp']:.2f}% in material '{results['material'].ID}' whose wavelength sampled by {results['N']} cells. Maximum significant frequency estimated as {results['maxfreq']:g}Hz" + Style.RESET_ALL)

查看文件

@@ -23,7 +23,6 @@ from .cmds_geometry.fractal_box_builder import FractalBoxBuilder
from .cmds_multiple import UserObjectMulti from .cmds_multiple import UserObjectMulti
from .cmds_single_use import (Discretisation, Domain, TimeWindow, from .cmds_single_use import (Discretisation, Domain, TimeWindow,
UserObjectSingle) UserObjectSingle)
from .exceptions import CmdInputError, GeneralError
from .materials import create_built_in_materials from .materials import create_built_in_materials
from .subgrids.user_objects import SubGridBase as SubGridUserBase from .subgrids.user_objects import SubGridBase as SubGridUserBase
from .user_inputs import create_user_input_points from .user_inputs import create_user_input_points
@@ -54,7 +53,8 @@ class Scene:
elif isinstance(user_object, UserObjectSingle): elif isinstance(user_object, UserObjectSingle):
self.single_cmds.append(user_object) self.single_cmds.append(user_object)
else: else:
raise GeneralError('This object is unknown to gprMax') logger.exception('This object is unknown to gprMax')
raise ValueError
def process_subgrid_commands(self, subgrids): def process_subgrid_commands(self, subgrids):
# Check for subgrid user objects # Check for subgrid user objects
@@ -90,8 +90,9 @@ class Scene:
# points belong to. # points belong to.
try: try:
obj.create(grid, uip) obj.create(grid, uip)
except CmdInputError: except ValueError:
logger.exception('Error creating user input object') logger.exception('Error creating user input object')
raise
return self return self
@@ -99,13 +100,15 @@ class Scene:
# Check for duplicate commands and warn user if they exist # Check for duplicate commands and warn user if they exist
cmds_unique = list(set(self.single_cmds)) cmds_unique = list(set(self.single_cmds))
if len(cmds_unique) != len(self.single_cmds): if len(cmds_unique) != len(self.single_cmds):
raise CmdInputError('Duplicate single-use commands exist in the input.') logger.exception('Duplicate single-use commands exist in the input.')
raise ValueError
# Check essential commands and warn user if missing # Check essential commands and warn user if missing
for cmd_type in self.essential_cmds: for cmd_type in self.essential_cmds:
d = any([isinstance(cmd, cmd_type) for cmd in cmds_unique]) d = any([isinstance(cmd, cmd_type) for cmd in cmds_unique])
if not d: if not d:
raise CmdInputError('Your input file is missing essential commands required to run a model. Essential commands are: Domain, Discretisation, Time Window') logger.exception('Your input file is missing essential commands required to run a model. Essential commands are: Domain, Discretisation, Time Window')
raise ValueError
self.process_cmds(cmds_unique, G) self.process_cmds(cmds_unique, G)

查看文件

@@ -29,7 +29,6 @@ from .cython.fields_updates_normal import \
update_electric as update_electric_cpu update_electric as update_electric_cpu
from .cython.fields_updates_normal import \ from .cython.fields_updates_normal import \
update_magnetic as update_magnetic_cpu update_magnetic as update_magnetic_cpu
from .exceptions import GeneralError
from .fields_outputs import kernel_template_store_outputs from .fields_outputs import kernel_template_store_outputs
from .fields_outputs import store_outputs as store_outputs_cpu from .fields_outputs import store_outputs as store_outputs_cpu
from .receivers import dtoh_rx_array, htod_rx_arrays from .receivers import dtoh_rx_array, htod_rx_arrays
@@ -445,7 +444,8 @@ class CUDAUpdates:
# Check if coefficient arrays will fit on constant memory of GPU # Check if coefficient arrays will fit on constant memory of GPU
if (self.grid.updatecoeffsE.nbytes + self.grid.updatecoeffsH.nbytes if (self.grid.updatecoeffsE.nbytes + self.grid.updatecoeffsH.nbytes
> config.get_model_config().cuda['gpu'].constmem): > config.get_model_config().cuda['gpu'].constmem):
raise GeneralError(f"Too many materials in the model to fit onto constant memory of size {human_size(config.get_model_config().cuda['gpu'].constmem)} on {config.get_model_config().cuda['gpu'].deviceID} - {config.get_model_config().cuda['gpu'].name} GPU") logger.exception(f"Too many materials in the model to fit onto constant memory of size {human_size(config.get_model_config().cuda['gpu'].constmem)} on {config.get_model_config().cuda['gpu'].deviceID} - {config.get_model_config().cuda['gpu'].name} GPU")
raise ValueError
updatecoeffsE = kernelE.get_global('updatecoeffsE')[0] updatecoeffsE = kernelE.get_global('updatecoeffsE')[0]
updatecoeffsH = kernelH.get_global('updatecoeffsH')[0] updatecoeffsH = kernelH.get_global('updatecoeffsH')[0]

查看文件

@@ -22,7 +22,6 @@ import gprMax.config as config
import numpy as np import numpy as np
from colorama import Fore, Style, init from colorama import Fore, Style, init
init() init()
from .exceptions import CmdInputError
from .subgrids.base import SubGridBase from .subgrids.base import SubGridBase
from .utilities import round_value from .utilities import round_value
@@ -103,7 +102,7 @@ class MainGridUserInput(UserInput):
p = self.check_point(p, cmd_str, name) p = self.check_point(p, cmd_str, name)
if self.grid.within_pml(p): if self.grid.within_pml(p):
logger.warning(Fore.RED + f"'{cmd_str}' sources and receivers should not normally be positioned within the PML." + Style.RESET_ALL) logger.warning(f"'{cmd_str}' sources and receivers should not normally be positioned within the PML.")
return p return p
@@ -112,7 +111,8 @@ class MainGridUserInput(UserInput):
p2 = self.check_point(p2, cmd_str, name='upper') p2 = self.check_point(p2, cmd_str, name='upper')
if np.greater(p1, p2).any(): if np.greater(p1, p2).any():
raise CmdInputError(logger.exception(f"'{cmd_str}' the lower coordinates should be less than the upper coordinates.")) logger.exception(f"'{cmd_str}' the lower coordinates should be less than the upper coordinates.")
raise ValueError
return p1, p2 return p1, p2

查看文件

@@ -432,7 +432,7 @@ def mem_check_host(mem):
""" """
if mem > config.sim_config.hostinfo['ram']: if mem > config.sim_config.hostinfo['ram']:
logger.exception(f"Memory (RAM) required ~{human_size(mem)} exceeds {human_size(config.sim_config.hostinfo['ram'], a_kilobyte_is_1024_bytes=True)} detected!\n") logger.exception(f"Memory (RAM) required ~{human_size(mem)} exceeds {human_size(config.sim_config.hostinfo['ram'], a_kilobyte_is_1024_bytes=True)} detected!\n")
raise raise ValueError
def mem_check_gpu_snaps(total_mem, snaps_mem): def mem_check_gpu_snaps(total_mem, snaps_mem):
@@ -445,7 +445,7 @@ def mem_check_gpu_snaps(total_mem, snaps_mem):
""" """
if total_mem - snaps_mem > config.get_model_config().cuda['gpu'].totalmem: if total_mem - snaps_mem > config.get_model_config().cuda['gpu'].totalmem:
logger.exception(f"Memory (RAM) required ~{human_size(total_mem)} exceeds {human_size(config.get_model_config().cuda['gpu'].totalmem, a_kilobyte_is_1024_bytes=True)} detected on specified {config.get_model_config().cuda['gpu'].deviceID} - {config.get_model_config().cuda['gpu'].name} GPU!\n") logger.exception(f"Memory (RAM) required ~{human_size(total_mem)} exceeds {human_size(config.get_model_config().cuda['gpu'].totalmem, a_kilobyte_is_1024_bytes=True)} detected on specified {config.get_model_config().cuda['gpu'].deviceID} - {config.get_model_config().cuda['gpu'].name} GPU!\n")
raise raise ValueError
# If the required memory without the snapshots will fit on the GPU then # If the required memory without the snapshots will fit on the GPU then
# transfer and store snaphots on host # transfer and store snaphots on host
@@ -548,7 +548,7 @@ def detect_gpus():
# Check and list any CUDA-Enabled GPUs # Check and list any CUDA-Enabled GPUs
if drv.Device.count() == 0: if drv.Device.count() == 0:
logger.exception('No NVIDIA CUDA-Enabled GPUs detected (https://developer.nvidia.com/cuda-gpus)') logger.exception('No NVIDIA CUDA-Enabled GPUs detected (https://developer.nvidia.com/cuda-gpus)')
raise raise ValueError
elif 'CUDA_VISIBLE_DEVICES' in os.environ: elif 'CUDA_VISIBLE_DEVICES' in os.environ:
deviceIDsavail = os.environ.get('CUDA_VISIBLE_DEVICES') deviceIDsavail = os.environ.get('CUDA_VISIBLE_DEVICES')
deviceIDsavail = [int(s) for s in deviceIDsavail.split(',')] deviceIDsavail = [int(s) for s in deviceIDsavail.split(',')]

查看文件

@@ -1,3 +1,21 @@
# Copyright (C) 2015-2020: The University of Edinburgh
# Authors: Craig Warren and Antonis Giannopoulos
#
# This file is part of gprMax.
#
# gprMax is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gprMax is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import numpy as np import numpy as np
import gprMax.config as config import gprMax.config as config

查看文件

@@ -23,7 +23,6 @@ from pathlib import Path
import h5py import h5py
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from gprMax.exceptions import CmdInputError
"""Plots a comparison of fields between given simulation output and experimental data files.""" """Plots a comparison of fields between given simulation output and experimental data files."""
@@ -50,7 +49,8 @@ else:
polarity = 1 polarity = 1
if args.output[0] not in availablecomponents: if args.output[0] not in availablecomponents:
raise CmdInputError(f"{args.output[0]} output requested to plot, but the available output for receiver 1 is {', '.join(availablecomponents)}") logger.exception(f"{args.output[0]} output requested to plot, but the available output for receiver 1 is {', '.join(availablecomponents)}")
raise ValueError
floattype = f[path + args.output[0]].dtype floattype = f[path + args.output[0]].dtype
iterations = f.attrs['Iterations'] iterations = f.attrs['Iterations']

查看文件

@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
import sys import sys
from pathlib import Path from pathlib import Path
@@ -25,9 +26,10 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
from colorama import Fore, Style, init from colorama import Fore, Style, init
init() init()
from gprMax.exceptions import GeneralError
from tests.analytical_solutions import hertzian_dipole_fs from tests.analytical_solutions import hertzian_dipole_fs
logger = logging.getLogger(__name__)
if sys.platform == 'linux': if sys.platform == 'linux':
plt.switch_backend('agg') plt.switch_backend('agg')
@@ -92,7 +94,8 @@ for i, model in enumerate(testmodels):
for ID, name in enumerate(outputstest): for ID, name in enumerate(outputstest):
datatest[:, ID] = filetest[path + str(name)][:] datatest[:, ID] = filetest[path + str(name)][:]
if np.any(np.isnan(datatest[:, ID])): if np.any(np.isnan(datatest[:, ID])):
raise GeneralError('Test data contains NaNs') logger.exception('Test data contains NaNs')
raise ValueError
# Tx/Rx position to feed to analytical solution # Tx/Rx position to feed to analytical solution
rxpos = filetest[path].attrs['Position'] rxpos = filetest[path].attrs['Position']
@@ -117,7 +120,8 @@ for i, model in enumerate(testmodels):
outputsref = list(fileref[path].keys()) outputsref = list(fileref[path].keys())
outputstest = list(filetest[path].keys()) outputstest = list(filetest[path].keys())
if outputsref != outputstest: if outputsref != outputstest:
raise GeneralError('Field output components do not match reference solution') logger.exception('Field output components do not match reference solution')
raise ValueError
# Check that type of float used to store fields matches # Check that type of float used to store fields matches
if filetest[path + outputstest[0]].dtype != fileref[path + outputsref[0]].dtype: if filetest[path + outputstest[0]].dtype != fileref[path + outputsref[0]].dtype:
@@ -138,7 +142,8 @@ for i, model in enumerate(testmodels):
dataref[:, ID] = fileref[path + str(name)][:] dataref[:, ID] = fileref[path + str(name)][:]
datatest[:, ID] = filetest[path + str(name)][:] datatest[:, ID] = filetest[path + str(name)][:]
if np.any(np.isnan(datatest[:, ID])): if np.any(np.isnan(datatest[:, ID])):
raise GeneralError('Test data contains NaNs') logger.exception('Test data contains NaNs')
raise ValueError
fileref.close() fileref.close()
filetest.close() filetest.close()

查看文件

@@ -17,8 +17,10 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse import argparse
import logging
logger = logging.getLogger(__name__)
from gprMax.exceptions import CmdInputError
"""Converts old to new style input files.""" """Converts old to new style input files."""
@@ -40,7 +42,7 @@ except:
newfile = inputfile newfile = inputfile
newfile += '_v3syntax' 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 model2D = False
txs = [] txs = []
@@ -62,7 +64,7 @@ while(lindex < len(inputlines)):
model2D = True model2D = True
# Syntax of old command: #dx_dy: x y # 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])) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -90,7 +92,7 @@ while(lindex < len(inputlines)):
if model2D: if model2D:
# Syntax of old command: #domain: x y # Syntax of old command: #domain: x y
replacement = '#domain: {:g} {:g} {:g}'.format(float(params[0]), float(params[1]), dx_dy_dz[2]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
domain = (float(params[0]), float(params[1]), dx_dy_dz[2]) domain = (float(params[0]), float(params[1]), dx_dy_dz[2])
@@ -110,7 +112,7 @@ while(lindex < len(inputlines)):
elif cmdname == '#num_of_procs': elif cmdname == '#num_of_procs':
# Syntax of old command: #num_of_procs: nthreads # Syntax of old command: #num_of_procs: nthreads
replacement = '#num_threads: {}'.format(params[0]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -139,7 +141,7 @@ while(lindex < len(inputlines)):
if model2D: if model2D:
# Syntax of old command: #rx: x1 y1 # Syntax of old command: #rx: x1 y1
replacement = '#rx: {} {} {}'.format(params[0], params[1], 0) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -151,7 +153,7 @@ while(lindex < len(inputlines)):
else: else:
# Syntax of old command: #rx_box: x1 y1 z1 x2 y2 z2 dx dy dz # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -163,7 +165,7 @@ while(lindex < len(inputlines)):
else: else:
# Syntax of old command: #tx_steps: dx dy dz # Syntax of old command: #tx_steps: dx dy dz
replacement = '#src_steps: {} {} {}'.format(params[0], params[1], params[2]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -175,7 +177,7 @@ while(lindex < len(inputlines)):
else: else:
# Syntax of old command: #rx_steps: dx dy dz # Syntax of old command: #rx_steps: dx dy dz
replacement = '#rx_steps: {} {} {}'.format(params[0], params[1], params[2]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -183,12 +185,12 @@ while(lindex < len(inputlines)):
elif cmdname == '#medium': elif cmdname == '#medium':
# Syntax of old command: #medium: e_rs e_inf tau sig_e mu_r sig_m ID # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
if float(params[1]) > 0: if float(params[1]) > 0:
replacement = '#add_dispersion_debye: 1 {} {} {}'.format(float(params[0]) - float(params[1]), params[2], params[6]) 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) inputlines.insert(lindex + 1, replacement)
lindex += 1 lindex += 1
@@ -196,7 +198,7 @@ while(lindex < len(inputlines)):
if model2D: if model2D:
# Syntax of old command: #box: x1 y1 x2 y2 ID # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 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 # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -217,13 +219,13 @@ while(lindex < len(inputlines)):
elif cmdname == '#wedge': elif cmdname == '#wedge':
# Syntax of old command: #wedge: x1 y1 z1 x2 y2 z2 x3 y3 z3 thickness ID # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
elif cmdname == '#bowtie': 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) inputlines.pop(lindex)
elif cmdname == '#cylinder': elif cmdname == '#cylinder':
@@ -239,7 +241,7 @@ while(lindex < len(inputlines)):
elif params[0] == 'z': elif params[0] == 'z':
replacement = '#cylinder: {} {} {} {} {} {} {} {}'.format(params[3], params[4], params[1], params[3], params[4], params[2], params[5], params[6]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -247,33 +249,33 @@ while(lindex < len(inputlines)):
elif cmdname == '#cylinder_new': elif cmdname == '#cylinder_new':
# Syntax of old command: #cylinder_new: x1 y1 z1 x2 y2 z2 radius ID # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
elif cmdname == '#cylindrical_segment': 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) inputlines.pop(lindex)
elif cmdname in ['#x_segment', '#y_segment']: 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) inputlines.pop(lindex)
elif cmdname == '#media_file': 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) inputlines.pop(lindex)
elif cmdname == '#pml_layers': elif cmdname == '#pml_layers':
# Syntax of old command: #pml_layers: num_layers # Syntax of old command: #pml_layers: num_layers
replacement = '#pml_cells: {}'.format(params[0]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
elif cmdname in ['#abc_order', '#abc_type', 'abc_optimisation_angles', '#abc_mixing_parameters', '#abc_stability_factors']: 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) inputlines.pop(lindex)
elif cmdname == '#analysis': 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])) extra = " To run a model multiple times use the command line option -n, e.g. gprMax {} -n {}".format(inputfile, int(params[0]))
else: else:
extra = '' 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) inputlines.pop(lindex)
elif cmdname in ['#end_analysis', '#number_of_media', '#nips_number']: 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) inputlines.pop(lindex)
elif cmdname == '#snapshot': elif cmdname == '#snapshot':
@@ -296,7 +298,7 @@ while(lindex < len(inputlines)):
else: else:
# Syntax of old command: #snapshot: i1 x1 y1 z1 x2 y2 z2 dx dy dz time filename type # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -306,7 +308,7 @@ while(lindex < len(inputlines)):
if params[0].endswith('.geo'): if params[0].endswith('.geo'):
params = params[0].split('.') 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
@@ -314,13 +316,14 @@ while(lindex < len(inputlines)):
elif cmdname == '#geometry_vtk': elif cmdname == '#geometry_vtk':
# Syntax of old command: #geometry_vtk: x1 y1 z1 x2 y2 z2 dx dy dz filename type # 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]) 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.pop(lindex)
inputlines.insert(lindex, replacement) inputlines.insert(lindex, replacement)
lindex += 1 lindex += 1
elif cmdname in ['#plane_wave', '#thin_wire', '#huygens_surface']: 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: else:
lindex += 1 lindex += 1
@@ -332,7 +335,8 @@ while(lindex < len(inputlines)):
for source in linesources: for source in linesources:
params = source.split() params = source.split()
if params[3] is badwaveforms: 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': elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm' params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[4]) waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[4])
@@ -343,7 +347,7 @@ for source in linesources:
else: else:
hertzian = '#hertzian_dipole: z {} {} {} {}'.format(hertziantx[1], hertziantx[2], 0, hertziantx[3]) 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(source)
inputlines.remove(tx) inputlines.remove(tx)
inputlines.append(waveform) inputlines.append(waveform)
@@ -353,7 +357,8 @@ for source in linesources:
for source in hertziandipoles: for source in hertziandipoles:
params = source.split() params = source.split()
if params[3] is badwaveforms: 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': elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm' params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[4]) waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[4])
@@ -364,7 +369,7 @@ for source in hertziandipoles:
else: else:
hertzian = '#hertzian_dipole: {} {} {} {} {}'.format(hertziantx[1], hertziantx[2], hertziantx[3], hertziantx[4], hertziantx[5]) 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(source)
inputlines.remove(tx) inputlines.remove(tx)
inputlines.append(waveform) inputlines.append(waveform)
@@ -374,7 +379,8 @@ for source in hertziandipoles:
for source in voltagesources: for source in voltagesources:
params = source.split() params = source.split()
if params[3] is badwaveforms: 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': elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm' params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[5]) waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[5])
@@ -385,7 +391,7 @@ for source in voltagesources:
else: else:
voltagesource = '#voltage_source: {} {} {} {} {} {}'.format(voltagesourcetx[1], voltagesourcetx[2], voltagesourcetx[3], voltagesourcetx[4], params[4], voltagesourcetx[5]) 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(source)
inputlines.remove(tx) inputlines.remove(tx)
inputlines.append(waveform) inputlines.append(waveform)
@@ -395,7 +401,8 @@ for source in voltagesources:
for source in transmissionlines: for source in transmissionlines:
params = source.split() params = source.split()
if params[3] is badwaveforms: 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': elif params[3] == 'ricker':
params[3] = 'gaussiandotnorm' params[3] = 'gaussiandotnorm'
waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[6]) waveform = '#waveform: {} {} {} {}'.format(params[3], params[1], params[2], params[6])
@@ -406,7 +413,7 @@ for source in transmissionlines:
else: else:
transmissionline = '#transmission_line: {} {} {} {} {} {}'.format(transmissionlinetx[1], transmissionlinetx[2], transmissionlinetx[3], transmissionlinetx[4], params[5], transmissionlinetx[5]) 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(source)
inputlines.remove(tx) inputlines.remove(tx)
inputlines.append(waveform) inputlines.append(waveform)
@@ -419,4 +426,4 @@ with open(newinputfile, 'w') as f:
for line in inputlines: for line in inputlines:
f.write('{}\n'.format(line)) 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 argparse
import glob import glob
import logging
import os import os
from pathlib import Path from pathlib import Path
import h5py import h5py
import numpy as np import numpy as np
from gprMax._version import __version__ from gprMax._version import __version__
from gprMax.exceptions import CmdInputError
logger = logging.getLogger(__name__)
def get_output_data(filename, rxnumber, rxcomponent): def get_output_data(filename, rxnumber, rxcomponent):
@@ -47,14 +49,16 @@ def get_output_data(filename, rxnumber, rxcomponent):
# Check there are any receivers # Check there are any receivers
if nrx == 0: 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) + '/' path = '/rxs/rx' + str(rxnumber) + '/'
availableoutputs = list(f[path].keys()) availableoutputs = list(f[path].keys())
# Check if requested output is in file # Check if requested output is in file
if rxcomponent not in availableoutputs: 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 = f[path + '/' + rxcomponent]
outputdata = np.array(outputdata) outputdata = np.array(outputdata)

查看文件

@@ -17,16 +17,18 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse import argparse
import logging
from pathlib import Path from pathlib import Path
import h5py import h5py
import matplotlib.gridspec as gridspec import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from gprMax.exceptions import CmdInputError
from gprMax.receivers import Rx from gprMax.receivers import Rx
from gprMax.utilities import fft_power from gprMax.utilities import fft_power
logger = logging.getLogger(__name__)
def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False): def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
"""Plots electric and magnetic fields and currents from all receiver points """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 # Check there are any receivers
if not paths: 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 # Loop through all grids
for path in paths: 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 # Check for single output component when doing a FFT
if fft: if fft:
if not len(outputs) == 1: 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 # New plot for each receiver
for rx in range(1, nrx + 1): for rx in range(1, nrx + 1):
@@ -98,7 +102,8 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
output = outputs[0] output = outputs[0]
if output not in availableoutputs: 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 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 # Check if requested output is in file
if output not in availableoutputs: 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 outputdata = f[rxpath + output][:] * polarity

查看文件

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

查看文件

@@ -17,15 +17,17 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse import argparse
import logging
from pathlib import Path from pathlib import Path
import h5py import h5py
import matplotlib.gridspec as gridspec import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from gprMax.exceptions import CmdInputError
from scipy.io import loadmat from scipy.io import loadmat
logger = logging.getLogger(__name__)
def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=None, rxcomponent=None): 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. """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()) availableoutputs = list(f[rxpath].keys())
if rxcomponent not in availableoutputs: 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 rxpath += rxcomponent

查看文件

@@ -17,14 +17,16 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import argparse import argparse
import logging
from pathlib import Path from pathlib import Path
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from gprMax.exceptions import CmdInputError
from gprMax.utilities import fft_power, round_value from gprMax.utilities import fft_power, round_value
from gprMax.waveforms import Waveform from gprMax.waveforms import Waveform
logger = logging.getLogger(__name__)
def check_timewindow(timewindow, dt): def check_timewindow(timewindow, dt):
"""Checks and sets time window and number of iterations. """Checks and sets time window and number of iterations.
@@ -51,7 +53,8 @@ def check_timewindow(timewindow, dt):
if timewindow > 0: if timewindow > 0:
iterations = round_value((timewindow / dt)) + 1 iterations = round_value((timewindow / dt)) + 1
else: 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 return timewindow, iterations
@@ -164,9 +167,11 @@ if __name__ == "__main__":
# Check waveform parameters # Check waveform parameters
if args.type.lower() not in Waveform.types: 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: 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 # Create waveform instance
w = Waveform() w = Waveform()

查看文件

@@ -1,8 +1,12 @@
import argparse import argparse
import logging
import os import os
import h5py import h5py
logger = logging.getLogger(__name__)
# Parse command line arguments # Parse command line arguments
parser = argparse.ArgumentParser(description='Writes a HDF5 file of AustinMan or AustinWoman head only.', usage='python head_only_hdf5 filename') parser = argparse.ArgumentParser(description='Writes a HDF5 file of AustinMan or AustinWoman head only.', usage='python head_only_hdf5 filename')
parser.add_argument('filename', help='name and path to (HDF5) file containing AustinMan or AustinWoman model') parser.add_argument('filename', help='name and path to (HDF5) file containing AustinMan or AustinWoman model')
@@ -16,7 +20,7 @@ data = f['/data'][:, :, :]
# Define head as last 1/8 of total body height # Define head as last 1/8 of total body height
nzhead = 7 * int(data.shape[2] / 8) nzhead = 7 * int(data.shape[2] / 8)
print('Dimensions of head model: {:g} x {:g} x {:g} cells'.format(data.shape[0], data.shape[1], data.shape[2] - nzhead)) logger.info(f'Dimensions of head model: {data.shape[0]:g} x {data.shape[1]:g} x {data.shape[2] - nzhead:g} cells')
# Write HDF5 file # Write HDF5 file
headfile = os.path.splitext(args.filename)[0] + '_head.h5' headfile = os.path.splitext(args.filename)[0] + '_head.h5'

查看文件

@@ -6,6 +6,7 @@
# Please use the attribution at http://dx.doi.org/10.1016/j.sigpro.2016.04.010 # Please use the attribution at http://dx.doi.org/10.1016/j.sigpro.2016.04.010
import argparse import argparse
import logging
import os import os
import sys import sys
@@ -14,6 +15,9 @@ import h5py
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
logger = logging.getLogger(__name__)
# Parse command line arguments # Parse command line arguments
parser = argparse.ArgumentParser(description='Calculate and store (in a Numpy file) field patterns from a simulation with receivers positioned in circles around an antenna.', usage='cd gprMax; python -m user_libs.antenna_patterns.initial_save outputfile') parser = argparse.ArgumentParser(description='Calculate and store (in a Numpy file) field patterns from a simulation with receivers positioned in circles around an antenna.', usage='cd gprMax; python -m user_libs.antenna_patterns.initial_save outputfile')
parser.add_argument('outputfile', help='name of gprMax output file including path') parser.add_argument('outputfile', help='name of gprMax output file including path')
@@ -58,13 +62,13 @@ if epsr:
wavelength = v1 / f wavelength = v1 / f
# Print some useful information # Print some useful information
print('Centre frequency: {} GHz'.format(f / 1e9)) logger.info('Centre frequency: {} GHz'.format(f / 1e9))
if epsr: if epsr:
print('Critical angle for Er {} is {} degrees'.format(epsr, thetac)) logger.info('Critical angle for Er {} is {} degrees'.format(epsr, thetac))
print('Wavelength: {:.3f} m'.format(wavelength)) logger.info('Wavelength: {:.3f} m'.format(wavelength))
print('Observation distance(s) from {:.3f} m ({:.1f} wavelengths) to {:.3f} m ({:.1f} wavelengths)'.format(radii[0], radii[0] / wavelength, radii[-1], radii[-1] / wavelength)) logger.info('Observation distance(s) from {:.3f} m ({:.1f} wavelengths) to {:.3f} m ({:.1f} wavelengths)'.format(radii[0], radii[0] / wavelength, radii[-1], radii[-1] / wavelength))
print('Theoretical boundary between reactive & radiating near-field (0.62*sqrt((D^3/wavelength): {:.3f} m'.format(0.62 * np.sqrt((D**3) / wavelength))) logger.info('Theoretical boundary between reactive & radiating near-field (0.62*sqrt((D^3/wavelength): {:.3f} m'.format(0.62 * np.sqrt((D**3) / wavelength)))
print('Theoretical boundary between radiating near-field & far-field (2*D^2/wavelength): {:.3f} m'.format((2 * D**2) / wavelength)) logger.info('Theoretical boundary between radiating near-field & far-field (2*D^2/wavelength): {:.3f} m'.format((2 * D**2) / wavelength))
# Load text file with coordinates of pattern origin # Load text file with coordinates of pattern origin
origin = np.loadtxt(os.path.splitext(outputfile)[0] + '_rxsorigin.txt') origin = np.loadtxt(os.path.splitext(outputfile)[0] + '_rxsorigin.txt')
@@ -176,4 +180,4 @@ for radius in range(0, len(radii)):
# Save pattern to numpy file # Save pattern to numpy file
np.save(os.path.splitext(outputfile)[0], patternsave) np.save(os.path.splitext(outputfile)[0], patternsave)
print('Written Numpy file: {}.npy'.format(os.path.splitext(outputfile)[0])) logger.info('Written Numpy file: {}.npy'.format(os.path.splitext(outputfile)[0]))

查看文件

@@ -6,6 +6,7 @@
# Please use the attribution at http://dx.doi.org/10.1016/j.sigpro.2016.04.010 # Please use the attribution at http://dx.doi.org/10.1016/j.sigpro.2016.04.010
import argparse import argparse
import logging
import os import os
import sys import sys
@@ -13,6 +14,9 @@ import gprMax.config as config
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
logger = logging.getLogger(__name__)
# Parse command line arguments # Parse command line arguments
parser = argparse.ArgumentParser(description='Plot field patterns from a simulation with receivers positioned in circles around an antenna. This module should be used after the field pattern data has been processed and stored using the initial_save.py module.', usage='cd gprMax; python -m user_libs.antenna_patterns.plot_fields numpyfile') parser = argparse.ArgumentParser(description='Plot field patterns from a simulation with receivers positioned in circles around an antenna. This module should be used after the field pattern data has been processed and stored using the initial_save.py module.', usage='cd gprMax; python -m user_libs.antenna_patterns.plot_fields numpyfile')
parser.add_argument('numpyfile', help='name of numpy file including path') parser.add_argument('numpyfile', help='name of numpy file including path')
@@ -55,13 +59,13 @@ if epsr:
wavelength = v1 / f wavelength = v1 / f
# Print some useful information # Print some useful information
print('Centre frequency: {} GHz'.format(f / 1e9)) logger.info('Centre frequency: {} GHz'.format(f / 1e9))
if epsr: if epsr:
print('Critical angle for Er {} is {} degrees'.format(epsr, thetac)) logger.info('Critical angle for Er {} is {} degrees'.format(epsr, thetac))
print('Wavelength: {:.3f} m'.format(wavelength)) logger.info('Wavelength: {:.3f} m'.format(wavelength))
print('Observation distance(s) from {:.3f} m ({:.1f} wavelengths) to {:.3f} m ({:.1f} wavelengths)'.format(radii[0], radii[0] / wavelength, radii[-1], radii[-1] / wavelength)) logger.info('Observation distance(s) from {:.3f} m ({:.1f} wavelengths) to {:.3f} m ({:.1f} wavelengths)'.format(radii[0], radii[0] / wavelength, radii[-1], radii[-1] / wavelength))
print('Theoretical boundary between reactive & radiating near-field (0.62*sqrt((D^3/wavelength): {:.3f} m'.format(0.62 * np.sqrt((D**3) / wavelength))) logger.info('Theoretical boundary between reactive & radiating near-field (0.62*sqrt((D^3/wavelength): {:.3f} m'.format(0.62 * np.sqrt((D**3) / wavelength)))
print('Theoretical boundary between radiating near-field & far-field (2*D^2/wavelength): {:.3f} m'.format((2 * D**2) / wavelength)) logger.info('Theoretical boundary between radiating near-field & far-field (2*D^2/wavelength): {:.3f} m'.format((2 * D**2) / wavelength))
# Setup figure # Setup figure
fig = plt.figure(num=args.numpyfile, figsize=(8, 8), facecolor='w', edgecolor='w') fig = plt.figure(num=args.numpyfile, figsize=(8, 8), facecolor='w', edgecolor='w')

查看文件

@@ -5,8 +5,11 @@
# #
# Please use the attribution at http://dx.doi.org/10.1190/1.3548506 # Please use the attribution at http://dx.doi.org/10.1190/1.3548506
import logging
import gprMax import gprMax
from gprMax.exceptions import CmdInputError
logger = logging.getLogger(__name__)
def antenna_like_GSSI_1500(x, y, z, resolution=0.001): def antenna_like_GSSI_1500(x, y, z, resolution=0.001):
@@ -59,7 +62,8 @@ def antenna_like_GSSI_1500(x, y, z, resolution=0.001):
patchheight = 0.016 patchheight = 0.016
tx = x + 0.114, y + 0.052, z + skidthickness tx = x + 0.114, y + 0.052, z + skidthickness
else: else:
raise CmdInputError('This antenna module can only be used with a spatial discretisation of 1mm or 2mm') logger.exception('This antenna module can only be used with a spatial discretisation of 1mm or 2mm')
raise ValueError
# Specify optimisation state of antenna model # Specify optimisation state of antenna model
optstate = ['WarrenThesis', 'DebyeAbsorber', 'GiannakisPaper'] optstate = ['WarrenThesis', 'DebyeAbsorber', 'GiannakisPaper']
@@ -367,7 +371,8 @@ def antenna_like_GSSI_400(x, y, z, resolution=0.001):
metalboxheight = 0.088 metalboxheight = 0.088
tx = x + 0.01 + 0.004 + 0.056, y + casethickness + 0.005 + 0.143 - 0.002, z + skidthickness tx = x + 0.01 + 0.004 + 0.056, y + casethickness + 0.005 + 0.143 - 0.002, z + skidthickness
else: else:
raise CmdInputError('This antenna module can only be used with a spatial discretisation of 0.5mm, 1mm, 2mm') logger.exception('This antenna module can only be used with a spatial discretisation of 0.5mm, 1mm, 2mm')
raise ValueError
# Material definitions # Material definitions
absorber = gprMax.Material(er=absorberEr, se=absorbersig, mr=1, sm=0, id='absorber') absorber = gprMax.Material(er=absorberEr, se=absorbersig, mr=1, sm=0, id='absorber')

查看文件

@@ -5,8 +5,11 @@
# #
# Please use the attribution at http://dx.doi.org/10.1190/1.3548506 # Please use the attribution at http://dx.doi.org/10.1190/1.3548506
import logging
import gprMax import gprMax
from gprMax.exceptions import CmdInputError
logger = logging.getLogger(__name__)
def antenna_like_MALA_1200(x, y, z, resolution=0.001): def antenna_like_MALA_1200(x, y, z, resolution=0.001):
@@ -66,7 +69,8 @@ def antenna_like_MALA_1200(x, y, z, resolution=0.001):
bowtieheight = 0.024 bowtieheight = 0.024
tx = x + 0.062, y + 0.052, z + skidthickness tx = x + 0.062, y + 0.052, z + skidthickness
else: else:
raise CmdInputError('This antenna module can only be used with a spatial resolution of 1mm or 2mm') logger.exception('This antenna module can only be used with a spatial resolution of 1mm or 2mm')
raise ValueError
# SMD resistors - 3 on each Tx & Rx bowtie arm # SMD resistors - 3 on each Tx & Rx bowtie arm
txres = 470 # Ohms txres = 470 # Ohms