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

Merge branch 'enh/basis_alignment' into 'master'

ENH:Basis alignment tool

See merge request fsl/fsl_mrs!68
parents 72a51b48 a3c83096
Pipeline #15976 failed with stage
This document contains the FSL-MRS release history in reverse chronological order.
2.0.7 (Wednesday 19th October 2022)
2.0.7 (Thursday 20th October 2022)
-----------------------------------
- Added linear phase modulation to phasing processing tool, alternative to (interpolated) time domain time-shift
- Added more linear phase metrics to static fitting report.
- Refactored fitting models. 'Freeshift' model added to enable unconstrained frequency shifts.
- Added `basis_tools shift_all` command that can be used to tweak basis set based on a `freeshift` fit on high SNR data.
- Fix bug introduced in 2.0.5 in `fsl_mrs_preproc` where there was exactly one bad/good transient removed/kept.
2.0.6 (Monday 17th October 2022)
--------------------------------
......
......@@ -99,6 +99,21 @@ def main():
help='Output location, can overwrite.')
shiftparser.set_defaults(func=shift)
# Shift all peaks based on results
shiftparser = sp.add_parser(
'shift_all',
help='ADVANCED: Frequency shift all basis spectra using fit results. '
'This should only be carried out using high SNR population/cohort average data.')
shiftparser.add_argument('file', type=Path,
help='Basis file to modify')
shiftparser.add_argument('results_dir', type=Path,
help='Path to fit results dir. '
'Fit model must be free_shift. '
'Basis set metabolites must be identical.')
shiftparser.add_argument('output', type=Path,
help='Output location, can overwrite.')
shiftparser.set_defaults(func=all_shift)
# Rescale tool
scaleparser = sp.add_parser(
'scale',
......@@ -327,6 +342,21 @@ def shift(args):
basis.save(args.output, overwrite=True)
def all_shift(args):
from fsl_mrs.utils import basis_tools
from fsl_mrs.utils.mrs_io import read_basis
import pandas as pd
import numpy as np
basis = read_basis(args.file)
all_results = pd.read_csv(args.results_dir / 'all_parameters.csv', index_col=0)
shift_res = all_results.filter(regex='eps', axis=0)['mean'] / (2 * np.pi * basis.cf)
for name, shift in zip(basis.names, shift_res.to_list()):
basis = basis_tools.shift_basis(basis, name, shift)
basis.save(args.output, overwrite=True)
def rescale(args):
from fsl_mrs.utils import basis_tools
from fsl_mrs.utils.mrs_io import read_basis
......
......@@ -214,10 +214,14 @@ def main():
report=report_dir)
if bd_data is None:
bd_shape = 0
elif bd_data.ndim == 4:
bd_shape = 1
else:
bd_shape = bd_data.shape[4]
if supp_data is None:
supp_shape = 0
elif supp_data.ndim == 4:
supp_shape = 1
else:
supp_shape = supp_data.shape[4]
verbose_print(f'{bd_shape}/{supp_shape + bd_shape} '
......
......@@ -187,3 +187,5 @@ def test_remove_hlsvd(tmp_path):
assert out_loc.is_dir()
assert (out_loc / 'NAA.json').is_file()
# TO DO: Add tests fro shift_all
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