你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 15:27:57 +08:00
Updated with ruff formatter
这个提交包含在:
@@ -90,7 +90,13 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False, save=False):
|
||||
if w.freq and w.type != "gaussian" and w.type != "impulse":
|
||||
logging.info(f"Centre frequency: {w.freq:g} Hz")
|
||||
|
||||
if w.type in ["gaussian", "gaussiandot", "gaussiandotnorm", "gaussianprime", "gaussiandoubleprime"]:
|
||||
if w.type in [
|
||||
"gaussian",
|
||||
"gaussiandot",
|
||||
"gaussiandotnorm",
|
||||
"gaussianprime",
|
||||
"gaussiandoubleprime",
|
||||
]:
|
||||
delay = 1 / w.freq
|
||||
logging.info(f"Time to centre of pulse: {delay:g} s")
|
||||
elif w.type in ["gaussiandotdot", "gaussiandotdotnorm", "ricker"]:
|
||||
@@ -113,7 +119,9 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False, save=False):
|
||||
pltrange = np.where(freqs > 4 * w.freq)[0][0]
|
||||
pltrange = np.s_[0:pltrange]
|
||||
|
||||
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, num=w.type, figsize=(20, 10), facecolor="w", edgecolor="w")
|
||||
fig, (ax1, ax2) = plt.subplots(
|
||||
nrows=1, ncols=2, num=w.type, figsize=(20, 10), facecolor="w", edgecolor="w"
|
||||
)
|
||||
|
||||
# Plot waveform
|
||||
ax1.plot(time, waveform, "r", lw=2)
|
||||
@@ -121,7 +129,9 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False, save=False):
|
||||
ax1.set_ylabel("Amplitude")
|
||||
|
||||
# Plot frequency spectra
|
||||
markerline, stemlines, baseline = ax2.stem(freqs[pltrange], power[pltrange], "-.")
|
||||
markerline, stemlines, baseline = ax2.stem(
|
||||
freqs[pltrange], power[pltrange], "-."
|
||||
)
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "r")
|
||||
plt.setp(markerline, "markerfacecolor", "r", "markeredgecolor", "r")
|
||||
@@ -130,7 +140,9 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False, save=False):
|
||||
ax2.set_ylabel("Power [dB]")
|
||||
|
||||
else:
|
||||
fig, ax1 = plt.subplots(num=w.type, figsize=(10, 10), facecolor="w", edgecolor="w")
|
||||
fig, ax1 = plt.subplots(
|
||||
num=w.type, figsize=(10, 10), facecolor="w", edgecolor="w"
|
||||
)
|
||||
|
||||
# Plot waveform
|
||||
ax1.plot(time, waveform, "r", lw=2)
|
||||
@@ -143,9 +155,21 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False, save=False):
|
||||
if save:
|
||||
savefile = Path(__file__).parent / w.type
|
||||
# Save a PDF of the figure
|
||||
fig.savefig(savefile.with_suffix(".pdf"), dpi=None, format="pdf", bbox_inches="tight", pad_inches=0.1)
|
||||
fig.savefig(
|
||||
savefile.with_suffix(".pdf"),
|
||||
dpi=None,
|
||||
format="pdf",
|
||||
bbox_inches="tight",
|
||||
pad_inches=0.1,
|
||||
)
|
||||
# Save a PNG of the figure
|
||||
fig.savefig(savefile.with_suffix(".png"), dpi=150, format="png", bbox_inches="tight", pad_inches=0.1)
|
||||
fig.savefig(
|
||||
savefile.with_suffix(".png"),
|
||||
dpi=150,
|
||||
format="png",
|
||||
bbox_inches="tight",
|
||||
pad_inches=0.1,
|
||||
)
|
||||
|
||||
return plt
|
||||
|
||||
@@ -161,18 +185,27 @@ if __name__ == "__main__":
|
||||
parser.add_argument("freq", type=float, help="centre frequency of waveform")
|
||||
parser.add_argument("timewindow", help="time window to view waveform")
|
||||
parser.add_argument("dt", type=float, help="time step to view waveform")
|
||||
parser.add_argument("-fft", action="store_true", default=False, help="plot FFT of waveform")
|
||||
parser.add_argument(
|
||||
"-save", action="store_true", default=False, help="save plot directly to file, i.e. do not display"
|
||||
"-fft", action="store_true", default=False, help="plot FFT of waveform"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-save",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="save plot directly to file, i.e. do not display",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check waveform parameters
|
||||
if args.type.lower() not in Waveform.types:
|
||||
logging.exception(f"The waveform must have one of the following types {', '.join(Waveform.types)}")
|
||||
logging.exception(
|
||||
f"The waveform must have one of the following types {', '.join(Waveform.types)}"
|
||||
)
|
||||
raise ValueError
|
||||
if args.freq <= 0:
|
||||
logging.exception("The waveform requires an excitation frequency value of greater than zero")
|
||||
logging.exception(
|
||||
"The waveform requires an excitation frequency value of greater than zero"
|
||||
)
|
||||
raise ValueError
|
||||
|
||||
# Create waveform instance
|
||||
@@ -182,5 +215,7 @@ if __name__ == "__main__":
|
||||
w.freq = args.freq
|
||||
|
||||
timewindow, iterations = check_timewindow(args.timewindow, args.dt)
|
||||
plthandle = mpl_plot(w, timewindow, args.dt, iterations, fft=args.fft, save=args.save)
|
||||
plthandle = mpl_plot(
|
||||
w, timewindow, args.dt, iterations, fft=args.fft, save=args.save
|
||||
)
|
||||
plthandle.show()
|
||||
|
在新工单中引用
屏蔽一个用户