Пример #1
0
def Equilib(plot1=False, printA=False):
    D1 = np.load(nppath + 'angle_cal.npy')
    D2 = np.load(nppath + 'extra_decay.npy')
    X1, Y1 = D1[:, 0] / 100, D1[:, 1]
    X2, Y2 = D2[:, 0] / 100, D2[:, 1]

    x1, y1, x2, y2, avX, avY = AuxTwo(.55, 15.76, 'maxima', X2, Y2, 25)

    d1 = dp.data(X1, Y1, '-', 'b', 'data 1')
    d2 = dp.data(X2, Y2, '-', 'b', 'data 2')
    d3 = dp.data([x1, x2], [y1, y2], '*', 'g', 'maxima')
    d4 = dp.data(avX, avY, '-', 'r', 'eq 2')

    if plot1 == True:
        ax1 = dp.ax([d1], 121, 'time [$10^2$ sec]', '$\\theta_{comp}$ [mRad]',
                    'Equilibrium Angle 1')
        ax2 = dp.ax([d2, d3, d4], 122, 'time [$10^2$ sec]',
                    '$\\theta_{comp}$ [mRad]', 'Equilibrium Angle 2')

        dp.plot([ax1, ax2])

    eq1 = -1.8  # mRad
    eq2 = avY[0]  # mRad

    if printA == True:
        print("eq 1 = %s mRad" % eq1)
        print("eq 2 = %s mRad" % eq2)

    return eq1, eq2
Пример #2
0
def Angle_calibration(plot1=False, plot2=False, printA=False):
    plt.close('all')
    angle_data = np.load(nppath + "angle_cal.npy")
    X = angle_data[:, 0]  # sec
    Y = angle_data[:, 1]  # mRad

    x_minima = [62, 178, 293, 407]  # sec
    x_maxima = [120, 235, 350]  # sec
    minima, maxima = dg.extrema(X, Y, 10, x_minima, x_maxima)
    ext = minima + maxima
    ext = dg.sort(np.array(ext), 0)

    if plot1 == True:  # '0_1_Angles_cal', angles for angle calibration
        # plots: X , Y , style , label
        p1 = dp.data(X, Y, '-', 'b', '$\\theta_{comp}$')
        p2 = dp.data(ext[:, 0], ext[:, 1], 'r*', 'r', 'Extrema')
        ax = dp.ax([p1, p2], 111, 'time [sec]', "$\\theta_{comp}$ [mRad]",
                   "$\\theta_{comp}$ for Angle Calibration")

        dp.plot([ax], name=gp + '0_1_Angles_cal')

    X_data, Y_data = AuxOne(L.val, S.val, ext[:, 1])
    m, m_err = df.m_exp(X_data, Y_data), df.sig_m(X_data, Y_data)
    b, b_err = df.b_exp(X_data, Y_data), df.sig_b(X_data, Y_data)
    m_err_p, b_err_p = m_err * 100 / m, b_err * 100 / b
    r2 = df.R2(X_data, Y_data)
    X_lin = np.linspace(0, max(X_data) + 10, 1000)
    Y_lin = df.lin_fit(X_data, Y_data, X_lin)

    if plot2 == True:
        p1 = dp.data(X_data, Y_data, 'bs', 'b', 'Laser vs Comp')
        p2 = dp.data(X_lin, Y_lin, 'r-', 'r', 'Linear Fit')
        n2 = dp.note(
            "Y = C x + B\nm = %s $\pm$ %s\nb = %s $\pm$ %s\nR$^2$ = %s" %
            (round(m, 2), round(m_err, 2), round(b, 1), round(
                b_err, 1), round(r2, 5)), 20, 7, p2.color)
        ax = dp.ax([p1, p2], 111, '$\\theta_{comp}$ [mRad]',
                   '$\\theta_{laser}$ [mRad]',
                   '$\\theta_{laser}$ vs. $\\theta_{comp}$')
        ax.notes = [n2]

        dp.plot([ax], name=gp + '0_2_laser_vs_comp')

    if printA == True:
        print("")
        print("Calibrtion:")
        print("theta_comp = %s" % X_data)
        print("theta_laser = %s" % Y_data)
        print("calibration constant = %s +/- %s (%s)" % (m, m_err, m_err_p))
        print("intercept = %s +/- %s (%s)" % (b, b_err, b_err_p))
        print("R2 = %s" % r2)
        print("")
    return m, m_err
