Skip to content

Commit

Permalink
fix: activation handler errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
paquiteau committed Feb 25, 2025
1 parent fc330ba commit ef57582
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/snake/core/handlers/activations/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit ef57582

Please sign in to comment.