Skip to content
Snippets Groups Projects
Commit 035e6ba2 authored by JupyterHub User's avatar JupyterHub User
Browse files

part4

parent ce03bab4
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:f3bb2a53-f571-4da3-b09f-4c8ee8c75a83 tags:
``` python
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
import numpy as np
from sklearn.linear_model import LinearRegression
```
%% Cell type:code id:a9461575-0bd1-4e25-8403-ed4eb12ccce2 tags:
``` python
voltage_values = [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2.0, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3.0, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4.0, 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5.0, 5.05, 5.1, 5.15, 5.2, 5.25, 5.3, 5.35, 5.4, 5.45, 5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.85, 5.9, 5.95, 6.0, 6.05, 6.1, 6.15, 6.2, 6.25, 6.3, 6.35, 6.4, 6.45, 6.5, 6.55, 6.6, 6.65, 6.7, 6.75, 6.8, 6.85, 6.9, 6.95, 7.0, 7.05, 7.1, 7.15, 7.2, 7.25, 7.3, 7.35, 7.4, 7.45, 7.5, 7.55, 7.6, 7.65, 7.7, 7.75, 7.8, 7.85, 7.9, 7.95, 8.0, 8.05, 8.1, 8.15, 8.2, 8.25, 8.3, 8.35, 8.4, 8.45, 8.5, 8.55, 8.6, 8.65, 8.7, 8.75, 8.8, 8.85, 8.9, 8.95, 9.0, 9.05, 9.1, 9.15, 9.2, 9.25, 9.3, 9.35, 9.4, 9.45, 9.5, 9.55, 9.6, 9.65, 9.7, 9.75, 9.8, 9.85, 9.9, 9.95, 10.0]
print(len(voltage_values))
```
%% Output
201
%% Cell type:code id:b12e1696-12d9-4b94-9028-2610ec7e73c6 tags:
``` python
current_values = [-2.0172e-07, 1.7837e-05, 3.7577e-05, 6.0445e-05, 8.5833e-05, 0.000113797, 0.00014604, 0.0001823, 0.00022479, 0.00027261, 0.00032461, 0.00038161, 0.00044615, 0.00051651, 0.00059047, 0.00066731, 0.00075451, 0.0008448, 0.00093602, 0.00102376, 0.0011258, 0.0012281, 0.0013295, 0.0014353, 0.0015563, 0.0016701, 0.0017803, 0.0018951, 0.002029, 0.0021518, 0.0022691, 0.0023878, 0.0025273, 0.0026616, 0.0027876, 0.002916, 0.0030592, 0.0032063, 0.0033439, 0.003475, 0.0036308, 0.0037965, 0.0039297, 0.0040698, 0.0042341, 0.004404, 0.0045565, 0.0046994, 0.0048693, 0.0050476, 0.0052095, 0.0053543, 0.0055203, 0.0057068, 0.0058664, 0.0060137, 0.0061811, 0.0063717, 0.0065344, 0.0066796, 0.0068391, 0.0070318, 0.0072005, 0.0073433, 0.0074938, 0.0076875, 0.0078528, 0.0079939, 0.0081331, 0.008324, 0.0084877, 0.0086322, 0.0087642, 0.0089491, 0.0091169, 0.0092587, 0.0094001, 0.0095756, 0.0097471, 0.0098836, 0.0100007, 0.0101695, 0.0103403, 0.0104739, 0.0105835, 0.010747, 0.0109165, 0.0110492, 0.0111549, 0.0113035, 0.011437, 0.011582, 0.011752, 0.011885, 0.01199, 0.012118, 0.012294, 0.012424, 0.012515, 0.012631, 0.012812, 0.012943, 0.013039, 0.013146, 0.013317, 0.01345, 0.013551, 0.013645, 0.013811, 0.01394, 0.014039, 0.014122, 0.014289, 0.014246, 0.014127, 0.014193, 0.014335, 0.014895, 0.014997, 0.015063, 0.01521, 0.01535, 0.015448, 0.015513, 0.015641, 0.015792, 0.015895, 0.015949, 0.016056, 0.016203, 0.016302, 0.016362, 0.016492, 0.016636, 0.016745, 0.016774, 0.016874, 0.017036, 0.017124, 0.017172, 0.017251, 0.01741, 0.017513, 0.017609, 0.017646, 0.017794, 0.017869, 0.017955, 0.01802, 0.018137, 0.018244, 0.018323, 0.018396, 0.018502, 0.018611, 0.018682, 0.018713, 0.018826, 0.018934, 0.019005, 0.019042, 0.019156, 0.019268, 0.019344, 0.019375, 0.019478, 0.019604, 0.019675, 0.019701, 0.019793, 0.019926, 0.019996, 0.020026, 0.020103, 0.020242, 0.020314, 0.020345, 0.020408, 0.020549, 0.020624, 0.021077, 0.020751, 0.020862, 0.02093, 0.020973, 0.021014, 0.021131, 0.021219, 0.021269, 0.021204, 0.02139, 0.02151, 0.021572, 0.02159, 0.021701, 0.021798, 0.021869, 0.021896, 0.021991, 0.022039, 0.022167]
print(len(current_values))
```
%% Output
201
%% Cell type:code id:c7f1a914-cca3-4de7-8cbc-ccdb94197658 tags:
``` python
#add title to the results
header = ['Voltage(V)', 'Current(A)']
data = {header[0]:voltage_values,header[1]:current_values}
df = pd.DataFrame(data)
date = str(datetime.today().replace(microsecond=0))
print(date)
```
%% Output
2023-09-08 09:08:43
2023-09-08 09:46:45
%% Cell type:code id:30ac24c1-d6ed-4e41-8d7c-fa0fe44e072f tags:
``` python
#export table in pdf file
fig = plt.figure(figsize = (8,2))
fig.suptitle('I-V measurement results at:'+ date, y=9)
ax = fig.add_subplot(111)
ax.table(cellText = df.values,
rowLabels = df.index,
colLabels = df.columns,
loc = "center")
plt.axis('off')
plt.savefig('results.pdf',format="pdf",bbox_inches="tight")
```
%% Output
%% Cell type:code id:09d63039-ef49-4c65-be9d-9c7326428cdc tags:
``` python
#exporting the data frame in an excel file
#file_name = 'results '+date+'.xlsx'
#df.to_excel(file_name)
file_name = '\results '+date+'.txt'
file_name = '\ results '+date+'.txt'
path = "\\FILESERVER\public\Datentransfer\Asonitis, Alexandros" + file_name
#export DataFrame to text file (keep header row and index column)
with open(path, 'a') as f:
f.write('title.\n\n')
df_string = df.to_string()
f.write(df_string)
```
%% Cell type:code id:1f89f490-e901-43cb-b1f4-cda5b4cf6ae8 tags:
``` python
x=np.array(voltage_values).reshape((-1,1)) #column matrix
y = np.array(current_values)
#create a model
model = LinearRegression()
model.fit(x, y)
r_sq = model.score(x, y)
print(f"coefficient of determination: {r_sq}")
print(f"intercept: {model.intercept_}")
print(f"slope: {model.coef_}")
plt.figure()
plt.plot(voltage_values,current_values,label='real curve')
plt.plot(x,model.coef_*x+model.intercept_,label='linear')
plt.xlabel('Voltage(V)')
plt.ylabel('Current(A)')
plt.title("I-V plot")
plt.legend()
plt.show()
```
%% Output
coefficient of determination: 0.9873880135298887
intercept: -0.00043234755330870747
slope: [0.00243783]
%% Cell type:code id:49c0c86e-bc82-42c6-b6fa-a3b8fa926f6d tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment