Skip to content

Commit e893baa

Browse files
authored
Removing dependancy to nilearn (Inria-Empenn#241)
* Removing nilearn dependency from 98BT * Removing nilearn dependency from UK24 * Removing last dependancies to nilearn + bug correction in conftest
1 parent f9ead2e commit e893baa

File tree

9 files changed

+37
-42
lines changed

9 files changed

+37
-42
lines changed

narps_open/data/results/team_2T6S.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from shutil import copyfile
99

10-
from nibabel import load
11-
from nilearn.image import math_img
10+
from nibabel import load, save, Nifti1Image
1211

1312
from narps_open.data.results import ResultsCollection
1413

@@ -44,5 +43,4 @@ def rectify(self):
4443

4544
# Change the signs of values inside the input image
4645
input_image = load(input_file)
47-
output_image = math_img('img*-1', img = input_image)
48-
output_image.to_filename(rectified_file)
46+
save(Nifti1Image(input_image.get_fdata()*-1, input_image.affine), rectified_file)

narps_open/pipelines/team_98BT.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ def get_parameters_file(
424424
from os import makedirs
425425
from os.path import join
426426
from nibabel import load
427+
from nibabel.processing import resample_from_to
427428
from numpy import mean
428-
from pandas import read_table
429-
from nilearn.image import iter_img, resample_to_img
429+
from pandas import read_csv
430430

431431
# Ignore all future warnings
432432
from warnings import simplefilter
@@ -435,22 +435,23 @@ def get_parameters_file(
435435
simplefilter(action = 'ignore', category = RuntimeWarning)
436436

437437
# Load wc2 file and create a mask out of it
438-
wc2 = load(wc2_file)
439-
wc2_mask = wc2.get_fdata() > 0.6
440-
wc2_mask = wc2_mask.astype(int)
438+
wm_class_image = load(wc2_file)
439+
wm_mask_data = wm_class_image.get_fdata() > 0.6
440+
wm_mask_data = wm_mask_data.astype(int)
441441

442442
# Compute the mean signal in white matter, for each slice of the functional data
443443
mean_wm = []
444-
for current_slice in iter_img(load(func_file)):
445-
slice_data = resample_to_img(
446-
current_slice, wc2, interpolation = 'nearest', clip = True).get_fdata()
444+
func_image = load(func_file)
445+
for index in range(func_image.header.get_data_shape()[3]):
446+
resampled_func = resample_from_to(
447+
func_image.slicer[..., index], wm_class_image, order = 0, mode = 'nearest')
448+
447449
# Append mean value of masked data
448-
mean_wm.append(mean(slice_data * wc2_mask))
450+
mean_wm.append(mean(resampled_func.get_fdata() * wm_mask_data))
449451

450452
# Create new parameters file
451-
data_frame = read_table(parameters_file, sep = ' ', header = None)
453+
data_frame = read_csv(parameters_file, sep = '\t', dtype = str)
452454
data_frame['Mean_WM'] = mean_wm
453-
454455
new_parameters_file = join(working_dir, 'parameters_files',
455456
f'parameters_file_sub-{subject_id}_run-{run_id}.tsv')
456457

narps_open/pipelines/team_UK24.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,21 @@ def get_average_values(
6868
"""
6969
from os import makedirs
7070
from os.path import join, abspath
71-
72-
from nilearn.image import load_img, math_img, index_img, get_data
71+
from nibabel import load
72+
from numpy import mean
7373

7474
# Load input images
75-
mask_img = load_img(mask)
76-
in_file_img = load_img(in_file)
75+
mask_image = load(mask)
76+
in_file_image = load(in_file)
77+
78+
# Create mask
79+
mask_data = mask_image.get_fdata() > 0.0
80+
mask_data = mask_data.astype(int)
7781

7882
# Loop through time points
7983
average_values = []
80-
for frame_index in range(in_file_img.shape[3]):
81-
average_values.append(
82-
get_data(math_img(
83-
'np.mean(image * (mask > 0.0))',
84-
image = index_img(in_file_img, frame_index),
85-
mask = mask_img
86-
))
87-
)
84+
for index in range(in_file_image.shape[3]):
85+
average_values.append(mean(in_file_image.slicer[..., index].get_fdata() * mask_data))
8886

8987
# Write confounds to a file
9088
out_file_name = abspath(f'sub-{subject_id}_run-{run_id}_' + out_file_suffix)

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
'importlib_resources>=5.10.2,<5.11',
1818
'tomli>=2.0.1,<2.1',
1919
'networkx>=2.0,<3.0', # a workaround to nipype's bug (issue 3530)
20-
'nilearn>=0.10.0,<0.11',
2120
'nipype>=1.8.6,<1.9',
2221
'pandas>=1.5.2,<1.6',
2322
'niflow-nipype1-workflows>=0.0.5,<0.1.0'

tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from numpy import isclose
1818

1919
from narps_open.pipelines import Pipeline
20-
from narps_open.runner import PipelineRunner
20+
from narps_open.runner import PipelineRunner, PipelineRunnerLevel
2121
from narps_open.utils import get_subject_id
2222
from narps_open.utils.correlation import get_correlation_coefficient
2323
from narps_open.utils.configuration import Configuration
@@ -113,7 +113,7 @@ def test_pipeline_execution(
113113

114114
# Get missing subjects
115115
missing_subjects = set()
116-
for file in runner.get_missing_first_level_outputs():
116+
for file in runner.get_missing_outputs(PipelineRunnerLevel.FIRST):
117117
subject_id = get_subject_id(file)
118118
if subject_id is not None:
119119
missing_subjects.add(subject_id)
@@ -125,19 +125,19 @@ def test_pipeline_execution(
125125
# Start pipeline
126126
runner.subjects = missing_subjects
127127
try: # This avoids errors in the workflow to make the test fail
128-
runner.start(True, False)
128+
runner.start(PipelineRunnerLevel.FIRST)
129129
except(RuntimeError) as err:
130130
print('RuntimeError: ', err)
131131

132132
# Check missing files for the last time
133-
missing_files = runner.get_missing_first_level_outputs()
133+
missing_files = runner.get_missing_outputs(PipelineRunnerLevel.FIRST)
134134
if missing_files:
135135
print('Missing files:', missing_files)
136136
raise Exception('There are missing files for first level analysis.')
137137

138138
# Start pipeline for the group level only
139139
runner.nb_subjects = nb_subjects
140-
runner.start(False, True)
140+
runner.start(PipelineRunnerLevel.SECOND)
141141

142142
# Indices and keys to the unthresholded maps
143143
indices = list(range(1, 18, 2))

tests/pipelines/test_team_98BT.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_subject_information():
140140
helpers.compare_float_2d_arrays(pmod.param, [
141141
[14.0, 34.0, 38.0, 10.0, 16.0],
142142
[6.0, 14.0, 19.0, 15.0, 17.0],
143-
[1, 1, 0, 0, 0]
143+
[1, 2, -2, -2, -1]
144144
])
145145

146146
@staticmethod
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"CSF WhiteMatter GlobalSignal stdDVARS non-stdDVARS vx-wisestdDVARS FramewiseDisplacement tCompCor00 tCompCor01 tCompCor02 tCompCor03 tCompCor04 tCompCor05 aCompCor00 aCompCor01 aCompCor02 aCompCor03 aCompCor04 aCompCor05 Cosine00 Cosine01 Cosine02 Cosine03 Cosine04 Cosine05 NonSteadyStateOutlier00 X Y Z RotX RotY RotZ" 261.948061726888
2-
"6551.281999999999 6476.4653 9874.576 n/a n/a n/a n/a 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 -0.0 0.0" 241.43458658854166
3-
"6484.7285 6473.4890000000005 9830.212 1.09046686 52.78273392 1.05943739 0.13527900930999998 0.0263099209 -0.0673065879 0.0934882554 -0.0079328884 0.0338007737 -0.011491083999999999 -0.042411347099999996 0.027736422900000002 0.0453303087 -0.07022609490000001 0.0963618709 -0.0200867957 0.0665186088 0.0665174038 0.0665153954 0.0665125838 0.0665089688 0.06650455059999999 0.0 -0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819" 246.2539803059896
4-
"6441.5337 6485.7256 9821.212 1.07520139 52.04382706 1.03821933 0.12437666391 -0.0404820317 0.034150583 0.13661184210000002 0.0745358691 -0.0054829985999999995 -0.0217322686 0.046214115199999996 0.005774624 -0.043909359800000006 -0.075619539 0.17546891539999998 -0.0345256763 0.0665153954 0.06650455059999999 0.06648647719999999 0.0664611772 0.0664286533 0.0663889091 0.0 -2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988" 246.21754170735676
1+
6551.281999999999 6476.4653 9874.576 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 -0.0 0.0 261.948061726888
2+
6484.7285 6473.4890000000005 9830.212 1.09046686 52.78273392 1.05943739 0.13527900930999998 0.0263099209 -0.0673065879 0.0934882554 -0.0079328884 0.0338007737 -0.011491083999999999 -0.042411347099999996 0.027736422900000002 0.0453303087 -0.07022609490000001 0.0963618709 -0.0200867957 0.0665186088 0.0665174038 0.0665153954 0.0665125838 0.0665089688 0.06650455059999999 0.0 -0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819 241.43458658854166
3+
6441.5337 6485.7256 9821.212 1.07520139 52.04382706 1.03821933 0.12437666391 -0.0404820317 0.034150583 0.13661184210000002 0.0745358691 -0.0054829985999999995 -0.0217322686 0.046214115199999996 0.005774624 -0.043909359800000006 -0.075619539 0.17546891539999998 -0.0345256763 0.0665153954 0.06650455059999999 0.06648647719999999 0.0664611772 0.0664286533 0.0663889091 0.0 -2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988 246.2539803059896
Binary file not shown.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
52.34728240966797
2-
52.014034271240234
3-
52.75069808959961
4-
52.45905303955078
1+
52.34728190104167
2+
52.014033203125
3+
52.75069986979167
4+
52.459052734375

0 commit comments

Comments
 (0)