[FIX]: Make native warped components persist #274

Merged
synchon merged 5 commits from fix/nibabel-cache-bypass into main 2023-11-07 14:47:03 +00:00
5 changed files with 35 additions and 17 deletions

View file

@ -0,0 +1 @@
Store native warped parcellations, coordinates and masks in element-scoped tempdirs for the pipeline to work by `Synchon Mandal`_

View file

@ -240,24 +240,31 @@ def get_coordinates(
f"{target_data['space']} space for further computation."
)
# Create tempdir
# Create component-scoped tempdir
tempdir = WorkDirManager().get_tempdir(prefix="coordinates")
# Save existing coordinates
# Save existing coordinates to a component-scoped tempfile
pretransform_coordinates_path = (
tempdir / "pretransform_coordinates.txt"
)
np.savetxt(pretransform_coordinates_path, seeds)
# Create a tempfile for transformed coordinates output
std2imgcoord_out_path = tempdir / "coordinates_transformed.txt"
# Create element-scoped tempdir so that transformed coordinates is
# available later as numpy stores file path reference for
# loading on computation
element_tempdir = WorkDirManager().get_element_tempdir(
prefix="coordinates"
)
# Create an element-scoped tempfile for transformed coordinates output
std2imgcoord_out_path = element_tempdir / "coordinates_transformed.txt"
# Set std2imgcoord command
std2imgcoord_cmd = [
"std2imgcoord",
f"-img {target_data['reference_path'].resolve()}",
f"-warp {extra_input['Warp']['path'].resolve()}",
f"{pretransform_coordinates_path}",
f"> {std2imgcoord_out_path}",
f"{pretransform_coordinates_path.resolve()}",
f"> {std2imgcoord_out_path.resolve()}",
]
# Call std2imgcoord
std2imgcoord_cmd_str = " ".join(std2imgcoord_cmd)
@ -272,8 +279,6 @@ def get_coordinates(
shell=True, # needed for respecting $PATH
check=False,
)
# Delete saved coordinates file
pretransform_coordinates_path.unlink()
# Check for success or failure
if std2imgcoord_process.returncode == 0:
logger.info(

View file

@ -344,15 +344,20 @@ def get_mask( # noqa: C901
f"{target_data['space']} space for further computation."
)
# Create tempdir
# Create component-scoped tempdir
tempdir = WorkDirManager().get_tempdir(prefix="masks")
# Save mask image
# Save mask image to a component-scoped tempfile
prewarp_mask_path = tempdir / "prewarp_mask.nii.gz"
nib.save(mask_img, prewarp_mask_path)
# Create a tempfile for warped output
applywarp_out_path = tempdir / "mask_warped.nii.gz"
# Create element-scoped tempdir so that warped mask is
# available later as nibabel stores file path reference for
# loading on computation
element_tempdir = WorkDirManager().get_element_tempdir(prefix="masks")
# Create an element-scoped tempfile for warped output
applywarp_out_path = element_tempdir / "mask_warped.nii.gz"
# Set applywarp command
applywarp_cmd = [
"applywarp",

View file

@ -289,15 +289,22 @@ def get_parcellation(
f"{target_data['space']} space for further computation."
)
# Create tempdir
# Create component-scoped tempdir
tempdir = WorkDirManager().get_tempdir(prefix="parcellations")
# Save parcellation image
# Save parcellation image to a component-scoped tempfile
prewarp_parcellation_path = tempdir / "prewarp_parcellation.nii.gz"
nib.save(resampled_parcellation_img, prewarp_parcellation_path)
# Create a tempfile for warped output
applywarp_out_path = tempdir / "parcellation_warped.nii.gz"
# Create element-scoped tempdir so that warped parcellation is
# available later as nibabel stores file path reference for
# loading on computation
element_tempdir = WorkDirManager().get_element_tempdir(
prefix="parcellations"
)
# Create an element-scoped tempfile for warped output
applywarp_out_path = element_tempdir / "parcellation_warped.nii.gz"
# Set applywarp command
applywarp_cmd = [
"applywarp",

View file

@ -35,7 +35,7 @@ class BOLDWarper(BasePreprocessor):
] = [
{
"name": "fsl",
"optional": True,
"optional": False,
"commands": ["applywarp"],
},
]