Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michiel Cottaar
fsl_mrs
Commits
3b31c7e2
Commit
3b31c7e2
authored
Apr 20, 2020
by
William Clarke
Browse files
Slight reworking of rescaling. Makes fitting more robust.
parent
a9fa0d04
Changes
4
Show whitespace changes
Inline
Side-by-side
fsl_mrs/core.py
View file @
3b31c7e2
...
...
@@ -246,6 +246,23 @@ class MRS(object):
# Helper functions
def
processForFitting
(
self
,
ppmlim
=
(.
2
,
4.2
),):
""" Apply rescaling and run the conjugation checks"""
self
.
check_FID
(
ppmlim
=
ppmlim
,
repair
=
True
)
self
.
check_Basis
(
ppmlim
=
ppmlim
,
repair
=
True
)
self
.
rescaleForFitting
()
def
rescaleForFitting
(
self
,
scale
=
100
):
""" Apply rescaling across data, basis and H20"""
scaledFID
,
scaling
=
misc
.
rescale_FID
(
self
.
FID
,
scale
=
scale
)
self
.
set_FID
(
scaledFID
)
if
self
.
H2O
is
not
None
:
self
.
H2O
*=
scaling
if
self
.
basis
is
not
None
:
self
.
basis
,
_
=
misc
.
rescale_FID
(
self
.
basis
,
scale
=
scale
)
def
check_FID
(
self
,
ppmlim
=
(.
2
,
4.2
),
repair
=
False
):
"""
Check if FID needs to be conjugated
...
...
fsl_mrs/scripts/fsl_mrs
View file @
3b31c7e2
...
...
@@ -160,16 +160,8 @@ def main():
FID
,
dataheader
=
mrs_io
.
read_FID
(
args
.
data
)
basis
,
names
,
basisheader
=
mrs_io
.
read_basis
(
args
.
basis
)
# Rescale FID and basis to have nice range
if
not
args
.
no_rescale
:
FID
=
misc
.
rescale_FID
(
FID
,
scale
=
100
)
basis
=
misc
.
rescale_FID
(
basis
,
scale
=
100
)
if
args
.
h2o
is
not
None
:
H2O
,
_
=
mrs_io
.
read_FID
(
args
.
h2o
)
if
not
args
.
no_rescale
:
H2O
=
misc
.
rescale_FID
(
H2O
,
scale
=
100
)
else
:
H2O
=
None
...
...
@@ -221,6 +213,10 @@ def main():
if
conjugated
==
1
:
warnings
.
warn
(
'Basis has been checked and conjugated. Please check!'
,
UserWarning
)
# Rescale FID, H2O and basis to have nice range
if
not
args
.
no_rescale
:
mrs
.
rescaleForFitting
()
# Do phase correction
if
args
.
phase_correct
:
if
args
.
verbose
:
...
...
fsl_mrs/utils/fitting.py
View file @
3b31c7e2
...
...
@@ -398,6 +398,7 @@ def fit_FSLModel(mrs,
verbose
=
False
,
monitor
=
True
,
args
=
args
)
results
.
optim_out
=
res_vb
# de-log
if
model
.
lower
()
==
'lorentzian'
:
...
...
fsl_mrs/utils/misc.py
View file @
3b31c7e2
...
...
@@ -434,7 +434,7 @@ def rescale_FID(x,scale=100):
else
:
factor
=
np
.
linalg
.
norm
(
np
.
mean
(
y
,
axis
=
1
),
axis
=
0
)
y
=
y
/
factor
*
scale
return
y
return
y
,
1
/
factor
*
scale
def
create_peak
(
mrs
,
ppm
,
gamma
=
0
,
sigma
=
0
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment