Lightweight Python wrapper for LCModel MRS fitting
Project description
PyLCModel is a lightweight Python wrapper that streamlines the use of LCModel for least-squares spectral fitting in MRS. It automates control-file generation, handles flexible data input, manages the LCModel executable for you, and parses the output (with single- and multi-core processing).
Features
- Zero-setup binaries — the LCModel executable is resolved automatically (download, build from source, or your own path); nothing is bundled in the wheel.
- Flexible input — NumPy arrays, NIfTI-MRS, jMRUI text, and LCModel
.RAW, in time or frequency domain. - Automated control files — generated to match your data, or templated from an existing one.
- Basis conversion (experimental) — jMRUI, FSL-MRS, LCModel
.RAW, and Osprey/FID-A basis sets to.basis. - Batch fitting — single- or multi-core, with full output parsing (concentrations, CRLBs, QC, fitted series).
Installation
From PyPI
pip install lcmodel-wrapper
Enter your API token:
From Source
git clone https://github.com/julianmer/PyLCModel.git
cd PyLCModel
pip install -e .
How the LCModel binary is handled
The LCModel program is not part of this package and is not shipped in the wheel. On first use, the binary is resolved in this order:
- an explicit
path2exec="/path/to/lcmodel"you pass toPyLCModel, - a previously cached download/build (under
~/.cache/lcmodel_wrapper, or%LOCALAPPDATA%on Windows; override withLCMODEL_CACHE_DIR), - a download of the matching binary for your OS/architecture from schorschinho/LCModel,
- a build from the LCModel Fortran source via
gfortran(source fetched on demand).
There is no git submodule and no bundled lcmodel/ folder — keeping both the repository and the PyPI wheel small.
Getting Started
from lcmodel_wrapper import PyLCModel
# Initialize the wrapper with your basis set (the LCModel binary is resolved automatically)
lcmodel = PyLCModel(path2basis="/path/to/your/basis_set.basis")
# `data` can be a NumPy array of FIDs (time domain), a NIfTI-MRS path, etc.
concentrations, crlbs = lcmodel(data)
print("Fitted Metabolite Concentrations:", concentrations)
print("CRLBs:", crlbs)
Frequency-domain input or a custom executable:
lcmodel = PyLCModel(
path2basis="/path/to/basis.basis",
domain="freq", # pass spectra instead of FIDs
path2exec="/path/to/lcmodel", # optional: use your own binary
)
Experimental basis conversion (other formats -> .basis):
# Auto-detect the source format (jMRUI/AQSES/QUEST .txt folder, FSL-MRS .json folder,
# LCModel .RAW folder, or Osprey/FID-A .mat):
lcmodel = PyLCModel(path2basis="/path/to/basis_folder", convert_basis=True)
# ...or force a format and supply parameters the source does not carry:
lcmodel = PyLCModel(
path2basis="/path/to/raw_folder",
convert_basis=True,
basis_format="raw", # "jmrui" | "fsl" | "raw" | "mat"
bandwidth=4000, central_freq=123.25,
)
# Or convert directly without fitting:
from lcmodel_wrapper import convert_to_basis
convert_to_basis("/path/to/jmrui_folder", out_path="out.basis")
Basis conversion is experimental and not validated. For a dedicated, more complete tool, see the MRS Basis Set Conversion Toolbox.
Licensing
This wrapper (the Python code) is released under the Apache License 2.0 (see LICENSE).
LCModel itself is a separate program by Dr. Stephen Provencher, distributed under the BSD 3-Clause License (see LICENSE.lcmodel). This package does not bundle LCModel; when it downloads, builds, or runs the LCModel executable, that BSD-3-Clause license and the attributions in NOTICE apply. See the LCModel home page for details.
Acknowledgements
- LCModel binaries: schorschinho/LCModel (Georg Oeltzschner and contributors)
- Basis conversion reference: MRS Basis Set Conversion Toolbox (Kay Igwe)
- NIfTI-MRS: spec2nii, NIfTI-MRS Pyhton tools (Will Clarke)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lcmodel_wrapper-0.2.0.tar.gz.
File metadata
- Download URL: lcmodel_wrapper-0.2.0.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccff12c31e2152e9921361fc7ad24d8c7088dedafa6b4d21b3cd8ebb966a7cc0
|
|
| MD5 |
8bfd0193ddd72408193a54b7cc06a958
|
|
| BLAKE2b-256 |
4f7957037288c297f5e526238e60eb935daa24a792ffa10544a30dd42b5fe1e1
|
File details
Details for the file lcmodel_wrapper-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lcmodel_wrapper-0.2.0-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
043810bb6f80d2e4bf41bd5f46d344fadf95edcc7f57e31c014806064bdaee2b
|
|
| MD5 |
02cf1b0b1ac860878386ce691f4ccb33
|
|
| BLAKE2b-256 |
9663233e0a50b62e7dce0dac13e899b3f62b89b857bdde7bbec55d64cf48a93d
|