-
Notifications
You must be signed in to change notification settings - Fork 260
Intent to deprecate: 64-bit integer NIfTI images #1089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for writing this up! I would add to the dtype parameter that you should explicitly test to make sure that if somebody passes the |
I know this is hacky but you can actually use the
So you can do something like this:
which results in
|
Note that the Python |
@jbteves wow! I did not know that. That is a very nice trick. It does provide a future mechanism for a user to explicitly demand |
@jbteves - ah - but it's subtle, because
the user might expect the same for |
Yes, I agree! I more meant for the purposes of this particular saving function, if we want a user to be very explicit we can use the string casting to check if they used
|
Yes - sure - or maybe
? |
That's much less hacky, good idea! I always forget about Python's inheritance features. |
Just to make it concrete, I was thinking something quite simple: 46bf959. (This is on the |
See nipy/nibabel#1089 np.array using int64 for arrays created with all integers. These arrays cannot be passed to directly to Nifti1Pair constructor anymore without explicit dtype argument specifying that the user wants a int64 image. I added a dtype=float specification to the np.array construction to get rid of this error.
64 bit integer images are easy to generate in nibabel due to numpy semantics, but almost universally incompatible with non-Python tools. We must balance breaking existing Python scripts, the Python library ecosystem, and the wider neuroimaging ecosystem that uses NIfTI as an interchange format.
Recognizing that we are currently contributing to breakage in the wider ecosystem, we have decided to deprecate 64-bit integer image creation except via explicit override. The following path is proposed in order to bring major Python libraries into alignment over a 6-month window through escalating warnings and errors.
NiBabel will take the following steps:
dtype=
parameter toNifti1Image()
(and similar) to pass toset_data_dtype()
after initialization (NF: Pass dtype to Analyze-like images at initialization/serialization, warn on creation of NIfTI images with 64-bit ints (API change) #1082)Nifti1Image(data, affine)
if data.dtype is int64 or uint64 unless dtype or header is provided (NF: Pass dtype to Analyze-like images at initialization/serialization, warn on creation of NIfTI images with 64-bit ints (API change) #1082)nib-cast
(name may change) command-line tool to recast existing files to new data type (NF: nib-convert CLI tool #1113)dtype=
parameter toNifti1Image.to_filename()
(and similar) toset_data_dtype()
before serializingimg.get_data_dtype()
is (u)int64 anddtype
is not passed, raise a warning, to be promoted to error in 5.0__init__
andto_filename()
:TypeError
ifdtype
isint
or"int"
(np.dtype(int) == np.dtype("int") == np.dtype("int64"))
so users need to explicitly requestnp.int64
.img.to_filename(dtype=None)
to raise exception ifimg.get_data_dtype()
is (u)int64cc @matthew-brett @jbteves @neurolabusc @mrneont @jeromedockes @NicolasGensollen
Please add anything I've missed or let me know if anything needs adjustment.
The text was updated successfully, but these errors were encountered: