Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mrs_tools info interprets dwelltime and spectral width wrongly when time unit is not second #33

Closed
Microdeep-ZL opened this issue Nov 7, 2024 · 1 comment

Comments

@Microdeep-ZL
Copy link
Contributor

Microdeep-ZL commented Nov 7, 2024

Hi,

I'm working on developing a tool to convert Bruker ParaVision 6.0.1 specoscopy data into NIfTI-MRS format (because spec2nii crashes with our data). When I tested the generated .nii.gz file, I found that mrs_tools info doesn't interpret dwell time and spectral width correctly when time unit is not second.

FSL-MRS version: 2.3.1
python version: 3.12

Below is a minimal example to reproduce the error.

import nibabel as nib
import numpy as np
import json

N=128
dwelltime=125

fid = np.linspace(1,10,N,dtype=np.complex64).reshape(1,1,1,N)
hdrext = json.loads('''
{
        "ResonantNucleus": [
            "13C"
        ],
        "SpectrometerFrequency": [
            100.679124582065
        ]
}
''')

header=nib.nifti2.Nifti2Header()
header.set_data_dtype(fid.dtype)
header.set_xyzt_units('mm','usec')
header["intent_name"]=np.array([b'mrs_v0_9'],dtype='S16')
header["dim"]=np.array([4,1,1,1,N,1,1,1])
header["pixdim"]=np.array([1,10000,10000,10000,dwelltime,1,1,1])

vox_offset=np.ceil((header["sizeof_hdr"] + 4 + header.extensions.get_sizeondisk())/16)*16
header["vox_offset"]=vox_offset
header.single_vox_offset=vox_offset


headerext=nib.nifti1.Nifti1Extension(44,json.dumps(hdrext).encode())
header.extensions.append(headerext)
spec=nib.nifti2.Nifti2Image(fid,None,header)
nib.nifti2.save(spec,'demo.nii.gz')
$ mrs_tools info ./demo.nii.gz
File demo.nii.gz (/home/nmr/Projects/NIfTI_MRS_converter)
NIfTI-MRS version 0.9
Data shape (1, 1, 1, 128)
Dimension tags: [None, None, None]
Spectrometer Frequency: 100.679124582065 MHz
Dwelltime (Spectral bandwidth): 1.250E+02 s (0 Hz)
Nucleus: 13C
Field Strength: 9.40 T

As you can see, dwell time is interpreted as 125s instead of 125 us.

I found the problem is due to from fsl.data.image import Image, where Image doesn't interpret dwell time correctly. However, I attempted to fix this problem but failed.
For now, the workaround is always using second as the time unit. Don't use "usec" or "msec".

@Microdeep-ZL
Copy link
Contributor Author

Hi,

I found the way to correct it.
I'll close this issue and then submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant