Beispiel #1
0
    def create_local_dir_if_not_exists(self):
        '''
        Create a local directory to store testing files and return it.

        The directory path is also written to self.local_test_dir
        '''
        self.local_test_dir = create_local_temp_dir(self.shortname)
        return self.local_test_dir
    def create_local_dir_if_not_exists(self):
        '''
        Create a local directory to store testing files and return it.

        The directory path is also written to self.local_test_dir
        '''
        self.local_test_dir = create_local_temp_dir(
            self.shortname, directory=os.environ.get("NEO_TEST_FILE_DIR", None))
        return self.local_test_dir
    def test_Riehle_et_al_97_UE(self):
        url = "http://raw.githubusercontent.com/ReScience-Archives/Rostami-" \
              "Ito-Denker-Gruen-2017/master/data"
        shortname = "unitary_event_analysis_test_data"
        local_test_dir = create_local_temp_dir(shortname)
        files_to_download = ["extracted_data.npy", "winny131_23.gdf"]
        context = ssl._create_unverified_context()
        for filename in files_to_download:
            url_file = "{url}/{filename}".format(url=url, filename=filename)
            dist = urlopen(url_file, context=context)
            localfile = os.path.join(local_test_dir, filename)
            with open(localfile, 'wb') as f:
                f.write(dist.read())

        # load spike data of figure 2 of Riehle et al 1997
        spiketrain = self.load_gdf2Neo(os.path.join(local_test_dir,
                                                    "winny131_23.gdf"),
                                       trigger='RS_4',
                                       t_pre=1799 * pq.ms,
                                       t_post=300 * pq.ms)

        # calculating UE ...
        winsize = 100 * pq.ms
        binsize = 5 * pq.ms
        winstep = 5 * pq.ms
        pattern_hash = [3]
        t_start = spiketrain[0][0].t_start
        t_stop = spiketrain[0][0].t_stop
        t_winpos = ue._winpos(t_start, t_stop, winsize, winstep)
        significance_level = 0.05

        UE = ue.jointJ_window_analysis(spiketrain,
                                       binsize,
                                       winsize,
                                       winstep,
                                       pattern_hash,
                                       method='analytic_TrialAverage')
        # load extracted data from figure 2 of Riehle et al 1997
        extracted_data = np.load(os.path.join(local_test_dir,
                                              'extracted_data.npy'),
                                 encoding='latin1',
                                 allow_pickle=True).item()
        Js_sig = ue.jointJ(significance_level)
        sig_idx_win = np.where(UE['Js'] >= Js_sig)[0]
        diff_UE_rep = []
        y_cnt = 0
        for trial_id in range(len(spiketrain)):
            trial_id_str = "trial{}".format(trial_id)
            indices_unique = np.unique(UE['indices'][trial_id_str])
            if len(indices_unique) > 0:
                # choose only the significant coincidences
                indices_unique_significant = []
                for j in sig_idx_win:
                    significant = indices_unique[np.where(
                        (indices_unique * binsize >= t_winpos[j])
                        & (indices_unique * binsize < t_winpos[j] + winsize))]
                    indices_unique_significant.extend(significant)
                x_tmp = np.unique(indices_unique_significant) * \
                    binsize.magnitude
                if len(x_tmp) > 0:
                    ue_trial = np.sort(extracted_data['ue'][y_cnt])
                    diff_UE_rep = np.append(diff_UE_rep, x_tmp - ue_trial)
                    y_cnt += +1
        shutil.rmtree(local_test_dir)
        np.testing.assert_array_less(np.abs(diff_UE_rep), 0.3)