Commit 9c6c2917 authored by William Clarke's avatar William Clarke
Browse files

Merge branch 'BF_fslmrsi_basis_conj' into 'master'

BF: Conjugation of basis in fsl_mrsi now happens before adding any MM. Fixed report MRM reference.

Closes #17 and #18

See merge request !26
parents 04adb4db bf30a6dd
Pipeline #11111 passed with stages
in 2 minutes and 15 seconds
This document contains the FSL-MRS release history in reverse chronological order.
1.1.8 (Tuesday 5th October 2021)
-------------------------------
- Fix bug in fsl_mrsi when default MM are added to a incorrectly conjugated basis set.
- Fix MRM reference in HTML report.
1.1.7 (Monday 4th October 2021)
-------------------------------
- Fixed commandline arguments for mrs_tools.
......
......@@ -73,8 +73,7 @@ class MRSI(object):
self.num_masked_voxels = np.sum(self.mask)
# MRS output options
self.conj_basis = False
self.no_conj_basis = False
self.conj_basis = None
self.conj_FID = False
self.no_conj_FID = False
self.rescale = False
......@@ -195,10 +194,14 @@ class MRSI(object):
def mrs_by_index(self, index):
''' Return MRS object by index (tuple - x,y,z).'''
if not np.array_equal(self.H2O, np.full(self.data.shape[:3], None)):
H2O = self.H2O[index[0], index[1], index[2], :]
else:
H2O = None
mrs_out = MRS(FID=self.data[index[0], index[1], index[2], :],
header=self.header,
basis=self._basis,
H2O=self.H2O[index[0], index[1], index[2], :])
H2O=H2O)
self._process_mrs(mrs_out)
return mrs_out
......@@ -237,10 +240,10 @@ class MRSI(object):
to all voxels.
'''
if self._basis is not None:
if self.conj_basis:
if self.conj_basis is True:
mrs.conj_Basis = True
elif self.no_conj_basis:
pass
elif self.conj_basis is False:
mrs.conj_Basis = False
else:
mrs.check_Basis(repair=True)
......@@ -352,6 +355,19 @@ class MRSI(object):
return data
def check_basis(self, ppmlim=(.2, 4.2)):
"""Check orientation of basis using a single generated mrs object.
:param ppmlim: Region of expected signal, defaults to (.2, 4.2)
:type ppmlim: tuple, optional
"""
if self._basis is not None:
mrs = self.mrs_by_index((0, 0, 0))
mrs.check_Basis(ppmlim=ppmlim, repair=True)
self.conj_basis = mrs.conj_Basis
else:
raise AttributeError('MRSI._basis not populated, add basis.')
def add_MM_peaks(self, ppmlist=None, amplist=None, gamma=0, sigma=0):
"""Add default MM spectra to basis set
......@@ -384,7 +400,12 @@ class MRSI(object):
names = [f'MM{i[0]*10:02.0f}' for i in ppmlist]
if self.conj_basis is True:
conj = True
else:
conj = False
for name, ppm, amp in zip(names, ppmlist, amplist):
self._basis.add_peak(ppm, amp, name, gamma, sigma)
self._basis.add_peak(ppm, amp, name, gamma, sigma, conj=conj)
return len(ppmlist)
......@@ -199,14 +199,20 @@ def main():
mrsi.set_tissue_seg(csf, wm, gm)
# Set mrs output options from MRSI class object
mrsi.conj_basis = args.conj_basis
mrsi.no_conj_basis = args.no_conj_basis
mrsi.conj_FID = args.conj_fid
mrsi.no_conj_FID = args.no_conj_fid
mrsi.rescale = not args.no_rescale
mrsi.keep = args.keep
mrsi.ignore = args.ignore
# Basis orientation
if args.conj_basis:
mrsi.conj_basis = True
elif args.no_conj_basis:
mrsi.conj_basis = False
else:
mrsi.check_basis(ppmlim=args.ppmlim)
# Parse metabolite groups
metab_groups = misc.parse_metab_groups(mrsi, args.metab_groups)
......
......@@ -394,7 +394,7 @@ def create_report(mrs, res, filename, fidfile, basisfile, h2ofile, date, locatio
else:
algo = ""
methods = f"<p>Fitting of the SVS data was performed using a Linear Combination model as described in [1] and as implemented in FSL-MRS version {__version__}, part of FSL (FMRIB's Software Library, www.fmrib.ox.ac.uk/fsl). Briefly, basis spectra are fitted to the complex-valued spectrum in the frequency domain. The basis spectra are shifted and broadened with parameters fitted to the data and grouped into {max(res.metab_groups)+1} metabolite groups. A complex polynomial baseline is also concurrrently fitted (order={res.baseline_order}). {algo} <p><h3>References</h3><p>[1] Clarke WT, Stagg CJ, Jbabdi S. FSL-MRS: An end-to-end spectroscopy analysis package. Magnetic Resonance in Medicine 2021;85:29502964 doi: 10.1002/mrm.28630."
methods = f"<p>Fitting of the SVS data was performed using a Linear Combination model as described in [1] and as implemented in FSL-MRS version {__version__}, part of FSL (FMRIB's Software Library, www.fmrib.ox.ac.uk/fsl). Briefly, basis spectra are fitted to the complex-valued spectrum in the frequency domain. The basis spectra are shifted and broadened with parameters fitted to the data and grouped into {max(res.metab_groups)+1} metabolite groups. A complex polynomial baseline is also concurrrently fitted (order={res.baseline_order}). {algo} <p><h3>References</h3><p>[1] Clarke WT, Stagg CJ, Jbabdi S. FSL-MRS: An end-to-end spectroscopy analysis package. Magnetic Resonance in Medicine 2021;85:2950-2964 doi: 10.1002/mrm.28630."
section = f"""
<h1><a name="methods">Analysis methods</a></h1>
<div>{methods}</div>
......
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