From 8bb1a70c8bca37f97fa4dd300df897c525581aa2 Mon Sep 17 00:00:00 2001 From: Xiao Gui Date: Wed, 9 Oct 2024 09:21:38 +0200 Subject: [PATCH] fix notebook 4 fix notebook (convert to pdf & upload as artefact) --- .github/workflows/test-paper-notebooks.yml | 29 +++-- .../4-probabilistic-assignment.ipynb | 120 +----------------- 2 files changed, 24 insertions(+), 125 deletions(-) diff --git a/.github/workflows/test-paper-notebooks.yml b/.github/workflows/test-paper-notebooks.yml index 4fc6e6c6..a1510e0c 100644 --- a/.github/workflows/test-paper-notebooks.yml +++ b/.github/workflows/test-paper-notebooks.yml @@ -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: @@ -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 diff --git a/paper_notebookes/4-probabilistic-assignment.ipynb b/paper_notebookes/4-probabilistic-assignment.ipynb index 5844a7f4..d9fa19b1 100644 --- a/paper_notebookes/4-probabilistic-assignment.ipynb +++ b/paper_notebookes/4-probabilistic-assignment.ipynb @@ -1,6 +1,5 @@ { - "cells": [ - { + "cells": [{ "cell_type": "code", "execution_count": null, "id": "51571a53", @@ -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", @@ -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": { @@ -391,4 +277,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file