BIC-MNI / minc-tools

Basic minc-tools from former minc repository
Other
29 stars 25 forks source link

mnc2nii do not populate time_units header field in the NIfTI file #100

Closed cmadjar closed 4 years ago

cmadjar commented 4 years ago

the time_units header field in the NIfTI file is populated to unknown for functional datasets. This causes issues when validating NIfTI files through the BIDS validator where we get the following error:

    2: [ERR] Repetition time was not defined in seconds, milliseconds or microseconds in the scan's header. (code: 11 - REPETITION_TIME_UNITS)

Output of fslhd:

filename    /Users/cmadjar/LORIS/PREVENT-AD_open_test_data/BIDS_export/PREVENT-AD_open_release_1.0/sub-7550757/ses-PREBL00/func/sub-7550757_ses-PREBL00_task-encoding_run-001_bold.nii.gz
size of header  348
data_type   FLOAT32
dim0        4
dim1        64
dim2        64
dim3        32
dim4        183
dim5        0
dim6        0
dim7        0
vox_units   Unknown
time_units  Unknown
datatype    16
nbyper      4
bitpix      32
pixdim0     0.000000
pixdim1     4.000000
pixdim2     4.000000
pixdim3     4.000000
pixdim4     2.000000
pixdim5     0.000000
pixdim6     0.000000
pixdim7     0.000000
vox_offset  352
cal_max     0.000000
cal_min     0.000000
scl_slope   0.000000
scl_inter   0.000000
phase_dim   0
freq_dim    0
slice_dim   0
slice_name  Unknown
slice_code  0
slice_start 0
slice_end   0
slice_duration  0.000000
toffset     0.000000
intent      Unknown
intent_code 0
intent_name 
intent_p1   0.000000
intent_p2   0.000000
intent_p3   0.000000
qform_name  Unknown
qform_code  0
qto_xyz:1   4.000000 0.000000 0.000000 0.000000 
qto_xyz:2   0.000000 4.000000 0.000000 0.000000 
qto_xyz:3   0.000000 0.000000 4.000000 0.000000 
qto_xyz:4   0.000000 0.000000 0.000000 1.000000 
qform_xorient   Left-to-Right
qform_yorient   Posterior-to-Anterior
qform_zorient   Inferior-to-Superior
sform_name  Unknown
sform_code  1
sto_xyz:1   -3.992773 0.163161 0.176467 111.911812 
sto_xyz:2   -0.138906 -3.963409 0.521628 138.049561 
sto_xyz:3   16.000000 -0.514557 -3.961914 -388.975708 
sto_xyz:4   0.000000 0.000000 0.000000 1.000000 
sform_xorient   Inferior-to-Superior
sform_yorient   Anterior-to-Posterior
sform_zorient   Right-to-Left
file_type   NIFTI-1+
file_code   1
descrip     mnc2nii /Users/cmadjar/LORIS/PREVENT-AD_open_test_data/assembly/7550757/PREBL00
aux_file    
gdevenyi commented 4 years ago

I can find no documentation regarding what values are valid for time_units in the NIFTI library...

gdevenyi commented 4 years ago

After falling down the terrifying rabbithole that is the NIFTI1 library... https://github.com/NIFTI-Imaging/nifti_clib/blob/9659cbecc827e15c07ccc1a03023e8c348aa14fe/nifti2/nifti1.h#L1329-L1333

gdevenyi commented 4 years ago

We need

nim->time_units = NIFTI_UNITS_SEC ;

Or similar set.

Need to find the docs on the units inside MINC.

gdevenyi commented 4 years ago

There is a units specification for dimensions:

               time:units = "s" 

However,

s - String that specifies the units of a dimension, if applicable. The units should be compatible with the UCAR udunits library. In MINC 2.0, this attribute is generally included for informational purposes only and is not interpreted by the MINC library code.

So we either assume seconds, or use this to check and set appropriately on conversion.

cmadjar commented 4 years ago

This issue was indeed resolved by the fix. Sorry, I forgot to update and close the issue...