]

        # all_feature_names_s1=['s1_wave_dur_time','s1_wave_ini_time','s1_wave_ter_time','s1_wave_asy_time','s1_pr_on_time','s1_pr_peak_time','s1_pr_off_time','s1_pp_on_time']
        index_num = 0
        for arr in all_time_features:
            index_num = index_num + 1
            trend_s0 = pecg.extract_trend_frm_list(arr)
            # trend_s1=pecg.extract_trend_frm_list(s1_wave_ini_time)
            ###plot pwave points  and save fig ####
            fig_pwave, plot_pwave = graphs.plotScatter(
                record,
                range(len(trend_s0)),
                trend_s0,
                "Number of 10 P wave-length intervals",
                " P dur variability (samples) ",
                "P dur variability",
                "b",
                xlim_lo=0,
                xlim_hi=140,
                ylim_lo=0,
                ylim_hi=140,
                axline=0,
            )
            plt.plot(
                range(len(trend_s0)), np.poly1d(np.polyfit(range(len(trend_s0)), trend_s0, 1))(range(len(trend_s0)))
            )
            plt.xlim(0, 100)
            plt.ylim(0, 140)
            # fig_pwave,plot_pwave=graphs.plot_simple(rec_name,range(len(p_wave_times_0)),p_wave_times_0, "serial num", " pwave duration (ms) ", "s0 p wave duration ", 'g',xlim_lo=0, xlim_hi=0, ylim_lo=0, ylim_hi=0)
            fig_pwave.savefig(output_folder + "trend_s0_pwave_ini_" + record + ".pdf", format="pdf")
            plt.show()
            print ("done")
    for sig_num in signals: # this for loop generates feature arrays for both signals 0 and 1
        all_time_features=pecg.extract_wave_times(output_folder,record,rec_name,annotation,start_time,end_time,sig_num)
        
#         all_feature_names=['wave_dur_time','wave_ini_time','wave_ter_time','wave_asy_time','pr_on_time','pr_peak_time','pr_off_time']
#         stat_feature_names=[sig_num+'_'+'size_val',sig_num+'_'+'min',sig_num+'_'+'max',sig_num+'_'+'mean_val',sig_num+'_'+'var_val',sig_num+'_'+'skewness_val',sig_num+'_'+'kurtosis_val']
        all_feature_names=['wave_dur_time']
        stat_feature_names=[sig_num+'_'+'size_val',sig_num+'_'+'min',sig_num+'_'+'max',sig_num+'_'+'mean_val',sig_num+'_'+'var_val',sig_num+'_'+'skewness_val',sig_num+'_'+'kurtosis_val']
        
        #all_feature_names_s1=['s1_wave_dur_time','s1_wave_ini_time','s1_wave_ter_time','s1_wave_asy_time','s1_pr_on_time','s1_pr_peak_time','s1_pr_off_time','s1_pp_on_time']
        index_num=0;
        for arr in all_time_features:
            index_num=index_num+1;
            trend_s0=pecg.extract_trend_frm_list(arr)
            #trend_s1=pecg.extract_trend_frm_list(s1_wave_ini_time)
            ###plot pwave points  and save fig ####
            fig_pwave,plot_pwave=graphs.plotScatter(record,range(len(trend_s0)),trend_s0, "Number of 10 P wave-length intervals", " P dur variability (samples) ", "P dur variability", 'b',xlim_lo=0, xlim_hi=140, ylim_lo=0, ylim_hi=140,axline=0)
            plt.plot(range(len(trend_s0)), np.poly1d(np.polyfit(range(len(trend_s0)), trend_s0, 1))(range(len(trend_s0))))
            plt.xlim(0,100);
            plt.ylim(0,140);
            #fig_pwave,plot_pwave=graphs.plot_simple(rec_name,range(len(p_wave_times_0)),p_wave_times_0, "serial num", " pwave duration (ms) ", "s0 p wave duration ", 'g',xlim_lo=0, xlim_hi=0, ylim_lo=0, ylim_hi=0)
            fig_pwave.savefig(output_folder+"trend_s0_pwave_ini_"+record+".pdf",format='pdf')
            plt.show()   
            print("done")
            exit()
    #all_features.append(feature_rec)
    


    #pwave_time_patient,pwave_time_normal=pecg.separate_p_n_pwave(record,db_name,p_wave_times,pwave_time_patient,pwave_time_normal) #i dont thing we need this
