From d5b5b97eb2847cee0ecd90cf8c7b3173baddd14f Mon Sep 17 00:00:00 2001 From: Alexander R Craven <12934018+alexcraven@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:58:47 +0100 Subject: [PATCH] Added non-English character tests to test_ge_pfile Corresponding test data https://github.com/user-attachments/files/17702724/GE_character_encoding_test_data.zip expected under spec2nii_test_data/ge/pFiles/PRESS/MR30.1 --- tests/test_ge_pfile.py | 92 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/tests/test_ge_pfile.py b/tests/test_ge_pfile.py index 4489409..dcaba00 100644 --- a/tests/test_ge_pfile.py +++ b/tests/test_ge_pfile.py @@ -35,8 +35,12 @@ # HBCD / ISTHMUS datasets hbcd2_path = ge_path / 'pFiles' / 'hbcd' / 'P31744.7' +# Test set from Bergen (MR30.1, non-English characters in header text) +bergen_press_301 = ge_path / 'pFiles' / 'PRESS' / 'MR30.1' / 'P30101.7' +bergen_press_301_non_english = ge_path / 'pFiles' / 'PRESS' / 'MR30.1' / 'P30104.7' -def test_svs(tmp_path): + +def testsvs(tmp_path): subprocess.check_call(['spec2nii', 'ge', '-f', 'svs', @@ -68,7 +72,7 @@ def test_svs(tmp_path): assert np.isclose(hdr_ext['RepetitionTime'], 2.0) -def test_mrsi(tmp_path): +def testmrsi(tmp_path): subprocess.check_call(['spec2nii', 'ge', '-f', 'mrsi', @@ -90,7 +94,7 @@ def test_mrsi(tmp_path): assert hdr_ext['OriginalFile'][0] == mrsi_path.name -def test_mpress(tmp_path): +def testmpress(tmp_path): subprocess.check_call(['spec2nii', 'ge', '-f', 'mpress', @@ -123,7 +127,7 @@ def test_mpress(tmp_path): assert np.isclose(hdr_ext['RepetitionTime'], 2.0) -def test_mm_hercules(tmp_path): +def testmm_hercules(tmp_path): for path in mm_herc: subprocess.run([ 'spec2nii', 'ge', @@ -160,7 +164,7 @@ def test_mm_hercules(tmp_path): assert hdr_ext_ref['dim_7'] == 'DIM_EDIT' -def test_mm_hermes(tmp_path): +def testmm_hermes(tmp_path): for path in mm_hermes: subprocess.run([ 'spec2nii', 'ge', @@ -196,7 +200,7 @@ def test_mm_hermes(tmp_path): assert hdr_ext_ref['dim_7'] == 'DIM_EDIT' -def test_mm_mega(tmp_path): +def testmm_mega(tmp_path): for path in mm_mega.rglob('*.7'): subprocess.run([ 'spec2nii', 'ge', @@ -238,7 +242,7 @@ def test_mm_mega(tmp_path): assert hdr_ext_ref['dim_7'] == 'DIM_EDIT' -def test_mm_press(tmp_path): +def testmm_press(tmp_path): for path in mm_press.rglob('*.7'): subprocess.run([ 'spec2nii', 'ge', @@ -273,7 +277,7 @@ def test_mm_press(tmp_path): assert hdr_ext_ref['dim_6'] == 'DIM_DYN' -def test_mm_press_noid(tmp_path): +def testmm_press_noid(tmp_path): subprocess.run([ 'spec2nii', 'ge', '-f', mm_press_noid.stem, @@ -300,7 +304,7 @@ def test_mm_press_noid(tmp_path): assert hdr_ext_ref['dim_5'] == 'DIM_COIL' -def test_mm_slaser(tmp_path): +def testmm_slaser(tmp_path): subprocess.run([ 'spec2nii', 'ge', '-f', mm_slaser.stem, @@ -327,7 +331,7 @@ def test_mm_slaser(tmp_path): assert hdr_ext_ref['dim_5'] == 'DIM_COIL' -def test_hbcd_isthmus(tmp_path): +def testhbcd_isthmus(tmp_path): subprocess.run([ 'spec2nii', 'ge', '-f', 'hbcd', @@ -355,3 +359,71 @@ def test_hbcd_isthmus(tmp_path): img = NIFTI_MRS(tmp_path / 'hbcd_short_te.nii.gz') assert img.shape == (1, 1, 1, 2048, 32, 8) assert img.dim_tags == ['DIM_DYN', 'DIM_COIL', None] + + +def testsvs_bergen_301(tmp_path): + + subprocess.check_call(['spec2nii', 'ge', + '-f', 'svs', + '-o', tmp_path, + '-j', + str(bergen_press_301)]) + + img, hdr_ext = read_nifti_mrs_with_hdr(tmp_path / 'svs.nii.gz') + img_ref, hdr_ext_ref = read_nifti_mrs_with_hdr(tmp_path / 'svs_ref.nii.gz') + + assert img.shape == (1, 1, 1, 4096, 48, 2) + assert np.iscomplexobj(img.dataobj) + assert 1 / img.header['pixdim'][4] == 5000.0 + assert hdr_ext['WaterSuppressed'] + + assert img_ref.shape == (1, 1, 1, 4096, 48, 2) + assert np.iscomplexobj(img_ref.dataobj) + assert 1 / img_ref.header['pixdim'][4] == 5000.0 + assert not hdr_ext_ref['WaterSuppressed'] + + assert hdr_ext['dim_5'] == 'DIM_COIL' + assert hdr_ext['dim_6'] == 'DIM_DYN' + assert np.isclose(127.7, hdr_ext['SpectrometerFrequency'][0], atol=1E-1) + assert hdr_ext['ResonantNucleus'][0] == '1H' + + assert np.isclose(hdr_ext['EchoTime'], 0.03) + assert np.isclose(hdr_ext['RepetitionTime'], 2.0) + + assert hdr_ext['PatientName'] == 'fantom' + assert hdr_ext['SequenceName'] == 'PROBE-P' + assert hdr_ext['ProtocolName'] == 'PROBE-P' + + +def testsvs_bergen_301_non_english(tmp_path): + + subprocess.check_call(['spec2nii', 'ge', + '-f', 'svs', + '-o', tmp_path, + '-j', + str(bergen_press_301_non_english)]) + + img, hdr_ext = read_nifti_mrs_with_hdr(tmp_path / 'svs.nii.gz') + img_ref, hdr_ext_ref = read_nifti_mrs_with_hdr(tmp_path / 'svs_ref.nii.gz') + + assert img.shape == (1, 1, 1, 4096, 48, 2) + assert np.iscomplexobj(img.dataobj) + assert 1 / img.header['pixdim'][4] == 5000.0 + assert hdr_ext['WaterSuppressed'] + + assert img_ref.shape == (1, 1, 1, 4096, 48, 2) + assert np.iscomplexobj(img_ref.dataobj) + assert 1 / img_ref.header['pixdim'][4] == 5000.0 + assert not hdr_ext_ref['WaterSuppressed'] + + assert hdr_ext['dim_5'] == 'DIM_COIL' + assert hdr_ext['dim_6'] == 'DIM_DYN' + assert np.isclose(127.7, hdr_ext['SpectrometerFrequency'][0], atol=1E-1) + assert hdr_ext['ResonantNucleus'][0] == '1H' + + assert np.isclose(hdr_ext['EchoTime'], 0.03) + assert np.isclose(hdr_ext['RepetitionTime'], 2.0) + + assert hdr_ext['PatientName'] == 'fantom^prøve' + assert hdr_ext['SequenceName'] == 'PROBE-P' + assert hdr_ext['ProtocolName'] == 'PROBE-P åøæäöÅØÆÄÖ'