Exemplo n.º 1
0
def aufgabe1_2():
    #load parameters aufgabe 1.2
    #Temp in °C, U1 in V, U3 in V, Uf in V
    hlines, data = ppk.readCSV("Aufgabe1.csv",1)
    #load data
    #t,UA,U2
    hlines, d160 = ppk.readCSV("12aufgabe_160.csv",3)
    hlines, d150 = ppk.readCSV("12aufgabe_150.csv",3)
    hlines, d140 = ppk.readCSV("12aufgabe_140.csv",3)
    hlines, d120 = ppk.readCSV("12aufgabe_120.csv",3)
    dcsv = [d160,d150,d140,d120]

    splx = spline_it(dcsv,4)

    HP160, TP = minmaxfind( splx[0]( splx[1] ) )
    HP150, TP = minmaxfind( splx[2]( splx[3] ) )
    HP140, TP = minmaxfind( splx[4]( splx[5] ) )
    HP120, TP = minmaxfind( splx[6]( splx[7] ) )

    #korrekturen
    HP140 = np.delete(HP140,0)
    HP120 = np.delete(HP120, [0,1,2])
    HP = [HP160, HP150, HP140, HP120]

    #berechungen
    i = 0
    UKm = np.array([])
    while i < 4:
        U1 = data[1][i]
        U2 = splx[2*i+1]
        peaks = HP[i]
        pc = len(peaks)

        UDach = U2[peaks[0]] + U1
        DeltaU = np.array([])

        for j in np.arange(1,pc-1):
            temp = U2[peaks[j]] - U2[peaks[j-1]]
            DeltaU = np.hstack((DeltaU, temp))
        DUm = np.mean(DeltaU)
        UK = UDach - DUm
        UKm = np.hstack((UKm, UK))
        print(i, DUm, UK, "\n")
        i += 1
        pass
    UKm = np.mean(UKm)
    print(UKm)
    '''
    for i in np.arange(4):
        plot(splx,i)
    '''
    return;
Exemplo n.º 2
0
def loadCSV(name,hlines=1,split=2): #liest eine , getrennte CSV ein und teilt in arrays nach spalten
    hlines, data = ppk.readCSV(name,hlines)
    data = np.array(data)
    a,b=np.split(data,split)
    a = a[0] # anpassen nach split
    b = b[0]
    return a,b;
Exemplo n.º 3
0
def aufgabe1_4a():
    U1 = 2.3    #V
    Uf = 6.0    #V
    U3 = 0.91   #V
    T  = 120     #°C
    #U2 in V, Ig2 in A
    hlines, data = ppk.readCSV("Aufgabe1_4a.csv",2)
    data[0] = data[0] - UK

    slb, intb, r, p, std = stats.linregress(data[0][:6], data[1][:6]);
    slr, intr, r, p, std = stats.linregress(data[0][6:12], data[1][6:12]);

    pb = np.poly1d([slb,intb])
    pr = np.poly1d([slr,intr])
    xb = np.linspace(-3,12,50)
    xr = np.linspace(8,20,50)

    x0 = np.roots((pb-pr))
    print(x0)

    plt.plot(data[0][0:6],data[1][0:6],"ob")
    plt.plot(xb,pb(xb),"-b")

    plt.plot(data[0][6:12],data[1][6:12],"or")
    plt.plot(xr,pr(xr),"-r")

    plt.plot(x0,pb(x0),"xk")
    plt.plot(data[0][12:],data[1][12:],"og")

    plt.xlabel("U2 in V")
    plt.ylabel("Anodenstrom I in A")
    plt.grid(True)
    plt.show()
    return;
Exemplo n.º 4
0
def a14():
    hlines, doK = ppk.readCSV("daten14oK.csv", 3)
    hlines, dmK = ppk.readCSV("daten14mK.csv", 3)
    vok = doK[2] / doK[1]
    vmk = dmK[2] / dmK[1]

    plt.plot(doK[0], vok, "xb", label="Ohne Kondensator")
    #plt.plot(doK[0], vok, "-b")
    plt.plot(dmK[0], vmk, "xr", label="Mit Kondensator")
    #plt.plot(dmK[0], vmk, "-r")
    plt.legend()
    plt.xscale("log")
    plt.xlabel("f in Hz")
    plt.ylabel("Verstärkungsfaktor")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 5
