Skip to content

Commit b26f6b7

Browse files
authored
Merge pull request INT-NIT#162 from sifaoufatai/clean-branch
Improve documentation: add structured descriptions to each module
2 parents 2808277 + 7cc49c8 commit b26f6b7

27 files changed

+382
-135
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ Thumbs.db
5656
*~
5757

5858
# Fichiers temporaires à ignorer
59-
BIDSTools/fff.json
60-
BIDSTools/ffffff.json
61-
BIDSTools/fff.CSV
59+
BIDSTools/dev_tests/fff.json
60+
BIDSTools/dev_tests/ffffff.json
61+
BIDSTools/dev_tests/fff.CSV

BIDSTools/BidsDatatype.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
"""
2-
BIDSTools/BidsDatatype.py, this file is used to load data types from a YAML file.
3-
this module aim to load all the data types defined by the BIDS standard. and provide a function to retrieve the value of a specific data type based on its name."""
4-
import yaml
2+
BidsDatatype.py
53
4+
This module loads and manages data types defined by the BIDS (Brain Imaging Data Structure) standard.
5+
It provides utilities to retrieve data type values from a YAML schema and facilitates working with BIDS-compliant datasets.
66
7-
def _load_data_types(yaml_path="ressources/schema/objects/datatypes.yaml"):
8-
"""
9-
Load data types from a YAML file.
7+
Main Features:
8+
- Loads all BIDS data types from a YAML configuration file.
9+
- Provides access to data type names and values.
10+
- Facilitates lookup of data type values by name.
1011
11-
Args:
12-
yaml_path (str): The path to the YAML file containing data type data.
12+
Typical Usage:
13+
from BIDSTools.BidsDatatype import DataTypes
14+
datatypes = DataTypes()
15+
value = datatypes.get_data_type_value("anat")
16+
17+
Refer to the BIDS specification for more details on data type definitions.
18+
"""
19+
import yaml
20+
from BIDSTools.resource_paths import DATATYPES_YAML
21+
from BIDSTools.helper import load_yaml_file
1322

14-
Returns:
15-
dict: A dictionary containing data type data.
16-
"""
17-
with open(yaml_path, 'r') as file:
18-
data_types_data = yaml.safe_load(file)
19-
return data_types_data
2023

2124

2225
class DataTypes:
2326
def __init__(self):
2427
"""
2528
Initialize a DataTypes object and load data types from a YAML file.
2629
"""
27-
self.data_types = _load_data_types()
30+
self.data_types = load_yaml_file(DATATYPES_YAML)
2831

2932
def get_data_type_value(self, data_type_name):
3033
"""

BIDSTools/BidsDirectoryStructure.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
"""
2-
this module aim to load all all the directories defined by the BIDS standard, their level and their details
2+
BidsDirectoryStructure.py
3+
4+
This module loads and manages directory structures defined by the BIDS (Brain Imaging Data Structure) standard.
5+
It provides utilities to retrieve, inspect BIDS directory structures .
6+
7+
Main Features:
8+
- Loads all BIDS directories and their attributes from a YAML configuration file.
9+
- Provides access to directory names, levels, and requirements.
10+
- Facilitates validation and inspection of directory structures for BIDS compliance.
11+
12+
Typical Usage:
13+
from BIDSTools.BidsDirectoryStructure import DirectoryStructure
14+
ds = DirectoryStructure()
15+
print(ds.all_directory)
16+
17+
Refer to the BIDS specification for directory structure guidelines.
318
"""
419

520
from pathlib import Path
621
import yaml
722
import BIDSTools.helper as helper
23+
from resource_paths import DIRECTORIES_YAML
824

925

1026
class DirectoryStructure:
1127
def __init__(self):
1228
"""
1329
Initialize a DirectoryStructure object with default parameters.
1430
"""
15-
self.relative_path = "ressources/schema/rules/directories.yaml"
31+
self.relative_path = DIRECTORIES_YAML
1632
self.entity_directory = []
1733
self.all_directory = None
1834
self.value_directory = None

BIDSTools/BidsEmptyRepositoryGenerator.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
"""BIDS Empty Repository Generator. This module generates an empty BIDS repository structure."""
1+
"""
2+
BidsEmptyRepositoryGenerator.py
3+
4+
This module generates an empty BIDS (Brain Imaging Data Structure) repository structure.
5+
It creates the required directory .
6+
7+
8+
9+
Refer to the BIDS specification for repository initialization guidelines.
10+
"""
211
import sys
312
from BIDSTools.Createfile import CreatFile
413
from BIDSTools.Createdirectory import Createdirectory

