{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "155622" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from freesurfer_surface import Surface\n", "\n", "SUBJECTS_DIR = '../tests/subjects'\n", "surface = Surface.read_triangular(SUBJECTS_DIR + '/fabian/surf/lh.pial')\n", "surface.load_annotation_file(SUBJECTS_DIR + '/fabian/label/lh.aparc.annot')\n", "len(surface.annotation.vertex_label_index)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/autofs/space/tanha_002/users/greve/fsdev.build/average/colortable_desikan_killiany.txt'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "surface.annotation.colortable_path.decode()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameredgreenbluetransparencyhex_color_codecolor_code
0unknown255250#1905190
1bankssts25100400#1964282647065
2caudalanteriorcingulate1251001600#7d64a010511485
3caudalmiddlefrontal1002500#6419006500
4corpuscallosum12070500#7846323294840
\n", "
" ], "text/plain": [ " name red green blue transparency hex_color_code \\\n", "0 unknown 25 5 25 0 #190519 \n", "1 bankssts 25 100 40 0 #196428 \n", "2 caudalanteriorcingulate 125 100 160 0 #7d64a0 \n", "3 caudalmiddlefrontal 100 25 0 0 #641900 \n", "4 corpuscallosum 120 70 50 0 #784632 \n", "\n", " color_code \n", "0 0 \n", "1 2647065 \n", "2 10511485 \n", "3 6500 \n", "4 3294840 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas\n", "\n", "label_frame = pandas.DataFrame((dict(color_code=label.color_code,\n", " hex_color_code=label.hex_color_code,\n", " **vars(label))\n", " for label in surface.annotation.labels.values()),\n", " columns=['index', 'name', \n", " 'red', 'green', 'blue', 'transparency', \n", " 'hex_color_code', 'color_code'])\n", "label_frame.drop(columns=['index']).head()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vertex_indexlabel_indexindexnameredgreenbluetransparencyhex_color_codecolor_code
0055cuneus220201000#dc14646558940
1155cuneus220201000#dc14646558940
2255cuneus220201000#dc14646558940
3355cuneus220201000#dc14646558940
4455cuneus220201000#dc14646558940
\n", "
" ], "text/plain": [ " vertex_index label_index index name red green blue transparency \\\n", "0 0 5 5 cuneus 220 20 100 0 \n", "1 1 5 5 cuneus 220 20 100 0 \n", "2 2 5 5 cuneus 220 20 100 0 \n", "3 3 5 5 cuneus 220 20 100 0 \n", "4 4 5 5 cuneus 220 20 100 0 \n", "\n", " hex_color_code color_code \n", "0 #dc1464 6558940 \n", "1 #dc1464 6558940 \n", "2 #dc1464 6558940 \n", "3 #dc1464 6558940 \n", "4 #dc1464 6558940 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas\n", "\n", "vertex_frame = pandas.DataFrame(surface.annotation.vertex_label_index.items(),\n", " columns=['vertex_index', 'label_index'])\n", "vertex_label_frame = vertex_frame.merge(label_frame, left_on='label_index', right_on='index')\n", "vertex_label_frame.head()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "superiorfrontal 12532\n", "superiorparietal 9883\n", "lateraloccipital 9792\n", "rostralmiddlefrontal 9484\n", "supramarginal 8156\n", "unknown 8062\n", "precentral 7944\n", "postcentral 7095\n", "superiortemporal 7006\n", "inferiorparietal 6737\n", "lingual 5636\n", "precuneus 5560\n", "middletemporal 5207\n", "fusiform 5003\n", "inferiortemporal 4756\n", "lateralorbitofrontal 4383\n", "caudalmiddlefrontal 4128\n", "insula 4117\n", "cuneus 3033\n", "medialorbitofrontal 3017\n", "parsopercularis 2839\n", "pericalcarine 2734\n", "paracentral 2507\n", "parstriangularis 2460\n", "posteriorcingulate 2352\n", "isthmuscingulate 1861\n", "rostralanteriorcingulate 1711\n", "caudalanteriorcingulate 1362\n", "bankssts 1322\n", "parsorbitalis 1078\n", "parahippocampal 991\n", "transversetemporal 990\n", "entorhinal 789\n", "temporalpole 727\n", "frontalpole 368\n", "Name: name, dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vertex_label_frame['name'].value_counts()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.10" } }, "nbformat": 4, "nbformat_minor": 2 }