[FIX]: Make native warped components persist #274
5 changed files with 35 additions and 17 deletions
1
docs/changes/newsfragments/274.bugfix
Normal file
1
docs/changes/newsfragments/274.bugfix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Store native warped parcellations, coordinates and masks in element-scoped tempdirs for the pipeline to work by `Synchon Mandal`_
|
||||||
|
|
@ -240,24 +240,31 @@ def get_coordinates(
|
||||||
f"{target_data['space']} space for further computation."
|
f"{target_data['space']} space for further computation."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create tempdir
|
# Create component-scoped tempdir
|
||||||
tempdir = WorkDirManager().get_tempdir(prefix="coordinates")
|
tempdir = WorkDirManager().get_tempdir(prefix="coordinates")
|
||||||
|
|
||||||
# Save existing coordinates
|
# Save existing coordinates to a component-scoped tempfile
|
||||||
pretransform_coordinates_path = (
|
pretransform_coordinates_path = (
|
||||||
tempdir / "pretransform_coordinates.txt"
|
tempdir / "pretransform_coordinates.txt"
|
||||||
)
|
)
|
||||||
np.savetxt(pretransform_coordinates_path, seeds)
|
np.savetxt(pretransform_coordinates_path, seeds)
|
||||||
|
|
||||||
# Create a tempfile for transformed coordinates output
|
# Create element-scoped tempdir so that transformed coordinates is
|
||||||
std2imgcoord_out_path = tempdir / "coordinates_transformed.txt"
|
# 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
|
# Set std2imgcoord command
|
||||||
std2imgcoord_cmd = [
|
std2imgcoord_cmd = [
|
||||||
"std2imgcoord",
|
"std2imgcoord",
|
||||||
f"-img {target_data['reference_path'].resolve()}",
|
f"-img {target_data['reference_path'].resolve()}",
|
||||||
f"-warp {extra_input['Warp']['path'].resolve()}",
|
f"-warp {extra_input['Warp']['path'].resolve()}",
|
||||||
f"{pretransform_coordinates_path}",
|
f"{pretransform_coordinates_path.resolve()}",
|
||||||
f"> {std2imgcoord_out_path}",
|
f"> {std2imgcoord_out_path.resolve()}",
|
||||||
]
|
]
|
||||||
# Call std2imgcoord
|
# Call std2imgcoord
|
||||||
std2imgcoord_cmd_str = " ".join(std2imgcoord_cmd)
|
std2imgcoord_cmd_str = " ".join(std2imgcoord_cmd)
|
||||||
|
|
@ -272,8 +279,6 @@ def get_coordinates(
|
||||||
shell=True, # needed for respecting $PATH
|
shell=True, # needed for respecting $PATH
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
# Delete saved coordinates file
|
|
||||||
pretransform_coordinates_path.unlink()
|
|
||||||
# Check for success or failure
|
# Check for success or failure
|
||||||
if std2imgcoord_process.returncode == 0:
|
if std2imgcoord_process.returncode == 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
|
||||||
|
|
@ -344,15 +344,20 @@ def get_mask( # noqa: C901
|
||||||
f"{target_data['space']} space for further computation."
|
f"{target_data['space']} space for further computation."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create tempdir
|
# Create component-scoped tempdir
|
||||||
tempdir = WorkDirManager().get_tempdir(prefix="masks")
|
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"
|
prewarp_mask_path = tempdir / "prewarp_mask.nii.gz"
|
||||||
nib.save(mask_img, prewarp_mask_path)
|
nib.save(mask_img, prewarp_mask_path)
|
||||||
|
|
||||||
# Create a tempfile for warped output
|
# Create element-scoped tempdir so that warped mask is
|
||||||
applywarp_out_path = tempdir / "mask_warped.nii.gz"
|
# 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
|
# Set applywarp command
|
||||||
applywarp_cmd = [
|
applywarp_cmd = [
|
||||||
"applywarp",
|
"applywarp",
|
||||||
|
|
|
||||||
|
|
@ -289,15 +289,22 @@ def get_parcellation(
|
||||||
f"{target_data['space']} space for further computation."
|
f"{target_data['space']} space for further computation."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create tempdir
|
# Create component-scoped tempdir
|
||||||
tempdir = WorkDirManager().get_tempdir(prefix="parcellations")
|
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"
|
prewarp_parcellation_path = tempdir / "prewarp_parcellation.nii.gz"
|
||||||
nib.save(resampled_parcellation_img, prewarp_parcellation_path)
|
nib.save(resampled_parcellation_img, prewarp_parcellation_path)
|
||||||
|
|
||||||
# Create a tempfile for warped output
|
# Create element-scoped tempdir so that warped parcellation is
|
||||||
applywarp_out_path = tempdir / "parcellation_warped.nii.gz"
|
# 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
|
# Set applywarp command
|
||||||
applywarp_cmd = [
|
applywarp_cmd = [
|
||||||
"applywarp",
|
"applywarp",
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class BOLDWarper(BasePreprocessor):
|
||||||
] = [
|
] = [
|
||||||
{
|
{
|
||||||
"name": "fsl",
|
"name": "fsl",
|
||||||
"optional": True,
|
"optional": False,
|
||||||
"commands": ["applywarp"],
|
"commands": ["applywarp"],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue