Skip to content

Commit

Permalink
fix more positionnal arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbore committed Jan 27, 2025
1 parent d07a454 commit 251e9b6
Show file tree
Hide file tree
Showing 39 changed files with 91 additions and 70 deletions.
2 changes: 1 addition & 1 deletion scilpy/denoise/asym_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def unified_filtering(sh_data, sh_order, sh_basis, is_legacy, full_basis,
raise ValueError('Option use_opencl must be enabled '
'to use device \'gpu\'.')

sphere = get_sphere(sphere_str)
sphere = get_sphere(name=sphere_str)

if sigma_spatial is not None:
if sigma_spatial <= 0.0:
Expand Down
12 changes: 8 additions & 4 deletions scilpy/image/volume_b0_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,20 @@ def compute_b0_synthesis(t1_data, t1_bet_data, b0_data, b0_bet_data,
t1_bet_to_b0, t1_bet_to_b0_transform = register_image(
b0_bet_data, b0_affine, t1_bet_data, t1_affine, fine=True)
affine_map = AffineMap(t1_bet_to_b0_transform,
b0_data.shape, b0_affine,
t1_data.shape, t1_affine)
domain_grid_shape=b0_data.shape,
domain_grid2world=b0_affine,
codomain_grid_shape=t1_data.shape,
codomain_grid2world=t1_affine)
t1_skull_to_b0 = affine_map.transform(t1_data.astype(np.float64))

# Then register to MNI (using the BET again)
_, t1_bet_to_b0_to_mni_transform = register_image(
template_data, template_affine, t1_bet_to_b0, b0_affine, fine=True)
affine_map = AffineMap(t1_bet_to_b0_to_mni_transform,
template_data.shape, template_affine,
b0_data.shape, b0_affine)
domain_grid_shape=template_data.shape,
domain_grid2world=template_affine,
codomain_grid_shape=b0_data.shape,
codomain_grid2world=b0_affine)

# But for prediction, we want the skull
b0_skull_to_mni = affine_map.transform(b0_data.astype(np.float64))
Expand Down
14 changes: 9 additions & 5 deletions scilpy/image/volume_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ def apply_transform(transfo, reference, moving,
if moving_data.ndim == 3:
orig_type = moving_data.dtype
affine_map = AffineMap(np.linalg.inv(transfo),
dim, grid2world,
moving_data.shape, moving_affine)
domain_grid_shape=dim,
domain_grid2world=grid2world,
codomain_grid_shape=moving_data.shape,
codomain_grid2world=moving_affine)
resampled = affine_map.transform(moving_data.astype(np.float64),
interpolation=interp)
elif moving_data.ndim == 4:
Expand All @@ -168,8 +170,10 @@ def apply_transform(transfo, reference, moving,
'bvecs with scil_gradients_apply_transform.py')

affine_map = AffineMap(np.linalg.inv(transfo),
dim[0:3], grid2world,
moving_data.shape[0:3], moving_affine)
domain_grid_shape=dim[0:3],
domain_grid2world=grid2world,
codomain_grid_shape=moving_data.shape[0:3],
codomain_grid2world=moving_affine)

