How hmella/feelmri works
1. Project shape
- FEelMRI is a Python-first scientific imaging library with a compiled C++ backend.
- The core purpose is to turn finite-element simulation data into synthetic MRI signals and reconstructed images.
2. Top-level execution model
- Users typically run Python example scripts from examples/, often under mpirun.
- Inputs come from parameter YAML files, phantom datasets, and optionally FE mesh/solution data.
- Outputs are simulated MR signals, k-space data, and reconstructed images/plots.
3. Python package is the orchestration layer
- python/feelmri/ contains the main application logic and most of the user-facing API.
- Modules are split by concern: physics (Bloch.py, Motion.py), acquisition (KSpaceTraj.py, MRImaging.py), reconstruction (Recon.py), data models (MRObjects.py, Phantom.py), configuration (Parameters.py), I/O (IO.py), filtering/noise/math (Filters.py, Noise.py, Math.py), plotting (Plotter.py), and MPI support (MPIUtilities.py).
4. Physics and signal simulation boundary
- Bloch.py and Motion.py represent the MRI physics layer, including spin evolution and motion effects.
- This layer sits between the FE simulation domain and the acquisition domain: it transforms spatial/temporal state into MR signal evolution.
- The README’s emphasis on PDE-driven FE simulations and arbitrary cell geometries matches this boundary.
5. Compiled C++ backend
- cpp/feelmri/ provides performance-critical implementation for assembly and Bloch simulation.
- Key components include BlochSimulator, Assemble, MRIAssemble, PODHelper, and FEUtils.
- This backend is likely the bridge between discrete FE data structures and efficient numerical MR simulation, exposed to Python as an extension module built with CMake.
6. Data model and configuration flow
- Parameters.py and the YAML files in examples/parameters/ define experiment setup: sequence parameters, trajectories, phantoms, and reconstruction settings.
- MRObjects.py provides the structured objects passed through the pipeline.
- Phantom.py and the files in examples/phantoms/ provide synthetic anatomy/material distributions used as simulation sources.
7. Acquisition pipeline
- KSpaceTraj.py defines k-space sampling trajectories.
- MRImaging.py coordinates the simulated acquisition using the chosen sequence, trajectory, and physics modules.
- The output of this stage is typically complex-valued signal or k-space measurements rather than final images.
8. Reconstruction and post-processing
- Recon.py converts simulated acquisition data into image-space outputs.
- Filters.py, Noise.py, and Math.py support signal conditioning and numerical utilities around the main reconstruction path.
- Plotter.py is used for visual inspection and result generation, especially in the example workflows.
9. MPI and parallel execution
- MPIUtilities.py and the README’s mpirun instructions indicate the simulation is designed to scale across multiple processes.
- Parallelism is an architectural boundary: examples are run in distributed fashion, and tests include test_parallel.py.
- This matters for diagramming because simulation work is not single-process-only; it is expected to be partitioned across cores.
10. Examples as system demonstrations
- examples/ is not just documentation; it is the main integration surface showing end-to-end use cases.
- The scripts cover distinct MRI scenarios: 4dflow.py, free_running.py, phase_contrast.py, spamm.py, water_and_fat.py, and others.
- The examples/planning/ ParaView state files and scripts support FOV planning and geometry setup before simulation.
11. Build and deployment boundaries
- The repo uses pyproject.toml plus CMakeLists.txt to combine Python packaging with a native extension build.
- docker/Dockerfile provides a reproducible Linux container for the full stack, including MPI and GUI-capable plotting if needed.
- CI in .github/workflows/ci.yml and tests under tests/ validate imports, example execution, and parallel behavior.
12. End-to-end architecture summary
- The main flow is: configuration/phantom/FE data in → Python orchestration → C++-accelerated FE/Bloch computation → k-space acquisition → reconstruction/post-processing → images/plots out.
- The important boundary is between the scientific Python orchestration layer and the native C++ numerical backend.
- A second boundary is between simulation and visualization/planning tooling, which is provided but separate from the core computation path.
Main entry points: MRImaging.py MR Imaging · 4dflow.py Example Suite · Recon.py Recon · Parameters.py Parameters
Components 22
Python package
User-facing orchestration layer and scientific MRI pipeline modules.
- Parameters · Experiment setup, sequence options, and runtime configuration objects.
python/feelmri/Parameters.py - MR Objects · Structured objects passed through acquisition and reconstruction stages.
python/feelmri/MRObjects.py - Phantom · Synthetic anatomy and material distributions used as simulation inputs.
python/feelmri/Phantom.py - Bloch · MRI spin evolution and signal formation logic in Python.
python/feelmri/Bloch.py - Motion · Motion and deformation effects coupled into the simulated signal.
python/feelmri/Motion.py - K-space Traj · Definitions of k-space sampling trajectories.
python/feelmri/KSpaceTraj.py - MR Imaging · Coordinates simulation of acquisition from physics, trajectory, and inputs.
python/feelmri/MRImaging.py - Recon · Converts simulated measurements into image-space outputs.
python/feelmri/Recon.py - IO · File loading and persistence for inputs and outputs.
python/feelmri/IO.py - Plotter · Visualization and result generation for simulations and examples.
python/feelmri/Plotter.py - MPI Utils · MPI-oriented helpers for distributed execution.
python/feelmri/MPIUtilities.py - Filters · Signal conditioning and filtering utilities.
python/feelmri/Filters.py - Noise · Noise models and perturbation utilities.
python/feelmri/Noise.py - Math · Numerical helper routines shared across the Python pipeline.
python/feelmri/Math.py
Native backend
C++ extension code for performance-critical finite-element and Bloch simulation work.
- Bloch Simulator · Native Bloch simulation implementation for performance-critical workloads.
cpp/feelmri/BlochSimulator.cpp - Assemble · Finite-element assembly routines for simulation inputs.
cpp/feelmri/Assemble.cpp - MRI Assemble · Native bridge from FE data structures to MRI-oriented assembly.
cpp/feelmri/MRIAssemble.cpp - POD Helper · Helper routines for low-dimensional numerical support paths.
cpp/feelmri/PODHelper.cpp
Examples
End-to-end workflows, parameters, phantoms, meshes, and planning assets.
- Example Suite · End-to-end executable scenarios demonstrating the main simulation pipeline.
examples/4dflow.py - Planning Assets · ParaView states and setup artifacts for geometry and field-of-view planning.
examples/planning/README.md
Build and CI
Packaging, native build, containerization, and validation infrastructure.
- Build System · Python packaging plus native build integration.
CMakeLists.txt - CI and Container · Automated validation and reproducible containerized runtime support.
.github/workflows/ci.yml
Connections 26
- Parameters → Phantom: configures · Parameters define the phantom and experiment setup.
- Parameters → K-space Traj: selects · Parameters specify the sampling trajectory and sequence settings.
- Parameters → MR Imaging: drives · Runtime options flow into the acquisition engine.
- Phantom → MR Imaging: feeds · Phantom data provides the simulated object being imaged.
- MR Objects → MR Imaging: structures · Shared objects carry experiment state into acquisition.
- Bloch → MR Imaging: physics · Bloch dynamics are used during signal simulation.
- Motion → MR Imaging: motion · Motion effects perturb acquisition and signal evolution.
- K-space Traj → MR Imaging: samples · Trajectory definition determines how k-space is traversed.
- MR Imaging → Recon: produces · Simulated measurements are passed to reconstruction.
- Recon → Plotter: visualized by · Reconstructed images are rendered for inspection.
- Filters → Recon: supports · Filtering assists reconstruction and post-processing.
- Noise → Recon: supports · Noise utilities model or adjust measurement contamination.
- Math → MR Imaging: supports · Shared numerical helpers support the simulation pipeline.
- Math → Recon: supports · Shared numerical helpers support reconstruction routines.
- MPI Utils → MR Imaging: parallelizes · MPI helpers support distributed simulation execution.
- Example Suite → Parameters: loads · Example scripts consume YAML parameter files.
- Example Suite → MR Imaging: runs · Examples execute the main simulation pipeline.
- Example Suite → Plotter: renders · Examples generate plots and result figures.
- Example Suite → MPI Utils: executes with · Examples are often launched under MPI.
- Planning Assets → Example Suite: supports · Planning assets prepare geometry and acquisition setup for examples.
- Assemble → MRI Assemble: feeds · Assembly routines underpin MRI-oriented native assembly.
- MRI Assemble → Bloch Simulator: supports · Native assembly and Bloch simulation cooperate in the backend.
- Build System → Bloch Simulator: builds · CMake integrates the native extension build.
- Build System → MR Imaging: packages · The build system packages the Python orchestration layer.
- CI and Container → Example Suite: validates · CI checks that examples run successfully.
- CI and Container → Build System: verifies · CI validates packaging and native build integration.