Commit fba26ca8 authored by William Clarke's avatar William Clarke
Browse files

Fix tests and phasing and multi coil data in pre_proc.

parent 6b1c0bd4
......@@ -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:
......
......@@ -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 \
......
......@@ -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 combination on both sets of data using the command line
# Run align 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.isclose(data, directRun[0]).all()
assert np.allclose(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.isclose(data[2, 2, 2, ...], directRun[0],
atol=1E-3, rtol=1E-3).all()
assert np.allclose(data[2, 2, 2, ...], directRun[0],
atol=1E-1, rtol=1E-1)
def test_ecc(svs_data, mrsi_data, tmp_path):
......
......@@ -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) : Disable hlsvd step
hlsvd (bool,optional) : Enable 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}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment