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
8edd9280
Commit
8edd9280
authored
Apr 16, 2020
by
William Clarke
Browse files
Minor bug fixes
parent
42f0efe8
Changes
5
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/core.py
View file @
8edd9280
...
...
@@ -246,7 +246,7 @@ class MRS(object):
# Helper functions
def
check_FID
(
self
,
ppmlim
=
(.
2
,
4.2
),
repar
e
=
False
):
def
check_FID
(
self
,
ppmlim
=
(.
2
,
4.2
),
repa
i
r
=
False
):
"""
Check if FID needs to be conjugated
by looking at total power within ppmlim range
...
...
@@ -254,7 +254,7 @@ class MRS(object):
Parameters
----------
ppmlim : list
repar
e
: if True applies conjugation to FID
repa
i
r : if True applies conjugation to FID
Returns
-------
...
...
@@ -266,7 +266,7 @@ class MRS(object):
Spec2
=
np
.
real
(
misc
.
FIDToSpec
(
np
.
conj
(
self
.
FID
)))[
first
:
last
]
if
np
.
linalg
.
norm
(
misc
.
detrend
(
Spec1
,
deg
=
4
))
<
np
.
linalg
.
norm
(
misc
.
detrend
(
Spec2
,
deg
=
4
)):
if
repar
e
is
False
:
if
repa
i
r
is
False
:
warnings
.
warn
(
'YOU MAY NEED TO CONJUGATE YOUR FID!!!'
)
return
-
1
else
:
...
...
@@ -282,7 +282,7 @@ class MRS(object):
self
.
FID
=
np
.
conj
(
self
.
FID
)
self
.
Spec
=
misc
.
FIDToSpec
(
self
.
FID
)
def
check_Basis
(
self
,
ppmlim
=
(.
2
,
4.2
),
repar
e
=
False
):
def
check_Basis
(
self
,
ppmlim
=
(.
2
,
4.2
),
repa
i
r
=
False
):
"""
Check if Basis needs to be conjugated
by looking at total power within ppmlim range
...
...
@@ -290,7 +290,7 @@ class MRS(object):
Parameters
----------
ppmlim : list
repar
e
: if True applies conjugation to basis
repa
i
r : if True applies conjugation to basis
Returns
-------
...
...
@@ -309,7 +309,7 @@ class MRS(object):
conjOrNot
.
append
(
0.0
)
if
(
sum
(
conjOrNot
)
/
len
(
conjOrNot
))
>
0.5
:
if
repar
e
is
False
:
if
repa
i
r
is
False
:
warnings
.
warn
(
'YOU MAY NEED TO CONJUGATE YOUR BASIS!!!'
)
return
-
1
else
:
...
...
fsl_mrs/scripts/fsl_mrs
View file @
8edd9280
...
...
@@ -197,7 +197,7 @@ def main():
if
args
.
conjfid
:
mrs
.
conj_FID
()
else
:
conjugated
=
mrs
.
check_FID
(
repar
e
=
True
)
conjugated
=
mrs
.
check_FID
(
repa
i
r
=
True
)
if
args
.
verbose
:
if
conjugated
==
1
:
warnings
.
warn
(
'FID has been checked and conjugated. Please check!'
,
UserWarning
)
...
...
@@ -206,7 +206,7 @@ def main():
if
args
.
conjbasis
:
mrs
.
conj_Basis
()
else
:
conjugated
=
mrs
.
check_Basis
(
repar
e
=
True
)
conjugated
=
mrs
.
check_Basis
(
repa
i
r
=
True
)
if
args
.
verbose
:
if
conjugated
==
1
:
warnings
.
warn
(
'Basis has been checked and conjugated. Please check!'
,
UserWarning
)
...
...
fsl_mrs/utils/plotting.py
View file @
8edd9280
...
...
@@ -285,13 +285,7 @@ def plot_spectrum(mrs,ppmlim=(0.0,4.5),FID=None,proj='real',c='k'):
return
plt
.
gcf
()
def
plot_spectra
(
FIDlist
,
bandwidth
,
centralFrequency
,
ppmlim
=
(
0
,
4.5
),
single_FID
=
None
,
plot_avg
=
True
):
numPoints
=
FIDlist
[
0
].
size
frequencyAxis
=
np
.
linspace
(
-
bandwidth
/
2
,
bandwidth
/
2
,
numPoints
)
ppmAxisShift
=
hz2ppm
(
centralFrequency
,
frequencyAxis
,
shift
=
True
)
def
plot_spectra
(
MRSList
,
ppmlim
=
(
0
,
4.5
),
single_FID
=
None
,
plot_avg
=
True
):
plt
.
figure
(
figsize
=
(
10
,
10
))
plt
.
xlim
(
ppmlim
)
...
...
@@ -303,15 +297,16 @@ def plot_spectra(FIDlist,bandwidth,centralFrequency,ppmlim=(0,4.5),single_FID=No
plt
.
autoscale
(
enable
=
True
,
axis
=
'y'
,
tight
=
True
)
avg
=
0
for
FID
in
FIDlist
:
data
=
np
.
real
(
FID2Spec
(
FID
))
for
mrs
in
MRSList
:
data
=
np
.
real
(
mrs
.
getSpectrum
(
ppmlim
=
ppmlim
))
ppmAxisShift
=
mrs
.
getAxes
(
ppmlim
=
ppmlim
)
avg
+=
data
plt
.
plot
(
ppmAxisShift
,
data
,
color
=
'k'
,
linewidth
=
.
5
,
linestyle
=
'-'
)
if
single_FID
is
not
None
:
data
=
np
.
real
(
FID2Spec
(
single_FID
))
data
=
np
.
real
(
single_FID
.
getSpectrum
(
ppmlim
=
ppmlim
))
plt
.
plot
(
ppmAxisShift
,
data
,
color
=
'r'
,
linewidth
=
2
,
linestyle
=
'-'
)
if
plot_avg
:
avg
/=
len
(
FIDl
ist
)
avg
/=
len
(
MRSL
ist
)
plt
.
plot
(
ppmAxisShift
,
avg
,
color
=
'g'
,
linewidth
=
2
,
linestyle
=
'-'
)
autoscale_y
(
plt
.
gca
(),
margin
=
0.05
)
...
...
fsl_mrs/utils/qc.py
View file @
8edd9280
...
...
@@ -216,7 +216,7 @@ def getNoiseSDDist(specIn,noiseregionmask):
noiseOnlySpec
=
specIn
[
noiseregionmask
]
npoints
=
noiseOnlySpec
.
size
regionPoints
=
100
regionPoints
=
min
(
100
,
int
(
npoints
/
10
))
def
running_std_strides
(
seq
,
window
=
100
):
stride
=
seq
.
strides
[
0
]
...
...
fsl_mrs/utils/results.py
View file @
8edd9280
...
...
@@ -247,20 +247,17 @@ class FitRes(object):
# Functions to return physically meaningful units from the fitting results
def
getConc
(
self
,
scaling
=
'raw'
,
metab
=
None
,
function
=
'mean'
):
if
function
is
None
:
dfFunc
=
lambda
m
:
self
.
fitResults
[
m
]
.
values
dfFunc
=
lambda
m
:
self
.
fitResults
[
m
]
else
:
dfFunc
=
lambda
m
:
self
.
fitResults
[
m
].
apply
(
function
)
dfFunc
=
lambda
m
:
self
.
fitResults
[
m
].
apply
(
function
)
.
to_numpy
()
# Extract concentrations from parameters.
if
metab
is
not
None
:
if
metab
not
in
self
.
metabs
:
raise
ValueError
(
f
'
{
metab
}
is not a recognised metabolite.'
)
rawConc
=
np
.
asarray
(
dfFunc
(
metab
))
else
:
rawConc
=
[]
for
m
in
self
.
metabs
:
rawConc
.
append
(
dfFunc
(
m
))
rawConc
=
np
.
asarray
(
rawConc
)
rawConc
=
dfFunc
(
metab
)
else
:
rawConc
=
dfFunc
(
self
.
metabs
)
if
scaling
==
'raw'
:
return
rawConc
...
...
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