From 4dd3b0658cc328a3db5c78119f87d7e21c24517b Mon Sep 17 00:00:00 2001 From: Jonathan Endres Date: Wed, 11 Nov 2026 11:15:31 +0100 Subject: [PATCH 1/2] build: support Python >= 3.10 and make heavy dependencies optional bifti 0.3.1 supports Python 3.10, so the requirement is relaxed from >= 3.12 to >= 3.10. Tested in fresh venvs on Python 3.10 - 3.15. - replace typing.Self (3.11+) with a string annotation - bump bifti to >= 0.3.1 and declare numpy, which is imported directly - add tested minimum versions: nibabel >= 5.2, numpy >= 1.22 - move scikit-image and torchkbnufft, which MRzeroCore never imports, to the new `playground` extra - move ismrmrd to the new `mrd` extra (>= 1.14.1, older versions break with current xsdata). Its h5py dependency has no wheels for some environments, e.g. Python 3.15. ismrmrd is imported lazily, so `import MRzeroCore` works without it and sig_to_mrd raises an ImportError that names the extra. Co-Authored-By: Claude Opus 5.5 --- documentation/src/api-unsorted.md | 2 ++ pyproject.toml | 24 +++++++++++----- python/MRzeroCore/phantom/tissue_dict.py | 4 +-- python/MRzeroCore/simulation/sig_to_mrd.py | 32 ++++++++++++++++------ 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/documentation/src/api-unsorted.md b/documentation/src/api-unsorted.md index d8aa377..17e0933 100644 --- a/documentation/src/api-unsorted.md +++ b/documentation/src/api-unsorted.md @@ -21,6 +21,8 @@ The configuration files with the used tissue parameters can be found here: [brai Write the simulation output to an [ISMRMD](https://github.com/ismrmrd/ismrmrd) file; supported by many reconstruction tools. +Requires the optional `ismrmrd` dependency: `pip install mrzerocore[mrd]`. + | Parameter | Description | | --------- | ----------- | | `mrd_path` | path where the file will be written to | diff --git a/pyproject.toml b/pyproject.toml index 0b0e7a4..8c9a11f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,29 +13,39 @@ readme = "README.md" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Programming Language :: Python :: Implementation :: PyPy", "License :: OSI Approved :: GNU Affero General Public License v3", ] -requires-python = ">=3.12" +requires-python = ">=3.10" dependencies = [ - "bifti>=0.3.0", - "ismrmrd", + "bifti>=0.3.1", "matplotlib>=3.5", + "nibabel>=5.2", + "numpy>=1.22", "pydisseqt>=0.1.13", - "pypulseq", + "pypulseq", "requests>=2.20", - "scikit-image", "scipy>=1.7", - "torchkbnufft", "torch>=1.12", "tqdm", - "nibabel", ] # --- OPTIONAL INSTALLS --- [project.optional-dependencies] # to select pypulseq 1.4 or <1.5 use pip install mrzerocore[pp14] pp15 = ["pypulseq"] +# ISMRMRD export (mr0.sig_to_mrd); optional because h5py lacks wheels for some environments +mrd = ["ismrmrd>=1.14.1"] +# Not used by MRzeroCore itself, only by some of the playground notebooks +playground = ["scikit-image", "torchkbnufft"] [project.urls] Repository = "https://github.com/MRsources/MRzero-Core" diff --git a/python/MRzeroCore/phantom/tissue_dict.py b/python/MRzeroCore/phantom/tissue_dict.py index 428b4e4..279f845 100644 --- a/python/MRzeroCore/phantom/tissue_dict.py +++ b/python/MRzeroCore/phantom/tissue_dict.py @@ -5,7 +5,7 @@ import torch import numpy as np import matplotlib.pyplot as plt -from typing import Literal, Self +from typing import Literal class TissueDict(dict[str, VoxelGridPhantom]): @@ -158,7 +158,7 @@ def build(self, PD_threshold: float = 1e-6, return SimData(**kwargs) - def recover(self, sim_data: SimData) -> Self: + def recover(self, sim_data: SimData) -> "TissueDict": """Provided to :class:`SimData` to reverse the ``build()``""" assert sim_data.tissue_masks is not None diff --git a/python/MRzeroCore/simulation/sig_to_mrd.py b/python/MRzeroCore/simulation/sig_to_mrd.py index 6343ca9..be4bdde 100644 --- a/python/MRzeroCore/simulation/sig_to_mrd.py +++ b/python/MRzeroCore/simulation/sig_to_mrd.py @@ -1,18 +1,28 @@ +from __future__ import annotations + import os -import ismrmrd import numpy as np import pypulseq as pp import torch from tqdm import tqdm +# ismrmrd (and its h5py dependency) is an optional dependency, only needed for +# MRD export: install with `pip install mrzerocore[mrd]`. +try: + import ismrmrd +except ImportError as e: + ismrmrd = None + _ISMRMRD_IMPORT_ERROR = e + +# Pulseq ADC label -> name of the ISMRMRD acquisition flag PULSEQ_MRD_FLAGS = { - "NAV": ismrmrd.ACQ_IS_PHASECORR_DATA, - "REV": ismrmrd.ACQ_IS_REVERSE, - "REF": ismrmrd.ACQ_IS_PARALLEL_CALIBRATION, - "IMA": ismrmrd.ACQ_IS_PARALLEL_CALIBRATION_AND_IMAGING, - "NOISE": ismrmrd.ACQ_IS_NOISE_MEASUREMENT, - "PMC": ismrmrd.ACQ_IS_RTFEEDBACK_DATA, + "NAV": "ACQ_IS_PHASECORR_DATA", + "REV": "ACQ_IS_REVERSE", + "REF": "ACQ_IS_PARALLEL_CALIBRATION", + "IMA": "ACQ_IS_PARALLEL_CALIBRATION_AND_IMAGING", + "NOISE": "ACQ_IS_NOISE_MEASUREMENT", + "PMC": "ACQ_IS_RTFEEDBACK_DATA", } @@ -38,6 +48,12 @@ def sig_to_mrd( verbose : int, optional Logging verbosity level from 0 (silent) to 5 (most detailed). Default is 0. """ + if ismrmrd is None: + raise ImportError( + "sig_to_mrd requires the optional 'ismrmrd' package: " + "pip install mrzerocore[mrd] (or: pip install ismrmrd)" + ) from _ISMRMRD_IMPORT_ERROR + # Convert signal tensor to NumPy for ISMRMRD compatibility mr0_signal_numpy = mr0_signal.detach().cpu().numpy() @@ -233,7 +249,7 @@ def _labels_to_acq_head( for key, item in PULSEQ_MRD_FLAGS.items(): label_value = seq_labels.get(key, 0) if label_value > 0: - acq_head.set_flag(item) + acq_head.set_flag(getattr(ismrmrd, item)) return acq_head From da9e847875173c91a0368c401bbcb8a5f2472d37 Mon Sep 17 00:00:00 2001 From: Jonathan Endres Date: Wed, 11 Nov 2026 11:15:46 +0100 Subject: [PATCH 2/2] chore: update version number to 1.4.0 and changelog Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- pyproject.toml | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b22b007..6065b49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +- 1.4.0 + - requires Python >= 3.10 again (was >= 3.12), now that `bifti` 0.3.1 supports Python 3.10; tested on Python 3.10 - 3.15 + - `scikit-image` and `torchkbnufft` are no longer installed by default (they are not used by MRzeroCore itself); install them with `pip install mrzerocore[playground]` + - `ismrmrd` is now an optional dependency, only needed for `sig_to_mrd`: install it with `pip install mrzerocore[mrd]`. Without it, `sig_to_mrd` raises an `ImportError`; everything else works. This avoids building `h5py` from source where no wheels exist (e.g. Python 3.15) + - `numpy` is now a declared dependency; minimum versions: `bifti>=0.3.1`, `nibabel>=5.2`, `numpy>=1.22`, `ismrmrd>=1.14.1` (with `[mrd]`) - 1.3.0 - use the official [`bifti`](https://pypi.org/project/bifti/) package for BIfTI phantoms instead of the internal implementation (#201). `NiftiPhantom`, `NiftiTissue` and `ResliceConfig` are now aliases of `bifti.BiftiPhantom`, `bifti.BiftiTissue` and `bifti.ResliceTo`; `TissueDict.load` uses the `bifti` loader (density-weighted resampling, `patient` position support, complex B1 maps, `func` mappings are parsed instead of `eval`ed) - `TissueDict.save` uses `bifti.NumpyPhantom.save`: NIfTIs are named `_.nii.gz` (e.g. `phantom_B1plus_0.nii.gz`) and stored as float64 / complex128; the `.json` no longer contains `reslice_to` diff --git a/Cargo.lock b/Cargo.lock index 4bde265..ea26301 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,7 +67,7 @@ dependencies = [ [[package]] name = "mrzero_core" -version = "1.3.0" +version = "1.4.0" dependencies = [ "num-complex", "pulseq-rs", diff --git a/Cargo.toml b/Cargo.toml index 46a2a11..ff4a82c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mrzero_core" -version = "1.3.0" +version = "1.4.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/pyproject.toml b/pyproject.toml index 8c9a11f..0f86e50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "mrzerocore" -version = "1.3.0" +version = "1.4.0" description = "Core functionality of MRzero" authors = [ {name = "Jonathan Endres", email = "jonathan.endres@uk-erlangen.de"},