Ejemplo n.º 1
0
def shortPR_test():
    '''Find more accurate characteristic point position.'''
    shortPR_folder = '/home/alex/LabGit/ECG_random_walk/experiments/record_test/shortQT/results0516/'
    shortPR_outputfolder = '/home/alex/LabGit/ECG_random_walk/experiments/record_test/shortQT/mcmc_enhanced157_Tonset/'
    import glob
    files = glob.glob(shortPR_folder + '*.json')

    
    loader = cLoader(2,1)
    
    file_ind = 0
    for result_file in files:
        recordID = os.path.split(result_file)[-1]
        recordID = recordID.split('.')[0]
        print 'Processing record: %s' % recordID
        file_ind += 1
        print '%d records left.' % (len(files) - file_ind)

        if os.path.exists(shortPR_outputfolder + '%s.json' % recordID) == True:
            continue

        sig = loader.loadID(recordID)

        with open(result_file, 'r') as fin:
            annots = json.load(fin)
            annots = post_p(sig, annots, 500)
            annots.sort(key = lambda x:x[0])
            annots = post_p_mcmc(sig, annots, 500)

        with open(shortPR_outputfolder + '%s.json' % recordID, 'w') as fout:
            json.dump(annots, fout, indent = 4)
Ejemplo n.º 2
0
def test1():
    '''Testing with changgeng data.'''
    from randomwalk.changgengLoader import ECGLoader as cLoader
    loader = cLoader(1, 1)
    sig = loader.loadID('2259')

    tool = PwavePicker()
    tool.pick(sig, start_index=0)
    pass
Ejemplo n.º 3
0
def post_p_mcmc_test():
    '''Find more accurate characteristic point position.'''
    loader = cLoader(2, 1)
    recordID = '5395'
    sig = loader.loadID(recordID)
    with open('./data/tmpWT/%s.json' % recordID, 'r') as fin:
        annots = json.load(fin)
        annots = post_p(sig, annots, 500)
        annots.sort(key=lambda x: x[0])
        annots = post_p_mcmc(sig, annots, 500)

    fig, ax = plt.subplots(1, 1)
    plt.plot(sig)
    plotExpertLabels(ax, sig, annots)
    plt.show()
Ejemplo n.º 4
0
def enhance_test():
    '''Find more accurate characteristic point position.'''
    loader = cLoader(2, 1)
    recordID = '54722'
    sig = loader.loadID(recordID)
    with open('./data/tmpWT/%s.json' % recordID, 'r') as fin:
        annots = json.load(fin)
        annots = post_p(sig, annots, 500)
        annots.sort(key=lambda x: x[0])

    x_range_list = list()
    x_range_start = None
    for ind in xrange(0, len(annots)):
        pos, label = annots[ind]
        if label == 'Ponset':
            x_range_start = pos - 5
        elif label == 'Poffset':
            if x_range_start is not None:
                x_range_list.append((x_range_start, pos + 5))
            x_range_start = None

    # MCMC testing
    for x_range in x_range_list:
        figID = recordID + '_x_%d' % x_range[0]
        Pannots = map(
            lambda x: [x[0] - x_range[0], x[1]],
            filter(lambda x: x[0] >= x_range[0] and x[0] <= x_range[1],
                   annots))
        pwave = PWave(sig, fs=500.0)
        pwave.detectGaussian(sig[x_range[0]:x_range[1]],
                             Pannots,
                             500.0,
                             savefig_path='./data/%s.png' % figID,
                             figID=figID)

        # pdb.set_trace()

    print 'Annotations:'
    print Pannots

    fig, ax = plt.subplots(1, 1)
    plt.plot(sig)
    plotExpertLabels(ax, sig, annots)
    plt.show()
Ejemplo n.º 5
0
def enhance_demo():
    '''Find more accurate characteristic point position.'''
    loader = cLoader(2, 1)
    recordID = '54722'
    sig = loader.loadID(recordID)
    with open('./data/tmpWT/%s.json' % recordID, 'r') as fin:
        annots = json.load(fin)
        annots = post_p(sig, annots, 500)

    x_range = (920, 1010)
    Pannots = map(
        lambda x: [x[0] - x_range[0], x[1]],
        filter(lambda x: x[0] >= x_range[0] and x[0] <= x_range[1], annots))
    pwave = PWave(sig, fs=500.0)
    pwave.detectGaussian(sig[x_range[0]:x_range[1]], Pannots, 500.0)

    print 'Annotations:'
    print Pannots

    fig, ax = plt.subplots(1, 1)
    plt.plot(sig)
    plotExpertLabels(ax, sig, annots)
    plt.show()