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