0
def gamma():
    t = 200
    rho = 11530
    R0 = 0.224
    tau = 0.001
    hlines, dCo = ppk.readCSV("gammaCo.csv", 2)
    hlines, dCs = ppk.readCSV("gammaCs.csv", 2)

    dPb = dCo[0] / 1000
    RCouk = dCo[1] / t
    RCsuk = dCs[1] / t
    RCo = (RCouk / (1 - RCouk * tau)) - R0
    RCs = (RCsuk / (1 - RCsuk * tau)) - R0

    RCo = np.log(RCo)
    RCs = np.log(RCs)

    slp1, int1, r_value, p_value, std_err = stats.linregress(dPb, RCo)
    slp2, int2, r_value, p_value, std_err = stats.linregress(dPb, RCs)

    myCo = slp1
    myCs = slp2

    cCo = myCo / rho
    cCs = myCs / rho

    dhCo = np.log(2) / myCo
    dhCs = np.log(2) / myCs

    print("absorbkoeff my Co, Cs: ", myCo, myCs)
    print("massenabsorbkoeff c Co, Cs: ", cCo, cCs)
    print("halbwertsdicke blei Co, Cs: ", dhCo, dhCs)

    plt.plot(dPb, RCo, "ob")
    plt.plot(dPb, RCs, "or")
    plt.plot(dPb, slp1 * dPb + int1, "-b")
    plt.plot(dPb, slp2 * dPb + int2, "-r")
    plt.xlabel("dicke Blei in m")
    plt.ylabel("Korrigierte Zählrate (log)")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 6
0
def aufgabe1_4b():
    #t,UA,U2
    hlines, data = ppk.readCSV("14baufgabe.csv",3)
    data[2] = data[2] - UK

    plt.plot(data[2], data[1], "-r")
    plt.xlabel("U2 in V")
    plt.ylabel("UA in V")
    plt.grid(True)
    plt.show()
    return;
Exemplo n.º 7
0
def nulleffekt12():
    hlines, data = ppk.readCSV("Nulleffekt2.csv", 2)
    N = np.arange(len(data[1]))
    for i in np.arange(len(data[1]) - 1):
        N[i + 1] = data[1][i + 1] - data[1][i]

    Nt = N / 5

    NUm = np.mean(Nt)
    NUs = np.std(Nt)
    print(NUm, NUs)

    return
Exemplo n.º 8
0
def a23():
    hlines, d = ppk.readCSV("daten23.csv", 3)
    v = d[1] / 0.5

    plt.plot(d[0], v, "xb")
    #plt.plot(d[0], v, "-b")
    plt.legend()
    plt.xscale("log")
    plt.xlabel("f in Hz")
    plt.ylabel("Verstärkungsfaktor")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 9
0
def beta():
    hlines, data = ppk.readCSV("beta.csv", 1)
    d = data[0] * 1e-6
    R0 = 0.224
    tau = 0.001
    rho = 2.71 * 1000

    Ruk = data[1] / data[2]
    R = (Ruk / (1 - Ruk * tau)) - R0
    R = np.log(R)

    slp1, int1, r_value, p_value, std_err = stats.linregress(d[:7], R[:7])
    slp2, int2, r_value, p_value, std_err = stats.linregress(d[7:16], R[7:16])
    polc1 = np.array([slp1, int1])
    polc2 = np.array([slp2, int2])
    polcR0 = np.array([0, R0])

    RY = np.roots(polc2 - polcR0)
    RSr = np.roots(polc1 - polc2)

    mySrY = slp1
    mySr = slp1 - slp2
    myY = slp2

    cSr = mySr / rho
    cY = myY / rho

    rho = rho / 1000
    RSr = RSr * 100
    RY = RY * 100

    WSr = 1.92 * np.sqrt((RSr**2 * rho**2) + (0.22 * RSr * rho))
    WY = 1.92 * np.sqrt((RY**2 * rho**2) + (0.22 * RY * rho))

    cSr2 = 17 * WSr**(-1.43)
    cY2 = 17 * WY**(-1.43)

    print("Reichweite Sr, Y: ", RSr, RY)
    print("absorptions my Sr+Y, Sr, Y: ", mySrY, mySr, myY)
    print("massenabsorb c Sr, Y: ", cSr, cY)
    print("Flammersfeld W Sr, Y: ", WSr, WY)
    print("letztes c Sr, Y: ", cSr2, cY2)

    plt.plot(d[:-2], R[:-2], "xb")
    plt.plot(d[:7], slp1 * d[:7] + int1, "-g")
    plt.plot(d[7:16], slp2 * d[7:16] + int2, "-r")
    plt.xlabel("d in micrometer")
    plt.ylabel("Korrigierte Zählrate")
    plt.grid(True)
    #plt.show()
    return
