Skip to content

Commit

Permalink
Add new config option to set derivatives root (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger authored Feb 15, 2021
1 parent 654d447 commit a976d60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
24 changes: 16 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
```
"""

deriv_root: Optional[PathLike] = None
"""
The root of the derivatives directory in which the Study Template will store
the processing results. If ``None``, this will be
``derivatives/mne-study-template`` inside the BIDS root.
"""

subjects_dir: Optional[PathLike] = None
"""
Path to the directory that contains the MRI data files and their
Expand Down Expand Up @@ -1069,9 +1076,9 @@
# ``export MNE_BIDS_STUDY_CONFIG=/data/mystudy/mydataset-template-config.py``

if "MNE_BIDS_STUDY_CONFIG" in os.environ:
cfg_path = os.environ['MNE_BIDS_STUDY_CONFIG']
cfg_path = pathlib.Path(os.environ['MNE_BIDS_STUDY_CONFIG'])

if os.path.exists(cfg_path):
if cfg_path.exists():
msg = f'Using custom configuration: {cfg_path}'
logger.info(msg)
else:
Expand Down Expand Up @@ -1099,7 +1106,7 @@
# BIDS_ROOT environment variable takes precedence over any configuration file
# values.
if os.getenv('BIDS_ROOT') is not None:
bids_root = os.getenv('BIDS_ROOT')
bids_root = pathlib.Path(os.getenv('BIDS_ROOT'))

# If we don't have a bids_root until now, raise an exeception as we cannot
# proceed.
Expand All @@ -1109,12 +1116,13 @@
'root folder of your BIDS dataset')
raise ValueError(msg)

bids_root = pathlib.Path(bids_root).expanduser()
bids_root: pathlib.Path = pathlib.Path(bids_root).expanduser()

###############################################################################
# Derivates root
# --------------
deriv_root = os.path.join(bids_root, 'derivatives', PIPELINE_NAME)
if deriv_root is None:
deriv_root = bids_root / 'derivatives' / PIPELINE_NAME
else:
deriv_root = pathlib.Path(deriv_root).expanduser()


###############################################################################
Expand Down Expand Up @@ -1336,7 +1344,7 @@ def get_reject() -> dict:

def get_fs_subjects_dir():
if not subjects_dir:
return os.path.join(bids_root, 'derivatives', 'freesurfer', 'subjects')
return bids_root / 'derivatives' / 'freesurfer' / 'subjects'
else:
return subjects_dir

Expand Down
1 change: 1 addition & 0 deletions docs/source/settings/general.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
::: config.study_name
::: config.bids_root
::: config.deriv_root
::: config.subjects_dir
::: config.daysback
::: config.interactive
Expand Down
1 change: 1 addition & 0 deletions tests/configs/config_ds000246.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

study_name = 'ds000246'
bids_root = '~/mne_data/ds000246'
deriv_root = '~/mne_data/ds000246/derivatives/mne-study-template'
runs = ['01']
l_freq = .3
h_freq = 100.
Expand Down

0 comments on commit a976d60

Please sign in to comment.