-
Notifications
You must be signed in to change notification settings - Fork 24
[ENH] Add emc helper functions - vectors #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
5f51f9d
e4e8f82
47fe0e9
f5ca8c1
66f8b48
7e1b11e
8b365f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,3 +375,58 @@ def bvecs2ras(affine, bvecs, norm=True, bvec_norm_epsilon=0.2): | |
rotated_bvecs[~b0s] /= norms_bvecs[~b0s, np.newaxis] | ||
rotated_bvecs[b0s] = np.zeros(3) | ||
return rotated_bvecs | ||
|
||
|
||
def _nonoverlapping_qspace_samples( | ||
prediction_bval, prediction_bvec, all_bvals, all_bvecs, cutoff | ||
): | ||
"""Ensure that none of the training samples are too close to the sample to predict. | ||
Parameters | ||
dPys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
dPys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
min_bval = min(min(all_bvals), prediction_bval) | ||
all_qvals = np.sqrt(all_bvals - min_bval) | ||
prediction_qval = np.sqrt(prediction_bval - min_bval) | ||
|
||
# Convert q values to percent of maximum qval | ||
max_qval = max(max(all_qvals), prediction_qval) | ||
all_qvals_scaled = all_qvals / max_qval * 100 | ||
scaled_qvecs = all_bvecs * all_qvals_scaled[:, np.newaxis] | ||
scaled_prediction_qvec = prediction_bvec * (prediction_qval / max_qval * 100) | ||
|
||
# Calculate the distance between the sampled qvecs and the prediction qvec | ||
ok_samples = ( | ||
np.linalg.norm(scaled_qvecs - scaled_prediction_qvec, axis=1) > cutoff | ||
) * (np.linalg.norm(scaled_qvecs + scaled_prediction_qvec, axis=1) > cutoff) | ||
|
||
return ok_samples | ||
|
||
|
||
def _rasb_to_bvec_list(in_rasb): | ||
""" | ||
Create a list of b-vectors from a rasb gradient table. | ||
|
||
Parameters | ||
---------- | ||
in_rasb : str or os.pathlike | ||
File path to a RAS-B gradient table. | ||
""" | ||
dPys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import numpy as np | ||
|
||
ras_b_mat = np.genfromtxt(in_rasb, delimiter="\t") | ||
bvec = [vec for vec in ras_b_mat[:, 0:3] if not np.isclose(all(vec), 0)] | ||
return list(bvec) | ||
|
||
|
||
def _rasb_to_bval_floats(in_rasb): | ||
""" | ||
Create a list of b-values from a rasb gradient table. | ||
|
||
Parameters | ||
---------- | ||
in_rasb : str or os.pathlike | ||
File path to a RAS-B gradient table. | ||
""" | ||
import numpy as np | ||
|
||
ras_b_mat = np.genfromtxt(in_rasb, delimiter="\t") | ||
return [float(bval) for bval in ras_b_mat[:, 3] if bval > 0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you point me at the location where these are needed? I believe our Gradients class has already this covered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oesteban -- These are all used in signal prediction See: https://github.com/nipreps/dmriprep/pull/62/files#diff-4fa7776741ad932fa7371fd581572c12R176-R322 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (and not covered in Gradients class) |
Uh oh!
There was an error while loading. Please reload this page.