[BUG]: Correct path propagation logic for ReHoEstimator and ALFFEstimator #286

Merged
synchon merged 5 commits from fix/reho-falff-path-propagation-native into main 2023-12-22 12:26:10 +00:00
7 changed files with 50 additions and 22 deletions

View file

@ -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`_

View file

@ -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,

View file

@ -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(
return self._compute_alff_python(
data, highpass=highpass, lowpass=lowpass, tr=tr
)
return output
def fit_transform(
self,
@ -350,16 +349,18 @@ 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"]
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
@ -368,12 +369,20 @@ 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
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

View file

@ -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
----------

View file

@ -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,
@ -491,14 +488,15 @@ 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"]
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
@ -507,9 +505,19 @@ 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
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(

View file

@ -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

View file

@ -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