@@ -377,30 +377,56 @@ def bvecs2ras(affine, bvecs, norm=True, bvec_norm_epsilon=0.2):
377
377
return rotated_bvecs
378
378
379
379
380
- def reorient_bvecs_from_ras_b (ras_b , affines ):
380
+ def _nonoverlapping_qspace_samples (
381
+ prediction_bval , prediction_bvec , all_bvals , all_bvecs , cutoff
382
+ ):
383
+ """Ensure that none of the training samples are too close to the sample to predict.
384
+ Parameters
385
+ """
386
+ min_bval = min (min (all_bvals ), prediction_bval )
387
+ all_qvals = np .sqrt (all_bvals - min_bval )
388
+ prediction_qval = np .sqrt (prediction_bval - min_bval )
389
+
390
+ # Convert q values to percent of maximum qval
391
+ max_qval = max (max (all_qvals ), prediction_qval )
392
+ all_qvals_scaled = all_qvals / max_qval * 100
393
+ scaled_qvecs = all_bvecs * all_qvals_scaled [:, np .newaxis ]
394
+ scaled_prediction_qvec = prediction_bvec * (prediction_qval / max_qval * 100 )
395
+
396
+ # Calculate the distance between the sampled qvecs and the prediction qvec
397
+ ok_samples = (
398
+ np .linalg .norm (scaled_qvecs - scaled_prediction_qvec , axis = 1 ) > cutoff
399
+ ) * (np .linalg .norm (scaled_qvecs + scaled_prediction_qvec , axis = 1 ) > cutoff )
400
+
401
+ return ok_samples
402
+
403
+
404
+ def _rasb_to_bvec_list (in_rasb ):
381
405
"""
382
- Reorient the vectors from a rasb .tsv file.
383
- When correcting for motion, rotation of the diffusion-weighted volumes
384
- might cause systematic bias in rotationally invariant measures, such as FA
385
- and MD, and also cause characteristic biases in tractography, unless the
386
- gradient directions are appropriately reoriented to compensate for this
387
- effect [Leemans2009]_.
406
+ Create a list of b-vectors from a rasb gradient table.
388
407
389
408
Parameters
390
409
----------
391
- rasb_file : str or os.pathlike
392
- File path to a RAS-B gradient table. If rasb_file is provided,
393
- then bvecs and bvals will be dismissed.
394
-
395
- affines : list or ndarray of shape (n, 4, 4) or (n, 3, 3)
396
- Each entry in this list or array contain either an affine
397
- transformation (4,4) or a rotation matrix (3, 3).
398
- In both cases, the transformations encode the rotation that was applied
399
- to the image corresponding to one of the non-zero gradient directions.
410
+ in_rasb : str or os.pathlike
411
+ File path to a RAS-B gradient table.
400
412
"""
401
- from dipy . core . gradients import gradient_table_from_bvals_bvecs , reorient_bvecs
413
+ import numpy as np
402
414
403
- ras_b_mat = np .genfromtxt (ras_b , delimiter = '\t ' )
404
- gt = gradient_table_from_bvals_bvecs (ras_b_mat [:,3 ], ras_b_mat [:,0 :3 ], b0_threshold = 50 )
415
+ ras_b_mat = np .genfromtxt (in_rasb , delimiter = "\t " )
416
+ bvec = [vec for vec in ras_b_mat [:, 0 :3 ] if not np .isclose (all (vec ), 0 )]
417
+ return list (bvec )
418
+
419
+
420
+ def _rasb_to_bval_floats (in_rasb ):
421
+ """
422
+ Create a list of b-values from a rasb gradient table.
423
+
424
+ Parameters
425
+ ----------
426
+ in_rasb : str or os.pathlike
427
+ File path to a RAS-B gradient table.
428
+ """
429
+ import numpy as np
405
430
406
- return reorient_bvecs (gt , affines )
431
+ ras_b_mat = np .genfromtxt (in_rasb , delimiter = "\t " )
432
+ return [float (bval ) for bval in ras_b_mat [:, 3 ] if bval > 0 ]
0 commit comments