orig_type = moving_data.dtype
resampled = transform_dwi(affine_map, static_data, moving_data,
Expand Down Expand Up @@ -268,7 +272,7 @@ def register_image(static, static_grid2world, moving, moving_grid2world,

sigmas = [8.0, 4.0, 2.0, 1.0] if fine else [8.0, 4.0, 2.0]
factors = [8, 4, 2, 1.0] if fine else [8, 4, 2]
metric = MutualInformationMetric(nbins, sampling_prop)
metric = MutualInformationMetric(nbins=nbins, sampling_proportion=sampling_prop)
reg_obj = AffineRegistration(metric=metric, level_iters=level_iters,
sigmas=sigmas, factors=factors, verbosity=0)

Expand Down
2 changes: 1 addition & 1 deletion scilpy/reconst/bingham.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def bingham_fit_sh(sh, max_lobes=5, abs_th=0.,
order, full_basis = get_sh_order_and_fullness(sh.shape[-1])
shape = sh.shape

sphere = get_sphere('symmetric724').subdivide(2)
sphere = get_sphere(name='symmetric724').subdivide(n=2)
B_mat = sh_to_sf_matrix(sphere, order,
full_basis=full_basis,
return_inv=False)
Expand Down
2 changes: 1 addition & 1 deletion scilpy/reconst/fodf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_ventricles_max_fodf(data, fa, md, zoom, sh_basis,
"""

order = find_order_from_nb_coeff(data)
sphere = get_sphere('repulsion100')
sphere = get_sphere(name='repulsion100')
b_matrix, _ = sh_to_sf_matrix(sphere, order, sh_basis, legacy=is_legacy)
mask = np.zeros(data.shape[:-1])

Expand Down
6 changes: 3 additions & 3 deletions scilpy/reconst/frf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def compute_ssst_frf(data, bvals, bvecs, b0_threshold=DEFAULT_B0_THRESHOLD,
logging.warning("Your b-vectors do not seem normalized... Normalizing")
bvecs = normalize_bvecs(bvecs)

gtab = gradient_table(bvals, bvecs, b0_threshold=b0_threshold)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=b0_threshold)

if mask is not None:
data = applymask(data, mask)
Expand Down Expand Up @@ -236,7 +236,7 @@ def compute_msmt_frf(data, bvals, bvecs, btens=None, data_dti=None,
# Note. Using the tolerance here because currently, the gtab.b0s_mask is
# not used. Below, we use the tolerance only (in dipy).
# An issue has been added in dipy too.
gtab = gradient_table(bvals, bvecs, btens=btens, b0_threshold=tol)
gtab = gradient_table(bvals, bvecs=bvecs, btens=btens, b0_threshold=tol)

if data_dti is None and bvals_dti is None and bvecs_dti is None:
logging.warning(
Expand All @@ -257,7 +257,7 @@ def compute_msmt_frf(data, bvals, bvecs, btens=None, data_dti=None,
logging.warning('Your b-vectors do not seem normalized...')
bvecs_dti = normalize_bvecs(bvecs_dti)

gtab_dti = gradient_table(bvals_dti, bvecs_dti, btens=btens_dti)
gtab_dti = gradient_table(bvals_dti, bvecs=bvecs_dti, btens=btens_dti)

wm_frf_mask, gm_frf_mask, csf_frf_mask \
= mask_for_response_msmt(gtab_dti, data_dti,
Expand Down
9 changes: 5 additions & 4 deletions scilpy/reconst/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ def _peaks_from_sh_loop(shm_coeff, B, sphere, relative_peak_threshold,
odf[odf < absolute_threshold] = 0.

dirs, peaks, ind = peak_directions(odf, sphere,
relative_peak_threshold,
min_separation_angle,
is_symmetric)
relative_peak_threshold=relative_peak_threshold,
min_separation_angle=min_separation_angle,
is_symmetric=is_symmetric)

if peaks.shape[0] != 0:
n = min(npeaks, peaks.shape[0])
Expand Down Expand Up @@ -287,7 +287,8 @@ def peaks_from_sh(shm_coeff, sphere, mask=None, relative_peak_threshold=0.5,
tuple of np.ndarray
peak_dirs, peak_values, peak_indices
"""
sh_order = order_from_ncoef(shm_coeff.shape[-1], full_basis)
sh_order = order_from_ncoef(shm_coeff.shape[-1],
full_basis=full_basis)
B, _ = sh_to_sf_matrix(sphere, sh_order, sh_basis_type,
full_basis, legacy=is_legacy)

Expand Down
2 changes: 1 addition & 1 deletion scilpy/reconst/tests/test_fodf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_get_ventricles_max_fodf():

# Reconstruct SF values same as in method.
order = find_order_from_nb_coeff(fodf_3x3_order8_descoteaux07)
sphere = get_sphere('repulsion100')
sphere = get_sphere(name='repulsion100')
b_matrix, _ = sh_to_sf_matrix(sphere, order, sh_basis, legacy=True)

sf1 = np.dot(fodf_3x3_order8_descoteaux07[1, 0, 0], b_matrix)
Expand Down
4 changes: 2 additions & 2 deletions scilpy/segment/recobundlesx.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def _register_model_to_neighb(self, select_model=1000, select_target=1000,
possible_slr_transform_type = {'translation': 0, 'rigid': 1,
'similarity': 2, 'scaling': 3}
static = select_random_set_of_streamlines(self.model_centroids,
select_model, self.rng)
select_model, rng=self.rng)
moving = select_random_set_of_streamlines(self.neighb_centroids,
select_target, self.rng)
select_target, rng=self.rng)

# Tuple 0,1,2 are the min & max bound in x,y,z for translation
# Tuple 3,4,5 are the min & max bound in x,y,z for rotation
Expand Down
2 changes: 1 addition & 1 deletion scilpy/tracking/propagator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def __init__(self, datavolume, step_size, rk_order, dipy_sphere,
"""
super().__init__(datavolume, step_size, rk_order, space, origin)

self.sphere = dipy.data.get_sphere(dipy_sphere).subdivide(sub_sphere)
self.sphere = dipy.data.get_sphere(dipy_sphere).subdivide(n=sub_sphere)
self.dirs = np.zeros(len(self.sphere.vertices), dtype=np.ndarray)
for i in range(len(self.sphere.vertices)):
self.dirs[i] = TrackingDirection(self.sphere.vertices[i], i)
Expand Down
2 changes: 1 addition & 1 deletion scilpy/tracking/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def get_direction_getter(in_img, algo, sphere, sub_sphere, theta, sh_basis,
img_data = nib.load(in_img).get_fdata(dtype=np.float32)

sphere = HemiSphere.from_sphere(
get_sphere(sphere)).subdivide(sub_sphere)
get_sphere(sphere)).subdivide(n=sub_sphere)

# Theta depends on user choice and algorithm
theta = get_theta(theta, algo)
Expand Down
2 changes: 1 addition & 1 deletion scilpy/tractanalysis/afd_along_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def afd_and_rd_sums_along_streamlines(sft, fodf, fodf_basis,

fodf_data = fodf.get_fdata(dtype=np.float32)
order = find_order_from_nb_coeff(fodf_data)
sphere = get_sphere('repulsion724')
sphere = get_sphere(name='repulsion724')
b_matrix, _ = sh_to_sf_matrix(sphere, order, fodf_basis, legacy=is_legacy)
_, n = sph_harm_ind_list(order)
legendre0_at_n = lpn(order, 0)[0][n]
Expand Down
2 changes: 1 addition & 1 deletion scilpy/tractanalysis/reproducibility_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def tractogram_pairwise_comparison(sft_one, sft_two, mask, nbr_cpu=1,
sft_2.to_center()

global B
B, _ = sh_to_sf_matrix(get_sphere('repulsion724'), 8, 'descoteaux07')
B, _ = sh_to_sf_matrix(get_sphere(name='repulsion724'), 8, 'descoteaux07')

diff_data, acc_data = _compare_tractogram_wrapper(
mask, nbr_cpu, skip_streamlines_distance)
Expand Down
2 changes: 1 addition & 1 deletion scilpy/tractograms/tractogram_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def transform_warp_sft(sft, linear_transfo, target, inverse=False,
streamlines = transform_streamlines(streamlines, linear_transfo)

streamlines._data = streamlines._data.astype(dtype)
new_sft = StatefulTractogram(streamlines, target, Space.RASMM,
new_sft = StatefulTractogram(streamlines, target, space=Space.RASMM,
data_per_point=sft.data_per_point,
data_per_streamline=sft.data_per_streamline)
if cut_invalid:
Expand Down
4 changes: 2 additions & 2 deletions scilpy/viz/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def plot_each_shell(ms, centroids, plot_sym_vecs=True, use_sphere=True,
_colors = generate_n_colors(len(ms))

if use_sphere:
sphere = get_sphere('symmetric724')
sphere = get_sphere(name='symmetric724')
shape = (1, 1, 1, sphere.vertices.shape[0])
_, fname = mkstemp(suffix='_odf_slicer.mmap')
odfs = np.memmap(fname, dtype=np.float64, mode='w+', shape=shape)
Expand Down Expand Up @@ -108,7 +108,7 @@ def plot_proj_shell(ms, use_sym=True, use_sphere=True, same_color=False,
scene = window.Scene()
scene.SetBackground(1, 1, 1)
if use_sphere:
sphere = get_sphere('symmetric724')
sphere = get_sphere(name='symmetric724')
shape = (1, 1, 1, sphere.vertices.shape[0])
_, fname = mkstemp(suffix='_odf_slicer.mmap')
odfs = np.memmap(fname, dtype=np.float64, mode='w+', shape=shape)
Expand Down
2 changes: 1 addition & 1 deletion scilpy/viz/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def create_odf_slicer(sh_fodf, orientation, slice_index, sphere, sh_order,

# Subdivide the spheres if nb_subdivide is provided
if nb_subdivide is not None:
sphere = sphere.subdivide(nb_subdivide)
sphere = sphere.subdivide(n=nb_subdivide)

fodf = sh_to_sf(sh_fodf, sphere, sh_order, sh_basis,
full_basis=full_basis, legacy=is_legacy)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_bundle_clean_qbx_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def save_clusters(cluster_lists, indexes_list, directory, basenames_list,
if directory:
tmp_sft = StatefulTractogram(streamlines,
cluster_lists[0],
Space.RASMM)
space=Space.RASMM)
tmp_filename = os.path.join(directory,
basenames_list[idx])
save_tractogram(tmp_sft, tmp_filename,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_bundle_generate_priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def main():

# Memory friendly saving, as soon as possible saving then delete
priors_3d = np.zeros(sh_shape)
sphere = get_sphere('repulsion724')
sphere = get_sphere(name='repulsion724')
priors_3d[sub_mask_3d] = sf_to_sh(todi_sf, sphere,
sh_order_max=sh_order,
basis_type=sh_basis,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_dki_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def main():
_ = check_b0_threshold(bvals.min(), b0_thr=args.tolerance,
skip_b0_check=args.skip_b0_check,
overwrite_with_min=False)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.tolerance)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=args.tolerance)

# Processing

Expand Down
8 changes: 4 additions & 4 deletions scripts/scil_dti_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def main():
args.b0_threshold = check_b0_threshold(bvals.min(),
b0_thr=args.b0_threshold,
skip_b0_check=args.skip_b0_check)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.b0_threshold)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=args.b0_threshold)

# Processing

Expand All @@ -220,7 +220,7 @@ def main():
tenmodel = TensorModel(gtab, fit_method=args.method,
min_signal=np.min(data[data > 0]))

tenfit = tenmodel.fit(data, mask)
tenfit = tenmodel.fit(data, mask=mask)

# Save all metrics.
if args.tensor:
Expand Down Expand Up @@ -345,12 +345,12 @@ def main():

for i in range(data.shape[0]):
if args.mask is not None:
tenfit2 = tenmodel.fit(data[i, :, :, :], mask[i, :, :])
tenfit2 = tenmodel.fit(data[i, :, :, :], mask=mask[i, :, :])
else:
tenfit2 = tenmodel.fit(data[i, :, :, :])

S0_i = np.maximum(S0[i, :, :], tenfit2.model.min_signal)
tenfit2_predict[i, :, :, :] = tenfit2.predict(gtab, S0_i)
tenfit2_predict[i, :, :, :] = tenfit2.predict(gtab, S0=S0_i)

R, data_diff = compute_residuals(
predicted_data=tenfit2_predict.astype(np.float32),
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_dwi_extract_b0.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def main():
args.b0_threshold = check_b0_threshold(bvals.min(),
b0_thr=args.b0_threshold,
skip_b0_check=args.skip_b0_check)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.b0_threshold)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=args.b0_threshold)
b0_idx = np.where(gtab.b0s_mask)[0]

logger.info('Number of b0 images in the data: {}'.format(len(b0_idx)))
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_dwi_powder_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def main():
len(pwd_avg_idx), shell))

# remove b0 indices
b0_idx = get_bval_indices(bvals, 0, args.b0_thr)
b0_idx = get_bval_indices(bvals, 0, tol=args.b0_thr)
logging.debug('{} b0 volumes detected and not included'.format(
len(b0_idx)))
for val in b0_idx:
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_dwi_to_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
args.b0_threshold = check_b0_threshold(bvals.min(),
b0_thr=args.b0_threshold,
skip_b0_check=args.skip_b0_check)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.b0_threshold)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=args.b0_threshold)

sh_basis, is_legacy = parse_sh_basis_arg(args)

Expand Down
10 changes: 6 additions & 4 deletions scripts/scil_fibertube_score_tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ def main():
our_origin = Origin('center')

logging.debug('Loading centerline tractogram & diameters')
truth_sft = load_tractogram(args.in_fibertubes, 'same', our_space,
our_origin)
truth_sft = load_tractogram(args.in_fibertubes, 'same',
to_space=our_space,
to_origin=our_origin)
centerlines = truth_sft.get_streamlines_copy()
centerlines, centerlines_length = get_streamlines_as_fixed_array(
centerlines)
Expand All @@ -176,8 +177,9 @@ def main():
len(centerlines))

logging.debug('Loading reconstructed tractogram')
in_sft = load_tractogram(args.in_tracking, 'same', our_space,
our_origin)
in_sft = load_tractogram(args.in_tracking, 'same',
to_space=our_space,
to_origin=our_origin)
streamlines = in_sft.get_streamlines_copy()
streamlines, streamlines_length = get_streamlines_as_fixed_array(
streamlines)
Expand Down
4 changes: 3 additions & 1 deletion scripts/scil_fibertube_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def main():
our_origin = Origin('center')

logging.debug('Loading tractogram & diameters')
in_sft = load_tractogram(args.in_fibertubes, 'same', our_space, our_origin)
in_sft = load_tractogram(args.in_fibertubes, 'same',
to_space=our_space,
to_origin=our_origin)
centerlines = list(in_sft.get_streamlines_copy())
diameters = np.reshape(in_sft.data_per_streamline['diameters'],
len(centerlines))
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_fodf_memsmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def main():
wm_frf, gm_frf, csf_frf = verify_frf_files(wm_frf, gm_frf, csf_frf)

# Loading spheres
reg_sphere = get_sphere('symmetric362')
reg_sphere = get_sphere(name='symmetric362')

# Starting main process!

Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_fodf_msmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def main():
_ = check_b0_threshold(bvals.min(), b0_thr=args.tolerance,
skip_b0_check=args.skip_b0_check,
overwrite_with_min=False)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.tolerance)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=args.tolerance)

# Loading spheres
reg_sphere = get_sphere('symmetric362')
reg_sphere = get_sphere(name='symmetric362')

# Starting main process!

Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_fodf_ssst.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def main():
args.b0_threshold = check_b0_threshold(bvals.min(),
b0_thr=args.b0_threshold,
skip_b0_check=args.skip_b0_check)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.b0_threshold)
gtab = gradient_table(bvals, bvecs=bvecs, b0_threshold=args.b0_threshold)

# Checking full_frf and separating it
if not full_frf.shape[0] == 4:
Expand All @@ -115,7 +115,7 @@ def main():
mean_b0_val = full_frf[3]

# Loading the sphere
reg_sphere = get_sphere('symmetric362')
reg_sphere = get_sphere(name='symmetric362')

# Computing CSD
csd_model = ConstrainedSphericalDeconvModel(gtab, (frf, mean_b0_val),
Expand Down
Loading

0 comments on commit 251e9b6

Please sign in to comment.