Comments (8)
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.
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.
Can you post a script that replicates the error?
from nibabel.
If it needs an image maybe post it somewhere I can see it and I will have a look
from nibabel.
look here
http://github.com/cindeem/nibabel-nan
from nibabel.
its a PET image that was realigned to other images using spm8....let me know if you find anything obvious I missed
from nibabel.
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.
BF - closed by f3814d6
- dtype-cmp-fix:
BF - add dtypes to recoder to deal with odd dtype hashing
from nibabel.
Related Issues (20)
- Request: adding `CITATION.cff` and updating citation wording HOT 3
- TypeError of import nibabel will be displayed after running make html
- Numpy 2.0-dev support and testing HOT 12
- 3 tests fail HOT 4
- ValueError: Irregular spacing not supported HOT 4
- [Question] Native code in NiBabel HOT 2
- Loss of precision in NIFTI header affine HOT 3
- Python3.12: distutils have been removed from stdlib HOT 3
- numpy.AxisError: axis 1 is out of bounds for array of dimension 1 HOT 13
- Unresolved attribute reference warning in Pycharm HOT 4
- Nibabel converts nan to zero when saving a floating point image HOT 2
- Type checking issues HOT 9
- How to replace the voxel values based on a csv file and save it as a new nifti file?
- Reading CAT12 geometries HOT 6
- Loss of Data Precision Issue When Saving Nifti1Image HOT 2
- `file` constructor in `doc/source/devel/register_me.py` HOT 6
- Add test runners for non-x86/x64 architectures
- Segfaulting on test_array_interface_with_dtype and numpy 2.0-dev HOT 3
- 1 test fails: test_pkg_info HOT 3
- Request: stop throwing ExpiredDeprecationError HOT 23
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nibabel.