Skip to content

Commit 2af0d01

Browse files
committed
Moved the bids-specific tools to a bids subdirectory and started writing tests
1 parent b4927fa commit 2af0d01

32 files changed

Lines changed: 2215 additions & 37 deletions

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
- name: Lint with flake8
3636
run: |
3737
# stop the build if there are Python syntax errors or undefined names
38-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=hedtools/hed/tools/*
38+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3939
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
40-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=hedtools/hed/tools/*
40+
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4141
4242
- name: Test with unittest
4343
run: |

hedtools/hed/tools/bids/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import json
3+
from hed.tools.data_util import get_new_dataframe
4+
from hed.schema.hed_schema_file import load_schema_version
5+
from hed.tools.bids.bids_event_files import BidsEventFiles
6+
7+
8+
class BidsDataset:
9+
"""Represents a bids dataset."""
10+
11+
def __init__(self, root_path):
12+
self.root_path = os.path.abspath(root_path)
13+
self.dataset_description = {}
14+
self.participants = []
15+
self.hed_schema = None
16+
self._load_info()
17+
self.event_files = BidsEventFiles(root_path)
18+
19+
def _load_info(self):
20+
part_path = os.path.join(self.root_path, "participants.tsv")
21+
self.participants = get_new_dataframe(part_path)
22+
desc_path = os.path.join(self.root_path, "dataset_description.json")
23+
with open(desc_path, "r") as fp:
24+
self.dataset_description = json.load(fp)
25+
hed = self.dataset_description.get("HEDVersion", None)
26+
if isinstance(hed, str):
27+
self.hed_schema = load_schema_version(xml_version_number=hed)
28+
29+
30+
if __name__ == '__main__':
31+
path = 'D:\\Research\\HED\\hed-examples\\datasets\\eeg_ds003654s'
32+
bids = BidsDataset(path)

hedtools/hed/tools/bids_dataset_summary.py renamed to hedtools/hed/tools/bids/bids_dataset_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from hed.tools.bids_event_files import BidsEventFiles
2+
from hed.tools.bids.bids_event_files import BidsEventFiles
33

44
class BidsDatasetSummary():
55

hedtools/hed/tools/bids_event_file.py renamed to hedtools/hed/tools/bids/bids_event_file.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
2-
from bids_file import BidsFile
32
from hed.models.events_input import EventsInput
3+
from hed.tools.bids.bids_file import BidsFile
44

55

66
class BidsEventFile(BidsFile):
@@ -19,7 +19,12 @@ def set_contents(self):
1919
name=os.path.abspath(self.file_path))
2020

2121
def set_sidecars(self, sidecars):
22-
self.sidecars = sidecars
22+
if sidecars is None:
23+
self.sidecars = []
24+
elif not isinstance(sidecars, list):
25+
self.sidecars = [sidecars]
26+
else:
27+
self.sidecars = sidecars
2328

2429
def __str__(self):
2530
my_str = super().__str__()

hedtools/hed/tools/bids_event_files.py renamed to hedtools/hed/tools/bids/bids_event_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22
from hed.errors.error_reporter import get_printable_issue_string
33
from hed.schema.hed_schema_file import load_schema
4-
from hed.tools.bids_event_file import BidsEventFile
5-
from hed.tools.bids_sidecar_file import BidsSidecarFile
4+
from hed.tools.bids.bids_event_file import BidsEventFile
5+
from hed.tools.bids.bids_sidecar_file import BidsSidecarFile
66
from hed.models.events_input import EventsInput
77
from hed.tools.io_util import get_dir_dictionary, get_file_list, get_path_components
88
from hed.validator.hed_validator import HedValidator
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from hed.tools.bids_util import parse_bids_filename
2+
from hed.tools.bids.bids_util import parse_bids_filename
33
from hed.tools.io_util import get_file_list
44

55

hedtools/hed/tools/bids_sidecar_file.py renamed to hedtools/hed/tools/bids/bids_sidecar_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from hed.models.sidecar import Sidecar
3-
from hed.tools.bids_file import BidsFile
3+
from hed.tools.bids.bids_file import BidsFile
44

55

66
class BidsSidecarFile(BidsFile):

0 commit comments

Comments
 (0)