Example #1
0
    def _manage_params(self):
        self._manage_files()
        mgr = read_manager.ReadManager(self.f_info, self.f_data, self.f_tags)
        self.set_param('sample_type', mgr.get_param('sample_type'))
        self.set_param('sampling_rate',
                       str(int(float(mgr.get_param('sampling_frequency')))))
        self.set_param('channel_names',
                       ';'.join(mgr.get_param('channels_names')))
        self.set_param('active_channels', self.get_param('channel_names'))
        self.set_param('channel_gains',
                       ';'.join(mgr.get_param('channels_gains')))
        self.set_param('channel_offsets',
                       ';'.join(mgr.get_param('channels_offsets')))

        self._samples = mgr.get_samples()
        self._tags = mgr.get_tags()
        self._ind = 0
        super(PyAmplifierFile, self)._manage_params()
Example #2
0
def montage_custom(mgr, chnls):
    '''apply custom montage to manager, by chnls'''
    indexes = []
    for chnl in chnls:
        index = mgr.get_param('channels_names').index(chnl)
        if index < 0:
            raise Exception("Montage - couldn`t channel: " + str(chnl))
        else:
            indexes.append(index)

    new_samples = get_montage(
        mgr.get_samples(),
        get_montage_matrix_custom(int(mgr.get_param('number_of_channels')),
                                  indexes))
    info_source = copy.deepcopy(mgr.info_source)
    tags_source = copy.deepcopy(mgr.tags_source)
    samples_source = read_data_source.MemoryDataSource(new_samples)
    return read_manager.ReadManager(info_source, samples_source, tags_source)
Example #3
0
def filter(mgr,
           wp,
           ws,
           gpass,
           gstop,
           analog=0,
           ftype='ellip',
           output='ba',
           unit='radians',
           use_filtfilt=False):
    if unit == 'radians':
        b, a = signal.iirdesign(wp, ws, gpass, gstop, analog, ftype, output)
    elif unit == 'hz':
        sampling = float(mgr.get_param('sampling_frequency'))
        try:
            wp = wp / sampling
            ws = ws / sampling
        except TypeError:
            wp = [i / sampling for i in wp]
            ws = [i / sampling for i in ws]

        b, a = signal.iirdesign(wp, ws, gpass, gstop, analog, ftype, output)
    if use_filtfilt:
        import filtfilt
        #samples_source = read_data_source.MemoryDataSource(mgr.get_samples(), False)
        for i in range(int(mgr.get_param('number_of_channels'))):
            print("FILT FILT CHANNEL " + str(i))
            mgr.get_samples()[i, :] = filtfilt.filtfilt(
                b, a,
                mgr.get_samples()[i])
        samples_source = read_data_source.MemoryDataSource(
            mgr.get_samples(), False)
    else:
        print("FILTER CHANNELs")
        filtered = signal.lfilter(b, a, mgr.get_samples())
        print("FILTER CHANNELs finished")
        samples_source = read_data_source.MemoryDataSource(filtered, True)

    info_source = copy.deepcopy(mgr.info_source)
    tags_source = copy.deepcopy(mgr.tags_source)
    new_mgr = read_manager.ReadManager(info_source, samples_source,
                                       tags_source)
    return new_mgr
Example #4
0
    def make_new_file(self, old_file):

        in_file = acquisition_helper.get_file_path(self.file_path, old_file)

        try:
            manager = read_manager.ReadManager(in_file + ".obci.xml",
                                               in_file + ".obci.raw",
                                               in_file + ".obci.tag")
        except IOError:
            self.logger.error("No such file or directory: {}".format(in_file))
            sys.exit(1)

        fs = int(float(manager.get_param("sampling_frequency")))
        data = manager.get_samples()
        self.logger.info(
            "START resampling: file: {}, old_fs = {} Hz, new_fs = {} Hz...".
            format(old_file, fs, self.new_fs))

        if not fs % self.new_fs == 0:
            self.logger.error(
                "WRONG new sampling frequency!!\n You can choose sampling frequency, which is the divisor of old sampling frequency"
            )
            sys.exit(0)
        else:
            sample_step = fs / self.new_fs

        new_data = np.array(
            [data[:, i] for i in range(0, data.shape[1], sample_step)]).T
        manager.set_samples(new_data, manager.get_param("channels_names"))
        manager.set_param("sampling_frequency", str(self.new_fs))
        self.logger.info(
            "FINISH resampling: file: {}, old_fs = {} Hz, new_fs = {} Hz".
            format(old_file, fs, self.new_fs))
        self.logger.info(
            "START saving data to {}...".format(in_file + "_resampling_to_" +
                                                str(self.new_fs)))
        manager.save_to_file(self.file_path,
                             in_file + "_resampling_to_" + str(self.new_fs))
        self.logger.info("FINISH saving new data")
