{
"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",
" name | \n",
" red | \n",
" green | \n",
" blue | \n",
" transparency | \n",
" hex_color_code | \n",
" color_code | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" unknown | \n",
" 25 | \n",
" 5 | \n",
" 25 | \n",
" 0 | \n",
" #190519 | \n",
" 0 | \n",
"
\n",
" \n",
" 1 | \n",
" bankssts | \n",
" 25 | \n",
" 100 | \n",
" 40 | \n",
" 0 | \n",
" #196428 | \n",
" 2647065 | \n",
"
\n",
" \n",
" 2 | \n",
" caudalanteriorcingulate | \n",
" 125 | \n",
" 100 | \n",
" 160 | \n",
" 0 | \n",
" #7d64a0 | \n",
" 10511485 | \n",
"
\n",
" \n",
" 3 | \n",
" caudalmiddlefrontal | \n",
" 100 | \n",
" 25 | \n",
" 0 | \n",
" 0 | \n",
" #641900 | \n",
" 6500 | \n",
"
\n",
" \n",
" 4 | \n",
" corpuscallosum | \n",
" 120 | \n",
" 70 | \n",
" 50 | \n",
" 0 | \n",
" #784632 | \n",
" 3294840 | \n",
"
\n",
" \n",
"
\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",
" vertex_index | \n",
" label_index | \n",
" index | \n",
" name | \n",
" red | \n",
" green | \n",
" blue | \n",
" transparency | \n",
" hex_color_code | \n",
" color_code | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 5 | \n",
" 5 | \n",
" cuneus | \n",
" 220 | \n",
" 20 | \n",
" 100 | \n",
" 0 | \n",
" #dc1464 | \n",
" 6558940 | \n",
"
\n",
" \n",
" 1 | \n",
" 1 | \n",
" 5 | \n",
" 5 | \n",
" cuneus | \n",
" 220 | \n",
" 20 | \n",
" 100 | \n",
" 0 | \n",
" #dc1464 | \n",
" 6558940 | \n",
"
\n",
" \n",
" 2 | \n",
" 2 | \n",
" 5 | \n",
" 5 | \n",
" cuneus | \n",
" 220 | \n",
" 20 | \n",
" 100 | \n",
" 0 | \n",
" #dc1464 | \n",
" 6558940 | \n",
"
\n",
" \n",
" 3 | \n",
" 3 | \n",
" 5 | \n",
" 5 | \n",
" cuneus | \n",
" 220 | \n",
" 20 | \n",
" 100 | \n",
" 0 | \n",
" #dc1464 | \n",
" 6558940 | \n",
"
\n",
" \n",
" 4 | \n",
" 4 | \n",
" 5 | \n",
" 5 | \n",
" cuneus | \n",
" 220 | \n",
" 20 | \n",
" 100 | \n",
" 0 | \n",
" #dc1464 | \n",
" 6558940 | \n",
"
\n",
" \n",
"
\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
}