Skip to content
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

How to use my own atlas?ValueError: Array shape is not valid. #111

Open
AstonshisL opened this issue Jan 23, 2024 · 1 comment
Open

How to use my own atlas?ValueError: Array shape is not valid. #111

AstonshisL opened this issue Jan 23, 2024 · 1 comment

Comments

@AstonshisL
Copy link

AstonshisL commented Jan 23, 2024

Many thanks to the authors for creating brainspace, which helped me.
But I was curious, how do you plot gradients using atlas and brain templates other than examples?

Here is my code:

surf_labels_lh = nb.freesurfer.read_annot('E:\Papers\Datasets\MCI diagnosis\BN_Atals\label/lh.BN_Atlas.annot')[0]
surf_labels_rh = nb.freesurfer.read_annot( 'E:\Papers\Datasets\MCI diagnosis\BN_Atals\label/rh.BN_Atlas.annot')[0]

labeling = np.concatenate([surf_labels_lh, surf_labels_rh])
mask = labeling != 0
surf_lh = brainspace.mesh.mesh_io.read_surface('E:\Papers\Datasets\MCI diagnosis\BN_Atals\surf/fsaverage.L.pial.32k_fs_LR.surf.gii')
surf_rh = brainspace.mesh.mesh_io.read_surface('E:\Papers\Datasets\MCI diagnosis\BN_Atals\surf/fsaverage.R.pial.32k_fs_LR.surf.gii')

correlation_matrix = scipy.io.loadmat('E:\Papers\Datasets\MCI diagnosis\MCI/MCI_subject_1_matrix.mat')
input_matrix = correlation_matrix['subject_1_matrix']
gm = GradientMaps(n_components=2, random_state=0)
gm.fit(input_matrix)
grad = [None] * 2

for i in range(2):
    gradients = gradient_zscore(gm.gradients_[:, i])
    grad[i] = map_to_labels(gradients, labeling, mask=mask)
plot_hemispheres(surf_lh, surf_rh, array_name=grad, size=(1200, 400), cmap='viridis_r',
                 color_bar=True,label_text=['Grad1', 'Grad2'], zoom=1.55)`
The dimension of the input matrix is 248*248.
But in the last step:```
plot_hemispheres(surf_lh, surf_rh, array_name=grad, size=(1200, 400), cmap='viridis_r',
                 color_bar=True,label_text=['Grad1', 'Grad2'], zoom=1.55)

An error has occurred:

C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\brainspace\gradient\embedding.py:70: UserWarning: Affinity is not symmetric. Making symmetric.
  warnings.warn('Affinity is not symmetric. Making symmetric.')
Traceback (most recent call last):
  File "E:\Papers\Code\mycode_IDSCN\OpenBUB test\Code\MCI_gradients.py", line 91, in <module>
    plot_hemispheres(surf_lh, surf_rh, array_name=grad, size=(1200, 400), cmap='viridis_r',
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\brainspace\vtk_interface\decorators.py", line 41, in _wrapper_wrap
    data = func(*args, **kwds)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\brainspace\plotting\surface_plotting.py", line 557, in plot_hemispheres
    surf_rh.append_array(an[n_pts_lh:], name=name, at='p')
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\brainspace\vtk_interface\wrappers\data_object.py", line 214, in append_array
    _array_overwrite(self.PointData, to_point)
  File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\brainspace\vtk_interface\wrappers\data_object.py", line 211, in _array_overwrite
    raise ValueError('Array shape is not valid.')
ValueError: Array shape is not valid.

How should I modify my code? Please help me, this problem has been bothering me for a long time!

@AstonshisL AstonshisL changed the title How to use my own atlas? How to use my own atlas?ValueError: Array shape is not valid. Jan 23, 2024
@acamargofb
Copy link

I have a similar problem when I am trying to use my own atlas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants