[pymvpa] NiftiImage from stream or string object
James Kyle
jameskyle at ucla.edu
Fri Mar 27 13:00:08 UTC 2009
On Mar 26, 2009, at 10:44 PM, Michael Hanke wrote:
> On Thu, Mar 26, 2009 at 03:26:47PM -0700, James Kyle wrote:
>> I've run into something that I need a bit of clarification on in the
>> NiftiImage lib. Specifically in the updateNiftiHeaderFromDict method.
>>
>> Line 238 of utils.py throws an exception if the data_type field is
>> > 9.
>> From my reading of the nifti spec and parsing of the raw header file,
>> this field appears to be a char[10]. (char data_type[10]).
>>
>> Where'd the other byte go?
>
> I'm not exactly sure why I did that, but I suspect it was because of
> the
> '\0' appendix of strings in C. If the Python string has 10 elements it
> would probably need 11 in a C representation and hence writting it to
> the header probably corrupts it (unless special care is taken) -- I
> might be wrong.
>
> Is this critical? If you need to store more information, you might
> want
> to consider a header extension.
I'm not storing anything, I'm reading in an existing header. So I'm
doing something similar to:
> im = read(im_path) # except this is actually a socket read, but for
> testing I use this
>
> header["data_type"] = struct.unpack(byte_order + "10s", im[4:14])[0]
Which results in a 10 char python string padded with nulls. Since the
specification doesn't require that the string be terminated with a \0,
it could result loss of information in some special cases.
It's not critical, I can just truncate it with:
> header["data_type"] = struct.unpack(byte_order + "10s", im[4:14])[0]
> [:-1]
But I thought I'd mention it while my eyes were on it.
-james
More information about the Pkg-ExpPsy-PyMVPA
mailing list