Пример #3
0
def DrivenG(plot=False, printA=False):
    plt.close('all')

    D = np.load(nppath + 'driven.npy')
    X, Y = D[:, 0] / 1000, (D[:, 1] - eq2) * C.val  # data
    data = dp.data(X, Y, '-', 'b', 'data')  # data

    i_1 = dg.maxima(X, Y, 2.87, 25)
    x1, y1 = X[i_1], Y[i_1]
    d1 = dp.data([x1], [y1], '*', 'r', '$X[t_0],\ Y[t_0]$')

    X2 = X[i_1:]
    Y2 = Y[i_1:]
    Y2_env, Y2_man, Y2_fit, par_f = dampedWave(X2, Y2, par_m)
    d2_man = dp.data(X2, Y2_man, '--', 'm', 'manual fit')
    d2_env = dp.data(X2, Y2_env, '--', 'c', 'upper envelope')
    d2_fit = dp.data(X2, Y2_fit, '-', 'r', 'least-square fit')

    n1 = '$\\theta_e + A e^{-\\gamma t} \cos{\\omega t}$'
    n2 = '$\\theta_e$ = %s $\pm$ %s mRad' % (round(par_f[0], 1), .1)
    n3 = 'A = %s $\pm$ %s mRad' % (round(par_f[1], 1), .2)
    n4 = '$\\gamma$ = %s $\pm$ %s (10$^3$ s)$^{-1}$' % (round(par_f[2], 1), .1)
    n5 = '$\\omega$ = %s $\pm$ %s (10$^3$ s)$^{-1}$' % (round(par_f[3], 1), .2)
    note = dp.note(n1 + '\n' + n2 + '\n' + n3 + '\n' + n4 + '\n' + n5, 4, -10,
                   'r')

    theta_d = theta_driven(X2, Y2, y1, printA=True)
    G_d = dg.var('G_d', G(theta_d.val), G_d_err(k, theta_d, R, M_m, m_m, d),
                 'N m^2 kg^-2')
    dg.printvar(G_d)
    print(G_d.val, G_d.err)

    if plot == True:
        ax = dp.ax([data, d1, d2_env, d2_man, d2_fit], 111,
                   'time [$10^3$ sec]', '$\\theta_{laser}$ [mRad]',
                   'Driven Measurement')
        ax.notes = [note]

        dp.plot([ax])  #, name=gp+'0_4_DrivenG')

    if printA == True:
        print("Driven G Results:")

    return theta_d
Пример #4
0
def DrivenG(N=13, plot=False, printA=False):
    plt.close('all')

    D = np.load(nppath + 'driven.npy')
    X, Y = D[:, 0] / 1000, (D[:, 1] - eq2) * C.val  # data
    data = dp.data(X, Y, '-', 'b', 'data')  # data

    i_1 = dg.maxima(X, Y, 2.87, 25)
    x1, y1 = X[i_1], Y[i_1]
    d1 = dp.data([x1], [y1], '*', 'r', '$X[t_0],\ Y[t_0]$')

    X2 = X[i_1:]
    Y2 = Y[i_1:]
    Y2_env, Y2_man, Y2_fit, par_f = dampedWave(X2, Y2, par_m)
    d2_man = dp.data(X2, Y2_man, '--', 'm', 'manual fit')
    d2_env = dp.data(X2, Y2_env, '--', 'c', 'upper envelope')
    d2_fit = dp.data(X2, Y2_fit, '-', 'r', 'least-square fit')

    n1 = '$\\theta_e + A e^{-\\gamma t} \cos{\\omega t}$'
    n2 = '$\\theta_e$ = %s $\pm$ %s mRad' % (round(par_f[0], 1), .1)
    n3 = 'A = %s $\pm$ %s mRad' % (round(par_f[1], 1), .2)
    n4 = '$\\gamma$ = %s $\pm$ %s (10$^3$ s)$^{-1}$' % (round(par_f[2], 1), .1)
    n5 = '$\\omega$ = %s $\pm$ %s (10$^3$ s)$^{-1}$' % (round(par_f[3], 1), .2)
    note = dp.note(n1 + '\n' + n2 + '\n' + n3 + '\n' + n4 + '\n' + n5, 4, -10,
                   'r')

    ext, theta_d = theta_driven(X, Y, 6, N=N)

    d2_ext = dp.data(ext[:, 0], ext[:, 1], '*', 'g', '$\\theta_n$')

    if plot == True:
        ax = dp.ax([data, d1, d2_env, d2_man, d2_fit, d2_ext], 111,
                   'time [$10^3$ sec]', '$\\theta_{laser}$ [mRad]',
                   'Driven Measurement')
        ax.notes = [note]

        dp.plot([ax], name=gp + '0_4_DrivenG')

    if printA == True:
        print("fitting parameters")
        print(par_f)

    return theta_d