Exemplo n.º 10
0
def abstand():
    hlines, data = ppk.readCSV("14aufgabe.csv", 2)
    d = data[0]
    lN = np.log10(data[1])
    rlN = lN[:15]
    rd = d[:15]

    slope, intercept, r_value, p_value, std_err = stats.linregress(rd, rlN)
    print(slope)

    plt.plot(d, lN, "xb")
    plt.plot(rd, intercept + slope * rd, "-b")
    plt.xlabel("d in cm")
    plt.ylabel("log(N)")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 11
0
def plateuanstieg11():
    hlines, data = ppk.readCSV("11aufgabe.csv", 2)

    NpT = data[2] / data[0]
    U = data[1]

    NpTPB = NpT[5:]
    UPB = U[5:]
    slope, intercept, r_value, p_value, std_err = stats.linregress(UPB, NpTPB)
    print("P-Anstieg", slope, " +- ", std_err)
    plt.plot(U, NpT, "xb")
    plt.plot(UPB, intercept + slope * UPB, "-b")
    plt.xlabel("Zählrate N/T")
    plt.ylabel("U in V")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 12
0
def aufgabe1_3():
    U1 = 2.3    #V
    Uf = 6.0    #V
    U3 = 0.91   #V
    T  = 150     #°C
    #U2 in V, Ig2 in myA
    hlines, data = ppk.readCSV("Aufgabe1_3.csv",2)
    data[0] = data[0]**(3/2)

    slope, intercept, r_value, p_value, std_err = stats.linregress(data[0][:15], data[1][:15]);
    print(slope)

    plt.plot(data[0],data[1],"ob")
    plt.plot(data[0][:15], slope*data[0][:15] + intercept, "-r")
    plt.xlabel("Spannung U2^(3/2) in V^(3/2)")
    plt.ylabel("Anodenstrom I in \u039CA")
    plt.grid(True)
    plt.show()
    return;
Exemplo n.º 13
0
def aufgabe11():
    #R**2 = R*k*lambda
    lambdaGelb = 590e-9
    lambdaBlau = 465e-9
    #n, r links in mm, r rechts in mm
    hlines, data = ppk.readCSV("11aufgabeG.csv", 2)
    #hlines, data = ppk.readCSV("11aufgabeB.csv",2)
    #lambdaGelb = lambdaBlau
    '''
    for i in np.arange(len(data[2])):
        x = data[2][i]
        data[2][i] = uc.ufloat(x, 0.1)
    for i in np.arange(len(data[1])):
        data[1][i] = uc.ufloat(data[1][i], 0.1)
    for i in np.arange(len(data[0])):
        data[0][i] = uc.ufloat(data[0][i],0)
    '''

    rsq = (((data[1] - data[2]) / 2) * (10**(-3)))**2
    R = (rsq) / (data[0] * lambdaGelb)
    R = uc.ufloat(np.mean(R), np.std(R))
    lGk = data[0] * lambdaGelb
    lGk = lGk * (10**9)
    rsq = rsq * (10**9)

    slp, inter, r_value, p_value, std_err = stats.linregress(lGk, rsq)
    #p = np.polyfit(lGk, rsq, 1)
    #pol = np.poly1d(p)
    R2 = uc.ufloat(slp, std_err)
    print(R2)

    plt.plot(lGk, rsq, "or")
    plt.plot(lGk, lGk * slp + inter, "-b")
    #plt.errorbar(lGk, rsq, yerr = 0.06)
    #plt.plot(lGk , pol(lGk), "-c")
    plt.title("Aufgabe 1.1 Gelbe LED")
    plt.xlabel("lambda*n in nm")
    plt.ylabel("r^2 in nm^2")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 14
