BigThonkers / ThonkTools

Revolutionary wrappers for stupid lab stuff.
1 stars 3 forks source link

Add functions from V81 #10

Open munnich opened 5 years ago

munnich commented 5 years ago

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```
munnich commented 5 years ago

Started a new branch for these: https://github.com/BigThonkers/ThonkTools/tree/new_funcs I don't see any reason to include the third function, as it seems more like a single use case thing than anything else.