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

Finished processing provenance in preprocessing.

parent 9db53ccb
......@@ -76,3 +76,143 @@ def test_aligndiff():
assert aligned.hdr_ext['ProcessingApplied'][0]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.aligndiff, dim_align=DIM_COIL, '\
'dim_diff=DIM_DYN, diff_type=add, target=None, ppmlim=(1.0, 4.0).'
def test_ecc():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
ref_obj = read_FID(ecc)
corrected = nproc.ecc(nmrs_obj, reference=ref_obj)
assert corrected.hdr_ext['ProcessingApplied'][1]['Method'] == 'Eddy current correction'
assert corrected.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.ecc, reference=ecc.nii.gz.'
def test_remove():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
corrected = nproc.remove_peaks(nmrs_obj, (4, 5.30))
assert corrected.hdr_ext['ProcessingApplied'][1]['Method'] == 'Nuisance peak removal'
assert corrected.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.remove_peaks, limits=(4, 5.3), limit_units=ppm+shift.'
def test_tshift():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
shifted = nproc.tshift(nmrs_obj, tshiftStart=0.001, tshiftEnd=0.001, samples=1024)
assert shifted.hdr_ext['ProcessingApplied'][1]['Method'] == 'Temporal resample'
assert shifted.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.tshift, tshiftStart=0.001, tshiftEnd=0.001, samples=1024.'
def test_truncate_or_pad():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
shifted = nproc.truncate_or_pad(nmrs_obj, -2, 'last')
assert shifted.hdr_ext['ProcessingApplied'][1]['Method'] == 'Zero-filling'
assert shifted.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.truncate_or_pad, npoints=-2, position=last.'
def test_apodize():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
apodized = nproc.apodize(nmrs_obj, (10.0,))
assert apodized.hdr_ext['ProcessingApplied'][1]['Method'] == 'Apodization'
assert apodized.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.apodize, amount=(10.0,), filter=exp.'
def test_fshift():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
shifted = nproc.fshift(nmrs_obj, 10.0)
assert shifted.hdr_ext['ProcessingApplied'][1]['Method'] == 'Frequency and phase correction'
assert shifted.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.fshift, amount=10.0.'
def test_shift_to_reference():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
shifted = nproc.shift_to_reference(nmrs_obj, 4.65, (4.0, 5.0))
assert shifted.hdr_ext['ProcessingApplied'][1]['Method'] == 'Frequency and phase correction'
assert shifted.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.shift_to_reference, ppm_ref=4.65, peak_search=(4.0, 5.0).'
def test_remove_unlike():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.coilcombine(nmrs_obj)
processed, _ = nproc.remove_unlike(nmrs_obj)
assert processed.hdr_ext['ProcessingApplied'][1]['Method'] == 'Outlier removal'
assert processed.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.remove_unlike, ppmlim=None, sdlimit=1.96, niter=2.'
def test_phase_correct():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
phased = nproc.phase_correct(nmrs_obj, (4.0, 5.0), hlsvd=False)
assert phased.hdr_ext['ProcessingApplied'][1]['Method'] == 'Phasing'
assert phased.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.phase_correct, ppmlim=(4.0, 5.0), hlsvd=False.'
def test_apply_fixed_phase():
nmrs_obj = read_FID(wrefc)
nmrs_obj = nproc.average(nmrs_obj, 'DIM_DYN')
phased = nproc.apply_fixed_phase(nmrs_obj, 180.0, p1=0.001)
assert phased.hdr_ext['ProcessingApplied'][1]['Method'] == 'Phasing'
assert phased.hdr_ext['ProcessingApplied'][1]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.apply_fixed_phase, p0=180.0, p1=0.001.'
def test_subtract():
nmrs_obj = read_FID(wrefc)
subtracted = nproc.subtract(nmrs_obj, dim='DIM_DYN')
assert subtracted.hdr_ext['ProcessingApplied'][0]['Method'] == 'Subtraction of sub-spectra'
assert subtracted.hdr_ext['ProcessingApplied'][0]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.subtract, data1=None, dim=DIM_DYN.'
def test_add():
nmrs_obj = read_FID(wrefc)
added = nproc.add(nmrs_obj, dim='DIM_DYN')
assert added.hdr_ext['ProcessingApplied'][0]['Method'] == 'Addition of sub-spectra'
assert added.hdr_ext['ProcessingApplied'][0]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.add, data1=None, dim=DIM_DYN.'
def test_conjugate():
nmrs_obj = read_FID(wrefc)
conjugated = nproc.conjugate(nmrs_obj)
assert conjugated.hdr_ext['ProcessingApplied'][0]['Method'] == 'Conjugation'
assert conjugated.hdr_ext['ProcessingApplied'][0]['Details']\
== 'fsl_mrs.utils.preproc.nifti_mrs_proc.conjugate.'
......@@ -297,6 +297,7 @@ def aligndiff(data,
if figure:
for ff in fig:
ff.show()
# Update processing prov
processing_info = f'{__name__}.aligndiff, '
processing_info += f'dim_align={dim_align}, '
......@@ -351,6 +352,12 @@ def ecc(data, reference, figure=False, report=None, report_all=False):
for ff in fig:
ff.show()
# Update processing prov
processing_info = f'{__name__}.ecc, '
processing_info += f'reference={reference.filename}.'
update_processing_prov(corrected_obj, 'Eddy current correction', processing_info)
return corrected_obj
......@@ -387,6 +394,13 @@ def remove_peaks(data, limits, limit_units='ppm+shift', figure=False, report=Non
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.remove_peaks, '
processing_info += f'limits={limits}, '
processing_info += f'limit_units={limit_units}.'
update_processing_prov(corrected_obj, 'Nuisance peak removal', processing_info)
return corrected_obj
......@@ -439,6 +453,14 @@ def tshift(data, tshiftStart=0.0, tshiftEnd=0.0, samples=None, figure=False, rep
shifted_obj.dwelltime = newDT
# Update processing prov
processing_info = f'{__name__}.tshift, '
processing_info += f'tshiftStart={tshiftStart}, '
processing_info += f'tshiftEnd={tshiftEnd}, '
processing_info += f'samples={samples}.'
update_processing_prov(shifted_obj, 'Temporal resample', processing_info)
return shifted_obj
......@@ -489,6 +511,14 @@ def truncate_or_pad(data, npoints, position, figure=False, report=None, report_a
function=rep_func)
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.truncate_or_pad, '
processing_info += f'npoints={npoints}, '
processing_info += f'position={position}.'
update_processing_prov(trunc_obj, 'Zero-filling', processing_info)
return trunc_obj
......@@ -523,6 +553,13 @@ def apodize(data, amount, filter='exp', figure=False, report=None, report_all=Fa
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.apodize, '
processing_info += f'amount={amount}, '
processing_info += f'filter={filter}.'
update_processing_prov(apod_obj, 'Apodization', processing_info)
return apod_obj
......@@ -558,6 +595,12 @@ def fshift(data, amount, figure=False, report=None, report_all=False):
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.fshift, '
processing_info += f'amount={amount}.'
update_processing_prov(shift_obj, 'Frequency and phase correction', processing_info)
return shift_obj
......@@ -596,6 +639,13 @@ def shift_to_reference(data, ppm_ref, peak_search, figure=False, report=None, re
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.shift_to_reference, '
processing_info += f'ppm_ref={ppm_ref}, '
processing_info += f'peak_search={peak_search}.'
update_processing_prov(shift_obj, 'Frequency and phase correction', processing_info)
return shift_obj
......@@ -659,6 +709,17 @@ def remove_unlike(data, ppmlim=None, sdlimit=1.96, niter=2, figure=False, report
else:
bad_out = None
# Update processing prov
processing_info = f'{__name__}.remove_unlike, '
if ppmlim is None:
processing_info += 'ppmlim=None, '
else:
processing_info += f'ppmlim={ppmlim}, '
processing_info += f'sdlimit={sdlimit}, '
processing_info += f'niter={niter}.'
update_processing_prov(good_out, 'Outlier removal', processing_info)
return good_out, bad_out
......@@ -698,6 +759,13 @@ def phase_correct(data, ppmlim, hlsvd=True, figure=False, report=None, report_al
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.phase_correct, '
processing_info += f'ppmlim={ppmlim}, '
processing_info += f'hlsvd={hlsvd}.'
update_processing_prov(phs_obj, 'Phasing', processing_info)
return phs_obj
......@@ -741,6 +809,13 @@ def apply_fixed_phase(data, p0, p1=0.0, figure=False, report=None, report_all=Fa
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.apply_fixed_phase, '
processing_info += f'p0={p0}, '
processing_info += f'p1={p1}.'
update_processing_prov(phs_obj, 'Phasing', processing_info)
return phs_obj
......@@ -792,6 +867,19 @@ def subtract(data0, data1=None, dim=None, figure=False, report=None, report_all=
else:
raise ValueError('One of data1 or dim arguments must not be None.')
# Update processing prov
processing_info = f'{__name__}.subtract, '
if data1 is None:
processing_info += 'data1=None, '
else:
processing_info += f'data1={data1.filename}, '
if dim is None:
processing_info += 'dim=None.'
else:
processing_info += f'dim={dim}.'
update_processing_prov(sub_ob, 'Subtraction of sub-spectra', processing_info)
return sub_ob
......@@ -843,6 +931,19 @@ def add(data0, data1=None, dim=None, figure=False, report=None, report_all=False
else:
raise ValueError('One of data1 or dim arguments must not be None.')
# Update processing prov
processing_info = f'{__name__}.add, '
if data1 is None:
processing_info += 'data1=None, '
else:
processing_info += f'data1={data1.filename}, '
if dim is None:
processing_info += 'dim=None.'
else:
processing_info += f'dim={dim}.'
update_processing_prov(add_ob, 'Addition of sub-spectra', processing_info)
return add_ob
......@@ -877,4 +978,8 @@ def conjugate(data, figure=False, report=None, report_all=False):
if figure:
fig.show()
# Update processing prov
processing_info = f'{__name__}.conjugate.'
update_processing_prov(conj_data, 'Conjugation', processing_info)
return conj_data
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