#     feature_rec.append(p_wave_times_0)
#     global_vocab_ecg,index_of_features_ecg=cl.fill_global_vocab("pwave_time_0", index_of_features_ecg, global_vocab_ecg)
def calc_std_5min_sodp_measures(rec_name, annotation, total_min, radius_array):
    #this functions calculates features from 5 min of RR intervals for record , and calculates std of each feature for all 5min intervlas in a 30min record.
    #it returns  all_features_6_intervals : each list corresponds to one feature and values within the list are denote the feature value per interval
    #it returns: std_dev_all_features :each value is the std dev of the feature in 6 intervals
    #it also returns feature_name_overall : names of features whose std dev can be found in std_dev_all_Features

    feature_list_5min = []
    num_5min_interval = 1  #keeps track of which chunck of 5 min interval it is
    feature_name = []

    start_time_arr = range(0, total_min, 5)
    end_time_arr = range(5, total_min + 5, 5)

    # everytime the loop runs it extracts feauters for those 5 mins

    for start_time, end_time in zip(start_time_arr, end_time_arr):
        error_rec_names = []
        count_quad1 = 0
        count_quad2 = 0
        count_quad3 = 0
        count_quad4 = 0

        count_quad11 = 0
        count_quad12 = 0
        count_quad13 = 0
        count_quad14 = 0

        count_quad21 = 0
        count_quad22 = 0
        count_quad23 = 0
        count_quad24 = 0

        count_quad31 = 0
        count_quad32 = 0
        count_quad33 = 0
        count_quad34 = 0

        count_quad41 = 0
        count_quad42 = 0
        count_quad43 = 0
        count_quad44 = 0
        points_at_origin = 0
        quad = 0
        print("calculating std of 5 min sodp features")
        print("start time is: " + str(start_time))
        print("end time is: " + str(end_time))

        ##### Extract RR intervals here #######

        RR_sec_unclean = pr.get_RR_interval(rec_name, annotation, start_time,
                                            end_time)

        ####DELETE THE FIRST RR_sec_unclean value#####
        del RR_sec_unclean[0]

        RR_sec = RR_sec_unclean

        #print("len of 5min RR_sec is: " + str(len(RR_sec)))
        num_RR_5min = len(RR_sec)

        #print("num_RR_5min_"+str(num_5min_interval))
        x_val_sodp, y_val_sodp, ctm_array, ctm_feature_name, distance_array, dist_feature_name = calc_sodp_measures(
            rec_name, RR_sec, radius_array)
        ## calculate the number of poitns in each quadrant
        num_points_on_graph = len(x_val_sodp)

        ####plot sodp and save fig ####
        record_name = "n43"
        output_folder = "/home/ubuntu/Documents/Thesis_work/results/thesis_images/chapter_5/"
        fig_sodp, plot_sodp = graphs.plotScatter(
            record_name,
            x_val_sodp,
            y_val_sodp,
            "x[n+1]-x[n]",
            " x[n+2]-x[n+1] ",
            "SODP plot for 5min segment " + str(num_5min_interval),
            'b',
            xlim_lo=-1,
            xlim_hi=1,
            ylim_lo=-1,
            ylim_hi=1,
            axline=1)
        fig_sodp.savefig(output_folder + "sodp_plot_" + record_name + "_" +
                         str(num_5min_interval) + ".pdf",
                         format='pdf')

        for x_val, y_val in zip(x_val_sodp, y_val_sodp):
            if x_val < -1 or x_val > 1 or y_val < -1 or y_val > 1:
                print("x_val is: " + str(x_val) + "y_val is: " + str(y_val))
                print("errorneous value in: " + str(rec_name) + "_" +
                      str(num_5min_interval))
                error_rec_names.append(rec_name)

            elif x_val > 0 and y_val > 0:
                quad = 1
                count_quad1 = count_quad1 + 1
                sub_quad = count_points_in_16quad(x_val, y_val, quad)
                if sub_quad is 11:
                    count_quad11 = count_quad11 + 1
                elif sub_quad is 12:
                    count_quad12 = count_quad12 + 1
                elif sub_quad is 13:
                    count_quad13 = count_quad13 + 1
                elif sub_quad is 14:
                    count_quad14 = count_quad14 + 1
            elif x_val < 0 and y_val > 0:
                quad = 2
                count_quad2 = count_quad2 + 1
                sub_quad = count_points_in_16quad(x_val, y_val, quad)
                if sub_quad is 21:
                    count_quad21 = count_quad21 + 1
                elif sub_quad is 22:
                    count_quad22 = count_quad22 + 1
                elif sub_quad is 23:
                    count_quad23 = count_quad23 + 1
                elif sub_quad is 24:
                    count_quad24 = count_quad24 + 1

            elif x_val < 0 and y_val < 0:
                quad = 3
                count_quad3 = count_quad3 + 1
                sub_quad = count_points_in_16quad(x_val, y_val, quad)
                if sub_quad is 31:
                    count_quad31 = count_quad31 + 1
                elif sub_quad is 32:
                    count_quad32 = count_quad32 + 1
                elif sub_quad is 33:
                    count_quad33 = count_quad33 + 1
                elif sub_quad is 34:
                    count_quad34 = count_quad34 + 1

            elif x_val > 0 and y_val < 0:
                quad = 4
                count_quad4 = count_quad4 + 1
                sub_quad = count_points_in_16quad(x_val, y_val, quad)
                if sub_quad is 41:
                    count_quad41 = count_quad41 + 1
                elif sub_quad is 42:
                    count_quad42 = count_quad42 + 1
                elif sub_quad is 43:
                    count_quad43 = count_quad43 + 1
                elif sub_quad is 44:
                    count_quad44 = count_quad44 + 1
            else:
                points_at_origin = points_at_origin + 1

        ratio_points_at_origin = float(points_at_origin) / num_points_on_graph
        #store the quad count values in features list

        feature_list_5min.append(ratio_points_at_origin)
        feature_name.append("ratio_points_at_origin_5min_" +
                            str(num_5min_interval))

        #calculate quad_ratio
        quad1_ratio = float(count_quad1) / num_points_on_graph
        quad2_ratio = float(count_quad2) / num_points_on_graph
        quad3_ratio = float(count_quad3) / num_points_on_graph
        quad4_ratio = float(count_quad4) / num_points_on_graph

        quad_11_ratio = float(count_quad11) / num_points_on_graph
        quad_12_ratio = float(count_quad12) / num_points_on_graph
        quad_13_ratio = float(count_quad13) / num_points_on_graph
        quad_14_ratio = float(count_quad14) / num_points_on_graph

        quad_21_ratio = float(count_quad21) / num_points_on_graph
        quad_22_ratio = float(count_quad22) / num_points_on_graph
        quad_23_ratio = float(count_quad23) / num_points_on_graph
        quad_24_ratio = float(count_quad24) / num_points_on_graph

        quad_31_ratio = float(count_quad31) / num_points_on_graph
        quad_32_ratio = float(count_quad32) / num_points_on_graph
        quad_33_ratio = float(count_quad33) / num_points_on_graph
        quad_34_ratio = float(count_quad34) / num_points_on_graph

        quad_41_ratio = float(count_quad41) / num_points_on_graph
        quad_42_ratio = float(count_quad42) / num_points_on_graph
        quad_43_ratio = float(count_quad43) / num_points_on_graph
        quad_44_ratio = float(count_quad44) / num_points_on_graph

        #store the quad ratio values in features list
        feature_list_5min.append(quad1_ratio)
        feature_name.append("std_quad1_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad2_ratio)
        feature_name.append("std_quad2_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad3_ratio)
        feature_name.append("std_quad3_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad4_ratio)
        feature_name.append("std_quad4_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_11_ratio)
        feature_name.append("std_quad11_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_12_ratio)
        feature_name.append("std_quad12_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_13_ratio)
        feature_name.append("std_quad13_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_14_ratio)
        feature_name.append("std_quad14_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_21_ratio)
        feature_name.append("std_quad21_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_22_ratio)
        feature_name.append("std_quad22_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_23_ratio)
        feature_name.append("std_quad23_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_24_ratio)
        feature_name.append("std_quad24_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_31_ratio)
        feature_name.append("std_quad31_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_32_ratio)
        feature_name.append("std_quad32_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_33_ratio)
        feature_name.append("std_quad33_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_34_ratio)
        feature_name.append("std_quad34_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_41_ratio)
        feature_name.append("std_quad41_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_42_ratio)
        feature_name.append("std_quad42_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_43_ratio)
        feature_name.append("std_quad43_ratio_5min_" + str(num_5min_interval))

        feature_list_5min.append(quad_44_ratio)
        feature_name.append("std_quad44_ratio_5min_" + str(num_5min_interval))

        #print ("feature list for this 5 min interval is: " + str(feature_list_5min))
        #print("indexes are:                              " + str(range(len(feature_list_5min))))
        num_5min_interval = num_5min_interval + 1
        print("rec_names with errornos records are : " + str(error_rec_names))

    dist_bw_feature = 21
    start_ind = 0
    end_ind = 105
    feature_name_overall = []
    #print (len(feature_list_5min))
    all_features_6_intervals = []
    for i in range(0, 21):
        name = str(feature_name[i])
        feature_name_overall.append(name[:-2])
        #print("feature_name is: " + str(name[:-2]))
        feature_index_5min = range(start_ind, end_ind + 21, dist_bw_feature)
        one_feature_all_intervals = []
        for val in feature_index_5min:
            #print("val is : "+str(val))
            feature_val = feature_list_5min[val]
            #print("feature_val at index : " + str(val)+" is: "+str(feature_val))
            one_feature_all_intervals.append(feature_val)

        all_features_6_intervals.append(one_feature_all_intervals)
        start_ind = start_ind + 1
        end_ind = end_ind + 1
        feature_index_5min = range(start_ind, end_ind + 21, dist_bw_feature)
        #print ("new indexes for feature index is: " + str(feature_index_5min))

    std_dev_all_features = []
    for list_feature_vals in all_features_6_intervals:
        std_dev_5min_feature = np.std(list_feature_vals)
        std_dev_all_features.append(std_dev_5min_feature)

    #for name,val in zip(feature_name_overall,std_dev_all_features):
    #print("name of feature is : " + str(name))
    #print("val of feature is : " + str(val))
    return all_features_6_intervals, std_dev_all_features, feature_name_overall
        global_vocab,index_of_features=cl.fill_global_vocab(name, index_of_features, global_vocab)
    
    
#     if "n" in record:
#         ####plot sodp and save fig ####
#         fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot ", 'b',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
#         fig_sodp.savefig(output_folder+"sodp_plot_"+record+".pdf",format='pdf')
#     if "p" in record:
#         ####plot sodp and save fig ####
#         fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot ", 'r',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
#         fig_sodp.savefig(output_folder+"sodp_plot_"+record+".pdf",format='pdf')
    
    ############## showing 16 quadrants
    if "p" in record:
        ####plot sodp and save fig ####
        fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "16 Quadrants in the SODP plot ", 'r',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
        fig_sodp.savefig(output_folder+"quad_sodp_plot_"+record+".pdf",format='pdf')
    
    
    
    ###################################3
    #     ##### Calculating 30 min quadrant points ratio features  #################
  
    #end_time=1;
    feature_list_30min,feature_name=nlm.calc_30min_sodp_measures(rec_name,annotation, start_time,end_time, x_val_sodp,y_val_sodp)
    
    ##add value to feature array and name to global vocab
    for val,name in zip(feature_list_30min,feature_name):
        feature_rec.append(val)
        #print name
        #print val
示例#5
0
        #
        #         if "n" in record:
        #
        #             ####plot sodp and save fig ####
        #             fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot for "+str(start_time)+"to"+str(end_time), 'b',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
        #             fig_sodp.savefig(output_folder+"sodp_plot_"+record+"_"+str(start_time)+"to"+str(end_time)+".png")
        #
        #         elif "p" in record:
        #         ####plot sodp and save fig ####
        #             fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot for "+str(start_time)+"to"+str(end_time), 'r',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
        #             fig_sodp.savefig(output_folder+"sodp_plot_"+record+"_"+str(start_time)+"to"+str(end_time)+".png")
        #
        ######### PLOTTING SODP for afib plots array ################

        ####plot sodp and save fig ####
        fig_sodp, plot_sodp = graphs.plotScatter(
            rec_name,
            x_val_sodp,
            y_val_sodp,
            "x[n+1]-x[n]",
            " x[n+2]-x[n+1] ",
            "SODP plot for " + str(start_time) + "to" + str(end_time),
            'b',
            xlim_lo=-1,
            xlim_hi=1,
            ylim_lo=-1,
            ylim_hi=1,
            axline=1)
        fig_sodp.savefig(output_folder + "sodp_plot_" + record + "_" +
                         str(start_time) + "to" + str(end_time) + ".png")
def calc_std_5min_sodp_measures(rec_name,annotation, total_min, radius_array):
    #this functions calculates features from 5 min of RR intervals for record , and calculates std of each feature for all 5min intervlas in a 30min record.
    #it returns  all_features_6_intervals : each list corresponds to one feature and values within the list are denote the feature value per interval
    #it returns: std_dev_all_features :each value is the std dev of the feature in 6 intervals 
    #it also returns feature_name_overall : names of features whose std dev can be found in std_dev_all_Features
    
 
    feature_list_5min=[]
    num_5min_interval=1 #keeps track of which chunck of 5 min interval it is
    feature_name=[]
    
    
    
    start_time_arr=range(0,total_min,5)
    end_time_arr=range(5,total_min+5,5)
    
    # everytime the loop runs it extracts feauters for those 5 mins
    
    for start_time, end_time in zip(start_time_arr,end_time_arr):
        error_rec_names=[]
        count_quad1=0;
        count_quad2=0;
        count_quad3=0;
        count_quad4=0;
       
        count_quad11=0;  
        count_quad12=0
        count_quad13=0
        count_quad14=0
        
        count_quad21=0;  
        count_quad22=0
        count_quad23=0
        count_quad24=0
        
        count_quad31=0;  
        count_quad32=0
        count_quad33=0
        count_quad34=0
        
        
        count_quad41=0;  
        count_quad42=0
        count_quad43=0
        count_quad44=0
        points_at_origin=0;
        quad=0;
        print("calculating std of 5 min sodp features")
        print ("start time is: " +str(start_time));
        print ("end time is: " +str(end_time));
        
        
        
        
        ##### Extract RR intervals here #######
        
        RR_sec_unclean=pr.get_RR_interval(rec_name,annotation,start_time,end_time)
        
        ####DELETE THE FIRST RR_sec_unclean value#####
        del RR_sec_unclean[0];
        
        RR_sec=RR_sec_unclean
        
        #print("len of 5min RR_sec is: " + str(len(RR_sec)))
        num_RR_5min=len(RR_sec)
        
        #print("num_RR_5min_"+str(num_5min_interval))
        x_val_sodp,y_val_sodp,ctm_array,ctm_feature_name,distance_array,dist_feature_name=calc_sodp_measures(rec_name,RR_sec, radius_array);
        ## calculate the number of poitns in each quadrant
        num_points_on_graph=len(x_val_sodp)
        
       
        ####plot sodp and save fig ####
        record_name="n43"
        output_folder="/home/ubuntu/Documents/Thesis_work/results/thesis_images/chapter_5/"
        fig_sodp,plot_sodp=graphs.plotScatter(record_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot for 5min segment "+str(num_5min_interval) , 'b',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
        fig_sodp.savefig(output_folder+"sodp_plot_"+record_name+"_"+str(num_5min_interval)+".pdf",format='pdf')
  
        
        
        
        for x_val,y_val in zip(x_val_sodp,y_val_sodp):
            if x_val <-1 or x_val>1 or y_val<-1 or y_val>1:
                print("x_val is: " +str(x_val) + "y_val is: " + str(y_val))
                print("errorneous value in: " + str(rec_name) +"_"+str(num_5min_interval))
                error_rec_names.append(rec_name)
            
            elif x_val > 0 and y_val >0:
                quad=1;
                count_quad1=count_quad1+1;
                sub_quad=count_points_in_16quad(x_val,y_val,quad)
                if sub_quad is 11:
                    count_quad11=count_quad11+1;
                elif sub_quad is 12:
                    count_quad12=count_quad12+1;
                elif sub_quad is 13:
                    count_quad13=count_quad13+1;
                elif sub_quad is 14:
                    count_quad14=count_quad14+1;
            elif x_val <0  and y_val >0:
                quad=2;
                count_quad2=count_quad2+1;
                sub_quad=count_points_in_16quad(x_val,y_val,quad)
                if sub_quad is 21:
                    count_quad21=count_quad21+1
                elif sub_quad is 22:
                    count_quad22=count_quad22+1
                elif sub_quad is 23:
                    count_quad23=count_quad23+1
                elif sub_quad is 24:
                    count_quad24=count_quad24+1
                 
            elif x_val <0 and y_val <0:
                quad=3;
                count_quad3=count_quad3+1;
                sub_quad=count_points_in_16quad(x_val,y_val,quad)
                if sub_quad is 31:
                    count_quad31=count_quad31+1
                elif sub_quad is 32:
                    count_quad32=count_quad32+1
                elif sub_quad is 33:
                    count_quad33=count_quad33+1
                elif sub_quad is 34:
                    count_quad34=count_quad34+1
                 
                 
                 
            elif x_val>0 and y_val<0:
                quad=4;
                count_quad4=count_quad4+1;
                sub_quad=count_points_in_16quad(x_val,y_val,quad)
                if sub_quad is 41:
                    count_quad41=count_quad41+1
                elif sub_quad is 42:
                    count_quad42=count_quad42+1
                elif sub_quad is 43:
                    count_quad43=count_quad43+1
                elif sub_quad is 44:
                    count_quad44=count_quad44+1
            else:
                points_at_origin=points_at_origin+1 
                
        ratio_points_at_origin=float(points_at_origin)/num_points_on_graph
        #store the quad count values in features list
         
        
        
        
       
        
        
        feature_list_5min.append(ratio_points_at_origin)
        feature_name.append("ratio_points_at_origin_5min_"+str(num_5min_interval))
        
        

        
        #calculate quad_ratio 
        quad1_ratio=float(count_quad1)/num_points_on_graph;
        quad2_ratio=float(count_quad2)/num_points_on_graph;
        quad3_ratio=float(count_quad3)/num_points_on_graph;
        quad4_ratio=float(count_quad4)/num_points_on_graph;
        
        quad_11_ratio=float(count_quad11)/num_points_on_graph;
        quad_12_ratio=float(count_quad12)/num_points_on_graph;
        quad_13_ratio=float(count_quad13)/num_points_on_graph;
        quad_14_ratio=float(count_quad14)/num_points_on_graph;
        
        quad_21_ratio=float(count_quad21)/num_points_on_graph;
        quad_22_ratio=float(count_quad22)/num_points_on_graph;
        quad_23_ratio=float(count_quad23)/num_points_on_graph;
        quad_24_ratio=float(count_quad24)/num_points_on_graph;
        
        quad_31_ratio=float(count_quad31)/num_points_on_graph;
        quad_32_ratio=float(count_quad32)/num_points_on_graph;
        quad_33_ratio=float(count_quad33)/num_points_on_graph;
        quad_34_ratio=float(count_quad34)/num_points_on_graph;
        
        quad_41_ratio=float(count_quad41)/num_points_on_graph;
        quad_42_ratio=float(count_quad42)/num_points_on_graph;
        quad_43_ratio=float(count_quad43)/num_points_on_graph;
        quad_44_ratio=float(count_quad44)/num_points_on_graph;
        
        #store the quad ratio values in features list
        feature_list_5min.append(quad1_ratio)
        feature_name.append("std_quad1_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad2_ratio)
        feature_name.append("std_quad2_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad3_ratio)
        feature_name.append("std_quad3_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad4_ratio)
        feature_name.append("std_quad4_ratio_5min_"+str(num_5min_interval))
        
        
   
        feature_list_5min.append(quad_11_ratio)
        feature_name.append("std_quad11_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_12_ratio)
        feature_name.append("std_quad12_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad_13_ratio)
        feature_name.append("std_quad13_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_14_ratio)
        feature_name.append("std_quad14_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_21_ratio)
        feature_name.append("std_quad21_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_22_ratio)
        feature_name.append("std_quad22_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad_23_ratio)
        feature_name.append("std_quad23_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_24_ratio)
        feature_name.append("std_quad24_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad_31_ratio)
        feature_name.append("std_quad31_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_32_ratio)
        feature_name.append("std_quad32_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad_33_ratio)
        feature_name.append("std_quad33_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_34_ratio)
        feature_name.append("std_quad34_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad_41_ratio)
        feature_name.append("std_quad41_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_42_ratio)
        feature_name.append("std_quad42_ratio_5min_"+str(num_5min_interval))
        
        feature_list_5min.append(quad_43_ratio)
        feature_name.append("std_quad43_ratio_5min_"+str(num_5min_interval))
    
        feature_list_5min.append(quad_44_ratio)
        feature_name.append("std_quad44_ratio_5min_"+str(num_5min_interval))
        
        #print ("feature list for this 5 min interval is: " + str(feature_list_5min))
        #print("indexes are:                              " + str(range(len(feature_list_5min))))
        num_5min_interval=num_5min_interval+1;
        print ("rec_names with errornos records are : " + str(error_rec_names))
    
    dist_bw_feature=21
    start_ind=0
    end_ind=105
    feature_name_overall=[]
    #print (len(feature_list_5min))
    all_features_6_intervals=[]
    for i in range(0,21):
        name=str(feature_name[i])
        feature_name_overall.append(name[:-2])
        #print("feature_name is: " + str(name[:-2]))
        feature_index_5min=range(start_ind,end_ind+21,dist_bw_feature)
        one_feature_all_intervals=[]
        for val in feature_index_5min:
            #print("val is : "+str(val))
            feature_val=feature_list_5min[val]
            #print("feature_val at index : " + str(val)+" is: "+str(feature_val))
            one_feature_all_intervals.append(feature_val)
             
        all_features_6_intervals.append(one_feature_all_intervals)    
        start_ind=start_ind+1
        end_ind=end_ind+1
        feature_index_5min=range(start_ind,end_ind+21,dist_bw_feature)
        #print ("new indexes for feature index is: " + str(feature_index_5min))
    
    std_dev_all_features=[]
    for list_feature_vals in all_features_6_intervals:
        std_dev_5min_feature=np.std(list_feature_vals)
        std_dev_all_features.append(std_dev_5min_feature)    
       
    #for name,val in zip(feature_name_overall,std_dev_all_features):
        #print("name of feature is : " + str(name))
        #print("val of feature is : " + str(val))
    return all_features_6_intervals,std_dev_all_features,feature_name_overall
        ctm_array=[];
        dist_array=[];
       
        x_val_sodp,y_val_sodp,ctm_array,dist_array=nlm.calc_sodp_measures(rec_name,RR_sec, radius_array);
        ctm_list_list.append(ctm_array)
        dist_list_list.append(dist_array) 
#         ######### PLOTTING SODP for afib plots array ################
#           
#         if "n" in record:
#               
#             ####plot sodp and save fig ####
#             fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot for "+str(start_time)+"to"+str(end_time), 'b',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
#             fig_sodp.savefig(output_folder+"sodp_plot_"+record+"_"+str(start_time)+"to"+str(end_time)+".png")
#              
#         elif "p" in record:   
#         ####plot sodp and save fig ####
#             fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot for "+str(start_time)+"to"+str(end_time), 'r',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
#             fig_sodp.savefig(output_folder+"sodp_plot_"+record+"_"+str(start_time)+"to"+str(end_time)+".png")
#         
        ######### PLOTTING SODP for afib plots array ################
           
       
               
        ####plot sodp and save fig ####
        fig_sodp,plot_sodp=graphs.plotScatter(rec_name,x_val_sodp,y_val_sodp, "x[n+1]-x[n]", " x[n+2]-x[n+1] ", "SODP plot for "+str(start_time)+"to"+str(end_time), 'b',xlim_lo=-1, xlim_hi=1, ylim_lo=-1, ylim_hi=1,axline=1)
        fig_sodp.savefig(output_folder+"sodp_plot_"+record+"_"+str(start_time)+"to"+str(end_time)+".png")