lcmodel-wrapper 0.1.2__tar.gz → 0.2.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.2.0/LICENSE +202 -0
- lcmodel_wrapper-0.2.0/LICENSE.lcmodel +39 -0
- lcmodel_wrapper-0.2.0/MANIFEST.in +4 -0
- lcmodel_wrapper-0.2.0/NOTICE +34 -0
- lcmodel_wrapper-0.2.0/PKG-INFO +141 -0
- lcmodel_wrapper-0.2.0/README.md +119 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/__init__.py +24 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/basis.py +100 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/binaries.py +245 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/control.py +120 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/convert.py +364 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/coord.py +136 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/core.py +271 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper/io.py +292 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper.egg-info/PKG-INFO +141 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper.egg-info/SOURCES.txt +28 -0
- lcmodel_wrapper-0.2.0/lcmodel_wrapper.egg-info/requires.txt +8 -0
- lcmodel_wrapper-0.2.0/pyproject.toml +38 -0
- lcmodel_wrapper-0.2.0/tests/test_lcm.py +98 -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.2.0}/lcmodel_wrapper.egg-info/dependency_links.txt +0 -0
- {lcmodel_wrapper-0.1.2/src → lcmodel_wrapper-0.2.0}/lcmodel_wrapper.egg-info/top_level.txt +0 -0
- {lcmodel_wrapper-0.1.2 → lcmodel_wrapper-0.2.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,34 @@
|
|
|
1
|
+
PyLCModel (lcmodel_wrapper)
|
|
2
|
+
Copyright (c) 2024 Julian P. Merkofer and contributors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
------------------------------------------------------------------------------
|
|
7
|
+
Third-party components
|
|
8
|
+
------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
LCModel
|
|
11
|
+
LCModel is NOT part of this project's copyright. It is a separate program by
|
|
12
|
+
Dr. Stephen Provencher, distributed under the BSD 3-Clause License
|
|
13
|
+
(Copyright (c) 1992-2021, Stephen Provencher). See LICENSE.lcmodel for the
|
|
14
|
+
full text. This wrapper can download, build, or run the LCModel executable,
|
|
15
|
+
but does not claim any rights over it.
|
|
16
|
+
Home page: https://s-provencher.com/lcmodel.shtml
|
|
17
|
+
|
|
18
|
+
LCModel compiled binaries
|
|
19
|
+
Pre-compiled LCModel binaries are obtained on demand from the community
|
|
20
|
+
collection at https://github.com/schorschinho/LCModel (maintained by
|
|
21
|
+
Georg Oeltzschner et al.). Individual builds were contributed by:
|
|
22
|
+
- macOS Catalina (Intel) - Georg Oeltzschner
|
|
23
|
+
- macOS Monterey (M1) - Bethany A. Stennett
|
|
24
|
+
- macOS Sequoia (M4) - Julian P. Merkofer
|
|
25
|
+
- Windows 10 (x86_64) - Georg Oeltzschner
|
|
26
|
+
- Linux (x86_64) - Will Foran
|
|
27
|
+
The BSD 3-Clause LCModel license (LICENSE.lcmodel) applies to these binaries.
|
|
28
|
+
|
|
29
|
+
Other referenced tools (not bundled)
|
|
30
|
+
- Augmentrum (https://github.com/julianmer/Augmentrum) - NIfTI-MRS augmentation
|
|
31
|
+
- MRS-Basis-Set-Conversion-Toolbox
|
|
32
|
+
(https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox) - basis set
|
|
33
|
+
conversion reference
|
|
34
|
+
- Osprey (https://github.com/schorschinho/osprey) - control/basis tooling
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lcmodel_wrapper
|
|
3
|
+
Version: 0.2.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: pandas>=1.4; extra == "test"
|
|
20
|
+
Requires-Dist: openpyxl>=3.0; extra == "test"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
<img src="https://raw.githubusercontent.com/julianmer/PyLCModel/main/assets/logo_grey.png" alt="PyLCModel Logo" width="160"/>
|
|
25
|
+
<h1 style="margin-top:-10px; margin-bottom: 5px;">PyLCModel</h1>
|
|
26
|
+
<p style="margin-top: 0px;"><em>A lightweight Python wrapper for LCModel spectral fitting in MR spectroscopy</em></p>
|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/lcmodel-wrapper/)
|
|
29
|
+
[](https://www.python.org/)
|
|
30
|
+
[](LICENSE)
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
**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).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Zero-setup binaries** — the LCModel executable is resolved automatically (download, build from source, or your own path); nothing is bundled in the wheel.
|
|
40
|
+
- **Flexible input** — NumPy arrays, NIfTI-MRS, jMRUI text, and LCModel `.RAW`, in time or frequency domain.
|
|
41
|
+
- **Automated control files** — generated to match your data, or templated from an existing one.
|
|
42
|
+
- **Basis conversion (experimental)** — jMRUI, FSL-MRS, LCModel `.RAW`, and Osprey/FID-A basis sets to `.basis`.
|
|
43
|
+
- **Batch fitting** — single- or multi-core, with full output parsing (concentrations, CRLBs, QC, fitted series).
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
### From PyPI
|
|
50
|
+
```bash
|
|
51
|
+
pip install lcmodel-wrapper
|
|
52
|
+
```
|
|
53
|
+
Enter your API token:
|
|
54
|
+
|
|
55
|
+
### From Source
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/julianmer/PyLCModel.git
|
|
58
|
+
cd PyLCModel
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## How the LCModel binary is handled
|
|
65
|
+
|
|
66
|
+
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:
|
|
67
|
+
|
|
68
|
+
1. an explicit `path2exec="/path/to/lcmodel"` you pass to `PyLCModel`,
|
|
69
|
+
2. a previously cached download/build (under `~/.cache/lcmodel_wrapper`, or `%LOCALAPPDATA%` on Windows; override with `LCMODEL_CACHE_DIR`),
|
|
70
|
+
3. a download of the matching binary for your OS/architecture from [schorschinho/LCModel](https://github.com/schorschinho/LCModel),
|
|
71
|
+
4. a build from the LCModel Fortran source via `gfortran` (source fetched on demand).
|
|
72
|
+
|
|
73
|
+
There is no git submodule and no bundled `lcmodel/` folder — keeping both the repository and the PyPI wheel small.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Getting Started
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from lcmodel_wrapper import PyLCModel
|
|
81
|
+
|
|
82
|
+
# Initialize the wrapper with your basis set (the LCModel binary is resolved automatically)
|
|
83
|
+
lcmodel = PyLCModel(path2basis="/path/to/your/basis_set.basis")
|
|
84
|
+
|
|
85
|
+
# `data` can be a NumPy array of FIDs (time domain), a NIfTI-MRS path, etc.
|
|
86
|
+
concentrations, crlbs = lcmodel(data)
|
|
87
|
+
|
|
88
|
+
print("Fitted Metabolite Concentrations:", concentrations)
|
|
89
|
+
print("CRLBs:", crlbs)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Frequency-domain input or a custom executable:
|
|
93
|
+
```python
|
|
94
|
+
lcmodel = PyLCModel(
|
|
95
|
+
path2basis="/path/to/basis.basis",
|
|
96
|
+
domain="freq", # pass spectra instead of FIDs
|
|
97
|
+
path2exec="/path/to/lcmodel", # optional: use your own binary
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Experimental basis conversion (other formats -> `.basis`):
|
|
102
|
+
```python
|
|
103
|
+
# Auto-detect the source format (jMRUI/AQSES/QUEST .txt folder, FSL-MRS .json folder,
|
|
104
|
+
# LCModel .RAW folder, or Osprey/FID-A .mat):
|
|
105
|
+
lcmodel = PyLCModel(path2basis="/path/to/basis_folder", convert_basis=True)
|
|
106
|
+
|
|
107
|
+
# ...or force a format and supply parameters the source does not carry:
|
|
108
|
+
lcmodel = PyLCModel(
|
|
109
|
+
path2basis="/path/to/raw_folder",
|
|
110
|
+
convert_basis=True,
|
|
111
|
+
basis_format="raw", # "jmrui" | "fsl" | "raw" | "mat"
|
|
112
|
+
bandwidth=4000, central_freq=123.25,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Or convert directly without fitting:
|
|
116
|
+
from lcmodel_wrapper import convert_to_basis
|
|
117
|
+
convert_to_basis("/path/to/jmrui_folder", out_path="out.basis")
|
|
118
|
+
```
|
|
119
|
+
> 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).
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Licensing
|
|
124
|
+
|
|
125
|
+
This wrapper (the Python code) is released under the **Apache License 2.0** (see [LICENSE](LICENSE)).
|
|
126
|
+
|
|
127
|
+
**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.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Acknowledgements
|
|
132
|
+
|
|
133
|
+
- LCModel binaries: [schorschinho/LCModel](https://github.com/schorschinho/LCModel) (Georg Oeltzschner and contributors)
|
|
134
|
+
- Basis conversion reference: [MRS Basis Set Conversion Toolbox](https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox) (Kay Igwe)
|
|
135
|
+
- NIfTI-MRS: [spec2nii](https://github.com/wtclarke/spec2nii), [NIfTI-MRS Pyhton tools](https://github.com/wtclarke/nifti_mrs_tools) (Will Clarke)
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
<div align="center">
|
|
140
|
+
<sub>Built with ❤️ for the MRS community</sub>
|
|
141
|
+
</div>
|
|
@@ -0,0 +1,119 @@
|
|
|
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, 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
|
+
Enter your API token:
|
|
32
|
+
|
|
33
|
+
### From Source
|
|
34
|
+
```bash
|
|
35
|
+
git clone https://github.com/julianmer/PyLCModel.git
|
|
36
|
+
cd PyLCModel
|
|
37
|
+
pip install -e .
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## How the LCModel binary is handled
|
|
43
|
+
|
|
44
|
+
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:
|
|
45
|
+
|
|
46
|
+
1. an explicit `path2exec="/path/to/lcmodel"` you pass to `PyLCModel`,
|
|
47
|
+
2. a previously cached download/build (under `~/.cache/lcmodel_wrapper`, or `%LOCALAPPDATA%` on Windows; override with `LCMODEL_CACHE_DIR`),
|
|
48
|
+
3. a download of the matching binary for your OS/architecture from [schorschinho/LCModel](https://github.com/schorschinho/LCModel),
|
|
49
|
+
4. a build from the LCModel Fortran source via `gfortran` (source fetched on demand).
|
|
50
|
+
|
|
51
|
+
There is no git submodule and no bundled `lcmodel/` folder — keeping both the repository and the PyPI wheel small.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Getting Started
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from lcmodel_wrapper import PyLCModel
|
|
59
|
+
|
|
60
|
+
# Initialize the wrapper with your basis set (the LCModel binary is resolved automatically)
|
|
61
|
+
lcmodel = PyLCModel(path2basis="/path/to/your/basis_set.basis")
|
|
62
|
+
|
|
63
|
+
# `data` can be a NumPy array of FIDs (time domain), a NIfTI-MRS path, etc.
|
|
64
|
+
concentrations, crlbs = lcmodel(data)
|
|
65
|
+
|
|
66
|
+
print("Fitted Metabolite Concentrations:", concentrations)
|
|
67
|
+
print("CRLBs:", crlbs)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Frequency-domain input or a custom executable:
|
|
71
|
+
```python
|
|
72
|
+
lcmodel = PyLCModel(
|
|
73
|
+
path2basis="/path/to/basis.basis",
|
|
74
|
+
domain="freq", # pass spectra instead of FIDs
|
|
75
|
+
path2exec="/path/to/lcmodel", # optional: use your own binary
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Experimental basis conversion (other formats -> `.basis`):
|
|
80
|
+
```python
|
|
81
|
+
# Auto-detect the source format (jMRUI/AQSES/QUEST .txt folder, FSL-MRS .json folder,
|
|
82
|
+
# LCModel .RAW folder, or Osprey/FID-A .mat):
|
|
83
|
+
lcmodel = PyLCModel(path2basis="/path/to/basis_folder", convert_basis=True)
|
|
84
|
+
|
|
85
|
+
# ...or force a format and supply parameters the source does not carry:
|
|
86
|
+
lcmodel = PyLCModel(
|
|
87
|
+
path2basis="/path/to/raw_folder",
|
|
88
|
+
convert_basis=True,
|
|
89
|
+
basis_format="raw", # "jmrui" | "fsl" | "raw" | "mat"
|
|
90
|
+
bandwidth=4000, central_freq=123.25,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# Or convert directly without fitting:
|
|
94
|
+
from lcmodel_wrapper import convert_to_basis
|
|
95
|
+
convert_to_basis("/path/to/jmrui_folder", out_path="out.basis")
|
|
96
|
+
```
|
|
97
|
+
> 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).
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Licensing
|
|
102
|
+
|
|
103
|
+
This wrapper (the Python code) is released under the **Apache License 2.0** (see [LICENSE](LICENSE)).
|
|
104
|
+
|
|
105
|
+
**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.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Acknowledgements
|
|
110
|
+
|
|
111
|
+
- LCModel binaries: [schorschinho/LCModel](https://github.com/schorschinho/LCModel) (Georg Oeltzschner and contributors)
|
|
112
|
+
- Basis conversion reference: [MRS Basis Set Conversion Toolbox](https://github.com/igweckay/MRS-Basis-Set-Conversion-Toolbox) (Kay Igwe)
|
|
113
|
+
- NIfTI-MRS: [spec2nii](https://github.com/wtclarke/spec2nii), [NIfTI-MRS Pyhton tools](https://github.com/wtclarke/nifti_mrs_tools) (Will Clarke)
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
<div align="center">
|
|
118
|
+
<sub>Built with ❤️ for the MRS community</sub>
|
|
119
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
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 .core import PyLCModel
|
|
8
|
+
from .basis import read_basis, LCModelBasis
|
|
9
|
+
from .convert import ensure_basis, convert_to_basis, detect_format
|
|
10
|
+
from . import binaries, io, control, coord, convert
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"PyLCModel",
|
|
14
|
+
"read_basis",
|
|
15
|
+
"LCModelBasis",
|
|
16
|
+
"ensure_basis",
|
|
17
|
+
"convert_to_basis",
|
|
18
|
+
"detect_format",
|
|
19
|
+
"binaries",
|
|
20
|
+
"io",
|
|
21
|
+
"control",
|
|
22
|
+
"coord",
|
|
23
|
+
"convert",
|
|
24
|
+
]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
# basis.py #
|
|
3
|
+
####################################################################################################
|
|
4
|
+
# #
|
|
5
|
+
# Authors: J. P. Merkofer (j.p.merkofer@tue.nl) #
|
|
6
|
+
# #
|
|
7
|
+
# Created: 26/06/26 #
|
|
8
|
+
# #
|
|
9
|
+
# Purpose: Lightweight parser for LCModel ".basis" files. Replaces the previous dependency on #
|
|
10
|
+
# fsl_mrs for reading basis metadata. It extracts only what the wrapper needs to build #
|
|
11
|
+
# control files and to align fitted concentrations: the field strength (HZPPPM), dwell #
|
|
12
|
+
# time (BADELT), number of points (NDATAB) and the ordered metabolite names (METABO). #
|
|
13
|
+
# #
|
|
14
|
+
####################################################################################################
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
from dataclasses import dataclass, field
|
|
19
|
+
from typing import List, Optional
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#*************************#
|
|
23
|
+
# basis data container #
|
|
24
|
+
#*************************#
|
|
25
|
+
@dataclass
|
|
26
|
+
class LCModelBasis:
|
|
27
|
+
"""Metadata parsed from an LCModel ".basis" file."""
|
|
28
|
+
|
|
29
|
+
path: str
|
|
30
|
+
central_freq: Optional[float] = None # HZPPPM, field strength in MHz
|
|
31
|
+
dwell: Optional[float] = None # BADELT, dwell time in seconds
|
|
32
|
+
n_points: Optional[int] = None # NDATAB, number of complex points
|
|
33
|
+
echo_time: Optional[float] = None # ECHOT, echo time
|
|
34
|
+
names: List[str] = field(default_factory=list) # METABO entries, in file order
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def bandwidth(self) -> Optional[float]:
|
|
38
|
+
"""Spectral bandwidth in Hz (1 / dwell)."""
|
|
39
|
+
if self.dwell in (None, 0):
|
|
40
|
+
return None
|
|
41
|
+
return 1.0 / self.dwell
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def n_metabs(self) -> int:
|
|
45
|
+
return len(self.names)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#***********************************#
|
|
49
|
+
# parse a single namelist value #
|
|
50
|
+
#***********************************#
|
|
51
|
+
def _find_scalar(text: str, key: str):
|
|
52
|
+
"""Return the first numeric scalar assigned to "key" (e.g. "HZPPPM = 123.26")."""
|
|
53
|
+
m = re.search(rf"{key}\s*=\s*([-+0-9.eEdD]+)", text)
|
|
54
|
+
if not m:
|
|
55
|
+
return None
|
|
56
|
+
raw = m.group(1).replace("D", "E").replace("d", "e")
|
|
57
|
+
try:
|
|
58
|
+
return float(raw)
|
|
59
|
+
except ValueError:
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#******************#
|
|
64
|
+
# read a basis #
|
|
65
|
+
#******************#
|
|
66
|
+
def read_basis(path: str) -> LCModelBasis:
|
|
67
|
+
"""Parse an LCModel ".basis" file and return an LCModelBasis.
|
|
68
|
+
|
|
69
|
+
Only the header namelists and the "METABO" names are read; the (large) numeric
|
|
70
|
+
basis vectors are skipped for speed.
|
|
71
|
+
"""
|
|
72
|
+
if not os.path.isfile(path):
|
|
73
|
+
raise FileNotFoundError(f"Basis file not found: {path}")
|
|
74
|
+
|
|
75
|
+
basis = LCModelBasis(path=os.path.abspath(path))
|
|
76
|
+
|
|
77
|
+
with open(path, "r", errors="ignore") as fh:
|
|
78
|
+
header_lines = []
|
|
79
|
+
for line in fh:
|
|
80
|
+
header_lines.append(line)
|
|
81
|
+
# "METABO" lines are sparse; keep scanning the whole file for them.
|
|
82
|
+
# Match exactly "METABO =" (not "METABO_CONTAM" / "METABO_SINGLET").
|
|
83
|
+
m = re.match(r"\s*METABO\s*=\s*'(.*?)'", line)
|
|
84
|
+
if m:
|
|
85
|
+
basis.names.append(m.group(1).strip())
|
|
86
|
+
|
|
87
|
+
header = "".join(header_lines[:200]) # scalars live near the top
|
|
88
|
+
|
|
89
|
+
basis.central_freq = _find_scalar(header, "HZPPPM")
|
|
90
|
+
basis.dwell = _find_scalar(header, "BADELT")
|
|
91
|
+
basis.echo_time = _find_scalar(header, "ECHOT")
|
|
92
|
+
ndatab = _find_scalar(header, "NDATAB")
|
|
93
|
+
basis.n_points = int(ndatab) if ndatab is not None else None
|
|
94
|
+
|
|
95
|
+
if not basis.names:
|
|
96
|
+
raise ValueError(
|
|
97
|
+
f"No METABO entries found in basis file: {path}. "
|
|
98
|
+
"Is this a valid LCModel .basis file?"
|
|
99
|
+
)
|
|
100
|
+
return basis
|