komamripy 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- komamripy-0.0.2/.github/dependabot.yml +12 -0
- komamripy-0.0.2/.github/workflows/ci.yml +76 -0
- komamripy-0.0.2/.github/workflows/publish.yml +38 -0
- komamripy-0.0.2/.gitignore +218 -0
- komamripy-0.0.2/.mailmap +1 -0
- komamripy-0.0.2/LICENSE +21 -0
- komamripy-0.0.2/PKG-INFO +86 -0
- komamripy-0.0.2/README.md +64 -0
- komamripy-0.0.2/examples/basic_simulation.py +29 -0
- komamripy-0.0.2/komamripy/__init__.py +56 -0
- komamripy-0.0.2/komamripy/_session.py +30 -0
- komamripy-0.0.2/komamripy/juliapkg.json +24 -0
- komamripy-0.0.2/pyproject.toml +47 -0
- komamripy-0.0.2/tests/test_integration.py +21 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
# Keep GitHub Actions versions (checkout, setup-uv, cache, etc.) up to date.
|
|
4
|
+
- package-ecosystem: "github-actions"
|
|
5
|
+
directory: "/"
|
|
6
|
+
schedule:
|
|
7
|
+
interval: "weekly"
|
|
8
|
+
groups:
|
|
9
|
+
# Bundle all action bumps into one PR instead of one PR per action.
|
|
10
|
+
actions:
|
|
11
|
+
patterns:
|
|
12
|
+
- "*"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
lint:
|
|
13
|
+
name: Lint
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v7
|
|
17
|
+
- uses: astral-sh/setup-uv@v7
|
|
18
|
+
- name: Ruff lint
|
|
19
|
+
run: uv run --group lint ruff check .
|
|
20
|
+
- name: Ruff format check
|
|
21
|
+
run: uv run --group lint ruff format --check .
|
|
22
|
+
|
|
23
|
+
test:
|
|
24
|
+
name: Test (Python ${{ matrix.python-version }} - ${{ matrix.os }})
|
|
25
|
+
runs-on: ${{ matrix.os }}
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
# Python coverage (floor + ceiling) runs on Linux; Windows and macOS each
|
|
29
|
+
# run once at the ceiling. OS bugs are Python-version-independent and
|
|
30
|
+
# Python bugs are OS-independent, so this covers both axes without the
|
|
31
|
+
# full 3x2 cross-product -- and the floor never lands on the OS/old-Python
|
|
32
|
+
# cells that needed special handling, so one install path works for all.
|
|
33
|
+
matrix:
|
|
34
|
+
include:
|
|
35
|
+
- os: ubuntu-latest
|
|
36
|
+
python-version: "3.10"
|
|
37
|
+
- os: ubuntu-latest
|
|
38
|
+
python-version: "3.14"
|
|
39
|
+
- os: macos-latest
|
|
40
|
+
python-version: "3.14"
|
|
41
|
+
- os: windows-latest
|
|
42
|
+
python-version: "3.14"
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/checkout@v7
|
|
45
|
+
|
|
46
|
+
- uses: actions/setup-python@v6
|
|
47
|
+
id: setup-python
|
|
48
|
+
with:
|
|
49
|
+
python-version: ${{ matrix.python-version }}
|
|
50
|
+
check-latest: true
|
|
51
|
+
|
|
52
|
+
# Install a known-good Julia and force juliacall to use it (see
|
|
53
|
+
# PYTHON_JULIAPKG_EXE below), so it doesn't pick a runner Julia with
|
|
54
|
+
# broken embed paths.
|
|
55
|
+
- uses: julia-actions/setup-julia@v3
|
|
56
|
+
id: setup-julia
|
|
57
|
+
with:
|
|
58
|
+
version: "1.11"
|
|
59
|
+
|
|
60
|
+
- uses: astral-sh/setup-uv@v7
|
|
61
|
+
|
|
62
|
+
- name: Cache Julia depot
|
|
63
|
+
uses: actions/cache@v6
|
|
64
|
+
with:
|
|
65
|
+
path: ~/.julia
|
|
66
|
+
key: julia-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('komamripy/juliapkg.json') }}
|
|
67
|
+
|
|
68
|
+
- name: Install package and test tools
|
|
69
|
+
run: uv sync --group test --python "${{ steps.setup-python.outputs.python-path }}"
|
|
70
|
+
|
|
71
|
+
- name: Run tests
|
|
72
|
+
env:
|
|
73
|
+
# Point juliapkg at the Julia installed above (full exe path, so
|
|
74
|
+
# juliacall can derive its bindir), instead of selecting a runner one.
|
|
75
|
+
PYTHON_JULIAPKG_EXE: ${{ steps.setup-julia.outputs.julia-bindir }}${{ runner.os == 'Windows' && '\julia.exe' || '/julia' }}
|
|
76
|
+
run: uv run --group test pytest -v -s
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Does not pin updated dependencies, full manual release
|
|
4
|
+
# Manual release: triggered by pushing a version tag
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
tags:
|
|
9
|
+
- "v*"
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
pypi:
|
|
13
|
+
name: Publish package to PyPI
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment: pypi
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
id-token: write # required for Trusted Publishing
|
|
19
|
+
steps:
|
|
20
|
+
- name: Check out repository
|
|
21
|
+
uses: actions/checkout@v7
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v6
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.14"
|
|
27
|
+
|
|
28
|
+
- name: Set up uv
|
|
29
|
+
uses: astral-sh/setup-uv@v7
|
|
30
|
+
|
|
31
|
+
- name: Build package
|
|
32
|
+
run: uv build
|
|
33
|
+
|
|
34
|
+
- name: Check package metadata
|
|
35
|
+
run: uv run --with twine python -m twine check dist/*
|
|
36
|
+
|
|
37
|
+
- name: Publish package distributions to PyPI
|
|
38
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
komamripy-0.0.2/.mailmap
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
anvika-singhal <anvikasinghal@outlook.com> anvikasinghal <asinghal@caltech.edu>
|
komamripy-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Carlos Castillo Passi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
komamripy-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: komamripy
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Pulseq-compatible, high-performance MRI simulation in Python, powered by KomaMRI.jl.
|
|
5
|
+
Project-URL: Homepage, https://github.com/JuliaHealth/komamripy
|
|
6
|
+
Project-URL: Repository, https://github.com/JuliaHealth/komamripy
|
|
7
|
+
Project-URL: Issues, https://github.com/JuliaHealth/komamripy/issues
|
|
8
|
+
Author: Anvika Singhal
|
|
9
|
+
Author-email: Carlos Castillo Passi <cacp@stanford.edu>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: Julia,KomaMRI,MRI,Pulseq,medical-imaging,simulation
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: juliacall>=0.9.20
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# komamripy
|
|
24
|
+
|
|
25
|
+
[](https://github.com/JuliaHealth/komamripy/actions/workflows/ci.yml)
|
|
26
|
+
|
|
27
|
+
**Pulseq-compatible, high-performance MRI simulation in Python.**
|
|
28
|
+
|
|
29
|
+
`komamripy` is a thin Python interface to
|
|
30
|
+
[KomaMRI.jl](https://github.com/JuliaHealth/KomaMRI.jl), a high-performance
|
|
31
|
+
Julia framework for MRI simulation. It exposes KomaMRI to Python through
|
|
32
|
+
[juliacall](https://juliapy.github.io/PythonCall.jl/stable/juliacall/), so
|
|
33
|
+
Python users can run fast CPU/GPU MRI simulations without writing any Julia.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
Install by using [uv](https://docs.astral.sh/uv/) (recommended) or pip (remove uv):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv pip install git+https://github.com/JuliaHealth/komamripy
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You do **not** need to install Julia yourself: `juliacall` provisions a suitable
|
|
44
|
+
Julia automatically, and KomaMRI is installed on first import.
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
The first import downloads Julia and precompiles KomaMRI, which can take a few
|
|
49
|
+
minutes. Subsequent runs are fast.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import komamripy as km
|
|
53
|
+
import numpy as np
|
|
54
|
+
|
|
55
|
+
sys = km.Scanner() # scanner hardware
|
|
56
|
+
obj = km.brain_phantom2D() # 2D brain phantom
|
|
57
|
+
seq = km.PulseDesigner.EPI_example() # example EPI sequence
|
|
58
|
+
|
|
59
|
+
sim_params = km.KomaMRICore.default_sim_params()
|
|
60
|
+
sim_params["return_type"] = "mat" # return the raw signal matrix
|
|
61
|
+
|
|
62
|
+
raw = km.simulate(obj, seq, sys, sim_params=sim_params)
|
|
63
|
+
signal = np.asarray(raw)
|
|
64
|
+
|
|
65
|
+
print(signal.shape)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A runnable version lives in [`examples/`](examples/).
|
|
69
|
+
|
|
70
|
+
## How it works
|
|
71
|
+
|
|
72
|
+
`komamripy` mirrors the KomaMRI Julia namespace: any function or type that
|
|
73
|
+
KomaMRI exposes is available as an attribute of `komamripy`. Julia code
|
|
74
|
+
therefore translates to Python almost line for line.
|
|
75
|
+
|
|
76
|
+
Simulation results are returned as Julia objects; convert array-like results to
|
|
77
|
+
NumPy with `numpy.asarray`.
|
|
78
|
+
|
|
79
|
+
## Status
|
|
80
|
+
|
|
81
|
+
`komamripy` is under active development as a Google Summer of Code project.
|
|
82
|
+
|
|
83
|
+
Currently supported: the core simulation pipeline and reading Pulseq files.
|
|
84
|
+
|
|
85
|
+
Planned: PyPI releases, GPU backend selection, tighter pypulseq integration,
|
|
86
|
+
and differentiable workflows.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# komamripy
|
|
2
|
+
|
|
3
|
+
[](https://github.com/JuliaHealth/komamripy/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
**Pulseq-compatible, high-performance MRI simulation in Python.**
|
|
6
|
+
|
|
7
|
+
`komamripy` is a thin Python interface to
|
|
8
|
+
[KomaMRI.jl](https://github.com/JuliaHealth/KomaMRI.jl), a high-performance
|
|
9
|
+
Julia framework for MRI simulation. It exposes KomaMRI to Python through
|
|
10
|
+
[juliacall](https://juliapy.github.io/PythonCall.jl/stable/juliacall/), so
|
|
11
|
+
Python users can run fast CPU/GPU MRI simulations without writing any Julia.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Install by using [uv](https://docs.astral.sh/uv/) (recommended) or pip (remove uv):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv pip install git+https://github.com/JuliaHealth/komamripy
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You do **not** need to install Julia yourself: `juliacall` provisions a suitable
|
|
22
|
+
Julia automatically, and KomaMRI is installed on first import.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
The first import downloads Julia and precompiles KomaMRI, which can take a few
|
|
27
|
+
minutes. Subsequent runs are fast.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import komamripy as km
|
|
31
|
+
import numpy as np
|
|
32
|
+
|
|
33
|
+
sys = km.Scanner() # scanner hardware
|
|
34
|
+
obj = km.brain_phantom2D() # 2D brain phantom
|
|
35
|
+
seq = km.PulseDesigner.EPI_example() # example EPI sequence
|
|
36
|
+
|
|
37
|
+
sim_params = km.KomaMRICore.default_sim_params()
|
|
38
|
+
sim_params["return_type"] = "mat" # return the raw signal matrix
|
|
39
|
+
|
|
40
|
+
raw = km.simulate(obj, seq, sys, sim_params=sim_params)
|
|
41
|
+
signal = np.asarray(raw)
|
|
42
|
+
|
|
43
|
+
print(signal.shape)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A runnable version lives in [`examples/`](examples/).
|
|
47
|
+
|
|
48
|
+
## How it works
|
|
49
|
+
|
|
50
|
+
`komamripy` mirrors the KomaMRI Julia namespace: any function or type that
|
|
51
|
+
KomaMRI exposes is available as an attribute of `komamripy`. Julia code
|
|
52
|
+
therefore translates to Python almost line for line.
|
|
53
|
+
|
|
54
|
+
Simulation results are returned as Julia objects; convert array-like results to
|
|
55
|
+
NumPy with `numpy.asarray`.
|
|
56
|
+
|
|
57
|
+
## Status
|
|
58
|
+
|
|
59
|
+
`komamripy` is under active development as a Google Summer of Code project.
|
|
60
|
+
|
|
61
|
+
Currently supported: the core simulation pipeline and reading Pulseq files.
|
|
62
|
+
|
|
63
|
+
Planned: PyPI releases, GPU backend selection, tighter pypulseq integration,
|
|
64
|
+
and differentiable workflows.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Minimal end-to-end example: simulate an EPI acquisition and read the signal.
|
|
2
|
+
|
|
3
|
+
Run from the repository root after installing the package (see the README)::
|
|
4
|
+
|
|
5
|
+
python examples/basic_simulation.py
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
import komamripy as km
|
|
11
|
+
|
|
12
|
+
# Build the simulation inputs. These mirror KomaMRI's Julia API directly.
|
|
13
|
+
sys = km.Scanner()
|
|
14
|
+
obj = km.brain_phantom2D()
|
|
15
|
+
seq = km.PulseDesigner.EPI_example()
|
|
16
|
+
|
|
17
|
+
# Request the plain signal matrix.
|
|
18
|
+
sim_params = km.KomaMRICore.default_sim_params()
|
|
19
|
+
sim_params["return_type"] = "mat"
|
|
20
|
+
|
|
21
|
+
# The first call compiles Julia code and may take a little while.
|
|
22
|
+
raw = km.simulate(obj, seq, sys, sim_params=sim_params)
|
|
23
|
+
|
|
24
|
+
# `raw` already behaves like an array: NumPy functions such as np.abs or np.sum
|
|
25
|
+
# accept it directly. Use np.asarray only when you want a native NumPy array.
|
|
26
|
+
signal = np.asarray(raw)
|
|
27
|
+
|
|
28
|
+
print("signal shape:", signal.shape)
|
|
29
|
+
print("first sample magnitudes:", np.abs(signal[:5]).ravel())
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""komamripy — a Python interface to KomaMRI.jl, the Julia MRI simulator.
|
|
2
|
+
|
|
3
|
+
komamripy mirrors the KomaMRI Julia namespace through juliacall: any name that
|
|
4
|
+
KomaMRI exposes is available as an attribute of ``komamripy``. As a result,
|
|
5
|
+
Julia code translates to Python almost line for line.
|
|
6
|
+
|
|
7
|
+
Julia::
|
|
8
|
+
|
|
9
|
+
using KomaMRI
|
|
10
|
+
sys = Scanner()
|
|
11
|
+
obj = brain_phantom2D()
|
|
12
|
+
seq = PulseDesigner.EPI_example()
|
|
13
|
+
sim_params = KomaMRICore.default_sim_params()
|
|
14
|
+
raw = simulate(obj, seq, sys; sim_params)
|
|
15
|
+
|
|
16
|
+
Python::
|
|
17
|
+
|
|
18
|
+
import komamripy as km
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
sys = km.Scanner()
|
|
22
|
+
obj = km.brain_phantom2D()
|
|
23
|
+
seq = km.PulseDesigner.EPI_example()
|
|
24
|
+
sim_params = km.KomaMRICore.default_sim_params()
|
|
25
|
+
raw = km.simulate(obj, seq, sys, sim_params=sim_params)
|
|
26
|
+
|
|
27
|
+
Simulation results are returned as Julia objects; use ``numpy.asarray`` to
|
|
28
|
+
convert array-like results (such as a ``"mat"`` signal) into NumPy arrays.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from ._session import get_julia
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def __getattr__(name):
|
|
35
|
+
"""Resolve attribute access against the Julia session (the KomaMRI mirror).
|
|
36
|
+
|
|
37
|
+
Python invokes this only when normal module lookup fails, so anything
|
|
38
|
+
defined or imported in this module takes precedence, and the Julia session
|
|
39
|
+
starts lazily on the first real attribute access.
|
|
40
|
+
|
|
41
|
+
Note: any Python-side helper submodule added in future must be imported
|
|
42
|
+
explicitly in this file, otherwise the mirror would shadow it whenever its
|
|
43
|
+
name also exists in Julia (Julia's Base exports ``diff``, for instance).
|
|
44
|
+
"""
|
|
45
|
+
# Avoid starting Julia just to answer dunder probes from the import system.
|
|
46
|
+
if name.startswith("__") and name.endswith("__"):
|
|
47
|
+
raise AttributeError(name)
|
|
48
|
+
|
|
49
|
+
jl = get_julia()
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
return getattr(jl, name)
|
|
53
|
+
except AttributeError as exc:
|
|
54
|
+
raise AttributeError(
|
|
55
|
+
f"module 'komamripy' has no attribute '{name}'; KomaMRI does not expose it"
|
|
56
|
+
) from exc
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Management of the Julia session that backs komamripy.
|
|
2
|
+
|
|
3
|
+
The Julia runtime and KomaMRI are loaded lazily on first use, so importing
|
|
4
|
+
komamripy stays inexpensive until a Julia-backed feature is actually called.
|
|
5
|
+
All access to Julia flows through :func:`get_julia`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
_session = None # cached juliacall ``Main`` module, created on first use
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_julia():
|
|
14
|
+
"""Return the initialized Julia ``Main`` module, starting it if needed.
|
|
15
|
+
|
|
16
|
+
On the first call this imports juliacall (which provisions a private Julia
|
|
17
|
+
if one is not already available), loads KomaMRI, and caches the resulting
|
|
18
|
+
``Main`` module for reuse.
|
|
19
|
+
|
|
20
|
+
``using KomaMRI`` is evaluated as source because ``using`` is Julia syntax
|
|
21
|
+
rather than a callable; every other interaction with KomaMRI uses ordinary
|
|
22
|
+
attribute access on the returned module.
|
|
23
|
+
"""
|
|
24
|
+
global _session
|
|
25
|
+
if _session is None:
|
|
26
|
+
from juliacall import Main as jl
|
|
27
|
+
|
|
28
|
+
jl.seval("using KomaMRI")
|
|
29
|
+
_session = jl
|
|
30
|
+
return _session
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"packages": {
|
|
3
|
+
"KomaMRI": {
|
|
4
|
+
"uuid": "6a340f8b-2cdf-4c04-99be-4953d9b66d0a",
|
|
5
|
+
"version": "=0.10.4"
|
|
6
|
+
},
|
|
7
|
+
"KomaMRIBase": {
|
|
8
|
+
"uuid": "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c",
|
|
9
|
+
"version": "=0.11.3"
|
|
10
|
+
},
|
|
11
|
+
"KomaMRICore": {
|
|
12
|
+
"uuid": "4baa4f4d-2ae9-40db-8331-a7d1080e3f4e",
|
|
13
|
+
"version": "=0.11.3"
|
|
14
|
+
},
|
|
15
|
+
"KomaMRIFiles": {
|
|
16
|
+
"uuid": "fcf631a6-1c7e-4e88-9e64-b8888386d9dc",
|
|
17
|
+
"version": "=0.10.4"
|
|
18
|
+
},
|
|
19
|
+
"KomaMRIPlots": {
|
|
20
|
+
"uuid": "76db0263-63f3-4d26-bb9a-5dba378db904",
|
|
21
|
+
"version": "=0.11.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "komamripy"
|
|
3
|
+
version = "0.0.2"
|
|
4
|
+
|
|
5
|
+
description = "Pulseq-compatible, high-performance MRI simulation in Python, powered by KomaMRI.jl."
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
license-files = ["LICENSE"]
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Carlos Castillo Passi", email = "cacp@stanford.edu" },
|
|
12
|
+
{ name = "Anvika Singhal" },
|
|
13
|
+
]
|
|
14
|
+
keywords = ["MRI", "simulation", "Pulseq", "KomaMRI", "Julia", "medical-imaging"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"juliacall >=0.9.20",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/JuliaHealth/komamripy"
|
|
29
|
+
Repository = "https://github.com/JuliaHealth/komamripy"
|
|
30
|
+
Issues = "https://github.com/JuliaHealth/komamripy/issues"
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
test = ["pytest", "numpy"]
|
|
34
|
+
lint = ["ruff"]
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["hatchling"]
|
|
38
|
+
build-backend = "hatchling.build"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["komamripy"]
|
|
42
|
+
|
|
43
|
+
[tool.ruff.lint]
|
|
44
|
+
select = ["E", "F", "I", "W", "B", "UP"]
|
|
45
|
+
|
|
46
|
+
[tool.hatch.version]
|
|
47
|
+
path = "komamripy/__init__.py"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Integration tests that exercise the Julia/KomaMRI backend end to end.
|
|
2
|
+
Thorough tests to check functionality.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
import komamripy as km
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_epi_simulation_returns_signal():
|
|
11
|
+
sys = km.Scanner()
|
|
12
|
+
obj = km.brain_phantom2D()
|
|
13
|
+
seq = km.PulseDesigner.EPI_example()
|
|
14
|
+
|
|
15
|
+
sim_params = km.KomaMRICore.default_sim_params()
|
|
16
|
+
sim_params["return_type"] = "mat"
|
|
17
|
+
|
|
18
|
+
signal = np.asarray(km.simulate(obj, seq, sys, sim_params=sim_params))
|
|
19
|
+
|
|
20
|
+
assert np.iscomplexobj(signal)
|
|
21
|
+
assert signal.shape[0] == 10201
|