75 lines
3.1 KiB
Python
75 lines
3.1 KiB
Python
import datetime
|
|
import numpy as np
|
|
from matplotlib.backends.backend_pdf import PdfPages
|
|
import matplotlib.pyplot as plt
|
|
import os
|
|
from PIL import Image
|
|
|
|
|
|
def calculate_1st_dervative( x, y):
|
|
derv = []
|
|
for i in range(len(x)):
|
|
if i < len(x) - 1:
|
|
derv.append((y[i + 1] - y[i]) / (x[i + 1] - x[i]))
|
|
return derv
|
|
|
|
|
|
antenna_number = '2'
|
|
measuremnts_dir = os.path.join(os.getcwd(), 'measurements', 'triact', 'measurements')
|
|
files = os.listdir(measuremnts_dir)
|
|
with PdfPages(os.path.join(measuremnts_dir, 'Plots.pdf')) as pdf:
|
|
for i, file in enumerate(files):
|
|
fileType = file.split('.')[1]
|
|
fileName = file.split('.')[0]
|
|
if fileType == 'npy':
|
|
sweptFrequenciesArray = np.load(os.path.join(measuremnts_dir, file))
|
|
xAxis = np.real(sweptFrequenciesArray[:, 0] / 1000)
|
|
|
|
coloumn = int(antenna_number)
|
|
yAxisReal = np.real(sweptFrequenciesArray[:, coloumn])
|
|
yAxisImag = np.imag(sweptFrequenciesArray[:, coloumn])
|
|
derv_imag = calculate_1st_dervative(list(xAxis), list(yAxisImag))
|
|
derv_real = calculate_1st_dervative(list(xAxis), list(yAxisReal))
|
|
abs = np.abs(sweptFrequenciesArray[:, coloumn])
|
|
derv_abs = calculate_1st_dervative(list(xAxis), np.abs(sweptFrequenciesArray[:, coloumn]))
|
|
|
|
plt.figure(1, figsize=(8, 6), dpi=120)
|
|
plt.plot(xAxis, yAxisReal, label='antenna ' + antenna_number + ' real part')
|
|
plt.plot(xAxis, yAxisImag, label='antenna' + antenna_number + ' imag. part')
|
|
plt.plot(xAxis[0:-1], derv_real, '--',
|
|
label='antenna ' + antenna_number + ' 1st derv real part')
|
|
plt.plot(xAxis[0:-1], derv_imag, '--',
|
|
label='antenna' + antenna_number + ' 1st derv imag. part')
|
|
plt.plot(xAxis, abs, '-*', label='antenna ' + antenna_number + ' abs')
|
|
plt.plot(xAxis[0:-1], derv_abs, '-o', label='antenna' + antenna_number + ' 1st derv of abs')
|
|
|
|
plt.annotate("Min. real", (xAxis[np.where(yAxisReal == np.min(yAxisReal))], np.min(yAxisReal)))
|
|
plt.annotate("Min. imag", (xAxis[np.where(yAxisImag == np.min(yAxisImag))], np.min(yAxisImag)))
|
|
|
|
plt.annotate("Max. real", (xAxis[np.where(yAxisReal == np.max(yAxisReal))], np.max(yAxisReal)))
|
|
plt.annotate("Max. imag", (xAxis[np.where(yAxisImag == np.max(yAxisImag))], np.max(yAxisImag)))
|
|
|
|
plt.annotate("Max. abs", (xAxis[np.where(abs == np.max(abs))], np.max(abs)))
|
|
plt.annotate("Min. abs", (xAxis[np.where(abs == np.min(abs))], np.min(abs)))
|
|
|
|
plt.legend()
|
|
plt.grid()
|
|
plt.xlabel('Frequency (kHz)')
|
|
plt.ylabel('Induced voltage (V)')
|
|
plt.title('Object number ' + fileName.split('_')[0])
|
|
|
|
pdf.savefig(1) # saves the current figure into a pdf page
|
|
plt.close()
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
#
|
|
# with PdfPages('multipage_pdf.pdf') as pdf:
|
|
# plt.figure(figsize=(3, 3))
|
|
# plt.plot(range(7), [3, 1, 4, 1, 5, 9, 2], 'r-o')
|
|
# plt.title('Page One')
|
|
# pdf.savefig() # saves the current figure into a pdf page
|
|
# plt.close() |