komamripy 0.0.2__py3-none-any.whl

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/__init__.py ADDED
@@ -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
komamripy/_session.py ADDED
@@ -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,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
+ [![CI](https://github.com/JuliaHealth/komamripy/actions/workflows/ci.yml/badge.svg?branch=main)](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,7 @@
1
+ komamripy/__init__.py,sha256=YViFE3kuJoDAvNozq3uWqAufSAoFPZe7M_Xm_7x-gmM,1913
2
+ komamripy/_session.py,sha256=EIn551Vy6XZ8SzypnNooDhbhTuQJdk_a20CwDJRoSBY,1037
3
+ komamripy/juliapkg.json,sha256=iNHgvxPnP3VTkpA3iopiuwrybCcaRKkVOALlTZqo6GY,566
4
+ komamripy-0.0.2.dist-info/METADATA,sha256=UqTBkvWj7CAf0cGHNGpU8J9q9dp6LDxK6FJHRudebkg,3101
5
+ komamripy-0.0.2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
6
+ komamripy-0.0.2.dist-info/licenses/LICENSE,sha256=ki-YGkgdVygl8ObgkPEvgSJK57-R8gLO29vfS80w8GM,1078
7
+ komamripy-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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.