Metadata-Version: 2.5
Name: spinsight
Version: 1.4.0
Summary: MR image simulator for teaching purposes
Project-URL: Homepage, http://spinsight.surgsci.uu.se/
Project-URL: Repository, https://github.com/bretglun/spinsight
Author-email: Johan Berglund <berglund.hpj@gmail.com>
License-Expression: GPL-3.0-or-later
License-File: LICENSE.md
Requires-Python: >=3.10
Requires-Dist: darkdetect>=0.8.0
Requires-Dist: finufft>=2.4.1
Requires-Dist: holoviews>=1.21.0
Requires-Dist: mri-nufft>=1.2.1
Requires-Dist: numpy>=2.2.6
Requires-Dist: panel>=1.8.2
Requires-Dist: param>=2.2.1
Requires-Dist: scipy>=1.15.3
Requires-Dist: svgpathtools>=1.7.1
Requires-Dist: toml>=0.10.2
Requires-Dist: xarray>=2025.6.1
Description-Content-Type: text/markdown

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

![](docs/images/demo.webp)

# SpinSight MRI simulator
SpinSight is an MRI simulator written in Python and created for educational purposes. 
It jointly visualizes the imaging parameters, the MRI pulse sequence, the k-space data matrix, and the MR image. 
These are updated in near real-time when the user changes parameters. 
The simulator is run as a web browser dashboard. 
The data is simulated from computational 2D phantoms in vector graphics format (SVG).

## Starting the Simulator
Install using pip: 
```
pip install spinsight
```
Then run as a command line tool
```
spinsight
```
This serves SpinSight on the local host, and opens a web browser at [localhost](http://localhost) (browser popup can be suppressed using the `-b` flag). 
Be aware that several minutes may be required upon loading a phantom for the first time.

Other command line flags include `-l` to get continuous updates when dragging input parameter sliders, and `-t` to get text input boxes next to sliders for increased control. 
There are also flags to deploy the simulator on a local network, or on a web server. Run `spinsight -h` to display all command line options.

## Usage
The simulated MR image is updated instantly as input parameter are changed. 
This is also true for the *k*-space plot and pulse sequence diagram (they are hidden by default, but can be shown using the buttons to the top left). 
This enables easy exploration of how different imaging parameters affect the pulse sequence, the *k*-space data, and the MR image.
The plots can be navigated through scrolling (zooming) and dragging (panning).

A sidebar menu can be exposed by clicking the ☰ icon left of the title. 
Here, you can load preset parameters and change the computational phantom, the field strength, and the input parameter style (reflecting different MRI vendors).
You can also enable "help mode" by clicking the (?)-icon, which displays a help icon next to each parameter.
Hover the help icons to read explanations of each parameter.

A more comprehensive list of features is provided in the paper ([see How to cite](#how-to-cite)).

## Phantom construction
To create a new phantom, add a directory with the phantom name under [spinsight/phantoms](./spinsight/phantoms). 
This directory shall contain files with the same name as the directory. Two formats are supported:

### A single `.toml` file
The file shall consist of a list of shapes (see [Shepp-Logan_shapes.toml](./spinsight/phantoms/Shepp-Logan/Shepp-Logan.toml) for reference). 
Each shape is assigned a tissue type which must be defined in the `TISSUES` dict in [constants.py](./spinsight/constants.py).

### A pair of `.toml` and `.svg` files
The `.toml` file specifies a mapping from hexcolors to tissues (see [brain.toml](./spinsight/phantoms/brain/brain.toml) for reference). 
The tissues must be defined in the `TISSUES` dict in [constants.py](./spinsight/constants.py).

The specified `.svg` file must meet the following specifications:
* All paths must be closed
* All paths must have a fill color matching a hexcolor defined in the `.toml` file (this defines the tissue).
* Only polygons are supported (not Bézier curves etc.)


## Dependencies
See [pyproject.toml](./pyproject.toml), *dependencies* under heading **[project]**. 

## How to cite
If you use this software in your research, please cite:

> Berglund J. "SpinSight – an Educational Open-Source MRI Simulator". *Magnetic Resonance in Medicine*, 2026. [DOI: 10.1002/mrm.70694]

## License
SpinSight is distributed under the terms of the GNU General Public License. See [LICENSE.md](./LICENSE.md).

## Contact Information
Johan Berglund, Ph.D.  
Uppsala University Hospital,  
Uppsala, Sweden.  
johan.berglund@akademiska.se

---
Copyright © 2021–2026 Johan Berglund.