Beispiel #1
0
def run_wav2(wav0):
    conn = psycopg2.connect(
        user="******",
        password="******",
        host="test-heroku.cs0ubczlcaiz.us-west-1.rds.amazonaws.com",
        port="5432",
        database="test-aws")
    cur = conn.cursor()

    print('\nProcessing Run Wave 2...\n')
    # wav = os.path.join('data/new_data/fft/' + string2 + '.png')
    # wav0 = os.listdir('data/new_data/')[0]
    wav = wav0.strip('data/new_data/')
    wav1 = wav.strip('.wav') + '.png'

    # wav = os.listdir('data/new_data/')[0]
    # wav = next(join('data/new_data/', f) for f in os.listdir('data/new_data/'))

    # print('Wav0: \n', wav0)
    # print('Wav: \n', wav)
    # print('Wav1: \n', wav1)
    word = wav.split('-')
    # print('Word: \n', word)
    mea_date = word[0]
    # print('Measure Date: \n', mea_date)
    disp_date = mea_date[0:4] + '-' + mea_date[4:6] + '-' + mea_date[
        6:8] + ' ' + mea_date[8:10] + ':' + mea_date[10:12] + ':' + mea_date[
            12:14]
    # print('Display Date: \n', disp_date)
    dev_id = word[1]
    # print('Dev ID: \n', dev_id)
    qr_code0 = word[3]
    qr_code = qr_code0.strip('.wav')
    # print('RQ Code: \n', qr_code)
    loc = word[2]
    # print('Location: \n', loc)

    print('\nProcessing Prob...')

    conf = testModel()
    p  # rint('Conf-2: ',conf)
    # run_prob (dev_id)
    print('\nFinished Prob.')

    # path = '/Users/andy/Projects/flow-ez/data'
    # print("Moving file:")
    # print(os.listdir(path))
    # source = '/Users/andy/Projects/flow-ez/data/new_data'
    # destination = '/Users/andy/Projects/flow-ez/data/old_data'
    # dest = shutil.move(source, destination, copy_function=copy2)

    # print("Finished Moving file:")
    # print(os.listdir(path))
    # print("Destination path:", dest)

    print('\nProcessing Pulse...')
    plt.figure(dpi=2400)
    my_pulse(wav0)
    print('\nFinished Pulse.')

    print('\nProcessing FFT...')
    my_fft(wav0)
    print('\nFinished FFT.')

    if (conf > 50):
        res = 'Abnormal'
    else:
        res = 'Normal'

    first_name = names.get_first_name()
    last_name = names.get_last_name()

    shutil.copy('static/trend/20191101101100-003004802801-UP-00000001.png',
                'static/trend/' + wav1)

    cur.execute("BEGIN TRANSACTION;")
    # cur.execute("Update data_table (mea_date,dev_id,qr_code,loc,pulse,fft,trend) VALUES (?,?,?,?,?,?,?)",(mea_date,dev_id,qr_code,loc,wav1,wav1,wav1) where (last_name='West'))
    # cur.execute("UPDATE data_table set mea_date=?,disp_date=?,dev_id=?,qr_code=?,loc=?,pulse=?,fft=?,trend=?,res=?,prob=? WHERE dev_id=?", (mea_date,disp_date,dev_id,qr_code,loc,wav1,wav1,wav1,res,conf,dev_id,) )
    cur.execute(
        "INSERT INTO data_table (first_name,last_name,mea_date,disp_date,dev_id,qr_code,loc,pulse,fft,trend,res,prob) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
        (first_name, last_name, mea_date, disp_date, dev_id, qr_code, loc,
         wav1, wav1, wav1, res, conf))
    cur.execute("COMMIT TRANSACTION;")
    cur.close
    conn.close()

    #source = os.listdir("/Users/andy/Projects/flow-ez/data/new_data/")
    #destination = "/Users/andy/Projects/flow-ez/data/old_data/"
    source = os.listdir("/AboveCare/Projects/flow-ez/data/new_data/")
    destination = "/AboveCare/Projects/flow-ez/data/old_data/"
    for files in source:
        if files.endswith('.wav'):
            shutil.move("/AboveCare/Projects/flow-ez/data/new_data/" + files,
                        destination)
            print('\nWave Files Moved.')

    # my_psp (wav0) ## Leadtek's data has "RuntimeWarning: divide by zero" issue
def afm_dno_solver_rk4(K, ep, mu, Llx, tf, Mval, dt):
    KT = 2 * K
    # Find the wave numbers to implement the 2/3 de-aliasing throughout
    Kc = int(np.floor(2. * K / 3.))
    Kuc = KT - Kc + 1
    Kc = Kc + 1

    ftrans = my_fft.my_fft(KT)

    eta0 = pyfftw.empty_aligned(KT, dtype='complex128')
    q0 = pyfftw.empty_aligned(KT, dtype='complex128')
    etan = pyfftw.empty_aligned(KT, dtype='complex128')
    qn = pyfftw.empty_aligned(KT, dtype='complex128')
    un = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    k1 = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    k2 = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    k3 = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    k4 = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    svec = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    G0 = pyfftw.empty_aligned(KT, dtype='float64')
    qh2 = pyfftw.empty_aligned(KT, dtype='complex128')

    Xmesh = pyfftw.empty_aligned(KT, dtype='float64')
    Kmesh = pyfftw.empty_aligned(KT, dtype='float64')
    tnh = pyfftw.empty_aligned(KT, dtype='float64')
    mDk = pyfftw.empty_aligned(KT, dtype='float64')
    L1 = pyfftw.empty_aligned(KT, dtype='float64')
    Zs = np.zeros([KT, KT], dtype=np.float64)
    Is = np.identity(KT, dtype=np.float64)
    dx = 2. * Llx / KT

    Xmesh[:] = np.arange(-Llx, Llx, dx)

    Kmesh[:] = np.pi / Llx * (np.concatenate(
        (np.arange(0, K + 1), np.arange(-K + 1, 0)), 0))

    nmax = int(np.round(tf / dt))

    mDk[:] = mu * Kmesh
    tnh[:] = np.tanh(mDk)

    L1[:] = Kmesh * np.tanh(mu * Kmesh) / mu

    Lop = np.concatenate((np.concatenate(
        (Zs, np.diag(L1)), axis=1), np.concatenate((-Is, Zs), axis=1)),
                         axis=0)

    eLdt2 = expm(dt * Lop / 2.)
    eLdt = np.matmul(eLdt2, eLdt2)

    eta0[:] = np.cos(np.pi * Xmesh / Llx)
    q0[:] = np.sin(np.pi * Xmesh / Llx)

    etan[:] = ftrans.fft(eta0)
    qn[:] = ftrans.fft(q0)
    etan[Kc - 1:Kuc] = 0
    qn[Kc - 1:Kuc] = 0

    un[:] = np.concatenate((etan, qn))
    G0[:] = ftrans.ifft(L1 * qn).real

    for jj in xrange(nmax):
        G0[:] = ftrans.ifft(L1 * qn).real

        k1[:] = dt * nonlinearity(K, etan, qn, G0, ep, mu, Kmesh, mDk, tnh,
                                  Mval, ftrans)

        svec[:] = np.matmul(eLdt2, (un + .5 * k1))
        qh2[:] = svec[KT:]
        qh2[Kc - 1:Kuc] = 0.
        G0[:] = ftrans.ifft(L1 * qh2).real

        k2[:] = dt * nonlinearity(K, svec[0:KT], svec[KT:], G0, ep, mu, Kmesh,
                                  mDk, tnh, Mval, ftrans)

        svec[:] = np.matmul(eLdt2, un) + .5 * k2
        qh2[:] = svec[KT:]
        qh2[Kc - 1:Kuc] = 0.
        G0[:] = ftrans.ifft(L1 * qh2).real

        k3[:] = dt * nonlinearity(K, svec[0:KT], svec[KT:], G0, ep, mu, Kmesh,
                                  mDk, tnh, Mval, ftrans)

        svec[:] = np.matmul(eLdt, un) + np.matmul(eLdt2, k3)
        qh2[:] = svec[KT:]
        qh2[Kc - 1:Kuc] = 0.
        G0[:] = ftrans.ifft(L1 * qh2).real

        k4[:] = dt * nonlinearity(K, svec[0:KT], svec[KT:], G0, ep, mu, Kmesh,
                                  mDk, tnh, Mval, ftrans)

        un[:] = (np.matmul(eLdt, (un + k1 / 6.)) +
                 np.matmul(eLdt2, (k2 + k3) / 3.) + k4 / 6.)

        etan = un[0:KT]
        qn = un[KT:]

        etan[Kc - 1:Kuc] = 0
        qn[Kc - 1:Kuc] = 0
        un[:] = np.concatenate((etan, qn))

    return ftrans.ifft(etan).real