Example #5
0
    def run(self):
        self.logger.info("START FDA...")

        f_name = self.config.get_param("data_file_name")
        f_dir = self.config.get_param("data_file_path")

        in_file = acquisition_helper.get_file_path(f_dir, f_name)

        filename = os.path.join(f_dir, f_name + ".obci")
        data = sp.signalParser(filename)

        fs = int(float(data.getSamplingFrequency()))

        mgr = read_manager.ReadManager(in_file + '.obci.xml',
                                       in_file + '.obci.raw',
                                       in_file + '.obci.tag')

        if self.use_channels is None:
            self.use_channels = data.getChannelList()
        if self.ignore_channels is not None:
            for i in self.ignore_channels:
                try:
                    self.use_channels.remove(i)
                except:
                    pass

        self.montage = self.config.get_param("montage")
        tmp = self.config.get_param("montage_channels")
        if len(tmp) > 0:
            self.montage_channels = tmp.split(';')
        else:
            self.montage_channels = []

        self.logger.info("USE CHANNELS: " + str(self.use_channels))
        self.logger.info("CHANNELS NAMES: " +
                         str(mgr.get_param('channels_names')))

        ## Get data and tags
        data.setMontage(self.montage_channels)
        Signal = data.getData(self.use_channels)
        trgTags = data.get_p300_tags()
        ntrgTags = data.get_not_p300_tags()

        print "Signal.shape[1]: ", Signal.shape[1]
        print "last trg: ", trgTags[-1]
        print "last ntrg: ", ntrgTags[-1]
        m = max([trgTags[-1], ntrgTags[-1]])
        # ?!?!?!?!?!?!?!?! Why blinks are <0
        trgTags = trgTags[trgTags > 0]
        ntrgTags = ntrgTags[ntrgTags > 0]
        trgTags = trgTags[trgTags < Signal.shape[1] - fs]
        ntrgTags = ntrgTags[ntrgTags < Signal.shape[1] - fs]
        print "last trg: ", trgTags[-1]
        print "last ntrg: ", ntrgTags[-1]

        target, nontarget = data.getTargetNontarget(Signal, trgTags, ntrgTags)

        ## Get params from file
        pPer = float(self.config.get_param("p_per"))
        nRepeat = int(self.config.get_param("n_repeat"))
        nMin = int(self.config.get_param("n_min"))
        nMax = int(self.config.get_param("n_max"))

        avrM_l = map(lambda x: int(x),
                     self.config.get_param("avr_m").split(';'))
        conN_l = map(lambda x: int(x),
                     self.config.get_param("con_n").split(';'))
        csp_dt_l = map(lambda x: float(x),
                       self.config.get_param("csp_dt").split(';'))
        csp_time_l = map(lambda x: float(x),
                         self.config.get_param("csp_time").split(';'))

        plotFlag = int(self.config.get_param("plot_flag"))
        debugFlag = int(self.config.get_param("debug_flag"))

        ## Define buffer
        buffer = 1.1 * fs
        self.logger.info("Computer buffer len: " + str(buffer))

        ## Make montage matrix
        conf = self.use_channels, self.montage, self.montage_channels
        self.montage_matrix = self._get_montage_matrix(
            conf[0], conf[1], conf[2], mgr.get_param('channels_names'))
        print "self.montage_matrix: ", self.montage_matrix

        channels = ";".join(self.use_channels)

        # Test all combination of parameters
        N = 0
        d = {}
        for avrM in avrM_l:
            for conN in conN_l:
                for csp_time in csp_time_l:
                    for dt in csp_dt_l:
                        d[N] = {
                            "avrM": avrM,
                            "conN": conN,
                            "csp_time": [csp_time, csp_time + dt]
                        }
                        print "d[%i] = " % N, d[N]
                        N += 1

        #################################
        ## CROSS CHECKING
        P_dict, dVal_dict = {}, {}
        l = np.zeros(N)
        for idxN in range(N):
            KEY = d[idxN].keys()
            for k in KEY:
                exec "{0}_tmp = {1}".format(k,
                                            d[idxN][k]) in globals(), locals()

            self.logger.info("Zestaw: {0} / {1}".format(idxN, N))
            self.logger.info(str(d[idxN]))

            csp = csp_time_tmp[0] * fs, csp_time_tmp[1] * fs

            # Crop signalas to csp_time : csp_time+csp_dt
            _target = target[:, :, csp[0]:csp[1]]
            _nontarget = nontarget[:, :, csp[0]:csp[1]]

            p300 = P300_train(channels, fs, avrM_tmp, conN_tmp, csp_time_tmp,
                              pPer)
            l[idxN] = p300.valid_kGroups(Signal, _target, _nontarget, 2)
            P_dict[idxN] = p300.getPWC()
            dVal_dict[idxN] = p300.getDValDistribution()

            if debugFlag:
                p300.saveDist2File("target_%i" % idxN, "nontarget_%i" % idxN)

            self.logger.info("Test score: " + str(l[idxN]))

        self.logger.info("Calibration passed")
        #################################

        if debugFlag:
            distributionDraw = P300_draw(fs)
            # Plot all d distributions
            for idx in range(N):
                dTarget, dNontarget = dVal_dict[idx]
                distributionDraw.plotDistribution(dTarget, dNontarget)

        #################################
        # Finding best

        self.logger.info("\n" * 5)
        self.logger.info("L: " + str(l))

        P, conN, avrM, csp_time = None, None, None, None
        BEST = -1
        arr = np.arange(len(l))
        for i in range(5):
            bestN = int(arr[l == l.min()][0])

            print "best_{0}: {1}".format(i, bestN)
            print "d[bestN]: ", d[bestN]
            print "l[bestN]: ", l.min()
            if (l.min() > 100) and (BEST == -1): BEST = bestN
            l[bestN] = l.max() - 1

        P, w, c = P_dict[BEST]
        dTarget, dNontarget = dVal_dict[BEST]
        pVal = st.scoreatpercentile(dNontarget, pPer)
        pdf = dNontarget

        avrM = d[BEST]["avrM"]
        conN = d[BEST]["conN"]
        csp_time = d[BEST]["csp_time"]

        cfg = {
            "csp_time": csp_time,
            "use_channels": ';'.join(self.use_channels),
            'avrM': avrM,
            'conN': conN,
            'pdf': pdf,
            "P": P,
            "w": w,
            "c": c,
            "montage": self.montage,
            "montage_channels": ';'.join(self.montage_channels),
            "buffer": buffer
        }

        f_name = self.config.get_param("fda_file_name")
        f_dir = self.config.get_param("fda_file_path")

        csp_helper.set_csp_config(f_dir, f_name, cfg)

        if plotFlag:
            ## Plotting best
            p300_draw = P300_draw()
            p300_draw.setCalibration(target, nontarget)
            p300_draw.setCSP(P)
            p300_draw.setTimeLine(conN, avrM, csp_time)
            p300_draw.plotSignal()
            #~ p300_draw.plotSignal_ds()

        self.logger.info("FDA classifier -- DONE")
        if not self.run_offline:
            self._run_next_scenario()
