[BUG]: compute_brain_mask fails to find Warp object #394
3 changed files with 9 additions and 20 deletions
1
docs/changes/newsfragments/394.bugfix
Normal file
1
docs/changes/newsfragments/394.bugfix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Refactor ``compute_brain_mask``'s interface and internals to not fail during native space warping by `Synchon Mandal`_
|
||||||
|
|
@ -47,7 +47,6 @@ _masks_path = Path(__file__).parent
|
||||||
|
|
||||||
def compute_brain_mask(
|
def compute_brain_mask(
|
||||||
target_data: Dict[str, Any],
|
target_data: Dict[str, Any],
|
||||||
extra_input: Optional[Dict[str, Any]] = None,
|
|
||||||
mask_type: str = "brain",
|
mask_type: str = "brain",
|
||||||
threshold: float = 0.5,
|
threshold: float = 0.5,
|
||||||
) -> "Nifti1Image":
|
) -> "Nifti1Image":
|
||||||
|
|
@ -61,9 +60,6 @@ def compute_brain_mask(
|
||||||
target_data : dict
|
target_data : dict
|
||||||
The corresponding item of the data object for which mask will be
|
The corresponding item of the data object for which mask will be
|
||||||
loaded.
|
loaded.
|
||||||
extra_input : dict, optional
|
|
||||||
The other fields in the data object. Useful for accessing other data
|
|
||||||
types (default None).
|
|
||||||
mask_type : {"brain", "gm", "wm"}, optional
|
mask_type : {"brain", "gm", "wm"}, optional
|
||||||
Type of mask to be computed:
|
Type of mask to be computed:
|
||||||
|
|
||||||
|
|
@ -94,26 +90,19 @@ def compute_brain_mask(
|
||||||
|
|
||||||
# Check pre-requirements for space manipulation
|
# Check pre-requirements for space manipulation
|
||||||
target_space = target_data["space"]
|
target_space = target_data["space"]
|
||||||
# Set target standard space to target space
|
# Conditional for native space-warped target data
|
||||||
target_std_space = target_space
|
|
||||||
# Extra data type requirement check if target space is native
|
|
||||||
if target_space == "native":
|
if target_space == "native":
|
||||||
# Check for extra inputs
|
# prewarp_space is added in SpaceWarper and should be there
|
||||||
if extra_input is None:
|
target_std_space = target_data["prewarp_space"]
|
||||||
raise_error(
|
else:
|
||||||
"No extra input provided, requires `Warp` "
|
# Set target standard space to target space
|
||||||
"data type to infer target template space."
|
target_std_space = target_space
|
||||||
)
|
|
||||||
# Set target standard space to warp file space source
|
|
||||||
for entry in extra_input["Warp"]:
|
|
||||||
if entry["dst"] == "native":
|
|
||||||
target_std_space = entry["src"]
|
|
||||||
|
|
||||||
# Fetch template in closest resolution
|
# Fetch template in closest resolution
|
||||||
template = get_template(
|
template = get_template(
|
||||||
space=target_std_space,
|
space=target_std_space,
|
||||||
target_data=target_data,
|
target_data=target_data,
|
||||||
extra_input=extra_input,
|
extra_input=None,
|
||||||
template_type=mask_type,
|
template_type=mask_type,
|
||||||
)
|
)
|
||||||
# Resample template to target image
|
# Resample template to target image
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,8 @@ def test_compute_brain_mask(mask_type: str, threshold: float) -> None:
|
||||||
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
||||||
mask = compute_brain_mask(
|
mask = compute_brain_mask(
|
||||||
target_data=element_data["BOLD"],
|
target_data=element_data["BOLD"],
|
||||||
extra_input=None,
|
|
||||||
mask_type=mask_type,
|
mask_type=mask_type,
|
||||||
|
threshold=threshold,
|
||||||
)
|
)
|
||||||
assert isinstance(mask, nib.nifti1.Nifti1Image)
|
assert isinstance(mask, nib.nifti1.Nifti1Image)
|
||||||
|
|
||||||
|
|
@ -104,7 +104,6 @@ def test_compute_brain_mask_for_native(mask_type: str) -> None:
|
||||||
)
|
)
|
||||||
mask = compute_brain_mask(
|
mask = compute_brain_mask(
|
||||||
target_data=element_data["BOLD"],
|
target_data=element_data["BOLD"],
|
||||||
extra_input=None,
|
|
||||||
mask_type=mask_type,
|
mask_type=mask_type,
|
||||||
)
|
)
|
||||||
assert isinstance(mask, nib.nifti1.Nifti1Image)
|
assert isinstance(mask, nib.nifti1.Nifti1Image)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue