Skip to content

andrewendlinger/xmris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

129 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xmris logo

A modern, N-dimensional, xarray-based toolbox for Magnetic Resonance Imaging and Spectroscopy.

MyST GitHub Pages Deploy Tests codecov
uv Ruff Python Versions License: AGPL v3

01. Documentation

Documentation, tutorials, and API reference can be found here.

02. Overview

xmris bridges the gap between modern data structures and magnetic resonance research. By building on top of xarray, it provides a robust environment for handling multi-dimensional MRI and MRS data with labeled coordinates, powerful broadcasting, and seamless integration with the scientific Python ecosystem.

Key Features:

  • N-Dimensional Data: Native handling of complex MRI/MRS datasets using xarray.
  • MRS Integration: Direct compatibility with tools like pyAMARES and nmrglue.
  • Modern Tooling: Built for speed and reliability, developed using uv and strictly typed for modern Python environments.

03. Installation

You can install the package directly from PyPI using standard package managers:

# Using pip
pip install xmris

# Using uv (recommended)
uv add xmris

04. Quick Start

import numpy as np
import xarray as xr
import xmris  # Registers the .xmr accessor!

# 1. Create a dummy N-dimensional FID (e.g., 5 Voxels x 1024 Time points)
time = np.linspace(0, 1, 1024)
data = np.random.randn(5, 1024) + 1j * np.random.randn(5, 1024)

mrsi_data = xr.DataArray(
    data,
    dims=["voxel", "time"],
    coords={"voxel": np.arange(5), "time": time},
    attrs={"MHz": 120.0, "sw": 10000.0}
)

# 2. Process all voxels simultaneously using the .xmr accessor!
results = (
    mrsi_data
    .xmr.zero_fill(target_points=2048)
    .xmr.apodize_exp(lb=5.0)
    .xmr.to_spectrum()
    .xmr.autophase()
)

05. Development

We use uv for lightning-fast dependency management and Ruff for linting/formatting. To set up a local development environment:

  1. Fork this repository and then clone your version of this repository.

  2. Sync the environment and install dependencies:

uv sync
  1. Run tests via pytest (which includes notebook testing via nbmake):
uv run test
  1. Build the MyST based documentation :
uv run docs

More information can be found in the documentation here


License & Commercial Use

xmris is licensed under the GNU Affero General Public License v3.0 (AGPLv3).