FZJ-INM1-BDA / siibra-python

Software interfaces for interacting with brain atlases - Python client
Apache License 2.0
48 stars 10 forks source link

Building mask from Julich parent node fails #600

Closed dickscheid closed 1 month ago

dickscheid commented 2 months ago

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 commented 2 months ago

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)
AhmetNSimsek commented 1 month ago

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.