Skip to content

Commit

Permalink
Merge branch 'main' into colab_notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
lrlunin authored Dec 11, 2024
2 parents 70a778f + 28038b1 commit fc790da
Showing 111 changed files with 2,471 additions and 950 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -94,7 +94,15 @@ jobs:
run: |
VERSION=${{ needs.build-testpypi-package.outputs.version }}
SUFFIX=${{ needs.build-testpypi-package.outputs.suffix }}
python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
for i in {1..3}; do
if python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/; then
echo "Package installed successfully."
break
else
echo "Attempt $i failed. Retrying in 10 seconds..."
sleep 10
fi
done
build-pypi-package:
name: Build Package for PyPI
36 changes: 4 additions & 32 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -147,14 +147,14 @@ jobs:
run: |
notebook=${{ matrix.notebook }}
echo "ARTIFACT_NAME=${notebook/.ipynb/}" >> $GITHUB_OUTPUT
echo "HTML_RESULT=${notebook/.ipynb/.html}" >> $GITHUB_OUTPUT
echo "IPYNB_EXECUTED=${notebook}" >> $GITHUB_OUTPUT
- name: Upload notebook
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ steps.artifact_names.outputs.ARTIFACT_NAME }}
path: ${{ github.workspace }}/nb-runner.out/${{ steps.artifact_names.outputs.HTML_RESULT }}
path: ${{ github.workspace }}/nb-runner.out/${{ steps.artifact_names.outputs.IPYNB_EXECUTED }}
env:
RUNNER: ${{ toJson(runner) }}

@@ -177,39 +177,11 @@ jobs:
- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[docs]

- name: Download notebook html files
- name: Download executed notebook ipynb files
id: download
uses: actions/download-artifact@v4
with:
path: ./docs/source/notebook_artifact/

- name: Copy notebook html files
run: |
mkdir ./docs/source/_notebooks
cd ./docs/source/notebook_artifact/
notebooks=$(grep -rl --include='*' './')
for nb in $notebooks
do
echo "current jupyter-notebook: $nb"
cp ./$nb ../_notebooks/
done
- name: List of notebooks
run: |
cd ./docs/source/_notebooks/
notebooks=$(grep -rl --include='*.html' './')
cd ../
echo "" >> examples.rst
for nb in $notebooks
do
echo " notebook_${nb/.html/.rst}" >> examples.rst
notebook_description=$(grep '<h1 id=' ./_notebooks/$nb | sed 's/.*">\(.*\)<a class=.*/\1/')
echo $notebook_description
echo $notebook_description > "notebook_${nb/.html/.rst}"
echo "========" >> "notebook_${nb/.html/.rst}"
echo ".. raw:: html" >> "notebook_${nb/.html/.rst}"
echo " :file: ./_notebooks/$nb" >> "notebook_${nb/.html/.rst}"
done
path: ./docs/source/_notebooks/

- name: Build docs
run: |
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ instance/

# Sphinx documentation
docs/_build/
docs/source/_notebooks/*

# PyBuilder
.pybuilder/
25 changes: 12 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ repos:
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
@@ -15,22 +14,22 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.1
hooks:
- id: ruff # linter
args: [--fix]
- id: ruff-format # formatter

- repo: https://github.com/crate-ci/typos
rev: v1.27.0
rev: typos-dict-v0.11.37
hooks:
- id: typos

- repo: https://github.com/fzimmermann89/check_all
rev: v1.0
rev: v1.1
hooks:
- id: check-init-all
args: [--double-quotes]
args: [--double-quotes, --fix]
exclude: ^tests/

- repo: https://github.com/pre-commit/mirrors-mypy
@@ -54,11 +53,11 @@ repos:
- "--extra-index-url=https://pypi.python.org/simple"

ci:
autofix_commit_msg: |
[pre-commit] auto fixes from pre-commit hooks
autofix_prs: false
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit] pre-commit autoupdate'
autoupdate_schedule: monthly
skip: [mypy]
submodules: false
autofix_commit_msg: |
[pre-commit] auto fixes from pre-commit hooks
autofix_prs: false
autoupdate_branch: ""
autoupdate_commit_msg: "[pre-commit] pre-commit autoupdate"
autoupdate_schedule: monthly
skip: [mypy]
submodules: false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MRpro

![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12-blue)
![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
![Coverage Bagde](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/ckolbPTB/48e334a10caf60e6708d7c712e56d241/raw/coverage.json)

@@ -52,7 +52,7 @@ Quantitative parameter maps can be obtained by creating a functional to be minim
# Define signal model
model = MagnitudeOp() @ InversionRecovery(ti=idata_multi_ti.header.ti)
# Define loss function and combine with signal model
mse = MSEDataDiscrepancy(idata_multi_ti.data.abs())
mse = MSE(idata_multi_ti.data.abs())
functional = mse @ model
[...]
# Run optimization
12 changes: 12 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -34,6 +34,9 @@
'sphinx.ext.autosummary',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'myst_nb',
'sphinx.ext.mathjax',
'sphinx-mathjax-offline'
]
autosummary_generate = True
autosummary_imported_members = False
@@ -43,6 +46,11 @@
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
source_suffix = {'.rst': 'restructuredtext', '.txt': 'restructuredtext', '.md': 'markdown'}

myst_enable_extensions = [
"amsmath",
"dollarmath",
]
nb_execution_mode = "off"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
@@ -69,3 +77,7 @@
},
],
}

def setup(app):
# forces mathjax on all pages
app.set_html_assets_policy('always')
4 changes: 4 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
@@ -6,3 +6,7 @@ All of the notebooks can directly be run via binder or colab from the repo.

.. toctree::
:maxdepth: 1
:caption: Contents:
:glob:

_notebooks/*/*
8 changes: 4 additions & 4 deletions examples/direct_reconstruction.py
Original file line number Diff line number Diff line change
@@ -11,10 +11,10 @@

