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

[FIX]: Make native warped components persist #274

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/changes/newsfragments/274.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Store native warped parcellations, coordinates and masks in element-scoped tempdirs for the pipeline to work by `Synchon Mandal`_
21 changes: 13 additions & 8 deletions junifer/data/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
13 changes: 9 additions & 4 deletions junifer/data/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 11 additions & 4 deletions junifer/data/parcellations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion junifer/preprocess/fsl/bold_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BOLDWarper(BasePreprocessor):
] = [
{
"name": "fsl",
"optional": True,
"optional": False,
"commands": ["applywarp"],
},
]
Expand Down
Loading