BIDSTools/BidsEntity.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
""" this module aim to load all all the entities defined by the BIDS standard """
2-
import yaml
1+
"""
2+
BidsEntity.py
3+
4+
This module loads and manages entities defined by the BIDS (Brain Imaging Data Structure) standard.
5+
It provides utilities to retrieve entity names and details .
6+
37
48
9+
"""
10+
import yaml
11+
from BIDSTools.resource_paths import ENTITIES_YAML
12+
from BIDSTools.helper import load_yaml_file
13+
514
class Entity:
615
def __init__(self):
716
"""
817
Initialize an Entity object and load entities from a YAML file.
918
"""
10-
self.entities = self._load_entities()
19+
self.entities = load_yaml_file(ENTITIES_YAML)
1120

12-
def _load_entities(self, yaml_path="ressources/schema/objects/entities.yaml"):
13-
"""
14-
Load entities from a YAML file.
15-
16-
Args:
17-
yaml_path (str): The path to the YAML file containing entity data.
1821

19-
Returns:
20-
dict: A dictionary containing entity data.
21-
"""
22-
with open(yaml_path, 'r') as file:
23-
entities_data = yaml.safe_load(file)
24-
return entities_data
2522

2623
def get_entity_name(self, entity_name):
2724
"""

BIDSTools/BidsFilestructure.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1+
"""
2+
BidsFilestructure.py
3+
4+
This module loads and manages file structures defined by the BIDS (Brain Imaging Data Structure) standard.
5+
It provides utilities to retrieve, inspect, and validate BIDS file structures from YAML schemas.
6+
7+
Main Features:
8+
- Loads all BIDS file structure rules from YAML configuration files.
9+
- Provides access to file names, directory levels, and file details.
10+
- Facilitates validation and inspection of file structures for BIDS compliance.
11+
12+
Typical Usage:
13+
from BIDSTools.BidsFilestructure import FileStructure
14+
fs = FileStructure()
15+
print(fs.all_files)
16+
17+
Refer to the BIDS specification for file structure guidelines.
18+
"""
119

220
import yaml
321

422
import os
5-
23+
from BIDSTools.resource_paths import CORE_FILES_YAML, DIRECTORIES_YAML, FILES_YAML, TABLES_YAML
624

725
class FileStructure:
8-
def __init__(self, relative_path="ressources/schema/rules/files/common/core.yaml"):
26+
def __init__(self, relative_path=CORE_FILES_YAML):
927
"""
1028
Initialize a FileStructure object with a relative path to a YAML file.
1129
@@ -27,7 +45,7 @@ def get_all_files(self):
2745
"""
2846

2947
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
30-
'ressources/schema/objects/files.yaml'), 'r') as file:
48+
FILES_YAML), 'r') as file:
3149

3250
file_rules = yaml.safe_load(file)
3351
if file_rules:
@@ -62,7 +80,7 @@ def get_detail(self):
6280
self.get_all_files()
6381
self.get_all_files_detail(self.relative_path)
6482
self.get_all_files_detail(os.path.join(os.path.dirname(os.path.abspath(__file__)),
65-
"ressources/schema/rules/files/common/tables.yaml"))
83+
TABLES_YAML))
6684
return self
6785

6886
def get_detail_for_file(self, file_name):

BIDSTools/BidsModality.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1-
""" this module aim to load all all the modalities defined by the BIDS standard so that we can get the value of a specific modality based on its name."""
1+
"""
2+
BidsModality.py
3+
4+
This module provides functionality to load and manage all modalities defined by the BIDS (Brain Imaging Data Structure) standard.
5+
It enables retrieval of modality values based on their names, using a YAML schema as the source of truth for available modalities.
6+
7+
Main Features:
8+
- Loads BIDS modalities from a YAML configuration file.
9+
- Provides access to modality names and details.
10+
- Facilitates lookup of modality information by name.
11+
12+
Typical Usage:
13+
modality = Modality()
14+
available_modalities = modality.modalities
15+
details = modality.modality_details
16+
Example:
17+
modality = Modality()
18+
print("Available Modalities:", modality.modalities)
19+
print("Modality Details:", modality.modality_details)
20+
21+
22+
See the BIDS specification for more details on modality definitions.
23+
"""
224

325
import yaml
426
import os
527

6-
28+
from BIDSTools.resource_paths import MODALITIES_YAML
29+
from BIDSTools.helper import load_yaml_file
730
class Modality:
831
def __init__(self, relative_path=None):
932
"""
@@ -17,7 +40,7 @@ def __init__(self, relative_path=None):
1740
# Get the directory where the current script is located
1841
script_dir = os.path.dirname(os.path.abspath(__file__))
1942
# Construct the absolute path to modalities.yaml
20-
relative_path = os.path.join(script_dir, "ressources", "schema", "objects", "modalities.yaml")
43+
relative_path = os.path.join(script_dir, MODALITIES_YAML)
2144

2245
self.relative_path = relative_path
2346
self.modalities = []

BIDSTools/Createdirectory.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
"""
2-
this module contains the Createdirectory class that creates directory layout based on BIDS directory structure
2+
Createdirectory.py
3+
4+
This module defines the Createdirectory class, which automates the creation of directory layouts compliant with the BIDS (Brain Imaging Data Structure) directory structure.
5+
6+
Main Features:
7+
- Generates a BIDS-compliant directory tree for neuroimaging datasets.
8+
- Supports customization of subject ID, session ID, and modality.
9+
- Integrates with other BIDSTools components for file and entity management.
10+
11+
Typical Usage:
12+
creator = Createdirectory(output_path, sub_id=1, session_id=1, modality="micr")
13+
creator.create_directories()
14+
Example of outuput:
15+
sub-1
16+
└─ ses-1
17+
└─ micr
18+
19+
20+
21+
Refer to the BIDS specification for directory organization guidelines.
322
"""
423
import json
524
import os
6-
from BIDSTools.BidsFilestructure import FileStructure
7-
from BIDSTools.BidsDirectoryStructure import DirectoryStructure
8-
from BIDSTools.BidsEntity import Entity
9-
from BIDSTools.BidsDatatype import DataTypes
1025
from pathlib import Path
26+
from BIDSTools import BidsFilestructure
27+
from BIDSTools import BidsDirectoryStructure
28+
from BIDSTools import BidsEntity
29+
from BIDSTools import BidsDatatype
1130

1231

1332
class Createdirectory:
@@ -24,11 +43,11 @@ def __init__(self, output_path, sub_id=1, session_id=1, modality="micr"):
2443
self.session_path = None
2544
self.output_path = output_path
2645
self.dir_name = []
27-
self.filestructure = FileStructure()
46+
self.filestructure = BidsFilestructure.FileStructure()
2847
self.filestructure.get_detail()
29-
self.directorystructure = DirectoryStructure()
30-
self.entity = Entity()
31-
self.dataType = DataTypes()
48+
self.directorystructure = BidsDirectoryStructure.DirectoryStructure()
49+
self.entity = BidsEntity.Entity()
50+
self.dataType = BidsDatatype.DataTypes()
3251
self.sub_id = sub_id
3352
self.session_id = session_id
3453
self.modality = modality

BIDSTools/Createfile.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
"""
2-
this module contains the CreatFile class that creates files based on BIDS directory structure , its creat all files and dataset structure (especially agnostic files)
2+
Createfile.py
3+
4+
This module defines the CreatFile class for generating files and dataset structures based on the BIDS (Brain Imaging Data Structure) directory structure.
5+
It automates the creation of all required files, including modality-agnostic files, to ensure BIDS compliance.
6+
7+
Main Features:
8+
- Creates empty files and structured datasets following BIDS specifications.
9+
- Integrates with BIDSTools file structure components.
10+
- Supports automated generation of modality-agnostic files.
11+
12+
Typical Usage:
13+
from BIDSTools.Createfile import CreatFile
14+
creator = CreatFile(output_path)
15+
creator.create_empty_file('dataset_description.json')
16+
17+
Refer to the BIDS specification for file and dataset structure guidelines.
318
"""
419

520
import json
621
import os
7-
from .BidsFilestructure import FileStructure
22+
from BIDSTools.BidsFilestructure import FileStructure
823

924

1025
class CreatFile:

BIDSTools/Experiment.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
"""
2+
Experiment.py
3+
4+
This module defines the Experiment class for representing and managing experiment metadata in BIDS (Brain Imaging Data Structure) workflows.
5+
Each experiment is typically initialized from a row in a metadata CSV file, with dynamic attributes for each metadata field.
6+
7+
Main Features:
8+
- Dynamically creates attributes for each metadata field.
9+
- Provides methods for attribute access, modification, and comparison.
10+
- Integrates with BIDSTools for experiment-based data processing.
11+
12+
Typical Usage:
13+
from BIDSTools import Experiment
14+
exp = Experiment.Experiment(subject_id='01', session_id='01', modality='anat')
15+
print(exp.subject_id)
16+
17+
Refer to the BIDSTools documentation for more details on experiment management.
18+
"""
19+
120
import csv as csv
221
import json
322
import logging

0 commit comments

Comments
 (0)