From fb24eef4f9d0249ac4b1dd14612c774fc7ba8a4c Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 15 Dec 2023 09:14:38 +0100 Subject: [PATCH 1/5] refactor: simplify reho and falff estimator compute returns --- junifer/markers/falff/falff_estimator.py | 11 +++++------ junifer/markers/reho/reho_estimator.py | 9 +++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/junifer/markers/falff/falff_estimator.py b/junifer/markers/falff/falff_estimator.py index c05af4d71..0194a2ab0 100644 --- a/junifer/markers/falff/falff_estimator.py +++ b/junifer/markers/falff/falff_estimator.py @@ -308,17 +308,16 @@ class ALFFEstimator: if use_afni: # Create new temporary directory before using AFNI self.temp_dir_path = WorkDirManager().get_tempdir(prefix="falff") - output = self._compute_alff_afni( + return self._compute_alff_afni( data=data, highpass=highpass, lowpass=lowpass, tr=tr, ) - else: - output = self._compute_alff_python( - data, highpass=highpass, lowpass=lowpass, tr=tr - ) - return output + + return self._compute_alff_python( + data, highpass=highpass, lowpass=lowpass, tr=tr + ) def fit_transform( self, diff --git a/junifer/markers/reho/reho_estimator.py b/junifer/markers/reho/reho_estimator.py index 13eaf0a02..61d9315c9 100644 --- a/junifer/markers/reho/reho_estimator.py +++ b/junifer/markers/reho/reho_estimator.py @@ -462,12 +462,9 @@ class ReHoEstimator: if use_afni: # Create new temporary directory before using AFNI self.temp_dir_path = WorkDirManager().get_tempdir(prefix="reho") - output, output_path = self._compute_reho_afni(data, **reho_params) - else: - output, output_path = self._compute_reho_python( - data, **reho_params - ) - return output, output_path + return self._compute_reho_afni(data, **reho_params) + + return self._compute_reho_python(data, **reho_params) def fit_transform( self, -- 2.52.0 From a694bae87189b37469dab464b5dbc3d28e761056 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 15 Dec 2023 09:15:56 +0100 Subject: [PATCH 2/5] update: pass down input path if input space is native for reho and falff estimators --- junifer/markers/falff/falff_estimator.py | 16 +++++++++++++--- junifer/markers/reho/reho_estimator.py | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/junifer/markers/falff/falff_estimator.py b/junifer/markers/falff/falff_estimator.py index 0194a2ab0..9630068d4 100644 --- a/junifer/markers/falff/falff_estimator.py +++ b/junifer/markers/falff/falff_estimator.py @@ -349,9 +349,11 @@ class ALFFEstimator: Niimg-like object fALFF map. pathlib.Path - The path to the ALFF map as NIfTI. + The path to the ALFF map as NIfTI or the input data path if the + input data space is "native". pathlib.Path - The path to the fALFF map as NIfTI. + The path to the fALFF map as NIfTI or the input data path if the + input data space is "native". """ bold_path = input_data["path"] @@ -369,10 +371,18 @@ class ALFFEstimator: else: logger.info(f"Using fALFF map cache at {self._file_path}.") # Compute - return self._compute( + alff_map, falff_map, alff_map_path, falff_map_path = self._compute( use_afni=use_afni, data=bold_data, highpass=highpass, lowpass=lowpass, tr=tr, ) + # If the input data space is native already, the original path should + # be propagated down as it might be required for transforming + # coordinates to native space via get_coordinates(), else the alff + # / falff map path should be passed for use later if required. + if input_data["space"] == "native": + return alff_map, falff_map, input_data["path"], input_data["path"] + + return alff_map, falff_map, alff_map_path, falff_map_path diff --git a/junifer/markers/reho/reho_estimator.py b/junifer/markers/reho/reho_estimator.py index 61d9315c9..37d2ee2fe 100644 --- a/junifer/markers/reho/reho_estimator.py +++ b/junifer/markers/reho/reho_estimator.py @@ -488,7 +488,8 @@ class ReHoEstimator: Niimg-like object The ReHo map as NIfTI. pathlib.Path - The path to the ReHo map as NIfTI. + The path to the ReHo map as NIfTI or the input data path if the + input data space is "native". """ bold_path = input_data["path"] @@ -506,7 +507,17 @@ class ReHoEstimator: else: logger.info(f"Using ReHo map cache at {self._file_path}.") # Compute - return self._compute(use_afni, bold_data, **reho_params) + reho_map, reho_map_path = self._compute( + use_afni, bold_data, **reho_params + ) + # If the input data space is native already, the original path should + # be propagated down as it might be required for transforming + # coordinates to native space via get_coordinates(), else the reho map + # path should be passed for use later if required. + if input_data["space"] == "native": + return reho_map, input_data["path"] + + return reho_map, reho_map_path def _kendall_w_reho( -- 2.52.0 From c24513c258e2245b914d84071e9819614af03730 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 15 Dec 2023 09:19:29 +0100 Subject: [PATCH 3/5] chore: add commentary for path propagation caveat for reho and falff estimators --- junifer/markers/falff/falff_base.py | 3 +++ junifer/markers/reho/reho_base.py | 3 ++- junifer/markers/reho/reho_parcels.py | 3 +++ junifer/markers/reho/reho_spheres.py | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/junifer/markers/falff/falff_base.py b/junifer/markers/falff/falff_base.py index 49d08bc82..d22dd7f72 100644 --- a/junifer/markers/falff/falff_base.py +++ b/junifer/markers/falff/falff_base.py @@ -148,6 +148,9 @@ class ALFFBase(BaseMarker): estimator = ALFFEstimator() + # If the input data space is "native", then alff_path and falff_path + # both point to the input data path as it might be required to use + # in get_corrdinates() for transforming coordinates to native space. alff, falff, alff_path, falff_path = estimator.fit_transform( use_afni=self.use_afni, input_data=input, diff --git a/junifer/markers/reho/reho_base.py b/junifer/markers/reho/reho_base.py index c089dfdef..fc9b51ba4 100644 --- a/junifer/markers/reho/reho_base.py +++ b/junifer/markers/reho/reho_base.py @@ -110,7 +110,8 @@ class ReHoBase(BaseMarker): Niimg-like object The ReHo map as NIfTI. pathlib.Path - The path to the ReHo map as NIfTI. + The path to the ReHo map as NIfTI or the input data path if the + input data space is "native". References ---------- diff --git a/junifer/markers/reho/reho_parcels.py b/junifer/markers/reho/reho_parcels.py index 8fcb0dc78..b3f1133d1 100644 --- a/junifer/markers/reho/reho_parcels.py +++ b/junifer/markers/reho/reho_parcels.py @@ -127,6 +127,9 @@ class ReHoParcels(ReHoBase): """ logger.info("Calculating ReHo for parcels.") # Calculate reho map + # If the input data space is "native", then reho_file_path points to + # the input data path as it might be required to use in + # get_coordinates() for transforming coordinates to native space. if self.reho_params is not None: reho_map, reho_file_path = self.compute_reho_map( input=input, **self.reho_params diff --git a/junifer/markers/reho/reho_spheres.py b/junifer/markers/reho/reho_spheres.py index cb08e165e..73faaaaed 100644 --- a/junifer/markers/reho/reho_spheres.py +++ b/junifer/markers/reho/reho_spheres.py @@ -139,6 +139,9 @@ class ReHoSpheres(ReHoBase): """ logger.info("Calculating ReHo for spheres.") # Calculate reho map + # If the input data space is "native", then reho_file_path points to + # the input data path as it might be required to use in + # get_coordinates() for transforming coordinates to native space. if self.reho_params is not None: reho_map, reho_file_path = self.compute_reho_map( input=input, **self.reho_params -- 2.52.0 From 27ea781e86a2d2e2ac6b5ad866d4eb511e791c36 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 15 Dec 2023 09:20:37 +0100 Subject: [PATCH 4/5] chore: improve logging messages for reho and falff estimators --- junifer/markers/falff/falff_estimator.py | 4 ++-- junifer/markers/reho/reho_estimator.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/junifer/markers/falff/falff_estimator.py b/junifer/markers/falff/falff_estimator.py index 9630068d4..7105a4f03 100644 --- a/junifer/markers/falff/falff_estimator.py +++ b/junifer/markers/falff/falff_estimator.py @@ -360,7 +360,7 @@ class ALFFEstimator: bold_data = input_data["data"] # Clear cache if file path is different from when caching was done if self._file_path != bold_path: - logger.info(f"Removing fALFF map cache at {self._file_path}.") + logger.info(f"Removing fALFF map cache for {self._file_path}.") # Clear the cache self._compute.cache_clear() # Clear temporary directory files @@ -369,7 +369,7 @@ class ALFFEstimator: # Set the new file path self._file_path = bold_path else: - logger.info(f"Using fALFF map cache at {self._file_path}.") + logger.info(f"Using fALFF map cache for {self._file_path}.") # Compute alff_map, falff_map, alff_map_path, falff_map_path = self._compute( use_afni=use_afni, diff --git a/junifer/markers/reho/reho_estimator.py b/junifer/markers/reho/reho_estimator.py index 37d2ee2fe..82aaea806 100644 --- a/junifer/markers/reho/reho_estimator.py +++ b/junifer/markers/reho/reho_estimator.py @@ -496,7 +496,7 @@ class ReHoEstimator: bold_data = input_data["data"] # Clear cache if file path is different from when caching was done if self._file_path != bold_path: - logger.info(f"Removing ReHo map cache at {self._file_path}.") + logger.info(f"Removing ReHo map cache for {self._file_path}.") # Clear the cache self._compute.cache_clear() # Clear temporary directory files @@ -505,7 +505,7 @@ class ReHoEstimator: # Set the new file path self._file_path = bold_path else: - logger.info(f"Using ReHo map cache at {self._file_path}.") + logger.info(f"Using ReHo map cache for {self._file_path}.") # Compute reho_map, reho_map_path = self._compute( use_afni, bold_data, **reho_params -- 2.52.0 From 210d83a56af955353c760ae30208042bccbfb749 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Fri, 15 Dec 2023 09:27:59 +0100 Subject: [PATCH 5/5] chore: add changelog 286.bugfix --- docs/changes/newsfragments/286.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/286.bugfix diff --git a/docs/changes/newsfragments/286.bugfix b/docs/changes/newsfragments/286.bugfix new file mode 100644 index 000000000..302c07dfc --- /dev/null +++ b/docs/changes/newsfragments/286.bugfix @@ -0,0 +1 @@ +Pass down input path if input space is "native" for ``ReHoEstimator`` and ``ALFFEstimator``, else use respective compute maps by `Fede Raimondo`_ and `Synchon Mandal`_ -- 2.52.0