From d5e9e7b01d8cf162ffcd199567639f95edfe0943 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 15:12:58 -0500 Subject: [PATCH 01/38] Combining about 160 lines copy-pasted in both mti scripts. Nicer read of tests. --- scilpy/io/mti.py | 163 +++++++++ scripts/scil_mti_maps_MT.py | 206 +++--------- scripts/scil_mti_maps_ihMT.py | 185 ++--------- scripts/tests/test_mti_maps_MT.py | 358 +++----------------- scripts/tests/test_mti_maps_ihMT.py | 494 +++------------------------- 5 files changed, 322 insertions(+), 1084 deletions(-) create mode 100644 scilpy/io/mti.py diff --git a/scilpy/io/mti.py b/scilpy/io/mti.py new file mode 100644 index 000000000..953af4bd9 --- /dev/null +++ b/scilpy/io/mti.py @@ -0,0 +1,163 @@ +# -*- coding: utf-8 -*- +import logging +import os +import sys + +import nibabel as nib +import numpy as np + +from scilpy.image.volume_math import concatenate +from scilpy.io.image import load_img +from scilpy.io.utils import get_acq_parameters +from scilpy.reconst.mti import adjust_B1_map_intensities, smooth_B1_map, \ + process_contrast_map + + +def add_common_args_mti(p): + p.add_argument('--extended', action='store_true', + help='If set, outputs the folder Complementary_maps.') + p.add_argument('--filtering', action='store_true', + help='Gaussian filtering to remove Gibbs ringing. ' + 'Not recommended.') + + a = p.add_argument_group( + title='Acquisition parameters', + description='Acquisition parameters required for MTsat and ihMTsat ' + 'calculation. \nThese are the excitation flip angles ' + '(a_PD, a_T1), in DEGREES, and \nrepetition times (TR_PD, ' + 'TR_T1) of the PD and T1 images, in SECONDS. \nCan be ' + 'given through json files (--in_jsons) or directly ' + '(--in_acq_parameters).') + a1 = a.add_mutually_exclusive_group(required='--in_mtoff_t1' in sys.argv) + a1.add_argument('--in_jsons', nargs=2, + metavar=('PD_json', 'T1_json'), + help='Path to MToff PD json file and MToff T1 json file, ' + 'in that order. \nThe acquisition parameters will be ' + 'extracted from these files. \nMust come from a ' + 'Philips acquisition, otherwise, use ' + 'in_acq_parameters.') + a1.add_argument('--in_acq_parameters', nargs=4, type=float, + metavar=('PD flip angle', 'T1 flip angle', + 'PD repetition time', 'T1 repetition time'), + help='Acquisition parameters in that order: flip angle of ' + 'mtoff_PD, \nflip angle of mtoff_T1, repetition time ' + 'of mtoff_PD, \nrepetition time of mtoff_T1') + + b = p.add_argument_group(title='B1 correction') + b.add_argument('--in_B1_map', + help='Path to B1 coregister map to MT contrasts.') + b.add_argument('--B1_correction_method', + choices=['empiric', 'model_based'], default='empiric', + help='Choice of B1 correction method. Choose between ' + 'empiric and model-based. \nNote that the model-based ' + 'method requires a B1 fitvalues file. \nBoth method ' + 'will only correct the saturation measures. ' + '[%(default)s]') + b.add_argument('--B1_fitvalues', nargs='+', + help='Path to B1 fitvalues files obtained externally. ' + 'Should be one .mat \nfile per input MT-on image, ' + 'given in this specific order: \npositive frequency ' + 'saturation, negative frequency saturation.') + b.add_argument('--B1_nominal', default=100, type=float, + help='Nominal value for the B1 map. For Philips, should be ' + '100. [%(default)s]') + b.add_argument('--B1_smooth_dims', default=5, type=int, + help='Dimension of the squared window used for B1 ' + 'smoothing, in number of voxels. [%(default)s]') + + +def verifications_and_loading_mti(args, parser, input_maps_lists, + extended_dir, affine, contrast_names): + """ + Common verifications for both MT and ihMT scripts. + """ + # Verify that there is the same number of --positive, --negative, + # --in_mtoff_pd and --in_mtoff_t1 + for curr_map_list in input_maps_lists[1:]: + if len(curr_map_list) != len(input_maps_lists[0]): + parser.error('Not the same number of echoes per contrast') + + if len(input_maps_lists[0]) == 1: + single_echo = True + else: + single_echo = False + + if args.in_B1_map and not args.in_mtoff_t1: + logging.warning('No B1 correction was applied because no MTsat or ' + 'ihMTsat can be computed without the in_mtoff_t1.') + + if args.B1_correction_method == 'model_based' and not args.B1_fitvalues: + parser.error('Fitvalues files must be given when choosing the ' + 'model-based B1 correction method. Please use ' + '--B1_fitvalues.') + + # Set TR and FlipAngle parameters. Required with --in_mtoff_t1, in which + # case one of --in_aqc_parameters or --in_jsons is set. + rep_times = None + flip_angles = None + if args.in_acq_parameters: + flip_angles = np.asarray(args.in_acq_parameters[:2]) * np.pi / 180. + rep_times = np.asarray(args.in_acq_parameters[2:]) * 1000 + if rep_times[0] > 10000 or rep_times[1] > 10000: + logging.warning('Given repetition times do not seem to be given ' + 'in seconds. MTsat results might be affected.') + elif args.in_jsons: + rep_times = [] + flip_angles = [] + for curr_json in args.in_jsons: + acq_parameter = get_acq_parameters(curr_json, + ['RepetitionTime', 'FlipAngle']) + if acq_parameter[0] > 10: + logging.warning('Repetition time found in {} does not seem to ' + 'be given in seconds. MTsat and ihMTsat ' + 'results might be affected.'.format(curr_json)) + rep_times.append(acq_parameter[0] * 1000) # convert ms. + flip_angles.append(acq_parameter[1] * np.pi / 180.) # convert rad. + + # Fix issue from the presence of invalide value and division by zero + np.seterr(divide='ignore', invalid='ignore') + + # Load B1 image + B1_map = None + if args.in_B1_map and args.in_mtoff_t1: + B1_img = nib.load(args.in_B1_map) + B1_map = B1_img.get_fdata(dtype=np.float32) + B1_map = adjust_B1_map_intensities(B1_map, nominal=args.B1_nominal) + B1_map = smooth_B1_map(B1_map, wdims=args.B1_smooth_dims) + if args.B1_correction_method == 'model_based': + # Apply the B1 map to the flip angles for model-based correction + flip_angles[0] *= B1_map + flip_angles[1] *= B1_map + if args.extended: + nib.save(nib.Nifti1Image(B1_map, affine), + os.path.join(extended_dir, "B1_map.nii.gz")) + + # Define contrasts maps names + if args.filtering: + contrast_names = [curr_name + '_filter' + for curr_name in contrast_names] + if single_echo: + contrast_names = [curr_name + '_single_echo' + for curr_name in contrast_names] + if args.out_prefix: + contrast_names = [args.out_prefix + '_' + curr_name + for curr_name in contrast_names] + + # Compute contrasts maps + contrast_maps = [] + for idx, curr_map in enumerate(input_maps_lists): + input_images = [] + for image in curr_map: + img, _ = load_img(image) + input_images.append(img) + merged_curr_map = concatenate(input_images, input_images[0]) + contrast_maps.append(process_contrast_map(merged_curr_map, + filtering=args.filtering, + single_echo=single_echo)) + if args.extended: + nib.save(nib.Nifti1Image(contrast_maps[idx].astype(np.float32), + affine), + os.path.join(extended_dir, + contrast_names[idx] + '.nii.gz')) + + return single_echo, flip_angles, rep_times, B1_map, contrast_maps diff --git a/scripts/scil_mti_maps_MT.py b/scripts/scil_mti_maps_MT.py index 2c257280c..42bf3d36d 100755 --- a/scripts/scil_mti_maps_MT.py +++ b/scripts/scil_mti_maps_MT.py @@ -84,19 +84,15 @@ import nibabel as nib import numpy as np -from scilpy.io.utils import (get_acq_parameters, add_overwrite_arg, +from scilpy.io.mti import add_common_args_mti, verifications_and_loading_mti +from scilpy.io.utils import (add_overwrite_arg, assert_inputs_exist, add_verbose_arg, assert_output_dirs_exist_and_empty) -from scilpy.io.image import load_img -from scilpy.image.volume_math import concatenate -from scilpy.reconst.mti import (adjust_B1_map_intensities, - apply_B1_corr_empiric, +from scilpy.reconst.mti import (apply_B1_corr_empiric, apply_B1_corr_model_based, compute_ratio_map, compute_saturation_map, - process_contrast_map, - threshold_map, - smooth_B1_map) + threshold_map) EPILOG = """ Helms G, Dathe H, Kallenberg K, Dechent P. High-resolution maps of @@ -115,11 +111,6 @@ def _build_arg_parser(): help='Prefix to be used for each output image.') p.add_argument('--mask', help='Path to the binary brain mask.') - p.add_argument('--extended', action='store_true', - help='If set, outputs the folder Complementary_maps.') - p.add_argument('--filtering', action='store_true', - help='Gaussian filtering to remove Gibbs ringing. ' - 'Not recommended.') g = p.add_argument_group(title='Contrast maps', description='Path to ' 'echoes corresponding to contrast images. All ' @@ -147,54 +138,7 @@ def _build_arg_parser(): 'calculation of MTsat. \nAcquisition ' 'parameters should also be set with this image.') - a = p.add_argument_group(title='Acquisition parameters', - description='Acquisition parameters required ' - 'for MTsat and ihMTsat ' - 'calculation. \nThese are the ' - 'excitation flip angles ' - '(a_PD, a_T1), in DEGREES, and \n' - 'repetition times (TR_PD, TR_T1) of ' - 'the PD and T1 images, in SECONDS. ' - '\nCan be given through json files ' - '(--in_jsons) or directly ' - '(--in_acq_parameters).') - a1 = a.add_mutually_exclusive_group(required='--in_mtoff_t1' in sys.argv) - a1.add_argument('--in_jsons', nargs=2, - metavar=('PD_json', 'T1_json'), - help='Path to MToff PD json file and MToff T1 json file, ' - 'in that order. \nThe acquisition parameters will be ' - 'extracted from these files. \nMust come from a ' - 'Philips acquisition, otherwise, use ' - 'in_acq_parameters.') - a1.add_argument('--in_acq_parameters', nargs=4, type=float, - metavar=('PD flip angle', 'T1 flip angle', - 'PD repetition time', 'T1 repetition time'), - help='Acquisition parameters in that order: flip angle of ' - 'mtoff_PD, \nflip angle of mtoff_T1, repetition time ' - 'of mtoff_PD, \nrepetition time of mtoff_T1') - - b = p.add_argument_group(title='B1 correction') - b.add_argument('--in_B1_map', - help='Path to B1 coregister map to MT contrasts.') - b.add_argument('--B1_correction_method', - choices=['empiric', 'model_based'], default='empiric', - help='Choice of B1 correction method. Choose between ' - 'empiric and model-based. \nNote that the model-based ' - 'method requires a B1 fitvalues file. \nBoth method ' - 'will only correct the saturation measures. ' - '[%(default)s]') - b.add_argument('--B1_fitvalues', nargs='+', - help='Path to B1 fitvalues files obtained externally. ' - 'Should be one .mat \nfile per input MT-on image, ' - 'given in this specific order: \npositive frequency ' - 'saturation, negative frequency saturation.') - b.add_argument('--B1_nominal', default=100, type=float, - help='Nominal value for the B1 map. For Philips, should be ' - '100. [%(default)s]') - b.add_argument('--B1_smooth_dims', default=5, type=int, - help='Dimension of the squared window used for B1 ' - 'smoothing, in number of voxels. [%(default)s]') - + add_common_args_mti(p) add_verbose_arg(p) add_overwrite_arg(p) @@ -207,6 +151,7 @@ def main(): logging.getLogger().setLevel(logging.getLevelName(args.verbose)) output_dir = os.path.join(args.out_dir, 'MT_native_maps') + extended_dir = None if args.extended: extended_dir = os.path.join(args.out_dir, 'Complementary_maps') assert_output_dirs_exist_and_empty(parser, args, extended_dir, @@ -215,110 +160,34 @@ def main(): assert_output_dirs_exist_and_empty(parser, args, output_dir, create_dir=True) - # Merge all echos path into a list - input_maps = [] + # Combine all echos path into a list of lists + input_maps_lists = [] contrast_names = [] if args.in_positive: - input_maps.append(args.in_positive) + input_maps_lists.append(args.in_positive) contrast_names.append('positive') if args.in_negative: - input_maps.append(args.in_negative) + input_maps_lists.append(args.in_negative) contrast_names.append('negative') - input_maps.append(args.in_mtoff_pd) + input_maps_lists.append(args.in_mtoff_pd) contrast_names.append('mtoff_PD') if args.in_mtoff_t1: - input_maps.append(args.in_mtoff_t1) + input_maps_lists.append(args.in_mtoff_t1) contrast_names.append('mtoff_T1') + contrast_names_og = contrast_names # check data - assert_inputs_exist(parser, args.in_mtoff_pd) # Problem with maps_flat... - # cannot verify the not required input. Somehow it breaks the input_maps... - # even if it is not linked at all. WTF. - for curr_map in input_maps[1:]: - if len(curr_map) != len(input_maps[0]): - parser.error('Not the same number of echoes per contrast') - if len(input_maps[0]) == 1: - single_echo = True - else: - single_echo = False - - if args.in_B1_map and not args.in_mtoff_t1: - logging.warning('No B1 correction was applied because no MTsat or ' - 'ihMTsat can be computed without the in_mtoff_t1.') - - if args.B1_correction_method == 'model_based' and not args.B1_fitvalues: - parser.error('Fitvalues files must be given when choosing the ' - 'model-based B1 correction method. Please use ' - '--B1_fitvalues.') - - # Set TR and FlipAngle parameters - if args.in_acq_parameters: - flip_angles = np.asarray(args.in_acq_parameters[:2]) * np.pi / 180. - rep_times = np.asarray(args.in_acq_parameters[2:]) * 1000 - if rep_times[0] > 10000 or rep_times[1] > 10000: - logging.warning('Given repetition times do not seem to be given ' - 'in seconds. MTsat results might be affected.') - elif args.in_jsons: - rep_times = [] - flip_angles = [] - for curr_json in args.in_jsons: - acq_parameter = get_acq_parameters(curr_json, - ['RepetitionTime', 'FlipAngle']) - if acq_parameter[0] > 10: - logging.warning('Repetition time found in {} does not seem to ' - 'be given in seconds. MTsat results might be ' - 'affected.'.format(curr_json)) - rep_times.append(acq_parameter[0] * 1000) # convert ms. - flip_angles.append(acq_parameter[1] * np.pi / 180.) # convert rad. - - # Fix issue from the presence of invalide value and division by zero - np.seterr(divide='ignore', invalid='ignore') + input_maps_flat_list = [m for _list in input_maps_lists for m in _list] + assert_inputs_exist(parser, args.in_mtoff_pd + input_maps_flat_list, + optional=args.in_mtoff_t1 or [] + [args.mask]) # Define reference image for saving maps - affine = nib.load(input_maps[0][0]).affine - - # Load B1 image - if args.in_B1_map and args.in_mtoff_t1: - B1_img = nib.load(args.in_B1_map) - B1_map = B1_img.get_fdata(dtype=np.float32) - B1_map = adjust_B1_map_intensities(B1_map, nominal=args.B1_nominal) - B1_map = smooth_B1_map(B1_map, wdims=args.B1_smooth_dims) - if args.B1_correction_method == 'model_based': - # Apply the B1 map to the flip angles for model-based correction - flip_angles[0] *= B1_map - flip_angles[1] *= B1_map - if args.extended: - nib.save(nib.Nifti1Image(B1_map, affine), - os.path.join(extended_dir, "B1_map.nii.gz")) + affine = nib.load(input_maps_lists[0][0]).affine - # Define contrasts maps names - contrast_names_og = contrast_names - if args.filtering: - contrast_names = [curr_name + '_filter' - for curr_name in contrast_names] - if single_echo: - contrast_names = [curr_name + '_single_echo' - for curr_name in contrast_names] - if args.out_prefix: - contrast_names = [args.out_prefix + '_' + curr_name - for curr_name in contrast_names] - - # Compute contrasts maps - contrast_maps = [] - for idx, curr_map in enumerate(input_maps): - input_images = [] - for image in curr_map: - img, _ = load_img(image) - input_images.append(img) - merged_curr_map = concatenate(input_images, input_images[0]) - contrast_maps.append(process_contrast_map(merged_curr_map, - filtering=args.filtering, - single_echo=single_echo)) - if args.extended: - nib.save(nib.Nifti1Image(contrast_maps[idx].astype(np.float32), - affine), - os.path.join(extended_dir, - contrast_names[idx] + '.nii.gz')) + # Other checks, loading, saving contrast_maps. + single_echo, flip_angles, rep_times, B1_map, contrast_maps = \ + verifications_and_loading_mti(args, parser, input_maps_lists, + extended_dir, affine, contrast_names) # Compute MTR if 'positive' in contrast_names_og and 'negative' in contrast_names_og: @@ -327,8 +196,8 @@ def main(): else: MTR = compute_ratio_map(contrast_maps[0], contrast_maps[1]) - img_name = ['MTR'] - img_data = [MTR] + img_names = ['MTR'] + img_data_list = [MTR] # Compute MTsat if args.in_mtoff_t1: @@ -374,30 +243,29 @@ def main(): # MTR = apply_B1_correction_empiric(MTR, B1_map) MTsat = apply_B1_corr_empiric(MTsat, B1_map) - img_name.append('MTsat') - img_data.append(MTsat) + img_names.append('MTsat') + img_data_list.append(MTsat) # Apply thresholds on maps - for i, map in enumerate(img_data): - img_data[i] = threshold_map(map, args.mask, 0, 100) + for i, map in enumerate(img_data_list): + img_data_list[i] = threshold_map(map, args.mask, 0, 100) # Save ihMT and MT images if args.filtering: - img_name = [curr_name + '_filter' - for curr_name in img_name] + img_names = [curr_name + '_filter' + for curr_name in img_names] if single_echo: - img_name = [curr_name + '_single_echo' - for curr_name in img_name] + img_names = [curr_name + '_single_echo' + for curr_name in img_names] if args.in_B1_map: - img_name = [curr_name + '_B1_corrected' - for curr_name in img_name] + img_names = [curr_name + '_B1_corrected' + for curr_name in img_names] if args.out_prefix: - img_name = [args.out_prefix + '_' + curr_name - for curr_name in img_name] + img_names = [args.out_prefix + '_' + curr_name + for curr_name in img_names] - for img_to_save, name in zip(img_data, img_name): - nib.save(nib.Nifti1Image(img_to_save.astype(np.float32), - affine), + for img_to_save, name in zip(img_data_list, img_names): + nib.save(nib.Nifti1Image(img_to_save.astype(np.float32), affine), os.path.join(output_dir, name + '.nii.gz')) diff --git a/scripts/scil_mti_maps_ihMT.py b/scripts/scil_mti_maps_ihMT.py index 72320dca3..0459937e9 100755 --- a/scripts/scil_mti_maps_ihMT.py +++ b/scripts/scil_mti_maps_ihMT.py @@ -86,24 +86,19 @@ import argparse import logging import os -import sys import nibabel as nib import numpy as np -from scilpy.io.utils import (get_acq_parameters, add_overwrite_arg, +from scilpy.io.mti import add_common_args_mti, verifications_and_loading_mti +from scilpy.io.utils import (add_overwrite_arg, assert_inputs_exist, add_verbose_arg, assert_output_dirs_exist_and_empty) -from scilpy.io.image import load_img -from scilpy.image.volume_math import concatenate -from scilpy.reconst.mti import (adjust_B1_map_intensities, - apply_B1_corr_empiric, +from scilpy.reconst.mti import (apply_B1_corr_empiric, apply_B1_corr_model_based, compute_ratio_map, compute_saturation_map, - process_contrast_map, - threshold_map, - smooth_B1_map) + threshold_map) EPILOG = """ Varma G, Girard OM, Prevost VH, Grant AK, Duhamel G, Alsop DC. @@ -127,16 +122,10 @@ def _build_arg_parser(): formatter_class=argparse.RawTextHelpFormatter) p.add_argument('out_dir', help='Path to output folder.') - p.add_argument('--out_prefix', help='Prefix to be used for each output image.') p.add_argument('--mask', help='Path to the binary brain mask.') - p.add_argument('--extended', action='store_true', - help='If set, outputs the folder Complementary_maps.') - p.add_argument('--filtering', action='store_true', - help='Gaussian filtering to remove Gibbs ringing. ' - 'Not recommended.') g = p.add_argument_group(title='Contrast maps', description='Path to ' 'echoes corresponding to contrast images. All ' @@ -168,54 +157,7 @@ def _build_arg_parser(): 'calculation of MTsat and ihMTsat. \nAcquisition ' 'parameters should also be set with this image.') - a = p.add_argument_group(title='Acquisition parameters', - description='Acquisition parameters required ' - 'for MTsat and ihMTsat ' - 'calculation. \nThese are the ' - 'excitation flip angles ' - '(a_PD, a_T1), in DEGREES, and \n' - 'repetition times (TR_PD, TR_T1) of ' - 'the PD and T1 images, in SECONDS. ' - '\nCan be given through json files ' - '(--in_jsons) or directly ' - '(--in_acq_parameters).') - a1 = a.add_mutually_exclusive_group(required='--in_mtoff_t1' in sys.argv) - a1.add_argument('--in_jsons', nargs=2, - metavar=('PD_json', 'T1_json'), - help='Path to MToff PD json file and MToff T1 json file, ' - 'in that order. \nThe acquisition parameters will be ' - 'extracted from these files. \nMust come from a ' - 'Philips acquisition, otherwise, use ' - 'in_acq_parameters.') - a1.add_argument('--in_acq_parameters', nargs=4, type=float, - metavar=('PD flip angle', 'T1 flip angle', - 'PD repetition time', 'T1 repetition time'), - help='Acquisition parameters in that order: flip angle of ' - 'mtoff_PD, \nflip angle of mtoff_T1, repetition time ' - 'of mtoff_PD, \nrepetition time of mtoff_T1') - - b = p.add_argument_group(title='B1 correction') - b.add_argument('--in_B1_map', - help='Path to B1 coregister map to MT contrasts.') - b.add_argument('--B1_correction_method', - choices=['empiric', 'model_based'], default='empiric', - help='Choice of B1 correction method. Choose between ' - 'empiric and model-based. \nNote that the model-based ' - 'method requires a B1 fitvalues file. \nBoth method ' - 'will only correct the saturation measures. ' - '[%(default)s]') - b.add_argument('--B1_fitvalues', nargs=3, - help='Path to B1 fitvalues files obtained externally. ' - 'Should be three .mat \nfiles given in this specific ' - 'order: positive frequency saturation, \nnegative ' - 'frequency saturation, dual frequency saturation.') - b.add_argument('--B1_nominal', default=100, type=float, - help='Nominal value for the B1 map. For Philips, should be ' - '100. [%(default)s]') - b.add_argument('--B1_smooth_dims', default=5, type=int, - help='Dimension of the squared window used for B1 ' - 'smoothing, in number of voxels. [%(default)s]') - + add_common_args_mti(p) add_verbose_arg(p) add_overwrite_arg(p) @@ -228,6 +170,7 @@ def main(): logging.getLogger().setLevel(logging.getLevelName(args.verbose)) output_dir = os.path.join(args.out_dir, 'ihMT_native_maps') + extended_dir = None if args.extended: extended_dir = os.path.join(args.out_dir, 'Complementary_maps') assert_output_dirs_exist_and_empty(parser, args, extended_dir, @@ -241,106 +184,27 @@ def main(): else: out_prefix = "" - # Merge all echos path into a list - input_maps = [args.in_altnp, args.in_altpn, args.in_negative, - args.in_positive, args.in_mtoff_pd] - maps_flat = (args.in_altnp + args.in_altpn + args.in_negative + - args.in_positive + args.in_mtoff_pd) + # Combine all echos path into a list of lists + input_maps_lists = [args.in_altnp, args.in_altpn, args.in_negative, + args.in_positive, args.in_mtoff_pd] if args.in_mtoff_t1: - input_maps.append(args.in_mtoff_t1) - - # check echoes number and jsons - assert_inputs_exist(parser, maps_flat, optional=args.in_mtoff_t1) - for curr_map in input_maps[1:]: - if len(curr_map) != len(input_maps[0]): - parser.error('Not the same number of echoes per contrast') - if len(input_maps[0]) == 1: - single_echo = True - else: - single_echo = False - - if args.in_B1_map and not args.in_mtoff_t1: - logging.warning('No B1 correction was applied because no MTsat or ' - 'ihMTsat can be computed without the in_mtoff_t1.') - - if args.B1_correction_method == 'model_based' and not args.B1_fitvalues: - parser.error('Fitvalues files must be given when choosing the ' - 'model-based B1 correction method. Please use ' - '--B1_fitvalues.') - - # Set TR and FlipAngle parameters - if args.in_acq_parameters: - flip_angles = np.asarray(args.in_acq_parameters[:2]) * np.pi / 180. - rep_times = np.asarray(args.in_acq_parameters[2:]) * 1000 - if rep_times[0] > 10000 or rep_times[1] > 10000: - logging.warning('Given repetition times do not seem to be given ' - 'in seconds. MTsat results might be affected.') - elif args.in_jsons: - rep_times = [] - flip_angles = [] - for curr_json in args.in_jsons: - acq_parameter = get_acq_parameters(curr_json, - ['RepetitionTime', 'FlipAngle']) - if acq_parameter[0] > 10: - logging.warning('Repetition time found in {} does not seem to ' - 'be given in seconds. MTsat and ihMTsat ' - 'results might be affected.'.format(curr_json)) - rep_times.append(acq_parameter[0] * 1000) # convert ms. - flip_angles.append(acq_parameter[1] * np.pi / 180.) # convert rad. - - # Fix issue from the presence of invalide value and division by zero - np.seterr(divide='ignore', invalid='ignore') - - # Define affine - affine = nib.load(input_maps[4][0]).affine - - # Load B1 image - if args.in_B1_map and args.in_mtoff_t1: - B1_img = nib.load(args.in_B1_map) - B1_map = B1_img.get_fdata(dtype=np.float32) - B1_map = adjust_B1_map_intensities(B1_map, nominal=args.B1_nominal) - B1_map = smooth_B1_map(B1_map, wdims=args.B1_smooth_dims) - if args.B1_correction_method == 'model_based': - # Apply shift to the B1 map for better correction - # shift = 0.05 - # expt = 1.3 - # B1_map = (B1_map + shift) ** expt - # Apply the B1 map to the flip angles for model-based correction - flip_angles[0] *= B1_map - flip_angles[1] *= B1_map - if args.extended: - nib.save(nib.Nifti1Image(B1_map, affine), - os.path.join(extended_dir, out_prefix + "B1_map.nii.gz")) + input_maps_lists.append(args.in_mtoff_t1) + + input_maps_flat_list = [m for _list in input_maps_lists for m in _list] + assert_inputs_exist(parser, input_maps_flat_list, + optional=args.in_mtoff_t1 or [] + [args.mask]) + + # Define affine. Uses the first in_mtoff_pd (required). + affine = nib.load(input_maps_lists[4][0]).affine # Define contrasts maps names contrast_names = ['altnp', 'altpn', 'negative', 'positive', 'mtoff_PD', 'mtoff_T1'] - if args.filtering: - contrast_names = [curr_name + '_filter' - for curr_name in contrast_names] - if single_echo: - contrast_names = [curr_name + '_single_echo' - for curr_name in contrast_names] - if args.out_prefix: - contrast_names = [out_prefix + curr_name - for curr_name in contrast_names] - -# Compute contrasts maps - contrast_maps = [] - for idx, curr_map in enumerate(input_maps): - input_images = [] - for image in curr_map: - img, _ = load_img(image) - input_images.append(img) - merged_curr_map = concatenate(input_images, input_images[0]) - contrast_maps.append(process_contrast_map(merged_curr_map, - filtering=args.filtering, - single_echo=single_echo)) - if args.extended: - nib.save(nib.Nifti1Image(contrast_maps[idx].astype(np.float32), - affine), - os.path.join(extended_dir, - contrast_names[idx] + '.nii.gz')) + + # Other checks, loading, saving contrast_maps. + single_echo, flip_angles, rep_times, B1_map, contrast_maps = \ + verifications_and_loading_mti(args, parser, input_maps_lists, + extended_dir, affine, contrast_names) # Compute ratio maps MTR, ihMTR = compute_ratio_map((contrast_maps[2] + contrast_maps[3]) / 2, @@ -394,8 +258,6 @@ def main(): # Apply empiric B1 correction if args.in_B1_map and args.B1_correction_method == 'empiric': - # MTR = apply_B1_correction_empiric(MTR, B1_map) - # ihMTR = apply_B1_correction_empiric(ihMTR, B1_map) MTsat = apply_B1_corr_empiric(MTsat, B1_map) ihMTsat = apply_B1_corr_empiric(ihMTsat, B1_map) @@ -425,8 +287,7 @@ def main(): for curr_name in img_name] for img_to_save, name in zip(img_data, img_name): - nib.save(nib.Nifti1Image(img_to_save.astype(np.float32), - affine), + nib.save(nib.Nifti1Image(img_to_save.astype(np.float32), affine), os.path.join(output_dir, name + '.nii.gz')) diff --git a/scripts/tests/test_mti_maps_MT.py b/scripts/tests/test_mti_maps_MT.py index f8b77eb76..260deb0a6 100644 --- a/scripts/tests/test_mti_maps_MT.py +++ b/scripts/tests/test_mti_maps_MT.py @@ -11,6 +11,51 @@ tmp_dir = tempfile.TemporaryDirectory() +# Preparing once the filenames. +in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') + +in_mtoff_json = os.path.join(get_home(), + 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') +in_t1w_json = os.path.join(get_home(), + 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') + +in_e1_mtoff = os.path.join(get_home(), + 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') +in_e2_mtoff = os.path.join(get_home(), + 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') +in_e3_mtoff = os.path.join(get_home(), + 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') +in_e4_mtoff = os.path.join(get_home(), + 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') +in_e5_mtoff = os.path.join(get_home(), + 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') + +in_e1_mton = os.path.join(get_home(), + 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') +in_e2_mton = os.path.join(get_home(), + 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') +in_e3_mton = os.path.join(get_home(), + 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') +in_e4_mton = os.path.join(get_home(), + 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') +in_e5_mton = os.path.join(get_home(), + 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') + +in_e1_t1w = os.path.join(get_home(), + 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') +in_e2_t1w = os.path.join(get_home(), + 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') +in_e3_t1w = os.path.join(get_home(), + 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') +in_e4_t1w = os.path.join(get_home(), + 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') +in_e5_t1w = os.path.join(get_home(), + 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') + +in_b1_map = os.path.join(get_home(), 'MT', 'sub-001_run-01_B1map.nii.gz') +in_b1_json = os.path.join(get_home(), 'MT', 'sub-001_run-01_B1map.json') + + def test_help_option(script_runner): ret = script_runner.run('scil_mti_maps_MT.py', '--help') assert ret.success @@ -19,46 +64,6 @@ def test_help_option(script_runner): def test_execution_MT_no_option(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - in_e2_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') - in_e3_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') - in_e4_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') - in_e5_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - in_e2_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') - in_e3_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') - in_e4_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') - in_e5_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - in_e2_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') - in_e3_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') - in_e4_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') - in_e5_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') - # no option ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, @@ -76,46 +81,6 @@ def test_execution_MT_no_option(script_runner): def test_execution_MT_prefix(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - in_e2_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') - in_e3_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') - in_e4_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') - in_e5_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - in_e2_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') - in_e3_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') - in_e4_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') - in_e5_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - in_e2_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') - in_e3_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') - in_e4_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') - in_e5_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') - # --out_prefix ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, @@ -134,46 +99,6 @@ def test_execution_MT_prefix(script_runner): def test_execution_MT_extended(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - in_e2_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') - in_e3_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') - in_e4_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') - in_e5_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - in_e2_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') - in_e3_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') - in_e4_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') - in_e5_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - in_e2_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') - in_e3_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') - in_e4_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') - in_e5_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') - # --extended ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, @@ -192,46 +117,6 @@ def test_execution_MT_extended(script_runner): def test_execution_MT_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - in_e2_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') - in_e3_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') - in_e4_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') - in_e5_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - in_e2_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') - in_e3_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') - in_e4_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') - in_e5_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - in_e2_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') - in_e3_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') - in_e4_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') - in_e5_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') - # --filtering ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, @@ -250,50 +135,6 @@ def test_execution_MT_filtering(script_runner): def test_execution_MT_B1_map(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - in_e2_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') - in_e3_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') - in_e4_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') - in_e5_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - in_e2_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') - in_e3_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') - in_e4_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') - in_e5_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - in_e2_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') - in_e3_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') - in_e4_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') - in_e5_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') - - in_b1_map = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.nii.gz') - in_b1_json = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.json') out_b1_map = tmp_dir.name + '/B1map.nii.gz' # Temporary trick to have the B1 map with proper header. @@ -322,46 +163,6 @@ def test_execution_MT_B1_map(script_runner): def test_execution_MT_wrong_echoes(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - in_e2_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') - in_e3_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') - in_e4_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') - in_e5_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - in_e2_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') - in_e3_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') - in_e4_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') - in_e5_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - in_e2_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') - in_e3_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') - in_e4_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') - in_e5_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') - # Wrong number of echoes for negative ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, @@ -381,22 +182,6 @@ def test_execution_MT_wrong_echoes(script_runner): def test_execution_MT_single_echoe(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - # Single echoe ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, @@ -412,23 +197,6 @@ def test_execution_MT_single_echoe(script_runner): def test_execution_MT_B1_not_T1(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - - in_b1_map = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.nii.gz') - in_b1_json = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.json') out_b1_map = tmp_dir.name + '/B1map.nii.gz' # Temporary trick to have the B1 map with proper header. @@ -451,26 +219,6 @@ def test_execution_MT_B1_not_T1(script_runner): def test_execution_MT_B1_no_fit(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - - in_b1_map = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.nii.gz') - in_b1_json = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.json') out_b1_map = tmp_dir.name + '/B1map.nii.gz' # Temporary trick to have the B1 map with proper header. @@ -494,22 +242,6 @@ def test_execution_MT_B1_no_fit(script_runner): def test_execution_MT_acq_params(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') - - in_mtoff_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') - in_t1w_json = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') - - in_e1_mtoff = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') - - in_e1_mton = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') - - in_e1_t1w = os.path.join(get_home(), - 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') - # Acquisition parameters ret = script_runner.run('scil_mti_maps_MT.py', tmp_dir.name, '--mask', in_mask, diff --git a/scripts/tests/test_mti_maps_ihMT.py b/scripts/tests/test_mti_maps_ihMT.py index 960a39bbb..c074fe740 100644 --- a/scripts/tests/test_mti_maps_ihMT.py +++ b/scripts/tests/test_mti_maps_ihMT.py @@ -10,6 +10,60 @@ fetch_data(get_testing_files_dict(), keys=['ihMT.zip']) tmp_dir = tempfile.TemporaryDirectory() +# Preparing once the filenames. + +in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') + +in_mtoff_pd_json = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-mtoff_ihmt.json') +in_mtoff_t1_json = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-T1w_ihmt.json') + +in_e1_altnp = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') +in_e2_altnp = os.path.join(get_home(), + 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') +in_e3_altnp = os.path.join(get_home(), + 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') + +in_e1_altpn = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') +in_e2_altpn = os.path.join(get_home(), + 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') +in_e3_altpn = os.path.join(get_home(), + 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') + +in_e1_mtoff_pd = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') +in_e2_mtoff_pd = os.path.join(get_home(), + 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') +in_e3_mtoff_pd = os.path.join(get_home(), + 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') + +in_e1_neg = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') +in_e2_neg = os.path.join(get_home(), + 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') +in_e3_neg = os.path.join(get_home(), + 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') + +in_e1_pos = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') +in_e2_pos = os.path.join(get_home(), + 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') +in_e3_pos = os.path.join(get_home(), + 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') + +in_e1_mtoff_t1 = os.path.join(get_home(), + 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') +in_e2_mtoff_t1 = os.path.join(get_home(), + 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') +in_e3_mtoff_t1 = os.path.join(get_home(), + 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') + +in_b1_map = os.path.join(get_home(), 'ihMT', 'B1map.nii.gz') +in_b1_json = os.path.join(get_home(), 'MT', 'sub-001_run-01_B1map.json') + def test_help_option(script_runner): ret = script_runner.run('scil_mti_maps_ihMT.py', '--help') @@ -19,55 +73,6 @@ def test_help_option(script_runner): def test_execution_ihMT_no_option(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - in_e3_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') - # no option ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, @@ -90,55 +95,6 @@ def test_execution_ihMT_no_option(script_runner): def test_execution_ihMT_prefix(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - in_e3_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') - # --out_prefix ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, @@ -164,55 +120,6 @@ def test_execution_ihMT_prefix(script_runner): def test_execution_ihMT_extended(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - in_e3_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') - # --extended ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, @@ -238,55 +145,6 @@ def test_execution_ihMT_extended(script_runner): def test_execution_ihMT_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - in_e3_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') - # --filtering ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, @@ -311,59 +169,6 @@ def test_execution_ihMT_filtering(script_runner): def test_execution_ihMT_B1_map(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - in_e3_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') - - in_b1_map = os.path.join(get_home(), - 'ihMT', 'B1map.nii.gz') - in_b1_json = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.json') out_b1_map = tmp_dir.name + '/B1map.nii.gz' # Temporary trick to have the B1 map with proper header. @@ -394,52 +199,6 @@ def test_execution_ihMT_B1_map(script_runner): def test_execution_ihMT_B1_no_T1(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_b1_map = os.path.join(get_home(), - 'ihMT', 'B1map.nii.gz') - in_b1_json = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.json') out_b1_map = tmp_dir.name + '/B1map.nii.gz' # Temporary trick to have the B1 map with proper header. @@ -467,53 +226,6 @@ def test_execution_ihMT_B1_no_T1(script_runner): def test_execution_ihMT_wrong_echoes(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, '--in_altnp', in_e1_altnp, in_e2_altnp, @@ -534,59 +246,6 @@ def test_execution_ihMT_wrong_echoes(script_runner): def test_execution_ihMT_B1_no_fit(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - in_e2_altnp = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') - in_e3_altnp = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - in_e2_altpn = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') - in_e3_altpn = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - in_e2_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') - in_e3_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - in_e2_neg = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') - in_e3_neg = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - in_e2_pos = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') - in_e3_pos = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - in_e2_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') - in_e3_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') - - in_b1_map = os.path.join(get_home(), - 'ihMT', 'B1map.nii.gz') - in_b1_json = os.path.join(get_home(), - 'MT', 'sub-001_run-01_B1map.json') out_b1_map = tmp_dir.name + '/B1map.nii.gz' # Temporary trick to have the B1 map with proper header. @@ -617,31 +276,6 @@ def test_execution_ihMT_B1_no_fit(script_runner): def test_execution_ihMT_single_echo(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_mtoff_pd_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.json') - in_mtoff_t1_json = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.json') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, '--in_altnp', in_e1_altnp, @@ -659,26 +293,6 @@ def test_execution_ihMT_single_echo(script_runner): def test_execution_ihMT_acq_params(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') - - in_e1_altnp = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') - - in_e1_altpn = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') - - in_e1_mtoff_pd = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') - - in_e1_neg = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') - - in_e1_pos = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') - - in_e1_mtoff_t1 = os.path.join(get_home(), - 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') - ret = script_runner.run('scil_mti_maps_ihMT.py', tmp_dir.name, '--mask', in_mask, '--in_altnp', in_e1_altnp, From 399e3289cd1759c68b071ffe30b5aaf2f87a472f Mon Sep 17 00:00:00 2001 From: karp2601 Date: Thu, 29 Feb 2024 15:16:11 -0500 Subject: [PATCH 02/38] Removing peak_vals, adding future test, updating doc --- scripts/scil_gradients_validate_correct.py | 31 ++++++++----------- .../tests/test_gradients_validate_correct.py | 7 ++++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/scil_gradients_validate_correct.py b/scripts/scil_gradients_validate_correct.py index 41e092911..188f2af82 100755 --- a/scripts/scil_gradients_validate_correct.py +++ b/scripts/scil_gradients_validate_correct.py @@ -15,8 +15,10 @@ to the highest eigenvalue at each voxel. It is also possible to use a file containing multiple principal directions per -voxel, given that the amplitude of each direction is also given with the -argument --peaks_vals. +voxel, given that they are sorted by decreasing amplitude. In that case, the +first direction (with the highest amplitude) will be chosen for validation. +Only 4D data is supported, so the directions must be stored in a single +dimension. For example, peaks.nii.gz from scil_fodf_metrics.py could be used. Formerly: scil_validate_and_correct_bvecs.py """ @@ -58,12 +60,9 @@ def _build_arg_parser(): p.add_argument('--mask', help='Path to an optional mask. If set, FA and Peaks will ' 'only be used inside the mask.') - p.add_argument('--peaks_vals', - help='Path to peaks values file. If more than one peak per ' - 'voxel is found, the maximal peak only will be used.') - p.add_argument('--fa_th', default=0.2, type=float, + p.add_argument('--fa_threshold', default=0.2, type=float, help='FA threshold. Only voxels with FA higher ' - 'than fa_th will be considered. [%(default)s]') + 'than fa_threshold will be considered. [%(default)s]') p.add_argument('--column_wise', action='store_true', help='Specify if input peaks are column-wise (..., 3, N) ' 'instead of row-wise (..., N, 3).') @@ -79,7 +78,7 @@ def main(): logging.getLogger().setLevel(logging.getLevelName(args.verbose)) inputs = [args.in_bvec, args.in_peaks, args.in_FA] - optional = [args.mask, args.peaks_vals] + optional = [args.mask] assert_inputs_exist(parser, inputs, optional=optional) assert_outputs_exist(parser, args, args.out_bvec) @@ -88,6 +87,11 @@ def main(): fa = nib.load(args.in_FA).get_fdata() peaks = nib.load(args.in_peaks).get_fdata() + if peaks.shape[-1] > 3: + logging.info('More than one principal direction per voxel was given.') + peaks = peaks[..., 0:3] + logging.info('The first peak is assumed to be the biggest.') + # convert peaks to a volume of shape (H, W, D, N, 3) if args.column_wise: peaks = np.reshape(peaks, peaks.shape[:3] + (3, -1)) @@ -95,22 +99,13 @@ def main(): else: peaks = np.reshape(peaks, peaks.shape[:3] + (-1, 3)) - N = peaks.shape[3] - if N > 1: - if not args.peaks_vals: - parser.error('More than one principal direction per voxel. Specify' - ' peaks values with --peaks_vals to proceed.') - peaks_vals = nib.load(args.peaks_vals).get_fdata() - indices_max = np.argmax(peaks_vals, axis=-1)[..., None, None] - peaks = np.take_along_axis(peaks, indices_max, axis=-2) - peaks = np.squeeze(peaks) if args.mask: mask = get_data_as_mask(nib.load(args.mask)) fa[np.logical_not(mask)] = 0 peaks[np.logical_not(mask)] = 0 - peaks[fa < args.fa_th] = 0 + peaks[fa < args.fa_threshold] = 0 coherence, transform = compute_fiber_coherence_table(peaks, fa) best_t = transform[np.argmax(coherence)] diff --git a/scripts/tests/test_gradients_validate_correct.py b/scripts/tests/test_gradients_validate_correct.py index 9cf144f56..c07addc06 100644 --- a/scripts/tests/test_gradients_validate_correct.py +++ b/scripts/tests/test_gradients_validate_correct.py @@ -16,7 +16,7 @@ def test_help_option(script_runner): assert ret.success -def test_execution_processing(script_runner): +def test_execution_processing_dti_peaks(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop_1000.nii.gz') @@ -33,3 +33,8 @@ def test_execution_processing(script_runner): ret = script_runner.run('scil_gradients_validate_correct.py', in_bvec, 'evecs_v1.nii.gz', 'fa.nii.gz', 'bvec_corr', '-v') assert ret.success + + +def test_execution_processing_fodf_peaks(): + # ToDo + pass \ No newline at end of file From 6079de600832119f2d3601115bf0905da2734456 Mon Sep 17 00:00:00 2001 From: karp2601 Date: Thu, 29 Feb 2024 15:22:30 -0500 Subject: [PATCH 03/38] Fixing pep8 --- scripts/tests/test_gradients_validate_correct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/test_gradients_validate_correct.py b/scripts/tests/test_gradients_validate_correct.py index c07addc06..7d71b8091 100644 --- a/scripts/tests/test_gradients_validate_correct.py +++ b/scripts/tests/test_gradients_validate_correct.py @@ -37,4 +37,4 @@ def test_execution_processing_dti_peaks(script_runner): def test_execution_processing_fodf_peaks(): # ToDo - pass \ No newline at end of file + pass From fce54f8e23b3435d22e98f2d651f9d4550fe66f4 Mon Sep 17 00:00:00 2001 From: Philippe Karan Date: Fri, 1 Mar 2024 07:31:08 -0500 Subject: [PATCH 04/38] Adding test --- scripts/tests/test_gradients_validate_correct.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/tests/test_gradients_validate_correct.py b/scripts/tests/test_gradients_validate_correct.py index 7d71b8091..211f7a618 100644 --- a/scripts/tests/test_gradients_validate_correct.py +++ b/scripts/tests/test_gradients_validate_correct.py @@ -35,6 +35,16 @@ def test_execution_processing_dti_peaks(script_runner): assert ret.success -def test_execution_processing_fodf_peaks(): - # ToDo - pass +def test_execution_processing_fodf_peaks(script_runner): + os.chdir(os.path.expanduser(tmp_dir.name)) + in_bvec = os.path.join(get_home(), 'processing', + 'dwi.bvec') + in_peaks = os.path.join(get_home(), 'processing', + 'peaks.nii.gz') + in_fa = os.path.join(get_home(), 'processing', + 'fa.nii.gz') + + # test the actual script + ret = script_runner.run('scil_gradients_validate_correct.py', in_bvec, + in_peaks, in_fa, 'bvec_corr_fodf', '-v') + assert ret.success From 98f70c36f17fb495e98cc2bbaf3bcd850fe3e6cb Mon Sep 17 00:00:00 2001 From: Philippe Karan Date: Fri, 1 Mar 2024 08:02:21 -0500 Subject: [PATCH 05/38] Adding msmt support and test --- scripts/scil_frf_mean.py | 18 ++++++++++++++---- scripts/tests/test_frf_mean.py | 25 ++++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/scripts/scil_frf_mean.py b/scripts/scil_frf_mean.py index 2b62f62d7..86ced4d2d 100755 --- a/scripts/scil_frf_mean.py +++ b/scripts/scil_frf_mean.py @@ -5,6 +5,10 @@ Compute the mean Fiber Response Function from a set of individually computed Response Functions. +The FRF files are obtained from scil_frf_ssst.py, scil_frf_msmt.py in the +case of multi-shell data or scil_frf_memsmt.py in the case of multi-encoding +multi-shell data. + Formerly: scil_compute_mean_frf.py """ @@ -43,14 +47,20 @@ def main(): assert_inputs_exist(parser, args.frf_files) assert_outputs_exist(parser, args, args.mean_frf) - all_frfs = np.zeros((len(args.frf_files), 4)) + frf_shape = np.loadtxt(args.frf_files[0]).shape + all_frfs = np.zeros((len(args.frf_files),) + frf_shape) for idx, frf_file in enumerate(args.frf_files): frf = np.loadtxt(frf_file) - if not frf.shape[0] == 4: - raise ValueError('FRF file {} did not contain 4 elements. Invalid ' - 'or deprecated FRF format'.format(frf_file)) + if not frf.shape[-1] == 4: + raise ValueError('FRF file {} did not contain 4 elements per ' + 'line. Invalid or deprecated FRF format.' + .format(frf_file)) + + if not frf.shape == frf_shape: + raise ValueError('FRF file {} did not match the format of ' + 'previous files.'.format(frf_file)) all_frfs[idx] = frf diff --git a/scripts/tests/test_frf_mean.py b/scripts/tests/test_frf_mean.py index 25eaaf566..38fb77923 100644 --- a/scripts/tests/test_frf_mean.py +++ b/scripts/tests/test_frf_mean.py @@ -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() @@ -16,9 +17,23 @@ 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_mean.py', in_frf, 'mfrf.txt') + in_frf = os.path.join(get_home(), 'processing', 'frf.txt') + ret = script_runner.run('scil_frf_mean.py', in_frf, in_frf, 'mfrf1.txt') 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_mean.py', in_frf, in_frf, 'mfrf2.txt') + assert ret.success + + +def test_execution_processing_bad_input(script_runner): + os.chdir(os.path.expanduser(tmp_dir.name)) + in_wm_frf = os.path.join(get_home(), 'commit_amico', 'wm_frf.txt') + in_frf = os.path.join(get_home(), 'processing', 'frf.txt') + ret = script_runner.run('scil_frf_mean.py', in_wm_frf, in_frf, 'mfrf3.txt') + assert not ret.success From 1dad90c88759be7e707a0d1a0a3deddf44d915b1 Mon Sep 17 00:00:00 2001 From: Philippe Karan Date: Fri, 1 Mar 2024 08:03:57 -0500 Subject: [PATCH 06/38] Pep8 --- scripts/scil_frf_mean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scil_frf_mean.py b/scripts/scil_frf_mean.py index 86ced4d2d..0005a665c 100755 --- a/scripts/scil_frf_mean.py +++ b/scripts/scil_frf_mean.py @@ -57,7 +57,7 @@ def main(): raise ValueError('FRF file {} did not contain 4 elements per ' 'line. Invalid or deprecated FRF format.' .format(frf_file)) - + if not frf.shape == frf_shape: raise ValueError('FRF file {} did not match the format of ' 'previous files.'.format(frf_file)) From e1686ebe55c79e41b17d13a26a8da5e189cd0915 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 26 Feb 2024 15:34:38 -0500 Subject: [PATCH 07/38] fodf_max_in_ventricles: not sending args to method --- scilpy/reconst/fodf.py | 36 ++++++++++++++++---------- scripts/scil_fodf_max_in_ventricles.py | 31 +++++++++++----------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/scilpy/reconst/fodf.py b/scilpy/reconst/fodf.py index 0afe48915..8bed69930 100644 --- a/scilpy/reconst/fodf.py +++ b/scilpy/reconst/fodf.py @@ -15,14 +15,13 @@ cvx, have_cvxpy, _ = optional_package("cvxpy") -def get_ventricles_max_fodf(data, fa, md, zoom, sh_basis, args, - is_legacy=True): +def get_ventricles_max_fodf(data, fa, md, zoom, sh_basis, small_dims, + fa_threshold, md_threshold, is_legacy=True): """ - Compute mean maximal fodf value in ventricules. Given - heuristics thresholds on FA and MD values, finds the - voxels of the ventricules or CSF and computes a mean - fODF value. This is described in - Dell'Acqua et al HBM 2013. + Compute mean maximal fodf value in ventricules. Given heuristics thresholds + on FA and MD values, finds the voxels of the ventricules or CSF and + computes a mean fODF value. This is described in + Dell'Acqua et al. HBM 2013. Parameters ---------- @@ -32,18 +31,27 @@ def get_ventricles_max_fodf(data, fa, md, zoom, sh_basis, args, FA (Fractional Anisotropy) volume from DTI md: ndarray (x, y, z) MD (Mean Diffusivity) volume from DTI - zoom: int > 0 - Maximum number of voxels used to compute the mean. - 1000 works well at 2x2x2 = 8 mm3 + zoom: List of length 3 + The resolution. A total number of voxels of 1000 works well at + 2x2x2 = 8 mm3. sh_basis: str Either 'tournier07' or 'descoteaux07' + small_dims: bool + If set, takes the full range of data to search the max fodf amplitude + in ventricles. Useful when the data has small dimensions. + fa_threshold: float + Maximal threshold of FA (voxels under that threshold are considered + for evaluation). + md_threshold: float + Minimal threshold of MD in mm2/s (voxels above that threshold are + considered for evaluation). is_legacy : bool, optional Whether or not the SH basis is in its legacy form. Returns ------- mean, mask: int, ndarray (x, y, z) - Mean maximum fODF value and mask of voxels used + Mean maximum fODF value and mask of voxels used. """ order = find_order_from_nb_coeff(data) @@ -72,7 +80,7 @@ def get_ventricles_max_fodf(data, fa, md, zoom, sh_basis, args, # In the case of 2D-like data (3D data with one dimension size of 1), or # a small 3D dataset, the full range of data is scanned. - if args.small_dims: + if small_dims: all_i = list(range(0, data.shape[0])) all_j = list(range(0, data.shape[1])) all_k = list(range(0, data.shape[2])) @@ -90,8 +98,8 @@ def get_ventricles_max_fodf(data, fa, md, zoom, sh_basis, args, for k in all_k: if count > max_number_of_voxels - 1: continue - if fa[i, j, k] < args.fa_threshold \ - and md[i, j, k] > args.md_threshold: + if fa[i, j, k] < fa_threshold \ + and md[i, j, k] > md_threshold: sf = np.dot(data[i, j, k], b_matrix) sum_of_max += sf.max() count += 1 diff --git a/scripts/scil_fodf_max_in_ventricles.py b/scripts/scil_fodf_max_in_ventricles.py index b4b4aef58..4fb8ba430 100755 --- a/scripts/scil_fodf_max_in_ventricles.py +++ b/scripts/scil_fodf_max_in_ventricles.py @@ -3,7 +3,7 @@ """ Script to compute the maximum fODF in the ventricles. The ventricules are -estimated from a MD and FA threshold. +estimated from an MD and FA threshold. This allows to clip the noise of fODF using an absolute thresold. @@ -41,25 +41,23 @@ def _build_arg_parser(): p.add_argument('in_md', metavar='MD', help='Path to the mean diffusivity (MD) volume.') - p.add_argument('--fa_t', dest='fa_threshold', - type=float, default='0.1', - help='Maximal threshold of FA (voxels under that threshold' - ' are considered for evaluation, [%(default)s]).') - p.add_argument('--md_t', dest='md_threshold', - type=float, default='0.003', + p.add_argument('--fa_threshold', type=float, default='0.1', + help='Maximal threshold of FA (voxels under that threshold ' + 'are considered \nfor evaluation. [%(default)s]).') + p.add_argument('--md_threshold', type=float, default='0.003', help='Minimal threshold of MD in mm2/s (voxels above that ' - 'threshold are considered for ' - 'evaluation, [%(default)s]).') + 'threshold are \nconsidered for ' + 'evaluation. [%(default)s]).') p.add_argument('--max_value_output', metavar='file', help='Output path for the text file containing the value. ' - 'If not set the file will not be saved.') + 'If not set the \nfile will not be saved.') p.add_argument('--mask_output', metavar='file', help='Output path for the ventricule mask. If not set, ' - 'the mask will not be saved.') + 'the mask \nwill not be saved.') p.add_argument('--small_dims', action='store_true', help='If set, takes the full range of data to search the ' - 'max fodf amplitude in ventricles. Useful when the ' - 'data is 2D or has small dimensions.') + 'max fodf amplitude \nin ventricles. Useful when the ' + 'data has small dimensions.') add_sh_basis_args(p) add_verbose_arg(p) @@ -80,7 +78,6 @@ def main(): # Load input image img_fODFs = nib.load(args.in_fodfs) fodf = img_fODFs.get_fdata(dtype=np.float32) - affine = img_fODFs.affine zoom = img_fODFs.header.get_zooms()[:3] img_fa = nib.load(args.in_fa) @@ -91,11 +88,13 @@ def main(): sh_basis, is_legacy = parse_sh_basis_arg(args) - value, mask = get_ventricles_max_fodf(fodf, fa, md, zoom, sh_basis, args, + value, mask = get_ventricles_max_fodf(fodf, fa, md, zoom, sh_basis, + args.small_dims, args.fa_treshold, + args.md_threshold, is_legacy=is_legacy) if args.mask_output: - img = nib.Nifti1Image(np.array(mask, 'float32'), affine) + img = nib.Nifti1Image(np.array(mask, 'float32'), img_fODFs.affine) nib.save(img, args.mask_output) if args.max_value_output: From 4d5e4f233007a9fe383d099beb08fe47ad317f7b Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 26 Feb 2024 15:38:53 -0500 Subject: [PATCH 08/38] dwi_to_sh and fodf_metrics already ok! --- scripts/scil_fodf_memsmt.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/scil_fodf_memsmt.py b/scripts/scil_fodf_memsmt.py index 1be056dee..8a2e580f5 100755 --- a/scripts/scil_fodf_memsmt.py +++ b/scripts/scil_fodf_memsmt.py @@ -144,9 +144,7 @@ def main(): 'one file to output.') assert_inputs_exist(parser, [], - optional=list(np.concatenate((args.in_dwis, - args.in_bvals, - args.in_bvecs)))) + [args.in_dwis + args.in_bvals + args.in_bvecs]) assert_outputs_exist(parser, args, arglist) if not (len(args.in_dwis) == len(args.in_bvals) From 2ed95c1ad816d0aa430ec65d540373c7a246dfbb Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 26 Feb 2024 15:41:39 -0500 Subject: [PATCH 09/38] Fodf_metrics: already ok --- scripts/scil_fodf_metrics.py | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/scripts/scil_fodf_metrics.py b/scripts/scil_fodf_metrics.py index 195922b85..79c907b12 100755 --- a/scripts/scil_fodf_metrics.py +++ b/scripts/scil_fodf_metrics.py @@ -115,6 +115,7 @@ def main(): args = parser.parse_args() logging.getLogger().setLevel(logging.getLevelName(args.verbose)) + # Verifications if not args.not_all: args.afd_max = args.afd_max or 'afd_max.nii.gz' args.afd_total = args.afd_total or 'afd_total_sh0.nii.gz' @@ -135,6 +136,7 @@ def main(): assert_inputs_exist(parser, args.in_fODF) assert_outputs_exist(parser, args, arglist) + # Loading vol = nib.load(args.in_fODF) data = vol.get_fdata(dtype=np.float32) affine = vol.affine @@ -168,27 +170,28 @@ def main(): _, _ = maps_from_sh(data, peak_dirs, peak_values, peak_indices, sphere, nbr_processes=args.nbr_processes) - # Save result - if args.nufo: - nib.save(nib.Nifti1Image(nufo_map.astype(np.float32), - affine), args.nufo) + # Save result + if args.nufo: + nib.save(nib.Nifti1Image(nufo_map.astype(np.float32), affine), + args.nufo) - if args.afd_max: - nib.save(nib.Nifti1Image(afd_max.astype(np.float32), - affine), args.afd_max) + if args.afd_max: + nib.save(nib.Nifti1Image(afd_max.astype(np.float32), affine), + args.afd_max) - if args.afd_total: - # this is the analytical afd total - afd_tot = data[:, :, :, 0] - nib.save(nib.Nifti1Image(afd_tot.astype(np.float32), - affine), args.afd_total) + if args.afd_total: + # this is the analytical afd total + afd_tot = data[:, :, :, 0] + nib.save(nib.Nifti1Image(afd_tot.astype(np.float32), affine), + args.afd_total) - if args.afd_sum: - nib.save(nib.Nifti1Image(afd_sum.astype(np.float32), - affine), args.afd_sum) + if args.afd_sum: + nib.save(nib.Nifti1Image(afd_sum.astype(np.float32), affine), + args.afd_sum) - if args.rgb: - nib.save(nib.Nifti1Image(rgb_map.astype('uint8'), affine), args.rgb) + if args.rgb: + nib.save(nib.Nifti1Image(rgb_map.astype('uint8'), affine), + args.rgb) if args.peaks or args.peak_values: if not args.abs_peaks_and_values: From 3bcbf6515a7737712c8990ad20359d5b0709ac41 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 26 Feb 2024 15:47:54 -0500 Subject: [PATCH 10/38] Frf_msmt: already ok! --- scripts/scil_frf_msmt.py | 75 +++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/scripts/scil_frf_msmt.py b/scripts/scil_frf_msmt.py index 2d26a566b..92696ed38 100755 --- a/scripts/scil_frf_msmt.py +++ b/scripts/scil_frf_msmt.py @@ -2,28 +2,25 @@ # -*- coding: utf-8 -*- """ -Compute response functions for multi-shell multi-tissue (MSMT) -constrained spherical deconvolution from DWI data. +Compute response functions for multi-shell multi-tissue (MSMT) constrained +spherical deconvolution from DWI data. The script computes a response function for white-matter (wm), gray-matter (gm), csf and the mean b=0. - -In the wm, we compute the response function in each voxels where -the FA is superior at threshold_fa_wm. - -In the gm (or csf), we compute the response function in each voxels where -the FA is below at threshold_fa_gm (or threshold_fa_csf) and where -the MD is below threshold_md_gm (or threshold_md_csf). + - In the wm, we compute the response function in each voxel where the FA is + superior at threshold_fa_wm. + - In the gm (or csf), we compute the response function in each voxel where + the FA is below at threshold_fa_gm (or threshold_fa_csf) and where the MD + is below threshold_md_gm (or threshold_md_csf). We output one response function file for each tissue, containing the response function for each b-value (arranged by lines). These are saved as the diagonal of the axis-symmetric diffusion tensor (3 e-values) and a mean b0 value. -For example, a typical wm_frf is 15e-4 4e-4 4e-4 700, where the tensor e-values -are (15,4,4)x10^-4 mm^2/s and the mean b0 is 700. +For example, a typical wm_frf is [15e-4, 4e-4, 4e-4, 700], where the tensor +e-values are (15,4,4)x10^-4 mm^2/s and the mean b0 is 700. -Based on B. Jeurissen et al., Multi-tissue constrained spherical -deconvolution for improved analysis of multi-shell diffusion -MRI data. Neuroimage (2014) +Based on B. Jeurissen et al., Multi-tissue constrained spherical deconvolution +for improved analysis of multi-shell diffusion MRI data. Neuroimage (2014) Formerly: scil_compute_msmt_frf.py """ @@ -78,76 +75,63 @@ def _build_arg_parser(): help='Path to the input CSF mask file, used to improve the' ' final CSF frf mask.') - p.add_argument('--fa_thr_wm', - default=0.7, type=float, + p.add_argument('--fa_thr_wm', default=0.7, type=float, help='If supplied, use this threshold to select single WM ' 'fiber voxels from the FA inside the WM mask defined ' ' by mask_wm. Each voxel above this threshold will ' 'be selected. [%(default)s]') - p.add_argument('--fa_thr_gm', - default=0.2, type=float, + p.add_argument('--fa_thr_gm', default=0.2, type=float, help='If supplied, use this threshold to select GM voxels ' 'from the FA inside the GM mask defined by mask_gm. ' 'Each voxel below this threshold will be selected.' ' [%(default)s]') - p.add_argument('--fa_thr_csf', - default=0.1, type=float, + p.add_argument('--fa_thr_csf', default=0.1, type=float, help='If supplied, use this threshold to select CSF voxels ' 'from the FA inside the CSF mask defined by mask_csf. ' 'Each voxel below this threshold will be selected. ' '[%(default)s]') - p.add_argument('--md_thr_gm', - default=0.0007, type=float, + p.add_argument('--md_thr_gm', default=0.0007, type=float, help='If supplied, use this threshold to select GM voxels ' 'from the MD inside the GM mask defined by mask_gm. ' 'Each voxel below this threshold will be selected. ' '[%(default)s]') - p.add_argument('--md_thr_csf', - default=0.003, type=float, + p.add_argument('--md_thr_csf', default=0.003, type=float, help='If supplied, use this threshold to select CSF ' 'voxels from the MD inside the CSF mask defined by ' 'mask_csf. Each voxel below this threshold will be' ' selected. [%(default)s]') - p.add_argument('--min_nvox', - default=100, type=int, + p.add_argument('--min_nvox', default=100, type=int, help='Minimal number of voxels needed for each tissue masks' ' in order to proceed to frf estimation. ' '[%(default)s]') - p.add_argument('--tolerance', - type=int, default=20, + p.add_argument('--tolerance', type=int, default=20, help='The tolerated gap between the b-values to ' 'extract and the current b-value. [%(default)s]') add_skip_b0_check_arg(p, will_overwrite_with_min=False, b0_tol_name='--tolerance') - p.add_argument('--dti_bval_limit', - type=int, default=1200, + p.add_argument('--dti_bval_limit', type=int, default=1200, help='The highest b-value taken for the DTI model. ' '[%(default)s]') - p.add_argument('--roi_radii', - default=[20], nargs='+', type=int, + p.add_argument('--roi_radii', default=[20], nargs='+', type=int, help='If supplied, use those radii to select a cuboid roi ' 'to estimate the response functions. The roi will be ' 'a cuboid spanning from the middle of the volume in ' 'each direction with the different radii. The type is ' 'either an int (e.g. --roi_radii 10) or an array-like ' '(3,) (e.g. --roi_radii 20 30 10). [%(default)s]') - p.add_argument('--roi_center', - metavar='tuple(3)', nargs=3, type=int, + p.add_argument('--roi_center', metavar='tuple(3)', nargs=3, type=int, help='If supplied, use this center to span the cuboid roi ' 'using roi_radii. [center of the 3D volume] ' '(e.g. --roi_center 66 79 79)') - p.add_argument('--wm_frf_mask', - metavar='file', default='', + p.add_argument('--wm_frf_mask', metavar='file', default='', help='Path to the output WM frf mask file, the voxels used ' 'to compute the WM frf.') - p.add_argument('--gm_frf_mask', - metavar='file', default='', + p.add_argument('--gm_frf_mask', metavar='file', default='', help='Path to the output GM frf mask file, the voxels used ' 'to compute the GM frf.') - p.add_argument('--csf_frf_mask', - metavar='file', default='', + p.add_argument('--csf_frf_mask', metavar='file', default='', help='Path to the output CSF frf mask file, the voxels ' 'used to compute the CSF frf.') @@ -162,12 +146,14 @@ def main(): args = parser.parse_args() logging.getLogger().setLevel(logging.getLevelName(args.verbose)) + # Verifications assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec]) assert_outputs_exist(parser, args, [args.out_wm_frf, args.out_gm_frf, args.out_csf_frf]) roi_radii = assert_roi_radii_format(parser) + # Loading vol = nib.load(args.in_dwi) data = vol.get_fdata(dtype=np.float32) bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec) @@ -181,10 +167,9 @@ def main(): skip_b0_check=args.skip_b0_check) list_bvals = unique_bvals_tolerance(bvals, tol=args.tolerance) if not np.all(list_bvals <= dti_lim): - outputs = extract_dwi_shell(vol, bvals, bvecs, - list_bvals[list_bvals <= dti_lim], - tol=args.tolerance) - _, data_dti, bvals_dti, bvecs_dti = outputs + _, data_dti, bvals_dti, bvecs_dti = extract_dwi_shell( + vol, bvals, bvecs, list_bvals[list_bvals <= dti_lim], + tol=args.tolerance) bvals_dti = np.squeeze(bvals_dti) else: data_dti = None @@ -206,6 +191,7 @@ def main(): if args.mask_csf: mask_csf = get_data_as_mask(nib.load(args.mask_csf), dtype=bool) + # Processing responses, frf_masks = compute_msmt_frf(data, bvals, bvecs, data_dti=data_dti, bvals_dti=bvals_dti, @@ -222,6 +208,7 @@ def main(): roi_center=args.roi_center, tol=args.tolerance) + # Saving masks_files = [args.wm_frf_mask, args.gm_frf_mask, args.csf_frf_mask] for mask, mask_file in zip(frf_masks, masks_files): if mask_file: From e3a6fec2f650b3c17f644216338477ed1b87dc7f Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 26 Feb 2024 15:49:08 -0500 Subject: [PATCH 11/38] Frf_ssst: already ok! --- scripts/scil_frf_ssst.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/scil_frf_ssst.py b/scripts/scil_frf_ssst.py index 44f1c62ad..8722bc147 100755 --- a/scripts/scil_frf_ssst.py +++ b/scripts/scil_frf_ssst.py @@ -50,26 +50,22 @@ def _build_arg_parser(): p.add_argument('--mask_wm', help='Path to a binary white matter mask. Only the data ' 'inside this mask \nand above the threshold defined ' - 'by --fa will be used to estimate the \nfiber ' + 'by --fa_thresh will be used to estimate the \nfiber ' 'response function.') - p.add_argument('--fa', dest='fa_thresh', - default=0.7, type=float, + p.add_argument('--fa_thresh', default=0.7, type=float, help='If supplied, use this threshold as the initial ' 'threshold to select \nsingle fiber voxels. ' '[%(default)s]') - p.add_argument('--min_fa', dest='min_fa_thresh', - default=0.5, type=float, + p.add_argument('--min_fa_thresh', default=0.5, type=float, help='If supplied, this is the minimal value that will be ' 'tried when looking \nfor single fiber ' 'voxels. [%(default)s]') - p.add_argument('--min_nvox', - default=300, type=int, + p.add_argument('--min_nvox', default=300, type=int, help='Minimal number of voxels needing to be identified ' 'as single fiber voxels \nin the automatic ' 'estimation. [%(default)s]') - p.add_argument('--roi_radii', - default=[20], nargs='+', type=int, + p.add_argument('--roi_radii', default=[20], nargs='+', type=int, help='If supplied, use those radii to select a cuboid roi ' 'to estimate the \nresponse functions. The roi will ' 'be a cuboid spanning from the middle of \nthe volume ' From 483a55067de3b27c5951c1e240bf8c6847a2ef46 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 26 Feb 2024 15:55:53 -0500 Subject: [PATCH 12/38] Freewater maps ok! Adding test for freewater_priors --- scripts/scil_NODDI_priors.py | 4 ++-- scripts/scil_freewater_maps.py | 18 +++++++----------- scripts/scil_freewater_priors.py | 11 +---------- scripts/tests/test_freewater_priors.py | 7 +++++++ 4 files changed, 17 insertions(+), 23 deletions(-) create mode 100644 scripts/tests/test_freewater_priors.py diff --git a/scripts/scil_NODDI_priors.py b/scripts/scil_NODDI_priors.py index 822d30e7d..9d74b3393 100755 --- a/scripts/scil_NODDI_priors.py +++ b/scripts/scil_NODDI_priors.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """ -Compute the axial (para_diff), radial (perp_diff), -and mean (iso_diff) diffusivity priors for NODDI. +Compute the axial (para_diff), radial (perp_diff), and mean (iso_diff) +diffusivity priors for NODDI. Formerly: scil_compute_NODDI_priors.py """ diff --git a/scripts/scil_freewater_maps.py b/scripts/scil_freewater_maps.py index 50a71caf0..f24c3a94f 100755 --- a/scripts/scil_freewater_maps.py +++ b/scripts/scil_freewater_maps.py @@ -108,31 +108,29 @@ def main(): logging.getLogger().setLevel(logging.getLevelName(args.verbose)) redirected_stdout = redirect_stdout(sys.stdout) + # Verifications if args.compute_only and not args.save_kernels: parser.error('--compute_only must be used with --save_kernels.') assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec], args.mask) - assert_output_dirs_exist_and_empty(parser, args, - args.out_dir, + assert_output_dirs_exist_and_empty(parser, args, args.out_dir, optional=args.save_kernels) - # Generage a scheme file from the bvals and bvecs files + # Generate a scheme file from the bvals and bvecs files tmp_dir = tempfile.TemporaryDirectory() tmp_scheme_filename = os.path.join(tmp_dir.name, 'gradients.b') tmp_bval_filename = os.path.join(tmp_dir.name, 'bval') bvals, _ = read_bvals_bvecs(args.in_bval, args.in_bvec) - shells_centroids, indices_shells = identify_shells(bvals, - args.b_thr, + shells_centroids, indices_shells = identify_shells(bvals, args.b_thr, round_centroids=True) np.savetxt(tmp_bval_filename, shells_centroids[indices_shells], newline=' ', fmt='%i') fsl2mrtrix(tmp_bval_filename, args.in_bvec, tmp_scheme_filename) logging.info( - 'Compute FreeWater with AMICO on {} shells at found at {}.'.format( - len(shells_centroids), - shells_centroids)) + 'Computing FreeWater with AMICO on {} shells at found at {}.'.format( + len(shells_centroids), shells_centroids)) with redirected_stdout: amico.core.setup() @@ -150,9 +148,7 @@ def main(): model_type = 'Mouse' ae.model.set(args.para_diff, - np.linspace(args.perp_diff_min, - args.perp_diff_max, - 10), + np.linspace(args.perp_diff_min, args.perp_diff_max, 10), [args.iso_diff], model_type) diff --git a/scripts/scil_freewater_priors.py b/scripts/scil_freewater_priors.py index 75fd095e3..d0ae218ca 100755 --- a/scripts/scil_freewater_priors.py +++ b/scripts/scil_freewater_priors.py @@ -2,20 +2,11 @@ # -*- coding: utf-8 -*- """ -Compute the axial (para_diff) and mean (iso_diff) diffusivity priors for -freewater. +Synonym for scil_NODDI_priors.py """ from scripts.scil_NODDI_priors import main as noddi_priors_main -EPILOG = """ -Reference: - [1] Zhang H, Schneider T, Wheeler-Kingshott CA, Alexander DC. - NODDI: practical in vivo neurite orientation dispersion - and density imaging of the human brain. - NeuroImage. 2012 Jul 16;61:1000-16. -""" - def main(): noddi_priors_main() diff --git a/scripts/tests/test_freewater_priors.py b/scripts/tests/test_freewater_priors.py new file mode 100644 index 000000000..b2ff43fd6 --- /dev/null +++ b/scripts/tests/test_freewater_priors.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + + +def test_help_option(script_runner): + ret = script_runner.run('scil_freewater_priors.py', '--help') + assert ret.success From 148b612cd3491b6272778a45b0aedc4f943e03fa Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Tue, 27 Feb 2024 09:42:26 -0500 Subject: [PATCH 13/38] Fix: typo --- scripts/scil_fodf_max_in_ventricles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scil_fodf_max_in_ventricles.py b/scripts/scil_fodf_max_in_ventricles.py index 4fb8ba430..717f255c7 100755 --- a/scripts/scil_fodf_max_in_ventricles.py +++ b/scripts/scil_fodf_max_in_ventricles.py @@ -89,7 +89,7 @@ def main(): sh_basis, is_legacy = parse_sh_basis_arg(args) value, mask = get_ventricles_max_fodf(fodf, fa, md, zoom, sh_basis, - args.small_dims, args.fa_treshold, + args.small_dims, args.fa_threshold, args.md_threshold, is_legacy=is_legacy) From 456f648207b3e1c213f4c4eee3d6338687774b90 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Tue, 27 Feb 2024 09:49:17 -0500 Subject: [PATCH 14/38] Fix: list --- scripts/scil_fodf_memsmt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scil_fodf_memsmt.py b/scripts/scil_fodf_memsmt.py index 8a2e580f5..9689d28a0 100755 --- a/scripts/scil_fodf_memsmt.py +++ b/scripts/scil_fodf_memsmt.py @@ -144,7 +144,7 @@ def main(): 'one file to output.') assert_inputs_exist(parser, [], - [args.in_dwis + args.in_bvals + args.in_bvecs]) + args.in_dwis + args.in_bvals + args.in_bvecs) assert_outputs_exist(parser, args, arglist) if not (len(args.in_dwis) == len(args.in_bvals) From a66452cf70a5aa96246c037fddf9f391260e65c5 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 09:54:37 -0500 Subject: [PATCH 15/38] Combine common sections in fodf_memst, frf_msmt. --- scilpy/reconst/fodf.py | 55 +++++++++++++++++++ scilpy/reconst/sh.py | 20 +++++++ scripts/scil_fodf_memsmt.py | 106 +++++++++++++----------------------- scripts/scil_fodf_msmt.py | 69 +++++++---------------- 4 files changed, 132 insertions(+), 118 deletions(-) diff --git a/scilpy/reconst/fodf.py b/scilpy/reconst/fodf.py index 8bed69930..e6b5a9e58 100644 --- a/scilpy/reconst/fodf.py +++ b/scilpy/reconst/fodf.py @@ -188,3 +188,58 @@ def fit_from_model(model, data, mask=None, nbr_processes=None): fit_array = MultiVoxelFit(model, fit_array, mask) return fit_array + + +def verify_failed_voxels_shm_coeff(shm_coeff): + """ + Verifies if there are any NaN in the final coefficients, and if so raises + warnings. + """ + nan_count = len(np.argwhere(np.isnan(shm_coeff[..., 0]))) + voxel_count = np.prod(shm_coeff.shape[:-1]) + + if nan_count / voxel_count >= 0.05: + logging.warning( + "There are {} voxels out of {} that could not be solved by the " + "solver, reaching a critical amount of voxels. Make sure to tune " + "the response functions properly, as the solving process is very " + "sensitive to it. Proceeding to fill the problematic voxels by 0." + .format(nan_count, voxel_count)) + elif nan_count > 0: + logging.warning( + "There are {} voxels out of {} that could not be solved by the " + "solver. Make sure to tune the response functions properly, as " + "the solving process is very sensitive to it. Proceeding to fill " + "the problematic voxels by 0.".format(nan_count, voxel_count)) + + shm_coeff = np.where(np.isnan(shm_coeff), 0, shm_coeff) + return shm_coeff + + +def verify_frf_files(wm_frf, gm_frf, csf_frf): + """ + Verifies that all three frf files contain four columns, else raises + ValueErrors. + + Parameters + ---------- + wm_frf: np.ndarray + gm_frf: np.ndarray + csf_frf: np.ndarray + """ + if len(wm_frf.shape) == 1: + wm_frf = wm_frf[None, :] + if len(gm_frf.shape) == 1: + gm_frf = gm_frf[None, :] + if len(csf_frf.shape) == 1: + csf_frf = csf_frf[None, :] + + if not wm_frf.shape[1] == 4: + raise ValueError('WM frf file did not contain 4 elements. ' + 'Invalid or deprecated FRF format') + if not gm_frf.shape[1] == 4: + raise ValueError('GM frf file did not contain 4 elements. ' + 'Invalid or deprecated FRF format') + if not csf_frf.shape[1] == 4: + raise ValueError('CSF frf file did not contain 4 elements. ' + 'Invalid or deprecated FRF format') \ No newline at end of file diff --git a/scilpy/reconst/sh.py b/scilpy/reconst/sh.py index b25be9a0d..b0cb5b72f 100644 --- a/scilpy/reconst/sh.py +++ b/scilpy/reconst/sh.py @@ -17,6 +17,26 @@ from scilpy.dwi.operations import compute_dwi_attenuation +def verify_data_vs_sh_order(data, sh_order): + """ + Raises a warning if the dwi data shape is not enough for the chosen + sh_order. + + Parameters + ---------- + data: np.ndarray + Diffusion signal as weighted images (4D). + sh_order: int + SH order to fit, by default 4. + """ + if data.shape[-1] < (sh_order + 1) * (sh_order + 2) / 2: + logging.warning( + 'We recommend having at least {} unique DWIs volumes, but you ' + 'currently have {} volumes. Try lowering the parameter --sh_order ' + 'in case of non convergence.'.format( + (sh_order + 1) * (sh_order + 2) / 2, data.shape[-1])) + + def compute_sh_coefficients(dwi, gradient_table, b0_threshold=DEFAULT_B0_THRESHOLD, sh_order=4, basis_type='descoteaux07', smooth=0.006, diff --git a/scripts/scil_fodf_memsmt.py b/scripts/scil_fodf_memsmt.py index 9689d28a0..5f45f61af 100755 --- a/scripts/scil_fodf_memsmt.py +++ b/scripts/scil_fodf_memsmt.py @@ -3,10 +3,11 @@ """ Script to compute multi-encoding multi-shell multi-tissue (memsmt) -Constrained Spherical Deconvolution ODFs. In order to operate, -the script only needs the data from one type of b-tensor encoding. However, -giving only a spherical one will not produce good fODFs, as it only probes -spherical shapes. As for planar encoding, it should technically +Constrained Spherical Deconvolution ODFs. + +In order to operate, the script only needs the data from one type of b-tensor +encoding. However, giving only a spherical one will not produce good fODFs, as +it only probes spherical shapes. As for planar encoding, it should technically work alone, but seems to be very sensitive to noise and is yet to be properly documented. We thus suggest to always use at least the linear encoding, which will be equivalent to standard multi-shell multi-tissue if used alone, in @@ -14,10 +15,11 @@ supported, so that only the linear tensor encoding (LTE, b_delta = 1), the planar tensor encoding (PTE, b_delta = -0.5), the spherical tensor encoding (STE, b_delta = 0) and the cigar shape tensor encoding (b_delta = 0.5) are -available. Moreover, all of `--in_dwis`, `--in_bvals`, `--in_bvecs` and -`--in_bdeltas` must have the same number of arguments. Be sure to keep the -same order of encodings throughout all these inputs and to set `--in_bdeltas` -accordingly (IMPORTANT). +available. + +All of `--in_dwis`, `--in_bvals`, `--in_bvecs` and `--in_bdeltas` must have the +same number of arguments. Be sure to keep the same order of encodings +throughout all these inputs and to set `--in_bdeltas` accordingly (IMPORTANT). By default, will output all possible files, using default names. Specific names can be specified using the file flags specified in the @@ -50,12 +52,14 @@ convert_bdelta_to_bshape) from scilpy.io.image import get_data_as_mask from scilpy.io.utils import (add_overwrite_arg, add_processes_arg, + add_sh_basis_args, add_skip_b0_check_arg, + add_tolerance_arg, add_verbose_arg, assert_inputs_exist, assert_outputs_exist, - add_sh_basis_args, add_verbose_arg, - add_skip_b0_check_arg, add_tolerance_arg, parse_sh_basis_arg) -from scilpy.reconst.fodf import fit_from_model -from scilpy.reconst.sh import convert_sh_basis +from scilpy.reconst.fodf import (fit_from_model, + verify_failed_voxels_shm_coeff, + verify_frf_files) +from scilpy.reconst.sh import convert_sh_basis, verify_data_vs_sh_order def _build_arg_parser(): @@ -130,6 +134,7 @@ def main(): args = parser.parse_args() logging.getLogger().setLevel(logging.getLevelName(args.verbose)) + # Verifications if not args.not_all: args.wm_out_fODF = args.wm_out_fODF or 'wm_fodf.nii.gz' args.gm_out_fODF = args.gm_out_fODF or 'gm_fodf.nii.gz' @@ -140,19 +145,21 @@ def main(): arglist = [args.wm_out_fODF, args.gm_out_fODF, args.csf_out_fODF, args.vf, args.vf_rgb] if args.not_all and not any(arglist): - parser.error('When using --not_all, you need to specify at least ' + + parser.error('When using --not_all, you need to specify at least ' 'one file to output.') - assert_inputs_exist(parser, [], - args.in_dwis + args.in_bvals + args.in_bvecs) + required = args.in_dwis + args.in_bvals + args.in_bvecs + args.in_bdeltas + required += [args.in_wm_frf, args.in_gm_frf, args.in_csf_frf] + assert_inputs_exist(parser, required, optional=args.mask) assert_outputs_exist(parser, args, arglist) if not (len(args.in_dwis) == len(args.in_bvals) == len(args.in_bvecs) == len(args.in_bdeltas)): - msg = """The number of given dwis, bvals, bvecs and bdeltas must be the - same. Please verify that all inputs were correctly inserted.""" - raise ValueError(msg) + parser.error("The number of given dwis, bvals, bvecs and bdeltas must " + "be the same. Please verify that all inputs were " + "correctly inserted.") + # Loading data affine = extract_affine(args.in_dwis) wm_frf = np.loadtxt(args.in_wm_frf) @@ -175,74 +182,35 @@ def main(): if mask.shape != data.shape[:-1]: raise ValueError("Mask is not the same shape as data.") - sh_order = args.sh_order + # Checking data and sh_order + verify_data_vs_sh_order(data, args.sh_order) sh_basis, is_legacy = parse_sh_basis_arg(args) - # Checking data and sh_order - if data.shape[-1] < (sh_order + 1) * (sh_order + 2) / 2: - logging.warning( - 'We recommend having at least {} unique DWIs volumes, but you ' - 'currently have {} volumes. Try lowering the parameter --sh_order ' - 'in case of non convergence.'.format( - (sh_order + 1) * (sh_order + 2) / 2, data.shape[-1])) - - # Checking response functions and computing msmt response function - if len(wm_frf.shape) == 1: - wm_frf = np.reshape(wm_frf, (1,) + wm_frf.shape) - if len(gm_frf.shape) == 1: - gm_frf = np.reshape(gm_frf, (1,) + gm_frf.shape) - if len(csf_frf.shape) == 1: - csf_frf = np.reshape(csf_frf, (1,) + csf_frf.shape) - - if not wm_frf.shape[1] == 4: - raise ValueError('WM frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') - if not gm_frf.shape[1] == 4: - raise ValueError('GM frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') - if not csf_frf.shape[1] == 4: - raise ValueError('CSF frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') + # Checking response functions and computing mesmt response function + wm_frf, gm_frf, csf_frf = verify_frf_files(wm_frf, gm_frf, csf_frf) + + # Loading spheres + reg_sphere = get_sphere('symmetric362') + + # Starting main process! ubshapes = convert_bdelta_to_bshape(ubdeltas) - memsmt_response = multi_shell_fiber_response(sh_order, - ubvals, + memsmt_response = multi_shell_fiber_response(args.sh_order, ubvals, wm_frf, gm_frf, csf_frf, tol=args.tolerance, btens=ubshapes) - reg_sphere = get_sphere('symmetric362') - # Computing memsmt-CSD memsmt_model = MultiShellDeconvModel(gtab, memsmt_response, reg_sphere=reg_sphere, - sh_order=sh_order) + sh_order=args.sh_order) # Computing memsmt-CSD fit memsmt_fit = fit_from_model(memsmt_model, data, mask=mask, nbr_processes=args.nbr_processes) shm_coeff = memsmt_fit.all_shm_coeff - - nan_count = len(np.argwhere(np.isnan(shm_coeff[..., 0]))) - voxel_count = np.prod(shm_coeff.shape[:-1]) - - if nan_count / voxel_count >= 0.05: - msg = """There are {} voxels out of {} that could not be solved by - the solver, reaching a critical amount of voxels. Make sure to tune the - response functions properly, as the solving process is very sensitive - to it. Proceeding to fill the problematic voxels by 0. - """ - logging.warning(msg.format(nan_count, voxel_count)) - elif nan_count > 0: - msg = """There are {} voxels out of {} that could not be solved by - the solver. Make sure to tune the response functions properly, as the - solving process is very sensitive to it. Proceeding to fill the - problematic voxels by 0. - """ - logging.warning(msg.format(nan_count, voxel_count)) - - shm_coeff = np.where(np.isnan(shm_coeff), 0, shm_coeff) + shm_coeff = verify_failed_voxels_shm_coeff(shm_coeff) vf = memsmt_fit.volume_fractions vf = np.where(np.isnan(vf), 0, vf) diff --git a/scripts/scil_fodf_msmt.py b/scripts/scil_fodf_msmt.py index 7d524bb4c..f13ef7422 100755 --- a/scripts/scil_fodf_msmt.py +++ b/scripts/scil_fodf_msmt.py @@ -38,8 +38,11 @@ add_sh_basis_args, add_skip_b0_check_arg, add_verbose_arg, add_tolerance_arg, parse_sh_basis_arg) -from scilpy.reconst.fodf import fit_from_model -from scilpy.reconst.sh import convert_sh_basis +from scilpy.reconst.fodf import (fit_from_model, + verify_failed_voxels_shm_coeff, + verify_frf_files) +from scilpy.reconst.sh import convert_sh_basis, verify_data_vs_sh_order + def _build_arg_parser(): @@ -107,6 +110,7 @@ def main(): args = parser.parse_args() logging.getLogger().setLevel(logging.getLevelName(args.verbose)) + # Verifications if not args.not_all: args.wm_out_fODF = args.wm_out_fODF or 'wm_fodf.nii.gz' args.gm_out_fODF = args.gm_out_fODF or 'gm_fodf.nii.gz' @@ -117,7 +121,7 @@ def main(): arglist = [args.wm_out_fODF, args.gm_out_fODF, args.csf_out_fODF, args.vf, args.vf_rgb] if args.not_all and not any(arglist): - parser.error('When using --not_all, you need to specify at least ' + + parser.error('When using --not_all, you need to specify at least ' 'one file to output.') assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec, @@ -133,6 +137,11 @@ def main(): data = vol.get_fdata(dtype=np.float32) bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec) + # Checking data and sh_order + verify_frf_files(wm_frf, gm_frf, csf_frf) + verify_data_vs_sh_order(data, args.sh_order) + sh_basis, is_legacy = parse_sh_basis_arg(args) + # Checking mask if args.mask is None: mask = None @@ -141,18 +150,6 @@ def main(): if mask.shape != data.shape[:-1]: raise ValueError("Mask is not the same shape as data.") - sh_order = args.sh_order - sh_basis, is_legacy = parse_sh_basis_arg(args) - - # Checking data and sh_order - sh_order = args.sh_order - if data.shape[-1] < (sh_order + 1) * (sh_order + 2) / 2: - logging.warning( - 'We recommend having at least {} unique DWIs volumes, but you ' - 'currently have {} volumes. Try lowering the parameter --sh_order ' - 'in case of non convergence.'.format( - (sh_order + 1) * (sh_order + 2) / 2, data.shape[-1])) - # Checking bvals, bvecs values and loading gtab if not is_normalized_bvecs(bvecs): logging.warning('Your b-vectors do not seem normalized...') @@ -168,54 +165,28 @@ def main(): skip_b0_check=args.skip_b0_check) gtab = gradient_table(bvals, bvecs, b0_threshold=args.tolerance) + # Loading spheres + reg_sphere = get_sphere('symmetric362') + + # Starting main process! + # Checking response functions and computing msmt response function - if not wm_frf.shape[1] == 4: - raise ValueError('WM frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') - if not gm_frf.shape[1] == 4: - raise ValueError('GM frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') - if not csf_frf.shape[1] == 4: - raise ValueError('CSF frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') ubvals = unique_bvals_tolerance(bvals, tol=args.tolerance) - msmt_response = multi_shell_fiber_response(sh_order, ubvals, + msmt_response = multi_shell_fiber_response(args.sh_order, ubvals, wm_frf, gm_frf, csf_frf, tol=args.tolerance) - # Loading spheres - reg_sphere = get_sphere('symmetric362') - # Computing msmt-CSD msmt_model = MultiShellDeconvModel(gtab, msmt_response, reg_sphere=reg_sphere, - sh_order=sh_order) + sh_order=args.sh_order) # Computing msmt-CSD fit msmt_fit = fit_from_model(msmt_model, data, mask=mask, nbr_processes=args.nbr_processes) shm_coeff = msmt_fit.all_shm_coeff - - nan_count = len(np.argwhere(np.isnan(shm_coeff[..., 0]))) - voxel_count = np.prod(shm_coeff.shape[:-1]) - - if nan_count / voxel_count >= 0.05: - msg = """There are {} voxels out of {} that could not be solved by - the solver, reaching a critical amount of voxels. Make sure to tune the - response functions properly, as the solving process is very sensitive - to it. Proceeding to fill the problematic voxels by 0. - """ - logging.warning(msg.format(nan_count, voxel_count)) - elif nan_count > 0: - msg = """There are {} voxels out of {} that could not be solved by - the solver. Make sure to tune the response functions properly, as the - solving process is very sensitive to it. Proceeding to fill the - problematic voxels by 0. - """ - logging.warning(msg.format(nan_count, voxel_count)) - - shm_coeff = np.where(np.isnan(shm_coeff), 0, shm_coeff) + shm_coeff = verify_failed_voxels_shm_coeff(shm_coeff) vf = msmt_fit.volume_fractions vf = np.where(np.isnan(vf), 0, vf) From cd3aa4182bde7603b59629be296c48fabb071fa1 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 10:54:55 -0500 Subject: [PATCH 16/38] frf_set_diffusivities: encapsulate to allow unit test --- scilpy/reconst/frf.py | 36 +++++++++++++++++++++++++++ scripts/scil_frf_set_diffusivities.py | 33 +++++++----------------- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/scilpy/reconst/frf.py b/scilpy/reconst/frf.py index c14848b7d..85ececf12 100644 --- a/scilpy/reconst/frf.py +++ b/scilpy/reconst/frf.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import logging +from ast import literal_eval from dipy.core.gradients import gradient_table from dipy.reconst.csdeconv import (mask_for_response_ssst, @@ -301,3 +302,38 @@ def compute_msmt_frf(data, bvals, bvecs, btens=None, data_dti=None, responses = [response_wm, response_gm, response_csf] return responses, frf_masks + + +def replace_frf(old_frf, new_frf, no_factor): + """ + Replace old_frf with new_frf + + Parameters + ---------- + old_frf: np.ndarray + A loaded frf file, of shape (n, 4). + new_frf: tuple + The new frf, to be interpreted with a 10**-4 factor. Ex: (15,4,4) + no_factor: bool + If true, the fiber response function is evaluated without the + 10**-4 factor. + """ + old_frf = old_frf.T + new_frf = np.array(literal_eval(new_frf), dtype=np.float64) + + if not no_factor: + new_frf *= 10 ** -4 + b0_mean = old_frf[3] + + 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 + return response diff --git a/scripts/scil_frf_set_diffusivities.py b/scripts/scil_frf_set_diffusivities.py index 6b51e483b..2424087f2 100755 --- a/scripts/scil_frf_set_diffusivities.py +++ b/scripts/scil_frf_set_diffusivities.py @@ -13,7 +13,6 @@ """ import argparse -from ast import literal_eval import logging import numpy as np @@ -21,6 +20,7 @@ assert_inputs_exist, add_verbose_arg, assert_outputs_exist) +from scilpy.reconst.frf import replace_frf def _build_arg_parser(): @@ -29,11 +29,12 @@ def _build_arg_parser(): p.add_argument('frf_file', metavar='input', help='Path of the FRF file.') - 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). \nIf multi-shell, write the first shell' - ', then the second shell, \nand the third, etc ' + p.add_argument('new_frf', + help='New response function given as a tuple. We will ' + 'replace the \nresponse function in frf_file with ' + 'this fiber response \nfunction x 10**-4 (e.g. ' + '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.') @@ -56,24 +57,8 @@ 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)).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] - - 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 - + frf_file = np.loadtxt(args.frf_file) + response = replace_frf(frf_file, args.new_frf, args.no_factor) np.savetxt(args.output_frf_file, response) From f79343ffc5b063b2bee5857cfaf1ec3b02c26600 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 11:05:03 -0500 Subject: [PATCH 17/38] Bingham metrics: ok. Arranged argparser --- scripts/scil_bingham_metrics.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/scil_bingham_metrics.py b/scripts/scil_bingham_metrics.py index d4c2eabf0..9682e2e55 100755 --- a/scripts/scil_bingham_metrics.py +++ b/scripts/scil_bingham_metrics.py @@ -50,16 +50,18 @@ def _build_arg_parser(): p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter, epilog=EPILOG) - p.add_argument('in_bingham', help='Input Bingham image.') + p.add_argument('in_bingham', + help='Input Bingham nifti image.') - p.add_argument('--out_fd', default='', + p.add_argument('--out_fd', help='Path to output fiber density. [fd.nii.gz]') - p.add_argument('--out_fs', default='', + p.add_argument('--out_fs', help='Path to output fiber spread. [fs.nii.gz]') - p.add_argument('--out_ff', default='', + p.add_argument('--out_ff', help='Path to fiber fraction file. [ff.nii.gz]') p.add_argument('--not_all', action='store_true', - help='Do not compute all metrics.') + help='Do not compute all metrics. Then, please provide ' + 'the output paths of the files you need.') p.add_argument('--mask', help='Optional mask image. Only voxels inside ' 'the mask are computed.') From 389842cdbfa7c8339b2056990fcd3589b85e80c4 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 11:10:26 -0500 Subject: [PATCH 18/38] Add empty tests --- scilpy/reconst/fodf.py | 2 +- scilpy/reconst/tests/test_fodf.py | 10 ++++++++++ scilpy/reconst/tests/test_frf.py | 5 +++++ scilpy/reconst/tests/test_sh.py | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scilpy/reconst/fodf.py b/scilpy/reconst/fodf.py index e6b5a9e58..8973d75a9 100644 --- a/scilpy/reconst/fodf.py +++ b/scilpy/reconst/fodf.py @@ -242,4 +242,4 @@ def verify_frf_files(wm_frf, gm_frf, csf_frf): 'Invalid or deprecated FRF format') if not csf_frf.shape[1] == 4: raise ValueError('CSF frf file did not contain 4 elements. ' - 'Invalid or deprecated FRF format') \ No newline at end of file + 'Invalid or deprecated FRF format') diff --git a/scilpy/reconst/tests/test_fodf.py b/scilpy/reconst/tests/test_fodf.py index db016b324..9d8953bde 100644 --- a/scilpy/reconst/tests/test_fodf.py +++ b/scilpy/reconst/tests/test_fodf.py @@ -9,3 +9,13 @@ def test_get_ventricles_max_fodf(): def test_fit_from_model(): # toDO pass + + +def test_verify_failed_voxels_shm_coeff(): + # Quite simple, nothing to test + pass + + +def test_verify_frf_files(): + # Quite simple, nothing to test + pass diff --git a/scilpy/reconst/tests/test_frf.py b/scilpy/reconst/tests/test_frf.py index 6d9db9e32..8e1b6d9ad 100644 --- a/scilpy/reconst/tests/test_frf.py +++ b/scilpy/reconst/tests/test_frf.py @@ -9,3 +9,8 @@ def test_compute_ssst_frf(): def test_compute_msmt_frf(): # toDO pass + + +def test_replace_frf(): + # toDo + pass diff --git a/scilpy/reconst/tests/test_sh.py b/scilpy/reconst/tests/test_sh.py index 58b9c0458..ab46e94e8 100644 --- a/scilpy/reconst/tests/test_sh.py +++ b/scilpy/reconst/tests/test_sh.py @@ -1,6 +1,11 @@ # -*- coding: utf-8 -*- +def test_verify_data_vs_sh_order(): + # Quite simple, nothing to test + pass + + def test_compute_sh_coefficients(): # toDO pass From fcec7402ab8eecded5bd63545974824726a4a210 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 13:08:44 -0500 Subject: [PATCH 19/38] Fix failing check of path --- scripts/scil_bingham_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scil_bingham_metrics.py b/scripts/scil_bingham_metrics.py index 9682e2e55..0065afe72 100755 --- a/scripts/scil_bingham_metrics.py +++ b/scripts/scil_bingham_metrics.py @@ -93,7 +93,7 @@ def main(): outputs = [args.out_fd, args.out_fs, args.out_ff] assert_inputs_exist(parser, args.in_bingham, args.mask) - assert_outputs_exist(parser, args, outputs) + assert_outputs_exist(parser, args, [], optional=outputs) bingham_im = nib.load(args.in_bingham) bingham = bingham_im.get_fdata() From a74e507539113f58cf59c437eae515e885008f29 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 14:18:57 -0500 Subject: [PATCH 20/38] Add doc --- scilpy/reconst/fodf.py | 23 +++++++++++++++++++---- scripts/scil_fodf_memsmt.py | 7 ++++++- scripts/scil_fodf_msmt.py | 5 +++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/scilpy/reconst/fodf.py b/scilpy/reconst/fodf.py index 8973d75a9..ddb01c1af 100644 --- a/scilpy/reconst/fodf.py +++ b/scilpy/reconst/fodf.py @@ -133,12 +133,13 @@ def _fit_from_model_parallel(args): def fit_from_model(model, data, mask=None, nbr_processes=None): - """Fit the model to data + """Fit the model to data. Can use parallel processing. Parameters ---------- model : a model instance - `model` will be used to fit the data. + It will be used to fit the data. + e.g: An instance of dipy.reconst.shm.SphHarmFit. data : np.ndarray (4d) Diffusion data. mask : np.ndarray, optional @@ -150,8 +151,11 @@ def fit_from_model(model, data, mask=None, nbr_processes=None): Returns ------- - fit_array : np.ndarray - Array containing the fit + fit_array : MultiVoxelFit + Dipy's MultiVoxelFit, containing the fit. + It contains an array of fits. Any attributes of its individuals fits + (of class given by 'model.fit') can be accessed through the + MultiVoxelFit to get all fits at once. """ data_shape = data.shape if mask is None: @@ -194,6 +198,17 @@ def verify_failed_voxels_shm_coeff(shm_coeff): """ Verifies if there are any NaN in the final coefficients, and if so raises warnings. + + Parameters + ---------- + shm_coeff: np.ndarray + The shm_coeff given by dipy's fit classes. Of shape (x, y, z, n) with + the coefficients on the last dimension. + + Returns + ------- + shm_coeff: np.ndarray + The coefficients with 0 instead of NaNs. """ nan_count = len(np.argwhere(np.isnan(shm_coeff[..., 0]))) voxel_count = np.prod(shm_coeff.shape[:-1]) diff --git a/scripts/scil_fodf_memsmt.py b/scripts/scil_fodf_memsmt.py index 5f45f61af..d65b47cff 100755 --- a/scripts/scil_fodf_memsmt.py +++ b/scripts/scil_fodf_memsmt.py @@ -148,7 +148,7 @@ def main(): parser.error('When using --not_all, you need to specify at least ' 'one file to output.') - required = args.in_dwis + args.in_bvals + args.in_bvecs + args.in_bdeltas + required = args.in_dwis + args.in_bvals + args.in_bvecs required += [args.in_wm_frf, args.in_gm_frf, args.in_csf_frf] assert_inputs_exist(parser, required, optional=args.mask) assert_outputs_exist(parser, args, arglist) @@ -209,6 +209,11 @@ def main(): memsmt_fit = fit_from_model(memsmt_model, data, mask=mask, nbr_processes=args.nbr_processes) + # memsmt_fit is a MultiVoxelFit. + # - memsmt_fit.array_fit is a 3D np.ndarray, where value in each voxel is + # a dipy.reconst.mcsd.MSDeconvFit object. + # - When accessing memsmt_fit.all_shm_coeff, we get an array of shape + # (x, y, z, n), where n is the number of fitted values. shm_coeff = memsmt_fit.all_shm_coeff shm_coeff = verify_failed_voxels_shm_coeff(shm_coeff) diff --git a/scripts/scil_fodf_msmt.py b/scripts/scil_fodf_msmt.py index f13ef7422..d80350ebf 100755 --- a/scripts/scil_fodf_msmt.py +++ b/scripts/scil_fodf_msmt.py @@ -185,6 +185,11 @@ def main(): msmt_fit = fit_from_model(msmt_model, data, mask=mask, nbr_processes=args.nbr_processes) + # mmsmt_fit is a MultiVoxelFit. + # - memsmt_fit.array_fit is a 3D np.ndarray, where value in each voxel is + # a dipy.reconst.mcsd.MSDeconvFit object. + # - When accessing memsmt_fit.all_shm_coeff, we get an array of shape + # (x, y, z, n), where n is the number of fitted values. shm_coeff = msmt_fit.all_shm_coeff shm_coeff = verify_failed_voxels_shm_coeff(shm_coeff) From 9175c0e5f936ccba568eaf51d9729e145ef05285 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Wed, 28 Feb 2024 15:31:49 -0500 Subject: [PATCH 21/38] Answer Phil's comment --- scilpy/reconst/fodf.py | 2 ++ scripts/scil_fodf_msmt.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scilpy/reconst/fodf.py b/scilpy/reconst/fodf.py index ddb01c1af..2c18ae2d5 100644 --- a/scilpy/reconst/fodf.py +++ b/scilpy/reconst/fodf.py @@ -258,3 +258,5 @@ def verify_frf_files(wm_frf, gm_frf, csf_frf): if not csf_frf.shape[1] == 4: raise ValueError('CSF frf file did not contain 4 elements. ' 'Invalid or deprecated FRF format') + + return wm_frf, gm_frf, csf_frf diff --git a/scripts/scil_fodf_msmt.py b/scripts/scil_fodf_msmt.py index d80350ebf..ed3c935fa 100755 --- a/scripts/scil_fodf_msmt.py +++ b/scripts/scil_fodf_msmt.py @@ -138,7 +138,7 @@ def main(): bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec) # Checking data and sh_order - verify_frf_files(wm_frf, gm_frf, csf_frf) + wm_frf, gm_frf, csf_frf = verify_frf_files(wm_frf, gm_frf, csf_frf) verify_data_vs_sh_order(data, args.sh_order) sh_basis, is_legacy = parse_sh_basis_arg(args) From c32176a8853982a450ac53f9873c968e458014a4 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Thu, 29 Feb 2024 16:30:49 -0500 Subject: [PATCH 22/38] Add returns in docstring --- scilpy/reconst/fodf.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scilpy/reconst/fodf.py b/scilpy/reconst/fodf.py index 2c18ae2d5..d6545e399 100644 --- a/scilpy/reconst/fodf.py +++ b/scilpy/reconst/fodf.py @@ -239,8 +239,22 @@ def verify_frf_files(wm_frf, gm_frf, csf_frf): Parameters ---------- wm_frf: np.ndarray + The frf directly as loaded from its text file. gm_frf: np.ndarray + Idem csf_frf: np.ndarray + Idem + + Returns + ------- + wm_frf: np.ndarray + The file. In the case where there was only one line in the file, and it + has been loaded as a vector, we return the array formatted as 2D, with + the 4 frf values as columns. + gm_frf: np.ndarray + Idem + csf_frf: np.ndarray + Idem """ if len(wm_frf.shape) == 1: wm_frf = wm_frf[None, :] From aa2536647de4e34ccd8617c52e9a54498741ce58 Mon Sep 17 00:00:00 2001 From: EmmaRenauld Date: Mon, 4 Mar 2024 09:04:16 -0500 Subject: [PATCH 23/38] Add docstrings --- scilpy/io/mti.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/scilpy/io/mti.py b/scilpy/io/mti.py index 953af4bd9..81a9f8883 100644 --- a/scilpy/io/mti.py +++ b/scilpy/io/mti.py @@ -14,6 +14,11 @@ def add_common_args_mti(p): + """ + Defines arguments used in common for these scripts: + - scil_mti_maps_MT.py + - scil_mti_maps_ihMT.py + """ p.add_argument('--extended', action='store_true', help='If set, outputs the folder Complementary_maps.') p.add_argument('--filtering', action='store_true', @@ -69,7 +74,34 @@ def add_common_args_mti(p): def verifications_and_loading_mti(args, parser, input_maps_lists, extended_dir, affine, contrast_names): """ - Common verifications for both MT and ihMT scripts. + Common verifications and loading for both MT and ihMT scripts. + + Parameters + ---------- + args: Namespace + parser: Argparser + input_maps_lists: list[list] + A list of lists of inputs. + extended_dir: str + The folder for extended savings (with option args.extended). + affine: np.ndarray + A reference affine to save files. + contrast_names: list + A list of prefixes for each sub-list in input_maps_lists. + + Returns + ------- + single_echo: bool + True if the first list in input_maps_lists (i.e. the main echoes) + contains only one file. + flip_angles: list[float] + The flip angles, in radian + rep_times: list[float] + The rep times, in ms. + B1_map: np.ndarray + The loaded map, with adjusted intensities, smoothed, corrected. + contrast_maps: list[np.ndarray] + One contrast map per string in contrast_names. """ # Verify that there is the same number of --positive, --negative, # --in_mtoff_pd and --in_mtoff_t1 @@ -111,10 +143,10 @@ def verifications_and_loading_mti(args, parser, input_maps_lists, logging.warning('Repetition time found in {} does not seem to ' 'be given in seconds. MTsat and ihMTsat ' 'results might be affected.'.format(curr_json)) - rep_times.append(acq_parameter[0] * 1000) # convert ms. - flip_angles.append(acq_parameter[1] * np.pi / 180.) # convert rad. + rep_times.append(acq_parameter[0] * 1000) # convert to ms. + flip_angles.append(np.deg2rad(acq_parameter[1])) - # Fix issue from the presence of invalide value and division by zero + # Fix issue from the presence of invalid value and division by zero np.seterr(divide='ignore', invalid='ignore') # Load B1 image From eeeb65e84ed4ce51dd65ff4b32820c6240f96dd1 Mon Sep 17 00:00:00 2001 From: karp2601 Date: Tue, 5 Mar 2024 11:01:24 -0500 Subject: [PATCH 24/38] Pep8 --- scripts/tests/test_gradients_validate_correct.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/test_gradients_validate_correct.py b/scripts/tests/test_gradients_validate_correct.py index 211f7a618..ec1a41dd5 100644 --- a/scripts/tests/test_gradients_validate_correct.py +++ b/scripts/tests/test_gradients_validate_correct.py @@ -40,9 +40,9 @@ def test_execution_processing_fodf_peaks(script_runner): in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') in_peaks = os.path.join(get_home(), 'processing', - 'peaks.nii.gz') + 'peaks.nii.gz') in_fa = os.path.join(get_home(), 'processing', - 'fa.nii.gz') + 'fa.nii.gz') # test the actual script ret = script_runner.run('scil_gradients_validate_correct.py', in_bvec, From 47c59e12f2d295e88bb315a456ff1a0451a5ad30 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Tue, 16 Jan 2024 15:13:41 -0500 Subject: [PATCH 25/38] setup common scil_data cache --- .dvc/.gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .dvc/.gitignore diff --git a/.dvc/.gitignore b/.dvc/.gitignore new file mode 100644 index 000000000..528f30c71 --- /dev/null +++ b/.dvc/.gitignore @@ -0,0 +1,3 @@ +/config.local +/tmp +/cache From d80edd5900a61ae8203785ca05ec4b1cd095781d Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Tue, 16 Jan 2024 15:13:41 -0500 Subject: [PATCH 26/38] setup common scil_data cache --- .dvc/config | 4 ++++ .dvcignore | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 .dvc/config create mode 100644 .dvcignore diff --git a/.dvc/config b/.dvc/config new file mode 100644 index 000000000..05de59ae2 --- /dev/null +++ b/.dvc/config @@ -0,0 +1,4 @@ +[cache] + dir = /home/scil/.scilpy/dvc-cache/ + shared = group + type = symlink diff --git a/.dvcignore b/.dvcignore new file mode 100644 index 000000000..519730552 --- /dev/null +++ b/.dvcignore @@ -0,0 +1,3 @@ +# Add patterns of files dvc should ignore, which could improve +# the performance. Learn more at +# https://dvc.org/doc/user-guide/dvcignore From d50ea7db31eca2662ef1e01c3a606aa120317468 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Wed, 17 Jan 2024 23:18:25 -0500 Subject: [PATCH 27/38] First POC of DVC working as a data registry --- .dvc/config | 4 +++ data/test_descriptors.yml | 2 ++ scilpy/__init__.py | 19 ++++++++++ scilpy/io/dvc.py | 58 ++++++++++++++++++++++++++++++ scripts/tests/test_aodf_metrics.py | 24 ++++++------- 5 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 data/test_descriptors.yml create mode 100644 scilpy/io/dvc.py diff --git a/.dvc/config b/.dvc/config index 05de59ae2..957380e70 100644 --- a/.dvc/config +++ b/.dvc/config @@ -2,3 +2,7 @@ dir = /home/scil/.scilpy/dvc-cache/ shared = group type = symlink +[core] + remote = scil-data +['remote "scil-data"'] + url = https://scil.usherbrooke.ca/scil_test_data/dvc-store diff --git a/data/test_descriptors.yml b/data/test_descriptors.yml new file mode 100644 index 000000000..bf294bd45 --- /dev/null +++ b/data/test_descriptors.yml @@ -0,0 +1,2 @@ +aodf_metrics: + revision: 96d7d6d3c0b4ebdfb71aefcdbdb7893950f1945f diff --git a/scilpy/__init__.py b/scilpy/__init__.py index e69de29bb..fb666eb4d 100644 --- a/scilpy/__init__.py +++ b/scilpy/__init__.py @@ -0,0 +1,19 @@ + + +def get_home(): + import os + """ Set a user-writeable file-system location to put files. """ + if 'SCILPY_HOME' in os.environ: + scilpy_home = os.environ['SCILPY_HOME'] + else: + scilpy_home = os.path.join(os.path.expanduser('~'), '.scilpy') + return scilpy_home + + +def get_root(): + import os + return os.path.realpath(f"{os.path.dirname(os.path.abspath(__file__))}/..") + + +SCILPY_HOME = get_home() +SCILPY_ROOT = get_root() diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py new file mode 100644 index 000000000..8052ef319 --- /dev/null +++ b/scilpy/io/dvc.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + + +from dvc import config, api +import os +import yaml + +from scilpy import SCILPY_HOME, SCILPY_ROOT + + +DVC_REPOSITORY = "https://github.com/AlexVCaron/scil_data.git" + + +def pull_test_case_package(package_name): + with open(f"{SCILPY_ROOT}/data/test_descriptors.yml", 'r') as f: + test_descriptors = yaml.safe_load(f) + + if package_name not in test_descriptors: + raise ValueError(f"Unknown test case: {package_name}") + + pull_package_from_dvc_repository( + package_name, f"{SCILPY_HOME}/test_data", + test_descriptors[package_name]["revision"]) + + return f"{SCILPY_HOME}/test_data/{package_name}" + + +def pull_package_from_dvc_repository(package_name, output_dir, revision="main", + remote_url=DVC_REPOSITORY, + remote_name="scil-data", + dvc_config_root=f"{SCILPY_ROOT}/.dvc"): + """ + Pull a package from a correctly configured DVC remote repository. The + trivial valid configuration is a data storage located at the registry + root and named store. + """ + return pull_from_dvc_repository(f"store/{package_name}", output_dir, + revision, remote_url, remote_name, + dvc_config_root) + + +def pull_from_dvc_repository(package_name, output_dir, revision="main", + remote_url=DVC_REPOSITORY, + remote_name="scil-data", + dvc_config_root=f"{SCILPY_ROOT}/.dvc"): + """ + Pull data from a DVC remote repository. This is mostly used in + conjuction with SCILPY data DVC endpoints at : + - https://github.com/AlexVCaron/scil_data.git + - https://scil.usherbrooke.ca/scil_test_data/dvc-store + """ + + conf = config.Config(dvc_config_root) + registry = api.DVCFileSystem(remote_url, revision, + remote_name=remote_name, + remote_config=conf["remote"][remote_name]) + + registry.get(package_name, output_dir, True) diff --git a/scripts/tests/test_aodf_metrics.py b/scripts/tests/test_aodf_metrics.py index 12b7e88c9..28c8ed17b 100644 --- a/scripts/tests/test_aodf_metrics.py +++ b/scripts/tests/test_aodf_metrics.py @@ -4,11 +4,11 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home +from scilpy.io.dvc import pull_test_case_package # If they already exist, this only takes 5 seconds (check md5sum) -fetch_data(get_testing_files_dict(), keys=['processing.zip']) +test_data_root = pull_test_case_package("aodf_metrics") tmp_dir = tempfile.TemporaryDirectory() @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', - 'fodf_descoteaux07_sub_full.nii.gz') + in_fodf = os.path.join( + f"{test_data_root}/fodf_descoteaux07_sub_full.nii.gz") # Using a low resolution sphere for peak extraction reduces process time ret = script_runner.run('scil_aodf_metrics.py', in_fodf, @@ -30,8 +30,8 @@ def test_execution(script_runner): def test_assert_not_all(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', - 'fodf_descoteaux07_sub_full.nii.gz') + in_fodf = os.path.join( + f"{test_data_root}/fodf_descoteaux07_sub_full.nii.gz") ret = script_runner.run('scil_aodf_metrics.py', in_fodf, '--not_all') @@ -40,8 +40,8 @@ def test_assert_not_all(script_runner): def test_execution_not_all(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', - 'fodf_descoteaux07_sub_full.nii.gz') + in_fodf = os.path.join( + f"{test_data_root}/fodf_descoteaux07_sub_full.nii.gz") ret = script_runner.run('scil_aodf_metrics.py', in_fodf, '--not_all', '--asi_map', @@ -51,8 +51,8 @@ def test_execution_not_all(script_runner): def test_assert_symmetric_input(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', - 'fodf_descoteaux07.nii.gz') + in_fodf = os.path.join( + f"{test_data_root}/fodf_descoteaux07.nii.gz") # Using a low resolution sphere for peak extraction reduces process time ret = script_runner.run('scil_aodf_metrics.py', in_fodf, @@ -62,8 +62,8 @@ def test_assert_symmetric_input(script_runner): def test_execution_symmetric_input(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', - 'fodf_descoteaux07.nii.gz') + in_fodf = os.path.join( + f"{test_data_root}/fodf_descoteaux07.nii.gz") # Using a low resolution sphere for peak extraction reduces process time ret = script_runner.run('scil_aodf_metrics.py', in_fodf, From efdf059dbccfeccdf2c27e4520de0e01dd6692a2 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Wed, 17 Jan 2024 23:31:31 -0500 Subject: [PATCH 28/38] move descriptors to .dvc and update requirements --- {data => .dvc}/test_descriptors.yml | 0 requirements.txt | 7 +++++++ scilpy/io/dvc.py | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) rename {data => .dvc}/test_descriptors.yml (100%) diff --git a/data/test_descriptors.yml b/.dvc/test_descriptors.yml similarity index 100% rename from data/test_descriptors.yml rename to .dvc/test_descriptors.yml diff --git a/requirements.txt b/requirements.txt index 4678e389b..bf41ad024 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,13 @@ deepdiff==6.3.0 dmri-amico==2.0.* dmri-commit==2.0.* docopt==0.6.* +dvc==3.39.0 +dvc-data==3.7.0 +dvc-http==2.32.0 +dvc-objects==3.0.6 +dvc-render==1.0.0 +dvc-studio-client==0.18.0 +dvc-task==0.3.0 formulaic==0.3.* fury==0.9.* future==0.18.* diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index 8052ef319..d8ecaaeba 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -12,7 +12,7 @@ def pull_test_case_package(package_name): - with open(f"{SCILPY_ROOT}/data/test_descriptors.yml", 'r') as f: + with open(f"{SCILPY_ROOT}/.dvc/test_descriptors.yml", 'r') as f: test_descriptors = yaml.safe_load(f) if package_name not in test_descriptors: From 94e1e60c21c58ecf1240023fd9afb09dcbf96ed9 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Thu, 18 Jan 2024 13:32:54 -0500 Subject: [PATCH 29/38] Minor fix --- scilpy/io/dvc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index d8ecaaeba..9421c991f 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -34,7 +34,8 @@ def pull_package_from_dvc_repository(package_name, output_dir, revision="main", trivial valid configuration is a data storage located at the registry root and named store. """ - return pull_from_dvc_repository(f"store/{package_name}", output_dir, + return pull_from_dvc_repository(f"store/{package_name}", + f"{output_dir}/{package_name}", revision, remote_url, remote_name, dvc_config_root) From cf5accca2f3114b9ce7a93184b9cbdf7d6b034d2 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Thu, 29 Feb 2024 16:50:54 -0500 Subject: [PATCH 30/38] use new package --- scripts/tests/test_aodf_metrics.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/test_aodf_metrics.py b/scripts/tests/test_aodf_metrics.py index 28c8ed17b..f2b6cbc19 100644 --- a/scripts/tests/test_aodf_metrics.py +++ b/scripts/tests/test_aodf_metrics.py @@ -8,7 +8,7 @@ # If they already exist, this only takes 5 seconds (check md5sum) -test_data_root = pull_test_case_package("aodf_metrics") +test_data_root = pull_test_case_package("aodf") tmp_dir = tempfile.TemporaryDirectory() @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) in_fodf = os.path.join( - f"{test_data_root}/fodf_descoteaux07_sub_full.nii.gz") + f"{test_data_root}/fodf_descoteaux07_sub_unified_asym.nii.gz") # Using a low resolution sphere for peak extraction reduces process time ret = script_runner.run('scil_aodf_metrics.py', in_fodf, @@ -31,7 +31,7 @@ def test_execution(script_runner): def test_assert_not_all(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) in_fodf = os.path.join( - f"{test_data_root}/fodf_descoteaux07_sub_full.nii.gz") + f"{test_data_root}/fodf_descoteaux07_sub_unified_asym.nii.gz") ret = script_runner.run('scil_aodf_metrics.py', in_fodf, '--not_all') @@ -41,7 +41,7 @@ def test_assert_not_all(script_runner): def test_execution_not_all(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) in_fodf = os.path.join( - f"{test_data_root}/fodf_descoteaux07_sub_full.nii.gz") + f"{test_data_root}/fodf_descoteaux07_sub_unified_asym.nii.gz") ret = script_runner.run('scil_aodf_metrics.py', in_fodf, '--not_all', '--asi_map', From 7a65d55d7b4569eb599a9c5f4df943fea4f20dd4 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Thu, 29 Feb 2024 16:55:42 -0500 Subject: [PATCH 31/38] update revision for test descriptor --- .dvc/test_descriptors.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.dvc/test_descriptors.yml b/.dvc/test_descriptors.yml index bf294bd45..01aa55e63 100644 --- a/.dvc/test_descriptors.yml +++ b/.dvc/test_descriptors.yml @@ -1,2 +1,2 @@ -aodf_metrics: - revision: 96d7d6d3c0b4ebdfb71aefcdbdb7893950f1945f +aodf: + revision: ee0596f9474d8a24f7620e4cb00f2e2874ca02d1 From 4ff657c6afa9c741c9c798f44188c958aea2594c Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Thu, 29 Feb 2024 17:08:30 -0500 Subject: [PATCH 32/38] add vendor in name --- scilpy/io/dvc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index 9421c991f..bb4c3c15d 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -19,7 +19,7 @@ def pull_test_case_package(package_name): raise ValueError(f"Unknown test case: {package_name}") pull_package_from_dvc_repository( - package_name, f"{SCILPY_HOME}/test_data", + f"{package_name}", f"{SCILPY_HOME}/test_data", test_descriptors[package_name]["revision"]) return f"{SCILPY_HOME}/test_data/{package_name}" @@ -34,7 +34,7 @@ def pull_package_from_dvc_repository(package_name, output_dir, revision="main", trivial valid configuration is a data storage located at the registry root and named store. """ - return pull_from_dvc_repository(f"store/{package_name}", + return pull_from_dvc_repository(f"store/scilpy_tests/{package_name}", f"{output_dir}/{package_name}", revision, remote_url, remote_name, dvc_config_root) From 481f6e73cffee462cb78da4218ccb8224afe6236 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Thu, 29 Feb 2024 22:44:13 -0500 Subject: [PATCH 33/38] fix and document --- scilpy/io/dvc.py | 84 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index bb4c3c15d..608133134 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -12,29 +12,73 @@ def pull_test_case_package(package_name): + """ + Pull a package for a test case located in the `scilpy_tests` vendor. Refer + to the `Scilpy Tests Vendor`_ for available packages. + + Parameters + ---------- + package_name : str + Name of the package to pull from the `scilpy_tests` vendor. + + Returns + ------- + str + The path to the pulled package. + + .. _Scilpy Tests Vendor: + https://github.com/AlexVCaron/scil_data/tree/main/store/scilpy_tests + """ with open(f"{SCILPY_ROOT}/.dvc/test_descriptors.yml", 'r') as f: test_descriptors = yaml.safe_load(f) if package_name not in test_descriptors: - raise ValueError(f"Unknown test case: {package_name}") + raise ValueError(f"Unknown test package: {package_name}") pull_package_from_dvc_repository( - f"{package_name}", f"{SCILPY_HOME}/test_data", + "scilpy_tests", f"{package_name}", + f"{SCILPY_HOME}/test_data/{package_name}", test_descriptors[package_name]["revision"]) return f"{SCILPY_HOME}/test_data/{package_name}" -def pull_package_from_dvc_repository(package_name, output_dir, revision="main", +def pull_package_from_dvc_repository(vendor, package_name, output_dir, + revision="main", remote_url=DVC_REPOSITORY, remote_name="scil-data", dvc_config_root=f"{SCILPY_ROOT}/.dvc"): """ - Pull a package from a correctly configured DVC remote repository. The - trivial valid configuration is a data storage located at the registry - root and named store. + Pull a package from a correctly configured DVC remote repository. Packages + are located in the store directory, organized in vendors with different + purposes. Refer to the `SCIL Data Store`_ for more information. + + Parameters + ---------- + vendor : str + Name of the vendor to pull the package from. + package_name : str + Name of the package to pull from the vendor. + output_dir : str + Path to the directory where the package will be pulled. + revision : str + Git revision of the DVC artifact to pull. + remote_url : str + URL of the DVC git repository. + remote_name : str + Name of the DVC remote to use. + dvc_config_root : str + Location of the DVC configuration files. + + Returns + ------- + str + The path to the pulled package. + + .. _SCIL Data Store: + https://github.com/AlexVCaron/scil_data/tree/main/store """ - return pull_from_dvc_repository(f"store/scilpy_tests/{package_name}", + return pull_from_dvc_repository(f"store/{vendor}/{package_name}", f"{output_dir}/{package_name}", revision, remote_url, remote_name, dvc_config_root) @@ -45,12 +89,28 @@ def pull_from_dvc_repository(package_name, output_dir, revision="main", remote_name="scil-data", dvc_config_root=f"{SCILPY_ROOT}/.dvc"): """ - Pull data from a DVC remote repository. This is mostly used in - conjuction with SCILPY data DVC endpoints at : - - https://github.com/AlexVCaron/scil_data.git - - https://scil.usherbrooke.ca/scil_test_data/dvc-store + Pull data from a DVC remote repository to the specified location. + + Parameters + ---------- + package_name : str + Name of the package to pull from the DVC repository. + output_dir : str + Path to the directory where the package will be pulled. + revision : str + Git revision of the DVC artifact to pull. + remote_url : str + URL of the DVC git repository. + remote_name : str + Name of the DVC remote to use. + dvc_config_root : str + Location of the DVC configuration files. + + Returns + ------- + str + The path to the pulled package. """ - conf = config.Config(dvc_config_root) registry = api.DVCFileSystem(remote_url, revision, remote_name=remote_name, From 309eb17de16847dc09700d687603324c11e6926c Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Thu, 29 Feb 2024 23:29:31 -0500 Subject: [PATCH 34/38] fix --- scilpy/io/dvc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index 608133134..013445eef 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -36,8 +36,7 @@ def pull_test_case_package(package_name): raise ValueError(f"Unknown test package: {package_name}") pull_package_from_dvc_repository( - "scilpy_tests", f"{package_name}", - f"{SCILPY_HOME}/test_data/{package_name}", + "scilpy_tests", f"{package_name}", f"{SCILPY_HOME}/test_data", test_descriptors[package_name]["revision"]) return f"{SCILPY_HOME}/test_data/{package_name}" From 6e70e62e48d5840c4f14dd546ab90696f32d1ae8 Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Tue, 5 Mar 2024 16:39:35 -0500 Subject: [PATCH 35/38] first pass to answer arnaud's comments --- .dvc/config | 4 ---- scilpy/io/dvc.py | 29 +++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.dvc/config b/.dvc/config index 957380e70..2b46d4f45 100644 --- a/.dvc/config +++ b/.dvc/config @@ -1,7 +1,3 @@ -[cache] - dir = /home/scil/.scilpy/dvc-cache/ - shared = group - type = symlink [core] remote = scil-data ['remote "scil-data"'] diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index 013445eef..62e5eee1e 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -1,14 +1,25 @@ # -*- coding: utf-8 -*- -from dvc import config, api import os + import yaml +from dvc import api, config from scilpy import SCILPY_HOME, SCILPY_ROOT - DVC_REPOSITORY = "https://github.com/AlexVCaron/scil_data.git" +DEFAULT_CACHE_CONFIG = { + "type": "symlink", + "shared": "group", + "dir": os.path.join(SCILPY_HOME, "dvc-cache") +} + + +def get_default_config(): + return config.Config(config={ + "cache": DEFAULT_CACHE_CONFIG + }) def pull_test_case_package(package_name): @@ -27,7 +38,7 @@ def pull_test_case_package(package_name): The path to the pulled package. .. _Scilpy Tests Vendor: - https://github.com/AlexVCaron/scil_data/tree/main/store/scilpy_tests + https://github.com/AlexVCaron/scilus/tree/main/store/scilpy_tests """ with open(f"{SCILPY_ROOT}/.dvc/test_descriptors.yml", 'r') as f: test_descriptors = yaml.safe_load(f) @@ -75,10 +86,10 @@ def pull_package_from_dvc_repository(vendor, package_name, output_dir, The path to the pulled package. .. _SCIL Data Store: - https://github.com/AlexVCaron/scil_data/tree/main/store + https://github.com/scilus/scil_data/tree/main/store """ return pull_from_dvc_repository(f"store/{vendor}/{package_name}", - f"{output_dir}/{package_name}", + f"{output_dir}/", revision, remote_url, remote_name, dvc_config_root) @@ -110,9 +121,11 @@ def pull_from_dvc_repository(package_name, output_dir, revision="main", str The path to the pulled package. """ - conf = config.Config(dvc_config_root) + conf = get_default_config() + conf.merge(config.Config(dvc_config_root)) + registry = api.DVCFileSystem(remote_url, revision, - remote_name=remote_name, + config=conf, remote_name=remote_name, remote_config=conf["remote"][remote_name]) - registry.get(package_name, output_dir, True) + registry.get(package_name, output_dir, True, cache=True) From 1cbd4c15c9052ebdfb8105bf83c865b7485f7cbc Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Tue, 5 Mar 2024 17:07:51 -0500 Subject: [PATCH 36/38] switch get_home for new SCILPY_HOME constant --- scilpy/image/tests/test_volume_operations.py | 21 +++--- scilpy/io/fetcher.py | 24 +++---- .../test_streamline_and_mask_operations.py | 30 ++++---- .../tests/test_streamline_operations.py | 15 ++-- .../tests/test_tractogram_operations.py | 22 ++++-- scripts/tests/test_NODDI_maps.py | 11 +-- scripts/tests/test_NODDI_priors.py | 11 +-- scripts/tests/test_aodf_metrics.py | 5 +- scripts/tests/test_apply_transform_to_hdf5.py | 10 +-- scripts/tests/test_bids_validate.py | 10 +-- scripts/tests/test_bingham_metrics.py | 11 +-- scripts/tests/test_btensor_metrics.py | 51 +++++++------- scripts/tests/test_bundle_compute_centroid.py | 6 +- .../test_bundle_compute_endpoints_map.py | 6 +- scripts/tests/test_bundle_diameter.py | 8 +-- .../tests/test_bundle_filter_by_occurence.py | 10 +-- scripts/tests/test_bundle_generate_priors.py | 10 +-- scripts/tests/test_bundle_label_map.py | 8 +-- scripts/tests/test_bundle_mean_fixel_afd.py | 7 +- .../test_bundle_mean_fixel_afd_from_hdf5.py | 8 +-- .../test_bundle_mean_fixel_bingham_metric.py | 9 +-- scripts/tests/test_bundle_mean_std.py | 14 ++-- .../tests/test_bundle_pairwise_comparison.py | 34 ++++----- ...undle_score_many_bundles_one_tractogram.py | 10 +-- ...le_score_same_bundle_many_segmentations.py | 13 ++-- scripts/tests/test_bundle_shape_measures.py | 10 +-- scripts/tests/test_bundle_volume_per_label.py | 6 +- .../test_compute_hdf5_average_density_map.py | 6 +- scripts/tests/test_compute_pca.py | 10 +-- .../tests/test_compute_seed_density_map.py | 5 +- .../test_connectivity_compare_populations.py | 10 +-- .../test_connectivity_compute_matrices.py | 12 ++-- scripts/tests/test_connectivity_filter.py | 8 +-- .../tests/test_connectivity_graph_measures.py | 8 +-- scripts/tests/test_connectivity_math.py | 12 ++-- scripts/tests/test_connectivity_normalize.py | 12 ++-- .../test_connectivity_pairwise_agreement.py | 8 +-- .../test_connectivity_print_filenames.py | 8 +-- .../tests/test_connectivity_reorder_rois.py | 14 ++-- scripts/tests/test_convert_tensors.py | 9 +-- scripts/tests/test_decompose_connectivity.py | 8 +-- scripts/tests/test_denoising_nlmeans.py | 6 +- scripts/tests/test_dki_metrics.py | 9 +-- scripts/tests/test_dti_metrics.py | 11 +-- scripts/tests/test_dwi_apply_bias_field.py | 8 +-- scripts/tests/test_dwi_compute_snr.py | 14 ++-- scripts/tests/test_dwi_concatenate.py | 9 +-- .../tests/test_dwi_detect_volume_outliers.py | 9 +-- scripts/tests/test_dwi_extract_b0.py | 9 +-- scripts/tests/test_dwi_extract_shell.py | 21 +++--- scripts/tests/test_dwi_powder_average.py | 7 +- scripts/tests/test_dwi_reorder_philips.py | 25 +++---- scripts/tests/test_dwi_split_by_indices.py | 15 ++-- scripts/tests/test_dwi_to_sh.py | 9 +-- scripts/tests/test_fodf_max_in_ventricles.py | 9 +-- scripts/tests/test_fodf_memsmt.py | 39 ++++++----- scripts/tests/test_fodf_metrics.py | 5 +- scripts/tests/test_fodf_msmt.py | 17 ++--- scripts/tests/test_fodf_ssst.py | 11 +-- scripts/tests/test_fodf_to_bingham.py | 9 +-- scripts/tests/test_freewater_maps.py | 11 +-- scripts/tests/test_frf_mean.py | 9 +-- scripts/tests/test_frf_memsmt.py | 69 ++++++++++--------- scripts/tests/test_frf_msmt.py | 30 ++++---- scripts/tests/test_frf_set_diffusivities.py | 9 +-- scripts/tests/test_frf_ssst.py | 21 +++--- .../tests/test_gradients_apply_transform.py | 8 +-- scripts/tests/test_gradients_convert.py | 17 ++--- scripts/tests/test_gradients_modify_axes.py | 7 +- scripts/tests/test_gradients_round_bvals.py | 5 +- .../tests/test_gradients_validate_correct.py | 9 +-- .../test_gradients_validate_correct_eddy.py | 11 +-- scripts/tests/test_header_print_info.py | 7 +- .../test_header_validate_compatibility.py | 8 +-- .../test_json_convert_entries_to_xlsx.py | 6 +- scripts/tests/test_json_merge_entries.py | 8 +-- scripts/tests/test_labels_combine.py | 11 +-- scripts/tests/test_labels_dilate.py | 5 +- scripts/tests/test_labels_remove.py | 5 +- .../tests/test_labels_split_volume_by_ids.py | 5 +- .../test_labels_split_volume_from_lut.py | 7 +- scripts/tests/test_mti_adjust_B1_header.py | 7 +- scripts/tests/test_mti_maps_MT.py | 43 ++++++------ scripts/tests/test_mti_maps_ihMT.py | 49 ++++++------- scripts/tests/test_outlier_rejection.py | 6 +- scripts/tests/test_plot_stats_per_point.py | 6 +- scripts/tests/test_qball_metrics.py | 15 ++-- scripts/tests/test_rgb_convert.py | 6 +- .../tests/test_save_connections_from_hdf5.py | 6 +- scripts/tests/test_score_tractogram.py | 12 ++-- scripts/tests/test_screenshot_volume.py | 6 +- scripts/tests/test_sh_convert.py | 5 +- scripts/tests/test_sh_fusion.py | 7 +- scripts/tests/test_sh_to_aodf.py | 11 +-- scripts/tests/test_sh_to_rish.py | 5 +- scripts/tests/test_sh_to_sf.py | 9 +-- scripts/tests/test_shuffle_streamlines.py | 5 +- scripts/tests/test_stats_group_comparison.py | 8 +-- scripts/tests/test_surface_apply_transform.py | 8 +-- scripts/tests/test_surface_convert.py | 10 +-- scripts/tests/test_surface_flip.py | 6 +- scripts/tests/test_surface_smooth.py | 6 +- scripts/tests/test_tracking_local.py | 52 +++++++------- scripts/tests/test_tracking_local_dev.py | 8 +-- scripts/tests/test_tracking_pft.py | 12 ++-- scripts/tests/test_tracking_pft_maps.py | 10 +-- scripts/tests/test_tracking_pft_maps_edit.py | 9 +-- .../tests/test_tractogram_apply_transform.py | 12 ++-- .../test_tractogram_assign_custom_color.py | 8 +-- .../test_tractogram_assign_uniform_color.py | 6 +- scripts/tests/test_tractogram_commit.py | 15 ++-- scripts/tests/test_tractogram_compress.py | 6 +- scripts/tests/test_tractogram_compute_TODI.py | 10 +-- .../test_tractogram_compute_density_map.py | 8 +-- scripts/tests/test_tractogram_convert.py | 8 +-- .../test_tractogram_count_streamlines.py | 6 +- .../tests/test_tractogram_cut_streamlines.py | 8 +-- scripts/tests/test_tractogram_detect_loops.py | 6 +- scripts/tests/test_tractogram_dpp_math.py | 12 ++-- .../tests/test_tractogram_extract_ushape.py | 6 +- .../test_tractogram_filter_by_anatomy.py | 16 ++--- .../tests/test_tractogram_filter_by_length.py | 6 +- .../test_tractogram_filter_by_orientation.py | 6 +- .../tests/test_tractogram_filter_by_roi.py | 16 ++--- scripts/tests/test_tractogram_flip.py | 8 +-- scripts/tests/test_tractogram_math.py | 5 +- scripts/tests/test_tractogram_print_info.py | 6 +- ...t_tractogram_project_map_to_streamlines.py | 23 ++++--- ...t_tractogram_project_streamlines_to_map.py | 12 ++-- scripts/tests/test_tractogram_qbx.py | 6 +- scripts/tests/test_tractogram_register.py | 10 +-- .../tests/test_tractogram_remove_invalid.py | 6 +- scripts/tests/test_tractogram_resample.py | 7 +- .../test_tractogram_resample_nb_points.py | 6 +- .../tests/test_tractogram_segment_bundles.py | 14 ++-- .../test_tractogram_segment_one_bundles.py | 12 ++-- scripts/tests/test_tractogram_smooth.py | 5 +- scripts/tests/test_tractogram_split.py | 5 +- .../test_tractogram_uniformize_endpoints.py | 6 +- scripts/tests/test_visualize_bingham_fit.py | 5 +- .../tests/test_visualize_bundles_mosaic.py | 4 +- scripts/tests/test_visualize_connectivity.py | 8 +-- scripts/tests/test_visualize_fodf.py | 5 +- scripts/tests/test_visualize_histogram.py | 7 +- scripts/tests/test_visualize_scatterplot.py | 45 ++++++------ scripts/tests/test_volume_apply_transform.py | 10 +-- scripts/tests/test_volume_b0_synthesis.py | 11 +-- .../test_volume_count_non_zero_voxels.py | 6 +- scripts/tests/test_volume_crop.py | 5 +- scripts/tests/test_volume_flip.py | 6 +- scripts/tests/test_volume_math.py | 33 ++++----- .../test_volume_remove_outliers_ransac.py | 5 +- scripts/tests/test_volume_resample.py | 6 +- .../tests/test_volume_reshape_to_reference.py | 12 ++-- scripts/tests/test_volume_stats_in_ROI.py | 7 +- 155 files changed, 940 insertions(+), 868 deletions(-) diff --git a/scilpy/image/tests/test_volume_operations.py b/scilpy/image/tests/test_volume_operations.py index 3b051b716..c3d932921 100644 --- a/scilpy/image/tests/test_volume_operations.py +++ b/scilpy/image/tests/test_volume_operations.py @@ -3,27 +3,28 @@ import os import tempfile -from dipy.io.gradients import read_bvals_bvecs import nibabel as nib import numpy as np +from dipy.io.gradients import read_bvals_bvecs from numpy.testing import assert_equal -from scilpy.image.volume_operations import (flip_volume, - crop_volume, - apply_transform, +from scilpy import SCILPY_HOME +from scilpy.image.volume_operations import (apply_transform, compute_snr, + crop_volume, + flip_volume, resample_volume) -from scilpy.io.fetcher import fetch_data, get_testing_files_dict, get_home +from scilpy.io.fetcher import fetch_data, get_testing_files_dict from scilpy.utils.util import compute_nifti_bounding_box # Fetching testing dwi data. fetch_data(get_testing_files_dict(), keys='processing.zip') tmp_dir = tempfile.TemporaryDirectory() -in_dwi = os.path.join(get_home(), 'processing', 'dwi.nii.gz') -in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') -in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') -in_mask = os.path.join(get_home(), 'processing', 'cc.nii.gz') -in_noise_mask = os.path.join(get_home(), 'processing', +in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi.nii.gz') +in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') +in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') +in_mask = os.path.join(SCILPY_HOME, 'processing', 'cc.nii.gz') +in_noise_mask = os.path.join(SCILPY_HOME, 'processing', 'small_roi_gm_mask.nii.gz') diff --git a/scilpy/io/fetcher.py b/scilpy/io/fetcher.py index 8113e609d..e519fcb89 100644 --- a/scilpy/io/fetcher.py +++ b/scilpy/io/fetcher.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- +import hashlib import inspect import logging -import hashlib import os import pathlib -import requests import zipfile +import requests + +from scilpy import SCILPY_HOME DVC_URL = "https://scil.usherbrooke.ca/scil_test_data/dvc-store/files/md5" @@ -35,15 +37,6 @@ def save_response_content(response, destination): save_response_content(response, destination) -def get_home(): - """ Set a user-writeable file-system location to put files. """ - if 'SCILPY_HOME' in os.environ: - scilpy_home = os.environ['SCILPY_HOME'] - else: - scilpy_home = os.path.join(os.path.expanduser('~'), '.scilpy') - return scilpy_home - - def get_testing_files_dict(): """ Get dictionary linking zip file to their GDrive ID & MD5SUM """ return { @@ -76,10 +69,9 @@ def fetch_data(files_dict, keys=None): But with too many data accesses, downloaded become denied. Using trick from https://github.com/wkentaro/gdown/issues/43. """ - scilpy_home = get_home() - if not os.path.exists(scilpy_home): - os.makedirs(scilpy_home) + if not os.path.exists(SCILPY_HOME): + os.makedirs(SCILPY_HOME) if keys is None: keys = files_dict.keys() @@ -87,14 +79,14 @@ def fetch_data(files_dict, keys=None): keys = [keys] for f in keys: url_md5 = files_dict[f] - full_path = os.path.join(scilpy_home, f) + full_path = os.path.join(SCILPY_HOME, f) full_path_no_ext, ext = os.path.splitext(full_path) CURR_URL = DVC_URL + "/" + url_md5[:2] + "/" + url_md5[2:] if not os.path.isdir(full_path_no_ext): if ext == '.zip' and not os.path.isdir(full_path_no_ext): logging.warning('Downloading and extracting {} from url {} to ' - '{}'.format(f, CURR_URL, scilpy_home)) + '{}'.format(f, CURR_URL, SCILPY_HOME)) # Robust method to Virus/Size check from GDrive download_file_from_google_drive(CURR_URL, full_path) diff --git a/scilpy/tractograms/tests/test_streamline_and_mask_operations.py b/scilpy/tractograms/tests/test_streamline_and_mask_operations.py index 7980b198d..9efd46c54 100644 --- a/scilpy/tractograms/tests/test_streamline_and_mask_operations.py +++ b/scilpy/tractograms/tests/test_streamline_and_mask_operations.py @@ -4,21 +4,21 @@ import nibabel as nib import numpy as np - from dipy.io.streamline import load_tractogram -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home +from scilpy import SCILPY_HOME from scilpy.image.utils import split_mask_blobs_kmeans +from scilpy.io.fetcher import fetch_data, get_testing_files_dict from scilpy.tractograms.streamline_and_mask_operations import ( + _intersects_two_rois, compute_streamline_segment, cut_between_mask_two_blobs_streamlines, cut_outside_of_mask_streamlines, get_endpoints_density_map, get_head_tail_density_maps) -from scilpy.tractograms.streamline_and_mask_operations import \ - _intersects_two_rois from scilpy.tractograms.uncompress import uncompress + fetch_data(get_testing_files_dict(), keys=['tractograms.zip']) @@ -26,20 +26,20 @@ def _setup_files(): """ Load streamlines and masks relevant to the tests here. """ - in_ref = os.path.join(get_home(), 'tractograms', + in_ref = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_wm.nii.gz') - in_head_tail = os.path.join(get_home(), 'tractograms', + in_head_tail = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_head_tail.nii.gz') - in_head_tail_offset = os.path.join(get_home(), 'tractograms', + in_head_tail_offset = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_head_tail_offset.nii.gz') - in_center = os.path.join(get_home(), 'tractograms', + in_center = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_center.nii.gz') - in_sft = os.path.join(get_home(), 'tractograms', + in_sft = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4.tck') @@ -63,7 +63,7 @@ def test_get_endpoints_density_map(): endpoints_map = get_endpoints_density_map( sft, point_to_select=1) - in_result = os.path.join(get_home(), 'tractograms', + in_result = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_endpoints_1point.nii.gz') @@ -81,7 +81,7 @@ def test_get_endpoints_density_map_five_points(): endpoints_map = get_endpoints_density_map( sft, point_to_select=5) - in_result = os.path.join(get_home(), 'tractograms', + in_result = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_endpoints_5points.nii.gz') @@ -101,7 +101,7 @@ def test_get_head_tail_density_maps(): head_map, tail_map = get_head_tail_density_maps( sft, point_to_select=1) - in_result = os.path.join(get_home(), 'tractograms', + in_result = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_endpoints_1point.nii.gz') @@ -116,7 +116,7 @@ def test_cut_outside_of_mask_streamlines(): cut_sft = cut_outside_of_mask_streamlines( sft, center_roi) - in_result = os.path.join(get_home(), 'tractograms', + in_result = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_cut_center.tck') @@ -142,7 +142,7 @@ def test_cut_between_mask_two_blobs_streamlines(): sft, head_tail_rois) # The expected result is the input bundle. - in_result = os.path.join(get_home(), 'tractograms', + in_result = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4.tck') @@ -168,7 +168,7 @@ def test_cut_between_mask_two_blobs_streamlines_offset(): cut_sft = cut_between_mask_two_blobs_streamlines( sft, head_tail_offset_rois) - in_result = os.path.join(get_home(), 'tractograms', + in_result = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_and_mask_operations', 'bundle_4_cut_endpoints.tck') diff --git a/scilpy/tractograms/tests/test_streamline_operations.py b/scilpy/tractograms/tests/test_streamline_operations.py index faeb4e57c..e6344c910 100644 --- a/scilpy/tractograms/tests/test_streamline_operations.py +++ b/scilpy/tractograms/tests/test_streamline_operations.py @@ -5,11 +5,11 @@ import nibabel as nib import numpy as np import pytest - from dipy.io.streamline import load_tractogram from dipy.tracking.streamlinespeed import length -from scilpy.io.fetcher import fetch_data, get_testing_files_dict, get_home +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict from scilpy.tractograms.streamline_operations import ( filter_streamlines_by_length, filter_streamlines_by_total_length_per_dim, @@ -19,6 +19,7 @@ smooth_line_spline) from scilpy.tractograms.tractogram_operations import concatenate_sft + fetch_data(get_testing_files_dict(), keys=['tractograms.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -28,20 +29,20 @@ def _setup_files(): """ os.chdir(os.path.expanduser(tmp_dir.name)) - in_long_sft = os.path.join(get_home(), 'tractograms', + in_long_sft = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_operations', 'bundle_4.tck') - in_mid_sft = os.path.join(get_home(), 'tractograms', + in_mid_sft = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_operations', 'bundle_4_cut_endpoints.tck') - in_short_sft = os.path.join(get_home(), 'tractograms', + in_short_sft = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_operations', 'bundle_4_cut_center.tck') - in_ref = os.path.join(get_home(), 'tractograms', + in_ref = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_operations', 'bundle_4_wm.nii.gz') - in_rois = os.path.join(get_home(), 'tractograms', + in_rois = os.path.join(SCILPY_HOME, 'tractograms', 'streamline_operations', 'bundle_4_head_tail_offset.nii.gz') diff --git a/scilpy/tractograms/tests/test_tractogram_operations.py b/scilpy/tractograms/tests/test_tractogram_operations.py index e488a6a43..4b1df4197 100644 --- a/scilpy/tractograms/tests/test_tractogram_operations.py +++ b/scilpy/tractograms/tests/test_tractogram_operations.py @@ -6,16 +6,26 @@ import numpy as np from dipy.io.streamline import load_tractogram -from scilpy.io.fetcher import fetch_data, get_testing_files_dict, get_home -from scilpy.tractograms.tractogram_operations import flip_sft, \ - shuffle_streamlines, perform_tractogram_operation_on_lines, intersection, union, \ - difference, intersection_robust, difference_robust, union_robust, \ - concatenate_sft, perform_tractogram_operation_on_sft +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict +from scilpy.tractograms.tractogram_operations import ( + concatenate_sft, + difference, + difference_robust, + flip_sft, + intersection, + intersection_robust, + perform_tractogram_operation_on_lines, + perform_tractogram_operation_on_sft, + shuffle_streamlines, + union, + union_robust) + # Prepare SFT fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') tmp_dir = tempfile.TemporaryDirectory() -in_sft = os.path.join(get_home(), 'surface_vtk_fib', 'gyri_fanning.trk') +in_sft = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'gyri_fanning.trk') # Loading and keeping only a few streamlines for faster testing. sft = load_tractogram(in_sft, 'same')[0:4] diff --git a/scripts/tests/test_NODDI_maps.py b/scripts/tests/test_NODDI_maps.py index 946656adc..231180e48 100644 --- a/scripts/tests/test_NODDI_maps.py +++ b/scripts/tests/test_NODDI_maps.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['commit_amico.zip']) @@ -18,13 +19,13 @@ def test_help_option(script_runner): def test_execution_commit_amico(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'commit_amico', + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') - mask = os.path.join(get_home(), 'commit_amico', + mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') ret = script_runner.run('scil_NODDI_maps.py', in_dwi, in_bval, in_bvec, '--mask', mask, diff --git a/scripts/tests/test_NODDI_priors.py b/scripts/tests/test_NODDI_priors.py index 577ee2f9e..9e9ef59ed 100644 --- a/scripts/tests/test_NODDI_priors.py +++ b/scripts/tests/test_NODDI_priors.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,13 +19,13 @@ def test_help_option(script_runner): def test_execution_commit_amico(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fa = os.path.join(get_home(), 'processing', + in_fa = os.path.join(SCILPY_HOME, 'processing', 'fa.nii.gz') - in_ad = os.path.join(get_home(), 'processing', + in_ad = os.path.join(SCILPY_HOME, 'processing', 'ad.nii.gz') - in_md = os.path.join(get_home(), 'processing', + in_md = os.path.join(SCILPY_HOME, 'processing', 'md.nii.gz') - in_rd = os.path.join(get_home(), 'processing', + in_rd = os.path.join(SCILPY_HOME, 'processing', 'rd.nii.gz') ret = script_runner.run('scil_NODDI_priors.py', in_fa, in_ad, in_rd, in_md, '--out_txt_1fiber_para', '1fiber_para.txt', diff --git a/scripts/tests/test_aodf_metrics.py b/scripts/tests/test_aodf_metrics.py index f2b6cbc19..c6452bf65 100644 --- a/scripts/tests/test_aodf_metrics.py +++ b/scripts/tests/test_aodf_metrics.py @@ -6,7 +6,6 @@ from scilpy.io.dvc import pull_test_case_package - # If they already exist, this only takes 5 seconds (check md5sum) test_data_root = pull_test_case_package("aodf") tmp_dir = tempfile.TemporaryDirectory() @@ -52,7 +51,7 @@ def test_execution_not_all(script_runner): def test_assert_symmetric_input(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) in_fodf = os.path.join( - f"{test_data_root}/fodf_descoteaux07.nii.gz") + f"{test_data_root}/fodf_descoteaux07_sub.nii.gz") # Using a low resolution sphere for peak extraction reduces process time ret = script_runner.run('scil_aodf_metrics.py', in_fodf, @@ -63,7 +62,7 @@ def test_assert_symmetric_input(script_runner): def test_execution_symmetric_input(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) in_fodf = os.path.join( - f"{test_data_root}/fodf_descoteaux07.nii.gz") + f"{test_data_root}/fodf_descoteaux07_sub.nii.gz") # Using a low resolution sphere for peak extraction reduces process time ret = script_runner.run('scil_aodf_metrics.py', in_fodf, diff --git a/scripts/tests/test_apply_transform_to_hdf5.py b/scripts/tests/test_apply_transform_to_hdf5.py index 2819175e9..330f29781 100644 --- a/scripts/tests/test_apply_transform_to_hdf5.py +++ b/scripts/tests/test_apply_transform_to_hdf5.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,11 +19,11 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_h5 = os.path.join(get_home(), 'connectivity', + in_h5 = os.path.join(SCILPY_HOME, 'connectivity', 'decompose.h5') - in_target = os.path.join(get_home(), 'connectivity', + in_target = os.path.join(SCILPY_HOME, 'connectivity', 'endpoints_atlas.nii.gz') - in_transfo = os.path.join(get_home(), 'connectivity', + in_transfo = os.path.join(SCILPY_HOME, 'connectivity', 'affine.txt') ret = script_runner.run('scil_apply_transform_to_hdf5.py', in_h5, in_target, in_transfo, 'decompose_lin.h5') diff --git a/scripts/tests/test_bids_validate.py b/scripts/tests/test_bids_validate.py index 2da561d12..09e9765c5 100644 --- a/scripts/tests/test_bids_validate.py +++ b/scripts/tests/test_bids_validate.py @@ -2,13 +2,15 @@ # -*- coding: utf-8 -*- import json +import os +import tempfile + import nibabel as nib import numpy as np -import os import pytest -import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bids_json.zip']) @@ -311,7 +313,7 @@ def compare_jsons(json_output, test_dir): test_json[key] = value.replace(test_dir + os.path.sep,'') # Open correct json file - result_json = os.path.join(get_home(), 'bids_json', json_output.replace('test', 'result')) + result_json = os.path.join(SCILPY_HOME, 'bids_json', json_output.replace('test', 'result')) with open(result_json, 'r') as f: result = json.load(f)[0] diff --git a/scripts/tests/test_bingham_metrics.py b/scripts/tests/test_bingham_metrics.py index 6443a2333..aa4f11526 100644 --- a/scripts/tests/test_bingham_metrics.py +++ b/scripts/tests/test_bingham_metrics.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,7 +20,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bingham = os.path.join(get_home(), 'processing', + in_bingham = os.path.join(SCILPY_HOME, 'processing', 'fodf_bingham.nii.gz') ret = script_runner.run('scil_bingham_metrics.py', @@ -31,9 +32,9 @@ def test_execution_processing(script_runner): def test_execution_processing_mask(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bingham = os.path.join(get_home(), 'processing', + in_bingham = os.path.join(SCILPY_HOME, 'processing', 'fodf_bingham.nii.gz') - in_mask = os.path.join(get_home(), 'processing', + in_mask = os.path.join(SCILPY_HOME, 'processing', 'seed.nii.gz') ret = script_runner.run('scil_bingham_metrics.py', @@ -45,7 +46,7 @@ def test_execution_processing_mask(script_runner): def test_execution_processing_not_all(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bingham = os.path.join(get_home(), 'processing', + in_bingham = os.path.join(SCILPY_HOME, 'processing', 'fodf_bingham.nii.gz') ret = script_runner.run('scil_bingham_metrics.py', diff --git a/scripts/tests/test_btensor_metrics.py b/scripts/tests/test_btensor_metrics.py index 0156c5ef1..fc19b8ff8 100644 --- a/scripts/tests/test_btensor_metrics.py +++ b/scripts/tests/test_btensor_metrics.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['btensor_testdata.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,19 +18,19 @@ def test_help_option(script_runner): def test_nb_btensors_check(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - fa = os.path.join(get_home(), 'btensor', + fa = os.path.join(SCILPY_HOME, 'btensor', 'fa.nii.gz') ret = script_runner.run('scil_btensor_metrics.py', '--in_dwis', @@ -52,19 +53,19 @@ def test_nb_btensors_check(script_runner): def test_inputs_check(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - fa = os.path.join(get_home(), 'btensor', + fa = os.path.join(SCILPY_HOME, 'btensor', 'fa.nii.gz') ret = script_runner.run('scil_btensor_metrics.py', '--in_dwis', @@ -96,25 +97,25 @@ def test_inputs_check(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - in_dwi_sph = os.path.join(get_home(), 'btensor_testdata', + in_dwi_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_spherical.nii.gz') - in_bval_sph = os.path.join(get_home(), 'btensor_testdata', + in_bval_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvals') - in_bvec_sph = os.path.join(get_home(), 'btensor_testdata', + in_bvec_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvecs') - fa = os.path.join(get_home(), 'btensor_testdata', + fa = os.path.join(SCILPY_HOME, 'btensor_testdata', 'fa.nii.gz') ret = script_runner.run('scil_btensor_metrics.py', '--in_dwis', diff --git a/scripts/tests/test_bundle_compute_centroid.py b/scripts/tests/test_bundle_compute_centroid.py index cdefbc2ed..a3e4ffb00 100644 --- a/scripts/tests/test_bundle_compute_centroid.py +++ b/scripts/tests/test_bundle_compute_centroid.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM_uni.trk') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni.trk') ret = script_runner.run('scil_bundle_compute_centroid.py', in_bundle, 'IFGWM_uni_c.trk') assert ret.success diff --git a/scripts/tests/test_bundle_compute_endpoints_map.py b/scripts/tests/test_bundle_compute_endpoints_map.py index 43ed906c7..a9a73f845 100644 --- a/scripts/tests/test_bundle_compute_endpoints_map.py +++ b/scripts/tests/test_bundle_compute_endpoints_map.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM_uni.trk') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni.trk') ret = script_runner.run('scil_bundle_compute_endpoints_map.py', in_bundle, 'head.nii.gz', 'tail.nii.gz', '--binary') diff --git a/scripts/tests/test_bundle_diameter.py b/scripts/tests/test_bundle_diameter.py index e9c50f49c..b489286ac 100644 --- a/scripts/tests/test_bundle_diameter.py +++ b/scripts/tests/test_bundle_diameter.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') - in_labels = os.path.join(get_home(), 'tractometry', + in_labels = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_labels_map.nii.gz') ret = script_runner.run('scil_estimate_bundles_diameter.py', in_bundle, in_labels, diff --git a/scripts/tests/test_bundle_filter_by_occurence.py b/scripts/tests/test_bundle_filter_by_occurence.py index 79b7a819a..102012743 100644 --- a/scripts/tests/test_bundle_filter_by_occurence.py +++ b/scripts/tests/test_bundle_filter_by_occurence.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'filtering', 'bundle_4.trk') - in_2 = os.path.join(get_home(), 'filtering', 'bundle_4_filtered.trk') - in_3 = os.path.join(get_home(), 'filtering', + in_1 = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4.trk') + in_2 = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4_filtered.trk') + in_3 = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4_filtered_no_loops.trk') prefix = 'test_voting_' diff --git a/scripts/tests/test_bundle_generate_priors.py b/scripts/tests/test_bundle_generate_priors.py index a399bcbf8..f2e979b60 100644 --- a/scripts/tests/test_bundle_generate_priors.py +++ b/scripts/tests/test_bundle_generate_priors.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bst.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_bst(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'bst', 'rpt_m_lin.trk') - in_fodf = os.path.join(get_home(), 'bst', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'bst', 'mask.nii.gz') + in_bundle = os.path.join(SCILPY_HOME, 'bst', 'rpt_m_lin.trk') + in_fodf = os.path.join(SCILPY_HOME, 'bst', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'bst', 'mask.nii.gz') ret = script_runner.run('scil_bundle_generate_priors.py', in_bundle, in_fodf, in_mask, '--todi_sigma', '1', '--out_prefix', 'rpt_m', diff --git a/scripts/tests/test_bundle_label_map.py b/scripts/tests/test_bundle_label_map.py index 2847821e9..6442a9922 100644 --- a/scripts/tests/test_bundle_label_map.py +++ b/scripts/tests/test_bundle_label_map.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM.trk') - in_centroid = os.path.join(get_home(), 'tractometry', 'IFGWM_uni_c_10.trk') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') + in_centroid = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni_c_10.trk') ret = script_runner.run('scil_bundle_label_map.py', in_bundle, in_centroid, 'results_dir/', '--colormap', 'viridis') assert ret.success diff --git a/scripts/tests/test_bundle_mean_fixel_afd.py b/scripts/tests/test_bundle_mean_fixel_afd.py index 91845ad26..22ebe6658 100644 --- a/scripts/tests/test_bundle_mean_fixel_afd.py +++ b/scripts/tests/test_bundle_mean_fixel_afd.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,8 +19,8 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracking = os.path.join(get_home(), 'processing', 'tracking.trk') - in_fodf = os.path.join(get_home(), 'processing', + in_tracking = os.path.join(SCILPY_HOME, 'processing', 'tracking.trk') + in_fodf = os.path.join(SCILPY_HOME, 'processing', 'fodf_descoteaux07.nii.gz') ret = script_runner.run('scil_bundle_mean_fixel_afd.py', in_tracking, in_fodf, 'afd_test.nii.gz', diff --git a/scripts/tests/test_bundle_mean_fixel_afd_from_hdf5.py b/scripts/tests/test_bundle_mean_fixel_afd_from_hdf5.py index 56639aa70..81758f742 100644 --- a/scripts/tests/test_bundle_mean_fixel_afd_from_hdf5.py +++ b/scripts/tests/test_bundle_mean_fixel_afd_from_hdf5.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -20,8 +20,8 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_h5 = os.path.join(get_home(), 'connectivity', 'decompose.h5') - in_fodf = os.path.join(get_home(), 'connectivity', 'fodf.nii.gz') + in_h5 = os.path.join(SCILPY_HOME, 'connectivity', 'decompose.h5') + in_fodf = os.path.join(SCILPY_HOME, 'connectivity', 'fodf.nii.gz') ret = script_runner.run('scil_bundle_mean_fixel_afd_from_hdf5.py', in_h5, in_fodf, 'decompose_afd.nii.gz', '--length_weighting', '--sh_basis', 'descoteaux07', diff --git a/scripts/tests/test_bundle_mean_fixel_bingham_metric.py b/scripts/tests/test_bundle_mean_fixel_bingham_metric.py index 5d81eec72..fa86c3cb2 100644 --- a/scripts/tests/test_bundle_mean_fixel_bingham_metric.py +++ b/scripts/tests/test_bundle_mean_fixel_bingham_metric.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -20,9 +21,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bingham = os.path.join(get_home(), 'processing', 'fodf_bingham.nii.gz') - in_metric = os.path.join(get_home(), 'processing', 'fd.nii.gz') - in_bundles = os.path.join(get_home(), 'processing', 'tracking.trk') + in_bingham = os.path.join(SCILPY_HOME, 'processing', 'fodf_bingham.nii.gz') + in_metric = os.path.join(SCILPY_HOME, 'processing', 'fd.nii.gz') + in_bundles = os.path.join(SCILPY_HOME, 'processing', 'tracking.trk') ret = script_runner.run( 'scil_bundle_mean_fixel_bingham_metric.py', diff --git a/scripts/tests/test_bundle_mean_std.py b/scripts/tests/test_bundle_mean_std.py index 1eb02a666..d3e3a6221 100644 --- a/scripts/tests/test_bundle_mean_std.py +++ b/scripts/tests/test_bundle_mean_std.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution_tractometry_whole(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM.trk') - in_ref = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') + in_ref = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') ret = script_runner.run('scil_bundle_mean_std.py', in_bundle, in_ref, '--density_weighting', '--include_dps') assert ret.success @@ -28,10 +28,10 @@ def test_execution_tractometry_whole(script_runner): def test_execution_tractometry_per_point(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM.trk') - in_label = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') + in_label = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_labels_map.nii.gz') - in_ref = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') ret = script_runner.run('scil_bundle_mean_std.py', in_bundle, in_ref, '--per_point', in_label, '--density_weighting') diff --git a/scripts/tests/test_bundle_pairwise_comparison.py b/scripts/tests/test_bundle_pairwise_comparison.py index a5b825e84..12bb72753 100644 --- a/scripts/tests/test_bundle_pairwise_comparison.py +++ b/scripts/tests/test_bundle_pairwise_comparison.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -20,10 +20,10 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run( 'scil_bundle_pairwise_comparison.py', in_1, in_2, 'AF_L_similarity.json', @@ -34,10 +34,10 @@ def test_execution_bundles(script_runner): def test_single(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run( 'scil_bundle_pairwise_comparison.py', in_2, 'AF_L_similarity_single.json', @@ -49,10 +49,10 @@ def test_single(script_runner): def test_no_overlap(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run( 'scil_bundle_pairwise_comparison.py', in_1, in_2, 'AF_L_similarity_no_overlap.json', @@ -64,10 +64,10 @@ def test_no_overlap(script_runner): def test_ratio(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run( 'scil_bundle_pairwise_comparison.py', in_2, 'AF_L_similarity_ratio.json', @@ -83,10 +83,10 @@ def test_ratio_fail(script_runner): The test should fail. """ os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run( 'scil_bundle_pairwise_comparison.py', in_1, in_2, 'AF_L_similarity_fail.json', diff --git a/scripts/tests/test_bundle_score_many_bundles_one_tractogram.py b/scripts/tests/test_bundle_score_many_bundles_one_tractogram.py index ce9fa5288..ac1f4e837 100644 --- a/scripts/tests/test_bundle_score_many_bundles_one_tractogram.py +++ b/scripts/tests/test_bundle_score_many_bundles_one_tractogram.py @@ -3,8 +3,8 @@ import shutil import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_score_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'tracking', 'pft.trk') + in_tractogram = os.path.join(SCILPY_HOME, 'tracking', 'pft.trk') # Pretend we have our segmented bundles on disk shutil.copyfile(in_tractogram, './NC.trk') @@ -31,11 +31,11 @@ def test_score_bundles(script_runner): json_contents = { "bundle1": { - "gt_mask": os.path.join(get_home(), 'tracking', + "gt_mask": os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz'), }, "bundle2": { - "gt_mask": os.path.join(get_home(), 'tracking', + "gt_mask": os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz'), } } diff --git a/scripts/tests/test_bundle_score_same_bundle_many_segmentations.py b/scripts/tests/test_bundle_score_same_bundle_many_segmentations.py index 22c38400f..cc64ab043 100644 --- a/scripts/tests/test_bundle_score_same_bundle_many_segmentations.py +++ b/scripts/tests/test_bundle_score_same_bundle_many_segmentations.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -19,12 +20,12 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') - in_tractogram = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.trk') - in_model = os.path.join(get_home(), 'bundles', 'fibercup_atlas', + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') + in_tractogram = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.trk') + in_model = os.path.join(SCILPY_HOME, 'bundles', 'fibercup_atlas', 'subj_1', 'bundle_0.trk') ret = script_runner.run( 'scil_bundle_score_same_bundle_many_segmentations.py', diff --git a/scripts/tests/test_bundle_shape_measures.py b/scripts/tests/test_bundle_shape_measures.py index 609fc85fb..5d2ec3f19 100644 --- a/scripts/tests/test_bundle_shape_measures.py +++ b/scripts/tests/test_bundle_shape_measures.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -19,10 +19,10 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'bundles', 'bundle_0_reco.tck') - in_2 = os.path.join(get_home(), 'bundles', 'voting_results', + in_1 = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') + in_2 = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', 'bundle_all_1mm.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run('scil_bundle_shape_measures.py', in_1, in_2, '--out_json', 'AF_L_measures.json', '--reference', in_ref, '--processes', '1') diff --git a/scripts/tests/test_bundle_volume_per_label.py b/scripts/tests/test_bundle_volume_per_label.py index 51aabbfba..15cf46d22 100644 --- a/scripts/tests/test_bundle_volume_per_label.py +++ b/scripts/tests/test_bundle_volume_per_label.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_label_map = os.path.join(get_home(), 'tractometry', + in_label_map = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_labels_map.nii.gz') ret = script_runner.run('scil_bundle_volume_per_label.py', in_label_map, 'IFGWM') diff --git a/scripts/tests/test_compute_hdf5_average_density_map.py b/scripts/tests/test_compute_hdf5_average_density_map.py index e775d0719..42721e98c 100644 --- a/scripts/tests/test_compute_hdf5_average_density_map.py +++ b/scripts/tests/test_compute_hdf5_average_density_map.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_h5 = os.path.join(get_home(), 'connectivity', + in_h5 = os.path.join(SCILPY_HOME, 'connectivity', 'decompose.h5') ret = script_runner.run('scil_compute_hdf5_average_density_map.py', in_h5, 'avg_density_maps/', '--binary', diff --git a/scripts/tests/test_compute_pca.py b/scripts/tests/test_compute_pca.py index 687d3603d..3124964e4 100644 --- a/scripts/tests/test_compute_pca.py +++ b/scripts/tests/test_compute_pca.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['stats.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_pca(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - input_folder = os.path.join(get_home(), 'stats/pca') - output_folder = os.path.join(get_home(), 'stats/pca_out') - ids = os.path.join(get_home(), 'stats/pca', 'list_id.txt') + input_folder = os.path.join(SCILPY_HOME, 'stats/pca') + output_folder = os.path.join(SCILPY_HOME, 'stats/pca_out') + ids = os.path.join(SCILPY_HOME, 'stats/pca', 'list_id.txt') ret = script_runner.run( 'scil_compute_pca.py', input_folder, output_folder, '--metrics', 'ad', 'fa', 'md', 'rd', 'nufo', 'afd_total', 'afd_fixel', '--list_ids', diff --git a/scripts/tests/test_compute_seed_density_map.py b/scripts/tests/test_compute_seed_density_map.py index 966763b52..a97747646 100644 --- a/scripts/tests/test_compute_seed_density_map.py +++ b/scripts/tests/test_compute_seed_density_map.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracking = os.path.join(get_home(), 'processing', + in_tracking = os.path.join(SCILPY_HOME, 'processing', 'tracking.trk') ret = script_runner.run('scil_compute_seed_density_map.py', in_tracking, 'seeds_density.nii.gz') diff --git a/scripts/tests/test_connectivity_compare_populations.py b/scripts/tests/test_connectivity_compare_populations.py index 8f3161852..d36d76c42 100644 --- a/scripts/tests/test_connectivity_compare_populations.py +++ b/scripts/tests/test_connectivity_compare_populations.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_1 = os.path.join(get_home(), 'connectivity', 'sc.npy') - in_2 = os.path.join(get_home(), 'connectivity', 'sc_norm.npy') - in_mask = os.path.join(get_home(), 'connectivity', 'mask.npy') + in_1 = os.path.join(SCILPY_HOME, 'connectivity', 'sc.npy') + in_2 = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') + in_mask = os.path.join(SCILPY_HOME, 'connectivity', 'mask.npy') ret = script_runner.run('scil_connectivity_compare_populations.py', 'pval.npy', '--in_g1', in_1, '--in_g2', in_2, '--filtering_mask', in_mask) diff --git a/scripts/tests/test_connectivity_compute_matrices.py b/scripts/tests/test_connectivity_compute_matrices.py index b6b0179f2..4517ff633 100644 --- a/scripts/tests/test_connectivity_compute_matrices.py +++ b/scripts/tests/test_connectivity_compute_matrices.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,11 +19,11 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_h5 = os.path.join(get_home(), 'connectivity', 'decompose.h5') - in_atlas = os.path.join(get_home(), 'connectivity', + in_h5 = os.path.join(SCILPY_HOME, 'connectivity', 'decompose.h5') + in_atlas = os.path.join(SCILPY_HOME, 'connectivity', 'endpoints_atlas.nii.gz') - in_avg = os.path.join(get_home(), 'connectivity', 'avg_density_maps/') - in_afd = os.path.join(get_home(), 'connectivity', 'afd_max.nii.gz') + in_avg = os.path.join(SCILPY_HOME, 'connectivity', 'avg_density_maps/') + in_afd = os.path.join(SCILPY_HOME, 'connectivity', 'afd_max.nii.gz') ret = script_runner.run('scil_connectivity_compute_matrices.py', in_h5, in_atlas, '--volume', 'vol.npy', '--streamline_count', 'sc.npy', diff --git a/scripts/tests/test_connectivity_filter.py b/scripts/tests/test_connectivity_filter.py index e2f27b8b8..7d79bb71e 100644 --- a/scripts/tests/test_connectivity_filter.py +++ b/scripts/tests/test_connectivity_filter.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc.npy') - in_sim = os.path.join(get_home(), 'connectivity', + in_sim = os.path.join(SCILPY_HOME, 'connectivity', 'len.npy') ret = script_runner.run('scil_connectivity_filter.py', 'mask.npy', '--greater_than', in_sc, '5', '1', diff --git a/scripts/tests/test_connectivity_graph_measures.py b/scripts/tests/test_connectivity_graph_measures.py index 5d2b2dab9..73ec1e48b 100644 --- a/scripts/tests/test_connectivity_graph_measures.py +++ b/scripts/tests/test_connectivity_graph_measures.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', 'sc_norm.npy') - in_len = os.path.join(get_home(), 'connectivity', 'len.npy') + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') + in_len = os.path.join(SCILPY_HOME, 'connectivity', 'len.npy') ret = script_runner.run('scil_connectivity_graph_measures.py', in_sc, in_len, 'gtm.json', '--avg_node_wise', '--small_world') diff --git a/scripts/tests/test_connectivity_math.py b/scripts/tests/test_connectivity_math.py index 82a0267ac..88e5f111f 100644 --- a/scripts/tests/test_connectivity_math.py +++ b/scripts/tests/test_connectivity_math.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_connectivity_div(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc.npy') - in_vol = os.path.join(get_home(), 'connectivity', + in_vol = os.path.join(SCILPY_HOME, 'connectivity', 'vol.npy') ret = script_runner.run('scil_connectivity_math.py', 'division', in_sc, in_vol, 'sc_norm_vol.npy') @@ -30,7 +30,7 @@ def test_execution_connectivity_div(script_runner): def test_execution_connectivity_add(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc.npy') ret = script_runner.run('scil_connectivity_math.py', 'addition', in_sc, '10', 'sc_add_10.npy') @@ -39,7 +39,7 @@ def test_execution_connectivity_add(script_runner): def test_execution_connectivity_lower_threshold(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc.npy') ret = script_runner.run('scil_connectivity_math.py', 'lower_threshold', in_sc, '5', 'sc_lower_threshold.npy') diff --git a/scripts/tests/test_connectivity_normalize.py b/scripts/tests/test_connectivity_normalize.py index 6cf8a41db..4bd24c435 100644 --- a/scripts/tests/test_connectivity_normalize.py +++ b/scripts/tests/test_connectivity_normalize.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,11 +19,11 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', 'sc.npy') - in_len = os.path.join(get_home(), 'connectivity', 'len.npy') - in_atlas = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc.npy') + in_len = os.path.join(SCILPY_HOME, 'connectivity', 'len.npy') + in_atlas = os.path.join(SCILPY_HOME, 'connectivity', 'endpoints_atlas.nii.gz') - in_labels_list = os.path.join(get_home(), 'connectivity', + in_labels_list = os.path.join(SCILPY_HOME, 'connectivity', 'labels_list.txt') ret = script_runner.run('scil_connectivity_normalize.py', in_sc, 'sc_norm.npy', '--length', in_len, diff --git a/scripts/tests/test_connectivity_pairwise_agreement.py b/scripts/tests/test_connectivity_pairwise_agreement.py index 968c57ecc..28a084180 100644 --- a/scripts/tests/test_connectivity_pairwise_agreement.py +++ b/scripts/tests/test_connectivity_pairwise_agreement.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -20,8 +20,8 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', 'sc_norm.npy') - in_len = os.path.join(get_home(), 'connectivity', 'len.npy') + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') + in_len = os.path.join(SCILPY_HOME, 'connectivity', 'len.npy') ret = script_runner.run('scil_connectivity_pairwise_agreement.py', in_sc, in_len, 'diff.json', '--single_compare', in_sc) assert ret.success diff --git a/scripts/tests/test_connectivity_print_filenames.py b/scripts/tests/test_connectivity_print_filenames.py index f87446a6e..2740de312 100644 --- a/scripts/tests/test_connectivity_print_filenames.py +++ b/scripts/tests/test_connectivity_print_filenames.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') - in_labels_list = os.path.join(get_home(), 'connectivity', + in_labels_list = os.path.join(SCILPY_HOME, 'connectivity', 'labels_list.txt') ret = script_runner.run('scil_connectivity_print_filenames.py', in_sc, in_labels_list, 'success.txt') diff --git a/scripts/tests/test_connectivity_reorder_rois.py b/scripts/tests/test_connectivity_reorder_rois.py index f5b28dd40..f03243a60 100644 --- a/scripts/tests/test_connectivity_reorder_rois.py +++ b/scripts/tests/test_connectivity_reorder_rois.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_compute_OLO(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') - in_labels_list = os.path.join(get_home(), 'connectivity', + in_labels_list = os.path.join(SCILPY_HOME, 'connectivity', 'labels_list.txt') ret = script_runner.run('scil_connectivity_reorder_rois.py', in_sc, '--optimal_leaf_ordering', 'OLO.txt', @@ -32,9 +32,9 @@ def test_execution_compute_OLO(script_runner): def test_execution_apply_ordering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', 'sc_norm.npy') - in_txt = os.path.join(get_home(), 'connectivity', 'reorder.txt') - in_labels_list = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') + in_txt = os.path.join(SCILPY_HOME, 'connectivity', 'reorder.txt') + in_labels_list = os.path.join(SCILPY_HOME, 'connectivity', 'labels_list.txt') ret = script_runner.run('scil_connectivity_reorder_rois.py', in_sc, '--in_ordering', in_txt, diff --git a/scripts/tests/test_convert_tensors.py b/scripts/tests/test_convert_tensors.py index 84cf1604f..ee5fdfa77 100644 --- a/scripts/tests/test_convert_tensors.py +++ b/scripts/tests/test_convert_tensors.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -21,11 +22,11 @@ def test_execution_processing(script_runner): # No tensor in the current test data! I'm running the dti_metrics # to create one. - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') script_runner.run('scil_dti_metrics.py', in_dwi, in_bval, in_bvec, '--not_all', diff --git a/scripts/tests/test_decompose_connectivity.py b/scripts/tests/test_decompose_connectivity.py index 0a20f57ae..ca08dc12a 100644 --- a/scripts/tests/test_decompose_connectivity.py +++ b/scripts/tests/test_decompose_connectivity.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'connectivity', + in_bundle = os.path.join(SCILPY_HOME, 'connectivity', 'bundle_all_1mm.trk') - in_atlas = os.path.join(get_home(), 'connectivity', + in_atlas = os.path.join(SCILPY_HOME, 'connectivity', 'endpoints_atlas.nii.gz') ret = script_runner.run('scil_decompose_connectivity.py', in_bundle, in_atlas, 'decompose.h5', diff --git a/scripts/tests/test_denoising_nlmeans.py b/scripts/tests/test_denoising_nlmeans.py index bca4c3e17..89cf4cc4e 100644 --- a/scripts/tests/test_denoising_nlmeans.py +++ b/scripts/tests/test_denoising_nlmeans.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'others', 't1_resample.nii.gz') + in_img = os.path.join(SCILPY_HOME, 'others', 't1_resample.nii.gz') ret = script_runner.run('scil_denoising_nlmeans.py', in_img, 't1_denoised.nii.gz', '4', '--processes', '1') assert ret.success diff --git a/scripts/tests/test_dki_metrics.py b/scripts/tests/test_dki_metrics.py index 2f4b47379..1192e7ac3 100644 --- a/scripts/tests/test_dki_metrics.py +++ b/scripts/tests/test_dki_metrics.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dki_metrics.py', in_dwi, in_bval, in_bvec, '--not_all', diff --git a/scripts/tests/test_dti_metrics.py b/scripts/tests/test_dti_metrics.py index 093f1bf9e..c85c914e0 100644 --- a/scripts/tests/test_dti_metrics.py +++ b/scripts/tests/test_dti_metrics.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,12 +19,12 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', '1000.bvec') + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_1000.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') # No mask fitting with this data? Creating our own. - mask = os.path.join(get_home(), 'processing', 'ad.nii.gz') + mask = os.path.join(SCILPY_HOME, 'processing', 'ad.nii.gz') mask_uint8 = os.path.join('mask_uint8.nii.gz') script_runner.run('scil_volume_math.py', 'convert', mask, mask_uint8, '--data_type', 'uint8') diff --git a/scripts/tests/test_dwi_apply_bias_field.py b/scripts/tests/test_dwi_apply_bias_field.py index 09417552d..9256f4f88 100644 --- a/scripts/tests/test_dwi_apply_bias_field.py +++ b/scripts/tests/test_dwi_apply_bias_field.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bias = os.path.join(get_home(), 'processing', + in_bias = os.path.join(SCILPY_HOME, 'processing', 'bias_field_b0.nii.gz') ret = script_runner.run('scil_dwi_apply_bias_field.py', in_dwi, in_bias, 'dwi_crop_n4.nii.gz') diff --git a/scripts/tests/test_dwi_compute_snr.py b/scripts/tests/test_dwi_compute_snr.py index cc03f95a4..82b9836e9 100644 --- a/scripts/tests/test_dwi_compute_snr.py +++ b/scripts/tests/test_dwi_compute_snr.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['processing.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -18,15 +18,15 @@ def test_help_option(script_runner): def test_snr(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') - in_mask = os.path.join(get_home(), 'processing', + in_mask = os.path.join(SCILPY_HOME, 'processing', 'cc.nii.gz') - noise_mask = os.path.join(get_home(), 'processing', + noise_mask = os.path.join(SCILPY_HOME, 'processing', 'small_roi_gm_mask.nii.gz') ret = script_runner.run('scil_dwi_compute_snr.py', in_dwi, diff --git a/scripts/tests/test_dwi_concatenate.py b/scripts/tests/test_dwi_concatenate.py index 8139ac5f7..bfb4a2e83 100644 --- a/scripts/tests/test_dwi_concatenate.py +++ b/scripts/tests/test_dwi_concatenate.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing_concatenate(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_concatenate.py', 'dwi_concat.nii.gz', 'concat.bval', 'concat.bvec', diff --git a/scripts/tests/test_dwi_detect_volume_outliers.py b/scripts/tests/test_dwi_detect_volume_outliers.py index 2eec5a142..0db5101e4 100644 --- a/scripts/tests/test_dwi_detect_volume_outliers.py +++ b/scripts/tests/test_dwi_detect_volume_outliers.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_detect_volume_outliers.py', in_dwi, in_bval, in_bvec, '-v') diff --git a/scripts/tests/test_dwi_extract_b0.py b/scripts/tests/test_dwi_extract_b0.py index 68706fc8f..b5ae8a7d8 100644 --- a/scripts/tests/test_dwi_extract_b0.py +++ b/scripts/tests/test_dwi_extract_b0.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_extract_b0.py', in_dwi, in_bval, in_bvec, 'b0_mean.nii.gz', '--mean', '--b0', '20') diff --git a/scripts/tests/test_dwi_extract_shell.py b/scripts/tests/test_dwi_extract_shell.py index 30cc23f70..3b40e20cc 100644 --- a/scripts/tests/test_dwi_extract_shell.py +++ b/scripts/tests/test_dwi_extract_shell.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing_1000(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_extract_shell.py', in_dwi, in_bval, in_bvec, '0', '1000', @@ -33,11 +34,11 @@ def test_execution_processing_1000(script_runner): def test_execution_out_indices(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_extract_shell.py', in_dwi, in_bval, in_bvec, '0', '1000', @@ -49,11 +50,11 @@ def test_execution_out_indices(script_runner): def test_execution_processing_3000(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_extract_shell.py', in_dwi, in_bval, in_bvec, '0', '3000', diff --git a/scripts/tests/test_dwi_powder_average.py b/scripts/tests/test_dwi_powder_average.py index c4abe1eca..8cbb67f32 100644 --- a/scripts/tests/test_dwi_powder_average.py +++ b/scripts/tests/test_dwi_powder_average.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,9 +20,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') ret = script_runner.run('scil_dwi_powder_average.py', in_dwi, diff --git a/scripts/tests/test_dwi_reorder_philips.py b/scripts/tests/test_dwi_reorder_philips.py index 386326f30..fcb06839e 100644 --- a/scripts/tests/test_dwi_reorder_philips.py +++ b/scripts/tests/test_dwi_reorder_philips.py @@ -1,14 +1,15 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import os import json +import os import tempfile -from dipy.io.gradients import read_bvals_bvecs import numpy as np +from dipy.io.gradients import read_bvals_bvecs -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -22,9 +23,9 @@ def test_help_option(script_runner): def test_reorder(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') table = np.ones((64, 4)) bval, bvec = read_bvals_bvecs(in_bval, in_bvec) table[:, :3] = bvec @@ -41,9 +42,9 @@ def test_reorder(script_runner): def test_reorder_w_json_old_version(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') table = np.ones((64, 4)) bval, bvec = read_bvals_bvecs(in_bval, in_bvec) table[:, :3] = bvec @@ -64,9 +65,9 @@ def test_reorder_w_json_old_version(script_runner): def test_reorder_w_json_new_version(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') table = np.ones((64, 4)) bval, bvec = read_bvals_bvecs(in_bval, in_bvec) table[:, :3] = bvec diff --git a/scripts/tests/test_dwi_split_by_indices.py b/scripts/tests/test_dwi_split_by_indices.py index 625d1c2c9..7a644d9ee 100644 --- a/scripts/tests/test_dwi_split_by_indices.py +++ b/scripts/tests/test_dwi_split_by_indices.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_split_by_indices.py', in_dwi, in_bval, in_bvec, 'dwi', '5', '15', '25') assert ret.success @@ -28,9 +29,9 @@ def test_execution_processing(script_runner): def test_execution_processing_wrong_indices_given(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_dwi_split_by_indices.py', in_dwi, in_bval, in_bvec, 'dwi', '0', '15', '25') assert (not ret.success) diff --git a/scripts/tests/test_dwi_to_sh.py b/scripts/tests/test_dwi_to_sh.py index 7870631b0..c53ab93f6 100644 --- a/scripts/tests/test_dwi_to_sh.py +++ b/scripts/tests/test_dwi_to_sh.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_3000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '3000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '3000.bvec') ret = script_runner.run('scil_dwi_to_sh.py', in_dwi, in_bval, in_bvec, 'sh_1000.nii.gz') diff --git a/scripts/tests/test_fodf_max_in_ventricles.py b/scripts/tests/test_fodf_max_in_ventricles.py index 2c1a0e20a..eabcc722a 100644 --- a/scripts/tests/test_fodf_max_in_ventricles.py +++ b/scripts/tests/test_fodf_max_in_ventricles.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', + in_fodf = os.path.join(SCILPY_HOME, 'processing', 'fodf.nii.gz') - in_fa = os.path.join(get_home(), 'processing', + in_fa = os.path.join(SCILPY_HOME, 'processing', 'fa.nii.gz') - in_md = os.path.join(get_home(), 'processing', + in_md = os.path.join(SCILPY_HOME, 'processing', 'md.nii.gz') ret = script_runner.run('scil_fodf_max_in_ventricles.py', in_fodf, in_fa, in_md, '--sh_basis', 'tournier07') diff --git a/scripts/tests/test_fodf_memsmt.py b/scripts/tests/test_fodf_memsmt.py index 273a60b87..448f351c8 100644 --- a/scripts/tests/test_fodf_memsmt.py +++ b/scripts/tests/test_fodf_memsmt.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['btensor_testdata.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,23 +18,23 @@ def test_help_option(script_runner): def test_inputs_check(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - in_wm_frf = os.path.join(get_home(), 'btensor_testdata', + in_wm_frf = os.path.join(SCILPY_HOME, 'btensor_testdata', 'wm_frf.txt') - in_gm_frf = os.path.join(get_home(), 'btensor_testdata', + in_gm_frf = os.path.join(SCILPY_HOME, 'btensor_testdata', 'gm_frf.txt') - in_csf_frf = os.path.join(get_home(), 'btensor_testdata', + in_csf_frf = os.path.join(SCILPY_HOME, 'btensor_testdata', 'csf_frf.txt') ret = script_runner.run('scil_fodf_memsmt.py', in_wm_frf, @@ -64,23 +65,23 @@ def test_inputs_check(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_sph = os.path.join(get_home(), 'btensor_testdata', + in_dwi_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_spherical.nii.gz') - in_bval_sph = os.path.join(get_home(), 'btensor_testdata', + in_bval_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvals') - in_bvec_sph = os.path.join(get_home(), 'btensor_testdata', + in_bvec_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvecs') - in_wm_frf = os.path.join(get_home(), 'btensor_testdata', + in_wm_frf = os.path.join(SCILPY_HOME, 'btensor_testdata', 'wm_frf.txt') - in_gm_frf = os.path.join(get_home(), 'btensor_testdata', + in_gm_frf = os.path.join(SCILPY_HOME, 'btensor_testdata', 'gm_frf.txt') - in_csf_frf = os.path.join(get_home(), 'btensor_testdata', + in_csf_frf = os.path.join(SCILPY_HOME, 'btensor_testdata', 'csf_frf.txt') ret = script_runner.run('scil_fodf_memsmt.py', in_wm_frf, diff --git a/scripts/tests/test_fodf_metrics.py b/scripts/tests/test_fodf_metrics.py index 5c8d289dc..8fcbf8aae 100644 --- a/scripts/tests/test_fodf_metrics.py +++ b/scripts/tests/test_fodf_metrics.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', + in_fodf = os.path.join(SCILPY_HOME, 'processing', 'fodf_descoteaux07.nii.gz') ret = script_runner.run('scil_fodf_metrics.py', in_fodf, '--not_al', '--peaks', 'peaks.nii.gz', diff --git a/scripts/tests/test_fodf_msmt.py b/scripts/tests/test_fodf_msmt.py index 7749af9ff..f86a7d00d 100644 --- a/scripts/tests/test_fodf_msmt.py +++ b/scripts/tests/test_fodf_msmt.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['commit_amico.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,13 +18,13 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', 'dwi.bvec') - in_wm_frf = os.path.join(get_home(), 'commit_amico', 'wm_frf.txt') - in_gm_frf = os.path.join(get_home(), 'commit_amico', 'gm_frf.txt') - in_csf_frf = os.path.join(get_home(), 'commit_amico', 'csf_frf.txt') - mask = os.path.join(get_home(), 'commit_amico', 'mask.nii.gz') + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') + in_wm_frf = os.path.join(SCILPY_HOME, 'commit_amico', 'wm_frf.txt') + in_gm_frf = os.path.join(SCILPY_HOME, 'commit_amico', 'gm_frf.txt') + in_csf_frf = os.path.join(SCILPY_HOME, 'commit_amico', 'csf_frf.txt') + mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') ret = script_runner.run('scil_fodf_msmt.py', in_dwi, in_bval, in_bvec, in_wm_frf, in_gm_frf, in_csf_frf, diff --git a/scripts/tests/test_fodf_ssst.py b/scripts/tests/test_fodf_ssst.py index 8a4c57b5b..38c9ad62f 100644 --- a/scripts/tests/test_fodf_ssst.py +++ b/scripts/tests/test_fodf_ssst.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,13 +19,13 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_3000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '3000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '3000.bvec') - in_frf = os.path.join(get_home(), 'processing', + in_frf = os.path.join(SCILPY_HOME, 'processing', 'frf.txt') ret = script_runner.run('scil_fodf_ssst.py', in_dwi, in_bval, in_bvec, in_frf, 'fodf.nii.gz', '--sh_order', '4', diff --git a/scripts/tests/test_fodf_to_bingham.py b/scripts/tests/test_fodf_to_bingham.py index ea08e2bbf..1f93d06f8 100644 --- a/scripts/tests/test_fodf_to_bingham.py +++ b/scripts/tests/test_fodf_to_bingham.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,7 +20,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', + in_fodf = os.path.join(SCILPY_HOME, 'processing', 'fodf_descoteaux07.nii.gz') ret = script_runner.run('scil_fodf_to_bingham.py', in_fodf, 'bingham.nii.gz', @@ -34,9 +35,9 @@ def test_execution_processing(script_runner): def test_execution_processing_mask(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', + in_fodf = os.path.join(SCILPY_HOME, 'processing', 'fodf_descoteaux07.nii.gz') - in_mask = os.path.join(get_home(), 'processing', + in_mask = os.path.join(SCILPY_HOME, 'processing', 'seed.nii.gz') ret = script_runner.run('scil_fodf_to_bingham.py', in_fodf, 'bingham.nii.gz', diff --git a/scripts/tests/test_freewater_maps.py b/scripts/tests/test_freewater_maps.py index 2f2c1ada3..1d3f7f5cc 100644 --- a/scripts/tests/test_freewater_maps.py +++ b/scripts/tests/test_freewater_maps.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['commit_amico.zip']) @@ -18,13 +19,13 @@ def test_help_option(script_runner): def test_execution_commit_amico(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'commit_amico', + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') - mask = os.path.join(get_home(), 'commit_amico', + mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') ret = script_runner.run('scil_freewater_maps.py', in_dwi, in_bval, in_bvec, '--mask', mask, diff --git a/scripts/tests/test_frf_mean.py b/scripts/tests/test_frf_mean.py index 38fb77923..40cbbf3c6 100644 --- a/scripts/tests/test_frf_mean.py +++ b/scripts/tests/test_frf_mean.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip', @@ -26,14 +27,14 @@ def test_execution_processing_ssst(script_runner): 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') + in_frf = os.path.join(SCILPY_HOME, 'commit_amico', 'wm_frf.txt') ret = script_runner.run('scil_frf_mean.py', in_frf, in_frf, 'mfrf2.txt') assert ret.success def test_execution_processing_bad_input(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_wm_frf = os.path.join(get_home(), 'commit_amico', 'wm_frf.txt') - in_frf = os.path.join(get_home(), 'processing', 'frf.txt') + in_wm_frf = os.path.join(SCILPY_HOME, 'commit_amico', 'wm_frf.txt') + in_frf = os.path.join(SCILPY_HOME, 'processing', 'frf.txt') ret = script_runner.run('scil_frf_mean.py', in_wm_frf, in_frf, 'mfrf3.txt') assert not ret.success diff --git a/scripts/tests/test_frf_memsmt.py b/scripts/tests/test_frf_memsmt.py index fe3022196..9d57c86c8 100644 --- a/scripts/tests/test_frf_memsmt.py +++ b/scripts/tests/test_frf_memsmt.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['btensor_testdata.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,23 +18,23 @@ def test_help_option(script_runner): def test_roi_center_shape_parameter(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - in_dwi_sph = os.path.join(get_home(), 'btensor_testdata', + in_dwi_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_spherical.nii.gz') - in_bval_sph = os.path.join(get_home(), 'btensor_testdata', + in_bval_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvals') - in_bvec_sph = os.path.join(get_home(), 'btensor_testdata', + in_bvec_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvecs') ret = script_runner.run('scil_frf_memsmt.py', 'wm_frf.txt', @@ -49,23 +50,23 @@ def test_roi_center_shape_parameter(script_runner): def test_roi_radii_shape_parameter(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - in_dwi_sph = os.path.join(get_home(), 'btensor_testdata', + in_dwi_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_spherical.nii.gz') - in_bval_sph = os.path.join(get_home(), 'btensor_testdata', + in_bval_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvals') - in_bvec_sph = os.path.join(get_home(), 'btensor_testdata', + in_bvec_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvecs') ret = script_runner.run('scil_frf_memsmt.py', 'wm_frf.txt', 'gm_frf.txt', 'csf_frf.txt', '--in_dwis', @@ -100,17 +101,17 @@ def test_roi_radii_shape_parameter(script_runner): def test_inputs_check(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') ret = script_runner.run('scil_frf_memsmt.py', 'wm_frf.txt', @@ -131,23 +132,23 @@ def test_inputs_check(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi_lin = os.path.join(get_home(), 'btensor_testdata', + in_dwi_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_linear.nii.gz') - in_bval_lin = os.path.join(get_home(), 'btensor_testdata', + in_bval_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvals') - in_bvec_lin = os.path.join(get_home(), 'btensor_testdata', + in_bvec_lin = os.path.join(SCILPY_HOME, 'btensor_testdata', 'linear.bvecs') - in_dwi_plan = os.path.join(get_home(), 'btensor_testdata', + in_dwi_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_planar.nii.gz') - in_bval_plan = os.path.join(get_home(), 'btensor_testdata', + in_bval_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvals') - in_bvec_plan = os.path.join(get_home(), 'btensor_testdata', + in_bvec_plan = os.path.join(SCILPY_HOME, 'btensor_testdata', 'planar.bvecs') - in_dwi_sph = os.path.join(get_home(), 'btensor_testdata', + in_dwi_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'dwi_spherical.nii.gz') - in_bval_sph = os.path.join(get_home(), 'btensor_testdata', + in_bval_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvals') - in_bvec_sph = os.path.join(get_home(), 'btensor_testdata', + in_bvec_sph = os.path.join(SCILPY_HOME, 'btensor_testdata', 'spherical.bvecs') ret = script_runner.run('scil_frf_memsmt.py', 'wm_frf.txt', 'gm_frf.txt', 'csf_frf.txt', '--in_dwis', diff --git a/scripts/tests/test_frf_msmt.py b/scripts/tests/test_frf_msmt.py index 818266ade..514e42210 100644 --- a/scripts/tests/test_frf_msmt.py +++ b/scripts/tests/test_frf_msmt.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['commit_amico.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,14 +18,13 @@ def test_help_option(script_runner): def test_roi_radii_shape_parameter(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'commit_amico', + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') - mask = os.path.join(get_home(), 'commit_amico', - 'mask.nii.gz') + mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') ret = script_runner.run('scil_frf_msmt.py', in_dwi, in_bval, in_bvec, 'wm_frf.txt', 'gm_frf.txt', 'csf_frf.txt', '--mask', mask, '--roi_center', @@ -48,14 +48,13 @@ def test_roi_radii_shape_parameter(script_runner): def test_roi_radii_shape_parameter2(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'commit_amico', + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') - mask = os.path.join(get_home(), 'commit_amico', - 'mask.nii.gz') + mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') ret = script_runner.run('scil_frf_msmt.py', in_dwi, in_bval, in_bvec, 'wm_frf.txt', 'gm_frf.txt', 'csf_frf.txt', '--mask', mask, '--roi_radii', @@ -78,14 +77,13 @@ def test_roi_radii_shape_parameter2(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'commit_amico', + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') - mask = os.path.join(get_home(), 'commit_amico', - 'mask.nii.gz') + mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') ret = script_runner.run('scil_frf_msmt.py', in_dwi, in_bval, in_bvec, 'wm_frf.txt', 'gm_frf.txt', 'csf_frf.txt', '--mask', mask, '--min_nvox', '20', diff --git a/scripts/tests/test_frf_set_diffusivities.py b/scripts/tests/test_frf_set_diffusivities.py index 673df6e74..8efe05bf5 100644 --- a/scripts/tests/test_frf_set_diffusivities.py +++ b/scripts/tests/test_frf_set_diffusivities.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), @@ -19,7 +20,7 @@ def test_help_option(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', + in_frf = os.path.join(SCILPY_HOME, 'processing', 'frf.txt') ret = script_runner.run('scil_frf_set_diffusivities.py', in_frf, '15,4,4', 'new_frf.txt', '-f') @@ -28,7 +29,7 @@ def test_execution_processing_ssst(script_runner): def test_execution_processing_msmt(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_frf = os.path.join(get_home(), 'commit_amico', + in_frf = os.path.join(SCILPY_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') @@ -37,7 +38,7 @@ def test_execution_processing_msmt(script_runner): 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', + in_frf = os.path.join(SCILPY_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') diff --git a/scripts/tests/test_frf_ssst.py b/scripts/tests/test_frf_ssst.py index 40cea3878..8937bf6e9 100644 --- a/scripts/tests/test_frf_ssst.py +++ b/scripts/tests/test_frf_ssst.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_roi_center_parameter(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_frf_ssst.py', in_dwi, in_bval, in_bvec, 'frf.txt', '--roi_center', @@ -45,11 +46,11 @@ def test_roi_center_parameter(script_runner): def test_roi_radii_shape_parameter(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_frf_ssst.py', in_dwi, in_bval, in_bvec, 'frf.txt', '--roi_radii', @@ -70,11 +71,11 @@ def test_roi_radii_shape_parameter(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') ret = script_runner.run('scil_frf_ssst.py', in_dwi, in_bval, in_bvec, 'frf.txt', '-f') diff --git a/scripts/tests/test_gradients_apply_transform.py b/scripts/tests/test_gradients_apply_transform.py index 63b7bce27..bf3b9ba78 100755 --- a/scripts/tests/test_gradients_apply_transform.py +++ b/scripts/tests/test_gradients_apply_transform.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bst.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_bst(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bvecs = os.path.join(get_home(), 'processing', + in_bvecs = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') - in_aff = os.path.join(get_home(), 'bst', + in_aff = os.path.join(SCILPY_HOME, 'bst', 'output0GenericAffine.mat') ret = script_runner.run('scil_gradients_apply_transform.py', in_bvecs, in_aff, diff --git a/scripts/tests/test_gradients_convert.py b/scripts/tests/test_gradients_convert.py index a01e30065..c89dd6f5a 100644 --- a/scripts/tests/test_gradients_convert.py +++ b/scripts/tests/test_gradients_convert.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,9 +20,9 @@ def test_help_option(script_runner): def test_execution_processing_fsl(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') ret = script_runner.run('scil_gradients_convert.py', '--input_fsl', @@ -31,7 +32,7 @@ def test_execution_processing_fsl(script_runner): def test_execution_processing_mrtrix(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_encoding = os.path.join(get_home(), 'processing', + in_encoding = os.path.join(SCILPY_HOME, 'processing', '1000.b') ret = script_runner.run('scil_gradients_convert.py', '--input_mrtrix', @@ -41,9 +42,9 @@ def test_execution_processing_mrtrix(script_runner): def test_name_validation_mrtrix(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') ret = script_runner.run('scil_gradients_convert.py', '--input_fsl', @@ -59,7 +60,7 @@ def test_name_validation_mrtrix(script_runner): def test_name_validation_fsl_bval(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_encoding = os.path.join(get_home(), 'processing', + in_encoding = os.path.join(SCILPY_HOME, 'processing', '1000.b') ret = script_runner.run('scil_gradients_convert.py', '--input_mrtrix', @@ -79,7 +80,7 @@ def test_name_validation_fsl_bval(script_runner): def test_name_validation_fsl_bvec(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_encoding = os.path.join(get_home(), 'processing', + in_encoding = os.path.join(SCILPY_HOME, 'processing', '1000.b') ret = script_runner.run('scil_gradients_convert.py', '--input_mrtrix', diff --git a/scripts/tests/test_gradients_modify_axes.py b/scripts/tests/test_gradients_modify_axes.py index 11bdbaa05..ab2987662 100644 --- a/scripts/tests/test_gradients_modify_axes.py +++ b/scripts/tests/test_gradients_modify_axes.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -20,13 +21,13 @@ def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) # mrtrix - in_encoding = os.path.join(get_home(), 'processing', '1000.b') + in_encoding = os.path.join(SCILPY_HOME, 'processing', '1000.b') ret = script_runner.run('scil_gradients_modify_axes.py', in_encoding, '1000_flip.b', '-1', '3', '2') assert ret.success # FSL - in_encoding = os.path.join(get_home(), 'processing', '1000.bvec') + in_encoding = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') ret = script_runner.run('scil_gradients_modify_axes.py', in_encoding, '1000_flip.bvec', '1', '-3', '2') assert ret.success diff --git a/scripts/tests/test_gradients_round_bvals.py b/scripts/tests/test_gradients_round_bvals.py index dba341677..373bee483 100644 --- a/scripts/tests/test_gradients_round_bvals.py +++ b/scripts/tests/test_gradients_round_bvals.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,7 +20,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bval = os.path.join(get_home(), 'processing', '1000.bval') + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') ret = script_runner.run('scil_gradients_round_bvals.py', in_bval, '0', '1000', '1000_resample.b', "20", "-v") diff --git a/scripts/tests/test_gradients_validate_correct.py b/scripts/tests/test_gradients_validate_correct.py index ec1a41dd5..0e7a88e0a 100644 --- a/scripts/tests/test_gradients_validate_correct.py +++ b/scripts/tests/test_gradients_validate_correct.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_processing_dti_peaks(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') # generate the peaks file and fa map we'll use to test our script diff --git a/scripts/tests/test_gradients_validate_correct_eddy.py b/scripts/tests/test_gradients_validate_correct_eddy.py index dd2b19fa3..14905a34b 100644 --- a/scripts/tests/test_gradients_validate_correct_eddy.py +++ b/scripts/tests/test_gradients_validate_correct_eddy.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -19,8 +20,8 @@ def test_help_option(script_runner): def test_execution_extract_half(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') ret = script_runner.run('scil_gradients_validate_correct_eddy.py', in_bvec, in_bval, "32", 'out.bvec', @@ -30,8 +31,8 @@ def test_execution_extract_half(script_runner): def test_execution_extract_total(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bvec = os.path.join(get_home(), 'processing', 'dwi.bvec') - in_bval = os.path.join(get_home(), 'processing', 'dwi.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') + in_bval = os.path.join(SCILPY_HOME, 'processing', 'dwi.bval') ret = script_runner.run('scil_gradients_validate_correct_eddy.py', in_bvec, in_bval, "64", 'out.bvec', diff --git a/scripts/tests/test_header_print_info.py b/scripts/tests/test_header_print_info.py index 93d12d8b5..1d48ad4b9 100644 --- a/scripts/tests/test_header_print_info.py +++ b/scripts/tests/test_header_print_info.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -18,13 +19,13 @@ def test_help_option(script_runner): def test_execution_img(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'others', 'fa.nii.gz') + in_img = os.path.join(SCILPY_HOME, 'others', 'fa.nii.gz') ret = script_runner.run('scil_header_print_info.py', in_img) assert ret.success def test_execution_tractogram(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracto = os.path.join(get_home(), 'others', 'IFGWM.trk') + in_tracto = os.path.join(SCILPY_HOME, 'others', 'IFGWM.trk') ret = script_runner.run('scil_header_print_info.py', in_tracto) assert ret.success diff --git a/scripts/tests/test_header_validate_compatibility.py b/scripts/tests/test_header_validate_compatibility.py index a407d20e1..4836c5bc9 100644 --- a/scripts/tests/test_header_validate_compatibility.py +++ b/scripts/tests/test_header_validate_compatibility.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', 'bundle_all_1mm.trk') - in_roi = os.path.join(get_home(), 'filtering', 'mask.nii.gz') + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_all_1mm.trk') + in_roi = os.path.join(SCILPY_HOME, 'filtering', 'mask.nii.gz') ret = script_runner.run('scil_header_validate_compatibility.py', in_bundle, in_roi) assert ret.success diff --git a/scripts/tests/test_json_convert_entries_to_xlsx.py b/scripts/tests/test_json_convert_entries_to_xlsx.py index 0edf98775..af1fa537f 100644 --- a/scripts/tests/test_json_convert_entries_to_xlsx.py +++ b/scripts/tests/test_json_convert_entries_to_xlsx.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_json = os.path.join(get_home(), 'tractometry', + in_json = os.path.join(SCILPY_HOME, 'tractometry', 'length_stats_1.json') ret = script_runner.run('scil_json_convert_entries_to_xlsx.py', in_json, 'length_stats.xlsx') diff --git a/scripts/tests/test_json_merge_entries.py b/scripts/tests/test_json_merge_entries.py index 5d10c4930..f8b0ce773 100644 --- a/scripts/tests/test_json_merge_entries.py +++ b/scripts/tests/test_json_merge_entries.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_json_1 = os.path.join(get_home(), 'tractometry', + in_json_1 = os.path.join(SCILPY_HOME, 'tractometry', 'length_stats_1.json') - in_json_2 = os.path.join(get_home(), 'tractometry', + in_json_2 = os.path.join(SCILPY_HOME, 'tractometry', 'length_stats_2.json') ret = script_runner.run('scil_json_merge_entries.py', in_json_1, in_json_2, 'merge.json', '--keep_separate') diff --git a/scripts/tests/test_labels_combine.py b/scripts/tests/test_labels_combine.py index 944dc814e..5956e2ee0 100644 --- a/scripts/tests/test_labels_combine.py +++ b/scripts/tests/test_labels_combine.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['atlas.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_atlas(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_atlas_1 = os.path.join(get_home(), 'atlas', + in_atlas_1 = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2.nii.gz') - in_brainstem = os.path.join(get_home(), 'atlas', 'brainstem.nii.gz') + in_brainstem = os.path.join(SCILPY_HOME, 'atlas', 'brainstem.nii.gz') ret = script_runner.run('scil_labels_combine.py', 'atlas_freesurfer_v2_single_brainstem.nii.gz', '--volume_ids', in_atlas_1, '8', '47', '251', @@ -31,9 +32,9 @@ def test_execution_atlas(script_runner): def test_execution_atlas_merge(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_atlas_1 = os.path.join(get_home(), 'atlas', + in_atlas_1 = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2.nii.gz') - in_brainstem = os.path.join(get_home(), 'atlas', 'brainstem.nii.gz') + in_brainstem = os.path.join(SCILPY_HOME, 'atlas', 'brainstem.nii.gz') ret = script_runner.run('scil_labels_combine.py', 'atlas_freesurfer_v2_merge_brainstem.nii.gz', '--volume_ids', in_atlas_1, '8', '47', '251', diff --git a/scripts/tests/test_labels_dilate.py b/scripts/tests/test_labels_dilate.py index 8c00e9dfe..b54bb3a87 100644 --- a/scripts/tests/test_labels_dilate.py +++ b/scripts/tests/test_labels_dilate.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['atlas.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_atlas(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_atlas = os.path.join(get_home(), 'atlas', + in_atlas = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2_single_brainstem.nii.gz') ret = script_runner.run('scil_labels_dilate.py', in_atlas, 'atlas_freesurfer_v2_single_brainstem_dil.nii.gz', diff --git a/scripts/tests/test_labels_remove.py b/scripts/tests/test_labels_remove.py index 9296f7e71..2de1c9ef2 100644 --- a/scripts/tests/test_labels_remove.py +++ b/scripts/tests/test_labels_remove.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['atlas.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_atlas(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_atlas = os.path.join(get_home(), 'atlas', + in_atlas = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2.nii.gz') ret = script_runner.run('scil_labels_remove.py', in_atlas, 'atlas_freesurfer_v2_no_brainstem.nii.gz', diff --git a/scripts/tests/test_labels_split_volume_by_ids.py b/scripts/tests/test_labels_split_volume_by_ids.py index d44822fd0..163d877fd 100644 --- a/scripts/tests/test_labels_split_volume_by_ids.py +++ b/scripts/tests/test_labels_split_volume_by_ids.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['atlas.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_atlas(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_atlas = os.path.join(get_home(), 'atlas', + in_atlas = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2.nii.gz') ret = script_runner.run('scil_labels_split_volume_by_ids.py', in_atlas, '--out_prefix', 'brainstem', '-r', '173', '175') diff --git a/scripts/tests/test_labels_split_volume_from_lut.py b/scripts/tests/test_labels_split_volume_from_lut.py index 48f8aeba9..23efd50d7 100644 --- a/scripts/tests/test_labels_split_volume_from_lut.py +++ b/scripts/tests/test_labels_split_volume_from_lut.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['atlas.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_atlas(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_atlas = os.path.join(get_home(), 'atlas', + in_atlas = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2.nii.gz') - in_json = os.path.join(get_home(), 'atlas', + in_json = os.path.join(SCILPY_HOME, 'atlas', 'atlas_freesurfer_v2_LUT.json') ret = script_runner.run('scil_labels_split_volume_from_lut.py', in_atlas, '--out_prefix', 'brainstem', diff --git a/scripts/tests/test_mti_adjust_B1_header.py b/scripts/tests/test_mti_adjust_B1_header.py index cf432d190..24c72f212 100644 --- a/scripts/tests/test_mti_adjust_B1_header.py +++ b/scripts/tests/test_mti_adjust_B1_header.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['ihMT.zip']) @@ -19,9 +20,9 @@ def test_help_option(script_runner): def test_execution_ihMT_no_option(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_b1_map = os.path.join(get_home(), + in_b1_map = os.path.join(SCILPY_HOME, 'MT', 'sub-001_run-01_B1map.nii.gz') - in_b1_json = os.path.join(get_home(), + in_b1_json = os.path.join(SCILPY_HOME, 'MT', 'sub-001_run-01_B1map.json') # no option diff --git a/scripts/tests/test_mti_maps_MT.py b/scripts/tests/test_mti_maps_MT.py index 260deb0a6..f417836ef 100644 --- a/scripts/tests/test_mti_maps_MT.py +++ b/scripts/tests/test_mti_maps_MT.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['MT.zip']) @@ -12,48 +13,48 @@ # Preparing once the filenames. -in_mask = os.path.join(get_home(), 'MT', 'mask.nii.gz') +in_mask = os.path.join(SCILPY_HOME, 'MT', 'mask.nii.gz') -in_mtoff_json = os.path.join(get_home(), +in_mtoff_json = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.json') -in_t1w_json = os.path.join(get_home(), +in_t1w_json = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-1_acq-t1w_mtsat.json') -in_e1_mtoff = os.path.join(get_home(), +in_e1_mtoff = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-1_acq-mtoff_mtsat.nii.gz') -in_e2_mtoff = os.path.join(get_home(), +in_e2_mtoff = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-2_acq-mtoff_mtsat.nii.gz') -in_e3_mtoff = os.path.join(get_home(), +in_e3_mtoff = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-3_acq-mtoff_mtsat.nii.gz') -in_e4_mtoff = os.path.join(get_home(), +in_e4_mtoff = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-4_acq-mtoff_mtsat.nii.gz') -in_e5_mtoff = os.path.join(get_home(), +in_e5_mtoff = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-5_acq-mtoff_mtsat.nii.gz') -in_e1_mton = os.path.join(get_home(), +in_e1_mton = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-1_acq-mton_mtsat.nii.gz') -in_e2_mton = os.path.join(get_home(), +in_e2_mton = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-2_acq-mton_mtsat.nii.gz') -in_e3_mton = os.path.join(get_home(), +in_e3_mton = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-3_acq-mton_mtsat.nii.gz') -in_e4_mton = os.path.join(get_home(), +in_e4_mton = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-4_acq-mton_mtsat.nii.gz') -in_e5_mton = os.path.join(get_home(), +in_e5_mton = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-5_acq-mton_mtsat.nii.gz') -in_e1_t1w = os.path.join(get_home(), +in_e1_t1w = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-1_acq-t1w_mtsat.nii.gz') -in_e2_t1w = os.path.join(get_home(), +in_e2_t1w = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-2_acq-t1w_mtsat.nii.gz') -in_e3_t1w = os.path.join(get_home(), +in_e3_t1w = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-3_acq-t1w_mtsat.nii.gz') -in_e4_t1w = os.path.join(get_home(), +in_e4_t1w = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-4_acq-t1w_mtsat.nii.gz') -in_e5_t1w = os.path.join(get_home(), +in_e5_t1w = os.path.join(SCILPY_HOME, 'MT', 'sub-001_echo-5_acq-t1w_mtsat.nii.gz') -in_b1_map = os.path.join(get_home(), 'MT', 'sub-001_run-01_B1map.nii.gz') -in_b1_json = os.path.join(get_home(), 'MT', 'sub-001_run-01_B1map.json') +in_b1_map = os.path.join(SCILPY_HOME, 'MT', 'sub-001_run-01_B1map.nii.gz') +in_b1_json = os.path.join(SCILPY_HOME, 'MT', 'sub-001_run-01_B1map.json') def test_help_option(script_runner): diff --git a/scripts/tests/test_mti_maps_ihMT.py b/scripts/tests/test_mti_maps_ihMT.py index c074fe740..a4dc06d03 100644 --- a/scripts/tests/test_mti_maps_ihMT.py +++ b/scripts/tests/test_mti_maps_ihMT.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['ihMT.zip']) @@ -12,57 +13,57 @@ # Preparing once the filenames. -in_mask = os.path.join(get_home(), 'ihMT', 'mask_resample.nii.gz') +in_mask = os.path.join(SCILPY_HOME, 'ihMT', 'mask_resample.nii.gz') -in_mtoff_pd_json = os.path.join(get_home(), +in_mtoff_pd_json = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-mtoff_ihmt.json') -in_mtoff_t1_json = os.path.join(get_home(), +in_mtoff_t1_json = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-T1w_ihmt.json') -in_e1_altnp = os.path.join(get_home(), +in_e1_altnp = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-altnp_ihmt.nii.gz') -in_e2_altnp = os.path.join(get_home(), +in_e2_altnp = os.path.join(SCILPY_HOME, 'ihMT', 'echo-2_acq-altnp_ihmt.nii.gz') -in_e3_altnp = os.path.join(get_home(), +in_e3_altnp = os.path.join(SCILPY_HOME, 'ihMT', 'echo-3_acq-altnp_ihmt.nii.gz') -in_e1_altpn = os.path.join(get_home(), +in_e1_altpn = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-altpn_ihmt.nii.gz') -in_e2_altpn = os.path.join(get_home(), +in_e2_altpn = os.path.join(SCILPY_HOME, 'ihMT', 'echo-2_acq-altpn_ihmt.nii.gz') -in_e3_altpn = os.path.join(get_home(), +in_e3_altpn = os.path.join(SCILPY_HOME, 'ihMT', 'echo-3_acq-altpn_ihmt.nii.gz') -in_e1_mtoff_pd = os.path.join(get_home(), +in_e1_mtoff_pd = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-mtoff_ihmt.nii.gz') -in_e2_mtoff_pd = os.path.join(get_home(), +in_e2_mtoff_pd = os.path.join(SCILPY_HOME, 'ihMT', 'echo-2_acq-mtoff_ihmt.nii.gz') -in_e3_mtoff_pd = os.path.join(get_home(), +in_e3_mtoff_pd = os.path.join(SCILPY_HOME, 'ihMT', 'echo-3_acq-mtoff_ihmt.nii.gz') -in_e1_neg = os.path.join(get_home(), +in_e1_neg = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-neg_ihmt.nii.gz') -in_e2_neg = os.path.join(get_home(), +in_e2_neg = os.path.join(SCILPY_HOME, 'ihMT', 'echo-2_acq-neg_ihmt.nii.gz') -in_e3_neg = os.path.join(get_home(), +in_e3_neg = os.path.join(SCILPY_HOME, 'ihMT', 'echo-3_acq-neg_ihmt.nii.gz') -in_e1_pos = os.path.join(get_home(), +in_e1_pos = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-pos_ihmt.nii.gz') -in_e2_pos = os.path.join(get_home(), +in_e2_pos = os.path.join(SCILPY_HOME, 'ihMT', 'echo-2_acq-pos_ihmt.nii.gz') -in_e3_pos = os.path.join(get_home(), +in_e3_pos = os.path.join(SCILPY_HOME, 'ihMT', 'echo-3_acq-pos_ihmt.nii.gz') -in_e1_mtoff_t1 = os.path.join(get_home(), +in_e1_mtoff_t1 = os.path.join(SCILPY_HOME, 'ihMT', 'echo-1_acq-T1w_ihmt.nii.gz') -in_e2_mtoff_t1 = os.path.join(get_home(), +in_e2_mtoff_t1 = os.path.join(SCILPY_HOME, 'ihMT', 'echo-2_acq-T1w_ihmt.nii.gz') -in_e3_mtoff_t1 = os.path.join(get_home(), +in_e3_mtoff_t1 = os.path.join(SCILPY_HOME, 'ihMT', 'echo-3_acq-T1w_ihmt.nii.gz') -in_b1_map = os.path.join(get_home(), 'ihMT', 'B1map.nii.gz') -in_b1_json = os.path.join(get_home(), 'MT', 'sub-001_run-01_B1map.json') +in_b1_map = os.path.join(SCILPY_HOME, 'ihMT', 'B1map.nii.gz') +in_b1_json = os.path.join(SCILPY_HOME, 'MT', 'sub-001_run-01_B1map.json') def test_help_option(script_runner): diff --git a/scripts/tests/test_outlier_rejection.py b/scripts/tests/test_outlier_rejection.py index bdd599261..740048213 100644 --- a/scripts/tests/test_outlier_rejection.py +++ b/scripts/tests/test_outlier_rejection.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_all_1mm.trk') ret = script_runner.run('scil_outlier_rejection.py', in_bundle, 'inliers.trk', '--alpha', '0.6', diff --git a/scripts/tests/test_plot_stats_per_point.py b/scripts/tests/test_plot_stats_per_point.py index 41daabb1a..034ffbd80 100644 --- a/scripts/tests/test_plot_stats_per_point.py +++ b/scripts/tests/test_plot_stats_per_point.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_json = os.path.join(get_home(), 'tractometry', + in_json = os.path.join(SCILPY_HOME, 'tractometry', 'metric_label.json') ret = script_runner.run('scil_plot_stats_per_point.py', in_json, 'out/', '--stats_over_population') diff --git a/scripts/tests/test_qball_metrics.py b/scripts/tests/test_qball_metrics.py index 97ae505f7..1b36ec387 100644 --- a/scripts/tests/test_qball_metrics.py +++ b/scripts/tests/test_qball_metrics.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['processing.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,11 +18,11 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') ret = script_runner.run('scil_qball_metrics.py', in_dwi, in_bval, in_bvec) @@ -30,11 +31,11 @@ def test_execution_processing(script_runner): def test_execution_not_all(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi_crop_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') ret = script_runner.run('scil_qball_metrics.py', in_dwi, in_bval, in_bvec, "--not_all", "--sh", "2.nii.gz") diff --git a/scripts/tests/test_rgb_convert.py b/scripts/tests/test_rgb_convert.py index d04a82c7b..f0690768d 100644 --- a/scripts/tests/test_rgb_convert.py +++ b/scripts/tests/test_rgb_convert.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'others', + in_img = os.path.join(SCILPY_HOME, 'others', 'rgb.nii.gz') ret = script_runner.run('scil_rgb_convert.py', in_img, 'rgb_4D.nii.gz') diff --git a/scripts/tests/test_save_connections_from_hdf5.py b/scripts/tests/test_save_connections_from_hdf5.py index dde3518f3..9e9f7a156 100644 --- a/scripts/tests/test_save_connections_from_hdf5.py +++ b/scripts/tests/test_save_connections_from_hdf5.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_h5 = os.path.join(get_home(), 'connectivity', + in_h5 = os.path.join(SCILPY_HOME, 'connectivity', 'decompose.h5') ret = script_runner.run('scil_save_connections_from_hdf5.py', in_h5, 'save_trk/') diff --git a/scripts/tests/test_score_tractogram.py b/scripts/tests/test_score_tractogram.py index 41c1c7dbb..0b91011ca 100644 --- a/scripts/tests/test_score_tractogram.py +++ b/scripts/tests/test_score_tractogram.py @@ -2,8 +2,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -18,17 +18,17 @@ def test_help_option(script_runner): def test_score_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'tracking', 'pft.trk') + in_tractogram = os.path.join(SCILPY_HOME, 'tracking', 'pft.trk') json_contents = { "example_bundle": { "angle": 300, "length": [30, 190], - "any_mask": os.path.join(get_home(), 'tracking', + "any_mask": os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz'), - "gt_mask": os.path.join(get_home(), 'tracking', + "gt_mask": os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz'), - "endpoints": os.path.join(get_home(), 'tracking', + "endpoints": os.path.join(SCILPY_HOME, 'tracking', 'interface.nii.gz') } } diff --git a/scripts/tests/test_screenshot_volume.py b/scripts/tests/test_screenshot_volume.py index 68de49015..9428d9ca5 100644 --- a/scripts/tests/test_screenshot_volume.py +++ b/scripts/tests/test_screenshot_volume.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bst.zip']) @@ -13,7 +13,7 @@ def test_screenshot(script_runner): - in_fa = os.path.join(get_home(), 'bst', + in_fa = os.path.join(SCILPY_HOME, 'bst', 'fa.nii.gz') ret = script_runner.run( diff --git a/scripts/tests/test_sh_convert.py b/scripts/tests/test_sh_convert.py index 045f8dad4..80a7fd8e3 100644 --- a/scripts/tests/test_sh_convert.py +++ b/scripts/tests/test_sh_convert.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'processing', + in_fodf = os.path.join(SCILPY_HOME, 'processing', 'fodf.nii.gz') ret = script_runner.run('scil_sh_convert.py', in_fodf, 'fodf_descoteaux07.nii.gz', 'tournier07', diff --git a/scripts/tests/test_sh_fusion.py b/scripts/tests/test_sh_fusion.py index e4f405fbc..8268d9386 100644 --- a/scripts/tests/test_sh_fusion.py +++ b/scripts/tests/test_sh_fusion.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sh_1 = os.path.join(get_home(), 'processing', + in_sh_1 = os.path.join(SCILPY_HOME, 'processing', 'sh_1000.nii.gz') - in_sh_2 = os.path.join(get_home(), 'processing', + in_sh_2 = os.path.join(SCILPY_HOME, 'processing', 'sh_3000.nii.gz') ret = script_runner.run('scil_sh_fusion.py', in_sh_1, in_sh_2, 'sh.nii.gz') assert ret.success diff --git a/scripts/tests/test_sh_to_aodf.py b/scripts/tests/test_sh_to_aodf.py index a5d9eb469..8c3f683c9 100644 --- a/scripts/tests/test_sh_to_aodf.py +++ b/scripts/tests/test_sh_to_aodf.py @@ -1,18 +1,19 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import nibabel as nib -import numpy as np import os -import pytest import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home +import nibabel as nib +import numpy as np +import pytest +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['fodf_filtering.zip']) -data_path = os.path.join(get_home(), 'fodf_filtering') +data_path = os.path.join(SCILPY_HOME, 'fodf_filtering') tmp_dir = tempfile.TemporaryDirectory() diff --git a/scripts/tests/test_sh_to_rish.py b/scripts/tests/test_sh_to_rish.py index 3f792be81..8ab79a07a 100644 --- a/scripts/tests/test_sh_to_rish.py +++ b/scripts/tests/test_sh_to_rish.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sh = os.path.join(get_home(), 'processing', + in_sh = os.path.join(SCILPY_HOME, 'processing', 'sh.nii.gz') ret = script_runner.run('scil_sh_to_rish.py', in_sh, 'rish.nii.gz') assert ret.success diff --git a/scripts/tests/test_sh_to_sf.py b/scripts/tests/test_sh_to_sf.py index 6473bc85a..b86631b8c 100755 --- a/scripts/tests/test_sh_to_sf.py +++ b/scripts/tests/test_sh_to_sf.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_in_sphere(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sh = os.path.join(get_home(), 'processing', 'sh_1000.nii.gz') - in_b0 = os.path.join(get_home(), 'processing', 'fa.nii.gz') - in_bval = os.path.join(get_home(), 'processing', '1000.bval') + in_sh = os.path.join(SCILPY_HOME, 'processing', 'sh_1000.nii.gz') + in_b0 = os.path.join(SCILPY_HOME, 'processing', 'fa.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') # Required: either --sphere or --in_bvec. Here, --sphere ret = script_runner.run('scil_sh_to_sf.py', in_sh, diff --git a/scripts/tests/test_shuffle_streamlines.py b/scripts/tests/test_shuffle_streamlines.py index 63ea6471b..f1e2c0bf5 100644 --- a/scripts/tests/test_shuffle_streamlines.py +++ b/scripts/tests/test_shuffle_streamlines.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tracking(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracto = os.path.join(get_home(), 'tracking', + in_tracto = os.path.join(SCILPY_HOME, 'tracking', 'union.trk') ret = script_runner.run('scil_shuffle_streamlines.py', in_tracto, 'union_shuffle.trk') diff --git a/scripts/tests/test_stats_group_comparison.py b/scripts/tests/test_stats_group_comparison.py index 3237e01ff..e950a2e5e 100644 --- a/scripts/tests/test_stats_group_comparison.py +++ b/scripts/tests/test_stats_group_comparison.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['stats.zip']) @@ -21,8 +21,8 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_json = os.path.join(get_home(), 'stats/group', 'participants.tsv') - in_participants = os.path.join(get_home(), 'stats/group', 'meanstd_all.json') + in_json = os.path.join(SCILPY_HOME, 'stats/group', 'participants.tsv') + in_participants = os.path.join(SCILPY_HOME, 'stats/group', 'meanstd_all.json') ret = script_runner.run('scil_stats_group_comparison.py', in_participants, in_json, 'Group', diff --git a/scripts/tests/test_surface_apply_transform.py b/scripts/tests/test_surface_apply_transform.py index 4ebc278de..b27d5563b 100644 --- a/scripts/tests/test_surface_apply_transform.py +++ b/scripts/tests/test_surface_apply_transform.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_surf = os.path.join(get_home(), 'surface_vtk_fib', + in_surf = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'lhpialt.vtk') - in_aff = os.path.join(get_home(), 'surface_vtk_fib', + in_aff = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'affine.txt') ret = script_runner.run('scil_surface_apply_transform.py', in_surf, in_aff, 'lhpialt_lin.vtk') diff --git a/scripts/tests/test_surface_convert.py b/scripts/tests/test_surface_convert.py index 1e4bd2ad7..78fa4d470 100644 --- a/scripts/tests/test_surface_convert.py +++ b/scripts/tests/test_surface_convert.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_surf = os.path.join(get_home(), 'surface_vtk_fib', + in_surf = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'lhpialt.vtk') ret = script_runner.run('scil_surface_convert.py', in_surf, 'rhpialt.ply') @@ -28,9 +28,9 @@ def test_execution_surface_vtk_fib(script_runner): def test_execution_surface_vtk_xfrom(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_surf = os.path.join(get_home(), 'surface_vtk_fib', + in_surf = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'lh.pialt_xform') - x_form = os.path.join(get_home(), 'surface_vtk_fib', + x_form = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'log.txt') ret = script_runner.run('scil_surface_convert.py', in_surf, 'lh.pialt_xform.vtk', '--xform', x_form, diff --git a/scripts/tests/test_surface_flip.py b/scripts/tests/test_surface_flip.py index 44efd7137..b17ba4e0e 100644 --- a/scripts/tests/test_surface_flip.py +++ b/scripts/tests/test_surface_flip.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -21,7 +21,7 @@ def test_execution_surface_vtk_fib(script_runner): # Weird behavior, flip around the origin in RASMM rather than the center of # the volume in VOX os.chdir(os.path.expanduser(tmp_dir.name)) - in_surf = os.path.join(get_home(), 'surface_vtk_fib', + in_surf = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'lhpialt.vtk') ret = script_runner.run('scil_surface_flip.py', in_surf, 'rhpialt.vtk', 'x') diff --git a/scripts/tests/test_surface_smooth.py b/scripts/tests/test_surface_smooth.py index 4b55e1c2a..de71df516 100644 --- a/scripts/tests/test_surface_smooth.py +++ b/scripts/tests/test_surface_smooth.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_surf = os.path.join(get_home(), 'surface_vtk_fib', + in_surf = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'lhpialt.vtk') ret = script_runner.run('scil_surface_smooth.py', in_surf, 'lhpialt_smooth.vtk', '-n', '5', '-s', '1') diff --git a/scripts/tests/test_tracking_local.py b/scripts/tests/test_tracking_local.py index 88d150fde..153d3d054 100644 --- a/scripts/tests/test_tracking_local.py +++ b/scripts/tests/test_tracking_local.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -22,8 +22,8 @@ def test_execution_tracking_fodf_prob(script_runner): # Our testing seeding mask has 125 286 voxels, this would be long. # Only testing option npv in our first gpu test, below os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'local_prob.trk', '--nt', '100', @@ -34,8 +34,8 @@ def test_execution_tracking_fodf_prob(script_runner): def test_execution_tracking_fodf_det(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'local_det.trk', '--nt', '100', @@ -47,8 +47,8 @@ def test_execution_tracking_fodf_det(script_runner): def test_execution_tracking_ptt(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'local_ptt.trk', '--nt', '100', @@ -60,8 +60,8 @@ def test_execution_tracking_ptt(script_runner): def test_execution_sphere_subdivide(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'local_sphere.trk', @@ -74,8 +74,8 @@ def test_execution_sphere_subdivide(script_runner): def test_execution_sphere_gpu(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'sphere_gpu.trk', @@ -87,8 +87,8 @@ def test_execution_sphere_gpu(script_runner): def test_sh_interp_without_gpu(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'nearest_interp.trk', @@ -99,8 +99,8 @@ def test_sh_interp_without_gpu(script_runner): def test_forward_without_gpu(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'fwd_only.trk', @@ -111,8 +111,8 @@ def test_forward_without_gpu(script_runner): def test_batch_size_without_gpu(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'batch.trk', @@ -123,8 +123,8 @@ def test_batch_size_without_gpu(script_runner): def test_algo_with_gpu(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'gpu_det.trk', '--algo', @@ -135,8 +135,8 @@ def test_algo_with_gpu(script_runner): def test_execution_tracking_fodf_no_compression(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'local_prob2.trk', @@ -148,8 +148,8 @@ def test_execution_tracking_fodf_no_compression(script_runner): def test_execution_tracking_peaks(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_peaks = os.path.join(get_home(), 'tracking', 'peaks.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_peaks = os.path.join(SCILPY_HOME, 'tracking', 'peaks.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_peaks, in_mask, in_mask, 'local_eudx.trk', '--nt', '100', '--compress', '0.1', '--sh_basis', 'descoteaux07', @@ -160,8 +160,8 @@ def test_execution_tracking_peaks(script_runner): def test_execution_tracking_fodf_prob_pmf_mapping(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', 'seeding_mask.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local.py', in_fodf, in_mask, in_mask, 'local_prob3.trk', '--nt', '100', diff --git a/scripts/tests/test_tracking_local_dev.py b/scripts/tests/test_tracking_local_dev.py index c340a4895..b02bc4b76 100644 --- a/scripts/tests/test_tracking_local_dev.py +++ b/scripts/tests/test_tracking_local_dev.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_tracking_fodf(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_local_dev.py', in_fodf, in_mask, in_mask, 'local_prob.trk', '--nt', '10', diff --git a/scripts/tests/test_tracking_pft.py b/scripts/tests/test_tracking_pft.py index 3c8405c0c..6deb0900b 100644 --- a/scripts/tests/test_tracking_pft.py +++ b/scripts/tests/test_tracking_pft.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -20,13 +20,13 @@ def test_help_option(script_runner): def test_execution_tracking(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') - in_interface = os.path.join(get_home(), 'tracking', + in_interface = os.path.join(SCILPY_HOME, 'tracking', 'interface.nii.gz') - in_include = os.path.join(get_home(), 'tracking', + in_include = os.path.join(SCILPY_HOME, 'tracking', 'map_include.nii.gz') - in_exclude = os.path.join(get_home(), 'tracking', + in_exclude = os.path.join(SCILPY_HOME, 'tracking', 'map_exclude.nii.gz') ret = script_runner.run('scil_tracking_pft.py', in_fodf, in_interface, in_include, in_exclude, diff --git a/scripts/tests/test_tracking_pft_maps.py b/scripts/tests/test_tracking_pft_maps.py index c6ebbc8bc..31b1deb32 100644 --- a/scripts/tests/test_tracking_pft_maps.py +++ b/scripts/tests/test_tracking_pft_maps.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -20,11 +20,11 @@ def test_help_option(script_runner): def test_execution_tracking(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_wm = os.path.join(get_home(), 'tracking', + in_wm = os.path.join(SCILPY_HOME, 'tracking', 'map_wm.nii.gz') - in_gm = os.path.join(get_home(), 'tracking', + in_gm = os.path.join(SCILPY_HOME, 'tracking', 'map_gm.nii.gz') - in_csf = os.path.join(get_home(), 'tracking', + in_csf = os.path.join(SCILPY_HOME, 'tracking', 'map_csf.nii.gz') ret = script_runner.run('scil_tracking_pft_maps.py', in_wm, in_gm, in_csf) diff --git a/scripts/tests/test_tracking_pft_maps_edit.py b/scripts/tests/test_tracking_pft_maps_edit.py index 1f86342a8..a182afa92 100644 --- a/scripts/tests/test_tracking_pft_maps_edit.py +++ b/scripts/tests/test_tracking_pft_maps_edit.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_tracking(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_include = os.path.join(get_home(), 'tracking', + in_include = os.path.join(SCILPY_HOME, 'tracking', 'map_include.nii.gz') - in_exclude = os.path.join(get_home(), 'tracking', + in_exclude = os.path.join(SCILPY_HOME, 'tracking', 'map_exclude.nii.gz') - in_mask = os.path.join(get_home(), 'tracking', + in_mask = os.path.join(SCILPY_HOME, 'tracking', 'seeding_mask.nii.gz') ret = script_runner.run('scil_tracking_pft_maps_edit.py', in_include, in_exclude, in_mask, diff --git a/scripts/tests/test_tractogram_apply_transform.py b/scripts/tests/test_tractogram_apply_transform.py index f12717231..cc7604584 100644 --- a/scripts/tests/test_tractogram_apply_transform.py +++ b/scripts/tests/test_tractogram_apply_transform.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bst.zip']) @@ -19,13 +19,13 @@ def test_help_option(script_runner): def test_execution_bst(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_model = os.path.join(get_home(), 'bst', 'template', + in_model = os.path.join(SCILPY_HOME, 'bst', 'template', 'rpt_m.trk') - in_fa = os.path.join(get_home(), 'bst', + in_fa = os.path.join(SCILPY_HOME, 'bst', 'fa.nii.gz') - in_aff = os.path.join(get_home(), 'bst', + in_aff = os.path.join(SCILPY_HOME, 'bst', 'output0GenericAffine.mat') - in_warp = os.path.join(get_home(), 'bst', + in_warp = os.path.join(SCILPY_HOME, 'bst', 'output1InverseWarp.nii.gz') ret = script_runner.run('scil_tractogram_apply_transform.py', in_model, in_fa, in_aff, 'rpt_m_warp.trk', diff --git a/scripts/tests/test_tractogram_assign_custom_color.py b/scripts/tests/test_tractogram_assign_custom_color.py index c048d41b7..5e71a415c 100644 --- a/scripts/tests/test_tractogram_assign_custom_color.py +++ b/scripts/tests/test_tractogram_assign_custom_color.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') - in_anat = os.path.join(get_home(), 'tractometry', + in_anat = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_labels_map.nii.gz') ret = script_runner.run('scil_tractogram_assign_custom_color.py', in_bundle, 'colored.trk', '--from_anatomy', diff --git a/scripts/tests/test_tractogram_assign_uniform_color.py b/scripts/tests/test_tractogram_assign_uniform_color.py index 20147b069..a577eefd1 100644 --- a/scripts/tests/test_tractogram_assign_uniform_color.py +++ b/scripts/tests/test_tractogram_assign_uniform_color.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') ret = script_runner.run('scil_tractogram_assign_uniform_color.py', in_bundle, '--fill_color', '0x000000', diff --git a/scripts/tests/test_tractogram_commit.py b/scripts/tests/test_tractogram_commit.py index bcd7644a9..cfbf52606 100644 --- a/scripts/tests/test_tractogram_commit.py +++ b/scripts/tests/test_tractogram_commit.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['commit_amico.zip']) @@ -18,17 +19,17 @@ def test_help_option(script_runner): def test_execution_commit_amico(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracking = os.path.join(get_home(), 'commit_amico', + in_tracking = os.path.join(SCILPY_HOME, 'commit_amico', 'tracking.trk') - in_dwi = os.path.join(get_home(), 'commit_amico', + in_dwi = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') - in_bval = os.path.join(get_home(), 'commit_amico', + in_bval = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bval') - in_bvec = os.path.join(get_home(), 'commit_amico', + in_bvec = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.bvec') - in_mask = os.path.join(get_home(), 'commit_amico', + in_mask = os.path.join(SCILPY_HOME, 'commit_amico', 'mask.nii.gz') - in_peaks = os.path.join(get_home(), 'commit_amico', + in_peaks = os.path.join(SCILPY_HOME, 'commit_amico', 'peaks.nii.gz') ret = script_runner.run('scil_tractogram_commit.py', in_tracking, in_dwi, in_bval, in_bvec, 'results_bzs/', diff --git a/scripts/tests/test_tractogram_compress.py b/scripts/tests/test_tractogram_compress.py index 42a75a2f6..68a010bb3 100644 --- a/scripts/tests/test_tractogram_compress.py +++ b/scripts/tests/test_tractogram_compress.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fib = os.path.join(get_home(), 'surface_vtk_fib', + in_fib = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'gyri_fanning.trk') ret = script_runner.run('scil_tractogram_compress.py', in_fib, 'gyri_fanning_c.trk', '-e', '0.1') diff --git a/scripts/tests/test_tractogram_compute_TODI.py b/scripts/tests/test_tractogram_compute_TODI.py index 932854ac9..07a18eec1 100644 --- a/scripts/tests/test_tractogram_compute_TODI.py +++ b/scripts/tests/test_tractogram_compute_TODI.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bst.zip']) @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution_bst(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'bst', 'rpt_m_warp.trk') - in_mask = os.path.join(get_home(), 'bst', 'mask.nii.gz') + in_bundle = os.path.join(SCILPY_HOME, 'bst', 'rpt_m_warp.trk') + in_mask = os.path.join(SCILPY_HOME, 'bst', 'mask.nii.gz') ret = script_runner.run('scil_tractogram_compute_TODI.py', in_bundle, '--mask', in_mask, '--out_mask', 'todi_mask.nii.gz', @@ -34,7 +34,7 @@ def test_execution_bst(script_runner): def test_execution_asym(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'bst', 'rpt_m_warp.trk') + in_bundle = os.path.join(SCILPY_HOME, 'bst', 'rpt_m_warp.trk') ret = script_runner.run('scil_tractogram_compute_TODI.py', in_bundle, '--out_todi_sh', 'atodi_sh_8.nii.gz', '--asymmetric', '--n_steps', '2') diff --git a/scripts/tests/test_tractogram_compute_density_map.py b/scripts/tests/test_tractogram_compute_density_map.py index e081d63ad..0c2310cec 100644 --- a/scripts/tests/test_tractogram_compute_density_map.py +++ b/scripts/tests/test_tractogram_compute_density_map.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip', 'tractometry.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'others', 'IFGWM.trk') + in_bundle = os.path.join(SCILPY_HOME, 'others', 'IFGWM.trk') ret = script_runner.run('scil_tractogram_compute_density_map.py', in_bundle, 'binary.nii.gz', '--binary') assert ret.success @@ -28,7 +28,7 @@ def test_execution_others(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM.trk') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') ret = script_runner.run('scil_tractogram_compute_density_map.py', in_bundle, 'IFGWM.nii.gz', '--binary') assert ret.success diff --git a/scripts/tests/test_tractogram_convert.py b/scripts/tests/test_tractogram_convert.py index 130778853..0b9166184 100644 --- a/scripts/tests/test_tractogram_convert.py +++ b/scripts/tests/test_tractogram_convert.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fib = os.path.join(get_home(), 'surface_vtk_fib', + in_fib = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'gyri_fanning.fib') - in_fa = os.path.join(get_home(), 'surface_vtk_fib', + in_fa = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'fa.nii.gz') ret = script_runner.run('scil_tractogram_convert.py', in_fib, 'gyri_fanning.trk', '--reference', in_fa) diff --git a/scripts/tests/test_tractogram_count_streamlines.py b/scripts/tests/test_tractogram_count_streamlines.py index a14668065..fdd450569 100644 --- a/scripts/tests/test_tractogram_count_streamlines.py +++ b/scripts/tests/test_tractogram_count_streamlines.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'others', + in_bundle = os.path.join(SCILPY_HOME, 'others', 'IFGWM_sub.trk') ret = script_runner.run('scil_tractogram_count_streamlines.py', in_bundle) assert ret.success diff --git a/scripts/tests/test_tractogram_cut_streamlines.py b/scripts/tests/test_tractogram_cut_streamlines.py index c419f3797..b371dd9e3 100644 --- a/scripts/tests/test_tractogram_cut_streamlines.py +++ b/scripts/tests/test_tractogram_cut_streamlines.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'filtering', + in_tractogram = os.path.join(SCILPY_HOME, 'filtering', 'bundle_all_1mm.trk') - in_mask = os.path.join(get_home(), 'filtering', + in_mask = os.path.join(SCILPY_HOME, 'filtering', 'mask.nii.gz') ret = script_runner.run('scil_tractogram_cut_streamlines.py', in_tractogram, in_mask, 'out_tractogram_cut.trk', diff --git a/scripts/tests/test_tractogram_detect_loops.py b/scripts/tests/test_tractogram_detect_loops.py index 6b0a508f1..127b25d94 100644 --- a/scripts/tests/test_tractogram_detect_loops.py +++ b/scripts/tests/test_tractogram_detect_loops.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4_filtered.trk') ret = script_runner.run('scil_tractogram_detect_loops.py', in_bundle, 'bundle_4_filtered_no_loops.trk', diff --git a/scripts/tests/test_tractogram_dpp_math.py b/scripts/tests/test_tractogram_dpp_math.py index 60a9bb6f7..fc9e252b0 100644 --- a/scripts/tests/test_tractogram_dpp_math.py +++ b/scripts/tests/test_tractogram_dpp_math.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_tractogram_point_math_mean_3D_defaults(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni.trk') - in_t1 = os.path.join(get_home(), 'tractometry', + in_t1 = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') t1_on_bundle = 't1_on_streamlines.trk' @@ -45,10 +45,10 @@ def test_execution_tractogram_point_math_mean_3D_defaults(script_runner): def test_execution_tractogram_point_math_mean_4D_correlation(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tracking', + in_bundle = os.path.join(SCILPY_HOME, 'tracking', 'local_split_0.trk') - in_fodf = os.path.join(get_home(), 'tracking', + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') fodf_on_bundle = 'fodf_on_streamlines.trk' diff --git a/scripts/tests/test_tractogram_extract_ushape.py b/scripts/tests/test_tractogram_extract_ushape.py index 96217c165..1f666ce07 100644 --- a/scripts/tests/test_tractogram_extract_ushape.py +++ b/scripts/tests/test_tractogram_extract_ushape.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_trk = os.path.join(get_home(), 'tracking', 'union.trk') + in_trk = os.path.join(SCILPY_HOME, 'tracking', 'union.trk') out_trk = 'ushape.trk' remaining_trk = 'remaining.trk' ret = script_runner.run('scil_tractogram_extract_ushape.py', in_trk, out_trk, diff --git a/scripts/tests/test_tractogram_filter_by_anatomy.py b/scripts/tests/test_tractogram_filter_by_anatomy.py index bcea696a6..fe0256095 100644 --- a/scripts/tests/test_tractogram_filter_by_anatomy.py +++ b/scripts/tests/test_tractogram_filter_by_anatomy.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['anatomical_filtering.zip']) @@ -20,9 +20,9 @@ def test_help_option(script_runner): def test_execution_filtering_all_options(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'anatomical_filtering', + in_tractogram = os.path.join(SCILPY_HOME, 'anatomical_filtering', 'tractogram_filter_ana.trk') - in_wmparc = os.path.join(get_home(), 'anatomical_filtering', + in_wmparc = os.path.join(SCILPY_HOME, 'anatomical_filtering', 'wmparc_filter_ana.nii.gz') ret = script_runner.run('scil_tractogram_filter_by_anatomy.py', in_tractogram, in_wmparc, @@ -39,9 +39,9 @@ def test_execution_filtering_all_options(script_runner): def test_execution_filtering_rejected(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'anatomical_filtering', + in_tractogram = os.path.join(SCILPY_HOME, 'anatomical_filtering', 'tractogram_filter_ana.trk') - in_wmparc = os.path.join(get_home(), 'anatomical_filtering', + in_wmparc = os.path.join(SCILPY_HOME, 'anatomical_filtering', 'wmparc_filter_ana.nii.gz') ret = script_runner.run('scil_tractogram_filter_by_anatomy.py', in_tractogram, in_wmparc, @@ -57,9 +57,9 @@ def test_execution_filtering_rejected(script_runner): def test_execution_filtering_save_intermediate(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'anatomical_filtering', + in_tractogram = os.path.join(SCILPY_HOME, 'anatomical_filtering', 'tractogram_filter_ana.trk') - in_wmparc = os.path.join(get_home(), 'anatomical_filtering', + in_wmparc = os.path.join(SCILPY_HOME, 'anatomical_filtering', 'wmparc_filter_ana.nii.gz') ret = script_runner.run('scil_tractogram_filter_by_anatomy.py', in_tractogram, in_wmparc, diff --git a/scripts/tests/test_tractogram_filter_by_length.py b/scripts/tests/test_tractogram_filter_by_length.py index 7ecc8def2..7020949b8 100644 --- a/scripts/tests/test_tractogram_filter_by_length.py +++ b/scripts/tests/test_tractogram_filter_by_length.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4.trk') ret = script_runner.run('scil_tractogram_filter_by_length.py', in_bundle, 'bundle_4_filtered.trk', diff --git a/scripts/tests/test_tractogram_filter_by_orientation.py b/scripts/tests/test_tractogram_filter_by_orientation.py index a3b30af88..60e4748f2 100644 --- a/scripts/tests/test_tractogram_filter_by_orientation.py +++ b/scripts/tests/test_tractogram_filter_by_orientation.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4.trk') ret = script_runner.run('scil_tractogram_filter_by_orientation.py', in_bundle, 'bundle_4_filtered.trk', diff --git a/scripts/tests/test_tractogram_filter_by_roi.py b/scripts/tests/test_tractogram_filter_by_roi.py index c021dde49..a84c9a27e 100644 --- a/scripts/tests/test_tractogram_filter_by_roi.py +++ b/scripts/tests/test_tractogram_filter_by_roi.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,11 +19,11 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'filtering', + in_tractogram = os.path.join(SCILPY_HOME, 'filtering', 'bundle_all_1mm_inliers.trk') - in_roi = os.path.join(get_home(), 'filtering', + in_roi = os.path.join(SCILPY_HOME, 'filtering', 'mask.nii.gz') - in_bdo = os.path.join(get_home(), 'filtering', + in_bdo = os.path.join(SCILPY_HOME, 'filtering', 'sc.bdo') ret = script_runner.run('scil_tractogram_filter_by_roi.py', in_tractogram, 'bundle_4.trk', '--display_counts', @@ -35,11 +35,11 @@ def test_execution_filtering(script_runner): def test_execution_filtering_distance(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'filtering', + in_tractogram = os.path.join(SCILPY_HOME, 'filtering', 'bundle_all_1mm_inliers.trk') - in_roi = os.path.join(get_home(), 'filtering', + in_roi = os.path.join(SCILPY_HOME, 'filtering', 'mask.nii.gz') - in_bdo = os.path.join(get_home(), 'filtering', + in_bdo = os.path.join(SCILPY_HOME, 'filtering', 'sc.bdo') ret = script_runner.run('scil_tractogram_filter_by_roi.py', in_tractogram, 'bundle_5.trk', '--display_counts', diff --git a/scripts/tests/test_tractogram_flip.py b/scripts/tests/test_tractogram_flip.py index 3f831d82b..f66934c1c 100644 --- a/scripts/tests/test_tractogram_flip.py +++ b/scripts/tests/test_tractogram_flip.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fib = os.path.join(get_home(), 'surface_vtk_fib', + in_fib = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'gyri_fanning.fib') - in_fa = os.path.join(get_home(), 'surface_vtk_fib', + in_fa = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'fa.nii.gz') ret = script_runner.run('scil_tractogram_flip.py', in_fib, 'gyri_fanning.tck', 'x', '--reference', in_fa) diff --git a/scripts/tests/test_tractogram_math.py b/scripts/tests/test_tractogram_math.py index d722f2c5e..bf028cb4f 100644 --- a/scripts/tests/test_tractogram_math.py +++ b/scripts/tests/test_tractogram_math.py @@ -4,12 +4,13 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) tmp_dir = tempfile.TemporaryDirectory() -trk_path = os.path.join(get_home(), 'others') +trk_path = os.path.join(SCILPY_HOME, 'others') def test_help_option(script_runner): diff --git a/scripts/tests/test_tractogram_print_info.py b/scripts/tests/test_tractogram_print_info.py index 82e5bee86..e420063ea 100644 --- a/scripts/tests/test_tractogram_print_info.py +++ b/scripts/tests/test_tractogram_print_info.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,6 +19,6 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', 'bundle_4.trk') + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_4.trk') ret = script_runner.run('scil_tractogram_print_info.py', in_bundle) assert ret.success diff --git a/scripts/tests/test_tractogram_project_map_to_streamlines.py b/scripts/tests/test_tractogram_project_map_to_streamlines.py index ce3b125fe..67a3c8bc7 100644 --- a/scripts/tests/test_tractogram_project_map_to_streamlines.py +++ b/scripts/tests/test_tractogram_project_map_to_streamlines.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -19,8 +20,8 @@ def test_help_option(script_runner): def test_execution_3D_map(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_t1 = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') - in_tracto_1 = os.path.join(get_home(), 'others', + in_t1 = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') + in_tracto_1 = os.path.join(SCILPY_HOME, 'others', 'IFGWM_sub.trk') ret = script_runner.run('scil_tractogram_project_map_to_streamlines.py', @@ -32,8 +33,8 @@ def test_execution_3D_map(script_runner): def test_execution_4D_map(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_rgb = os.path.join(get_home(), 'others', 'rgb.nii.gz') - in_tracto_1 = os.path.join(get_home(), 'others', + in_rgb = os.path.join(SCILPY_HOME, 'others', 'rgb.nii.gz') + in_tracto_1 = os.path.join(SCILPY_HOME, 'others', 'IFGWM_sub.trk') ret = script_runner.run('scil_tractogram_project_map_to_streamlines.py', @@ -45,8 +46,8 @@ def test_execution_4D_map(script_runner): def test_execution_3D_map_endpoints_only(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_t1 = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') - in_tracto_1 = os.path.join(get_home(), 'others', + in_t1 = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') + in_tracto_1 = os.path.join(SCILPY_HOME, 'others', 'IFGWM_sub.trk') ret = script_runner.run('scil_tractogram_project_map_to_streamlines.py', @@ -60,8 +61,8 @@ def test_execution_3D_map_endpoints_only(script_runner): def test_execution_4D_map_endpoints_only(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_rgb = os.path.join(get_home(), 'others', 'rgb.nii.gz') - in_tracto_1 = os.path.join(get_home(), 'others', + in_rgb = os.path.join(SCILPY_HOME, 'others', 'rgb.nii.gz') + in_tracto_1 = os.path.join(SCILPY_HOME, 'others', 'IFGWM_sub.trk') ret = script_runner.run('scil_tractogram_project_map_to_streamlines.py', @@ -75,8 +76,8 @@ def test_execution_4D_map_endpoints_only(script_runner): def test_execution_3D_map_trilinear(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_t1 = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') - in_tracto_1 = os.path.join(get_home(), 'others', + in_t1 = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') + in_tracto_1 = os.path.join(SCILPY_HOME, 'others', 'IFGWM_sub.trk') ret = script_runner.run('scil_tractogram_project_map_to_streamlines.py', diff --git a/scripts/tests/test_tractogram_project_streamlines_to_map.py b/scripts/tests/test_tractogram_project_streamlines_to_map.py index 48cdc5a1b..e6803aa97 100644 --- a/scripts/tests/test_tractogram_project_streamlines_to_map.py +++ b/scripts/tests/test_tractogram_project_streamlines_to_map.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -20,8 +20,8 @@ def test_help_option(script_runner): def test_execution_dpp(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM_uni.trk') - in_mni = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni.trk') + in_mni = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') in_bundle_with_dpp = 'IFGWM_uni_with_dpp.trk' # Create our test data with dpp: add metrics as dpp. @@ -52,8 +52,8 @@ def test_execution_dpp(script_runner): def test_execution_dps(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', 'IFGWM_uni.trk') - in_mni = os.path.join(get_home(), 'tractometry', 'mni_masked.nii.gz') + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni.trk') + in_mni = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') in_bundle_with_dpp = 'IFGWM_uni_with_dpp.trk' in_bundle_with_dps = 'IFGWM_uni_with_dps.trk' diff --git a/scripts/tests/test_tractogram_qbx.py b/scripts/tests/test_tractogram_qbx.py index 740ca759e..b59aaa8d7 100644 --- a/scripts/tests/test_tractogram_qbx.py +++ b/scripts/tests/test_tractogram_qbx.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['filtering.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_filtering(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'filtering', + in_bundle = os.path.join(SCILPY_HOME, 'filtering', 'bundle_all_1mm.trk') ret = script_runner.run('scil_tractogram_qbx.py', in_bundle, '12', 'clusters/', '--out_centroids', 'centroids.trk') diff --git a/scripts/tests/test_tractogram_register.py b/scripts/tests/test_tractogram_register.py index e013fefcd..ae1d5b489 100644 --- a/scripts/tests/test_tractogram_register.py +++ b/scripts/tests/test_tractogram_register.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -19,11 +19,11 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_moving = os.path.join(get_home(), 'bundles', + in_moving = os.path.join(SCILPY_HOME, 'bundles', 'bundle_0_reco.tck') - in_static = os.path.join(get_home(), 'bundles', 'voting_results', + in_static = os.path.join(SCILPY_HOME, 'bundles', 'voting_results', 'bundle_0.trk') - in_ref = os.path.join(get_home(), 'bundles', + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run('scil_tractogram_register.py', in_moving, in_static, '--only_rigid', diff --git a/scripts/tests/test_tractogram_remove_invalid.py b/scripts/tests/test_tractogram_remove_invalid.py index eaca1c2ba..f6a3429bb 100644 --- a/scripts/tests/test_tractogram_remove_invalid.py +++ b/scripts/tests/test_tractogram_remove_invalid.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'bundles', + in_tractogram = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.trk') ret = script_runner.run('scil_tractogram_remove_invalid.py', in_tractogram, 'bundle_all_1mm.trk', '--cut', diff --git a/scripts/tests/test_tractogram_resample.py b/scripts/tests/test_tractogram_resample.py index ff9f56974..dbe6e84e8 100644 --- a/scripts/tests/test_tractogram_resample.py +++ b/scripts/tests/test_tractogram_resample.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_downsample(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracto = os.path.join(get_home(), 'tracking', + in_tracto = os.path.join(SCILPY_HOME, 'tracking', 'union_shuffle_sub.trk') ret = script_runner.run('scil_tractogram_resample.py', in_tracto, '500', 'union_shuffle_sub_downsampled.trk') @@ -27,7 +28,7 @@ def test_execution_downsample(script_runner): def test_execution_upsample(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracto = os.path.join(get_home(), 'tracking', + in_tracto = os.path.join(SCILPY_HOME, 'tracking', 'union_shuffle_sub.trk') # in_tracto contains 761 streamlines. 2000=upsample. 200=downsample. diff --git a/scripts/tests/test_tractogram_resample_nb_points.py b/scripts/tests/test_tractogram_resample_nb_points.py index c7d9390b7..ebad536e9 100644 --- a/scripts/tests/test_tractogram_resample_nb_points.py +++ b/scripts/tests/test_tractogram_resample_nb_points.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM_uni_c.trk') ret = script_runner.run('scil_tractogram_resample_nb_points.py', in_bundle, 'IFGWM_uni_c_10.trk', diff --git a/scripts/tests/test_tractogram_segment_bundles.py b/scripts/tests/test_tractogram_segment_bundles.py index bc7ace46e..caac375cc 100644 --- a/scripts/tests/test_tractogram_segment_bundles.py +++ b/scripts/tests/test_tractogram_segment_bundles.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import json import os import tempfile -import json - -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -20,12 +20,12 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'bundles', + in_tractogram = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.trk') - in_conf = os.path.join(get_home(), 'bundles', 'fibercup_atlas', + in_conf = os.path.join(SCILPY_HOME, 'bundles', 'fibercup_atlas', 'default_config_sim.json') - in_models = os.path.join(get_home(), 'bundles', 'fibercup_atlas') - in_aff = os.path.join(get_home(), 'bundles', + in_models = os.path.join(SCILPY_HOME, 'bundles', 'fibercup_atlas') + in_aff = os.path.join(SCILPY_HOME, 'bundles', 'affine.txt') tmp_config = {} diff --git a/scripts/tests/test_tractogram_segment_one_bundles.py b/scripts/tests/test_tractogram_segment_one_bundles.py index 3ac9e7c18..b03a6c1e2 100644 --- a/scripts/tests/test_tractogram_segment_one_bundles.py +++ b/scripts/tests/test_tractogram_segment_one_bundles.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bundles.zip']) @@ -19,13 +19,13 @@ def test_help_option(script_runner): def test_execution_bundles(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tractogram = os.path.join(get_home(), 'bundles', + in_tractogram = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.trk') - in_model = os.path.join(get_home(), 'bundles', 'fibercup_atlas', + in_model = os.path.join(SCILPY_HOME, 'bundles', 'fibercup_atlas', 'subj_1', 'bundle_0.trk') - in_aff = os.path.join(get_home(), 'bundles', + in_aff = os.path.join(SCILPY_HOME, 'bundles', 'affine.txt') - in_ref = os.path.join(get_home(), 'bundles', + in_ref = os.path.join(SCILPY_HOME, 'bundles', 'bundle_all_1mm.nii.gz') ret = script_runner.run('scil_tractogram_segment_one_bundles.py', in_tractogram, in_model, in_aff, diff --git a/scripts/tests/test_tractogram_smooth.py b/scripts/tests/test_tractogram_smooth.py index dd2b4d6af..69967d049 100644 --- a/scripts/tests/test_tractogram_smooth.py +++ b/scripts/tests/test_tractogram_smooth.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tracking(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracto = os.path.join(get_home(), 'tracking', + in_tracto = os.path.join(SCILPY_HOME, 'tracking', 'union_shuffle_sub.trk') ret = script_runner.run('scil_tractogram_smooth.py', in_tracto, 'union_shuffle_sub_smooth.trk', '--gaussian', '10', diff --git a/scripts/tests/test_tractogram_split.py b/scripts/tests/test_tractogram_split.py index 206a6dd8f..b5fb8e7dd 100644 --- a/scripts/tests/test_tractogram_split.py +++ b/scripts/tests/test_tractogram_split.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tracking.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_tracking(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_tracto = os.path.join(get_home(), 'tracking', + in_tracto = os.path.join(SCILPY_HOME, 'tracking', 'local.trk') ret = script_runner.run('scil_tractogram_split.py', in_tracto, 'local_split', '--nb_chunks', '3', '-f') diff --git a/scripts/tests/test_tractogram_uniformize_endpoints.py b/scripts/tests/test_tractogram_uniformize_endpoints.py index 4030a2753..80ee9d7c1 100644 --- a/scripts/tests/test_tractogram_uniformize_endpoints.py +++ b/scripts/tests/test_tractogram_uniformize_endpoints.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -20,7 +20,7 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bundle = os.path.join(get_home(), 'tractometry', + in_bundle = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.trk') ret = script_runner.run('scil_tractogram_uniformize_endpoints.py', in_bundle, 'IFGWM_uni.trk', '--auto') diff --git a/scripts/tests/test_visualize_bingham_fit.py b/scripts/tests/test_visualize_bingham_fit.py index 78c1da97d..480722656 100644 --- a/scripts/tests/test_visualize_bingham_fit.py +++ b/scripts/tests/test_visualize_bingham_fit.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['tracking.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -19,7 +20,7 @@ def test_silent_without_output(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) # dummy dataset (the script should raise an error before using it) - in_dummy = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') + in_dummy = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') ret = script_runner.run('scil_visualize_bingham_fit.py', in_dummy, '--silent') diff --git a/scripts/tests/test_visualize_bundles_mosaic.py b/scripts/tests/test_visualize_bundles_mosaic.py index aec5ccf23..490db91e2 100644 --- a/scripts/tests/test_visualize_bundles_mosaic.py +++ b/scripts/tests/test_visualize_bundles_mosaic.py @@ -15,10 +15,10 @@ def test_help_option(script_runner): # def test_image_create(script_runner): # os.chdir(os.path.expanduser(tmp_dir.name)) # in_vol = os.path.join( -# get_home(), 'bundles', 'fibercup_atlas', 'bundle_all_1mm.nii.gz') +# SCILPY_HOME, 'bundles', 'fibercup_atlas', 'bundle_all_1mm.nii.gz') # in_bundle = os.path.join( -# get_home(), 'bundles', 'fibercup_atlas', 'subj_1', 'bundle_0.trk') +# SCILPY_HOME, 'bundles', 'fibercup_atlas', 'subj_1', 'bundle_0.trk') # ret = script_runner.run('scil_visualize_bundles_mosaic.py', # in_vol, in_bundle, 'out.png') diff --git a/scripts/tests/test_visualize_connectivity.py b/scripts/tests/test_visualize_connectivity.py index 11ad40c8c..decd45329 100644 --- a/scripts/tests/test_visualize_connectivity.py +++ b/scripts/tests/test_visualize_connectivity.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['connectivity.zip']) @@ -19,9 +19,9 @@ def test_help_option(script_runner): def test_execution_connectivity(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sc = os.path.join(get_home(), 'connectivity', + in_sc = os.path.join(SCILPY_HOME, 'connectivity', 'sc_norm.npy') - in_labels_list = os.path.join(get_home(), 'connectivity', + in_labels_list = os.path.join(SCILPY_HOME, 'connectivity', 'labels_list.txt') ret = script_runner.run('scil_visualize_connectivity.py', in_sc, 'sc_norm.png', '--log', '--display_legend', diff --git a/scripts/tests/test_visualize_fodf.py b/scripts/tests/test_visualize_fodf.py index 37f789072..4a78d3832 100644 --- a/scripts/tests/test_visualize_fodf.py +++ b/scripts/tests/test_visualize_fodf.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict fetch_data(get_testing_files_dict(), keys=['tracking.zip']) tmp_dir = tempfile.TemporaryDirectory() @@ -17,7 +18,7 @@ def test_help_option(script_runner): def test_silent_without_output(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fodf = os.path.join(get_home(), 'tracking', 'fodf.nii.gz') + in_fodf = os.path.join(SCILPY_HOME, 'tracking', 'fodf.nii.gz') ret = script_runner.run('scil_visualize_fodf.py', in_fodf, '--silent') diff --git a/scripts/tests/test_visualize_histogram.py b/scripts/tests/test_visualize_histogram.py index 92744eaae..571a5562f 100644 --- a/scripts/tests/test_visualize_histogram.py +++ b/scripts/tests/test_visualize_histogram.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fa = os.path.join(get_home(), 'processing', + in_fa = os.path.join(SCILPY_HOME, 'processing', 'fa.nii.gz') - in_mask = os.path.join(get_home(), 'processing', + in_mask = os.path.join(SCILPY_HOME, 'processing', 'seed.nii.gz') ret = script_runner.run('scil_visualize_histogram.py', in_fa, in_mask, '20', 'histogram.png') diff --git a/scripts/tests/test_visualize_scatterplot.py b/scripts/tests/test_visualize_scatterplot.py index 394a4d58a..a3510e050 100644 --- a/scripts/tests/test_visualize_scatterplot.py +++ b/scripts/tests/test_visualize_scatterplot.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['plot.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_x = os.path.join(get_home(), 'plot', + in_x = os.path.join(SCILPY_HOME, 'plot', 'fa.nii.gz') - in_y = os.path.join(get_home(), 'plot', + in_y = os.path.join(SCILPY_HOME, 'plot', 'ad.nii.gz') ret = script_runner.run('scil_visualize_scatterplot.py', in_x, in_y, 'scatter_plot.png') @@ -29,11 +30,11 @@ def test_execution_processing(script_runner): def test_execution_processing_bin_mask(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_x = os.path.join(get_home(), 'plot', + in_x = os.path.join(SCILPY_HOME, 'plot', 'fa.nii.gz') - in_y = os.path.join(get_home(), 'plot', + in_y = os.path.join(SCILPY_HOME, 'plot', 'ad.nii.gz') - in_mask = os.path.join(get_home(), 'plot', + in_mask = os.path.join(SCILPY_HOME, 'plot', 'mask_wm.nii.gz') ret = script_runner.run('scil_visualize_scatterplot.py', in_x, in_y, 'scatter_plot_m.png', '--in_bin_mask', in_mask) @@ -42,13 +43,13 @@ def test_execution_processing_bin_mask(script_runner): def test_execution_processing_prob_map(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_x = os.path.join(get_home(), 'plot', + in_x = os.path.join(SCILPY_HOME, 'plot', 'fa.nii.gz') - in_y = os.path.join(get_home(), 'plot', + in_y = os.path.join(SCILPY_HOME, 'plot', 'ad.nii.gz') - in_prob_1 = os.path.join(get_home(), 'plot', + in_prob_1 = os.path.join(SCILPY_HOME, 'plot', 'map_wm.nii.gz') - in_prob_2 = os.path.join(get_home(), 'plot', + in_prob_2 = os.path.join(SCILPY_HOME, 'plot', 'map_gm.nii.gz') ret = script_runner.run('scil_visualize_scatterplot.py', in_x, in_y, 'scatter_plot_prob.png', @@ -58,13 +59,13 @@ def test_execution_processing_prob_map(script_runner): def test_execution_processing_atlas(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_x = os.path.join(get_home(), 'plot', + in_x = os.path.join(SCILPY_HOME, 'plot', 'fa.nii.gz') - in_y = os.path.join(get_home(), 'plot', + in_y = os.path.join(SCILPY_HOME, 'plot', 'ad.nii.gz') - in_atlas = os.path.join(get_home(), 'plot', + in_atlas = os.path.join(SCILPY_HOME, 'plot', 'atlas_brainnetome.nii.gz') - atlas_lut = os.path.join(get_home(), 'plot', + atlas_lut = os.path.join(SCILPY_HOME, 'plot', 'atlas_brainnetome.json') ret = script_runner.run('scil_visualize_scatterplot.py', in_x, in_y, 'scatter_plot', '--in_atlas', in_atlas, @@ -74,13 +75,13 @@ def test_execution_processing_atlas(script_runner): def test_execution_processing_atlas_folder(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_x = os.path.join(get_home(), 'plot', + in_x = os.path.join(SCILPY_HOME, 'plot', 'fa.nii.gz') - in_y = os.path.join(get_home(), 'plot', + in_y = os.path.join(SCILPY_HOME, 'plot', 'ad.nii.gz') - in_atlas = os.path.join(get_home(), 'plot', + in_atlas = os.path.join(SCILPY_HOME, 'plot', 'atlas_brainnetome.nii.gz') - atlas_lut = os.path.join(get_home(), 'plot', + atlas_lut = os.path.join(SCILPY_HOME, 'plot', 'atlas_brainnetome.json') ret = script_runner.run('scil_visualize_scatterplot.py', in_x, in_y, 'scatter_plot', '--in_atlas', in_atlas, @@ -91,13 +92,13 @@ def test_execution_processing_atlas_folder(script_runner): def test_execution_processing_atlas_folder_specific_label(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_x = os.path.join(get_home(), 'plot', + in_x = os.path.join(SCILPY_HOME, 'plot', 'fa.nii.gz') - in_y = os.path.join(get_home(), 'plot', + in_y = os.path.join(SCILPY_HOME, 'plot', 'ad.nii.gz') - in_atlas = os.path.join(get_home(), 'plot', + in_atlas = os.path.join(SCILPY_HOME, 'plot', 'atlas_brainnetome.nii.gz') - atlas_lut = os.path.join(get_home(), 'plot', + atlas_lut = os.path.join(SCILPY_HOME, 'plot', 'atlas_brainnetome.json') ret = script_runner.run('scil_visualize_scatterplot.py', in_x, in_y, 'scatter_plot', '--in_atlas', in_atlas, diff --git a/scripts/tests/test_volume_apply_transform.py b/scripts/tests/test_volume_apply_transform.py index e6d111aef..7c6d579fa 100644 --- a/scripts/tests/test_volume_apply_transform.py +++ b/scripts/tests/test_volume_apply_transform.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['bst.zip']) @@ -19,11 +19,11 @@ def test_help_option(script_runner): def test_execution_bst(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_model = os.path.join(get_home(), 'bst', 'template', + in_model = os.path.join(SCILPY_HOME, 'bst', 'template', 'template0.nii.gz') - in_fa = os.path.join(get_home(), 'bst', + in_fa = os.path.join(SCILPY_HOME, 'bst', 'fa.nii.gz') - in_aff = os.path.join(get_home(), 'bst', + in_aff = os.path.join(SCILPY_HOME, 'bst', 'output0GenericAffine.mat') ret = script_runner.run('scil_volume_apply_transform.py', in_model, in_fa, in_aff, diff --git a/scripts/tests/test_volume_b0_synthesis.py b/scripts/tests/test_volume_b0_synthesis.py index 52bea3fc8..72d01fb92 100644 --- a/scripts/tests/test_volume_b0_synthesis.py +++ b/scripts/tests/test_volume_b0_synthesis.py @@ -1,13 +1,16 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict import os import tempfile -import pytest import nibabel as nib import numpy as np +import pytest + +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict + tensorflow = pytest.importorskip("tensorflow") @@ -24,9 +27,9 @@ def test_help_option(script_runner): @pytest.mark.skipif(tensorflow is None, reason="Tensorflow not installed") def test_synthesis(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_t1 = os.path.join(get_home(), 'others', + in_t1 = os.path.join(SCILPY_HOME, 'others', 't1.nii.gz') - in_b0 = os.path.join(get_home(), 'processing', + in_b0 = os.path.join(SCILPY_HOME, 'processing', 'b0_mean.nii.gz') t1_img = nib.load(in_t1) diff --git a/scripts/tests/test_volume_count_non_zero_voxels.py b/scripts/tests/test_volume_count_non_zero_voxels.py index 0eb3dd9dd..fa080c23d 100644 --- a/scripts/tests/test_volume_count_non_zero_voxels.py +++ b/scripts/tests/test_volume_count_non_zero_voxels.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'others', + in_img = os.path.join(SCILPY_HOME, 'others', 'rgb.nii.gz') ret = script_runner.run('scil_volume_count_non_zero_voxels.py', in_img) assert ret.success diff --git a/scripts/tests/test_volume_crop.py b/scripts/tests/test_volume_crop.py index 16154af10..92aa1f3e2 100644 --- a/scripts/tests/test_volume_crop.py +++ b/scripts/tests/test_volume_crop.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_dwi = os.path.join(get_home(), 'processing', + in_dwi = os.path.join(SCILPY_HOME, 'processing', 'dwi.nii.gz') ret = script_runner.run('scil_crop_volume.py', in_dwi, 'dwi_crop.nii.gz') assert ret.success diff --git a/scripts/tests/test_volume_flip.py b/scripts/tests/test_volume_flip.py index 97ea1032e..356ec6b4d 100644 --- a/scripts/tests/test_volume_flip.py +++ b/scripts/tests/test_volume_flip.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys='surface_vtk_fib.zip') @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_surface_vtk_fib(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_fa = os.path.join(get_home(), 'surface_vtk_fib', + in_fa = os.path.join(SCILPY_HOME, 'surface_vtk_fib', 'fa.nii.gz') ret = script_runner.run('scil_volume_flip.py', in_fa, 'fa_flip.nii.gz', 'x') diff --git a/scripts/tests/test_volume_math.py b/scripts/tests/test_volume_math.py index 07c8e7e01..666b37a10 100644 --- a/scripts/tests/test_volume_math.py +++ b/scripts/tests/test_volume_math.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['atlas.zip']) @@ -18,11 +19,11 @@ def test_help_option(script_runner): def test_execution_add(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img_1 = os.path.join(get_home(), 'atlas', + in_img_1 = os.path.join(SCILPY_HOME, 'atlas', 'brainstem_173.nii.gz') - in_img_2 = os.path.join(get_home(), 'atlas', + in_img_2 = os.path.join(SCILPY_HOME, 'atlas', 'brainstem_174.nii.gz') - in_img_3 = os.path.join(get_home(), 'atlas', + in_img_3 = os.path.join(SCILPY_HOME, 'atlas', 'brainstem_175.nii.gz') ret = script_runner.run('scil_volume_math.py', 'addition', in_img_1, in_img_2, in_img_3, 'brainstem.nii.gz') @@ -31,7 +32,7 @@ def test_execution_add(script_runner): def test_execution_low_thresh(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'atlas', 'brainstem.nii.gz') + in_img = os.path.join(SCILPY_HOME, 'atlas', 'brainstem.nii.gz') ret = script_runner.run('scil_volume_math.py', 'lower_threshold', in_img, '1', 'brainstem_bin.nii.gz') assert ret.success @@ -39,7 +40,7 @@ def test_execution_low_thresh(script_runner): def test_execution_low_mult(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'atlas', 'brainstem_bin.nii.gz') + in_img = os.path.join(SCILPY_HOME, 'atlas', 'brainstem_bin.nii.gz') ret = script_runner.run('scil_volume_math.py', 'multiplication', in_img, '16', 'brainstem_unified.nii.gz') assert ret.success @@ -47,12 +48,12 @@ def test_execution_low_mult(script_runner): def test_execution_concatenate(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img_1 = os.path.join(get_home(), 'atlas', 'ids', '10.nii.gz') - in_img_2 = os.path.join(get_home(), 'atlas', 'ids', '11.nii.gz') - in_img_3 = os.path.join(get_home(), 'atlas', 'ids', '12.nii.gz') - in_img_4 = os.path.join(get_home(), 'atlas', 'ids', '13.nii.gz') - in_img_5 = os.path.join(get_home(), 'atlas', 'ids', '17.nii.gz') - in_img_6 = os.path.join(get_home(), 'atlas', 'ids', '18.nii.gz') + in_img_1 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '10.nii.gz') + in_img_2 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '11.nii.gz') + in_img_3 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '12.nii.gz') + in_img_4 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '13.nii.gz') + in_img_5 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '17.nii.gz') + in_img_6 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '18.nii.gz') ret = script_runner.run('scil_volume_math.py', 'concatenate', in_img_1, in_img_2, in_img_3, in_img_4, in_img_5, in_img_6, 'concat_ids.nii.gz') @@ -61,10 +62,10 @@ def test_execution_concatenate(script_runner): def test_execution_concatenate_4D(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img_1 = os.path.join(get_home(), 'atlas', 'ids', '10.nii.gz') - in_img_2 = os.path.join(get_home(), 'atlas', 'ids', '8_10.nii.gz') - in_img_3 = os.path.join(get_home(), 'atlas', 'ids', '12.nii.gz') - in_img_4 = os.path.join(get_home(), 'atlas', 'ids', '8_10.nii.gz') + in_img_1 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '10.nii.gz') + in_img_2 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '8_10.nii.gz') + in_img_3 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '12.nii.gz') + in_img_4 = os.path.join(SCILPY_HOME, 'atlas', 'ids', '8_10.nii.gz') ret = script_runner.run('scil_volume_math.py', 'concatenate', in_img_1, in_img_2, in_img_3, in_img_4, 'concat_ids_4d.nii.gz') diff --git a/scripts/tests/test_volume_remove_outliers_ransac.py b/scripts/tests/test_volume_remove_outliers_ransac.py index 3c4890b19..482cbe61a 100644 --- a/scripts/tests/test_volume_remove_outliers_ransac.py +++ b/scripts/tests/test_volume_remove_outliers_ransac.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['processing.zip']) @@ -18,7 +19,7 @@ def test_help_option(script_runner): def test_execution_processing(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_ad = os.path.join(get_home(), 'processing', + in_ad = os.path.join(SCILPY_HOME, 'processing', 'ad.nii.gz') ret = script_runner.run('scil_volume_remove_outliers_ransac.py', in_ad, 'ad_ransanc.nii.gz') diff --git a/scripts/tests/test_volume_resample.py b/scripts/tests/test_volume_resample.py index 9bf4cf81c..617b6c436 100644 --- a/scripts/tests/test_volume_resample.py +++ b/scripts/tests/test_volume_resample.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip']) @@ -19,7 +19,7 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'others', + in_img = os.path.join(SCILPY_HOME, 'others', 'fa.nii.gz') ret = script_runner.run('scil_volume_resample.py', in_img, 'fa_resample.nii.gz', '--voxel_size', '2') diff --git a/scripts/tests/test_volume_reshape_to_reference.py b/scripts/tests/test_volume_reshape_to_reference.py index 6eeffc552..e26e945f8 100644 --- a/scripts/tests/test_volume_reshape_to_reference.py +++ b/scripts/tests/test_volume_reshape_to_reference.py @@ -4,8 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import get_testing_files_dict, fetch_data, get_home - +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['others.zip', 'commit_amico.zip']) @@ -19,8 +19,8 @@ def test_help_option(script_runner): def test_execution_others(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'others', 't1_crop.nii.gz') - in_ref = os.path.join(get_home(), 'others', 't1.nii.gz') + in_img = os.path.join(SCILPY_HOME, 'others', 't1_crop.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'others', 't1.nii.gz') ret = script_runner.run('scil_volume_reshape_to_reference.py', in_img, in_ref, 't1_reshape.nii.gz', '--interpolation', 'nearest') @@ -29,8 +29,8 @@ def test_execution_others(script_runner): def test_execution_4D(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_img = os.path.join(get_home(), 'commit_amico', 'dwi.nii.gz') - in_ref = os.path.join(get_home(), 'others', 't1.nii.gz') + in_img = os.path.join(SCILPY_HOME, 'commit_amico', 'dwi.nii.gz') + in_ref = os.path.join(SCILPY_HOME, 'others', 't1.nii.gz') ret = script_runner.run('scil_volume_reshape_to_reference.py', in_img, in_ref, 'dwi_reshape.nii.gz', '--interpolation', 'nearest') diff --git a/scripts/tests/test_volume_stats_in_ROI.py b/scripts/tests/test_volume_stats_in_ROI.py index ee6b60603..0d2eb2f5e 100644 --- a/scripts/tests/test_volume_stats_in_ROI.py +++ b/scripts/tests/test_volume_stats_in_ROI.py @@ -4,7 +4,8 @@ import os import tempfile -from scilpy.io.fetcher import fetch_data, get_home, get_testing_files_dict +from scilpy import SCILPY_HOME +from scilpy.io.fetcher import fetch_data, get_testing_files_dict # If they already exist, this only takes 5 seconds (check md5sum) fetch_data(get_testing_files_dict(), keys=['tractometry.zip']) @@ -18,9 +19,9 @@ def test_help_option(script_runner): def test_execution_tractometry(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_mask = os.path.join(get_home(), 'tractometry', + in_mask = os.path.join(SCILPY_HOME, 'tractometry', 'IFGWM.nii.gz') - in_ref = os.path.join(get_home(), 'tractometry', + in_ref = os.path.join(SCILPY_HOME, 'tractometry', 'mni_masked.nii.gz') ret = script_runner.run('scil_volume_stats_in_ROI.py', in_mask, '--metrics', in_ref) From 772ec3de8cf1beb95394bfe328a4dcd8aa2b265b Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Tue, 5 Mar 2024 22:08:07 -0500 Subject: [PATCH 37/38] final replacements --- scripts/tests/test_frf_mean.py | 2 +- scripts/tests/test_gradients_validate_correct.py | 6 +++--- scripts/tests/test_sh_to_sf.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/tests/test_frf_mean.py b/scripts/tests/test_frf_mean.py index 40cbbf3c6..8879f639a 100644 --- a/scripts/tests/test_frf_mean.py +++ b/scripts/tests/test_frf_mean.py @@ -20,7 +20,7 @@ def test_help_option(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') + in_frf = os.path.join(SCILPY_HOME, 'processing', 'frf.txt') ret = script_runner.run('scil_frf_mean.py', in_frf, in_frf, 'mfrf1.txt') assert ret.success diff --git a/scripts/tests/test_gradients_validate_correct.py b/scripts/tests/test_gradients_validate_correct.py index 0e7a88e0a..cb7a305dd 100644 --- a/scripts/tests/test_gradients_validate_correct.py +++ b/scripts/tests/test_gradients_validate_correct.py @@ -38,11 +38,11 @@ def test_execution_processing_dti_peaks(script_runner): def test_execution_processing_fodf_peaks(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_bvec = os.path.join(get_home(), 'processing', + in_bvec = os.path.join(SCILPY_HOME, 'processing', 'dwi.bvec') - in_peaks = os.path.join(get_home(), 'processing', + in_peaks = os.path.join(SCILPY_HOME, 'processing', 'peaks.nii.gz') - in_fa = os.path.join(get_home(), 'processing', + in_fa = os.path.join(SCILPY_HOME, 'processing', 'fa.nii.gz') # test the actual script diff --git a/scripts/tests/test_sh_to_sf.py b/scripts/tests/test_sh_to_sf.py index b86631b8c..7606e1549 100755 --- a/scripts/tests/test_sh_to_sf.py +++ b/scripts/tests/test_sh_to_sf.py @@ -34,9 +34,9 @@ def test_execution_in_sphere(script_runner): def test_execution_in_bvec(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sh = os.path.join(get_home(), 'processing', 'sh_1000.nii.gz') - in_bval = os.path.join(get_home(), 'processing', '1000.bval') - in_bvec = os.path.join(get_home(), 'processing', '1000.bvec') + in_sh = os.path.join(SCILPY_HOME, 'processing', 'sh_1000.nii.gz') + in_bval = os.path.join(SCILPY_HOME, 'processing', '1000.bval') + in_bvec = os.path.join(SCILPY_HOME, 'processing', '1000.bvec') # --in_bvec: in_bval is required. ret = script_runner.run('scil_sh_to_sf.py', in_sh, @@ -56,8 +56,8 @@ def test_execution_in_bvec(script_runner): def test_execution_no_bval(script_runner): os.chdir(os.path.expanduser(tmp_dir.name)) - in_sh = os.path.join(get_home(), 'processing', 'sh_1000.nii.gz') - in_b0 = os.path.join(get_home(), 'processing', 'fa.nii.gz') + in_sh = os.path.join(SCILPY_HOME, 'processing', 'sh_1000.nii.gz') + in_b0 = os.path.join(SCILPY_HOME, 'processing', 'fa.nii.gz') # --sphere but no --bval ret = script_runner.run('scil_sh_to_sf.py', in_sh, From 9f34e4de357e91ad0e4b0e7c8251d8e4614c1e8c Mon Sep 17 00:00:00 2001 From: AlexVCaron Date: Wed, 6 Mar 2024 10:30:13 -0500 Subject: [PATCH 38/38] Switch scil_data for neurogister. Minor renaming for lisibility --- scilpy/io/dvc.py | 75 +++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/scilpy/io/dvc.py b/scilpy/io/dvc.py index 62e5eee1e..60f19112a 100644 --- a/scilpy/io/dvc.py +++ b/scilpy/io/dvc.py @@ -8,7 +8,7 @@ from scilpy import SCILPY_HOME, SCILPY_ROOT -DVC_REPOSITORY = "https://github.com/AlexVCaron/scil_data.git" +DVC_REPOSITORY = "https://github.com/scilus/neurogister.git" DEFAULT_CACHE_CONFIG = { "type": "symlink", "shared": "group", @@ -38,7 +38,7 @@ def pull_test_case_package(package_name): The path to the pulled package. .. _Scilpy Tests Vendor: - https://github.com/AlexVCaron/scilus/tree/main/store/scilpy_tests + https://github.com/scilus/neurogister/tree/main/store/scilpy_tests/meta.yml # noqa """ with open(f"{SCILPY_ROOT}/.dvc/test_descriptors.yml", 'r') as f: test_descriptors = yaml.safe_load(f) @@ -48,15 +48,15 @@ def pull_test_case_package(package_name): pull_package_from_dvc_repository( "scilpy_tests", f"{package_name}", f"{SCILPY_HOME}/test_data", - test_descriptors[package_name]["revision"]) + git_revision=test_descriptors[package_name]["revision"]) return f"{SCILPY_HOME}/test_data/{package_name}" -def pull_package_from_dvc_repository(vendor, package_name, output_dir, - revision="main", - remote_url=DVC_REPOSITORY, - remote_name="scil-data", +def pull_package_from_dvc_repository(vendor, package_name, local_destination, + git_remote_url=DVC_REPOSITORY, + git_revision="main", + dvc_remote_name="scil-data", dvc_config_root=f"{SCILPY_ROOT}/.dvc"): """ Pull a package from a correctly configured DVC remote repository. Packages @@ -69,13 +69,13 @@ def pull_package_from_dvc_repository(vendor, package_name, output_dir, Name of the vendor to pull the package from. package_name : str Name of the package to pull from the vendor. - output_dir : str - Path to the directory where the package will be pulled. - revision : str - Git revision of the DVC artifact to pull. - remote_url : str - URL of the DVC git repository. - remote_name : str + local_destination : str + Destination where to pull the package. + git_remote_url : str + URL of the Git repository containing DVC artifacts. + git_revision : str + Git revision of the DVC artifacts repository. + dvc_remote_name : str Name of the DVC remote to use. dvc_config_root : str Location of the DVC configuration files. @@ -86,32 +86,33 @@ def pull_package_from_dvc_repository(vendor, package_name, output_dir, The path to the pulled package. .. _SCIL Data Store: - https://github.com/scilus/scil_data/tree/main/store + https://github.com/scilus/neurogister/tree/main/store """ return pull_from_dvc_repository(f"store/{vendor}/{package_name}", - f"{output_dir}/", - revision, remote_url, remote_name, - dvc_config_root) + f"{local_destination}/", + git_remote_url, git_revision, + dvc_remote_name, dvc_config_root) -def pull_from_dvc_repository(package_name, output_dir, revision="main", - remote_url=DVC_REPOSITORY, - remote_name="scil-data", +def pull_from_dvc_repository(remote_location, local_destination, + git_remote_url=DVC_REPOSITORY, + git_revision="main", + dvc_remote_name="scil-data", dvc_config_root=f"{SCILPY_ROOT}/.dvc"): """ Pull data from a DVC remote repository to the specified location. Parameters ---------- - package_name : str - Name of the package to pull from the DVC repository. - output_dir : str - Path to the directory where the package will be pulled. - revision : str - Git revision of the DVC artifact to pull. - remote_url : str - URL of the DVC git repository. - remote_name : str + remote_location : str + Location of the data to pull in the repository. + local_destination : str + Destination where to pull the data. + git_remote_url : str + URL of the Git repository containing DVC artifacts. + git_revision : str + Git revision of the DVC artifacts repository. + dvc_remote_name : str Name of the DVC remote to use. dvc_config_root : str Location of the DVC configuration files. @@ -121,11 +122,13 @@ def pull_from_dvc_repository(package_name, output_dir, revision="main", str The path to the pulled package. """ - conf = get_default_config() - conf.merge(config.Config(dvc_config_root)) + repository_config = get_default_config() + repository_config.merge(config.Config(dvc_config_root)) + remote_config = repository_config["remote"][dvc_remote_name] - registry = api.DVCFileSystem(remote_url, revision, - config=conf, remote_name=remote_name, - remote_config=conf["remote"][remote_name]) + registry = api.DVCFileSystem(git_remote_url, git_revision, + config=repository_config, + remote_name=dvc_remote_name, + remote_config=remote_config) - registry.get(package_name, output_dir, True, cache=True) + registry.get(remote_location, local_destination, True, cache=True)