示例#1
0
def plotMITdbTestResult():
    RFfolder = os.path.join(\
           projhomepath,\
           'TestResult',\
           'pc',\
           'r3')
    TargetRecordList = [
        'sel38',
        'sel42',
    ]
    # ==========================
    # plot prediction result
    # ==========================
    reslist = glob.glob(os.path.join(\
           RFfolder,'*'))
    for fi, fname in enumerate(reslist):
        # block *.out
        if fname[-4:] == '.out' or '.json' in fname:
            continue
        print 'file name:', fname
        currecname = os.path.split(fname)[-1]
        if currecname not in TargetRecordList:
            pass
        pdb.set_trace()
        with open(fname, 'r') as fin:
            (recID, reslist) = pickle.load(fin)
        # load signal
        mitdb = MITdbLoader()
        rawsig = mitdb.load(recID)
        # plot res
        resploter = ECGResultPloter(rawsig, reslist)
        resploter.plot()
    def inspect_recs(self):
        reclist = self.qt.getQTrecnamelist()
        set_testing = set(conf['selQTall0_test_set'])
        set_training = set(reclist) - set_testing

        out_reclist = set_training

        # records selected
        selected_record_list = []
        for ind, recname in enumerate(out_reclist):
            # inspect
            print '{} records left.'.format(len(out_reclist) - ind - 1)
            # plot
            QTsig = self.qt.load(recname)
            rawsig = QTsig['sig']
            # expert labels
            testresult = self.qt.getexpertlabeltuple(recname)
            poslist, labellist = zip(*testresult)
            poslist = list(poslist)
            poslist.sort()
            dispRange = (poslist[0], poslist[-1])
            resplt = ECGResultPloter(rawsig, testresult)
            resplt.plot(plotTitle='QT record {}'.format(recname),
                        dispRange=dispRange)
            #self.qt.plotrec(recname)
            usethis = raw_input('Use this record as training record?(y/n):')
            if usethis == 'y':
                selected_record_list.append(recname)
            # debug
            #if ind > 2:
            #pass
        with open(
                os.path.join(os.path.dirname(curfilepath),
                             'selected_training_records.json'), 'w') as fout:
            json.dump(selected_record_list, fout)
def plot_QTdb_filtered_Result_with_syntax_filter(RFfolder,
                                                 TargetRecordList,
                                                 ResultFilterType,
                                                 showExpertLabels=False):
    # exit
    # ==========================
    # plot prediction result
    # ==========================
    reslist = getresultfilelist(RFfolder)
    qtdb = QTloader()
    non_result_extensions = ['out', 'json', 'log', 'txt']
    for fi, fname in enumerate(reslist):
        # block *.out
        file_extension = fname.split('.')[-1]
        if file_extension in non_result_extensions:
            continue
        print 'file name:', fname
        currecname = os.path.split(fname)[-1]
        print currecname
        #if currecname == 'result_sel820':
        #pdb.set_trace()
        if TargetRecordList is not None:
            if currecname not in TargetRecordList:
                continue
        # load signal and reslist
        with open(fname, 'r') as fin:
            (recID, reslist) = pickle.load(fin)
        # filter result of QT
        resfilter = ResultFilter(reslist)
        if len(ResultFilterType) >= 1 and ResultFilterType[0] == 'G':
            reslist = resfilter.group_local_result(cp_del_thres=1)
        reslist_syntax = reslist
        if len(ResultFilterType) >= 2 and ResultFilterType[1] == 'S':
            reslist_syntax = resfilter.syntax_filter(reslist)
        # empty signal result
        #if reslist is None or len(reslist) == 0:
        #continue
        #pdb.set_trace()
        sigstruct = qtdb.load(recID)
        if showExpertLabels == True:
            # Expert Label AdditionalPlot
            ExpertRes = qtdb.getexpertlabeltuple(recID)
            ExpertPoslist = map(lambda x: x[0], ExpertRes)
            AdditionalPlot = [
                ['kd', 'Expert Labels', ExpertPoslist],
            ]
        else:
            AdditionalPlot = None

        # plot res
        #resploter = ECGResultPloter(sigstruct['sig'],reslist)
        #resploter.plot(plotTitle = 'QT database',plotShow = True,plotFig = 2)
        # syntax_filter
        resploter_syntax = ECGResultPloter(sigstruct['sig'], reslist_syntax)
        resploter_syntax.plot(plotTitle='QT Record {}'.format(recID),
                              plotShow=True,
                              AdditionalPlot=AdditionalPlot)
示例#4
0
def plot_QTdb_filtered_Result_with_syntax_filter():
    # exit
    RFfolder = os.path.join(\
           projhomepath,\
           'TestResult',\
           'pc',\
           'r5')
    TargetRecordList = [
        'result_sel39',
        'result_sel41',
        'result_sel48',
    ]  #'sel38','sel42','result_sel821','result_sel14046']
    # ==========================
    # plot prediction result
    # ==========================
    reslist = glob.glob(os.path.join(\
           RFfolder,'*'))
    qtdb = QTloader()
    non_result_extensions = ['out', 'json', 'log']
    for fi, fname in enumerate(reslist):
        # block *.out
        file_extension = fname.split('.')[-1]
        if file_extension in non_result_extensions:
            continue
        print 'file name:', fname
        currecname = os.path.split(fname)[-1]
        print currecname
        #if currecname == 'result_sel820':
        #pdb.set_trace()
        if currecname not in TargetRecordList:
            pass
            continue
        # load signal and reslist
        with open(fname, 'r') as fin:
            (recID, reslist) = pickle.load(fin)
        # filter result of QT
        resfilter = ResultFilter(reslist)
        reslist = resfilter.group_local_result(cp_del_thres=1)
        reslist_syntax = resfilter.syntax_filter(reslist)
        # empty signal result
        #if reslist is None or len(reslist) == 0:
        #continue
        #pdb.set_trace()
        sigstruct = qtdb.load(recID)
        # plot res
        #resploter = ECGResultPloter(sigstruct['sig'],reslist)
        #resploter.plot(plotTitle = 'QT database',plotShow = True,plotFig = 2)
        # syntax_filter
        resploter_syntax = ECGResultPloter(sigstruct['sig'], reslist_syntax)
        resploter_syntax.plot(plotTitle='QT database syntax_filter',
                              plotShow=True)
示例#5
0
def plotMITdbTestResult():
    RFfolder = os.path.join(\
           projhomepath,\
           'TestResult',\
           'pc',\
           'r3')
    TargetRecordList = [
        'sel38',
        'sel42',
    ]
    # ==========================
    # plot prediction result
    # ==========================
    reslist = glob.glob(os.path.join(\
           RFfolder,'*'))
    for fi, fname in enumerate(reslist):
        # block *.out
        # filter file name
        if fname[-4:] == '.out' or '.json' in fname:
            continue
        currecname = os.path.split(fname)[-1]
        if currecname not in TargetRecordList:
            pass
        if not currecname.startswith('result'):
            continue
        print 'processing file', fname, '...'
        with open(fname, 'r') as fin:
            (recID, reslist) = pickle.load(fin)
        print 'pickle file loaded.'
        # load signal from MITdb
        print 'loading signal data from MITdb...'
        mitdb = MITdbLoader()
        rawsig = mitdb.load(recID)
        print 'signal loaded.'
        # filter result list
        resfilter = ResultFilter(reslist)
        reslist = resfilter.groupresult()
        # plot res
        resploter = ECGResultPloter(rawsig, reslist)
        dispRange = (20000, 21000)
        savefolderpath = os.path.join(curfolderpath, 'tmp', 'MITdbTestResult')
        # debug
        #pdb.set_trace()
        #resploter.plot()
        #resploter.plotAndsave(os.path.join(savefolderpath,recID),plotTitle = 'ID:{},Range:{}'.format(recID,dispRange),dispRange = dispRange)
        resploter.plot(plotTitle=recID)
        pdb.set_trace()
示例#6
0
    def debug_FN_FP(self,rawsig,reslist,FN,FP):
        # =================================
        # group result labels
        resgrper = ECGGrouper(reslist)
        ft_reslist = resgrper.group_local_result(reslist)

        # delete white point
        reslist = filter(lambda x:x[1]=='R',reslist)
        
        # R wave pos only
        ft_reslist = filter(lambda x:x[1]=='R',ft_reslist)
        # filtering
        ft_reslist = resgrper.syntax_filter(ft_reslist,Max_Len_Ratio = 1.0/5.0)
        # =================================
        FN_plot_line = ['rd','False Negtive',FN['pos']]
        FP_plot_line = ['ks','False Negtive',FP['pos']]
        #res_plot_line = ['ko','filtered R',map(lambda x:x[0],ft_reslist)]
        # plot res
        resploter = ECGResultPloter(rawsig,reslist)
        resploter.plot(plotTitle = 'Detection Result:'+FN['recname'][0],AdditionalPlot = [FN_plot_line,FP_plot_line,])
示例#7
0
def plotMITdbTestResult():
    RFfolder = os.path.join(\
           projhomepath,\
           'TestResult',\
           'pc',\
           'r3')
    TargetRecordList = ['sel38','sel42',]
    # ==========================
    # plot prediction result
    # ==========================
    reslist = glob.glob(os.path.join(\
           RFfolder,'*'))
    for fi,fname in enumerate(reslist):
        # block *.out
        # filter file name
        if fname[-4:] == '.out' or '.json' in fname:
            continue
        currecname = os.path.split(fname)[-1]
        if currecname not in TargetRecordList:
            pass
        if not currecname.startswith('result'):
            continue
        print 'processing file name:',fname
        with open(fname,'r') as fin:
            (recID,reslist) = pickle.load(fin)
        # load signal
        mitdb = MITdbLoader()
        rawsig = mitdb.load(recID)
        # plot res
        # group result labels
        resgrper = ECGGrouper(reslist)
        reslist = resgrper.group_local_result(reslist)

        resploter = ECGResultPloter(rawsig,reslist)
        dispRange = (20000,21000)
        savefolderpath = ur'E:\ECGResults\MITdbTestResult\pic'
        # debug
        #resploter.plot()
        resploter.plot(plotTitle = 'ID:{},Range:{}'.format(recID,dispRange),dispRange = dispRange)
示例#8
0
        if file_extension in non_result_extensions:
            continue
        print 'file name:', fname
        currecname = os.path.split(fname)[-1]
        print currecname
        #if currecname == 'result_sel820':
        #pdb.set_trace()
        if currecname not in TargetRecordList:
            pass
            #continue
        # load signal and reslist
        with open(fname, 'r') as fin:
            (recID, reslist) = pickle.load(fin)
        # filter result of QT
        resfilter = ResultFilter(reslist)
        reslist = resfilter.group_local_result(cp_del_thres=1)
        # empty signal result
        #if reslist is None or len(reslist) == 0:
        #continue
        #pdb.set_trace()
        sigstruct = qtdb.load(recID)
        # plot figure
        # plot res
        resploter = ECGResultPloter(sigstruct['sig'], reslist)
        resploter.plot(plotTitle='QT database')

    #==========================
    #show evaluation statistics
    #==========================
    #TestN_Eval(RFfolder)