Example #6
0
def montage_custom_matrix(mgr, montage_matrix):
    new_samples = get_montage(mgr.get_samples(), montage_matrix)
    info_source = copy.deepcopy(mgr.info_source)
    tags_source = copy.deepcopy(mgr.tags_source)
    samples_source = read_data_source.MemoryDataSource(new_samples)
    return read_manager.ReadManager(info_source, samples_source, tags_source)
Example #7
0
def find_and_print(info_file, data_file, spare_memory=True):
    manager = read_manager.ReadManager(info_file, data_file, None)
    l = find_lost_samples(manager, spare_memory=spare_memory)
    print_result(l)
Example #8
0
        f['data'] = sys.argv[2]
    else:
        dr = '/media/windows/titanis/bci/projekty/eksperyment_mikolaj/dane_07_12_2010/201/'
        f_name = 'test2-Tue_Dec__7_14_03_55_2010'
        f = {
            'info': os.path.join(dr, f_name + '.obci.info'),
            'data': os.path.join(dr, f_name + '.obci.dat'),
            #'tags':os.path.join(dr, f_name+'.obci.tags')
        }
    try:
        spare_memory = int(sys.argv[3])
    except:
        spare_memory = True

    try:
        saw_name = sys.argv[4]
    except:
        saw_name = "DriverSaw"

    print("ANALYSE: " + str(f))
    manager = read_manager.ReadManager(
        f['info'],
        f['data'],
        None  #f['tags']
    )

    l = find_lost_samples(manager,
                          spare_memory=spare_memory,
                          saw_name=saw_name)
    print_result(l)
    def run(self):
        LOGGER.info("START FDA...")

        f_name = self.config.get_param("data_file_name")
        f_dir = self.config.get_param("data_file_path")
        in_file = acquisition_helper.get_file_path(f_dir, f_name)

        filename = os.path.join(f_dir, f_name + ".obci")
        data = sp.signalParser(filename)

        fs = int(float(data.getSamplingFrequency()))

        mgr = read_manager.ReadManager(in_file + '.obci.xml',
                                       in_file + '.obci.raw',
                                       in_file + '.obci.tag')

        if self.use_channels is None:
            self.use_channels = data.getChannelList()
        if self.ignore_channels is not None:
            for i in self.ignore_channels:
                try:
                    self.use_channels.remove(i)
                except:
                    pass

        self.montage = self.config.get_param("montage")
        tmp = self.config.get_param("montage_channels")
        if len(tmp) > 0:
            self.montage_channels = tmp.split(';')
        else:
            self.montage_channels = []

        LOGGER.info("USE CHANNELS: " + str(self.use_channels))
        LOGGER.info("CHANNELS NAMES: " + str(mgr.get_param('channels_names')))

        ## Get data and tags
        data.setMontage(self.montage_channels)
        Signal = data.getData(self.use_channels)
        trgTags = data.get_p300_tags()
        ntrgTags = data.get_not_p300_tags()

        target, nontarget = data.getTargetNontarget(Signal, trgTags, ntrgTags)

        ## Get params from file
        pVal = float(self.config.get_param("p_val"))
        nRepeat = int(self.config.get_param("n_repeat"))
        nMin = int(self.config.get_param("n_min"))
        nMax = int(self.config.get_param("n_max"))

        avrM_l = map(lambda x: int(x),
                     self.config.get_param("avr_m").split(';'))
        conN_l = map(lambda x: int(x),
                     self.config.get_param("con_n").split(';'))
        csp_dt_l = map(lambda x: float(x),
                       self.config.get_param("csp_dt").split(';'))
        csp_time_l = map(lambda x: float(x),
                         self.config.get_param("csp_time").split(';'))

        ## Define buffer
        buffer = 1.1 * fs
        LOGGER.info("Computer buffer len: " + str(buffer))

        ## Make montage matrix
        conf = self.use_channels, self.montage, self.montage_channels
        self.montage_matrix = self._get_montage_matrix(
            conf[0], conf[1], conf[2], mgr.get_param('channels_names'))
        print "self.montage_matrix: ", self.montage_matrix

        channels = ";".join(self.use_channels)

        # make sure that:
        # channels -- is in format like "P07;O1;Oz;O2"
        # fs -- is a number
        # avrM -- are int
        # conN -- are int
        # csp_time -- is a list of two float 0 < x < 1
        N = 0
        d, P_dict = {}, {}
        for avrM in avrM_l:
            for conN in conN_l:
                for csp_time in csp_time_l:
                    for dt in csp_dt_l:
                        d[N] = {
                            "avrM": avrM,
                            "conN": conN,
                            "csp_time": [csp_time, csp_time + dt]
                        }
                        print "d[%i] = " % N, d[N]
                        N += 1

        #################################
        ## CROSS CHECKING
        l = np.zeros(N)
        for idxN in range(N):
            KEY = d[idxN].keys()
            for k in KEY:
                #~ c = "{0} = {1}".format(k, d[idxN][k])
                #~ print c
                #~ exec(c)
                exec "{0}_tmp = {1}".format(k,
                                            d[idxN][k]) in globals(), locals()

            p300 = P300_train(channels, fs, avrM_tmp, conN_tmp, csp_time_tmp)
            l[idxN] = p300.valid_kGroups(Signal, target, nontarget, 2)
            P_dict[idxN] = p300.getPWC()

        #################################
        # Finding best

        print "\n" * 5
        print "L: ", l
        P, conN, avrM, csp_time = None, None, None, None
        BEST = -1
        arr = np.arange(len(l))
        for i in range(5):
            bestN = int(arr[l == l.max()])

            print "best_{0}: {1}".format(i, bestN)
            print "d[bestN]: ", d[bestN]
            print "l[bestN]: ", l.max()
            if (l.max() < 1000) and (BEST == -1): BEST = bestN
            l[bestN] = l.min() - 1

        print "best: ", BEST

        P, w, c = P_dict[BEST]
        avrM = d[BEST]["avrM"]
        conN = d[BEST]["conN"]
        csp_time = d[BEST]["csp_time"]
        cfg = {
            "csp_time": csp_time,
            "use_channels": ';'.join(self.use_channels),
            'pVal': pVal,
            'avrM': avrM,
            'conN': conN,
            "nRepeat": nRepeat,
            "P": P,
            "w": w,
            "c": c,
            "montage": self.montage,
            "montage_channels": ';'.join(self.montage_channels),
            "buffer": buffer
        }

        f_name = self.config.get_param("csp_file_name")
        f_dir = self.config.get_param("csp_file_path")
        ssvep_csp_helper.set_csp_config(f_dir, f_name, cfg)

        ## Plotting best
        p300_draw = P300_draw()
        p300_draw.setCalibration(target, nontarget, trgTags, ntrgTags)
        p300_draw.setCSP(P)
        p300_draw.setTimeLine(conN, avrM, csp_time)
        p300_draw.plotSignal()
        p300_draw.plotSignal_ds()

        LOGGER.info("FDA Calibration complete")
        if not self.run_offline:
            self._run_next_scenario()
