Updated to take optional command line arguments for receiver antenna to calculate s21 parameter.

这个提交包含在:
Craig Warren
2016-05-09 14:59:49 +01:00
父节点 4eecbfa55c
当前提交 737794f36c

查看文件

@@ -21,345 +21,339 @@ import h5py
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec import matplotlib.gridspec as gridspec
#import scipy.io as sio
"""Plots antenna parameters (s11 parameter and input impedance and admittance) from an output file containing a transmission line source.""" from gprMax.exceptions import CmdInputError
# Parse command line arguments
parser = argparse.ArgumentParser(description='Plots antenna parameters (s11 parameter and input impedance and admittance) from an output file containing a transmission line source.', usage='cd gprMax; python -m tools.plot_antenna_params outputfile')
parser.add_argument('outputfile', help='name of output file including path')
parser.add_argument('-tln', default=1, type=int, help='transmission line number')
args = parser.parse_args()
print("Antenna parameter analysis from file '{}'...".format(args.outputfile)) def plot_antenna_params(filename, tln=1, rxn=None, rx=None):
"""Calculates and plots antenna parameters - s11, (s21) and input impedance.
Args:
filename (string): Filename (including path) of output file.
tln (int): Transmitting antenna - transmission line number
rxn (int): Receiver antenna - output number
rx (str): Receiver antenna - output electric field component
"""
# Open output file and read some attributes # Open output file and read some attributes
file = args.outputfile f = h5py.File(filename, 'r')
f = h5py.File(file, 'r') dt = f.attrs['dt']
dt = f.attrs['dt'] iterations = f.attrs['Iterations']
iterations = f.attrs['Iterations']
# Choose a specific frequency bin spacing # Calculate time array and frequency bin spacing
#df = 1.5e6 time = np.linspace(0, 1, iterations)
#iterations = int((1 / df) / dt) time *= (iterations * dt)
df = 1 / np.amax(time)
# Calculate time array and frequency bin spacing print('Time window: {:g} s ({} iterations)'.format(np.amax(time), iterations))
time = np.linspace(0, 1, iterations) print('Time step: {:g} s'.format(dt))
time *= (iterations * dt) print('Frequency bin spacing: {:g} Hz'.format(df))
df = 1 / np.amax(time)
print('Time window: {:g} s ({} iterations)'.format(np.amax(time), iterations)) # Read/calculate voltages and currents
print('Time step: {:g} s'.format(dt)) tlpath = '/tls/tl' + str(tln) + '/'
print('Frequency bin spacing: {:g} Hz'.format(df))
# Read/calculate voltages and currents # Incident voltages/currents
path = '/tls/tl' + str(args.tln) + '/' Vinc = f[tlpath + 'Vinc'][:]
Vinc = f[path + 'Vinc'][:] Iinc = f[tlpath + 'Iinc'][:]
Iinc = f[path + 'Iinc'][:]
Vtotal = f[path +'Vtotal'][:]
Itotal = f[path +'Itotal'][:]
Vrec = f['/rxs/rx1/Ex'][:] * -1
f.close()
Vref = Vtotal - Vinc
Iref = Itotal - Iinc
# Frequency bins # Total (incident + reflected) voltages/currents
freqs = np.fft.fftfreq(Vinc.size, d=dt) Vtotal = f[tlpath +'Vtotal'][:]
Itotal = f[tlpath +'Itotal'][:]
# Delay correction - current lags voltage, so delay voltage to match current timestep # Reflected voltages/currents
delaycorrection = np.exp(-1j * 2 * np.pi * freqs * (dt / 2)) Vref = Vtotal - Vinc
Iref = Itotal - Iinc
# Calculate s11 # If a receiver number for a receiever antenna is given can get received voltage for s21
s11 = np.abs(np.fft.fft(Vref) * delaycorrection) / np.abs(np.fft.fft(Vinc) * delaycorrection) if rxn:
s21 = np.abs(np.fft.fft(Vrec)) / np.abs(np.fft.fft(Vinc) * delaycorrection) if rx not in ['Ex', 'Ey', 'Ez']:
raise CmdInputError('The field component for the receiver antenna output must be Ex, Ey, or Ez')
rxpath = '/rxs/rx' + str(rxn) + '/' + rx
# Received voltage
Vrec = f[rxpath][:] * -1
f.close()
# Calculate input impedance # Frequency bins
zin = (np.fft.fft(Vtotal) * delaycorrection) / np.fft.fft(Itotal) freqs = np.fft.fftfreq(Vinc.size, d=dt)
# Load MoM zin from MATLAB antenna toolbox # Delay correction - current lags voltage, so delay voltage to match current timestep
#MoM = {} delaycorrection = np.exp(-1j * 2 * np.pi * freqs * (dt / 2))
#sio.loadmat('/../tests/numerical/vs_MoM_MATLAB/antenna_bowtie_fs/antenna_bowtie_fs_MoM.mat', MoM)
# Calculate input admittance # Calculate s11
yin = np.fft.fft(Itotal) / (np.fft.fft(Vtotal) * delaycorrection) s11 = np.abs(np.fft.fft(Vref) * delaycorrection) / np.abs(np.fft.fft(Vinc) * delaycorrection)
if rxn:
s21 = np.abs(np.fft.fft(Vrec)) / np.abs(np.fft.fft(Vinc) * delaycorrection)
# Convert to decibels # Calculate input impedance
Vincp = 20 * np.log10(np.abs((np.fft.fft(Vinc) * delaycorrection))) zin = (np.fft.fft(Vtotal) * delaycorrection) / np.fft.fft(Itotal)
Iincp = 20 * np.log10(np.abs(np.fft.fft(Iinc)))
Vrefp = 20 * np.log10(np.abs((np.fft.fft(Vref) * delaycorrection)))
Irefp = 20 * np.log10(np.abs(np.fft.fft(Iref)))
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)
s21 = 20 * np.log10(s21)
# Set plotting range # Calculate input admittance
pltrangemin = 1 yin = np.fft.fft(Itotal) / (np.fft.fft(Vtotal) * delaycorrection)
# To a certain drop from maximum power
pltrangemax = np.where((np.amax(Vincp[1::]) - Vincp[1::]) > 60)[0][0] + 1
# To a maximum frequency
#pltrangemax = np.where(freqs > 6e9)[0][0]
pltrange = np.s_[pltrangemin:pltrangemax]
# Print some useful values from s11, input impedance and admittance # Convert to decibels
s11minfreq = np.where(s11[pltrange] == np.amin(s11[pltrange]))[0][0] Vincp = 20 * np.log10(np.abs((np.fft.fft(Vinc) * delaycorrection)))
print('s11 minimum: {:g} dB at {:g} Hz'.format(np.amin(s11[pltrange]), freqs[s11minfreq + pltrangemin])) Iincp = 20 * np.log10(np.abs(np.fft.fft(Iinc)))
print('At {:g} Hz...'.format(freqs[s11minfreq + pltrangemin])) Vrefp = 20 * np.log10(np.abs((np.fft.fft(Vref) * delaycorrection)))
print('Input impedance: {:.1f}{:+.1f}j Ohms'.format(np.abs(zin[s11minfreq + pltrangemin]), zin[s11minfreq + pltrangemin].imag)) Irefp = 20 * np.log10(np.abs(np.fft.fft(Iref)))
print('Input admittance (mag): {:g} S'.format(np.abs(yin[s11minfreq + pltrangemin]))) Vtotalp = 20 * np.log10(np.abs((np.fft.fft(Vtotal) * delaycorrection)))
print('Input admittance (phase): {:.1f} deg'.format(np.angle(yin[s11minfreq + pltrangemin], deg=True))) Itotalp = 20 * np.log10(np.abs(np.fft.fft(Itotal)))
s11 = 20 * np.log10(s11)
if rxn:
s21 = 20 * np.log10(s21)
# Figure 1 # Set plotting range
# Plot incident voltage pltrangemin = 1
fig1, ax = plt.subplots(num='Transmission line parameters', figsize=(20, 12), facecolor='w', edgecolor='w') # To a certain drop from maximum power
gs1 = gridspec.GridSpec(4, 2, hspace=0.7) pltrangemax = np.where((np.amax(Vincp[1::]) - Vincp[1::]) > 60)[0][0] + 1
ax = plt.subplot(gs1[0, 0]) # To a maximum frequency
ax.plot(time, Vinc, 'r', lw=2, label='Vinc') #pltrangemax = np.where(freqs > 6e9)[0][0]
ax.set_title('Incident voltage') pltrange = np.s_[pltrangemin:pltrangemax]
ax.set_xlabel('Time [s]')
ax.set_ylabel('Voltage [V]')
ax.set_xlim([0, np.amax(time)])
ax.grid()
# Plot frequency spectra of incident voltage # Print some useful values from s11, and input impedance
ax = plt.subplot(gs1[0, 1]) s11minfreq = np.where(s11[pltrange] == np.amin(s11[pltrange]))[0][0]
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vincp[pltrange], '-.') print('s11 minimum: {:g} dB at {:g} Hz'.format(np.amin(s11[pltrange]), freqs[s11minfreq + pltrangemin]))
plt.setp(baseline, 'linewidth', 0) print('At {:g} Hz...'.format(freqs[s11minfreq + pltrangemin]))
plt.setp(stemlines, 'color', 'r') print('Input impedance: {:.1f}{:+.1f}j Ohms'.format(np.abs(zin[s11minfreq + pltrangemin]), zin[s11minfreq + pltrangemin].imag))
plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r') #print('Input admittance (mag): {:g} S'.format(np.abs(yin[s11minfreq + pltrangemin])))
ax.plot(freqs[pltrange], Vincp[pltrange], 'r', lw=2) #print('Input admittance (phase): {:.1f} deg'.format(np.angle(yin[s11minfreq + pltrangemin], deg=True)))
ax.set_title('Incident voltage')
ax.set_xlabel('Frequency [Hz]')
ax.set_ylabel('Power [dB]')
ax.grid()
# Plot incident current # Figure 1
ax = plt.subplot(gs1[1, 0]) # Plot incident voltage
ax.plot(time, Iinc, 'b', lw=2, label='Vinc') fig1, ax = plt.subplots(num='Transmission line parameters', figsize=(20, 12), facecolor='w', edgecolor='w')
ax.set_title('Incident current') gs1 = gridspec.GridSpec(4, 2, hspace=0.7)
ax.set_xlabel('Time [s]') ax = plt.subplot(gs1[0, 0])
ax.set_ylabel('Current [A]') ax.plot(time, Vinc, 'r', lw=2, label='Vinc')
ax.set_xlim([0, np.amax(time)]) ax.set_title('Incident voltage')
ax.grid() ax.set_xlabel('Time [s]')
ax.set_ylabel('Voltage [V]')
ax.set_xlim([0, np.amax(time)])
ax.grid()
# Plot frequency spectra of incident current # Plot frequency spectra of incident voltage
ax = plt.subplot(gs1[1, 1]) ax = plt.subplot(gs1[0, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Iincp[pltrange], '-.') markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vincp[pltrange], '-.')
plt.setp(baseline, 'linewidth', 0) plt.setp(baseline, 'linewidth', 0)
plt.setp(stemlines, 'color', 'b') plt.setp(stemlines, 'color', 'r')
plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b') plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r')
ax.plot(freqs[pltrange], Iincp[pltrange], 'b', lw=2) ax.plot(freqs[pltrange], Vincp[pltrange], 'r', lw=2)
ax.set_title('Incident current') ax.set_title('Incident voltage')
ax.set_xlabel('Frequency [Hz]') ax.set_xlabel('Frequency [Hz]')
ax.set_ylabel('Power [dB]') ax.set_ylabel('Power [dB]')
ax.grid() ax.grid()
# Plot total voltage # Plot incident current
ax = plt.subplot(gs1[2, 0]) ax = plt.subplot(gs1[1, 0])
ax.plot(time, Vtotal, 'r', lw=2, label='Vinc') ax.plot(time, Iinc, 'b', lw=2, label='Vinc')
ax.set_title('Total (incident + reflected) voltage') ax.set_title('Incident current')
ax.set_xlabel('Time [s]') ax.set_xlabel('Time [s]')
ax.set_ylabel('Voltage [V]') ax.set_ylabel('Current [A]')
ax.set_xlim([0, np.amax(time)]) ax.set_xlim([0, np.amax(time)])
ax.grid() ax.grid()
# Plot frequency spectra of total voltage # Plot frequency spectra of incident current
ax = plt.subplot(gs1[2, 1]) ax = plt.subplot(gs1[1, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vtotalp[pltrange], '-.') markerline, stemlines, baseline = ax.stem(freqs[pltrange], Iincp[pltrange], '-.')
plt.setp(baseline, 'linewidth', 0) plt.setp(baseline, 'linewidth', 0)
plt.setp(stemlines, 'color', 'r') plt.setp(stemlines, 'color', 'b')
plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r') plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
ax.plot(freqs[pltrange], Vtotalp[pltrange], 'r', lw=2) ax.plot(freqs[pltrange], Iincp[pltrange], 'b', lw=2)
ax.set_title('Total (incident + reflected) voltage') ax.set_title('Incident current')
ax.set_xlabel('Frequency [Hz]') ax.set_xlabel('Frequency [Hz]')
ax.set_ylabel('Power [dB]') ax.set_ylabel('Power [dB]')
ax.grid() ax.grid()
# Plot total current # Plot total voltage
ax = plt.subplot(gs1[3, 0]) ax = plt.subplot(gs1[2, 0])
ax.plot(time, Itotal, 'b', lw=2, label='Vinc') ax.plot(time, Vtotal, 'r', lw=2, label='Vinc')
ax.set_title('Total (incident + reflected) current') ax.set_title('Total (incident + reflected) voltage')
ax.set_xlabel('Time [s]') ax.set_xlabel('Time [s]')
ax.set_ylabel('Current [A]') ax.set_ylabel('Voltage [V]')
ax.set_xlim([0, np.amax(time)]) ax.set_xlim([0, np.amax(time)])
ax.grid() ax.grid()
# Plot frequency spectra of reflected current # Plot frequency spectra of total voltage
ax = plt.subplot(gs1[3, 1]) ax = plt.subplot(gs1[2, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Itotalp[pltrange], '-.') markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vtotalp[pltrange], '-.')
plt.setp(baseline, 'linewidth', 0) plt.setp(baseline, 'linewidth', 0)
plt.setp(stemlines, 'color', 'b') plt.setp(stemlines, 'color', 'r')
plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b') plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r')
ax.plot(freqs[pltrange], Itotalp[pltrange], 'b', lw=2) ax.plot(freqs[pltrange], Vtotalp[pltrange], 'r', lw=2)
ax.set_title('Total (incident + reflected) current') ax.set_title('Total (incident + reflected) voltage')
ax.set_xlabel('Frequency [Hz]') ax.set_xlabel('Frequency [Hz]')
ax.set_ylabel('Power [dB]') ax.set_ylabel('Power [dB]')
ax.grid() ax.grid()
## Plot reflected (reflected) voltage # Plot total current
#ax = plt.subplot(gs1[4, 0]) ax = plt.subplot(gs1[3, 0])
#ax.plot(time, Vref, 'r', lw=2, label='Vref') ax.plot(time, Itotal, 'b', lw=2, label='Vinc')
#ax.set_title('Reflected voltage') ax.set_title('Total (incident + reflected) current')
#ax.set_xlabel('Time [s]') ax.set_xlabel('Time [s]')
#ax.set_ylabel('Voltage [V]') ax.set_ylabel('Current [A]')
#ax.set_xlim([0, np.amax(time)]) ax.set_xlim([0, np.amax(time)])
#ax.grid() ax.grid()
#
## 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)
#plt.setp(stemlines, 'color', 'r')
#plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r')
#ax.plot(freqs[pltrange], Vrefp[pltrange], 'r', lw=2)
#ax.set_title('Reflected voltage')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Power [dB]')
#ax.grid()
#
## 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()
#
## 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)
#plt.setp(stemlines, 'color', 'b')
#plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
#ax.plot(freqs[pltrange], Irefp[pltrange], 'b', lw=2)
#ax.set_title('Reflected current')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Power [dB]')
#ax.grid()
# Figure 2 # Plot frequency spectra of reflected current
# Plot frequency spectra of s11 ax = plt.subplot(gs1[3, 1])
fig2, ax = plt.subplots(num='Antenna parameters', figsize=(20, 12), facecolor='w', edgecolor='w') markerline, stemlines, baseline = ax.stem(freqs[pltrange], Itotalp[pltrange], '-.')
gs2 = gridspec.GridSpec(2, 2, hspace=0.5) plt.setp(baseline, 'linewidth', 0)
ax = plt.subplot(gs2[0, 0]) plt.setp(stemlines, 'color', 'b')
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s11[pltrange], '-.') plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
plt.setp(baseline, 'linewidth', 0) ax.plot(freqs[pltrange], Itotalp[pltrange], 'b', lw=2)
plt.setp(stemlines, 'color', 'g') ax.set_title('Total (incident + reflected) current')
plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g') ax.set_xlabel('Frequency [Hz]')
ax.plot(freqs[pltrange], s11[pltrange], 'g', lw=2) ax.set_ylabel('Power [dB]')
ax.set_title('s11') ax.grid()
ax.set_xlabel('Frequency [Hz]')
ax.set_ylabel('Power [dB]')
#ax.set_xlim([0.88e9, 1.02e9])
ax.set_ylim([-20, 0])
ax.grid()
# Plot frequency spectra of s21 ## Plot reflected (reflected) voltage
ax = plt.subplot(gs2[0, 1]) #ax = plt.subplot(gs1[4, 0])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s21[pltrange], '-.') #ax.plot(time, Vref, 'r', lw=2, label='Vref')
plt.setp(baseline, 'linewidth', 0) #ax.set_title('Reflected voltage')
plt.setp(stemlines, 'color', 'g') #ax.set_xlabel('Time [s]')
plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g') #ax.set_ylabel('Voltage [V]')
ax.plot(freqs[pltrange], s21[pltrange], 'g', lw=2) #ax.set_xlim([0, np.amax(time)])
ax.set_title('s21') #ax.grid()
ax.set_xlabel('Frequency [Hz]') #
ax.set_ylabel('Power [dB]') ## Plot frequency spectra of reflected voltage
#ax.set_xlim([0.88e9, 1.02e9]) #ax = plt.subplot(gs1[4, 1])
ax.set_ylim([-25, 50]) #markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vrefp[pltrange], '-.')
ax.grid() #plt.setp(baseline, 'linewidth', 0)
#plt.setp(stemlines, 'color', 'r')
#plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r')
#ax.plot(freqs[pltrange], Vrefp[pltrange], 'r', lw=2)
#ax.set_title('Reflected voltage')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Power [dB]')
#ax.grid()
#
## 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()
#
## 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)
#plt.setp(stemlines, 'color', 'b')
#plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
#ax.plot(freqs[pltrange], Irefp[pltrange], 'b', lw=2)
#ax.set_title('Reflected current')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Power [dB]')
#ax.grid()
# Plot input resistance (real part of impedance) # Figure 2
ax = plt.subplot(gs2[1, 0]) # Plot frequency spectra of s11
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].real, '-.') fig2, ax = plt.subplots(num='Antenna parameters', figsize=(20, 12), facecolor='w', edgecolor='w')
plt.setp(baseline, 'linewidth', 0) gs2 = gridspec.GridSpec(2, 2, hspace=0.5)
plt.setp(stemlines, 'color', 'g') ax = plt.subplot(gs2[0, 0])
plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g') markerline, stemlines, baseline = ax.stem(freqs[pltrange], s11[pltrange], '-.')
ax.plot(freqs[pltrange], zin[pltrange].real, 'g', lw=2) plt.setp(baseline, 'linewidth', 0)
ax.set_title('Input impedance (resistive)') plt.setp(stemlines, 'color', 'g')
ax.set_xlabel('Frequency [Hz]') plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
ax.set_ylabel('Resistance [Ohms]') ax.plot(freqs[pltrange], s11[pltrange], 'g', lw=2)
#ax.set_xlim([0.88e9, 1.02e9]) ax.set_title('s11')
ax.set_ylim(bottom=0) ax.set_xlabel('Frequency [Hz]')
ax.set_ylim([0, 300]) ax.set_ylabel('Power [dB]')
ax.grid() #ax.set_xlim([0.88e9, 1.02e9])
#ax.set_ylim([-20, 0])
ax.grid()
# Plot input reactance (imaginery part of impedance) # Plot frequency spectra of s21
ax = plt.subplot(gs2[1, 1]) if rxn:
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].imag, '-.') ax = plt.subplot(gs2[0, 1])
plt.setp(baseline, 'linewidth', 0) markerline, stemlines, baseline = ax.stem(freqs[pltrange], s21[pltrange], '-.')
plt.setp(stemlines, 'color', 'g') plt.setp(baseline, 'linewidth', 0)
plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g') plt.setp(stemlines, 'color', 'g')
ax.plot(freqs[pltrange], zin[pltrange].imag, 'g', lw=2) plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
ax.set_title('Input impedance (reactive)') ax.plot(freqs[pltrange], s21[pltrange], 'g', lw=2)
ax.set_xlabel('Frequency [Hz]') ax.set_title('s21')
ax.set_ylabel('Reactance [Ohms]') ax.set_xlabel('Frequency [Hz]')
#ax.set_xlim([0.88e9, 1.02e9]) ax.set_ylabel('Power [dB]')
ax.set_ylim([-200, 100]) #ax.set_xlim([0.88e9, 1.02e9])
ax.grid() #ax.set_ylim([-25, 50])
ax.grid()
## Plot input admittance (magnitude) # Plot input resistance (real part of impedance)
#ax = plt.subplot(gs2[2, 0]) ax = plt.subplot(gs2[1, 0])
#markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.abs(yin[pltrange]), '-.') markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].real, '-.')
#plt.setp(baseline, 'linewidth', 0) plt.setp(baseline, 'linewidth', 0)
#plt.setp(stemlines, 'color', 'g') plt.setp(stemlines, 'color', 'g')
#plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g') plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
#ax.plot(freqs[pltrange], np.abs(yin[pltrange]), 'g', lw=2) ax.plot(freqs[pltrange], zin[pltrange].real, 'g', lw=2)
#ax.set_title('Input admittance (magnitude)') ax.set_title('Input impedance (resistive)')
#ax.set_xlabel('Frequency [Hz]') ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Admittance [Siemens]') ax.set_ylabel('Resistance [Ohms]')
##ax.set_xlim([0.88e9, 1.02e9]) #ax.set_xlim([0.88e9, 1.02e9])
##ax.set_ylim([0, 0.035]) ax.set_ylim(bottom=0)
#ax.grid() #ax.set_ylim([0, 300])
# ax.grid()
## 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)
#plt.setp(stemlines, 'color', 'g')
#plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
#ax.plot(freqs[pltrange], np.angle(yin[pltrange], deg=True), 'g', lw=2)
#ax.set_title('Input admittance (phase)')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Phase [degrees]')
##ax.set_xlim([0.88e9, 1.02e9])
##ax.set_ylim([-40, 100])
#ax.grid()
# Figure 3 - Comparison of numerical modelling techniques # Plot input reactance (imaginery part of impedance)
#fig3, ax = plt.subplots(num='FDTD vs MoM', figsize=(20, 5), facecolor='w', edgecolor='w') ax = plt.subplot(gs2[1, 1])
#gs3 = gridspec.GridSpec(1, 2, hspace=0.5) markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].imag, '-.')
# plt.setp(baseline, 'linewidth', 0)
## Plot input resistance (real part of impedance) plt.setp(stemlines, 'color', 'g')
#ax = plt.subplot(gs3[0, 0]) plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
#ax.plot(freqs[pltrange], zin[pltrange].real, 'g', lw=2, label='FDTD') ax.plot(freqs[pltrange], zin[pltrange].imag, 'g', lw=2)
#ax.plot(MoM['freqs'], MoM['zin'].real, 'r', lw=2, ls='--', label='MoM') ax.set_title('Input impedance (reactive)')
#ax.set_title('Input impedance (resistive)') ax.set_xlabel('Frequency [Hz]')
#ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Reactance [Ohms]')
#ax.set_ylabel('Resistance [Ohms]') #ax.set_xlim([0.88e9, 1.02e9])
##ax.set_xlim([0.88e9, 1.02e9]) #ax.set_ylim([-200, 100])
#ax.set_ylim(bottom=0) ax.grid()
#ax.set_ylim([0, 350])
#ax.grid()
#ax.legend()
#
## Plot input reactance (imaginery part of impedance)
#ax = plt.subplot(gs3[0, 1])
#ax.plot(freqs[pltrange], zin[pltrange].imag, 'g', lw=2, label='FDTD')
#ax.plot(MoM['freqs'], -MoM['zin'].imag, 'r', lw=2, ls='--', label='MoM')
#ax.set_title('Input impedance (reactive)')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Reactance [Ohms]')
##ax.set_xlim([0.88e9, 1.02e9])
#ax.set_ylim([-350, 350])
#ax.grid()
#ax.legend()
# Save a PDF/PNG of the figure ## Plot input admittance (magnitude)
#fig1.savefig(os.path.splitext(os.path.abspath(file))[0] + '_tl_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1) #ax = plt.subplot(gs2[2, 0])
#fig2.savefig(os.path.splitext(os.path.abspath(file))[0] + '_ant_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1) #markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.abs(yin[pltrange]), '-.')
#fig3.savefig(os.path.splitext(os.path.abspath(file))[0] + '_ant_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1) #plt.setp(baseline, 'linewidth', 0)
#fig1.savefig(os.path.splitext(os.path.abspath(file))[0] + '_tl_params.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #plt.setp(stemlines, 'color', 'g')
#fig2.savefig(os.path.splitext(os.path.abspath(file))[0] + '_ant_params.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
#ax.plot(freqs[pltrange], np.abs(yin[pltrange]), 'g', lw=2)
#ax.set_title('Input admittance (magnitude)')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Admittance [Siemens]')
##ax.set_xlim([0.88e9, 1.02e9])
##ax.set_ylim([0, 0.035])
#ax.grid()
#
## 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)
#plt.setp(stemlines, 'color', 'g')
#plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
#ax.plot(freqs[pltrange], np.angle(yin[pltrange], deg=True), 'g', lw=2)
#ax.set_title('Input admittance (phase)')
#ax.set_xlabel('Frequency [Hz]')
#ax.set_ylabel('Phase [degrees]')
##ax.set_xlim([0.88e9, 1.02e9])
##ax.set_ylim([-40, 100])
#ax.grid()
# Save a PDF/PNG of the figure
#fig1.savefig(os.path.splitext(os.path.abspath(file))[0] + '_tl_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
#fig2.savefig(os.path.splitext(os.path.abspath(file))[0] + '_ant_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
#fig3.savefig(os.path.splitext(os.path.abspath(file))[0] + '_ant_params.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
#fig1.savefig(os.path.splitext(os.path.abspath(file))[0] + '_tl_params.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
#fig2.savefig(os.path.splitext(os.path.abspath(file))[0] + '_ant_params.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
plt.show()
if __name__ == "__main__":
# Parse command line arguments
parser = argparse.ArgumentParser(description='Plots antenna parameters (s11, s21 parameters and input impedance) from an output file containing a transmission line source.', usage='cd gprMax; python -m tools.plot_antenna_params outputfile')
parser.add_argument('outputfile', help='name of output file including path')
parser.add_argument('-tln', default=1, type=int, help='transmitting antenna - transmission line number')
parser.add_argument('-rxn', type=int, help='receiver antenna - output number')
parser.add_argument('-rx', type=str, help='receiver antenna - output electric field component')
args = parser.parse_args()
plot_antenna_params(args.outputfile, args.tln, args.rxn, args.rx)
plt.show()