[Pkg-exppsy-pynifti] Issue putting packed binary data into extension
Michael Hanke
michael.hanke at gmail.com
Fri Feb 26 02:29:24 UTC 2010
Hi,
On Thu, Feb 25, 2010 at 05:08:56PM -0800, Brendan Moloney wrote:
> Hello,
>
> I am trying to put binary data into an extension. I use the python module 'struct' to pack the data into a string, but pyNifti seems to not like control characters in the string. Here is a simple example:
>
> >>import nifti, struct
>
> >>nim = nifti.NiftiImage('/path/to/nifti/file')
>
> >>packedData = struct.pack('I', 12345) # That's an uppercase i
>
> >>packedData
> '90\x00\x00'
>
> >>len(packedData)
> 4
>
> >>nim.extensions += (0, packedData)
>
> >>nim.extensions[-1]
> '90'
>
> >>len(nim.extensions[-1])
> 2
It should be possible to add binary data. Unfortunately, I cannot look
into it right now. Could you please check nibabel instead. This is
pynifti's successor (yet to be officially released). It has the same
extension code, but doesn't use the C library under the hood. This way
you may be able to figure it out.
Michael
--
GPG key: 1024D/3144BE0F Michael Hanke
http://mih.voxindeserto.de
More information about the Pkg-exppsy-pynifti
mailing list