Skip to content

Commit

Permalink
Merge pull request #896 from karanphil/set_frf_msmt
Browse files Browse the repository at this point in the history
Adding msmt support to set_frf_diffusivities
  • Loading branch information
arnaudbore authored Feb 14, 2024
2 parents a4f5d4f + dedb657 commit 1e9f814
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
26 changes: 20 additions & 6 deletions scripts/scil_frf_set_diffusivities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
Use this script when you want to use a fixed response function
and keep the mean b0.
The FRF file is obtained from scil_frf_ssst.py
The FRF file is obtained from scil_frf_ssst.py or scil_frf_msmt.py in the case
of multi-shell data.
Formerly: scil_set_response_function.py
"""
Expand All @@ -30,17 +31,19 @@ def _build_arg_parser():
p.add_argument('new_frf', metavar='tuple',
help='Replace the response function with\n'
'this fiber response function x 10**-4 (e.g. '
'15,4,4).')
'15,4,4). \nIf multi-shell, write the first shell'
', then the second shell, \nand the third, etc '
'(e.g. 15,4,4,13,5,5,12,5,5).')
p.add_argument('output_frf_file', metavar='output',
help='Path of the new FRF file.')
p.add_argument('--no_factor', action='store_true',
help='If supplied, the fiber response function is\n'
'evaluated without the x 10**-4 factor. [%(default)s].'
)

add_verbose_arg(p)
add_overwrite_arg(p)

return p


Expand All @@ -51,13 +54,24 @@ def main():
assert_inputs_exist(parser, args.frf_file)
assert_outputs_exist(parser, args, args.output_frf_file)

frf_file = np.array(np.loadtxt(args.frf_file))
frf_file = np.array(np.loadtxt(args.frf_file)).T
new_frf = np.array(literal_eval(args.new_frf), dtype=np.float64)
if not args.no_factor:
new_frf *= 10 ** -4
b0_mean = frf_file[3]

response = np.concatenate([new_frf, [b0_mean]])
if new_frf.shape[0] % 3 != 0:
raise ValueError('Inputed new frf is not valid. There should be '
'three values per shell, and thus the total number '
'of values should be a multiple of three.')

nb_shells = int(new_frf.shape[0] / 3)
new_frf = new_frf.reshape((nb_shells, 3))

response = np.empty((nb_shells, 4))
response[:, 0:3] = new_frf
response[:, 3] = b0_mean

np.savetxt(args.output_frf_file, response)


Expand Down
25 changes: 22 additions & 3 deletions scripts/tests/test_frf_set_diffusivities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict

# If they already exist, this only takes 5 seconds (check md5sum)
fetch_data(get_testing_files_dict(), keys=['processing.zip'])
fetch_data(get_testing_files_dict(),
keys=['processing.zip', 'commit_amico.zip'])
tmp_dir = tempfile.TemporaryDirectory()


Expand All @@ -16,10 +17,28 @@ def test_help_option(script_runner):
assert ret.success


def test_execution_processing(script_runner):
def test_execution_processing_ssst(script_runner):
os.chdir(os.path.expanduser(tmp_dir.name))
in_frf = os.path.join(get_home(), 'processing',
'frf.txt')
ret = script_runner.run('scil_frf_set_diffusivities.py', in_frf,
'15,4,4', 'nfrf.txt')
'15,4,4', 'new_frf.txt', '-f')
assert ret.success


def test_execution_processing_msmt(script_runner):
os.chdir(os.path.expanduser(tmp_dir.name))
in_frf = os.path.join(get_home(), 'commit_amico',
'wm_frf.txt')
ret = script_runner.run('scil_frf_set_diffusivities.py', in_frf,
'15,4,4,13,4,4,12,5,5', 'new_frf.txt', '-f')
assert ret.success


def test_execution_processing__wrong_input(script_runner):
os.chdir(os.path.expanduser(tmp_dir.name))
in_frf = os.path.join(get_home(), 'commit_amico',
'wm_frf.txt')
ret = script_runner.run('scil_frf_set_diffusivities.py', in_frf,
'15,4,4,13,4,4', 'new_frf.txt', '-f')
assert not ret.success

0 comments on commit 1e9f814

Please sign in to comment.