Skip to content

Commit

Permalink
fix notebook 4
Browse files Browse the repository at this point in the history
fix notebook (convert to pdf & upload as artefact)
  • Loading branch information
xgui3783 committed Oct 9, 2024
1 parent 0a40078 commit 8bb1a70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 125 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/test-paper-notebooks.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: '[test] test siibra-paper notebooks'
name: "[test] test siibra-paper notebooks"

on:
push:
branches: [ 'main', 'refactor_attr' ]
branches: ["main", "refactor_attr"]
pull_request:
branches: [ '*' ]
branches: ["*"]

jobs:
test_tutorials:
Expand All @@ -21,9 +21,22 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -U .
pip install -r requirements.txt
pip install matplotlib
pip install pytest nbmake
pip install matplotlib jupyter
apt-get install pandoc
- name: Run notebooks with nbmake
run: pytest --nbmake --nbmake-timeout=1200 paper_notebookes
run: |
for notebook in $(find ./paper_notebooks -type f)
do
echo "jupyter execute $notebook --allow-errors --inplace"
jupyter execute $notebook --allow-errors --inplace
echo "jupyter nbconvert --to pdf $notebook"
jupyter nbconvert --to pdf $notebook
done
- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: Notebook PDFs
path: paper_notebooks/*.pdf
120 changes: 3 additions & 117 deletions paper_notebookes/4-probabilistic-assignment.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"cells": [
{
"cells": [{
"cell_type": "code",
"execution_count": null,
"id": "51571a53",
Expand Down Expand Up @@ -233,6 +232,7 @@
"outputs": [],
"source": [
"\n",
"region = siibra.get_region('3.0.3', region.name)\n",
"features = siibra.find_features(region, siibra.modality_vocab.modality.STREAMLINECOUNTS)\n",
"\n",
"ft = features[0]\n",
Expand All @@ -254,120 +254,6 @@
"named_sorted_series = sorted_series.rename(index={r:shortname(r) for r in sorted_series.index})\n",
"named_sorted_series[:15].plot(kind=\"bar\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "15eed6e0",
"metadata": {},
"outputs": [],
"source": [
" features[0].plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3238c1e",
"metadata": {},
"outputs": [],
"source": [
"fts = siibra.features.get(region, siibra.features.connectivity.StreamlineCounts)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "035d099b",
"metadata": {},
"outputs": [],
"source": [
"fts[0].get_element(\"000\").plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc05ad7e",
"metadata": {},
"outputs": [],
"source": [
"def shortname(region):\n",
" return (\n",
" re.sub('\\s*\\(.*\\)\\s*|\\s*Area\\s*', ' ', region.name)\n",
" .replace('left', 'L')\n",
" .replace('right', 'R')\n",
" .strip()\n",
" )\n",
"\n",
"fts = siibra.features.get(region, siibra.features.connectivity.StreamlineCounts)\n",
"conn = fts[0].get_element(\"000\")\n",
"conndata = conn.get_profile(region).data\n",
"conndata.rename(index={r:shortname(r) for r in conndata.index}, inplace=True)\n",
"fig, ax = plt.subplots(1, 1, figsize=(3.5, 3.0))\n",
"conndata[:15].plot(kind='bar', rot=45, ax=ax)\n",
"plt.xticks(ha='right')\n",
"plt.tight_layout()\n",
"plt.grid(True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed0cbeb7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8ec0cc8",
"metadata": {},
"outputs": [],
"source": [
"# find cluster peaks\n",
"peak_accuracy_mm = 2\n",
"clusterpeaks = clustermap.find_peaks(mindist=10, sigma_mm=peak_accuracy_mm)\n",
"print(clusterpeaks)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6981e626",
"metadata": {},
"outputs": [],
"source": [
"# get one cluster peak\n",
"peak_id = 0\n",
"peakmap = siibra.volumes.from_pointset(clusterpeaks, label=peak_id, target=clustermap, min_num_points=1)\n",
"view = plotting.plot_glass_brain(peakmap.fetch(), alpha=1, threshold=0, cmap='RdBu')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b71082e",
"metadata": {},
"outputs": [],
"source": [
"matches = (\n",
" pmaps\n",
" .assign(clustermap)\n",
" .query(f\"correlation >= {min_correlation}\", engine='python')\n",
" .sort_values('correlation', ascending=False)\n",
")\n",
"matches"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ca50d55",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -391,4 +277,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit 8bb1a70

Please sign in to comment.