diff --git a/.gitignore b/.gitignore index b1cd690..e344584 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ __pycache__/ *.egg-info/ .vscode tmp_notes +build + diff --git a/CHANGELOG.md b/CHANGELOG.md index 2da23df..83296df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ This document contains the nifti_mrs_tools release history in reverse chronological order. +0.1.2 (Thursday 12th January 2023) +---------------------------------- +- Add option to prevent conjugation with numpy data. For spec2nii compatibility. + 0.1.1 (Wednesday 11th January 2023) ----------------------------------- - Make compliant with NIfTI-MRS V0.6 diff --git a/src/nifti_mrs/create_nmrs.py b/src/nifti_mrs/create_nmrs.py index d578ce9..1fa7731 100644 --- a/src/nifti_mrs/create_nmrs.py +++ b/src/nifti_mrs/create_nmrs.py @@ -37,7 +37,15 @@ def _default_affine(): return default -def gen_nifti_mrs(data, dwelltime, spec_freq, nucleus='1H', affine=None, dim_tags=[None, None, None], nifti_version=2): +def gen_nifti_mrs( + data, + dwelltime, + spec_freq, + nucleus='1H', + affine=None, + dim_tags=[None, None, None], + nifti_version=2, + no_conj=False): """Generate NIfTI-MRS from data and required metadata :param data: Complex-typed numpy array of at least 4 dimensions (max 7) @@ -54,6 +62,8 @@ def gen_nifti_mrs(data, dwelltime, spec_freq, nucleus='1H', affine=None, dim_tag :type dim_tags: list, optional :param nifti_version: Version of NIfTI header format, defaults to 2 :type nifti_version: int, optional + :param no_conj: If true stops conjugation of data on creation, defaults to False + :type no_conj: bool, optional :return: NIfTI-MRS object :rtype: nifti_mrs.nifti_mrs.NIFTI_MRS """ @@ -74,10 +84,11 @@ def gen_nifti_mrs(data, dwelltime, spec_freq, nucleus='1H', affine=None, dim_tag dwelltime, hdr_ext, affine=affine, - nifti_version=nifti_version) + nifti_version=nifti_version, + no_conj=no_conj) -def gen_nifti_mrs_hdr_ext(data, dwelltime, hdr_ext, affine=None, nifti_version=2): +def gen_nifti_mrs_hdr_ext(data, dwelltime, hdr_ext, affine=None, nifti_version=2, no_conj=False): """Generate NIfTI-MRS from data and header extension object :param data: Complex-typed numpy array of at least 4 dimensions (max 7) @@ -92,6 +103,8 @@ def gen_nifti_mrs_hdr_ext(data, dwelltime, hdr_ext, affine=None, nifti_version=2 :type dim_tags: list, optional :param nifti_version: Version of NIfTI header format, defaults to 2 :type nifti_version: int, optional + :param no_conj: If true stops conjugation of data on creation, defaults to False + :type no_conj: bool, optional :return: NIfTI-MRS object :rtype: nifti_mrs.nifti_mrs.NIFTI_MRS """ @@ -133,4 +146,7 @@ def gen_nifti_mrs_hdr_ext(data, dwelltime, hdr_ext, affine=None, nifti_version=2 extension = nib.nifti1.Nifti1Extension(44, json_s.encode('UTF-8')) header.extensions.append(extension) - return NIFTI_MRS(data, header=header) + if no_conj: + return NIFTI_MRS(data.conj(), header=header) + else: + return NIFTI_MRS(data, header=header) diff --git a/tests/test_create_nmrs.py b/tests/test_create_nmrs.py index 7f14966..6f2490d 100644 --- a/tests/test_create_nmrs.py +++ b/tests/test_create_nmrs.py @@ -72,3 +72,11 @@ def test_gen_new_nifti_mrs_conj(tmp_path): nucleus='1H') assert np.allclose(nmrs[:], obj_in[:]) + + nmrs = gen_nifti_mrs(obj_in[:], + obj_in.dwelltime, + obj_in.spectrometer_frequency[0], + nucleus='1H', + no_conj=True) + + assert np.allclose(nmrs[:], obj_in[:].conj())