Skip to content

Commit

Permalink
Added non-English character tests to test_ge_pfile
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexcraven authored Nov 11, 2024
1 parent 97455bc commit d5b5b97
Showing 1 changed file with 82 additions and 10 deletions.
92 changes: 82 additions & 10 deletions tests/test_ge_pfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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 åøæäöÅØÆÄÖ'

0 comments on commit d5b5b97

Please sign in to comment.