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

Add all option to command line.

parent 6892a023
This document contains the FSL-MRS release history in reverse chronological order.
1.1.5 (WIP)
-------------------------------
- fsl_mrs_proc align can now align across all higher dimension FIDs. Pass 'all' as dimension tag.
1.1.4 (Tuesday 3rd August 2021)
-------------------------------
- Fixed bug in calculation of molality concentration. Tissue mole fractions had been swapped for tissue volume fractions. Molar concentrations unaffected.
......
......@@ -85,6 +85,7 @@ def main():
help='List of files to align')
align_group.add_argument('--dim', type=str, default='DIM_DYN',
help='NIFTI-MRS dimension tag to align across.'
'Or "all" to align over all spectra in higer dimensions.'
'Default = DIM_DYN')
align_group.add_argument('--ppm', type=float, nargs=2,
metavar='<lower-limit upper-limit>',
......@@ -473,7 +474,9 @@ def average(dataobj, args):
def align(dataobj, args):
if args['dim'] not in dataobj.data.dim_tags:
if args['dim'].lower() == 'all':
pass
elif args['dim'] not in dataobj.data.dim_tags:
raise InappropriateDataError(f'Data ({dataobj.datafilename}) has no {args["dim"]} dimension.'
f' Dimensions are is {dataobj.data.dim_tags}.')
......
......@@ -195,11 +195,42 @@ def mrsi_data_diff(tmp_path):
return testfile, nmrs
@pytest.fixture
def svs_data_uncomb_reps(tmp_path):
coils = 2
noiseconv = 0.1 * np.eye(coils)
coilamps = np.random.randn(coils)
coilphs = np.random.random(coils) * 2 * np.pi
FID, hdr = syntheticFID(noisecovariance=noiseconv,
coilamps=coilamps,
coilphase=coilphs,
points=512)
FID2, hdr = syntheticFID(noisecovariance=noiseconv,
coilamps=coilamps,
coilphase=coilphs,
points=512)
FID = np.stack((np.asarray(FID).T, np.asarray(FID2).T), axis=2)
FID = FID.reshape((1, 1, 1) + FID.shape)
nmrs = gen_new_nifti_mrs(FID,
hdr['dwelltime'],
hdr['centralFrequency'],
dim_tags=['DIM_COIL', 'DIM_DYN', None])
testname = 'svsdata_uncomb_reps.nii'
testfile = op.join(tmp_path, testname)
nmrs.save(testfile)
return testfile, nmrs
def splitdata(svs, mrsi):
return svs[0], mrsi[0], svs[1], mrsi[1]
def test_filecreation(svs_data, mrsi_data, svs_data_uncomb, mrsi_data_uncomb):
def test_filecreation(svs_data, mrsi_data, svs_data_uncomb, mrsi_data_uncomb, svs_data_uncomb_reps):
svsfile, mrsifile, svsdata, mrsidata = splitdata(svs_data, mrsi_data)
data = read_FID(svsfile)
......@@ -221,6 +252,11 @@ def test_filecreation(svs_data, mrsi_data, svs_data_uncomb, mrsi_data_uncomb):
assert data.shape == (2, 2, 2, 512, 4)
assert np.allclose(data.data, mrsidata.data)
# Uncombined and reps
data = read_FID(svs_data_uncomb_reps[0])
assert data.shape == (1, 1, 1, 512, 2, 2)
assert np.allclose(data.data, svs_data_uncomb_reps[1].data)
def test_coilcombine(svs_data_uncomb, mrsi_data_uncomb, tmp_path):
svsfile, mrsifile, svsdata, mrsidata = splitdata(svs_data_uncomb,
......@@ -313,7 +349,6 @@ def test_align(svs_data, mrsi_data, tmp_path):
assert np.allclose(data.data, directRun.data)
# Run coil combination on both sets of data using the command line
subprocess.check_call(['fsl_mrs_proc',
'align',
'--dim', 'DIM_DYN',
......@@ -331,6 +366,27 @@ def test_align(svs_data, mrsi_data, tmp_path):
assert np.allclose(data.data, directRun.data, atol=1E-1, rtol=1E-1)
def test_align_all(svs_data_uncomb_reps, tmp_path):
svsfile, svsdata = svs_data_uncomb_reps[0], svs_data_uncomb_reps[1]
# Run align on both sets of data using the command line
subprocess.check_call(['fsl_mrs_proc',
'align',
'--dim', 'all',
'--file', svsfile,
'--ppm', '-10', '10',
'--output', tmp_path,
'--filename', 'tmp'])
# Load result for comparison
data = read_FID(op.join(tmp_path, 'tmp.nii.gz'))
# Run directly
directRun = preproc.align(svsdata, 'all', ppmlim=(-10, 10))
assert np.allclose(data.data, directRun.data)
def test_ecc(svs_data, mrsi_data, tmp_path):
svsfile, mrsifile, svsdata, mrsidata = splitdata(svs_data, mrsi_data)
......
......@@ -179,7 +179,7 @@ def align(data, dim, target=None, ppmlim=None, niter=2, apodize=10, figure=False
aligned_obj = data.copy()
if dim == 'all':
if dim.lower() == 'all':
generator = data.iterate_over_spatial()
else:
generator = data.iterate_over_dims(dim=dim,
......
Markdown is supported
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