Exemplo n.º 1
0
 def __init__(self, filename):
     self.file = HDFArray(filename)
     self.eeg = self.file.getChannelTable('EEG')[1]
     self.ecg = self.file.getChannelTable('ECG')[1]
     self.fd = self.file.getChannelTable('FD')[1]
     self.pnvm = self.file.getChannelTable('PNVM')[1]
     self.track = self.file.getChannelTable('TRACK_MARKERS')[1]
     self.count_stimuls = 0
     self.count_click = 0
     for i in range(len(self.track)):
         if (self.track[i][1] == 16000):
             self.count_stimuls += 1
         elif (self.track[i][1] == 2):
             self.count_click += 1
     xy = self.__eval_max_peaks_fd_channel()
     self.x_fd_peaks = xy[0]
     self.y_fd_peaks = xy[1]
     self.intervals = []
     self.__eval_intervals()
     self.file.close()
Exemplo n.º 2
0
#%%
import numpy as np
import pandas as pd
import os
from HDF.HDFData import HDFArray
import math

# %%

# Берем первый файл данных
file = HDFArray('dataset/0.h5')
# Достаем таблицу трекера
table_track = file.getChannelTable('TRACK_MARKERS')
# Выделяем маркеры трекера
track_markers_columns = table_track[0]
# Выделяем массивы данных трекера
track_markers_data = table_track[1]

# %%
track_filter = []
for i in range(len(track_markers_data)):
    if (track_markers_data[i][1] == 2):
        track_filter.append(track_markers_data[i])
    elif (i != len(track_markers_data) - 1 and track_markers_data[i][1] == 50
          and (track_markers_data[i + 1][1] != 50)):
        track_filter.append(track_markers_data[i])
    elif (track_markers_data[i][1] == 0):
        track_filter.append(track_markers_data[i])
    elif (track_markers_data[i][1] == 16000):
        track_filter.append(track_markers_data[i])
    elif (track_markers_data[i][1] - track_markers_data[i][1] % 10 == 1000):
Exemplo n.º 3
0
filteredPath = settings["paths"]["filtered"]

# опытным путем пришел к выводу, что данных номеров файлов нет среди данных
ban_files = [366, 269, 345, 344, 326, 325]
#for i in range(245, 368):
#    if (i not in ban_files):
#        print("id_files: ", i, "\nkeys: ", HDFArray("RawData/"+str(i) + '.h5').ListChannels().keys())

# %%
true_keys = ['EEG', 'TRACK_MARKERS', 'ECG', 'FD', 'PNVM']
all_files = 368 - 245 - len(ban_files)
good_files = 0
files = []
for i in range(245, 368):
    if (i not in ban_files):
        list_keys = HDFArray(path + str(i) + '.h5').ListChannels().keys()
        k = 0
        for key in true_keys:
            if (key not in list_keys):
                break
            else:
                k += 1
        if (k == len(true_keys)):
            files.append(str(i) + ".h5")
            good_files += 1
            print('file good of ', i, '.h5')
print('all files = ', all_files)
print("all good files = ", good_files)

# %%
import shutil
Exemplo n.º 4
0
class FileAnalyzer:
    def __init__(self, filename):
        self.file = HDFArray(filename)
        self.eeg = self.file.getChannelTable('EEG')[1]
        self.ecg = self.file.getChannelTable('ECG')[1]
        self.fd = self.file.getChannelTable('FD')[1]
        self.pnvm = self.file.getChannelTable('PNVM')[1]
        self.track = self.file.getChannelTable('TRACK_MARKERS')[1]
        self.count_stimuls = 0
        self.count_click = 0
        for i in range(len(self.track)):
            if (self.track[i][1] == 16000):
                self.count_stimuls += 1
            elif (self.track[i][1] == 2):
                self.count_click += 1
        xy = self.__eval_max_peaks_fd_channel()
        self.x_fd_peaks = xy[0]
        self.y_fd_peaks = xy[1]
        self.intervals = []
        self.__eval_intervals()
        self.file.close()

    def __eval_max_peaks_fd_channel(self):
        count_diff_peaks = 2
        _max, _min = pkd.peakdetect(self.fd, None, 50, 50)
        xm = [p[0] for p in _max]
        ym = [p[1] for p in _max]
        if (abs(self.count_stimuls - len(xm)) > count_diff_peaks):
            return xm, ym, 1
        else:
            diff = abs(len(xm) - self.count_stimuls)
            if (len(xm) > self.count_stimuls):
                xm = xm[:-diff]
                ym = ym[:-diff]
            elif (len(xm) < self.count_stimuls):
                self.count_stimuls -= diff
        return [xm, ym]

    def get_max_peaks_fd_channel(self):
        return [self.x_fd_peaks, self.y_fd_peaks]

    def plot_fd_channel(self, a = None, b = None):
        if (a is None or b is None):
            plt.plot(self.fd)
            plt.show()
        else:
            plt.plot(range(a,b), self.fd[a:b])
            plt.show()

    def get_count_synchrostimuls(self):
        return self.count_stimuls

    def get_count_click(self):
        return self.count_click

    def is_good_file(self):
        if (self.count_stimuls != len(self.x_fd_peaks)):
            return False
        return True
    
    def get_data_channels(self):
        return [self.eeg, self.ecg, self.pnvm, self.fd]

    def get_history(self):
        for i in self.track:
            if (i[1] == 16000):
                print('start')
            elif (i[1] - i[1]%10 == 1000):
                print('pos_obj = ', i[2], i[3])
            elif (i[1] == 2):
                print('click')
            elif (i[1] == 0):
                print('clear and stop')
                print('clear_obj = ', i[2], i[3])

    def __get_interval(self, a, b):
        obj_pos = [self.track[a][2],self.track[a][3]]
        a = a + 1
        int_eeg = self.eeg[a:b]
        int_ecg = self.ecg[a:b]
        int_pnvm = self.pnvm[a:b]
        int_fd = self.fd[a:b]
        int_track = self.track[a:b]
        return IntervalExperiment(obj_pos,int_eeg, int_ecg,int_pnvm, int_fd, int_track)

    def __eval_intervals(self):
        count_stim = self.count_stimuls
        stimuls = []
        for i in range(len(self.track)):
            if (self.track[i][1] == 16000):
                stimuls.append(i)
                count_stim -= 1
            elif (self.track[i][1] == 2 and count_stim == 0):
                stimuls.append(i)
        for i in range(1, len(stimuls)-1):
            interval = self.__get_interval(stimuls[i]-1, stimuls[i+1]-1)
            self.intervals.append(interval)

    def get_intervals(self):
        return self.intervals
    
    def get_min_length_intervals(self):
        min_length_interval = self.intervals[0].get_length()
        for interval in self.intervals:
            if (interval.get_length() < min_length_interval):
                min_length_interval = interval.get_length()
        #print('min length interval = ', min_length_interval)
        return min_length_interval

    def trim_intervals_and_save(self,path, id_begin_interval, min_length_interval):
        _id = id_begin_interval
        y = []
        for interval in self.intervals:
            if (interval.is_good()):
                interval.trim(0, min_length_interval)
                filename = path + str(_id) + '.csv'
                interval.save_to_csv(filename)
                characteristics = interval.get_characteristics()
                y.append(np.array([_id, characteristics[0], characteristics[1]]))
                _id += 1
        return np.array(y)