0
def aufgabe25():
    g = uc.ufloat(6.098, 0.016)
    g = g * 1e-6

    hlines, data = ppk.readCSV("25raufgabe.csv", 2)
    k = data[0]
    deg = data[1]
    min = [0, 1, 2, 3, 4]
    for i in np.arange(len(data[2])):
        x = data[2][i]
        min[i] = uc.ufloat(x, 3)
    min[2] = uc.ufloat(0, 0)
    min = np.array(min)

    ddec = deg + (min * (1 / 60))
    ddec[0] -= 360
    ddec[1] -= 360
    sindeg = [0, 1, 2, 3, 4]
    sdoe = [0, 1, 2, 3, 4]
    se = [0, 1, 2, 3, 4]
    for i in np.arange(5):
        x = ddec[i]
        x = (x / 180) * np.pi
        sx = sin(x)
        sindeg[i] = sx
        sdoe[i] = sx.n
        se[i] = sx.s

    slp, inter, r_value, p_value, std_err = stats.linregress(k, sdoe)
    m = uc.ufloat(slp, std_err)
    lam = g * m
    print("l ", lam)

    plt.plot(k, sdoe, "or")
    plt.plot(k, k * slp + inter, "-b")
    plt.xlabel("k")
    plt.ylabel("sin(alpha)")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 15
0
def aufgabe12():
    lambdaGelb = 590e-9
    R = 0.701
    hlines, data = ppk.readCSV("12aufgabe.csv", 2)
    rsq = (((data[1] - data[2]) / 2) * (10**(-3)))**2
    lGk = data[0] * lambdaGelb * R
    lGk = lGk * (10**9)
    rsq = rsq * (10**9)

    slp, inter, r_value, p_value, std_err = stats.linregress(lGk, rsq)
    R2 = uc.ufloat(1 / slp, std_err)

    plt.plot(lGk, rsq, "or")
    plt.plot(lGk, lGk * slp + inter, "-b")
    plt.title("Aufgabe 1.2")
    plt.xlabel("lambda*n in nm")
    plt.ylabel("r^2 in nm^2")
    plt.grid(True)
    plt.show()

    print(R2)
    return
Exemplo n.º 16
0
def aufgabe24():
    hlines, data = ppk.readCSV("24aufgabe.csv", 2)
    k = data[0]
    deg = data[1]
    min = [0, 1, 2, 3, 4, 5, 6]
    for i in np.arange(len(data[2])):
        x = data[2][i]
        min[i] = uc.ufloat(x, 3)
    min[2] = uc.ufloat(0, 0)
    lamNa = 589.3e-9  #m
    min = np.array(min)

    ddec = deg + (min * (1 / 60))
    ddec[0] -= 360
    ddec[1] -= 360
    ddec[2] -= 360
    sindeg = [0, 1, 2, 3, 4, 5, 6]
    sdoe = [0, 1, 2, 3, 4, 5, 6]
    se = [0, 1, 2, 3, 4, 5, 6]
    for i in np.arange(7):
        x = ddec[i]
        x = (x / 180) * np.pi
        sx = sin(x)
        sindeg[i] = sx
        sdoe[i] = sx.n
        se[i] = sx.s

    slp, inter, r_value, p_value, std_err = stats.linregress(k, sdoe)
    m = uc.ufloat(slp, std_err)
    g = lamNa / m
    print("g ", g)

    plt.plot(k, sdoe, "or")
    plt.plot(k, k * slp + inter, "-b")
    plt.xlabel("k")
    plt.ylabel("sin(alpha)")
    plt.grid(True)
    plt.show()
    return
Exemplo n.º 17
0
def aufgabe2():
    #t,UA,U2
    hlines, data = ppk.readCSV("2aufgabe.csv",3)
    data[2] = data[2] - UK + 0.5
    U2 = data[2]
    UA = data[1]

    U2new = np.linspace(U2[0],U2[-1],100)
    spl = make_interp_spline(U2,UA,k=5)

    HP,TP = minmaxfind(spl(U2new))
    HP = np.delete(HP,[0,1,2,3])
    print(U2new[HP])

    for i in HP:
        plt.axvline( U2new[i], 0, 12 )
    plt.plot(U2new, spl(U2new), "-r")
    plt.xlabel("U2 in V")
    plt.ylabel("UA in V")
    plt.grid(True)
    plt.show()

    return;
