lcmodel-wrapper 0.1.2__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lcmodel_wrapper-0.3.0/LICENSE +202 -0
- lcmodel_wrapper-0.3.0/LICENSE.lcmodel +39 -0
- lcmodel_wrapper-0.3.0/MANIFEST.in +4 -0
- lcmodel_wrapper-0.3.0/NOTICE +24 -0
- lcmodel_wrapper-0.3.0/PKG-INFO +170 -0
- lcmodel_wrapper-0.3.0/README.md +147 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/__init__.py +31 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/_version.py +4 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/basis.py +100 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/binaries.py +749 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/container.py +163 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/control.py +120 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/convert.py +364 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/coord.py +136 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/core.py +424 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper/io.py +334 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper.egg-info/PKG-INFO +170 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper.egg-info/SOURCES.txt +33 -0
- lcmodel_wrapper-0.3.0/lcmodel_wrapper.egg-info/requires.txt +9 -0
- lcmodel_wrapper-0.3.0/pyproject.toml +42 -0
- lcmodel_wrapper-0.3.0/tests/test_binaries.py +470 -0
- lcmodel_wrapper-0.3.0/tests/test_lcm.py +92 -0
- lcmodel_wrapper-0.1.2/PKG-INFO +0 -62
- lcmodel_wrapper-0.1.2/README.md +0 -48
- lcmodel_wrapper-0.1.2/pyproject.toml +0 -31
- lcmodel_wrapper-0.1.2/src/lcmodel_wrapper/__init__.py +0 -1
- lcmodel_wrapper-0.1.2/src/lcmodel_wrapper/pylcmodel.py +0 -460
- lcmodel_wrapper-0.1.2/src/lcmodel_wrapper.egg-info/PKG-INFO +0 -62
- lcmodel_wrapper-0.1.2/src/lcmodel_wrapper.egg-info/SOURCES.txt +0 -10
- lcmodel_wrapper-0.1.2/src/lcmodel_wrapper.egg-info/requires.txt +0 -3
- lcmodel_wrapper-0.1.2/tests/test_lcm.py +0 -136
- {lcmodel_wrapper-0.1.2/src → lcmodel_wrapper-0.3.0}/lcmodel_wrapper.egg-info/dependency_links.txt +0 -0
- {lcmodel_wrapper-0.1.2/src → lcmodel_wrapper-0.3.0}/lcmodel_wrapper.egg-info/top_level.txt +0 -0
- {lcmodel_wrapper-0.1.2 → lcmodel_wrapper-0.3.0}/setup.cfg +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Julian Merkofer
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
LCModel license
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
This project (PyLCModel / lcmodel_wrapper) is a Python wrapper. It does NOT
|
|
5
|
+
contain the original LCModel program in its own copyright. LCModel is a separate
|
|
6
|
+
work distributed under the BSD 3-Clause License reproduced below. When the
|
|
7
|
+
wrapper downloads, builds, or otherwise redistributes the LCModel executable or
|
|
8
|
+
its Fortran source, the following license and notice apply to that component.
|
|
9
|
+
|
|
10
|
+
Copyright (c) 1992-2021, Stephen Provencher
|
|
11
|
+
All rights reserved.
|
|
12
|
+
|
|
13
|
+
Redistribution and use in source and binary forms, with or without
|
|
14
|
+
modification, are permitted provided that the following conditions are met:
|
|
15
|
+
|
|
16
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
17
|
+
list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
20
|
+
this list of conditions and the following disclaimer in the documentation
|
|
21
|
+
and/or other materials provided with the distribution.
|
|
22
|
+
|
|
23
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
24
|
+
contributors may be used to endorse or promote products derived from
|
|
25
|
+
this software without specific prior written permission.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
28
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
29
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
30
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
31
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
32
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
33
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
34
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
35
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37
|
+
|
|
38
|
+
Reference: S.W. Provencher (1993) Magn. Reson. Med. 30, 672-679.
|
|
39
|
+
LCModel home page: https://s-provencher.com/lcmodel.shtml
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
PyLCModel (lcmodel_wrapper)
|
|
2
|
+
Copyright (c) 2024 Julian P. Merkofer and contributors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
------------------------------------------------------------------------------
|
|
7
|
+
LCModel
|
|
8
|
+
------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
LCModel is NOT part of this project's copyright. It is a separate program by
|
|
11
|
+
Dr. Stephen Provencher, distributed under the BSD 3-Clause License
|
|
12
|
+
(Copyright (c) 1992-2021, Stephen Provencher); see LICENSE.lcmodel for the
|
|
13
|
+
full text. Home page: https://s-provencher.com/lcmodel.shtml
|
|
14
|
+
|
|
15
|
+
This wrapper bundles no LCModel code or binary. At run time it may obtain one
|
|
16
|
+
from these sources, and the BSD 3-Clause license applies to every one of them:
|
|
17
|
+
|
|
18
|
+
- the community binary collection at https://github.com/schorschinho/LCModel
|
|
19
|
+
(maintained by Georg Oeltzschner and contributors),
|
|
20
|
+
- binaries and the container image ghcr.io/julianmer/lcmodel built by this
|
|
21
|
+
repository's CI (.github/workflows/lcmodel-binaries.yml) from the pinned
|
|
22
|
+
upstream source, unmodified, using the compilation flags documented there;
|
|
23
|
+
LICENSE.lcmodel and this NOTICE are published alongside them,
|
|
24
|
+
- a local build from the same source via gfortran.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lcmodel_wrapper
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Lightweight Python wrapper for LCModel MRS fitting
|
|
5
|
+
Author-email: Julian Merkofer <j.p.merkofer@tue.nl>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/julianmer/PyLCModel
|
|
8
|
+
Project-URL: Repository, https://github.com/julianmer/PyLCModel
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: LICENSE.lcmodel
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Requires-Dist: numpy>=1.22
|
|
15
|
+
Requires-Dist: scipy>=1.10
|
|
16
|
+
Requires-Dist: nibabel>=4.0
|
|
17
|
+
Requires-Dist: nifti-mrs>=1.0
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest>=7.0; extra == "test"
|
|
20
|
+
Requires-Dist: pandas>=1.4; extra == "test"
|
|
21
|
+
Requires-Dist: openpyxl>=3.0; extra == "test"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
<div align="center">
|
|
25
|
+
<img src="https://raw.githubusercontent.com/julianmer/PyLCModel/main/assets/logo_grey.png" alt="PyLCModel Logo" width="160"/>
|
|
26
|
+
<h1 style="margin-top:-10px; margin-bottom: 5px;">PyLCModel</h1>
|
|
27
|
+
<p style="margin-top: 0px;"><em>A lightweight Python wrapper for LCModel spectral fitting in MR spectroscopy</em></p>
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/lcmodel-wrapper/)
|
|
30
|
+
[](https://www.python.org/)
|
|
31
|
+
[](LICENSE)
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
**PyLCModel** is a lightweight Python wrapper that streamlines the use of [LCModel](https://s-provencher.com/lcmodel.shtml) 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).
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Zero-setup binaries** — the LCModel executable is resolved automatically (download, container image, build from source, or your own path); nothing is bundled in the wheel.
|
|
41
|
+
- **Flexible input** — NumPy arrays, NIfTI-MRS, jMRUI text, and LCModel `.RAW`, in time or frequency domain.
|
|
42
|
+
- **Automated control files** — generated to match your data, or templated from an existing one.
|
|
43
|
+
- **Basis conversion (experimental)** — jMRUI, FSL-MRS, LCModel `.RAW`, and Osprey/FID-A basis sets to `.basis`.
|
|
44
|
+
- **Batch fitting** — single- or multi-core, with full output parsing (concentrations, CRLBs, QC, fitted series).
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
### From PyPI
|
|
51
|
+
```bash
|
|
52
|
+
pip install lcmodel-wrapper
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### From Source
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/julianmer/PyLCModel.git
|
|
58
|
+
cd PyLCModel
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
Add `--recursive` to the clone (or run `git submodule update --init`) to also fetch the
|
|
62
|
+
[ISMRM 2016 fitting challenge](https://www.ismrm.org/workshops/Spectroscopy16/mrs_fitting_challenge/)
|
|
63
|
+
example data used by the tests.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## How the LCModel binary is handled
|
|
68
|
+
|
|
69
|
+
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:
|
|
70
|
+
|
|
71
|
+
1. an explicit `path2exec="/path/to/lcmodel"` you pass to `PyLCModel`,
|
|
72
|
+
2. a previously cached download/build (under `~/.cache/lcmodel_wrapper/<os>-<arch>/`, or `%LOCALAPPDATA%` on Windows; override the root with `LCMODEL_CACHE_DIR`),
|
|
73
|
+
3. a download of the matching binary for your OS/architecture from [schorschinho/LCModel](https://github.com/schorschinho/LCModel),
|
|
74
|
+
4. a download of the binary built by this repository's CI and attached to the [GitHub release](https://github.com/julianmer/PyLCModel/releases) matching the installed package version (Linux x86_64/aarch64 fully static, macOS arm64/x86_64 with libgfortran linked statically; each verified against its published SHA-256),
|
|
75
|
+
5. **a container** — if `docker` (or `podman`) is installed and running, the image `ghcr.io/julianmer/lcmodel` is pulled and a small launcher script is cached that runs LCModel from it (Linux, macOS, and Windows),
|
|
76
|
+
6. a build from the LCModel Fortran source via `gfortran` (source fetched on demand).
|
|
77
|
+
|
|
78
|
+
Every candidate is **run once before it is accepted** — LCModel is asked to identify itself, and anything that cannot execute or does not answer is moved to `<cache>/quarantine/` so the next source gets a turn. This is what stops a wrong-architecture download from being cached and served forever. Set `LCMODEL_SKIP_VERIFY=1` to bypass the check, or `LCMODEL_VERIFY_TIMEOUT` to change its 60 s bound.
|
|
79
|
+
|
|
80
|
+
The cache is keyed by architecture, so a home directory shared across a mixed-architecture cluster does not have nodes fighting over one file.
|
|
81
|
+
|
|
82
|
+
### Running from a container
|
|
83
|
+
|
|
84
|
+
The container is the one option that behaves identically everywhere: inside it LCModel is always the same statically linked Linux binary, so nothing depends on your macOS version, Homebrew, or which Apple-silicon generation you have (upstream's macOS builds are tied to the machine they were compiled on, which is why an M1 build does not run on an M4). Docker Desktop, OrbStack, Colima, or rootless podman all work.
|
|
85
|
+
|
|
86
|
+
On Linux and macOS the launcher bind-mounts your **working directory** and your **home directory** at the same paths inside the container, so the absolute paths in the control file need no translation. On Windows it mounts the **drives** holding those two at `/host/<LETTER>` and the wrapper rewrites the file paths in the control file to match (`C:\Users\me\x.basis` → `/host/C/Users/me/x.basis`); UNC paths are not supported. The one constraint: the basis set and any absolute `save_path` must live under the working or home directory (on Windows: on one of their drives); `PyLCModel` raises a clear error otherwise.
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
lcmodel = PyLCModel(path2basis="~/basis/press_3t.basis") # container used automatically if needed
|
|
90
|
+
lcmodel = PyLCModel(path2basis="...", allow_docker=False) # never use a container
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Environment knobs: `LCMODEL_NO_DOCKER=1` disables the rung, `LCMODEL_DOCKER_IMAGE` overrides the image (e.g. a locally built one), `LCMODEL_PULL_TIMEOUT` bounds the pull (default 900 s), and `LCMODEL_RELEASE_TAG` selects which release (and matching image tag) steps 4 and 5 use instead of the default `v<package version>`. Delete `<cache>/lcmodel-container` to make the resolver try the native sources again.
|
|
94
|
+
|
|
95
|
+
You can also use the image directly, without Python:
|
|
96
|
+
```bash
|
|
97
|
+
docker run --rm -i -v "$PWD:$PWD" -w "$PWD" ghcr.io/julianmer/lcmodel:latest < control.file
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
No LCModel code or binary is bundled — keeping both the repository and the PyPI wheel small. (The only git submodule in this repository is the optional example data under `example_data/`.)
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Getting Started
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from lcmodel_wrapper import PyLCModel
|
|
108
|
+
|
|
109
|
+
# Initialize the wrapper with your basis set (the LCModel binary is resolved automatically)
|
|
110
|
+
lcmodel = PyLCModel(path2basis="/path/to/your/basis_set.basis")
|
|
111
|
+
|
|
112
|
+
# `data` can be a NumPy array of FIDs (time domain), a NIfTI-MRS path, etc.
|
|
113
|
+
concentrations, crlbs = lcmodel(data)
|
|
114
|
+
|
|
115
|
+
print("Fitted Metabolite Concentrations:", concentrations)
|
|
116
|
+
print("CRLBs:", crlbs)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Frequency-domain input or a custom executable:
|
|
120
|
+
```python
|
|
121
|
+
lcmodel = PyLCModel(
|
|
122
|
+
path2basis="/path/to/basis.basis",
|
|
123
|
+
domain="freq", # pass spectra instead of FIDs
|
|
124
|
+
path2exec="/path/to/lcmodel", # optional: use your own binary
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Experimental basis conversion (other formats -> `.basis`):
|
|
129
|
+
```python
|
|
130
|
+
# Auto-detect the source format (jMRUI/AQSES/QUEST .txt folder, FSL-MRS .json folder,
|
|
131
|
+
# LCModel .RAW folder, or Osprey/FID-A .mat):
|
|
132
|
+
lcmodel = PyLCModel(path2basis="/path/to/basis_folder", convert_basis=True)
|
|
133
|
+
|
|
134
|
+
# ...or force a format and supply parameters the source does not carry:
|
|
135
|
+
lcmodel = PyLCModel(
|
|
136
|
+
path2basis="/path/to/raw_folder",
|
|
137
|
+
convert_basis=True,
|
|
138
|
+
basis_format="raw", # "jmrui" | "fsl" | "raw" | "mat"
|
|
139
|
+
bandwidth=4000, central_freq=123.25,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Or convert directly without fitting:
|
|
143
|
+
from lcmodel_wrapper import convert_to_basis
|
|
144
|
+
convert_to_basis("/path/to/jmrui_folder", out_path="out.basis")
|
|
145
|
+
```
|
|
146
|
+
> Basis conversion is **experimental** and not validated. For a dedicated, more complete tool, see the [MRS Basis Set Conversion Toolbox](https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox).
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Licensing
|
|
151
|
+
|
|
152
|
+
This wrapper (the Python code) is released under the **Apache License 2.0** (see [LICENSE](LICENSE)).
|
|
153
|
+
|
|
154
|
+
**LCModel itself is a separate program** by Dr. Stephen Provencher, distributed under the **BSD 3-Clause License** (see [LICENSE.lcmodel](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](NOTICE) apply. See the [LCModel home page](https://s-provencher.com/lcmodel.shtml) for details.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Acknowledgements
|
|
159
|
+
|
|
160
|
+
- LCModel source code: created and made [available](https://s-provencher.com/lcmodel.shtml) free of charge (Stephen Provencher).
|
|
161
|
+
- LCModel binaries: [schorschinho/LCModel](https://github.com/schorschinho/LCModel) (Georg Oeltzschner and contributors)
|
|
162
|
+
- Basis conversion reference: [MRS Basis Set Conversion Toolbox](https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox) (Kay Igwe)
|
|
163
|
+
- NIfTI-MRS: [spec2nii](https://github.com/wtclarke/spec2nii), [NIfTI-MRS Python tools](https://github.com/wtclarke/nifti_mrs_tools) (Will Clarke)
|
|
164
|
+
- Example data: [ISMRM 2016 MRS Fitting Challenge](https://www.ismrm.org/workshops/Spectroscopy16/mrs_fitting_challenge/) (Małgorzata Marjańska, Dinesh Deelchand, Roland Kreis), mirrored via [wtclarke/mrs_fitting_challenge](https://github.com/wtclarke/mrs_fitting_challenge)
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
<div align="center">
|
|
169
|
+
<sub>Built with ❤️ for the MRS community</sub>
|
|
170
|
+
</div>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/julianmer/PyLCModel/main/assets/logo_grey.png" alt="PyLCModel Logo" width="160"/>
|
|
3
|
+
<h1 style="margin-top:-10px; margin-bottom: 5px;">PyLCModel</h1>
|
|
4
|
+
<p style="margin-top: 0px;"><em>A lightweight Python wrapper for LCModel spectral fitting in MR spectroscopy</em></p>
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/lcmodel-wrapper/)
|
|
7
|
+
[](https://www.python.org/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
**PyLCModel** is a lightweight Python wrapper that streamlines the use of [LCModel](https://s-provencher.com/lcmodel.shtml) 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).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Zero-setup binaries** — the LCModel executable is resolved automatically (download, container image, build from source, or your own path); nothing is bundled in the wheel.
|
|
18
|
+
- **Flexible input** — NumPy arrays, NIfTI-MRS, jMRUI text, and LCModel `.RAW`, in time or frequency domain.
|
|
19
|
+
- **Automated control files** — generated to match your data, or templated from an existing one.
|
|
20
|
+
- **Basis conversion (experimental)** — jMRUI, FSL-MRS, LCModel `.RAW`, and Osprey/FID-A basis sets to `.basis`.
|
|
21
|
+
- **Batch fitting** — single- or multi-core, with full output parsing (concentrations, CRLBs, QC, fitted series).
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### From PyPI
|
|
28
|
+
```bash
|
|
29
|
+
pip install lcmodel-wrapper
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### From Source
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/julianmer/PyLCModel.git
|
|
35
|
+
cd PyLCModel
|
|
36
|
+
pip install -e .
|
|
37
|
+
```
|
|
38
|
+
Add `--recursive` to the clone (or run `git submodule update --init`) to also fetch the
|
|
39
|
+
[ISMRM 2016 fitting challenge](https://www.ismrm.org/workshops/Spectroscopy16/mrs_fitting_challenge/)
|
|
40
|
+
example data used by the tests.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## How the LCModel binary is handled
|
|
45
|
+
|
|
46
|
+
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:
|
|
47
|
+
|
|
48
|
+
1. an explicit `path2exec="/path/to/lcmodel"` you pass to `PyLCModel`,
|
|
49
|
+
2. a previously cached download/build (under `~/.cache/lcmodel_wrapper/<os>-<arch>/`, or `%LOCALAPPDATA%` on Windows; override the root with `LCMODEL_CACHE_DIR`),
|
|
50
|
+
3. a download of the matching binary for your OS/architecture from [schorschinho/LCModel](https://github.com/schorschinho/LCModel),
|
|
51
|
+
4. a download of the binary built by this repository's CI and attached to the [GitHub release](https://github.com/julianmer/PyLCModel/releases) matching the installed package version (Linux x86_64/aarch64 fully static, macOS arm64/x86_64 with libgfortran linked statically; each verified against its published SHA-256),
|
|
52
|
+
5. **a container** — if `docker` (or `podman`) is installed and running, the image `ghcr.io/julianmer/lcmodel` is pulled and a small launcher script is cached that runs LCModel from it (Linux, macOS, and Windows),
|
|
53
|
+
6. a build from the LCModel Fortran source via `gfortran` (source fetched on demand).
|
|
54
|
+
|
|
55
|
+
Every candidate is **run once before it is accepted** — LCModel is asked to identify itself, and anything that cannot execute or does not answer is moved to `<cache>/quarantine/` so the next source gets a turn. This is what stops a wrong-architecture download from being cached and served forever. Set `LCMODEL_SKIP_VERIFY=1` to bypass the check, or `LCMODEL_VERIFY_TIMEOUT` to change its 60 s bound.
|
|
56
|
+
|
|
57
|
+
The cache is keyed by architecture, so a home directory shared across a mixed-architecture cluster does not have nodes fighting over one file.
|
|
58
|
+
|
|
59
|
+
### Running from a container
|
|
60
|
+
|
|
61
|
+
The container is the one option that behaves identically everywhere: inside it LCModel is always the same statically linked Linux binary, so nothing depends on your macOS version, Homebrew, or which Apple-silicon generation you have (upstream's macOS builds are tied to the machine they were compiled on, which is why an M1 build does not run on an M4). Docker Desktop, OrbStack, Colima, or rootless podman all work.
|
|
62
|
+
|
|
63
|
+
On Linux and macOS the launcher bind-mounts your **working directory** and your **home directory** at the same paths inside the container, so the absolute paths in the control file need no translation. On Windows it mounts the **drives** holding those two at `/host/<LETTER>` and the wrapper rewrites the file paths in the control file to match (`C:\Users\me\x.basis` → `/host/C/Users/me/x.basis`); UNC paths are not supported. The one constraint: the basis set and any absolute `save_path` must live under the working or home directory (on Windows: on one of their drives); `PyLCModel` raises a clear error otherwise.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
lcmodel = PyLCModel(path2basis="~/basis/press_3t.basis") # container used automatically if needed
|
|
67
|
+
lcmodel = PyLCModel(path2basis="...", allow_docker=False) # never use a container
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Environment knobs: `LCMODEL_NO_DOCKER=1` disables the rung, `LCMODEL_DOCKER_IMAGE` overrides the image (e.g. a locally built one), `LCMODEL_PULL_TIMEOUT` bounds the pull (default 900 s), and `LCMODEL_RELEASE_TAG` selects which release (and matching image tag) steps 4 and 5 use instead of the default `v<package version>`. Delete `<cache>/lcmodel-container` to make the resolver try the native sources again.
|
|
71
|
+
|
|
72
|
+
You can also use the image directly, without Python:
|
|
73
|
+
```bash
|
|
74
|
+
docker run --rm -i -v "$PWD:$PWD" -w "$PWD" ghcr.io/julianmer/lcmodel:latest < control.file
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
No LCModel code or binary is bundled — keeping both the repository and the PyPI wheel small. (The only git submodule in this repository is the optional example data under `example_data/`.)
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Getting Started
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from lcmodel_wrapper import PyLCModel
|
|
85
|
+
|
|
86
|
+
# Initialize the wrapper with your basis set (the LCModel binary is resolved automatically)
|
|
87
|
+
lcmodel = PyLCModel(path2basis="/path/to/your/basis_set.basis")
|
|
88
|
+
|
|
89
|
+
# `data` can be a NumPy array of FIDs (time domain), a NIfTI-MRS path, etc.
|
|
90
|
+
concentrations, crlbs = lcmodel(data)
|
|
91
|
+
|
|
92
|
+
print("Fitted Metabolite Concentrations:", concentrations)
|
|
93
|
+
print("CRLBs:", crlbs)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Frequency-domain input or a custom executable:
|
|
97
|
+
```python
|
|
98
|
+
lcmodel = PyLCModel(
|
|
99
|
+
path2basis="/path/to/basis.basis",
|
|
100
|
+
domain="freq", # pass spectra instead of FIDs
|
|
101
|
+
path2exec="/path/to/lcmodel", # optional: use your own binary
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Experimental basis conversion (other formats -> `.basis`):
|
|
106
|
+
```python
|
|
107
|
+
# Auto-detect the source format (jMRUI/AQSES/QUEST .txt folder, FSL-MRS .json folder,
|
|
108
|
+
# LCModel .RAW folder, or Osprey/FID-A .mat):
|
|
109
|
+
lcmodel = PyLCModel(path2basis="/path/to/basis_folder", convert_basis=True)
|
|
110
|
+
|
|
111
|
+
# ...or force a format and supply parameters the source does not carry:
|
|
112
|
+
lcmodel = PyLCModel(
|
|
113
|
+
path2basis="/path/to/raw_folder",
|
|
114
|
+
convert_basis=True,
|
|
115
|
+
basis_format="raw", # "jmrui" | "fsl" | "raw" | "mat"
|
|
116
|
+
bandwidth=4000, central_freq=123.25,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Or convert directly without fitting:
|
|
120
|
+
from lcmodel_wrapper import convert_to_basis
|
|
121
|
+
convert_to_basis("/path/to/jmrui_folder", out_path="out.basis")
|
|
122
|
+
```
|
|
123
|
+
> Basis conversion is **experimental** and not validated. For a dedicated, more complete tool, see the [MRS Basis Set Conversion Toolbox](https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox).
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Licensing
|
|
128
|
+
|
|
129
|
+
This wrapper (the Python code) is released under the **Apache License 2.0** (see [LICENSE](LICENSE)).
|
|
130
|
+
|
|
131
|
+
**LCModel itself is a separate program** by Dr. Stephen Provencher, distributed under the **BSD 3-Clause License** (see [LICENSE.lcmodel](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](NOTICE) apply. See the [LCModel home page](https://s-provencher.com/lcmodel.shtml) for details.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Acknowledgements
|
|
136
|
+
|
|
137
|
+
- LCModel source code: created and made [available](https://s-provencher.com/lcmodel.shtml) free of charge (Stephen Provencher).
|
|
138
|
+
- LCModel binaries: [schorschinho/LCModel](https://github.com/schorschinho/LCModel) (Georg Oeltzschner and contributors)
|
|
139
|
+
- Basis conversion reference: [MRS Basis Set Conversion Toolbox](https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox) (Kay Igwe)
|
|
140
|
+
- NIfTI-MRS: [spec2nii](https://github.com/wtclarke/spec2nii), [NIfTI-MRS Python tools](https://github.com/wtclarke/nifti_mrs_tools) (Will Clarke)
|
|
141
|
+
- Example data: [ISMRM 2016 MRS Fitting Challenge](https://www.ismrm.org/workshops/Spectroscopy16/mrs_fitting_challenge/) (Małgorzata Marjańska, Dinesh Deelchand, Roland Kreis), mirrored via [wtclarke/mrs_fitting_challenge](https://github.com/wtclarke/mrs_fitting_challenge)
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
<div align="center">
|
|
146
|
+
<sub>Built with ❤️ for the MRS community</sub>
|
|
147
|
+
</div>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""PyLCModel - a lightweight Python wrapper for the LCModel MRS fitting tool.
|
|
2
|
+
|
|
3
|
+
LCModel itself is a separate program by Dr. Stephen Provencher, distributed under the
|
|
4
|
+
BSD 3-Clause License (see LICENSE.lcmodel). This package only wraps it.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from ._version import __version__
|
|
8
|
+
from .core import PyLCModel, LCModelError
|
|
9
|
+
from .basis import read_basis, LCModelBasis
|
|
10
|
+
from .binaries import verify_executable
|
|
11
|
+
from .convert import ensure_basis, convert_to_basis, detect_format
|
|
12
|
+
from .io import from_nifti_mrs, load_signals
|
|
13
|
+
from . import binaries, container, io, control, coord, convert
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"PyLCModel",
|
|
17
|
+
"LCModelError",
|
|
18
|
+
"verify_executable",
|
|
19
|
+
"read_basis",
|
|
20
|
+
"LCModelBasis",
|
|
21
|
+
"ensure_basis",
|
|
22
|
+
"convert_to_basis",
|
|
23
|
+
"detect_format",
|
|
24
|
+
"from_nifti_mrs",
|
|
25
|
+
"load_signals",
|
|
26
|
+
"binaries",
|
|
27
|
+
"io",
|
|
28
|
+
"control",
|
|
29
|
+
"coord",
|
|
30
|
+
"convert",
|
|
31
|
+
]
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Single source of truth for the package version. pyproject.toml reads it at build time,
|
|
2
|
+
# and binaries.py derives the GitHub release / container image tag ("v<version>") from
|
|
3
|
+
# it, so every wheel pairs with the LCModel artifacts built alongside it.
|
|
4
|
+
__version__ = "0.3.0"
|