Example #1
0
def test():
    print 'here we go'
    # while s.read(100000):
    #     print 'flush serial'
    uc = uControl()
    # junk = s.read(1000)
    print 'here'
    try:
        print 'uc.cuff_pressure', uc.cuff_pressure
        print 'maintain()'
        uc.maintain(200, 230, 3)
        uc.record(True)
        print 'len(uc.hirate)', len(uc.hirate)
        while uc.pump_state:
            print 'uc.cuff_pressure', uc.cuff_pressure
            serial_interact()
        print 'deflate'
        uc.deflate(40)
        uc.record(False)

        print 'len(uc.hirate)', len(uc.hirate)
        hirate = array(uc.hirate)
        if len(uc.hirate) > 0:
            dt = 0.004
            n_tap = 100
            lp_taps = util.get_lowpass_taps(5, dt, n_tap)
            llp_taps = util.get_lowpass_taps(.25, dt, n_tap)
            lpd = util.filter(hirate[:, 1] - hirate[0, 1],
                              lp_taps)[::10] + hirate[0, 1]
            llpd = util.filter(hirate[:, 1] - hirate[0, 1],
                               llp_taps)[::10] + hirate[0, 1]
            print len(lpd)
            times = hirate[::10, 0]
            ax = pylab.subplot(211)
            pylab.plot(times, lpd)
            pylab.plot(times, llpd)
            pylab.subplot(212, sharex=ax)
            pylab.plot(times, lpd - llpd)
            pfn = 'hirate.pkl'
            pickle.dump(hirate, open(pfn, 'w'))
            print 'write', pfn
            # pylab.figure(2); pylab.plot(uc.lpf.out)
            # pylab.figure(3); pylab.plot(hirate[:,1])

        print 'done'
    finally:
        uc.deflate(50)
        send_cmd(pump_rate=False, valve=getValveByte(valve0=True))
        time.sleep(2)
        send_cmd(pump_rate=False, valve=getValveByte(valve0=False), interval=0)
    pylab.show()
Example #2
0
def test():
    print 'here we go'
    # while s.read(100000):
    #     print 'flush serial'
    uc = uControl()
    # junk = s.read(1000)
    print 'here'
    try:
        print 'uc.cuff_pressure', uc.cuff_pressure
        print 'maintain()'
        uc.maintain(200, 230, 3)
        uc.record(True)
        print 'len(uc.hirate)', len(uc.hirate)
        while uc.pump_state:
            print 'uc.cuff_pressure', uc.cuff_pressure
            serial_interact()
        print 'deflate'
        uc.deflate(40)
        uc.record(False)
        
        print 'len(uc.hirate)', len(uc.hirate)
        hirate = array(uc.hirate)
        if len(uc.hirate) > 0:
            dt = 0.004
            n_tap = 100
            lp_taps = util.get_lowpass_taps(5, dt, n_tap)
            llp_taps = util.get_lowpass_taps(.25, dt, n_tap)
            lpd = util.filter(hirate[:,1] - hirate[0, 1], lp_taps)[::10] + hirate[0, 1]
            llpd = util.filter(hirate[:,1] - hirate[0, 1], llp_taps)[::10] + hirate[0, 1]
            print len(lpd)
            times = hirate[::10,0]
            ax = pylab.subplot(211)
            pylab.plot(times, lpd)
            pylab.plot(times, llpd)
            pylab.subplot(212, sharex=ax)
            pylab.plot(times, lpd - llpd)
            pfn = 'hirate.pkl'
            pickle.dump(hirate, open(pfn, 'w'))
            print 'write', pfn
            # pylab.figure(2); pylab.plot(uc.lpf.out)
            # pylab.figure(3); pylab.plot(hirate[:,1])

        print 'done'
    finally:
        uc.deflate(50)
        send_cmd(pump_rate=False, valve=getValveByte(valve0=True))
        time.sleep(2)
        send_cmd(pump_rate=False, valve=getValveByte(valve0=False), interval=0)
    pylab.show()
Example #3
0
def plot_hirate(hirate):
    times = hirate[:,0]
    gage = hirate[:,1]
    flow = hirate[:,2]

    figure(1)
    ax = pylab.subplot(211)
    ylabel('Gage mmHG')
    pylab.plot(times, gage)
    pylab.subplot(212)
    xlabel('Time sec.')
    ylabel('Flow')
    pylab.plot(times, flow)
    
    figure(2) ## plot high pass data
    lp_taps = util.get_lowpass_taps(.5, dt=.004, n=100)
    hpd = util.filter(gage - gage[0], lp_taps) + gage[0]
    plot(gage, gage - hpd)
Example #4
0
    def __init__(self, listener=None, dummy=False, port=None):
        self.__abort = False
        self.recording = False      # flag to indicate times when data is to be captured
        self.hirate = []            # store hirate data when recording
        self.lorate = []            # not used
        self.mpid_count = 0
        self.lpid_count = 0         # not used

        ## uControl readings
        self.cuff_pressure = None   
        self.flow_rate = None
        self.pulse_rate = None
        self.amb_pressure = None
        self.amb_temp = None
        self.pump_state = None
        self.valve_state = None
        self.short_msg = None
        self.last_update = None
        
        ## used to control inflation and deflation
        self.max_pressure = 1e6
        self.min_pressure = -1
        self.listener = listener
        
        self.dt = 0.004  ## DO NOT Change without also changing uControl firmware
        self.n_tap = 20
        self.lp_taps = util.get_lowpass_taps(10, self.dt, self.n_tap) ## 0 - 5 Hz filter for data
        self.lpf = util.StreamingFir(self.lp_taps, 2500, 10)
        
        ## get notifed of new messages from uControl firmware
        subscribe(MPID.PID, self.mpid_cb)
        subscribe(ShortPID.PID, self.short_cb)
        subscribe(StatusPID.PID, self.status_cb)

        ### connect to uControl hardware
        connect(port)
        send_cmd(cuff_pressure=True, interval=1)   ## interval=1 ==> .004 sec dt
        tries = 0
        if not dummy:
            while self.cuff_pressure is None:
                serial_interact()
                tries += 1
                if tries % 10 == 9:
                    print 'tries', tries
Example #5
0
    def __init__(self, listener=None, dummy=False):
        self.__abort = False
        self.recording = False      # flag to indicate times when data is to be captured
        self.hirate = []            # store hirate data when recording
        self.lorate = []            # not used
        self.mpid_count = 0
        self.lpid_count = 0         # not used

        ## uControl readings
        self.cuff_pressure = None   
        self.flow_rate = None
        self.pulse_rate = None
        self.amb_pressure = None
        self.amb_temp = None
        self.pump_state = None
        self.valve_state = None
        self.short_msg = None
        self.last_update = None
        
        ## used to control inflation and deflation
        self.max_pressure = 1e6
        self.min_pressure = -1
        self.listener = listener
        
        self.dt = 0.004  ## DO NOT Change without also changing uControl firmware
        self.n_tap = 20
        self.lp_taps = util.get_lowpass_taps(10, self.dt, self.n_tap) ## 0 - 5 Hz filter for data
        self.lpf = util.StreamingFir(self.lp_taps, 2500, 10)
        
        ## get notifed of new messages from uControl firmware
        subscribe(MPID.PID, self.mpid_cb)
        subscribe(ShortPID.PID, self.short_cb)
        subscribe(StatusPID.PID, self.status_cb)

        ### connect to uControl hardware
        send_cmd(cuff_pressure=True, interval=1)   ## interval=1 ==> .004 sec dt
        tries = 0
        if not dummy:
            while self.cuff_pressure is None:
                serial_interact()
                tries += 1
                if tries % 10 == 9:
                    print 'tries', tries
Example #6
0
def plot_hirate(hirate, color):
    dt = 0.004
    n_tap = 100
    fmax = 10 ## Hz
    lp_taps = util.get_lowpass_taps(fmax, dt, n_tap)
    delay_taps = zeros(defaults['n_tap'])
    delay_taps[defaults['n_tap'] // 2] = 1
    
    lpd = util.filter(hirate[:,1] - hirate[0, 1], lp_taps) + hirate[0, 1]

    ax = pylab.subplot(211)
    times = hirate[:,0]
    pylab.plot(times, lpd)
    peaks, troughs = util.find_peaks_and_troughs(lpd, eps=.1, edit=False)
    if peaks[0] < troughs[0]:
        peaks = peaks[1:]
    if peaks[-1] < troughs[-1]:
        troughs = troughs[:-1]
    pylab.plot(times[peaks], lpd[peaks], 'ro')
    pylab.plot(times[troughs], lpd[troughs], 'bo')
    deltas = lpd[peaks] - lpd[troughs]
    print std(deltas)
    pylab.subplot(212)
    pylab.plot(lpd[troughs], deltas)
Example #7
0
import glob
import csv
import os.path
import sys
import pickle
import time
from pylab import *
from numpy import *

from constants import *
import util
import scipy.interpolate.interpolate as interp
import scipy.integrate

## Filter taps
LP_TAPS = util.get_lowpass_taps(defaults["high_cuttoff_hz"], defaults["dt"], defaults["n_tap"])
LLP_TAPS = util.get_lowpass_taps(defaults["low_cuttoff_hz"], defaults["dt"], defaults["n_tap"])
DELAY_TAPS = zeros(defaults["n_tap"])
DELAY_TAPS[defaults["n_tap"] // 2] = 1


def get_flow(gage, cba):
    c, b, a = cba
    return (-b + sqrt(b ** 2 - 4 * a * (c - gage))) / (2 * a)


def flow_of_gage(flow, gage, cba=None):
    """
    return the quadratic smoothed flow values
    
    flow -- flow measurements corrected for temp and pressure
r_artery = .2
delta_r_artery = .04 * r_artery
l_artery = 10
deltaVa_n = 2 * pi * r_artery * delta_r_artery * l_artery
# Cn = deltaVa_n / PP
# print Cn

Pamb = 760     ## mmHg

OVERSAMPLE = 1
DT = defaults['dt'] / OVERSAMPLE

Tmax = 140

LP_TAPS = util.get_lowpass_taps(defaults['high_cuttoff_hz'], 
                                defaults['dt'],
                                defaults['n_tap'])
LLP_TAPS = util.get_lowpass_taps(defaults['low_cuttoff_hz'], 
                                 defaults['dt'],
                                 defaults['n_tap'])

T_OFFSET = .123123

def smooth_dP_dt(t, r0, p0):
    '''
    return average pressure change rate as a function of t
    '''
    return -r0 * exp(-(r0 / p0) * t)

def smooth_P(t, r0, p0):
    return P0 * exp(-(r0  / p0) * t)