コード例 #1
0
ファイル: spec2nii.py プロジェクト: wexeee/spec2nii
    def twix(self, args):
        """ Twix format handler."""
        from mapvbvd import mapVBVD
        from spec2nii.twixfunctions import process_twix, examineTwix

        # Call mapvbvd to load the twix file.
        twixObj = mapVBVD(args.file, quiet=args.quiet)

        if args.view:
            examineTwix(twixObj, op.basename(args.file), args.multiraid)
        else:
            if isinstance(twixObj, list):
                twixObj = twixObj[args.multiraid - 1]

            if not args.quiet:
                print(f"Converting twix file {args.file}.")
                print(f'Looking for evalinfo flag {args.evalinfo}.')

            overrides = {
                'dims': (args.dim5, args.dim6, args.dim7),
                'tags': (args.tag5, args.tag6, args.tag7)
            }

            self.imageOut, self.fileoutNames = process_twix(
                twixObj, args.fileout, args.file.name, args.evalinfo,
                overrides, args.quiet, args.verbose)
コード例 #2
0
ファイル: test_flags.py プロジェクト: wexeee/pymapvbvd
def test_flagRemoveOS():
    twixObj = mapVBVD(test_data_gre, quiet=False)
    twixObj[1].image.flagRemoveOS = False
    assert np.allclose(twixObj[1].image.dataSize,
                       [256, 16, 128, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
    twixObj[1].image.flagRemoveOS = True
    assert np.allclose(twixObj[1].image.dataSize,
                       [128, 16, 128, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

    # broken file
    twixObj = mapVBVD(test_data_vb_broken, quiet=False)
    twixObj.image.flagRemoveOS = False
    assert np.allclose(twixObj.image.dataSize,
                       [4096, 32, 1, 1, 1, 1, 1, 1, 1, 97, 1, 1, 1, 1, 1, 1])
    twixObj.image.flagRemoveOS = True
    assert np.allclose(twixObj.image.dataSize,
                       [2048, 32, 1, 1, 1, 1, 1, 1, 1, 97, 1, 1, 1, 1, 1, 1])
コード例 #3
0
ファイル: test_svs.py プロジェクト: wexeee/pymapvbvd
def test_vb():
    twixObj = mapVBVD(test_data_vb, quiet=False)
    assert np.allclose(twixObj.image.fullSize, [4096, 32, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1])
    assert np.allclose(twixObj.image.sqzSize, [2048, 32, 2])

    keys = twixObj.search_header_for_keys(('sTXSPEC', 'asNucleusInfo'), top_lvl='MeasYaps')
    assert ('sTXSPEC', 'asNucleusInfo', '0', 'tNucleus') in keys['MeasYaps']
    key_value = twixObj.search_header_for_val('MeasYaps', ('sTXSPEC', 'asNucleusInfo', '0', 'tNucleus'))
    assert key_value[0] == '"1H"'
コード例 #4
0
ファイル: test_flags.py プロジェクト: wexeee/pymapvbvd
def test_flagSkipToFirstLine():
    twixObj = mapVBVD(test_data_epi, quiet=False)

    twixObj[1].refscan.flagSkipToFirstLine = False
    assert np.allclose(twixObj[1].refscan.dataSize,
                       [110, 16, 82, 1, 5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1])
    twixObj[1].refscan.flagSkipToFirstLine = True
    assert np.allclose(twixObj[1].refscan.dataSize,
                       [110, 16, 54, 1, 5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1])
コード例 #5
0
ファイル: test_read.py プロジェクト: wexeee/pymapvbvd
def test_gre():
    twixObj = mapVBVD(test_data_gre, quiet=False)
    twixObj[1].image.squeeze = True
    twixObj[1].image.flagRemoveOS = False
    img_py = twixObj[1].image[:, :, :, 0]
    twixObj[1].image.flagRemoveOS = True
    img_py_os = twixObj[1].image[:, :, :, 0]

    with h5py.File(test_data_gre_mat, 'r') as f:
        base = f['img'][0, 0, :, :, :]
        img_mat = (base['real'] + 1j * base['imag']).transpose()
        base = f['img_os'][0, 0, :, :, :]
        img_mat_os = (base['real'] + 1j * base['imag']).transpose()

    assert np.allclose(img_py, img_mat)
    assert np.allclose(img_py_os, img_mat_os)
コード例 #6
0
ファイル: test_flags.py プロジェクト: wexeee/pymapvbvd
def test_flagIgnoreSeg_flagDoAverage():
    twixObj = mapVBVD(test_data_epi, quiet=False)

    twixObj[1].refscanPC.flagIgnoreSeg = False
    twixObj[1].refscanPC.flagDoAverage = False
    assert np.allclose(twixObj[1].refscanPC.dataSize,
                       [110, 16, 1, 1, 5, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1])
    twixObj[1].refscanPC.flagDoAverage = True
    assert np.allclose(twixObj[1].refscanPC.dataSize,
                       [110, 16, 1, 1, 5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1])

    twixObj[1].refscanPC.flagIgnoreSeg = True
    twixObj[1].refscanPC.flagDoAverage = False
    assert np.allclose(twixObj[1].refscanPC.dataSize,
                       [110, 16, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
    twixObj[1].refscanPC.flagDoAverage = True
    assert np.allclose(twixObj[1].refscanPC.dataSize,
                       [110, 16, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
コード例 #7
0
ファイル: test_read.py プロジェクト: wexeee/pymapvbvd
def test_epi():
    twixObj = mapVBVD(test_data_epi, quiet=False)
    twixObj[1].image.squeeze = True
    twixObj[1].image.flagRampSampRegrid = False
    twixObj[1].image.flagRemoveOS = False
    img_py = twixObj[1].image[:, :, :, 0, 0, 0]
    twixObj[1].image.flagRemoveOS = True
    img_py_os = twixObj[1].image[:, :, :, 0, 0, 0]
    twixObj[1].image.flagRampSampRegrid = True
    img_py_os_rg = twixObj[1].image[:, :, :, 0, 0, 0]

    with h5py.File(test_data_epi_mat, 'r') as f:
        base = f['img'][0, 0, 0, 0, 0, 0, 0, 0, :, :, :]
        img_mat = (base['real'] + 1j * base['imag']).transpose()
        base = f['img_os'][0, 0, 0, 0, 0, 0, 0, 0, :, :, :]
        img_mat_os = (base['real'] + 1j * base['imag']).transpose()
        base = f['img_os_rg'][0, 0, 0, 0, 0, 0, 0, 0, :, :, :]
        img_mat_os_rg = (base['real'] + 1j * base['imag']).transpose()

    assert np.allclose(img_py, img_mat)
    assert np.allclose(img_py_os, img_mat_os)
    assert np.allclose(img_py_os_rg, img_mat_os_rg, atol=1e-6, rtol=1e-6)
コード例 #8
0
def test_vb():
    twixObj = mapVBVD(test_data_vb, quiet=False)
    twixObj.image.flagRemoveOS = False
    assert np.allclose(twixObj.image.fullSize,
                       [4096, 32, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1])
    assert np.allclose(twixObj.image.sqzSize, [4096, 32, 2])

    twixObj.image.squeeze = True
    assert twixObj.image[0:2000, 0:32:4, 0:2].shape == (2000, 8, 2)
    assert twixObj.image[1000:2000, 0:32:4, 1].shape == (1000, 8)
    assert twixObj.image[10, 0:32:4, 1].shape == (8, )

    fulldata = twixObj.image['']
    assert np.allclose(twixObj.image[1000:2000, 0:32:4, 1],
                       fulldata[1000:2000, 0:32:4, 1])

    twixObj.image.squeeze = False
    assert twixObj.image[0:2000, 0:32:4, :, :, :, :, :, :,
                         0:2, :].shape == (2000, 8, 1, 1, 1, 1, 1, 1, 2, 1, 1,
                                           1, 1, 1, 1, 1)
    assert np.allclose(
        np.squeeze(twixObj.image[1000:2000, 0:32:4, :, :, :, :, :, :, 1, :]),
        fulldata[1000:2000, 0:32:4, 1])