Skip to content
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

WIP: Bval error check #1133

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions AFQ/api/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from AFQ.utils.path import apply_cmd_to_afq_derivs
from AFQ.viz.utils import BEST_BUNDLE_ORIENTATIONS, trim, get_eye

from AFQ.definitions.image import ScalarImage
import dipy.core.gradients as dpg


__all__ = ["ParticipantAFQ"]

Expand Down Expand Up @@ -98,6 +101,58 @@ def __init__(self,
self.logger = logging.getLogger('AFQ')
self.output_dir = output_dir

"""
bmag : int
From dipy.core.gradients:
The order of magnitude that the bvalues have to differ to be
considered an unique b-value. B-values are also rounded up to
this order of magnitude. Default: derive this value from the
maximal b-value provided: $bmag=log_{10}(max(bvals)) - 1$.
"""

if "bmag" not in kwargs:
kwargs.bmag = None

gtab = dpg.gradient_table(bval_file, bvec_file)
unique_bvals = dpg.unique_bvals_magnitude(gtab.bvals, kwargs.bmag)

if len(unique_bvals) < 3:
if "scalars" in kwargs:
for ii, scalar in enumerate(kwargs["scalars"]):
if scalar == "dki_fa":
# kwargs["scalars"][ii] = "dti_fa"
# self.logger.info("Not enough bvals, dki -> dti")
raise ValueError("Not enough bvals for dki_fa")
if scalar == "dki_md":
# kwargs["scalars"][ii] = "dti_md"
# self.logger.info("Not enough bvals, dki -> dti")
raise ValueError("Not enough bvals for dki_md")
if "tracking_params" in kwargs:
if "seed_mask" in kwargs["tracking_params"]:
seed_mask = kwargs["tracking_params"]["seed_mask"]
if seed_mask == ScalarImage("dki_fa"):
# kwargs["tracking_params"]["seed_mask"] = \
# ScalarImage("dti_fa")
# self.logger.info("Not enough bvals, dki -> dti")
raise ValueError("Not enough bvals for dki_fa")
if seed_mask == ScalarImage("dki_md"):
# kwargs["tracking_params"]["seed_mask"] = \
# ScalarImage("dti_md")
# self.logger.info("Not enough bvals, dki -> dti")
raise ValueError("Not enough bvals for dki_md")
if "stop_mask" in kwargs["tracking_params"]:
stop_mask = kwargs["tracking_params"]["stop_mask"]
if stop_mask == ScalarImage("dki_fa"):
# kwargs["tracking_params"]["stop_mask"] = \
# ScalarImage("dti_fa")
# self.logger.info("Not enough bvals, dki -> dti")
raise ValueError("Not enough bvals for dki_fa")
if stop_mask == ScalarImage("dki_md"):
# kwargs["tracking_params"]["stop_mask"] = \
# ScalarImage("dti_md")
# self.logger.info("Not enough bvals, dki -> dti")
raise ValueError("Not enough bvals for dki_md")

self.kwargs = dict(
dwi_path=dwi_data_file,
bval=bval_file,
Expand Down