<div dir="ltr"><div><br clear="all"></div><div>Hi there,</div><div><br></div><div>I am having an issue with writing an annotation file: <br></div><div><br></div><div>```<br>import numpy as np<br>from nibabel import freesurfer<br>from glob import glob<br><br>lh_labels= glob('*lh*.label')<br><br># initialize variables<br>lh_vertices = []<br># initialize names list starting with 'unknown'<br>names=['background']<br><br>for ii in lh_labels:<br>    lh_vertices.append(freesurfer.read_labels(ii))<br>    names.append(os.path.basename(ii.split('.',1)[0]))<br><br><br>lh_labels_array=np.concatente(lh_vertices)<br><br># load in long version of li 2016 parcellation including all 116 ROIs<br>ctab_long=np.loadtxt(path_to_rgb, dtype='int')<br><br># create ctab with the appropriate length<br>names_len=len(names)<br><br>ctab=np.delete(ctab_long, slice(names_len,116),0)<br><br>print('writing LH annotation file')<br>freesurfer.write_annot(outpath + 'lh.li2019_parc.annot', labels=lh_labels_array, ctab=ctab, names=names)<br>```<br><br>However, I get the same error as @danjgale.<br><br>```<br>IndexError                                Traceback (most recent call last)<br><ipython-input-31-dab2f8c108c2> in <module><br>----> 1 freesurfer.write_annot('lh.li2019_parc.annot', labels=lh_labels_array, ctab=ctab, names=names)<br>c:\programdata\miniconda3\lib\site-packages\nibabel\freesurfer\io.py in write_annot(filepath, labels, ctab, names, fill_ctab)<br>    542<br>    543         # convert labels into coded CLUT values<br>--> 544         clut_labels = ctab[:, -1][labels]<br>    545         clut_labels[np.where(labels == -1)] = 0<br>    546<br><br>IndexError: index 8505 is out of bounds for axis 0 with size 51<br><br>```<br><br><br>If I print the variables and their shapes I get the following:<br><br><br>```<br>In [35]: len(names)<br>Out[35]: 51<br><br>In [27]: names<br>Out[27]:<br>['background',<br> 'Net_10_ROIs_1_lh_native_dil2',<br> 'Net_11_ROIs_1_lh_native_dil2',<br> 'Net_12_ROIs_1_lh_native_dil2',<br> 'Net_12_ROIs_2_lh_native_dil2',<br> 'Net_13_ROIs_1_lh_native_dil2',<br> .....<br><br><br>In [36]: ctab.shape<br>Out[36]: (51, 4)<br><br>In [32]: ctab<br>Out[32]:<br>array([[255, 255, 255,   0],<br>       [ 25,   5,  25, 255],<br>       [ 25, 100,  40, 255],<br>       [ 70, 130, 180, 255],<br>       ....<br>```<br>Would really appreciate any advice or help.</div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><b>Benjamin L. Deck</b><div><i>Doctoral Student</i></div><div><i>Applied Cognitive and Brain Sciences</i></div><div><i>Department of Psychological and Brain Sciences</i></div><div><i>Drexel University</i></div></div></div></div></div><div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top:1px solid #d3d4de">
        <tr>
        <td style="width:55px;padding-top:13px"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;"></a></td>
                <td style="width:470px;padding-top:12px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link" target="_blank" style="color:#4453ea">www.avast.com</a>
                </td>
        </tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div>