Skip to content

Commit b1707bf

Browse files
committed
Re-Refactoring of IO helper functions (bidscoin.plugins -> bidscoin.utilities)
1 parent 13e414b commit b1707bf

File tree

13 files changed

+664
-669
lines changed

13 files changed

+664
-669
lines changed

bidscoin/bids.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
from fnmatch import fnmatch
2020
from pathlib import Path
2121
from typing import Union, Any, Iterable, NewType
22-
from pydicom import config
2322
from importlib.util import find_spec
2423
if find_spec('bidscoin') is None:
2524
import sys
2625
sys.path.append(str(Path(__file__).parents[1]))
27-
from bidscoin import bcoin, schemafolder, templatefolder, lsdirs, is_hidden, __version__, DEBUG
26+
from bidscoin import bcoin, schemafolder, templatefolder, is_hidden, __version__
2827
from bidscoin.plugins import EventsParser
2928
from ruamel.yaml import YAML
3029
yaml = YAML()
3130
yaml.representer.ignore_aliases = lambda *data: True # Expand aliases (https://stackoverflow.com/questions/58091449/disabling-alias-for-yaml-file-in-python)
32-
config.INVALID_KEY_BEHAVIOR = 'IGNORE'
3331

3432
# Define custom data types (replace with proper classes or TypeAlias of Python >= 3.10)
3533
Plugin = NewType('Plugin', dict[str, Any])

bidscoin/bidscoiner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
if find_spec('bidscoin') is None:
2222
sys.path.append(str(Path(__file__).parents[1]))
2323
from bidscoin import bcoin, bids, lsdirs, bidsversion, trackusage, __version__, DEBUG
24-
from bidscoin.plugins import unpack
24+
from bidscoin.utilities import unpack
2525

2626

2727
def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force: bool=False, bidsmap: str='bidsmap.yaml', cluster: str='') -> None:

bidscoin/bidsmapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
sys.path.append(str(Path(__file__).parents[1]))
2121
from bidscoin import bcoin, lsdirs, trackusage, check_version, __version__
2222
from bidscoin.bids import BidsMap
23-
from bidscoin.plugins import unpack
23+
from bidscoin.utilities import unpack
2424

2525
_, uptodate, versionmessage = check_version()
2626

bidscoin/plugins/__init__.py

Lines changed: 1 addition & 550 deletions
Large diffs are not rendered by default.

bidscoin/plugins/dcm2niix2bids.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from typing import Union
1515
from pathlib import Path
1616
from bidscoin import bids, run_command, lsdirs, due, Doi
17-
from bidscoin.utilities import physio
17+
from bidscoin.utilities import physio, is_dicomfile, is_parfile, get_dicomfield, get_parfield, get_dicomfile, get_parfiles
1818
from bidscoin.bids import BidsMap, DataFormat, Plugin, Plugins
19-
from bidscoin.plugins import PluginInterface, is_dicomfile, is_parfile, get_dicomfield, get_parfield, get_dicomfile, get_parfiles
19+
from bidscoin.plugins import PluginInterface
2020
try:
2121
from nibabel.testing import data_path
2222
except ImportError:
@@ -92,7 +92,6 @@ def has_support(self, file: Path, dataformat: Union[DataFormat, str]='') -> str:
9292

9393
return ''
9494

95-
9695
def get_attribute(self, dataformat: Union[DataFormat, str], sourcefile: Path, attribute: str, options) -> Union[str, int]:
9796
"""
9897
This plugin supports reading attributes from DICOM and PAR dataformats
@@ -109,7 +108,6 @@ def get_attribute(self, dataformat: Union[DataFormat, str], sourcefile: Path, at
109108
if dataformat == 'PAR':
110109
return get_parfield(attribute, sourcefile)
111110

112-
113111
def bidsmapper(self, session: Path, bidsmap_new: BidsMap, bidsmap_old: BidsMap, template: BidsMap) -> None:
114112
"""
115113
The goal of this plugin function is to identify all the different runs in the session and update the
@@ -190,7 +188,6 @@ def bidsmapper(self, session: Path, bidsmap_new: BidsMap, bidsmap_old: BidsMap,
190188
else:
191189
LOGGER.bcdebug(f"Existing/duplicate sample: {run.datasource}")
192190

193-
194191
@due.dcite(Doi('10.1016/j.jneumeth.2016.03.001'), description='dcm2niix: DICOM to NIfTI converter', tags=['reference-implementation'])
195192
def bidscoiner(self, session: Path, bidsmap: BidsMap, bidsses: Path) -> Union[None, dict]:
196193
"""
@@ -206,9 +203,8 @@ def bidscoiner(self, session: Path, bidsmap: BidsMap, bidsses: Path) -> Union[No
206203
"""
207204

208205
# Get the subject identifiers and the BIDS root folder from the bidsses folder
209-
subid = bidsses.name if bidsses.name.startswith('sub-') else bidsses.parent.name
210-
sesid = bidsses.name if bidsses.name.startswith('ses-') else ''
211-
bidsfolder = bidsses.parent.parent if sesid else bidsses.parent
206+
subid = bidsses.name if bidsses.name.startswith('sub-') else bidsses.parent.name
207+
sesid = bidsses.name if bidsses.name.startswith('ses-') else ''
212208

213209
# Get started and see what dataformat we have
214210
options = Plugin(bidsmap.plugins['dcm2niix2bids'])
@@ -222,13 +218,10 @@ def bidscoiner(self, session: Path, bidsmap: BidsMap, bidsses: Path) -> Union[No
222218

223219
# Make a list of all the data sources/runs
224220
sources: list[Path] = []
225-
manufacturer = 'UNKNOWN'
226221
if dataformat == 'DICOM':
227-
sources = lsdirs(session, '**/*')
228-
manufacturer = datasource.attributes('Manufacturer')
222+
sources = lsdirs(session, '**/*')
229223
elif dataformat == 'PAR':
230-
sources = get_parfiles(session)
231-
manufacturer = 'Philips Medical Systems'
224+
sources = get_parfiles(session)
232225
else:
233226
LOGGER.error(f"Unsupported dataformat '{dataformat}'")
234227

bidscoin/plugins/nibabel2bids.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def test(self, options: Plugin=OPTIONS) -> int:
6262

6363
return 0
6464

65-
6665
def has_support(self, file: Path, dataformat: Union[DataFormat, str]='') -> str:
6766
"""
6867
This plugin function assesses whether a sourcefile is of a supported dataformat
@@ -81,7 +80,6 @@ def has_support(self, file: Path, dataformat: Union[DataFormat, str]='') -> str:
8180

8281
return ''
8382

84-
8583
def get_attribute(self, dataformat: Union[DataFormat, str], sourcefile: Path, attribute: str, options: Plugin) -> Union[str, int, float, list]:
8684
"""
8785
This plugin supports reading attributes from DICOM and PAR dataformats
@@ -107,7 +105,6 @@ def get_attribute(self, dataformat: Union[DataFormat, str], sourcefile: Path, at
107105

108106
return value
109107

110-
111108
def bidscoiner(self, session: Path, bidsmap: BidsMap, bidsses: Path) -> None:
112109
"""
113110
The bidscoiner plugin to convert the session Nibabel source-files into BIDS-valid NIfTI-files in the

bidscoin/plugins/spec2nii2bids.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from pathlib import Path
1313
from bidscoin import run_command, is_hidden, bids, due, Doi
1414
from bidscoin.bids import BidsMap, DataFormat, Plugin
15-
from bidscoin.plugins import PluginInterface, is_dicomfile, get_twixfield, get_sparfield, get_p7field
15+
from bidscoin.plugins import PluginInterface
16+
from bidscoin.utilities import is_dicomfile, get_twixfield, get_sparfield, get_p7field
1617

1718
LOGGER = logging.getLogger(__name__)
1819

@@ -45,7 +46,6 @@ def test(self, options: Plugin=OPTIONS) -> int:
4546
# Test the spec2nii installation
4647
return run_command(f"{options.get('command',OPTIONS['command'])} -v")
4748

48-
4949
def has_support(self, file: Path, dataformat: Union[DataFormat, str]='') -> str:
5050
"""
5151
This plugin function assesses whether a sourcefile is of a supported dataformat
@@ -68,7 +68,6 @@ def has_support(self, file: Path, dataformat: Union[DataFormat, str]='') -> str:
6868

6969
return ''
7070

71-
7271
def get_attribute(self, dataformat: Union[DataFormat, str], sourcefile: Path, attribute: str, options: Plugin) -> str:
7372
"""
7473
This plugin function reads attributes from the supported sourcefile

0 commit comments

Comments
 (0)