These should be useful, but have to be cleaned up.
def csvreader(fname, remove_last=True):
import numpy as np
with open (fname, 'r') as myfile:
data = myfile.read().replace(',', '.').replace('\n', ',').replace(' ', ',')
datarray = data.split(',')
if remove_last == True:
return np.array([float(i) for i in datarray[2:-1]])
else:
return np.array([float(i) for i in datarray[2:]])
def findnegative(x, y):
i = 0
x_ = []
y_ = []
while y[i] < 0:
x_.append(x[i])
y_.append(y[i])
i +=1
return x_, y_
def positivecurrents(u, i, ie):
u_ = np.array([x for x in u if x not in findnegative(u, i)[0]])
i_ = np.sqrt(np.array([x for x in i if x not in findnegative(u, i)[1]]))
ue = tolerance(u_, 0.005, 0.001)
ie = (tolerance(i_, 0.008, np.array(ie) * 10**-6)) / 2
return u_, ue, i_, ie
def grenzspannung(u, i, ue, ie, label=None, color='darkorange'):
import numpy as np
plt.errorbar(u, (i), xerr=ue, yerr = ie, fmt='x', label=r'$\lambda={}\,$nm'.format(label), color=color)
TT.linreg(u, (i), method='lm', labelaus=r'Linear regression for $\lambda={}\,$nm'.format(label), color=color, grenz=False)
print('Critical voltage {}'.format(label), ufloat(TT.b(u, (i)), TT.Db(u, (i)))
/ ufloat(TT.a(u, (i)), TT.Da(u, (i))))
print('slope {}:'.format(label), TT.a(u, i), '\pm', TT.Da(u, i))
print('intercept {}:'.format(label), TT.b(u, i), '\pm', TT.Db(u, i))
return```
These should be useful, but have to be cleaned up.