import requests

with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5') as data_file:
response = requests.get(zenodo_url + fname, timeout=30)
data_file.write(response.content)
data_file.flush()
data_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5')
response = requests.get(zenodo_url + fname, timeout=30)
data_file.write(response.content)
data_file.flush()

# %% [markdown]
# ### Image reconstruction
8 changes: 4 additions & 4 deletions examples/iterative_sense_reconstruction.ipynb
Original file line number Diff line number Diff line change
@@ -37,10 +37,10 @@
"\n",
"import requests\n",
"\n",
"with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5') as data_file:\n",
" response = requests.get(zenodo_url + fname, timeout=30)\n",
" data_file.write(response.content)\n",
" data_file.flush()"
"data_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5')\n",
"response = requests.get(zenodo_url + fname, timeout=30)\n",
"data_file.write(response.content)\n",
"data_file.flush()"
]
},
{
8 changes: 4 additions & 4 deletions examples/iterative_sense_reconstruction.py
Original file line number Diff line number Diff line change
@@ -11,10 +11,10 @@

import requests

with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5') as data_file:
response = requests.get(zenodo_url + fname, timeout=30)
data_file.write(response.content)
data_file.flush()
data_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5')
response = requests.get(zenodo_url + fname, timeout=30)
data_file.write(response.content)
data_file.flush()

# %% [markdown]
# ### Image reconstruction
22 changes: 10 additions & 12 deletions examples/pulseq_2d_radial_golden_angle.ipynb
Original file line number Diff line number Diff line change
@@ -33,14 +33,13 @@
"cell_type": "code",
"execution_count": null,
"id": "d16f41f1",
"metadata": {
"lines_to_next_cell": 2
},
"metadata": {},
"outputs": [],
"source": [
"# define zenodo records URL and create a temporary directory and h5-file\n",
"zenodo_url = 'https://zenodo.org/records/10854057/files/'\n",
"fname = 'pulseq_radial_2D_402spokes_golden_angle_with_traj.h5'"
"fname = 'pulseq_radial_2D_402spokes_golden_angle_with_traj.h5'\n",
"data_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5')"
]
},
{
@@ -51,10 +50,9 @@
"outputs": [],
"source": [
"# Download raw data using requests\n",
"with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5') as data_file:\n",
" response = requests.get(zenodo_url + fname, timeout=30)\n",
" data_file.write(response.content)\n",
" data_file.flush()"
"response = requests.get(zenodo_url + fname, timeout=30)\n",
"data_file.write(response.content)\n",
"data_file.flush()"
]
},
{
@@ -127,10 +125,10 @@
"# download the sequence file from zenodo\n",
"zenodo_url = 'https://zenodo.org/records/10868061/files/'\n",
"seq_fname = 'pulseq_radial_2D_402spokes_golden_angle.seq'\n",
"with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.seq') as seq_file:\n",
" response = requests.get(zenodo_url + seq_fname, timeout=30)\n",
" seq_file.write(response.content)\n",
" seq_file.flush()"
"seq_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.seq')\n",
"response = requests.get(zenodo_url + seq_fname, timeout=30)\n",
"seq_file.write(response.content)\n",
"seq_file.flush()"
]
},
{
17 changes: 8 additions & 9 deletions examples/pulseq_2d_radial_golden_angle.py
Original file line number Diff line number Diff line change
@@ -19,14 +19,13 @@
# define zenodo records URL and create a temporary directory and h5-file
zenodo_url = 'https://zenodo.org/records/10854057/files/'
fname = 'pulseq_radial_2D_402spokes_golden_angle_with_traj.h5'

data_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5')

# %%
# Download raw data using requests
with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.h5') as data_file:
response = requests.get(zenodo_url + fname, timeout=30)
data_file.write(response.content)
data_file.flush()
response = requests.get(zenodo_url + fname, timeout=30)
data_file.write(response.content)
data_file.flush()

# %% [markdown]
# ### Image reconstruction using KTrajectoryIsmrmrd
@@ -63,10 +62,10 @@
# download the sequence file from zenodo
zenodo_url = 'https://zenodo.org/records/10868061/files/'
seq_fname = 'pulseq_radial_2D_402spokes_golden_angle.seq'
with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.seq') as seq_file:
response = requests.get(zenodo_url + seq_fname, timeout=30)
seq_file.write(response.content)
seq_file.flush()
seq_file = tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.seq')
response = requests.get(zenodo_url + seq_fname, timeout=30)
seq_file.write(response.content)
seq_file.flush()

# %%
# Read raw data and calculate trajectory using KTrajectoryPulseq
Loading

0 comments on commit fc790da

Please sign in to comment.