Exemplo n.º 1
0
 def test_get_get_file_list_suffix(self):
     dir_data = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data')
     file_list = get_file_list(dir_data, extensions=[".json", ".tsv"])
     for item in file_list:
         if item.endswith(".json") or item.endswith(".tsv"):
             continue
         raise HedFileError("BadFileType", "get_event_files expected only .html or .js files", "")
Exemplo n.º 2
0
 def _set_sidecar_dict(self):
     """ Get a dictionary of BidsSidecarFile objects with underlying Sidecar objects set"""
     files = get_file_list(self.root_path, name_suffix='_events', extensions=['.json'])
     file_dict = {}
     for file in files:
         file_dict[os.path.abspath(file)] = BidsSidecarFile(os.path.abspath(file), set_contents=True)
     self.sidecar_dict = file_dict
Exemplo n.º 3
0
 def _set_event_file_dict(self):
     """ Get a dictionary of BidsEventFile objects with underlying EventInput objects not set"""
     files = get_file_list(self.root_path, name_suffix='_events', extensions=['.tsv'])
     file_dict = {}
     for file in files:
         file_dict[os.path.abspath(file)] = BidsEventFile(file)
     self.events_dict = file_dict
Exemplo n.º 4
0
 def test_make_combined_dicts(self):
     files_bids = get_file_list(self.bids_dir,
                                extensions=[".tsv"],
                                name_suffix="_events")
     file_dict = make_file_dict(files_bids)
     dicts_all1, dicts1 = make_combined_dicts(file_dict)
     self.assertTrue(isinstance(dicts_all1, ColumnDict),
                     "make_combined_dicts should return a ColumnDict")
     self.assertTrue(
         isinstance(dicts1, dict),
         "make_combined_dicts should also return a dictionary of file names"
     )
     self.assertEqual(
         len(dicts1), 6,
         "make_combined_dicts should return correct number of file names")
     self.assertEqual(
         len(dicts_all1.categorical_info), 10,
         "make_combined_dicts should return right number of entries")
     dicts_all2, dicts2 = make_combined_dicts(
         file_dict, skip_cols=["onset", "duration", "sample"])
     self.assertTrue(isinstance(dicts_all2, ColumnDict),
                     "make_combined_dicts should return a ColumnDict")
     self.assertTrue(
         isinstance(dicts2, dict),
         "make_combined_dicts should also return a dictionary of file names"
     )
     self.assertEqual(
         len(dicts2), 6,
         "make_combined_dicts should return correct number of file names")
     self.assertEqual(
         len(dicts_all2.categorical_info), 7,
         "make_combined_dicts should return right number of entries")
Exemplo n.º 5
0
 def test_remap_a(self):
     key_cols = ['type']
     target_cols = ['event_type', 'task_role', 'letter']
     key_map = KeyMap(key_cols, target_cols, 'my_name')
     key_map.update(self.stern_map_path)
     event_file_list = get_file_list(self.data_dir,
                                     name_prefix='sternberg',
                                     name_suffix="_events",
                                     extensions=[".tsv"])
     for file in event_file_list:
         df_new, missing = key_map.remap(file)
         self.assertFalse(missing)
Exemplo n.º 6
0
def get_key_counts(root_dir, skip_cols=None):
    file_list = get_file_list(root_dir,
                              name_suffix="_events",
                              extensions=[".tsv"])
    count_dicts = {}
    for file in file_list:
        dataframe = get_new_dataframe(file)
        for col_name, col_values in dataframe.iteritems():
            if skip_cols and col_name in skip_cols:
                continue
            update_dict_counts(count_dicts, col_name, col_values)
    return count_dicts
Exemplo n.º 7
0
    def test_get_file_list_files(self):
        dir_pairs = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/hed_pairs/prologue_tests')
        test_files = [name for name in os.listdir(dir_pairs) if os.path.isfile(os.path.join(dir_pairs, name))]
        file_list1 = get_file_list(dir_pairs)
        for file in file_list1:
            if os.path.basename(file) in test_files:
                continue
            raise HedFileError("FileNotFound", f"get_file_list should have found file {file}", "")

        for file in test_files:
            if os.path.join(dir_pairs, file) in file_list1:
                continue
            raise HedFileError("FileShouldNotBeFound", f"get_event_files should have not have found file {file}", "")
Exemplo n.º 8
0
 def test_get_file_list_case(self):
     dir_data = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/sternberg')
     file_list = get_file_list(dir_data, name_prefix='STERNBerg', extensions=[".Tsv"])
     for item in file_list:
         filename = os.path.basename(item)
         self.assertTrue(filename.startswith('sternberg'))