siibra-python icon indicating copy to clipboard operation
siibra-python copied to clipboard

Building mask from Julich parent node fails

Open dickscheid opened this issue 1 year ago • 1 comments

Observed in version 1.0a14:

import siibra
p = siibra.parcellations.get('julich 3')
isocortex = p.get_region('cerebral cortex')
isocortex.get_regional_map(space='mni152', maptype='labelled')

fails when it ends up trying to merge less than two volumes in volumes/volume.py:673. It also appears to resample several volumes, which should not be necessary. I think this problem is already fixed in the siibra 2 development branches, but we might need a fix in the production version for the time being.

dickscheid avatar Aug 17 '24 06:08 dickscheid

what I would it expect to be doing is sth like this:

  import siibra
  import nibabel as nib
  import numpy as np
  labelled_map = siibra.get_map('julich 3', maptype='labelled', space='mni152')
  mapimg = labelled_map.fetch()
  region = labelled_map.parcellation.get_region('cerebral cortex')
  child_labels = [
      labelled_map.get_index(_).label
      for _ in labelled_map.regions 
      if labelled_map.parcellation.get_region(_).has_parent(region)
  ]
  mapdata = np.asanyarray(mapimg.dataobj)
  maskdata = np.zeros_like(mapdata)
  for l in child_labels:
      maskdata[mapdata == l] = 1
  result = nib.Nifti1Image(maskdata, mapimg.affine)

dickscheid avatar Aug 17 '24 06:08 dickscheid

Resampling is necessary for maps that do not have the same affine and resample will return the same nifti if resmapling is not required (thanks to nilearn). So the existing version is more robust.

Merge, by definition requires more than 1 volume but we can just return the volume provided.

AhmetNSimsek avatar Sep 12 '24 13:09 AhmetNSimsek