Example #10
0
def gsr_dat_csv(files):
    for f in files:
        print("START GSR FOR " + str(f) +
              "#############################################################")
        csv = csv_manager.Writer(f['tags'] + '.gsr.csv',
                                 d=';',
                                 q=CCC.QUOTE_NONE)
        csv.write_row(
            ['id', 'block_index', 'condition', 'gsr', 'gsr-base', 'gsr/base'])
        mgr = read_manager.ReadManager(f['info'], f['data'], f['tags'])
        sig = mgr.get_samples()
        tags = mgr.get_tags(p_tag_type='word')
        sf = float(mgr.get_param("sampling_frequency"))
        gain = float(mgr.get_param('channels_gains')[0])
        offset = float(mgr.get_param('channels_offsets')[0])

        bs_tag = mgr.get_tags(p_tag_type='baseline')[0]
        bs_raw = mgr.get_samples(
            (bs_tag['start_timestamp'] + 7.0) * sf,
            (bs_tag['end_timestamp'] - bs_tag['start_timestamp']) * sf)[0]
        bs_unit = bs_raw * gain + offset
        bs_avg = np.average(bs_unit)
        print("GAIN / OFFSET / SF / BS_AVG / sig_len:")
        print(gain, offset, sf, bs_avg, len(sig[0]))

        curr_block = 0
        last_ind = 0
        start_ts = tags[0]['start_timestamp']
        prev_tag = tags[0]
        for i, t in enumerate(tags[1:]):
            if int(t['desc']['block_index']) != curr_block:
                print("How many tags?: " + str(i - last_ind))
                last_ind = i

                print("Signal to grab: from: " + str(start_ts) + "len: " +
                      str(prev_tag['end_timestamp'] - start_ts))
                signal_start = int(start_ts * sf)
                signal_len = int((prev_tag['end_timestamp'] - start_ts) * sf)
                print("Signal to grab in samples: from: " + str(signal_start) +
                      "len: " + str(signal_len))
                gsr = np.average(
                    mgr.get_samples(signal_start, signal_len)[0] * gain +
                    offset)
                print("GSR!!!!!!!!!!!!!!!!: " + str(gsr))
                print(
                    mgr.get_samples(signal_start, signal_len)[0] * gain +
                    offset)
                gsr_base = gsr - bs_avg
                gsrbase = gsr / bs_avg

                csv.write_row([
                    f['info'][f['info'].rfind('/') + 1:f['info'].find('.')],
                    t['desc']['block_index'], t['desc']['condition'], gsr,
                    gsr_base, gsrbase
                ])

                start_ts = t['start_timestamp']
                curr_block = int(t['desc']['block_index'])
            prev_tag = t

        csv.close()
