Skip to content

Develop marco #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions nitools/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def make_label_cifti(data, bm_axis,
label_RGBA (list):
List of rgba vectors for labels
Returns:
cifti (GiftiImage): Label gifti image
cifti (GiftiImage): Label gifti image
"""
if data.ndim == 1:
# reshape to (1, num_vertices)
Expand Down Expand Up @@ -213,7 +213,7 @@ def split_cifti_to_giftis(cifti_img, type = "label", column_names = None):
))
return gii

def volume_from_cifti(cifti, struct_names=[]):
def volume_from_cifti(cifti, struct_names=None):
""" Gets the 4D nifti object containing the data
for all subcortical (volume-based) structures

Expand All @@ -222,7 +222,7 @@ def volume_from_cifti(cifti, struct_names=[]):
cifti object containing the data
struct_names (list or None):
List of structure names that are included
defaults to None
defaults to None (all)
Returns:
nii_vol(niftiImage):
nifti object containing the data
Expand All @@ -232,20 +232,22 @@ def volume_from_cifti(cifti, struct_names=[]):
# get the data array with all the time points, all the structures
d_array = cifti.get_fdata(dtype=np.float32)

struct_names = [nb.cifti2.BrainModelAxis.to_cifti_brain_structure_name(n) for n in struct_names]
if struct_names is None:
struct_names = [a for a,_,_ in bmf.iter_structures()]
else:
struct_names = [nb.cifti2.BrainModelAxis.to_cifti_brain_structure_name(n) for n in struct_names]

# initialize a matrix representing 4D data (x, y, z, time_point)
vol = np.zeros(bmf.volume_shape + (d_array.shape[0],))
for idx, (nam,slc,bm) in enumerate(bmf.iter_structures()):

if (any(s in nam for s in struct_names)):
if (nam in struct_names):
ijk = bm.voxel
bm_data = d_array[:, slc]
i = (ijk[:,0] > -1)

# fill in data
vol[ijk[i, 0], ijk[i, 1], ijk[i, 2], :]=bm_data[:,i].T

# save as nii
nii_vol_4d = nb.Nifti1Image(vol,bmf.affine)
return nii_vol_4d
Expand Down
5 changes: 3 additions & 2 deletions nitools/gifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ def get_gifti_colortable(gifti,ignore_zero=False):
labels = labels[1:]

cmap = mpl.colors.LinearSegmentedColormap.from_list('mylist', rgba, N=len(rgba))
mpl.cm.unregister_cmap("mycolormap")
mpl.cm.register_cmap("mycolormap", cmap)
# Removed - incomplatible with newer versions of matplotlib
# mpl.cm.unregister_cmap("mycolormap")
# mpl.cm.register_cmap("mycolormap", cmap)

return rgba, cmap

Expand Down
Loading