Exemplo n.º 18
0
def alpha():
    hlines, data = ppk.readCSV("alpha.csv", 1)
    d = data[0] + 2 + 7 + 1
    Ruk = data[1] / 200
    R0 = 0.224
    tau = 0.001
    r = 0.0045

    Rost = (Ruk / (1 - Ruk * tau)) - R0
    R = Rost * ((4 * (d**2)) / (r**2))

    plt.plot(d, Rost, "xb")
    plt.xlabel("d in mm")
    plt.ylabel("Korrigierte Zählrate")
    plt.grid(True)
    plt.show()
    plt.clf()

    plt.plot(d, R, "xb")
    plt.xlabel("d in mm")
    plt.ylabel("Korrigierte Zählrate")
    plt.grid(True)
    plt.show()
    return
##################################
# Definition of the fit function #
##################################
# Set an ASCII expression for this function
@ASCII(x_name="t", expression="A0*exp(-t/tau)")
# Set some LaTeX-related parameters for this function
@LaTeX(name='A',
       x_name="t",
       parameter_names=('A_0', '\\tau{}'),
       expression="A_0\\,\\exp(\\frac{-t}{\\tau})")
@FitFunction
def exponential(t, A0=1, tau=1):
    return A0 * exp(-t / tau)


hlines, data1 = ppk.readCSV("praezession.csv", nlhead=1)
print(hlines)

time, dF = data1

my_dataset = kafe.Dataset(data=data1,
                          title="Praezession",
                          axis_labels=['Drehfrequenz', 'Umlaufdauer'],
                          axis_units=['$Hz$', '$s$'])

my_dataset.add_error_source('x', 'simple', 0.01)
my_dataset.add_error_source('y', 'simple', 0.99)

#my_dataset=kafe.Dataset(data=data1)