Пример #5
0
def StaticG(plot=False, printA=False):
    plt.close('all')

    # static1
    D1 = np.load(nppath + 'static1.npy')
    X1, Y1 = D1[:, 0] / 1000, (D1[:, 1] -
                               eq1) * C.val  # time[s], theta_laser[mRad]

    x1_1a, y1_1a, x1_1b, y1_1b, XP_1, YP_1 = AuxTwo(.630, 2.25, 'maxima', X1,
                                                    Y1, 25)
    x1_2a, y1_2a, x1_2b, y1_2b, XP_2, YP_2 = AuxTwo(2.57, 4.1, 'minima', X1,
                                                    Y1, 25)
    x1_3a, y1_3a, x1_3b, y1_3b, XP_3, YP_3 = AuxTwo(4.40, 5.92, 'maxima', X1,
                                                    Y1, 25)
    x1_4a, y1_4a, x1_4b, y1_4b, XP_4, YP_4 = AuxTwo(6.40, 7.97, 'minima', X1,
                                                    Y1, 25)

    X2 = np.array([x1_1a, x1_1b, x1_2a, x1_2b, x1_3a, x1_3b, x1_4a, x1_4b])
    Y2 = np.array([y1_1a, y1_1b, y1_2a, y1_2b, y1_3a, y1_3b, y1_4a, y1_4b])
    X3 = np.hstack((XP_1, XP_2, XP_3, XP_4))
    Y3 = np.hstack((YP_1, YP_2, YP_3, YP_4))

    n1 = dp.note(str(round(np.average(YP_1), 2)), x1_1b - .8, y1_1b + .8, 'r')
    n2 = dp.note(str(round(np.average(YP_2), 2)), x1_2b - .8, y1_2b - .8, 'r')
    n3 = dp.note(str(round(np.average(YP_3), 2)), x1_3b - .8, y1_3b + .8, 'r')
    n4 = dp.note(str(round(np.average(YP_4), 2)), x1_4b - .8, y1_4b - .8, 'r')

    # static2
    D2 = np.load(nppath + 'static2.npy')
    X4, Y4 = D2[:, 0] / 1000, (D2[:, 1] - eq2) * C.val

    x2_1a, y2_1a, x2_1b, y2_1b, XP_5, YP_5 = AuxTwo(0.26, 1.8, 'minima', X4,
                                                    Y4, 25)
    x2_2a, y2_2a, x2_2b, y2_2b, XP_6, YP_6 = AuxTwo(2.07, 3.58, 'maxima', X4,
                                                    Y4, 25)

    X5 = np.array([x2_1a, x2_1b, x2_2a, x2_2b])
    Y5 = np.array([y2_1a, y2_1b, y2_2a, y2_2b])
    X6 = np.hstack((XP_5, XP_6))
    Y6 = np.hstack((YP_5, YP_6))

    n5 = dp.note(str(round(np.average(YP_5), 2)), x2_1b - .5, y2_1b - .5, 'r')
    n6 = dp.note(str(round(np.average(YP_6), 2)), x2_2b - .3, y2_2b + .3, 'r')

    Ts = np.array([
        Period(x1_1b, x1_1a, 1000, 4),
        Period(x1_2b, x1_2a, 1000, 4),
        Period(x1_3b, x1_3a, 1000, 4),
        Period(x1_4b, x1_4a, 1000, 4),
        Period(x2_1b, x2_1a, 1000, 4),
        Period(x2_2b, x2_2a, 1000, 4)
    ])
    T = dg.var('T', Ts, 'std', 's')

    theta_Ds = np.array([
        Theta_s(YP_1, YP_2),
        Theta_s(YP_2, YP_3),
        Theta_s(YP_3, YP_4),
        Theta_s(YP_5, YP_6)
    ])
    theta_s = dg.var('theta_s', theta_Ds, 'std', 'mRad')

    if plot == True:
        # static1
        d1 = dp.data(X1, Y1, '-', 'b', 'data 1')
        d2 = dp.data(X2, Y2, '*', 'g', '$\\theta_D$ Period')
        d3 = dp.data(X3, Y3, '-', 'r', '$\\theta_D$')

        ax1 = dp.ax([d1, d2, d3], 121, 'time [$10^3$ sec]',
                    '$\\theta_{laser}$ [mRad]', 'Static Measurement 1')
        ax1.notes = [n1, n2, n3, n4]

        # static2
        d4 = dp.data(X4, Y4, '-', 'b', 'data 2')
        d5 = dp.data(X5, Y5, '*', 'g', '$\\theta_s$ Period')
        d6 = dp.data(X6, Y6, '-', 'r', '$\\theta_s$')

        ax2 = dp.ax([d4, d5, d6], 122, 'time [$10^3$ sec]',
                    '$\\theta_{laser}$ [mRad]', 'Static Measurement 2')
        ax2.notes = [n5, n6]

        dp.plot([ax1, ax2], name=gp + '0_3_StaticG')
    if printA == True:
        print("")
        print("Static G Results:")
        print("periods = %s" % T.pval)
        print("Period: %s +/- %s %s" % (T.pav, T.perr, T.units))
        print("Theta_s = %s %s" % theta_s.pval, theta_s.units)
        print("theta_d_static = %s +/- %s %s" %
              (theta_s.pav, theta_s.perr, theta_s.units))
        print("Gs = %s %s" % (G_s.val, G_s.units))
        print("G = %s +/- %s %s" % (G_s.av, G_s.err, G_s.units))
    return theta_s