From ef57582241754399242c5c57ff1f406cac6c3bf0 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 25 Feb 2025 17:15:39 +0100 Subject: [PATCH] fix: activation handler errors. --- .../core/handlers/activations/activations.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/snake/core/handlers/activations/activations.py b/src/snake/core/handlers/activations/activations.py index cf26981..c04a9ba 100644 --- a/src/snake/core/handlers/activations/activations.py +++ b/src/snake/core/handlers/activations/activations.py @@ -115,23 +115,30 @@ def _get_roi_atlas(self, phantom: Phantom) -> NDArray: """ atlas_base, atlas_name = self.atlas.split("__") from nilearn.datasets.atlas import fetch_atlas_harvard_oxford - from nibabel.nifti1 import Nifti1Image if atlas_base == "hardvard-oxford": - atlas = fetch_atlas_harvard_oxford(atlas=atlas_name) + atlas = fetch_atlas_harvard_oxford(atlas_name=atlas_name) else: raise ValueError(f"Atlas {atlas_base} not supported.") - maps = Nifti1Image.from_filename(atlas.maps) - idx = atlas.labels.index(self.atlas_label) - if atlas.atlas_type == "probabilistic": - atlas_mask = np.array(maps.dataobj[..., idx]) + maps = atlas.maps + if isinstance(self.atlas_label, str): + idx = atlas.labels.index(self.atlas_label) else: - atlas_mask = np.array(maps.dataobj == idx) + idx = self.atlas_label + if maps.dataobj.ndim == 4: # probabilistic atlas + atlas_mask = np.array(maps.dataobj[..., idx]).astype(np.float32) + else: + atlas_mask = np.array(maps.dataobj == idx).astype(np.float32) # Resample the atlas to the phantom affine atlas_mask = apply_affine( - atlas_mask, maps.affine, phantom.affine, phantom.anat_shape, use_gpu=True + atlas_mask, + old_affine=maps.affine, + new_affine=phantom.affine, + new_shape=phantom.anat_shape, + use_gpu=True, ) - return atlas_mask + roi = atlas_mask * phantom.masks[phantom.labels_idx[self.base_tissue_name]] + return roi def get_dynamic(self, phantom: Phantom, sim_conf: SimConfig) -> DynamicData: """Get dynamic time series for adding Activations."""