Skip to content

Commit 9ab0037

Browse files
committed
Update
1 parent a360430 commit 9ab0037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+216
-19083
lines changed

CONTRIBUTING.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ You can contribute in many ways:
5555
Report Bugs
5656
~~~~~~~~~~~
5757

58-
Report bugs at https://github.com/nipy/dmriprep/issues.
58+
Report bugs at https://github.com/josephmje/dmriprep/issues.
5959

6060
If you are reporting a bug, please include:
6161

@@ -85,7 +85,7 @@ articles, and such.
8585
Submit Feedback
8686
~~~~~~~~~~~~~~~
8787

88-
The best way to send feedback is to file an issue at https://github.com/nipy/dmriprep/issues.
88+
The best way to send feedback is to file an issue at https://github.com/josephmje/dmriprep/issues.
8989

9090
If you are proposing a feature:
9191

dmriprep/__about__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
__packagename__ = 'dmriprep'
99
__credits__ = ('Contributors: please check the ``.zenodo.json`` file at the'
1010
'top-level folder of the repository')
11-
__url__ = 'https://github.com/nipy/dmriprep'
11+
__url__ = 'https://github.com/josephmje/dmriprep'
1212

1313
DOWNLOAD_URL = (
14-
'https://github.com/nipy/dmriprep/{name}/archive/{ver}.tar.gz'.format(
14+
'https://github.com/josephmje/dmriprep/{name}/archive/{ver}.tar.gz'.format(
1515
name=__packagename__, ver=__version__
1616
)
1717
)

dmriprep/cli.py

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import os
55
import sys
66
import warnings
7+
from multiprocessing import cpu_count
78

89
import click
910
from bids import BIDSLayout
11+
from nipype import config as ncfg
1012

1113
from .utils.bids import collect_participants
1214
from .workflows.base import init_dmriprep_wf
@@ -16,14 +18,17 @@
1618
warnings.filterwarnings('ignore', message='numpy.dtype size changed')
1719
warnings.filterwarnings('ignore', message='numpy.ufunc size changed')
1820

21+
1922
@click.command()
2023
# arguments as specified by BIDS-Apps
2124
@click.argument('bids_dir', type=click.Path(exists=True, file_okay=False))
2225
@click.argument(
2326
'output_dir', type=click.Path(exists=True, file_okay=False, writable=True)
2427
)
2528
@click.argument(
26-
'analysis_level', default='participant', type=click.Choice(['participant', 'group'])
29+
'analysis_level',
30+
default='participant',
31+
type=click.Choice(['participant', 'group'])
2732
)
2833
# optional arguments
2934
# options for filtering BIDS queries
@@ -66,46 +71,22 @@
6671
default=5,
6772
show_default=True,
6873
help='Threshold for b0 value',
69-
type=click.IntRange(min=0, max=10),
74+
type=click.IntRange(min=0, max=10)
7075
)
7176
@click.option(
7277
'--output_resolution',
7378
help='The isotropic voxel size in mm the data will be resampled to before eddy.',
7479
type=float,
7580
multiple=True
7681
)
77-
# specific options for eddy
78-
@click.option(
79-
'--nthreads',
80-
default=1,
81-
show_default=True,
82-
help='Maximum number of threads across all processes',
83-
type=int,
84-
)
85-
@click.option(
86-
'--omp_nthreads',
87-
default=1,
88-
show_default=True,
89-
help='Maximum number of threads per process',
90-
type=int,
91-
)
92-
@click.option(
93-
'--eddy_niter',
94-
default=5,
95-
show_default=True,
96-
help='Fixed number of eddy iterations. See '
97-
'https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/UsersGuide'
98-
'#A--niter',
99-
type=int,
100-
)
10182
@click.option(
10283
'--bet_dwi',
10384
default=0.3,
10485
show_default=True,
10586
help='Fractional intensity threshold for BET on the DWI. '
10687
'A higher value will be more strict; it will cut off more '
10788
'around what it analyzes the brain to be.',
108-
type=click.FloatRange(min=0, max=1),
89+
type=click.FloatRange(min=0, max=1)
10990
)
11091
@click.option(
11192
'--bet_mag',
@@ -114,54 +95,74 @@
11495
help='Fractional intensity threshold for BET on the magnitude. '
11596
'A higher value will be more strict; it will cut off more '
11697
'around what it analyzes the brain to be.',
117-
type=click.FloatRange(min=0, max=1),
98+
type=click.FloatRange(min=0, max=1)
99+
)
100+
# specific options for eddy
101+
@click.option(
102+
'--nthreads',
103+
default=1,
104+
show_default=True,
105+
help='Maximum number of threads across all processes',
106+
type=int
107+
)
108+
@click.option(
109+
'--omp_nthreads',
110+
default=1,
111+
show_default=True,
112+
help='Maximum number of threads per process',
113+
type=int
118114
)
119115
@click.option(
120116
'--acqp_file',
121117
default=None,
122118
help='If you want to pass in an acqp file for topup/eddy instead of'
123119
'generating it from the json by default.',
124-
type=click.Path(exists=True, dir_okay=False),
120+
type=click.Path(exists=True, dir_okay=False)
125121
)
126122
# workflow configuration
127123
@click.option(
128124
'--ignore',
129125
'-i',
130126
help='Specify which node(s) to skip during the preprocessing of the dwi.',
131127
type=click.Choice(['denoising', 'unringing', 'fieldmaps']),
132-
multiple=True,
128+
multiple=True
133129
)
134130
@click.option(
135131
'--work_dir',
136132
'-w',
137133
help='working directory',
138-
type=click.Path(exists=True, file_okay=False, writable=True),
134+
type=click.Path(exists=True, file_okay=False, writable=True)
139135
)
140136
@click.option(
141137
'--synb0_dir',
142138
default=None,
143139
help='If you want to use Synb0-DISCO for preprocessing.',
144-
type=click.Path(exists=True, file_okay=False),
140+
type=click.Path(exists=True, file_okay=False)
141+
)
142+
@click.option(
143+
'--write_graph',
144+
default=False,
145+
help='Write out nipype workflow graph.'
145146
)
146147
def main(
147-
participant_label,
148-
session_label,
149148
bids_dir,
150149
output_dir,
151150
analysis_level,
152151
skip_bids_validation,
153-
work_dir,
154-
ignore,
152+
participant_label,
153+
session_label,
155154
concat_dwis,
156155
b0_thresh,
157156
output_resolution,
158157
bet_dwi,
159158
bet_mag,
160159
nthreads,
161160
omp_nthreads,
162-
eddy_niter,
161+
acqp_file,
162+
ignore,
163+
work_dir,
163164
synb0_dir,
164-
acqp_file
165+
write_graph
165166
):
166167
"""
167168
BIDS_DIR: The directory with the input dataset formatted according to the
@@ -188,7 +189,6 @@ def main(
188189

189190
if not skip_bids_validation:
190191
from .utils.bids import validate_input_dir
191-
192192
validate_input_dir(bids_dir, all_subjects, subject_list)
193193

194194
if not work_dir:
@@ -197,27 +197,61 @@ def main(
197197
if len(output_resolution) == 1:
198198
output_resolution = output_resolution * 3
199199

200+
log_dir = os.path.join(output_dir, 'dmriprep', 'logs')
201+
202+
plugin_settings = {
203+
'plugin': 'MultiProc',
204+
'plugin_args': {
205+
'raise_insufficient': False,
206+
'maxtasksperchild': 1,
207+
'n_procs': nthreads
208+
}
209+
}
210+
211+
if omp_nthreads == 0:
212+
omp_nthreads = min(nthreads - 1 if nthreads > 1 else cpu_count(), 8)
213+
214+
ncfg.update_config({
215+
'logging': {
216+
'log_directory': log_dir,
217+
'log_to_file': True
218+
},
219+
'execution': {
220+
'crashdump_dir': log_dir,
221+
'crashfile_format': 'txt',
222+
'remove_unnecessary_outputs': False,
223+
'keep_inputs': True,
224+
'get_linked_libs': False,
225+
'stop_on_first_crash': True
226+
},
227+
'monitoring': {
228+
'enabled': True,
229+
'sample_frequency': '0.5',
230+
'summary_append': True
231+
}
232+
})
233+
200234
wf = init_dmriprep_wf(
201-
subject_list=subject_list,
202-
session_list=session_label,
203235
layout=layout,
204236
output_dir=output_dir,
205-
work_dir=work_dir,
206-
ignore=list(ignore),
237+
subject_list=subject_list,
238+
session_list=list(session_label),
207239
concat_dwis=list(concat_dwis),
208240
b0_thresh=b0_thresh,
209241
output_resolution=output_resolution,
210242
bet_dwi=bet_dwi,
211243
bet_mag=bet_mag,
212-
nthreads=nthreads,
213244
omp_nthreads=omp_nthreads,
245+
acqp_file=acqp_file,
246+
ignore=list(ignore),
247+
work_dir=work_dir,
214248
synb0_dir=synb0_dir
215249
)
216-
wf.write_graph()
217-
wf.config['execution']['remove_unnecessary_outputs'] = False
218-
wf.config['execution']['keep_inputs'] = True
219-
wf.config['execution']['crashfile_format'] = 'txt'
220-
wf.run()
250+
251+
if write_graph:
252+
wf.write_graph(graph2use='colored', format='svg', simple_form=True)
253+
254+
wf.run(**plugin_settings)
221255

222256
return 0
223257

dmriprep/utils/bids.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def collect_participants(
114114
return all_participants, found_label
115115

116116

117-
def collect_data(bids_dir, participant_label, session_label=None, bids_validate=True):
117+
def collect_data(bids_dir, participant_label, concat_dwis, session_label=None):
118118
"""
119119
Uses pybids to retrieve the input data for a given participant
120120
"""
@@ -140,9 +140,37 @@ def collect_data(bids_dir, participant_label, session_label=None, bids_validate=
140140
extension=['nii', 'nii.gz'], **query))
141141
for dtype, query in queries.items()}
142142

143+
subj_data['dwi'] = group_dwi(subj_data['dwi'], session_label, concat_dwis)
144+
143145
return subj_data, layout
144146

145147

148+
def group_dwi(dwi_files, session_list, concat_dwis):
149+
150+
all_dwis = []
151+
152+
if session_list:
153+
for session in session_list:
154+
session_groups = []
155+
session_dwis = [img for img in dwi_files if 'ses-%s' % session in img]
156+
for f in session_dwis:
157+
if any(acq in f for acq in concat_dwis):
158+
session_groups.append(f)
159+
else:
160+
all_dwis.append(f)
161+
all_dwis.append(session_groups)
162+
else:
163+
session_groups = []
164+
for f in dwi_files:
165+
if any(acq in f for acq in concat_dwis):
166+
session_groups.append(f)
167+
else:
168+
all_dwis.append(f)
169+
all_dwis.append(session_groups)
170+
171+
return all_dwis
172+
173+
146174
def validate_input_dir(bids_dir, all_subjects, subject_list):
147175
# Ignore issues and warnings that should not influence DMRIPREP
148176
import tempfile

0 commit comments

Comments
 (0)