From eef5488c65ce2bb4fcd88434ca2a0315cb05f487 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Tue, 14 Mar 2023 22:28:09 +0100 Subject: [PATCH 1/2] Add extra_input to reho/falff --- junifer/markers/falff/falff_base.py | 15 +++++++++++---- junifer/markers/falff/falff_parcels.py | 9 ++++++--- junifer/markers/falff/falff_spheres.py | 11 +++++++---- junifer/markers/reho/reho_parcels.py | 5 ++++- junifer/markers/reho/reho_spheres.py | 4 +++- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/junifer/markers/falff/falff_base.py b/junifer/markers/falff/falff_base.py index fe8ed478b..d3c889313 100644 --- a/junifer/markers/falff/falff_base.py +++ b/junifer/markers/falff/falff_base.py @@ -61,8 +61,8 @@ class AmplitudeLowFrequencyFluctuationBase(BaseMarker): use_afni: Optional[bool] = None, name: Optional[str] = None, ) -> None: - if highpass <= 0: - raise_error("Highpass must be positive") + if highpass < 0: + raise_error("Highpass must be positive or 0") if lowpass <= 0: raise_error("Lowpass must be positive") if highpass >= lowpass: @@ -160,18 +160,25 @@ class AmplitudeLowFrequencyFluctuationBase(BaseMarker): "path": None, } - out = self._postprocess(post_input) + out = self._postprocess(post_input, extra_input=extra_input) return out @abstractmethod - def _postprocess(self, input: Dict) -> Dict: + def _postprocess( + self, input: Dict, extra_input: Optional[Dict] = None + ) -> Dict: """Postprocess the output of the estimator. Parameters ---------- input : dict The output of the estimator. It must have the following + extra_input : dict, optional + The other fields in the pipeline data object. Useful for accessing + other data kind that needs to be used in the computation. For + example, the functional connectivity markers can make use of the + confounds if available (default None). """ raise_error( "_postprocess must be implemented", klass=NotImplementedError diff --git a/junifer/markers/falff/falff_parcels.py b/junifer/markers/falff/falff_parcels.py index 4dd518d0f..764731bab 100644 --- a/junifer/markers/falff/falff_parcels.py +++ b/junifer/markers/falff/falff_parcels.py @@ -26,7 +26,8 @@ class AmplitudeLowFrequencyFluctuationParcels( fractional : bool Whether to compute fractional ALFF. highpass : positive float, optional - The highpass cutoff frequency for the bandpass filter (default 0.01). + The highpass cutoff frequency for the bandpass filter. If 0, + it will not apply a highpass filter (default 0.01). lowpass : positive float, optional The lowpass cutoff frequency for the bandpass filter (default 0.1). tr : positive float, optional @@ -88,7 +89,9 @@ class AmplitudeLowFrequencyFluctuationParcels( use_afni=use_afni, ) - def _postprocess(self, input: Dict) -> Dict: + def _postprocess( + self, input: Dict, extra_input: Optional[Dict] = None + ) -> Dict: """Compute ALFF and fALFF. Parameters @@ -121,6 +124,6 @@ class AmplitudeLowFrequencyFluctuationParcels( ) # get the 2D timeseries after parcel aggregation - out = pa.compute(input) + out = pa.compute(input, extra_input=extra_input) return out diff --git a/junifer/markers/falff/falff_spheres.py b/junifer/markers/falff/falff_spheres.py index 933663dce..892816ac3 100644 --- a/junifer/markers/falff/falff_spheres.py +++ b/junifer/markers/falff/falff_spheres.py @@ -30,7 +30,8 @@ class AmplitudeLowFrequencyFluctuationSpheres( fractional : bool Whether to compute fractional ALFF. highpass : positive float, optional - The highpass cutoff frequency for the bandpass filter (default 0.01). + The highpass cutoff frequency for the bandpass filter. If 0, + it will not apply a highpass filter (default 0.01). lowpass : positive float, optional The lowpass cutoff frequency for the bandpass filter (default 0.1). tr : positive float, optional @@ -94,7 +95,9 @@ class AmplitudeLowFrequencyFluctuationSpheres( use_afni=use_afni, ) - def _postprocess(self, input: Dict) -> Dict: + def _postprocess( + self, input: Dict, extra_input: Optional[Dict] = None + ) -> Dict: """Compute ALFF and fALFF. Parameters @@ -127,7 +130,7 @@ class AmplitudeLowFrequencyFluctuationSpheres( on="fALFF", ) - # get the 2D timeseries after parcel aggregation - out = pa.compute(input) + # get the 2D timeseries after sphere aggregation + out = pa.compute(input, extra_input=extra_input) return out diff --git a/junifer/markers/reho/reho_parcels.py b/junifer/markers/reho/reho_parcels.py index ea7b40bcc..4b4dcab90 100644 --- a/junifer/markers/reho/reho_parcels.py +++ b/junifer/markers/reho/reho_parcels.py @@ -141,7 +141,10 @@ class ReHoParcels(ReHoBase): ) # Perform aggregation on reho map parcel_aggregation_input = {"data": reho_map} - output = parcel_aggregation.compute(input=parcel_aggregation_input) + output = parcel_aggregation.compute( + input=parcel_aggregation_input, + extra_input=extra_input, + ) # Only use the first row and expand row dimension output["data"] = output["data"][0][np.newaxis, :] return output diff --git a/junifer/markers/reho/reho_spheres.py b/junifer/markers/reho/reho_spheres.py index 01ca40282..e42e32bcc 100644 --- a/junifer/markers/reho/reho_spheres.py +++ b/junifer/markers/reho/reho_spheres.py @@ -149,7 +149,9 @@ class ReHoSpheres(ReHoBase): ) # Perform aggregation on reho map sphere_aggregation_input = {"data": reho_map} - output = sphere_aggregation.compute(input=sphere_aggregation_input) + output = sphere_aggregation.compute( + input=sphere_aggregation_input, extra_input=extra_input + ) # Only use the first row and expand row dimension output["data"] = output["data"][0][np.newaxis, :] return output -- 2.52.0 From 6d8deab439e2dc50949f4194182b081a905f56b3 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Tue, 14 Mar 2023 22:31:19 +0100 Subject: [PATCH 2/2] Update changes --- docs/changes/latest.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changes/latest.inc b/docs/changes/latest.inc index 23c012ce6..80d7168e3 100644 --- a/docs/changes/latest.inc +++ b/docs/changes/latest.inc @@ -54,6 +54,9 @@ Bugs - Fix ``junifer run`` to respect preprocess step specified in the pipeline (:gh:`159` by `Synchon Mandal`_). +- Fix :class:`junifer.markers.AmplitudeLowFrequencyFluctuationParcels`, :class:`junifer.markers.AmplitudeLowFrequencyFluctuationSpheres` + :class:`junifer.markers.ReHoSpheres` and :class:`junifer.markers.ReHoParcels` pass the ``extra_input`` parameter (:gh:`187` by `Fede Raimondo`_). + API changes ~~~~~~~~~~~ -- 2.52.0