[Neuroimaging] first dimension too large

Matthew Brett matthew.brett at gmail.com
Wed Jun 5 16:05:29 EDT 2019


Hi,

On Wed, Jun 5, 2019 at 8:55 PM Karla Kort <karla_kort at hotmail.com> wrote:
>
> Hi,
>
> I am trying to write to a new Nifti file in python, but I get this error when running the script from the commandline: 'UserWarning: Using large vector Freesurfer hack; header will not be compatible with SPM or FSL' And this file does not work. When I run the script in jupyter notebook it doesn't give an error, but the file still still doesn't work and seems empty.  I read online that this is because the first dimension is too large, the dimensions of my data are (498511, 1, 1). So I guess that really is the problem, but I could not find any way to work around this. Is there a way? I do really need the complete file.

Sorry - the problem lies with the NIfTI format - the data dimensions
are of type "short"

https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h

This is a signed 16-bit integer:

https://en.wikipedia.org/wiki/C_data_types

so the maximum number it can represent is 2^15-1 = 32767, and this is
the largest possible valid size for any dimension.

Can you use NIfTI2 instead?  It's designed to solve this problem.

> Also, is there a way to just replace the data part in a nifti file? I noticed that .set_fdata() is not an existing command.

No - you need to create a new image, as in:

img = nib.load('my_image.nii')
new_img = nib.Nifti1Image(new_data, None, img.header)

Cheers,

Matthew


More information about the Neuroimaging mailing list