Beispiel #3
0
def afm_dno_solver(K, ep, mu, Llx, tf, Mval, dt):

    KT = 2 * K
    # Find the wave numbers to implement the 2/3 de-aliasing throughout
    Kc = int(np.floor(2. * K / 3.))
    Kuc = KT - Kc + 1
    Kc = Kc + 1

    ftrans = my_fft.my_fft(KT)

    eta0 = pyfftw.empty_aligned(KT, dtype='complex128')
    q0 = pyfftw.empty_aligned(KT, dtype='complex128')

    eta1 = pyfftw.empty_aligned(KT, dtype='complex128')
    eta2 = pyfftw.empty_aligned(KT, dtype='complex128')

    q1 = pyfftw.empty_aligned(KT, dtype='complex128')
    q2 = pyfftw.empty_aligned(KT, dtype='complex128')

    etan = pyfftw.empty_aligned(KT, dtype='complex128')
    qn = pyfftw.empty_aligned(KT, dtype='complex128')

    G0 = pyfftw.empty_aligned(KT, dtype='complex128')

    etanm1 = pyfftw.empty_aligned(KT, dtype='complex128')
    qnm1 = pyfftw.empty_aligned(KT, dtype='complex128')

    etanp1 = pyfftw.empty_aligned(KT, dtype='complex128')
    qnp1 = pyfftw.empty_aligned(KT, dtype='complex128')

    nlvecn = pyfftw.empty_aligned(KT, dtype='complex128')
    nlvecq = pyfftw.empty_aligned(KT, dtype='complex128')

    nln = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    nlnm1 = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    nlnm2 = pyfftw.empty_aligned(2 * KT, dtype='complex128')
    nlnm3 = pyfftw.empty_aligned(2 * KT, dtype='complex128')

    Xmesh = pyfftw.empty_aligned(KT, dtype='complex128')
    Kmesh = pyfftw.empty_aligned(KT, dtype='complex128')
    tnh = pyfftw.empty_aligned(KT, dtype='complex128')
    mDk = pyfftw.empty_aligned(KT, dtype='complex128')
    L1 = pyfftw.empty_aligned(KT, dtype='complex128')
    Linvd = pyfftw.empty_aligned(KT, dtype='complex128')
    Linv12 = pyfftw.empty_aligned(KT, dtype='complex128')
    Linv21 = pyfftw.empty_aligned(KT, dtype='complex128')

    dx = 2. * Llx / KT

    Xmesh[:] = np.arange(-Llx, Llx, dx)

    Kmesh[:] = np.pi / Llx * np.concatenate(
        (np.arange(0, K + 1), np.arange(-K + 1, 0)), 0)
    nmax = int(np.round(tf / dt))

    mDk[:] = mu * Kmesh
    tnh[:] = np.tanh(mDk)

    L1[:] = Kmesh * np.tanh(mu * Kmesh) / mu

    Linvd[:] = (np.ones(KT, dtype='complex128') + 9. * dt**2 / 16. * L1)**(-1)
    Linv12[:] = 3. * dt / 4. * L1 * Linvd
    Linv21[:] = -3. * dt / 4. * Linvd

    eta0[:] = np.cos(np.pi * Xmesh / Llx)
    q0[:] = np.sin(np.pi * Xmesh / Llx)

    etan[:] = ftrans.fft(eta0)
    qn[:] = ftrans.fft(q0)

    etan[Kc - 1:Kuc] = 0
    qn[Kc - 1:Kuc] = 0
    G0[:] = ftrans.ifft(L1 * qn).real

    etanm1[:] = etan
    qnm1[:] = qn

    nln[:] = nonlinearity(K, etan, qn, G0, ep, mu, Kmesh, mDk, tnh, Mval,
                          ftrans)
    nlnm1[:] = nln
    nlnm2[:] = nlnm1
    nlnm3[:] = nlnm2

    for jj in xrange(nmax):

        G0[:] = ftrans.ifft(L1 * qn).real
        nln[:] = nonlinearity(K, etan, qn, G0, ep, mu, Kmesh, mDk, tnh, Mval,
                              ftrans)

        nlvecn[:] = 55. / 24. * nln[0:KT] - 59. / 24. * nlnm1[
            0:KT] + 37. / 24. * nlnm2[0:KT] - 3. / 8. * nlnm3[0:KT]
        nlvecq[:] = 55. / 24. * nln[KT:2 * KT] - 59. / 24. * nlnm1[
            KT:2 * KT] + 37. / 24. * nlnm2[KT:2 * KT] - 3. / 8. * nlnm3[KT:2 *
                                                                        KT]

        eta1[:] = Linvd * (etan + etanm1 / 3. + dt * nlvecn)
        eta2[:] = Linv12 * (qn + qnm1 / 3. + dt * nlvecq)

        q1[:] = Linvd * (qn + qnm1 / 3. + dt * nlvecq)
        q2[:] = Linv21 * (etan + etanm1 / 3. + dt * nlvecn)

        etanp1[:] = -etanm1 / 3. + eta1 + eta2
        qnp1[:] = -qnm1 / 3. + q1 + q2

        etanm1[:] = etan
        etan[:] = etanp1

        qnm1[:] = qn
        qn[:] = qnp1

        nlnm3[:] = nlnm2
        nlnm2[:] = nlnm1
        nlnm1[:] = nln

    return ftrans.ifft(etan).real
    Mval = 14

    params = [K, ep, mu, Llx, Mval, dt, dts, Nens, sig]

    Xfloats = np.array([-.1, .1])
    xint = np.zeros(2 * Xfloats.size, dtype='float64')

    xint[0:2 * Xfloats.size:2] = Xfloats
    xint[1:2 * Xfloats.size:2] = ep * (np.cos(np.pi * Xfloats / Llx))

    nindt = int(np.round(dts / dt))
    nmax = int(np.round(tf / dt))
    nsamp = int(np.round(nmax / nindt))
    Ndat = xint.size / 2

    fft = my_fft.my_fft(KT)

    Kmesh = empty_aligned(KT, dtype='float64')
    tnh = empty_aligned(KT, dtype='float64')
    mDk = empty_aligned(KT, dtype='float64')
    L1 = empty_aligned(KT, dtype='float64')

    # Build forcast and analysis matrices.
    xf = np.zeros([2 * (KT + Ndat), Nens], dtype='float64')

    # Build time invariant vectors and matrices associated with model
    # computations.
    Xmesh = np.linspace(-Llx, Llx, KT, endpoint=False)

    Kmesh[:] = np.pi / Llx * (np.concatenate(
        (np.arange(0, K + 1), np.arange(-K + 1, 0)), 0))