Skip to content

Commit

Permalink
Add missing test + remove unused fcts
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRenauld committed Nov 9, 2023
1 parent 291f86d commit 276a64c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 215 deletions.
204 changes: 0 additions & 204 deletions dwi_ml/unit_tests/visual_tests/visualise_error_sft.py

This file was deleted.

22 changes: 12 additions & 10 deletions scripts_python/dwiml_compute_connectivity_matrix_from_blocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def main():
in_img = nib.load(args.in_volume)

matrix, start_blocs, end_blocs = compute_triu_connectivity_from_blocs(
in_sft._streamlines_getter, in_img.shape, args.connectivity_nb_blocs)
in_sft.streamlines, in_img.shape, args.connectivity_nb_blocs)

# Options to try to investigate the connectivity matrix:
if args.save_biggest is not None:
i, j = np.unravel_index(np.argmax(matrix, axis=None), matrix.shape)
print("Saving biggest bundle: {} streamlines.".format(matrix[i, j]))
biggest = find_streamlines_with_chosen_connectivity(
in_sft._streamlines_getter, i, j, start_blocs, end_blocs)
in_sft.streamlines, i, j, start_blocs, end_blocs)
sft = in_sft.from_sft(biggest, in_sft)
save_tractogram(sft, args.save_biggest)

Expand All @@ -98,25 +98,27 @@ def main():
i, j = np.unravel_index(tmp_matrix.argmin(axis=None), matrix.shape)
print("Saving smallest bundle: {} streamlines.".format(matrix[i, j]))
biggest = find_streamlines_with_chosen_connectivity(
in_sft._streamlines_getter, i, j, start_blocs, end_blocs)
in_sft.streamlines, i, j, start_blocs, end_blocs)
sft = in_sft.from_sft(biggest, in_sft)
save_tractogram(sft, args.save_smallest)

if args.show_now:
plt.imshow(matrix)
plt.colorbar()
plt.imshow(matrix)
plt.colorbar()

plt.figure()
plt.imshow(matrix > 0)
plt.title('Binary')
plt.figure()
plt.imshow(matrix > 0)
plt.title('Binary')

if args.binary:
matrix = matrix > 0

# Save results.
np.save(args.out_file, matrix)

plt.savefig(out_fig)
plt.show()

if args.show_now:
plt.show()


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import tempfile

from dwi_ml.unit_tests.utils.data_and_models_for_tests import fetch_testing_data

data_dir = fetch_testing_data()
tmp_dir = tempfile.TemporaryDirectory()


def test_help_option(script_runner):
ret = script_runner.run('dwiml_compute_connectivity_matrix_from_blocs.py', '--help')
ret = script_runner.run('dwiml_compute_connectivity_matrix_from_blocs.py',
'--help')
assert ret.success


def test_run(script_runner):
os.chdir(os.path.expanduser(tmp_dir.name))

dwi_ml_folder = os.path.join(data_dir, 'dwi_ml_ready', 'subjX')
in_volume = os.path.join(dwi_ml_folder, 'anat', 't1.nii.gz')
streamlines = os.path.join(dwi_ml_folder, 'example_bundle', 'Fornix.trk')

out_file = 'test_matrix_connectivity.npy'
biggest = 'test_biggest.trk'

nb_blocs = '4'
ret = script_runner.run('dwiml_compute_connectivity_matrix_from_blocs.py',
in_volume, streamlines, out_file, nb_blocs,
'--binary', '--save_biggest', biggest)
assert ret.success

0 comments on commit 276a64c

Please sign in to comment.