my_fits = [kafe.Fit(my_dataset, linear_2par)]
Exemplo n.º 20
0
# -----example Code illustrating usage of FourierSpectrum ------
if __name__ == "__main__":
    import numpy as np, matplotlib.pyplot as plt, PhyPraKit as ppk
    from scipy import interpolate, signal
    import sys

    # check for / read command line arguments
    if len(sys.argv) == 2:
        fname = sys.argv[1]
    else:
        fname = "Wellenform.csv"
    print('\n*==* script ' + sys.argv[0]+ ' executing \n',\
        '     processing file ' + fname)

    # read data from PicoScope
    units, data = ppk.readPicoScope(fname, prlevel=2)
    t = data[0]
    a = data[1]

    print("** Fourier Spectrum")
    freq, amp = ppk.FourierSpectrum(t, a, fmax=20)
    # freq, amp = ppk.Fourier_fft(t, a)  # use fast algorithm
    frequency = freq[np.where(amp == max(amp))]
    print(" --> Frequenz mit max. Amplitude: ", frequency)

    # make  plots
    fig = plt.figure(1, figsize=(7.5, 7.5))
    fig.suptitle('Script: test_Fourier.py', size='x-large', color='b')
    fig.subplots_adjust(left=0.14,
                        bottom=0.1,
                        right=0.97,
Exemplo n.º 21
0
# -----example Code illustrating usage --------------------
if __name__ == "__main__":
    import numpy as np, matplotlib.pyplot as plt, PhyPraKit as ppk
    from scipy import interpolate, signal
    import sys

    # check for / read command line arguments
    if len(sys.argv) == 2:
        fname = sys.argv[1]
    else:
        fname = "Wellenform.csv"
    print('\n*==* script ' + sys.argv[0]+ ' executing \n',\
        '     processing file ' + fname)

    # read data from PicoScope
    units, data = ppk.readPicoScope(fname, prlevel=2)
    t = data[0]
    a = data[1]

    print("** Fourier Spectrum")
    freq, amp = ppk.FourierSpectrum(t, a, fmax=20)
    # freq, amp = ppk.Fourier_fft(t, a)  # use fast algorithm
    frequency = freq[np.where(amp == max(amp))]
    print(" --> Frequenz mit max. Amplitude: ", frequency)

    # calculate autocorrelation function
    print("** Autocorrelation Function")
    ac_a = ppk.autocorrelate(a)
    ac_t = t - t[0]

    # run peak finder
Exemplo n.º 22
0
# Mittelung korrelierter Messwerte mit kafe2 / k2Fit

import numpy as np, matplotlib.pyplot as plt
import PhyPraKit as ppk


# das Modell
def fitf(x, c):
    # das Ergebnis muss ein Vektor der Länge von x sein
    if len(np.shape(x)) == 0:
        return c
    else:
        return c * np.ones(len(x))


# Daten und Unsicherheiten
x = np.arange(6) + 1.
m = np.array([0.82, 0.81, 1.32, 1.44, 0.93, 0.99])
sig_u = 0.1  # unabhängig
sig_s = 0.15  # korreliert für Messungen (1,2), (3,4) und (5,6)
sig_t = 0.05  # korreliert für alle Messungen

# Konstruktion der Komponenten für die Kovarianz-Matrix
sys_y = [[sig_t, sig_t, sig_t, sig_t, sig_t, sig_t],
         [sig_s, sig_s, 0., 0., 0., 0.], [0., 0., sig_s, sig_s, 0., 0.],
         [0., 0., 0., 0., sig_s, sig_s]]

# Fit ausführen
par, pare, cor, chi2 = ppk.k2Fit(fitf, x, m, sx=0., sy=sig_u, yabscor=sys_y)
Exemplo n.º 23
0
    import numpy as np, matplotlib.pyplot as plt, PhyPraKit as ppk
    from scipy import interpolate, signal
    import sys

    # check for / read command line arguments
    if len(sys.argv) == 2:
        fname = sys.argv[1]
    else:
        fname = "Temperaturen.txt"  # output of PicoTech 8 channel data logger
        # '\t' separated values, 2 header lines
        # german decimal comma, special char '^@'
    print('\n*==* script ' + sys.argv[0]+ ' executing \n',\
        '     processing file ' + fname)

    # read data from file in .txt format
    hlines, data = ppk.readtxt(fname, delim='\t', nlhead=2)
    print(hlines)
    print(" --> number of columns", data.shape[0])
    print(" --> number of data points", data.shape[1])

    # make a plots
    fig = plt.figure(1, figsize=(10, 7.5))
    fig.suptitle('Script: test_readtxt.py', size='x-large', color='b')
    fig.subplots_adjust(left=0.14,
                        bottom=0.1,
                        right=0.97,
                        top=0.93,
                        wspace=None,
                        hspace=.25)  #

    ax1 = fig.add_subplot(1, 1, 1)
Exemplo n.º 24
0
def main():
    hlines,data = ppk.readCSV("data_b3_a1.sec", 0)
    #plot(data)
    HP, TP = minmaxfind(data[1])
    #clean data
    HPdel = np.array([])
    for i in np.arange(len(HP)):
        if ( data[1][HP[i]] ) <= 0.05:
            HPdel = np.hstack((HPdel,i))

    HP = np.delete(HP,HPdel)
    HP = np.hstack((1,HP))

    #clean false postives
    HPdel = np.array([])
    for i in np.arange(len(HP)):
        if ( i%2 ) == 0:
            HPdel = np.hstack((HPdel,i))

    HP = np.delete(HP,HPdel)

    #Aufgabe a:
    print("Aufgabe 1a:")
    #plot incl j0->j1 und Text
    Q_i = 10 #index letztes P element
    j0 = 0
    j1 = 1
    for i in np.arange(len(HP)):
        if i == 0:     print("P-Zweig:");
        if i == Q_i+1: print("R-Zweig:");
        if i <= 10:
            j0 = (Q_i - i) + 1
            j1 = j0 - 1
            print("%2d w: %4.3f || j_0 = %02d -> j_1 = %02d" % (i, data[0][HP[i]], j0, j1 )  )
        else:
            j0 = (i - (Q_i+1))
            j1 = j0 + 1
            print("%2d w: %4.3f || j_0 = %02d -> j_1 = %02d" % (i, data[0][HP[i]], j0, j1 )  )



    plt.plot(data[0],data[1],label="Original Data")
    plt.plot(data[0][HP[:11]], data[1][HP[:11]], "gx", label = "P - Zweig Peaks")
    plt.plot(data[0][HP[11:]], data[1][HP[11:]], "rx", label = "R - Zweig Peaks")

    plt.legend()
    plt.title("Blatt 3: Aufgabe 1a")
    plt.xlabel("Wellenzahl in 1/cm")
    plt.ylabel("Optische Dichte")
    plt.grid(True)
    plt.show()
    plt.clf()

    #Aufgabe b:
    print("\n\nAufgabe 1b:")
    #Dwj0 = 2*B1* (2*j0 +1)
    #Dwj1 = 2*B0* (2*j1 +1)
    Dwj0 = np.array([])
    Dwj1 = np.array([])

    for i in np.arange(0,Q_i+1):
        #start with j0 = 1
        if i <= Q_i - 1:
            j0P = (Q_i - i)
            j0R = (Q_i + i + 2)
            dw = data[0][HP[j0R]] - data[0][HP[j0P]]
            Dwj0 = np.hstack((Dwj0, dw))
            print("%2d j_0 = %02d || \u0394w = %3.3f" % (i, i+1, dw))

        if i <= Q_i - 1:
            #start with j1 = 1
            j1P = Q_i -i -1
            j1R = Q_i +1 +i
            dw = data[0][HP[j1R]] - data[0][HP[j1P]]
            Dwj1 = np.hstack((Dwj1, dw))
            print("%2d j_1 = %02d || \u0394w = %3.3f" % (i, i+1, dw))

    #Aufgabe c:
    x_vals = 2 * ( np.arange(1,11) ) + 1
    x_s = np.linspace(0,25, 250)
    m0, c0, r_value, p_value, std_err = stats.linregress(x_vals, Dwj1)
    m1, c1, r_value, p_value, std_err = stats.linregress(x_vals, Dwj0)
    print("B_0 = %.4f  ||  B_1 = %.4f" % (m0/2, m1/2))

    plt.plot(x_vals, Dwj1, "bx", label = "Punkte zu B_0")
    plt.plot(x_vals, Dwj0, "gx", label = "Punkte zu B_1")
    plt.plot(x_s, m0*x_s+c0, "r-", label = "linreg: m = 2*B0")
    plt.plot(x_s, m1*x_s+c1, "r-", label = "linreg: m = 2*B1")

    plt.legend()
    plt.title("Blatt 3: Aufgabe 1c")
    plt.xlabel("j_0 ; j_1")
    plt.ylabel("\u0394\u03c9")
    plt.grid(True)
    plt.show()
    plt.clf()



    return;
Exemplo n.º 25
0
def minimumfinder(xlist):
    minlist = np.zeros(len(xlist))
    k = 0
    for i in range(len(xlist)):
        if (i != 0 and i != len(xlist)-1):
            if (xlist[i-1] > xlist[i] and xlist[i+1] > xlist[i]):
                minlist[k] = xlist[i]
                k += 1
    truncatedminlist = minlist[minlist != 0]
    return truncatedminlist


fpath = "C:\\Users\\LiquidSpot\\PycharmProjects\\CGDA\Blatt 5\\signal.csv"

t = PhyPraKit.readCSV(fpath)
#print(t)
#Datenformat: Comma seperated values(CSV)
#Datenformat t = Liste von listen

#Numpy list for time and amplitude
time = np.zeros(10000);
amplitude = np.zeros(10000);

time = t[1][0]
amplitude = t[1][1]

#Smooth amplitude by mean, deltaA as difference between original and smooth Amplitude
smoothamplitude = PhyPraKit.meanFilter(amplitude,5)
deltaA = amplitude - smoothamplitude
Exemplo n.º 26
0
# -----example Code illustrating usage --------------------
if __name__ == "__main__":
    import numpy as np, matplotlib.pyplot as plt, PhyPraKit as ppk
    from scipy import interpolate, signal
    import sys

    # check for / read command line arguments
    if len(sys.argv) == 2:
        fname = sys.argv[1]
    else:
        fname = "Wellenform.csv"
    print('\n*==* script ' + sys.argv[0]+ ' executing \n',\
        '     processing file ' + fname)

    # read data from PicoScope
    units, data = ppk.readPicoScope(fname, prlevel=2)
    t = data[0]
    a = data[1]

    # run peak and edge finder
    width = 30
    #  use convoluted template filter
    pidx = ppk.convolutionPeakfinder(a, width, th=0.8)
    didx = ppk.convolutionEdgefinder(-a, width, th=0.4)
    if len(pidx) > 3:
        print(" --> %i peaks and %i edges found" % (len(pidx), len(didx)))
        tp, ap = np.array(t[pidx]), np.array(a[pidx])
        td, ad = np.array(t[didx]), np.array(a[didx])
    else:
        print("*!!* not enough peaks found - tune peakfinder parameters!")
        sys.exit(1)
Exemplo n.º 27
0
        tnam = tag.split(':')[1]
        if tnam == 'Zeit': t = np.array(values[i][:])
        if tnam == 'Weg': s = np.array(values[i][:])
        if tnam == 'Winkel': phi = np.array(values[i][:])

# print "time=", len(t), t
# print "phi_count=", len(s), s
# print "phi=", len(phi), phi

# ----  some examples of data analysis -----

# some filtering and smoothing
    print("** filtering:")
    # * use, if there is an unwanted offset
    print("  offset correction")
    phi_c = ppk.offsetFilter(phi)

    # * use , if there is high-frequency noise
    #print "  smoothing with sliding average"
    #phi=ppk.meanFilter(phi_c, width=10) #

    # * use, if sampling rate is too high
    if len(phi) > 2000:
        print("  resampling")
        phi, t = ppk.resample(phi, t, n=int(len(phi) /
                                            1000))  # average n samples into 1

# numerical differentiation with numpy
    print("** numerical derivative")
    dt = t[1] - t[0]
    omega = np.gradient(phi, dt)
##################################
# Definition of the fit function #
##################################
# Set an ASCII expression for this function
@ASCII(x_name="t", expression="A0*exp(-t/tau)")
# Set some LaTeX-related parameters for this function
@LaTeX(name='A',
       x_name="t",
       parameter_names=('A_0', '\\tau{}'),
       expression="A_0\\,\\exp(\\frac{-t}{\\tau})")
@FitFunction
def exponential(t, A0=1, tau=1):
    return A0 * exp(-t / tau)


hlines, data1 = ppk.readCSV("Nutationsfrequenz_ohneGewicht.csv", nlhead=1)
print(hlines)

hlines2, data2 = ppk.readCSV("Nutationsfrequenz_mitGewicht.csv", nlhead=1)

time1, dF1 = data1
time2, dF2 = data2

my_dataset = [
    kafe.Dataset(data=data1,
                 title="Nutation ohne Gewicht",
                 axis_label=['Drehfrequenz', 'Nutationsfrequenz'],
                 data_label=" ohne Gewicht"),
    kafe.Dataset(data=data2,
                 title="Nutation mit Gewicht",
                 data_label="mit Gewicht")
Exemplo n.º 29
0
import numpy as np
import matplotlib.pyplot as plt
import PhyPraKit as ppk
import kafe

#Bestimmung m_e ___________________________________________________________________________
M = 0.14174  #Angaben in kg
M_F = 0.0154
o_me = 0.1 * 10**-3  #Fehler von der Wage

me, o_me = (M + 1. / 3. * M_F), o_me + 1 / 3 * o_me

#Bestimmung von T ___________________________________________________________________________
hlines, data = ppk.readCSV('HandyPendel.csv')
t = data[0]
a = data[2]

#Glätten der Funktion
a_smooth = ppk.meanFilter(a, 7)

# calculate autocorrelation function
ac_a = ppk.autocorrelate(a_smooth)
ac_t = t

# find maxima and minima using convolution peak finder
width = 3
pidxac = ppk.convolutionPeakfinder(ac_a, width, th=0.66)
didxac = ppk.convolutionPeakfinder(-ac_a, width, th=0.66)
if len(pidxac) > 1:
    print(" --> %i auto-correlation peaks found" % (len(pidxac)))
    pidxac[0] = 0  # first peak is at 0 by construction