Example #11
0
    def run(self):
        self.logger.info("START CSP...")
        f_name = self.config.get_param("data_file_name")
        f_dir = self.config.get_param("data_file_path")
        in_file = acquisition_helper.get_file_path(f_dir, f_name)
        mgr = read_manager.ReadManager(in_file + '.obci.xml',
                                       in_file + '.obci.raw',
                                       in_file + '.obci.tag')
        fs = int(float(mgr.get_param("sampling_frequency")))
        if self.use_channels is None:
            self.use_channels = mgr.get_param('channels_names')
        if self.ignore_channels is not None:
            for i in self.ignore_channels:
                try:
                    self.use_channels.remove(i)
                except:
                    pass

        self.logger.info("USE CHANNELS: " + str(self.use_channels))
        csp_time = [0.0, 0.7]
        data = p300.p300_train(in_file + '.obci',
                               self.use_channels,
                               fs,
                               self.montage_channels,
                               self.montage,
                               idx=1,
                               csp_time=csp_time)  #idx oznacza indeks na który
        new_tags = data.wyr()
        not_idx_tags = data.data.get_p300_tags(
            idx=1, rest=True,
            samples=False)  #Tutaj idx musi być -idx z linijki 11
        #Tagi pozostałych przypadków
        mean, left, right = data.get_mean(new_tags,
                                          m_time=csp_time,
                                          plot_mean=True)
        buffer_start = int(-csp_time[0] * fs)
        buffer_len = len(mean)
        self.logger.info("Computer buffer start / len: " + str(buffer_start) +
                         " / " + str(buffer_len))
        mean[:left] = 0
        mean[right:] = 0
        t_vec = data.show_mean_CSP(csp_time, new_tags)
        plt.plot(t_vec, mean, 'r-')
        plt.show()
        sr = 12  #Maksymalna liczba odcinków do uśrednienia; gdzieś do parametryzacji
        #targets = np.zeros([sr, len(new_tags)])
        #non_targets = np.zeros([sr, len(not_idx_tags)])
        #mu = np.zeros(sr)
        #sigma = np.zeros(sr)
        #for i in xrange(1, sr + 1):
        #x = data.get_n_mean(i, new_tags, csp_time, 0.05)
        #targets[i - 1, :], non_targets[i - 1, :], mu[i - 1], sigma[i - 1] = x
        cl, mu, sigma, mean, left, right = data.prep_classifier(
            sr, P_vectors=2, reg=1, mean_time=csp_time)
        q = data
        cfg = {
            'mu': mu,
            'sigma': sigma,
            'mean': mean,
            #'targets':targets,
            #'non_targets':non_targets,
            'q': q,
            'buffer_len': buffer_len,
            'buffer_start': buffer_start,
            'use_channels': ';'.join(self.use_channels),
            'montage': self.montage,
            'montage_channels': ';'.join(self.montage_channels),
            'left': left,
            'right': right,
            'cl': cl,
            'a_features': data.a_features,
            'bands': data.bands
        }

        f_name = self.config.get_param("csp_file_name")
        f_dir = self.config.get_param("csp_file_path")
        ssvep_csp_helper.set_csp_config(f_dir, f_name, cfg)
        self.logger.info("CSP DONE")
        if not self.run_offline:
            self._run_next_scenario()
