Coder Social home page Coder Social logo

Comments (8)

matthew-brett avatar matthew-brett commented on June 14, 2024

Strange:

In [15]: import nibabel as nib
In [16]: img = nib.Nifti1Image(np.zeros((2,3,4), dtype='<f4'), np.eye(4))
In [18]: img = nib.Nifti1Image(np.zeros((2,3,4), dtype='>f4'), np.eye(4))

Could you post a self-contained example with the error? What version are you using?

from nibabel.

cindeem avatar cindeem commented on June 14, 2024

Im happy to say I am using the latest release (nice job!)
And this does not happen all the time, I was able to work around it by defining an empty header...but figured it might show up sooner or later?
Usecase:
I ran into this while creating an image where I replace the NaN with zeros
In [3]: infile = 'volume_with_nans.nii'
In [4]: dat = nibabel.load(infile).get_data().copy()
In [5]: newdat = np.nan_to_num(dat)
In [6]: affine = nibabel.load(infile).get_affine()

In [12]: newimg = nibabel.Nifti1Image(newdat, affine)

HeaderDataError Traceback (most recent call last)

/home/jagust/cindeem/CODE/ucsf/ in ()

/usr/local/python2.6.2/lib/python2.6/site-packages/nibabel/spatialimages.pyc in init(self, data, affine, header, extra, file_map)
292 if header is None:
293 if hasattr(data, 'dtype'):
--> 294 self._header.set_data_dtype(data.dtype)
295 # make header correspond with image and affine
296 self.update_header()
/usr/local/python2.6.2/lib/python2.6/site-packages/nibabel/analyze.pyc in set_data_dtype(self, datatype)
836 except KeyError:
837 raise HeaderDataError(
--> 838 'data dtype "%s" not recognized' % datatype)
839 dtype = self._data_type_codes.dtype[code]
840 # test for void, being careful of user-defined types
HeaderDataError: data dtype "float32" not recognized

from nibabel.

matthew-brett avatar matthew-brett commented on June 14, 2024

Can you post a script that replicates the error?

from nibabel.

matthew-brett avatar matthew-brett commented on June 14, 2024

If it needs an image maybe post it somewhere I can see it and I will have a look

from nibabel.

cindeem avatar cindeem commented on June 14, 2024

look here
http://github.com/cindeem/nibabel-nan

from nibabel.

cindeem avatar cindeem commented on June 14, 2024

its a PET image that was realigned to other images using spm8....let me know if you find anything obvious I missed

from nibabel.

matthew-brett avatar matthew-brett commented on June 14, 2024

This is due to a dtype comparison oddness in numpy:

http://projects.scipy.org/numpy/ticket/1637
http://comments.gmane.org/gmane.comp.python.numeric.general/41038

and probably needs a DtypeRecoder object that inherits from Recoder, but uses == for key lookups. For now the workaround is to make your own header instead of relying on the automatic header creation:

hdr = nib.Nifti1Header()
hdr.set_data_dtype(np.float32)
img = nib.Nifti1Image(arr, aff, hdr)

from nibabel.

matthew-brett avatar matthew-brett commented on June 14, 2024

BF - closed by f3814d6

  • dtype-cmp-fix:
    BF - add dtypes to recoder to deal with odd dtype hashing

from nibabel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.