espirit 0.1.0__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.
@@ -0,0 +1,70 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.x"
28
+
29
+ - name: Build release distributions
30
+ run: |
31
+ # NOTE: put your own distribution build steps here.
32
+ python -m pip install build
33
+ python -m build
34
+
35
+ - name: Upload distributions
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: release-dists
39
+ path: dist/
40
+
41
+ pypi-publish:
42
+ runs-on: ubuntu-latest
43
+ needs:
44
+ - release-build
45
+ permissions:
46
+ # IMPORTANT: this permission is mandatory for trusted publishing
47
+ id-token: write
48
+
49
+ # Dedicated environments with protections for publishing are strongly recommended.
50
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51
+ environment:
52
+ name: pypi
53
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54
+ # url: https://pypi.org/p/YOURPROJECT
55
+ #
56
+ # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57
+ # ALTERNATIVE: exactly, uncomment the following line instead:
58
+ # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
59
+
60
+ steps:
61
+ - name: Retrieve release distributions
62
+ uses: actions/download-artifact@v4
63
+ with:
64
+ name: release-dists
65
+ path: dist/
66
+
67
+ - name: Publish release distributions to PyPI
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ packages-dir: dist/
espirit-0.1.0/LICENSE ADDED
@@ -0,0 +1,60 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oscar van der Heide
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.
22
+
23
+ ---
24
+
25
+ ### Third-Party Software Attribution
26
+
27
+ This package contains a PyTorch translation of the ESPIRiT implementation from the
28
+ BART (Berkeley Advanced Reconstruction Toolbox):
29
+ https://codeberg.org/mrirecon/bart
30
+
31
+ Portions of this code are:
32
+ Copyright (c) 2013-2026. The Regents of the University of California.
33
+ Copyright (c) 2013-2026. BART Developer Team and Contributors.
34
+
35
+ BART is licensed under the BSD 3-Clause License:
36
+
37
+ Redistribution and use in source and binary forms, with or without
38
+ modification, are permitted provided that the following conditions are met:
39
+
40
+ 1. Redistributions of source code must retain the above copyright notice, this
41
+ list of conditions and the following disclaimer.
42
+
43
+ 2. Redistributions in binary form must reproduce the above copyright notice,
44
+ this list of conditions and the following disclaimer in the documentation
45
+ and/or other materials provided with the distribution.
46
+
47
+ 3. Neither the name of the copyright holder nor the names of its contributors
48
+ may be used to endorse or promote products derived from this software without
49
+ specific prior written permission.
50
+
51
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
52
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
53
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
55
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
57
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
58
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
espirit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: espirit
3
+ Version: 0.1.0
4
+ Summary: PyTorch-based ESPIRiT coil sensitivity calibration for MRI
5
+ Project-URL: Repository, https://github.com/oscarvanderheide/espirit
6
+ Author: Oscar van der Heide
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Keywords: coil-sensitivity,csm,espirit,medical-imaging,mri,pytorch
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: numpy>=2.0
16
+ Requires-Dist: torch>=2.0
17
+ Description-Content-Type: text/markdown
18
+
19
+ # ESPIRiT
20
+
21
+ PyTorch-based ESPIRiT coil sensitivity calibration for MRI.
22
+
23
+ Single codebase that runs on **CPU**, **CUDA GPU**, and **Apple Silicon (MPS)** — no separate code paths needed.
24
+
25
+ ## Notice
26
+
27
+ This package contains a PyTorch translation of the ESPIRiT implementation from the BART (Berkeley Advanced Reconstruction Toolbox), © 2013–2026 The Regents of the University of California and BART Developer Team. BART is licensed under the BSD 3-Clause License. See https://codeberg.org/mrirecon/bart.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ uv add espirit
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Command Line
38
+ ```bash
39
+ uvx espirit kspace.npy
40
+ ```
41
+
42
+ ### Python API
43
+ ```python
44
+ import numpy as np
45
+ import torch
46
+ from espirit import espirit
47
+
48
+ # NumPy
49
+ kspace_np = np.load("kspace.npy")
50
+ csm_np = espirit(kspace_np)
51
+
52
+ # PyTorch
53
+ kspace_torch = torch.randn(8, 24, 24, 24, dtype=torch.complex64)
54
+ csm_torch = espirit(kspace_torch)
55
+ ```
56
+
57
+ ### Advanced
58
+ All arguments for the `espirit()` function:
59
+ ```python
60
+ csm = espirit(
61
+ kspace, # (n_coils, *spatial_dims)
62
+ calib_size=24, # size of calibration region
63
+ kernel_size=6, # sliding-window kernel size
64
+ threshold=0.01, # relative singular-value threshold
65
+ mask_threshold=0.8, # eigenvalue mask threshold
66
+ normalize=True, # RSS=1 normalization
67
+ rotphase=True, # remove global phase ambiguity
68
+ device=None # auto-detect (cuda, mps, cpu)
69
+ )
70
+ ```
71
+
72
+ ## Device support
73
+
74
+ | Device | Backend | Notes |
75
+ |--------|---------|-------|
76
+ | `cpu` | NumPy/MKL | Always available |
77
+ | `cuda` | NVIDIA GPU | Requires CUDA toolkit |
78
+ | `mps` | Apple Metal | macOS with Apple Silicon |
79
+
80
+ The same code runs on all devices — PyTorch handles dispatch automatically.
@@ -0,0 +1,62 @@
1
+ # ESPIRiT
2
+
3
+ PyTorch-based ESPIRiT coil sensitivity calibration for MRI.
4
+
5
+ Single codebase that runs on **CPU**, **CUDA GPU**, and **Apple Silicon (MPS)** — no separate code paths needed.
6
+
7
+ ## Notice
8
+
9
+ This package contains a PyTorch translation of the ESPIRiT implementation from the BART (Berkeley Advanced Reconstruction Toolbox), © 2013–2026 The Regents of the University of California and BART Developer Team. BART is licensed under the BSD 3-Clause License. See https://codeberg.org/mrirecon/bart.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ uv add espirit
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Command Line
20
+ ```bash
21
+ uvx espirit kspace.npy
22
+ ```
23
+
24
+ ### Python API
25
+ ```python
26
+ import numpy as np
27
+ import torch
28
+ from espirit import espirit
29
+
30
+ # NumPy
31
+ kspace_np = np.load("kspace.npy")
32
+ csm_np = espirit(kspace_np)
33
+
34
+ # PyTorch
35
+ kspace_torch = torch.randn(8, 24, 24, 24, dtype=torch.complex64)
36
+ csm_torch = espirit(kspace_torch)
37
+ ```
38
+
39
+ ### Advanced
40
+ All arguments for the `espirit()` function:
41
+ ```python
42
+ csm = espirit(
43
+ kspace, # (n_coils, *spatial_dims)
44
+ calib_size=24, # size of calibration region
45
+ kernel_size=6, # sliding-window kernel size
46
+ threshold=0.01, # relative singular-value threshold
47
+ mask_threshold=0.8, # eigenvalue mask threshold
48
+ normalize=True, # RSS=1 normalization
49
+ rotphase=True, # remove global phase ambiguity
50
+ device=None # auto-detect (cuda, mps, cpu)
51
+ )
52
+ ```
53
+
54
+ ## Device support
55
+
56
+ | Device | Backend | Notes |
57
+ |--------|---------|-------|
58
+ | `cpu` | NumPy/MKL | Always available |
59
+ | `cuda` | NVIDIA GPU | Requires CUDA toolkit |
60
+ | `mps` | Apple Metal | macOS with Apple Silicon |
61
+
62
+ The same code runs on all devices — PyTorch handles dispatch automatically.
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "espirit"
7
+ version = "0.1.0"
8
+ description = "PyTorch-based ESPIRiT coil sensitivity calibration for MRI"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ authors = [
12
+ { name = "Oscar van der Heide" }
13
+ ]
14
+ license = { text = "MIT" }
15
+ keywords = ["espirit", "csm", "coil-sensitivity", "mri", "medical-imaging", "pytorch"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Science/Research",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ ]
22
+
23
+ dependencies = [
24
+ "torch>=2.0",
25
+ "numpy>=2.0",
26
+ ]
27
+
28
+ [project.scripts]
29
+ espirit = "espirit.espirit:main"
30
+
31
+ [project.urls]
32
+ Repository = "https://github.com/oscarvanderheide/espirit"
33
+
34
+ [tool.hatch.build.targets.wheel]
35
+ packages = ["src/espirit"]
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "pytest>=8.0",
40
+ ]
@@ -0,0 +1,17 @@
1
+ """ESPIRiT — PyTorch-based coil sensitivity calibration for MRI."""
2
+
3
+ from .device import available_devices, select_device
4
+ from .espirit import espirit
5
+ from .fft import fft2c, fft3c, ifft2c, ifft3c
6
+
7
+ __version__ = "0.1.0"
8
+
9
+ __all__ = [
10
+ "espirit",
11
+ "select_device",
12
+ "available_devices",
13
+ "fft2c",
14
+ "fft3c",
15
+ "ifft2c",
16
+ "ifft3c",
17
+ ]
@@ -0,0 +1,39 @@
1
+ """Device selection utilities for ESPIRiT."""
2
+
3
+ import torch
4
+
5
+
6
+ def select_device(preference: str | None = None) -> torch.device:
7
+ """
8
+ Select the best available torch device.
9
+
10
+ Priority: cuda > mps > cpu (unless overridden by *preference*).
11
+
12
+ Parameters
13
+ ----------
14
+ preference : str, optional
15
+ Force a specific device ("cpu", "cuda", "mps").
16
+ When None, auto-detects the best available.
17
+
18
+ Returns
19
+ -------
20
+ torch.device
21
+ """
22
+ if preference is not None:
23
+ return torch.device(preference)
24
+
25
+ if torch.cuda.is_available():
26
+ return torch.device("cuda")
27
+ if torch.backends.mps.is_available():
28
+ return torch.device("mps")
29
+ return torch.device("cpu")
30
+
31
+
32
+ def available_devices() -> list[torch.device]:
33
+ """Return a list of all available torch devices (for testing)."""
34
+ devices = [torch.device("cpu")]
35
+ if torch.cuda.is_available():
36
+ devices.append(torch.device("cuda"))
37
+ if torch.backends.mps.is_available():
38
+ devices.append(torch.device("mps"))
39
+ return devices