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
Hossein Rafipoor
fsl_mrs
Commits
fba26ca8
Commit
fba26ca8
authored
Jul 10, 2020
by
William Clarke
Browse files
Fix tests and phasing and multi coil data in pre_proc.
parent
6b1c0bd4
Changes
4
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/scripts/fsl_mrs_preproc
View file @
fba26ca8
...
...
@@ -413,9 +413,15 @@ def readData(files, conjugate):
if
conjugate
:
fid
=
np
.
conj
(
fid
)
else
:
mrs
=
MRS
(
FID
=
fid
,
header
=
header
)
mrs
.
check_FID
(
repair
=
True
)
fid
=
mrs
.
FID
if
fid
.
ndim
>
1
:
mrs
=
MRS
(
FID
=
np
.
mean
(
fid
,
axis
=
1
),
header
=
header
)
conj
=
mrs
.
check_FID
(
repair
=
True
)
if
conj
:
fid
=
np
.
conj
(
fid
)
else
:
mrs
=
MRS
(
FID
=
fid
,
header
=
header
)
mrs
.
check_FID
(
repair
=
True
)
fid
=
mrs
.
FID
if
shape
is
not
None
:
if
fid
.
shape
!=
shape
:
...
...
fsl_mrs/scripts/fsl_mrs_proc
View file @
fba26ca8
...
...
@@ -228,6 +228,8 @@ def main():
metavar
=
'<lower-limit upper-limit>'
,
default
=
(
2.8
,
3.2
),
help
=
'ppm limits of alignment window'
)
phase_group
.
add_argument
(
'--hlsvd'
,
action
=
"store_true"
,
help
=
'Remove peaks outside the search area'
)
phaseparser
.
set_defaults
(
func
=
phase
)
add_common_args
(
phaseparser
)
...
...
@@ -890,7 +892,8 @@ def phase(dataobj, args):
d
.
data
[
ijk
],
d
.
dataheader
[
'bandwidth'
],
d
.
dataheader
[
'centralFrequency'
]
*
1E6
,
ppmlim
=
args
[
'ppm'
])
ppmlim
=
args
[
'ppm'
],
hlsvd
=
args
[
'hlsvd'
])
if
args
[
'generateReports'
]
and
\
np
.
prod
(
d
.
data
.
shape
[:
3
])
==
1
and
\
...
...
fsl_mrs/tests/test_scripts_proc.py
View file @
fba26ca8
...
...
@@ -284,7 +284,7 @@ def test_average(svs_data, mrsi_data, tmp_path):
def
test_align
(
svs_data
,
mrsi_data
,
tmp_path
):
svsfile
,
mrsifile
,
svsdata
,
mrsidata
=
splitdata
(
svs_data
,
mrsi_data
)
# Run
coil combinatio
n on both sets of data using the command line
# Run
alig
n on both sets of data using the command line
subprocess
.
check_call
([
'fsl_mrs_proc'
,
'align'
,
'--file'
,
svsfile
[
0
],
svsfile
[
1
],
svsfile
[
2
],
...
...
@@ -304,9 +304,10 @@ def test_align(svs_data, mrsi_data, tmp_path):
niter
=
2
,
ppmlim
=
[
-
10.0
,
10.0
],
verbose
=
False
,
target
=
None
)
target
=
None
,
apodize
=
10
)
assert
np
.
is
close
(
data
,
directRun
[
0
])
.
all
()
assert
np
.
all
close
(
data
,
directRun
[
0
])
# Run coil combination on both sets of data using the command line
subprocess
.
check_call
([
'fsl_mrs_proc'
,
...
...
@@ -321,17 +322,18 @@ def test_align(svs_data, mrsi_data, tmp_path):
squeezeSVS
=
True
)
# Run using preproc.py directly
allFileData
=
[
d
[
2
,
2
,
2
,
...]
for
d
in
mrsidata
]
allFileData
=
[
d
[
2
,
2
,
2
,
...]
for
d
in
mrsidata
[
0
:
3
]
]
directRun
,
_
,
_
=
preproc
.
phase_freq_align
(
allFileData
,
4000
,
123E6
,
niter
=
2
,
ppmlim
=
[
-
10.0
,
10.0
],
verbose
=
False
,
target
=
None
)
target
=
None
,
apodize
=
10
)
assert
np
.
is
close
(
data
[
2
,
2
,
2
,
...],
directRun
[
0
],
atol
=
1E-
3
,
rtol
=
1E-
3
).
all
(
)
assert
np
.
all
close
(
data
[
2
,
2
,
2
,
...],
directRun
[
0
],
atol
=
1E-
1
,
rtol
=
1E-
1
)
def
test_ecc
(
svs_data
,
mrsi_data
,
tmp_path
):
...
...
fsl_mrs/utils/preproc/phasing.py
View file @
fba26ca8
...
...
@@ -22,7 +22,7 @@ def applyPhase(FID, phaseAngle):
return
FID
*
np
.
exp
(
1j
*
phaseAngle
)
def
phaseCorrect
(
FID
,
bw
,
cf
,
ppmlim
=
(
2.8
,
3.2
),
shift
=
True
,
no_
hlsvd
=
False
):
def
phaseCorrect
(
FID
,
bw
,
cf
,
ppmlim
=
(
2.8
,
3.2
),
shift
=
True
,
hlsvd
=
False
):
""" Phase correction based on the phase of a maximum point.
HLSVD is used to remove peaks outside the limits to flatten baseline first.
...
...
@@ -33,21 +33,23 @@ def phaseCorrect(FID, bw, cf, ppmlim=(2.8, 3.2), shift=True, no_hlsvd=False):
cf (float): central frequency in Hz
ppmlim (tuple,optional) : Limit to this ppm range
shift (bool,optional) : Apply H20 shft
no_
hlsvd (bool,optional)
: Dis
able hlsvd step
hlsvd (bool,optional)
: En
able hlsvd step
Returns:
FID (ndarray): Phase corrected FID
"""
# Run HLSVD to remove peaks outside limits
if
no_hlsvd
:
fid_hlsvd
=
FID
else
:
if
hlsvd
:
# Run HLSVD to remove peaks outside limits
try
:
fid_hlsvd
=
hlsvd
(
FID
,
1
/
bw
,
cf
,(
ppmlim
[
1
]
+
0.5
,
ppmlim
[
1
]
+
3.0
),
limitUnits
=
'ppm+shift'
)
fid_hlsvd
=
hlsvd
(
fid_hlsvd
,
1
/
bw
,
cf
,(
ppmlim
[
0
]
-
3.0
,
ppmlim
[
0
]
-
0.5
),
limitUnits
=
'ppm+shift'
)
except
:
fid_hlsvd
=
FID
print
(
'HLSVD in phaseCorrect failed, proceeding to phasing.'
)
else
:
fid_hlsvd
=
FID
# Find maximum of absolute spectrum in ppm limit
padFID
=
pad
(
fid_hlsvd
,
FID
.
size
*
3
)
MRSargs
=
{
'FID'
:
padFID
,
'bw'
:
bw
,
'cf'
:
cf
}
...
...
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