47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from matplotlib import pyplot as plt
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plotData(data):
|
|
"""Plot the data contained in the given DataFrame."""
|
|
|
|
fig, ax = plt.subplots(2, 1)
|
|
ax[0].plot(data['v'], data['i_dmm'], label='Keithley')
|
|
ax[0].plot(data['v'], data['i_hv'], label='HV port')
|
|
ax[0].plot(data['v'], data['i_calc'], label='Calculated')
|
|
ax[0].set_xlabel('Voltage (V)')
|
|
ax[0].set_ylabel('Current (1 uA)')
|
|
ax[0].legend()
|
|
ax[1].plot(data['v'], data['i_dmm'] - data['i_calc'], label='Difference KEI')
|
|
ax[1].plot(data['v'], data['i_hv'] - data['i_calc'], label='Difference HV')
|
|
ax[1].set_xlabel('Voltage (V)')
|
|
ax[1].grid()
|
|
ax[1].set_ylabel('Current difference (uA)')
|
|
ax[1].legend()
|
|
plt.show()
|
|
|
|
|
|
#import excel file
|
|
data = pd.read_excel('data_biasTEST.xlsx')
|
|
# data['ppm'] = (data['i_kei'] - data['i_hv']) / data['i_kei'] * 1e6
|
|
# sample_cal = round(len(data) * 0.8)
|
|
# print(f"Sample for calibration: {data['ppm'].iloc[sample_cal:sample_cal+20].mean()} ppm")
|
|
|
|
# linear regression for i_kei
|
|
from sklearn.linear_model import LinearRegression
|
|
X = data['v'].values.reshape(-1, 1)
|
|
y = data['i_hv'].values
|
|
reg = LinearRegression().fit(X, y)
|
|
data['i_calc'] = reg.predict(X)
|
|
print(f"Linear regression: {reg.coef_[0]} A/V")
|
|
print(f"Linear regression: {reg.intercept_} A")
|
|
|
|
|
|
print(data)
|
|
plotData(data)
|