From 039fb2cbdfc2769a6884330f960f6f24e8d56e8b Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 7 Nov 2023 14:19:02 +0100 Subject: [PATCH 1/5] fix: make applywarp compulsory for BOLDWarper _EXT_DEPENDENCIES --- junifer/preprocess/fsl/bold_warper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junifer/preprocess/fsl/bold_warper.py b/junifer/preprocess/fsl/bold_warper.py index 63d1c20a4d..e5993c0996 100644 --- a/junifer/preprocess/fsl/bold_warper.py +++ b/junifer/preprocess/fsl/bold_warper.py @@ -35,7 +35,7 @@ class BOLDWarper(BasePreprocessor): ] = [ { "name": "fsl", - "optional": True, + "optional": False, "commands": ["applywarp"], }, ] From 9f2f5706cbaec1242f0dd92f642dd343b77cde57 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 7 Nov 2023 14:20:13 +0100 Subject: [PATCH 2/5] update: make warped native parcellation persist by having it in element-scoped tempfile --- junifer/data/parcellations.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/junifer/data/parcellations.py b/junifer/data/parcellations.py index 25b690691d..d34ac08a95 100644 --- a/junifer/data/parcellations.py +++ b/junifer/data/parcellations.py @@ -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", From 00cc42a7c0dbb8745da3cae3737e53af31fe6562 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 7 Nov 2023 14:21:08 +0100 Subject: [PATCH 3/5] update: make warped native coordinates persist by having it in element-scoped tempfile --- junifer/data/coordinates.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/junifer/data/coordinates.py b/junifer/data/coordinates.py index 9bd903fa2b..f27b5a8e9a 100644 --- a/junifer/data/coordinates.py +++ b/junifer/data/coordinates.py @@ -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( From 8472167f1bca12f59d2f178f81eee3bde9df87f5 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 7 Nov 2023 14:22:04 +0100 Subject: [PATCH 4/5] update: make warped native mask persist by having it in element-scoped tempfile --- junifer/data/masks.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/junifer/data/masks.py b/junifer/data/masks.py index 2837130cc8..b96e18b044 100644 --- a/junifer/data/masks.py +++ b/junifer/data/masks.py @@ -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", From c507cfc1e6e89a09994ec87dcc1ecc5bbc87c9dd Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 7 Nov 2023 14:28:26 +0100 Subject: [PATCH 5/5] chore: add changelog 274.bugfix --- docs/changes/newsfragments/274.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/274.bugfix diff --git a/docs/changes/newsfragments/274.bugfix b/docs/changes/newsfragments/274.bugfix new file mode 100644 index 0000000000..1ae09259fb --- /dev/null +++ b/docs/changes/newsfragments/274.bugfix @@ -0,0 +1 @@ +Store native warped parcellations, coordinates and masks in element-scoped tempdirs for the pipeline to work by `Synchon Mandal`_