你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
updated a few more similar lines of code to make them more cleaner.
这个提交包含在:
@@ -90,7 +90,7 @@ class AddGrass(UserObjectGeometry):
|
||||
try:
|
||||
volume = volumes[0]
|
||||
except NameError:
|
||||
logger.exception(self.__str__() + f' cannot find FractalBox {fractal_box_id}')
|
||||
logger.exception(f'{self.__str__()} cannot find FractalBox {fractal_box_id}')
|
||||
raise
|
||||
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
@@ -98,32 +98,32 @@ class AddGrass(UserObjectGeometry):
|
||||
xf, yf, zf = p2
|
||||
|
||||
if frac_dim < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for ' +
|
||||
'the fractal dimension')
|
||||
raise ValueError
|
||||
if limits[0] < 0 or limits[1] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for ' +
|
||||
'the minimum and maximum heights for grass blades')
|
||||
raise ValueError
|
||||
|
||||
# Check for valid orientations
|
||||
if xs == xf:
|
||||
if ys == yf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if xs != volume.xs and xs != volume.xf:
|
||||
logger.exception(self.__str__() + ' must specify external surfaces on a fractal box')
|
||||
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dx), round_value(limits[1] / grid.dx))
|
||||
# xminus surface
|
||||
if xs == volume.xs:
|
||||
logger.exception(self.__str__() + ' grass can only be specified ' +
|
||||
logger.exception(f'{self.__str__()} grass can only be specified ' +
|
||||
'on surfaces in the positive axis direction')
|
||||
raise ValueError
|
||||
# xplus surface
|
||||
elif xf == volume.xf:
|
||||
if fractalrange[1] > grid.nx:
|
||||
logger.exception(self.__str__() + ' cannot apply grass to ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply grass to ' +
|
||||
'fractal box as it would exceed the domain ' +
|
||||
'size in the x direction')
|
||||
raise ValueError
|
||||
@@ -131,21 +131,21 @@ class AddGrass(UserObjectGeometry):
|
||||
|
||||
elif ys == yf:
|
||||
if xs == xf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if ys != volume.ys and ys != volume.yf:
|
||||
logger.exception(self.__str__() + ' must specify external surfaces on a fractal box')
|
||||
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dy), round_value(limits[1] / grid.dy))
|
||||
# yminus surface
|
||||
if ys == volume.ys:
|
||||
logger.exception(self.__str__() + ' grass can only be specified ' +
|
||||
logger.exception(f'{self.__str__()} grass can only be specified ' +
|
||||
'on surfaces in the positive axis direction')
|
||||
raise ValueError
|
||||
# yplus surface
|
||||
elif yf == volume.yf:
|
||||
if fractalrange[1] > grid.ny:
|
||||
logger.exception(self.__str__() + ' cannot apply grass to ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply grass to ' +
|
||||
'fractal box as it would exceed the domain ' +
|
||||
'size in the y direction')
|
||||
raise ValueError
|
||||
@@ -153,28 +153,28 @@ class AddGrass(UserObjectGeometry):
|
||||
|
||||
elif zs == zf:
|
||||
if xs == xf or ys == yf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if zs != volume.zs and zs != volume.zf:
|
||||
logger.exception(self.__str__() + ' must specify external surfaces on a fractal box')
|
||||
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dz), round_value(limits[1] / grid.dz))
|
||||
# zminus surface
|
||||
if zs == volume.zs:
|
||||
logger.exception(self.__str__() + ' grass can only be specified ' +
|
||||
logger.exception(f'{self.__str__()} grass can only be specified ' +
|
||||
'on surfaces in the positive axis direction')
|
||||
raise ValueError
|
||||
# zplus surface
|
||||
elif zf == volume.zf:
|
||||
if fractalrange[1] > grid.nz:
|
||||
logger.exception(self.__str__() + ' cannot apply grass to ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply grass to ' +
|
||||
'fractal box as it would exceed the domain ' +
|
||||
'size in the z direction')
|
||||
raise ValueError
|
||||
requestedsurface = 'zplus'
|
||||
|
||||
else:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
surface = FractalSurface(xs, xf, ys, yf, zs, zf, frac_dim)
|
||||
@@ -187,7 +187,7 @@ class AddGrass(UserObjectGeometry):
|
||||
surface.operatingonID = volume.ID
|
||||
surface.generate_fractal_surface()
|
||||
if n_blades > surface.fractalsurface.shape[0] * surface.fractalsurface.shape[1]:
|
||||
logger.exception(self.__str__() + ' the specified surface is not large ' +
|
||||
logger.exception(f'{self.__str__()} the specified surface is not large ' +
|
||||
'enough for the number of grass blades/roots specified')
|
||||
raise ValueError
|
||||
|
||||
@@ -234,13 +234,13 @@ class AddGrass(UserObjectGeometry):
|
||||
grass = next((x for x in grid.materials if x.ID == 'grass'))
|
||||
testgrass = next((x for x in grass.tau if x < grid.dt), None)
|
||||
if testgrass:
|
||||
logger.exception(self.__str__() + ' requires the time step for the ' +
|
||||
logger.exception(f'{self.__str__()} requires the time step for the ' +
|
||||
'model to be less than the relaxation time required to model grass.')
|
||||
raise ValueError
|
||||
|
||||
volume.fractalsurfaces.append(surface)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'{n_blades} blades of grass on surface from ' +
|
||||
logger.info(f'{self.grid_name(grid)}{n_blades} blades of grass on surface from ' +
|
||||
f'{xs * grid.dx:g}m, {ys * grid.dy:g}m, {zs * grid.dz:g}m, ' +
|
||||
f'to {xf * grid.dx:g}m, {yf * grid.dy:g}m, {zf * grid.dz:g}m ' +
|
||||
f'with fractal dimension {surface.dimension:g}, fractal seeding ' +
|
||||
|
@@ -74,13 +74,13 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
limits = np.array(self.kwargs['limits'])
|
||||
fractal_box_id = self.kwargs['fractal_box_id']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' incorrect parameters')
|
||||
logger.exception(f'{self.__str__()} incorrect parameters')
|
||||
raise
|
||||
|
||||
try:
|
||||
seed = self.kwargs['seed']
|
||||
except KeyError:
|
||||
logger.warning(self.__str__() + ' no value for seed detected. This ' +
|
||||
logger.warning(f'{self.__str__()} no value for seed detected. This ' +
|
||||
'means you will get a different fractal distribution ' +
|
||||
'every time the model runs.')
|
||||
seed = None
|
||||
@@ -93,7 +93,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
if volumes:
|
||||
volume = volumes[0]
|
||||
else:
|
||||
logger.exception(self.__str__() + f' cannot find FractalBox {fractal_box_id}')
|
||||
logger.exception(f'{self.__str__()} cannot find FractalBox {fractal_box_id}')
|
||||
raise ValueError
|
||||
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
@@ -101,25 +101,25 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
xf, yf, zf = p2
|
||||
|
||||
if frac_dim < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal dimension')
|
||||
raise ValueError
|
||||
if weighting[0] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the first direction of the surface')
|
||||
raise ValueError
|
||||
if weighting[1] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the second direction of the surface')
|
||||
raise ValueError
|
||||
|
||||
# Check for valid orientations
|
||||
if xs == xf:
|
||||
if ys == yf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if xs != volume.xs and xs != volume.xf:
|
||||
logger.exception(self.__str__() + ' can only be used on the external ' +
|
||||
logger.exception(f'{self.__str__()} can only be used on the external ' +
|
||||
'surfaces of a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dx),
|
||||
@@ -127,7 +127,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# xminus surface
|
||||
if xs == volume.xs:
|
||||
if fractalrange[0] < 0 or fractalrange[1] > volume.xf:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'upper coordinates of the fractal box or the ' +
|
||||
'domain in the x direction')
|
||||
@@ -136,7 +136,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# xplus surface
|
||||
elif xf == volume.xf:
|
||||
if fractalrange[0] < volume.xs or fractalrange[1] > grid.nx:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'lower coordinates of the fractal box or the ' +
|
||||
'domain in the x direction')
|
||||
@@ -145,10 +145,10 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
|
||||
elif ys == yf:
|
||||
if xs == xf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if ys != volume.ys and ys != volume.yf:
|
||||
logger.exception(self.__str__() + ' can only be used on the external ' +
|
||||
logger.exception(f'{self.__str__()} can only be used on the external ' +
|
||||
'surfaces of a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dy),
|
||||
@@ -156,7 +156,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# yminus surface
|
||||
if ys == volume.ys:
|
||||
if fractalrange[0] < 0 or fractalrange[1] > volume.yf:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'upper coordinates of the fractal box or the ' +
|
||||
'domain in the y direction')
|
||||
@@ -165,7 +165,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# yplus surface
|
||||
elif yf == volume.yf:
|
||||
if fractalrange[0] < volume.ys or fractalrange[1] > grid.ny:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'lower coordinates of the fractal box or the ' +
|
||||
'domain in the y direction')
|
||||
@@ -174,10 +174,10 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
|
||||
elif zs == zf:
|
||||
if xs == xf or ys == yf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if zs != volume.zs and zs != volume.zf:
|
||||
logger.exception(self.__str__() + ' can only be used on the external ' +
|
||||
logger.exception(f'{self.__str__()} can only be used on the external ' +
|
||||
'surfaces of a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dz),
|
||||
@@ -185,7 +185,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# zminus surface
|
||||
if zs == volume.zs:
|
||||
if fractalrange[0] < 0 or fractalrange[1] > volume.zf:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'upper coordinates of the fractal box or the ' +
|
||||
'domain in the x direction')
|
||||
@@ -194,7 +194,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# zplus surface
|
||||
elif zf == volume.zf:
|
||||
if fractalrange[0] < volume.zs or fractalrange[1] > grid.nz:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'lower coordinates of the fractal box or the ' +
|
||||
'domain in the z direction')
|
||||
@@ -202,7 +202,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
requestedsurface = 'zplus'
|
||||
|
||||
else:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
surface = FractalSurface(xs, xf, ys, yf, zs, zf, frac_dim)
|
||||
@@ -218,14 +218,14 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# List of existing surfaces IDs
|
||||
existingsurfaceIDs = [x.surfaceID for x in volume.fractalsurfaces]
|
||||
if surface.surfaceID in existingsurfaceIDs:
|
||||
logger.exception(self.__str__() + f' has already been used on the ' +
|
||||
logger.exception(f'{self.__str__()} has already been used on the ' +
|
||||
f'{surface.surfaceID} surface')
|
||||
raise ValueError
|
||||
|
||||
surface.generate_fractal_surface()
|
||||
volume.fractalsurfaces.append(surface)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Fractal surface from {xs * grid.dx:g}m, ' +
|
||||
logger.info(f'{self.grid_name(grid)}Fractal surface from {xs * grid.dx:g}m, ' +
|
||||
f'{ys * grid.dy:g}m, {zs * grid.dz:g}m, to {xf * grid.dx:g}m, ' +
|
||||
f'{yf * grid.dy:g}m, {zf * grid.dz:g}m with fractal dimension ' +
|
||||
f'{surface.dimension:g}, fractal weightings {surface.weighting[0]:g}, ' +
|
||||
|
@@ -144,7 +144,7 @@ class Box(UserObjectGeometry):
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
|
||||
logger.info(self.grid_name(grid) + f"Box from {p5[0]:g}m, {p5[1]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Box from {p5[0]:g}m, {p5[1]:g}m, " +
|
||||
f"{p5[2]:g}m, to {p6[0]:g}m, {p6[1]:g}m, {p6[2]:g}m of " +
|
||||
f"material(s) {', '.join(materialsrequested)} created, " +
|
||||
f"dielectric smoothing is {dielectricsmoothing}.")
|
||||
|
@@ -66,6 +66,5 @@ r = template.render(
|
||||
}]
|
||||
)
|
||||
|
||||
f = open('cython/dispersive_updates_test.pyx', 'w')
|
||||
f.write(r)
|
||||
f.close()
|
||||
with open('cython/dispersive_updates_test.pyx', 'w') as f:
|
||||
f.write(r)
|
||||
|
@@ -38,9 +38,9 @@ class UserObjectGeometry:
|
||||
"""Readable string of parameters given to object."""
|
||||
s = ''
|
||||
for _, v in self.kwargs.items():
|
||||
if isinstance(v, tuple) or isinstance(v, list):
|
||||
if isinstance(v, (tuple, list)):
|
||||
v = ' '.join([str(el) for el in v])
|
||||
s += str(v) + ' '
|
||||
s += f'{str(v)} '
|
||||
|
||||
return f'{self.hash}: {s[:-1]}'
|
||||
|
||||
@@ -109,7 +109,7 @@ def rotate_2point_object(pts, axis, angle, origin=None):
|
||||
# Use origin at centre of object if not given
|
||||
if not origin:
|
||||
origin = pts[0,:] + (pts[1,:] - pts[0,:]) / 2
|
||||
|
||||
|
||||
# Check angle value is suitable
|
||||
angle = int(angle)
|
||||
if angle < 0 or angle > 360:
|
||||
@@ -120,7 +120,7 @@ def rotate_2point_object(pts, axis, angle, origin=None):
|
||||
raise ValueError
|
||||
|
||||
# Check axis is valid
|
||||
if axis != 'x' and axis != 'y' and axis != 'z':
|
||||
if axis not in ['x', 'y', 'z']:
|
||||
logger.exception('Axis of rotation must be x, y, or z')
|
||||
raise ValueError
|
||||
|
||||
|
@@ -55,7 +55,7 @@ class Cone(UserObjectGeometry):
|
||||
r1 = self.kwargs['r1']
|
||||
r2 = self.kwargs['r2']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' please specify 2 points and two radii')
|
||||
logger.exception(f'{self.__str__()} please specify 2 points and two radii')
|
||||
raise
|
||||
|
||||
# Check averaging
|
||||
@@ -75,7 +75,7 @@ class Cone(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' no materials have been specified')
|
||||
logger.exception(f'{self.__str__()} no materials have been specified')
|
||||
raise
|
||||
|
||||
p3 = uip.round_to_grid_static_point(p1)
|
||||
@@ -85,15 +85,15 @@ class Cone(UserObjectGeometry):
|
||||
x2, y2, z2 = uip.round_to_grid(p2)
|
||||
|
||||
if r1 < 0:
|
||||
logger.exception(self.__str__() + f' the radius of the first face {r1:g} should be a positive value.')
|
||||
logger.exception(f'{self.__str__()} the radius of the first face {r1:g} should be a positive value.')
|
||||
raise ValueError
|
||||
|
||||
if r2 < 0:
|
||||
logger.exception(self.__str__() + f' the radius of the second face {r2:g} should be a positive value.')
|
||||
logger.exception(f'{self.__str__()} the radius of the second face {r2:g} should be a positive value.')
|
||||
raise ValueError
|
||||
|
||||
if r1 == 0 and r2 == 0:
|
||||
logger.exception(self.__str__() + f' not both radii can be zero.')
|
||||
logger.exception(f'{self.__str__()} not both radii can be zero.')
|
||||
raise ValueError
|
||||
|
||||
# Look up requested materials in existing list of material instances
|
||||
@@ -101,7 +101,7 @@ class Cone(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# Isotropic case
|
||||
@@ -141,7 +141,7 @@ class Cone(UserObjectGeometry):
|
||||
grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Cone with face centres {p3[0]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Cone with face centres {p3[0]:g}m, " +
|
||||
f"{p3[1]:g}m, {p3[2]:g}m and {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, " +
|
||||
f"with radii {r1:g}m and {r2:g}, of material(s) {', '.join(materialsrequested)} " +
|
||||
f"created, dielectric smoothing is {dielectricsmoothing}.")
|
||||
|
在新工单中引用
屏蔽一个用户