你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-06 20:46:52 +08:00
Formatting cleanups.
这个提交包含在:
@@ -56,7 +56,7 @@ with open(model.FileName[0], 'r') as f:
|
||||
if materials:
|
||||
# Get range of data
|
||||
mat_datarange = model.CellData.GetArray('Material').GetRange()
|
||||
|
||||
|
||||
# Create threshold for materials (name and numeric value)
|
||||
for x in range(0, int(mat_datarange[1]) + 1):
|
||||
for y in range(len(materials)):
|
||||
@@ -64,9 +64,9 @@ if materials:
|
||||
threshold = Threshold(Input=model)
|
||||
threshold.Scalars = 'Material'
|
||||
threshold.ThresholdRange = [materials[y][0], materials[y][0]]
|
||||
|
||||
|
||||
RenameSource(materials[y][1], threshold)
|
||||
|
||||
|
||||
if materials[y][0] != 1:
|
||||
# Show data in view
|
||||
thresholddisplay = Show(threshold, renderview)
|
||||
@@ -75,7 +75,7 @@ if materials:
|
||||
if srcs_pml:
|
||||
# Get ranges of data
|
||||
srcs_pml_datarange = model.CellData.GetArray('Sources_PML').GetRange()
|
||||
|
||||
|
||||
# Create threshold for sources/pml (name and numeric value)
|
||||
for x in range(1, int(srcs_pml_datarange[1]) + 1):
|
||||
for y in range(len(srcs_pml)):
|
||||
@@ -83,20 +83,20 @@ if srcs_pml:
|
||||
threshold = Threshold(Input=model)
|
||||
threshold.Scalars = 'Sources_PML'
|
||||
threshold.ThresholdRange = [srcs_pml[y][0], srcs_pml[y][0]]
|
||||
|
||||
|
||||
RenameSource(srcs_pml[y][1], threshold)
|
||||
|
||||
|
||||
# Show data in view
|
||||
thresholddisplay = Show(threshold, renderview)
|
||||
thresholddisplay.ColorArrayName = 'Sources_PML'
|
||||
|
||||
|
||||
if srcs_pml[y][0] == 1:
|
||||
thresholddisplay.Opacity = 0.5
|
||||
|
||||
if rxs:
|
||||
# Get ranges of data
|
||||
rxs_datarange = model.CellData.GetArray('Receivers').GetRange()
|
||||
|
||||
|
||||
# Create threshold for sources/pml (name and numeric value)
|
||||
for x in range(1, int(rxs_datarange[1]) + 1):
|
||||
for y in range(len(rxs)):
|
||||
@@ -104,9 +104,9 @@ if rxs:
|
||||
threshold = Threshold(Input=model)
|
||||
threshold.Scalars = 'Receivers'
|
||||
threshold.ThresholdRange = [rxs[y][0], rxs[y][0]]
|
||||
|
||||
|
||||
RenameSource(rxs[y][1], threshold)
|
||||
|
||||
|
||||
# Show data in view
|
||||
thresholddisplay = Show(threshold, renderview)
|
||||
thresholddisplay.ColorArrayName = 'Receivers'
|
||||
|
@@ -51,7 +51,7 @@ hertziandipoles = []
|
||||
|
||||
lindex = 0
|
||||
while(lindex < len(inputlines)):
|
||||
|
||||
|
||||
if inputlines[lindex].startswith('#') and not inputlines[lindex].startswith('##'):
|
||||
cmd = inputlines[lindex].split(':')
|
||||
cmdname = cmd[0].lower()
|
||||
@@ -66,7 +66,7 @@ while(lindex < len(inputlines)):
|
||||
inputlines.insert(lindex, replacement)
|
||||
lindex += 1
|
||||
dx_dy_dz = (float(params[0]), float(params[1]), float(params[1]))
|
||||
|
||||
|
||||
elif cmdname == '#dx_dy_dz':
|
||||
dx_dy_dz = (float(params[0]), float(params[1]), float(params[2]))
|
||||
lindex += 1
|
||||
@@ -75,16 +75,16 @@ while(lindex < len(inputlines)):
|
||||
lindex += 1
|
||||
|
||||
else:
|
||||
lindex +=1
|
||||
lindex += 1
|
||||
|
||||
lindex = 0
|
||||
while(lindex < len(inputlines)):
|
||||
|
||||
|
||||
if inputlines[lindex].startswith('#') and not inputlines[lindex].startswith('##'):
|
||||
cmd = inputlines[lindex].split(':')
|
||||
cmdname = cmd[0].lower()
|
||||
params = cmd[1].split()
|
||||
|
||||
|
||||
if cmdname == '#domain':
|
||||
if model2D:
|
||||
# Syntax of old command: #domain: x y
|
||||
@@ -105,7 +105,7 @@ while(lindex < len(inputlines)):
|
||||
else:
|
||||
timewindow = int(params[0])
|
||||
lindex += 1
|
||||
|
||||
|
||||
elif cmdname == '#num_of_procs':
|
||||
# Syntax of old command: #num_of_procs: nthreads
|
||||
replacement = '#num_threads: {}'.format(params[0])
|
||||
@@ -222,7 +222,7 @@ while(lindex < len(inputlines)):
|
||||
replacement = '#cylinder: {} {} {} {} {} {} {} {}'.format(params[1], params[3], params[4], params[2], params[3], params[4], params[5], params[6])
|
||||
elif params[0] == 'y':
|
||||
replacement = '#cylinder: {} {} {} {} {} {} {} {}'.format(params[3], params[1], params[4], params[3], params[2], params[4], params[5], params[6])
|
||||
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])
|
||||
|
||||
print("Command '{}', replaced with '{}'".format(inputlines[lindex], replacement))
|
||||
@@ -237,7 +237,7 @@ while(lindex < len(inputlines)):
|
||||
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]))
|
||||
inputlines.pop(lindex)
|
||||
@@ -312,7 +312,7 @@ while(lindex < len(inputlines)):
|
||||
lindex += 1
|
||||
|
||||
else:
|
||||
lindex +=1
|
||||
lindex += 1
|
||||
|
||||
# Convert separate #line_source and associated #tx to #waveform and #hertzian_dipole
|
||||
for source in linesources:
|
||||
@@ -370,7 +370,7 @@ for source in voltagesources:
|
||||
voltagesource = '#voltage_source: {} {} {} {} {} {} {} {}'.format(voltagesourcetx[1], voltagesourcetx[2], voltagesourcetx[3], voltagesourcetx[4], params[4], voltagesourcetx[5], voltagesourcetx[6], voltagesourcetx[7])
|
||||
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))
|
||||
inputlines.remove(source)
|
||||
inputlines.remove(tx)
|
||||
|
@@ -44,7 +44,7 @@ fout = h5py.File(outputfile, 'w')
|
||||
for model in range(modelruns):
|
||||
fin = h5py.File(basefilename + str(model + 1) + '.out', 'r')
|
||||
nrx = fin.attrs['nrx']
|
||||
|
||||
|
||||
# Write properties for merged file on first iteration
|
||||
if model == 0:
|
||||
fout.attrs['Iterations'] = fin.attrs['Iterations']
|
||||
@@ -63,7 +63,7 @@ for model in range(modelruns):
|
||||
availableoutputs = list(fin[path].keys())
|
||||
# For all receiver outputs
|
||||
for output in availableoutputs:
|
||||
fout[path + '/' + output][:,model] = fin[path + '/' + output][:]
|
||||
fout[path + '/' + output][:, model] = fin[path + '/' + output][:]
|
||||
|
||||
fin.close()
|
||||
|
||||
@@ -74,4 +74,3 @@ if not check or check == 'y':
|
||||
for model in range(modelruns):
|
||||
file = basefilename + str(model + 1) + '.out'
|
||||
os.remove(file)
|
||||
|
||||
|
@@ -31,16 +31,16 @@ from gprMax.receivers import Rx
|
||||
|
||||
def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
"""Plots electric and magnetic fields and currents from all receiver points in the given output file. Each receiver point is plotted in a new figure window.
|
||||
|
||||
|
||||
Args:
|
||||
filename (string): Filename (including path) of output file.
|
||||
outputs (list): List of field/current components to plot.
|
||||
fft (boolean): Plot FFT switch.
|
||||
|
||||
|
||||
Returns:
|
||||
plt (object): matplotlib plot object.
|
||||
"""
|
||||
|
||||
|
||||
# Open output file and read some attributes
|
||||
f = h5py.File(filename, 'r')
|
||||
nrx = f.attrs['nrx']
|
||||
@@ -62,10 +62,10 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
for rx in range(1, nrx + 1):
|
||||
path = '/rxs/rx' + str(rx) + '/'
|
||||
availableoutputs = list(f[path].keys())
|
||||
|
||||
|
||||
# If only a single output is required, create one subplot
|
||||
if len(outputs) == 1:
|
||||
|
||||
|
||||
# Check for polarity of output and if requested output is in file
|
||||
if outputs[0][-1] == '-':
|
||||
polarity = -1
|
||||
@@ -75,10 +75,10 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
polarity = 1
|
||||
outputtext = outputs[0]
|
||||
output = outputs[0]
|
||||
|
||||
|
||||
if output not in availableoutputs:
|
||||
raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(output, ', '.join(availableoutputs)))
|
||||
|
||||
|
||||
outputdata = f[path + output][:] * polarity
|
||||
|
||||
# Plotting if FFT required
|
||||
@@ -113,7 +113,7 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
ax2.set_xlabel('Frequency [Hz]')
|
||||
ax2.set_ylabel('Power [dB]')
|
||||
ax2.grid()
|
||||
|
||||
|
||||
# Change colours and labels for magnetic field components or currents
|
||||
if 'H' in outputs[0]:
|
||||
plt.setp(line1, color='g')
|
||||
@@ -127,17 +127,17 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
# plt.setp(ax1, ylabel=outputtext + ' current [A]')
|
||||
# plt.setp(stemlines, 'color', 'b')
|
||||
# plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
# Plotting if no FFT required
|
||||
else:
|
||||
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Time [s]', ylabel=outputtext + ' field strength [V/m]'), num='rx' + str(rx), figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
line = ax.plot(time, outputdata,'r', lw=2, label=outputtext)
|
||||
line = ax.plot(time, outputdata, 'r', lw=2, label=outputtext)
|
||||
ax.set_xlim([0, np.amax(time)])
|
||||
#ax.set_ylim([-15, 20])
|
||||
ax.grid()
|
||||
|
||||
|
||||
if 'H' in output:
|
||||
plt.setp(line, color='g')
|
||||
plt.setp(ax, ylabel=outputtext + ', field strength [A/m]')
|
||||
@@ -150,7 +150,7 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
fig, ax = plt.subplots(subplot_kw=dict(xlabel='Time [s]'), num='rx' + str(rx), figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
gs = gridspec.GridSpec(3, 2, hspace=0.3, wspace=0.3)
|
||||
for output in outputs:
|
||||
|
||||
|
||||
# Check for polarity of output and if requested output is in file
|
||||
if output[-1] == 'm':
|
||||
polarity = -1
|
||||
@@ -159,41 +159,41 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False):
|
||||
else:
|
||||
polarity = 1
|
||||
outputtext = output
|
||||
|
||||
|
||||
# Check if requested output is in file
|
||||
if output not in availableoutputs:
|
||||
raise CmdInputError('Output(s) requested to plot: {}, but available output(s) for receiver {} in the file: {}'.format(', '.join(outputs), rx, ', '.join(availableoutputs)))
|
||||
|
||||
|
||||
outputdata = f[path + output][:] * polarity
|
||||
|
||||
|
||||
if output == 'Ex':
|
||||
ax = plt.subplot(gs[0, 0])
|
||||
ax.plot(time, outputdata,'r', lw=2, label=outputtext)
|
||||
ax.plot(time, outputdata, 'r', lw=2, label=outputtext)
|
||||
ax.set_ylabel(outputtext + ', field strength [V/m]')
|
||||
#ax.set_ylim([-15, 20])
|
||||
elif output == 'Ey':
|
||||
ax = plt.subplot(gs[1, 0])
|
||||
ax.plot(time, outputdata,'r', lw=2, label=outputtext)
|
||||
ax.plot(time, outputdata, 'r', lw=2, label=outputtext)
|
||||
ax.set_ylabel(outputtext + ', field strength [V/m]')
|
||||
#ax.set_ylim([-15, 20])
|
||||
elif output == 'Ez':
|
||||
ax = plt.subplot(gs[2, 0])
|
||||
ax.plot(time, outputdata,'r', lw=2, label=outputtext)
|
||||
ax.plot(time, outputdata, 'r', lw=2, label=outputtext)
|
||||
ax.set_ylabel(outputtext + ', field strength [V/m]')
|
||||
#ax.set_ylim([-15, 20])
|
||||
elif output == 'Hx':
|
||||
ax = plt.subplot(gs[0, 1])
|
||||
ax.plot(time, outputdata,'g', lw=2, label=outputtext)
|
||||
ax.plot(time, outputdata, 'g', lw=2, label=outputtext)
|
||||
ax.set_ylabel(outputtext + ', field strength [A/m]')
|
||||
#ax.set_ylim([-0.03, 0.03])
|
||||
elif output == 'Hy':
|
||||
ax = plt.subplot(gs[1, 1])
|
||||
ax.plot(time, outputdata,'g', lw=2, label=outputtext)
|
||||
ax.plot(time, outputdata, 'g', lw=2, label=outputtext)
|
||||
ax.set_ylabel(outputtext + ', field strength [A/m]')
|
||||
#ax.set_ylim([-0.03, 0.03])
|
||||
elif output == 'Hz':
|
||||
ax = plt.subplot(gs[2, 1])
|
||||
ax.plot(time, outputdata,'g', lw=2, label=outputtext)
|
||||
ax.plot(time, outputdata, 'g', lw=2, label=outputtext)
|
||||
ax.set_ylabel(outputtext + ', field strength [A/m]')
|
||||
#ax.set_ylim([-0.03, 0.03])
|
||||
# elif output == 'Ix':
|
||||
@@ -228,6 +228,5 @@ if __name__ == "__main__":
|
||||
parser.add_argument('-fft', action='store_true', help='plot FFT (single output must be specified)', default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
plt = mpl_plot(args.outputfile, args.outputs, fft=args.fft)
|
||||
plt.show()
|
||||
|
||||
plthandle = mpl_plot(args.outputfile, args.outputs, fft=args.fft)
|
||||
plthandle.show()
|
||||
|
@@ -29,12 +29,12 @@ from gprMax.exceptions import CmdInputError
|
||||
|
||||
def get_output_data(filename, rxnumber, rxcomponent):
|
||||
"""Gets B-scan output data from a model.
|
||||
|
||||
|
||||
Args:
|
||||
filename (string): Filename (including path) of output file.
|
||||
rxnumber (int): Receiver output number.
|
||||
rxcomponent (str): Receiver output field/current component.
|
||||
|
||||
|
||||
Returns:
|
||||
outputdata (array): Array of A-scans, i.e. B-scan data.
|
||||
dt (float): Temporal resolution of the model.
|
||||
@@ -68,19 +68,19 @@ def get_output_data(filename, rxnumber, rxcomponent):
|
||||
|
||||
def mpl_plot(outputdata, dt, rxnumber, rxcomponent):
|
||||
"""Creates a plot (with matplotlib) of the B-scan.
|
||||
|
||||
|
||||
Args:
|
||||
outputdata (array): Array of A-scans, i.e. B-scan data.
|
||||
dt (float): Temporal resolution of the model.
|
||||
rxnumber (int): Receiver output number.
|
||||
rxcomponent (str): Receiver output field/current component.
|
||||
|
||||
|
||||
Returns:
|
||||
plt (object): matplotlib plot object.
|
||||
"""
|
||||
|
||||
fig = plt.figure(num='rx' + str(rxnumber), figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
plt.imshow(outputdata, extent=[0, outputdata.shape[1], outputdata.shape[0]*dt, 0], interpolation='nearest', aspect='auto', cmap='seismic', vmin=-np.amax(np.abs(outputdata)), vmax=np.amax(np.abs(outputdata)))
|
||||
plt.imshow(outputdata, extent=[0, outputdata.shape[1], outputdata.shape[0] * dt, 0], interpolation='nearest', aspect='auto', cmap='seismic', vmin=-np.amax(np.abs(outputdata)), vmax=np.amax(np.abs(outputdata)))
|
||||
plt.xlabel('Trace number')
|
||||
plt.ylabel('Time [s]')
|
||||
plt.grid()
|
||||
@@ -118,7 +118,6 @@ if __name__ == "__main__":
|
||||
|
||||
for rx in range(1, nrx + 1):
|
||||
outputdata, dt = get_output_data(args.outputfile, rx, args.rx_component)
|
||||
plt = mpl_plot(outputdata, dt, rx, args.rx_component)
|
||||
|
||||
plt.show()
|
||||
plthandle = mpl_plot(outputdata, dt, rx, args.rx_component)
|
||||
|
||||
plthandle.show()
|
||||
|
@@ -30,14 +30,14 @@ from gprMax.exceptions import CmdInputError
|
||||
|
||||
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.
|
||||
|
||||
|
||||
Args:
|
||||
filename (string): Filename (including path) of output file.
|
||||
tltxnumber (int): Transmitter antenna - transmission line number
|
||||
tlrxnumber (int): Receiver antenna - transmission line number
|
||||
rxnumber (int): Receiver antenna - output number
|
||||
rxcomponent (str): Receiver antenna - output electric field component
|
||||
|
||||
|
||||
Returns:
|
||||
antennaparams (dict): Antenna parameters.
|
||||
"""
|
||||
@@ -65,8 +65,8 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
|
||||
Iinc = f[tltxpath + 'Iinc'][:]
|
||||
|
||||
# Total (incident + reflected) voltages/currents
|
||||
Vtotal = f[tltxpath +'Vtotal'][:]
|
||||
Itotal = f[tltxpath +'Itotal'][:]
|
||||
Vtotal = f[tltxpath + 'Vtotal'][:]
|
||||
Itotal = f[tltxpath + 'Itotal'][:]
|
||||
|
||||
# Reflected voltages/currents
|
||||
Vref = Vtotal - Vinc
|
||||
@@ -75,17 +75,17 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
|
||||
# If a receiver antenna is used (with a transmission line or receiver), get received voltage for s21
|
||||
if tlrxnumber:
|
||||
tlrxpath = '/tls/tl' + str(tlrxnumber) + '/'
|
||||
Vrec = f[tlrxpath +'Vtotal'][:]
|
||||
Vrec = f[tlrxpath + 'Vtotal'][:]
|
||||
|
||||
elif rxnumber:
|
||||
rxpath = '/rxs/rx' + str(rxnumber) + '/'
|
||||
availableoutputs = list(f[rxpath].keys())
|
||||
|
||||
|
||||
if rxcomponent not in availableoutputs:
|
||||
raise CmdInputError('{} output requested, but the available output for receiver {} is {}'.format(rxcomponent, rxnumber, ', '.join(availableoutputs)))
|
||||
|
||||
|
||||
rxpath += rxcomponent
|
||||
|
||||
|
||||
# Received voltage
|
||||
if rxcomponent == 'Ex':
|
||||
Vrec = f[rxpath][:] * -1 * dxdydz[0]
|
||||
@@ -120,12 +120,12 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
|
||||
Vtotalp = 20 * np.log10(np.abs((np.fft.fft(Vtotal) * delaycorrection)))
|
||||
Itotalp = 20 * np.log10(np.abs(np.fft.fft(Itotal)))
|
||||
s11 = 20 * np.log10(s11)
|
||||
|
||||
|
||||
# Create dictionary of antenna parameters
|
||||
antennaparams = {'time': time, 'freqs': freqs, 'Vinc': Vinc, 'Vincp': Vincp, 'Iinc': Iinc, 'Iincp': Iincp,
|
||||
'Vref': Vref, 'Vrefp': Vrefp, 'Iref': Iref, 'Irefp': Irefp,
|
||||
'Vtotal': Vtotal, 'Vtotalp': Vtotalp, 'Itotal': Itotal, 'Itotalp': Itotalp,
|
||||
's11': s11, 'zin': zin, 'yin': yin}
|
||||
'Vref': Vref, 'Vrefp': Vrefp, 'Iref': Iref, 'Irefp': Irefp,
|
||||
'Vtotal': Vtotal, 'Vtotalp': Vtotalp, 'Itotal': Itotal, 'Itotalp': Itotalp,
|
||||
's11': s11, 'zin': zin, 'yin': yin}
|
||||
if tlrxnumber or rxnumber:
|
||||
s21 = 20 * np.log10(s21)
|
||||
antennaparams['s21'] = s21
|
||||
@@ -135,7 +135,7 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
|
||||
|
||||
def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref, Irefp, Vtotal, Vtotalp, Itotal, Itotalp, s11, zin, yin, s21=None):
|
||||
"""Plots antenna parameters - incident, reflected and total volatges and currents; s11, (s21) and input impedance.
|
||||
|
||||
|
||||
Args:
|
||||
filename (string): Filename (including path) of output file.
|
||||
time (array): Simulation time.
|
||||
@@ -145,11 +145,11 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
Vtotal, Vtotalp, Itotal, Itotalp (array): Time and frequency domain representations of total voltage and current.
|
||||
s11, s21 (array): s11 and, optionally, s21 parameters.
|
||||
zin, yin (array): Input impedance and input admittance parameters.
|
||||
|
||||
|
||||
Returns:
|
||||
plt (object): matplotlib plot object.
|
||||
"""
|
||||
|
||||
|
||||
# Set plotting range
|
||||
pltrangemin = 1
|
||||
# To a certain drop from maximum power
|
||||
@@ -253,16 +253,16 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
ax.set_ylabel('Power [dB]')
|
||||
ax.grid()
|
||||
|
||||
## Plot reflected (reflected) voltage
|
||||
# Plot reflected (reflected) voltage
|
||||
#ax = plt.subplot(gs1[4, 0])
|
||||
#ax.plot(time, Vref, 'r', lw=2, label='Vref')
|
||||
#ax.set_title('Reflected voltage')
|
||||
#ax.set_xlabel('Time [s]')
|
||||
#ax.set_ylabel('Voltage [V]')
|
||||
#ax.set_xlim([0, np.amax(time)])
|
||||
#ax.grid()
|
||||
# ax.grid()
|
||||
#
|
||||
## Plot frequency spectra of reflected voltage
|
||||
# Plot frequency spectra of reflected voltage
|
||||
#ax = plt.subplot(gs1[4, 1])
|
||||
#markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vrefp[pltrange], '-.')
|
||||
#plt.setp(baseline, 'linewidth', 0)
|
||||
@@ -272,18 +272,18 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
#ax.set_title('Reflected voltage')
|
||||
#ax.set_xlabel('Frequency [Hz]')
|
||||
#ax.set_ylabel('Power [dB]')
|
||||
#ax.grid()
|
||||
# ax.grid()
|
||||
#
|
||||
## Plot reflected (reflected) current
|
||||
# Plot reflected (reflected) current
|
||||
#ax = plt.subplot(gs1[5, 0])
|
||||
#ax.plot(time, Iref, 'b', lw=2, label='Iref')
|
||||
#ax.set_title('Reflected current')
|
||||
#ax.set_xlabel('Time [s]')
|
||||
#ax.set_ylabel('Current [A]')
|
||||
#ax.set_xlim([0, np.amax(time)])
|
||||
#ax.grid()
|
||||
# ax.grid()
|
||||
#
|
||||
## Plot frequency spectra of reflected current
|
||||
# Plot frequency spectra of reflected current
|
||||
#ax = plt.subplot(gs1[5, 1])
|
||||
#markerline, stemlines, baseline = ax.stem(freqs[pltrange], Irefp[pltrange], '-.')
|
||||
#plt.setp(baseline, 'linewidth', 0)
|
||||
@@ -293,7 +293,7 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
#ax.set_title('Reflected current')
|
||||
#ax.set_xlabel('Frequency [Hz]')
|
||||
#ax.set_ylabel('Power [dB]')
|
||||
#ax.grid()
|
||||
# ax.grid()
|
||||
|
||||
# Figure 2
|
||||
# Plot frequency spectra of s11
|
||||
@@ -356,7 +356,7 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
#ax.set_ylim([-300, 300])
|
||||
ax.grid()
|
||||
|
||||
## Plot input admittance (magnitude)
|
||||
# Plot input admittance (magnitude)
|
||||
#ax = plt.subplot(gs2[2, 0])
|
||||
#markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.abs(yin[pltrange]), '-.')
|
||||
#plt.setp(baseline, 'linewidth', 0)
|
||||
@@ -368,9 +368,9 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
#ax.set_ylabel('Admittance [Siemens]')
|
||||
##ax.set_xlim([0.88e9, 1.02e9])
|
||||
##ax.set_ylim([0, 0.035])
|
||||
#ax.grid()
|
||||
# ax.grid()
|
||||
#
|
||||
## Plot input admittance (phase)
|
||||
# Plot input admittance (phase)
|
||||
#ax = plt.subplot(gs2[2, 1])
|
||||
#markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.angle(yin[pltrange], deg=True), '-.')
|
||||
#plt.setp(baseline, 'linewidth', 0)
|
||||
@@ -382,7 +382,7 @@ def mpl_plot(filename, time, freqs, Vinc, Vincp, Iinc, Iincp, Vref, Vrefp, Iref,
|
||||
#ax.set_ylabel('Phase [degrees]')
|
||||
##ax.set_xlim([0.88e9, 1.02e9])
|
||||
##ax.set_ylim([-40, 100])
|
||||
#ax.grid()
|
||||
# ax.grid()
|
||||
|
||||
# Save a PDF/PNG of the figure
|
||||
#fig1.savefig(os.path.splitext(os.path.abspath(filename))[0] + '_tl_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
|
||||
@@ -405,6 +405,5 @@ if __name__ == "__main__":
|
||||
args = parser.parse_args()
|
||||
|
||||
antennaparams = calculate_antenna_params(args.outputfile, args.tltx_num, args.tlrx_num, args.rx_num, args.rx_component)
|
||||
plt = mpl_plot(args.outputfile, **antennaparams)
|
||||
plt.show()
|
||||
|
||||
plthandle = mpl_plot(args.outputfile, **antennaparams)
|
||||
plthandle.show()
|
||||
|
@@ -32,19 +32,19 @@ np.seterr(divide='ignore')
|
||||
|
||||
def check_timewindow(timewindow, dt):
|
||||
"""Checks and sets time window and number of iterations.
|
||||
|
||||
|
||||
Args:
|
||||
timewindow (float): Time window.
|
||||
dt (float): Time discretisation.
|
||||
|
||||
|
||||
Returns:
|
||||
timewindow (float): Time window.
|
||||
iterations (int): Number of interations.
|
||||
"""
|
||||
|
||||
|
||||
# Time window could be a string, float or int, so convert to string then check
|
||||
timewindow = str(timewindow)
|
||||
|
||||
|
||||
try:
|
||||
timewindow = int(timewindow)
|
||||
iterations = timewindow
|
||||
@@ -62,18 +62,18 @@ def check_timewindow(timewindow, dt):
|
||||
|
||||
def mpl_plot(w, timewindow, dt, iterations, fft=False):
|
||||
"""Plots waveform and prints useful information about its properties.
|
||||
|
||||
|
||||
Args:
|
||||
w (class): Waveform class instance.
|
||||
timewindow (float): Time window.
|
||||
dt (float): Time discretisation.
|
||||
iterations (int): Number of iterations.
|
||||
fft (boolean): Plot FFT switch.
|
||||
|
||||
|
||||
Returns:
|
||||
plt (object): matplotlib plot object.
|
||||
"""
|
||||
|
||||
|
||||
time = np.linspace(0, 1, iterations)
|
||||
time *= (iterations * dt)
|
||||
waveform = np.zeros(len(time))
|
||||
@@ -104,7 +104,7 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False):
|
||||
|
||||
# Calculate pulse width for gaussian
|
||||
if w.type == 'gaussian':
|
||||
powerdrop = -3 #dB
|
||||
powerdrop = -3 # dB
|
||||
start = np.where((10 * np.log10(waveform / np.amax(waveform))) > powerdrop)[0][0]
|
||||
stop = np.where((10 * np.log10(waveform[start:] / np.amax(waveform))) < powerdrop)[0][0] + start
|
||||
print('Pulse width at {:d}dB, i.e. FWHM: {:g} s'.format(powerdrop, time[stop] - time[start]))
|
||||
@@ -130,7 +130,7 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False):
|
||||
pltrange = np.s_[0:pltrange]
|
||||
|
||||
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)
|
||||
ax1.set_xlabel('Time [s]')
|
||||
@@ -153,7 +153,7 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False):
|
||||
ax1.set_xlabel('Time [s]')
|
||||
ax1.set_ylabel('Amplitude')
|
||||
|
||||
[ax.grid() for ax in fig.axes] # Turn on grid
|
||||
[ax.grid() for ax in fig.axes] # Turn on grid
|
||||
|
||||
# Save a PDF/PNG of the figure
|
||||
#fig.savefig(os.path.dirname(os.path.abspath(__file__)) + os.sep + w.type + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
|
||||
@@ -163,7 +163,7 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Plot built-in waveforms that can be used for sources.', usage='cd gprMax; python -m tools.plot_source_wave type amp freq timewindow dt')
|
||||
parser.add_argument('type', help='type of waveform', choices=Waveform.types)
|
||||
@@ -187,6 +187,5 @@ if __name__ == "__main__":
|
||||
w.freq = args.freq
|
||||
|
||||
timewindow, iterations = check_timewindow(args.timewindow, args.dt)
|
||||
plt = mpl_plot(w, timewindow, args.dt, iterations, args.fft)
|
||||
plt.show()
|
||||
|
||||
plthandle = mpl_plot(w, timewindow, args.dt, iterations, args.fft)
|
||||
plthandle.show()
|
||||
|
在新工单中引用
屏蔽一个用户