Example #12
0
def run(in_file,
        use_channels,
        ignore_channels,
        montage,
        montage_channels,
        dec_count,
        plot_stats=True,
        context=ctx.get_dummy_context('UgmBlinkingConnection')):
    logger = context['logger']
    mgr = read_manager.ReadManager(in_file + '.obci.xml',
                                   in_file + '.obci.raw',
                                   in_file + '.obci.tag')
    to_frequency = int(float(mgr.get_param("sampling_frequency")))
    if use_channels is None:
        use_channels = mgr.get_param('channels_names')
    if ignore_channels is not None:
        for i in ignore_channels:
            try:
                use_channels.remove(i)
            except:
                pass

    exp_info = mgr.get_tags('experimentInfo')[0]['desc']
    to_signal = float(exp_info['target_time'])
    freqs = [int(i) for i in exp_info['all_freqs'].split(';')]

    data = sp.signalParser(in_file + '.obci')
    train_tags = data.get_train_tags(trial_separator_name='diodes',
                                     screen=True)
    logger.info("Run csp with: use_channels: " + str(use_channels) +
                " motage: " + str(montage) + " montage_channels: " +
                str(montage_channels))
    q = csp.modCSP(in_file + '.obci', freqs, use_channels, montage,
                   montage_channels)
    q.start_CSP(to_signal,
                to_frequency,
                baseline=False,
                filt='cheby',
                method='regular',
                train_tags=train_tags)  #liczenie CSP
    time = pylab.linspace(1, to_signal, 7)
    t1, t2 = q.time_frequency_selection(to_frequency,
                                        train_tags,
                                        time=time,
                                        frequency_no=dec_count,
                                        plt=False)

    logger.info("Got times t1: " + str(t1) + " and t2: " + str(t2))
    logger.info("Set buffer time:" + str(t2))
    value, mu, sigma, means, stds, out_top, out_bottom = q.count_stats(
        to_signal, to_frequency, train_tags,
        plt=plot_stats)  #Liczenie statystyk
    logger.info("For freqs: " + str(freqs))
    logger.info("Got means: " + str(means))

    pairs = zip(means, freqs)
    pairs.sort(reverse=True)
    logger.info("Sorted: " + str(pairs))
    best = [i[1] for i in pairs]
    best_means = [i[0] for i in pairs]
    logger.info("Best freqs: " + str(best))
    logger.info("dec_count: " + str(dec_count))
    logger.info("freqs: " + str(best[:dec_count]))
    logger.info("Finished CSP with stats:")
    logger.info(str(value) + " / " + str(mu) + " / " + str(sigma))
    logger.info("And q:")
    logger.info(str(q))

    d = {
        'value': value,
        'mu': mu,
        'sigma': sigma,
        'q': q,
        'freqs': ';'.join([str(i) for i in best[:dec_count]]),
        'all_freqs': ';'.join([str(i) for i in best]),
        'all_means': ';'.join([str(i) for i in best_means]),
        'dec_count': dec_count,
        'buffer': t2,
        'use_channels': ';'.join(use_channels),
        'montage': montage,
        'montage_channels': ';'.join(montage_channels),
        'out_top': out_top,
        'out_bottom': out_bottom
    }
    return d