[BUG]: Correct path propagation logic for ReHoEstimator and ALFFEstimator #286
7 changed files with 50 additions and 22 deletions
1
docs/changes/newsfragments/286.bugfix
Normal file
1
docs/changes/newsfragments/286.bugfix
Normal 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`_
|
||||||
|
|
@ -148,6 +148,9 @@ class ALFFBase(BaseMarker):
|
||||||
|
|
||||||
estimator = ALFFEstimator()
|
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(
|
alff, falff, alff_path, falff_path = estimator.fit_transform(
|
||||||
use_afni=self.use_afni,
|
use_afni=self.use_afni,
|
||||||
input_data=input,
|
input_data=input,
|
||||||
|
|
|
||||||
|
|
@ -308,17 +308,16 @@ class ALFFEstimator:
|
||||||
if use_afni:
|
if use_afni:
|
||||||
# Create new temporary directory before using AFNI
|
# Create new temporary directory before using AFNI
|
||||||
self.temp_dir_path = WorkDirManager().get_tempdir(prefix="falff")
|
self.temp_dir_path = WorkDirManager().get_tempdir(prefix="falff")
|
||||||
output = self._compute_alff_afni(
|
return self._compute_alff_afni(
|
||||||
data=data,
|
data=data,
|
||||||
highpass=highpass,
|
highpass=highpass,
|
||||||
lowpass=lowpass,
|
lowpass=lowpass,
|
||||||
tr=tr,
|
tr=tr,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
output = self._compute_alff_python(
|
return self._compute_alff_python(
|
||||||
data, highpass=highpass, lowpass=lowpass, tr=tr
|
data, highpass=highpass, lowpass=lowpass, tr=tr
|
||||||
)
|
)
|
||||||
return output
|
|
||||||
|
|
||||||
def fit_transform(
|
def fit_transform(
|
||||||
self,
|
self,
|
||||||
|
|
@ -350,16 +349,18 @@ class ALFFEstimator:
|
||||||
Niimg-like object
|
Niimg-like object
|
||||||
fALFF map.
|
fALFF map.
|
||||||
pathlib.Path
|
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
|
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_path = input_data["path"]
|
||||||
bold_data = input_data["data"]
|
bold_data = input_data["data"]
|
||||||
# Clear cache if file path is different from when caching was done
|
# Clear cache if file path is different from when caching was done
|
||||||
if self._file_path != bold_path:
|
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
|
# Clear the cache
|
||||||
self._compute.cache_clear()
|
self._compute.cache_clear()
|
||||||
# Clear temporary directory files
|
# Clear temporary directory files
|
||||||
|
|
@ -368,12 +369,20 @@ class ALFFEstimator:
|
||||||
# Set the new file path
|
# Set the new file path
|
||||||
self._file_path = bold_path
|
self._file_path = bold_path
|
||||||
else:
|
else:
|
||||||
logger.info(f"Using fALFF map cache at {self._file_path}.")
|
logger.info(f"Using fALFF map cache for {self._file_path}.")
|
||||||
# Compute
|
# Compute
|
||||||
return self._compute(
|
alff_map, falff_map, alff_map_path, falff_map_path = self._compute(
|
||||||
use_afni=use_afni,
|
use_afni=use_afni,
|
||||||
data=bold_data,
|
data=bold_data,
|
||||||
highpass=highpass,
|
highpass=highpass,
|
||||||
lowpass=lowpass,
|
lowpass=lowpass,
|
||||||
tr=tr,
|
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
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,8 @@ class ReHoBase(BaseMarker):
|
||||||
Niimg-like object
|
Niimg-like object
|
||||||
The ReHo map as NIfTI.
|
The ReHo map as NIfTI.
|
||||||
pathlib.Path
|
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
|
References
|
||||||
----------
|
----------
|
||||||
|
|
|
||||||
|
|
@ -462,12 +462,9 @@ class ReHoEstimator:
|
||||||
if use_afni:
|
if use_afni:
|
||||||
# Create new temporary directory before using AFNI
|
# Create new temporary directory before using AFNI
|
||||||
self.temp_dir_path = WorkDirManager().get_tempdir(prefix="reho")
|
self.temp_dir_path = WorkDirManager().get_tempdir(prefix="reho")
|
||||||
output, output_path = self._compute_reho_afni(data, **reho_params)
|
return self._compute_reho_afni(data, **reho_params)
|
||||||
else:
|
|
||||||
output, output_path = self._compute_reho_python(
|
return self._compute_reho_python(data, **reho_params)
|
||||||
data, **reho_params
|
|
||||||
)
|
|
||||||
return output, output_path
|
|
||||||
|
|
||||||
def fit_transform(
|
def fit_transform(
|
||||||
self,
|
self,
|
||||||
|
|
@ -491,14 +488,15 @@ class ReHoEstimator:
|
||||||
Niimg-like object
|
Niimg-like object
|
||||||
The ReHo map as NIfTI.
|
The ReHo map as NIfTI.
|
||||||
pathlib.Path
|
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_path = input_data["path"]
|
||||||
bold_data = input_data["data"]
|
bold_data = input_data["data"]
|
||||||
# Clear cache if file path is different from when caching was done
|
# Clear cache if file path is different from when caching was done
|
||||||
if self._file_path != bold_path:
|
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
|
# Clear the cache
|
||||||
self._compute.cache_clear()
|
self._compute.cache_clear()
|
||||||
# Clear temporary directory files
|
# Clear temporary directory files
|
||||||
|
|
@ -507,9 +505,19 @@ class ReHoEstimator:
|
||||||
# Set the new file path
|
# Set the new file path
|
||||||
self._file_path = bold_path
|
self._file_path = bold_path
|
||||||
else:
|
else:
|
||||||
logger.info(f"Using ReHo map cache at {self._file_path}.")
|
logger.info(f"Using ReHo map cache for {self._file_path}.")
|
||||||
# Compute
|
# 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(
|
def _kendall_w_reho(
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,9 @@ class ReHoParcels(ReHoBase):
|
||||||
"""
|
"""
|
||||||
logger.info("Calculating ReHo for parcels.")
|
logger.info("Calculating ReHo for parcels.")
|
||||||
# Calculate reho map
|
# 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:
|
if self.reho_params is not None:
|
||||||
reho_map, reho_file_path = self.compute_reho_map(
|
reho_map, reho_file_path = self.compute_reho_map(
|
||||||
input=input, **self.reho_params
|
input=input, **self.reho_params
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,9 @@ class ReHoSpheres(ReHoBase):
|
||||||
"""
|
"""
|
||||||
logger.info("Calculating ReHo for spheres.")
|
logger.info("Calculating ReHo for spheres.")
|
||||||
# Calculate reho map
|
# 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:
|
if self.reho_params is not None:
|
||||||
reho_map, reho_file_path = self.compute_reho_map(
|
reho_map, reho_file_path = self.compute_reho_map(
|
||||||
input=input, **self.reho_params
|
input=input, **self.reho_params
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue