Пример #1
0
def get_more_evidence():
    """
    Obtains a new piece of evidence and introduces it in the appropriate
    structures.
    """
    if BUF.get_status() is BUF.Status.STOPPED:
        return
    dtime = _TFACTOR * (T.time() - _T0) * 1000.0
    cursize = SIG.get_signal_length()
    if dtime - sp2ms(cursize) > sp2ms(_STEP):
        nchunks = int((min(ms2sp(dtime), _DURATION) - cursize) / _STEP)
        init = _OFFSET + cursize
        for i in xrange(len(_REC.leads)):
            fragment = _REC.signal[i, init:init + nchunks * _STEP]
            if len(fragment) < nchunks * _STEP:
                fragment = np.concatenate(
                    (fragment,
                     fragment[-1] * np.ones(_STEP - len(fragment) % _STEP)))
            SIG.add_signal_fragment(fragment, _REC.leads[i])
        for ann in (a for a in _ANNOTS
                    if ((is_qrs_annotation(a) or a.code is ECGCodes.FLWAV)
                        and init <= a.time < init + nchunks * _STEP)):
            rdef = o.RDeflection()
            atime = ann.time - _OFFSET
            rdef.time.value = Iv(atime, atime)
            #The level is established according to the annotation information.
            rdef.level = {
                SIG.VALID_LEAD_NAMES[lead]: 127
                for lead in _REC.leads
            }
            rdef.level[SIG.VALID_LEAD_NAMES[_REC.leads[ann.chan]]] = (127 -
                                                                      ann.num)
            rdef.freeze()
            BUF.publish_observation(rdef)
        newsize = SIG.get_signal_length()
        if newsize >= _DURATION or newsize >= len(_REC.signal[0]) - _OFFSET:
            BUF.set_status(BUF.Status.STOPPED)
Пример #2
0

def get_record_name():
    """Obtains the name of the input reecord"""
    return _RECNAME


if __name__ == "__main__":
    REC = '/databases/mit/100'
    set_record(REC, 'qrs')
    set_duration(10240)
    set_offset(18550)
    start()
    while True:
        get_more_evidence()
        print(SIG.get_signal_length(), BUF.get_status())
        if BUF.get_status() == BUF.Status.STOPPED:
            break
        T.sleep(0.1)
    print('Total length of acquired signal: {0} (in {1} s)'.format(
        SIG.get_signal_length(),
        T.time() - _T0))
    reset()
    #We test higher temporal factors
    _TFACTOR = 30.0
    set_duration(650240)
    set_offset(0)
    start()
    while True:
        get_more_evidence()
        print(SIG.get_signal_length(), BUF.get_status())
Пример #3
0
cntr = searching.Construe(interp, KFACTOR)
ltime = (cntr.last_time, t0)
#Main loop
while cntr.best is None:
    IN.get_more_evidence()
    acq_time = IN.get_acquisition_point()
    #HINT debug code
    fstr = 'Int: {0:05d} '
    for i in range(int(sp2ms(acq_time - cntr.last_time) / 1000.0)):
        fstr += '-'
    fstr += ' Acq: {1}'
    if interp.counter > 100:
        print(fstr.format(int(cntr.last_time), acq_time))
    #End of debug code
    filt = ((lambda n: acq_time + n[0][2] >= MIN_DELAY)
            if obs_buffer.get_status() is obs_buffer.Status.ACQUIRING else
            (lambda _: True))
    cntr.step(filt)
    if cntr.last_time > ltime[0]:
        ltime = (cntr.last_time, time.time())
    #If the distance between acquisition time and interpretation time is
    #excessive, the search tree is pruned.
    if ms2sp((time.time() - ltime[1]) * 1000.0) * TFACTOR > MAX_DELAY:
        print('Pruning search')
        cntr.prune()
print('Finished in {0:.3f} seconds'.format(time.time() - t0))
print('Created {0} interpretations ({1} kept alive)'.format(
    interp.counter, interp.ndescendants))

#plotter.save_video(interp, '/tmp/vid.mp4', cntr.best.node)