Description
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:
- In NiBabel 4.0.0 (March 2022):
- Provide
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) - Warn on
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) - Provide
nib-cast
(name may change) command-line tool to recast existing files to new data type (NF: nib-convert CLI tool #1113) - Provide
dtype=
parameter toNifti1Image.to_filename()
(and similar) toset_data_dtype()
before serializing- If
img.get_data_dtype()
is (u)int64 anddtype
is not passed, raise a warning, to be promoted to error in 5.0 - Provide "mask" (uint8), "label" (int16 or int32 depending on values) aliases (ENH: Add static and dynamic dtype aliases to NIfTI images #1096)
- If
- For both
__init__
andto_filename()
:- Raise
TypeError
ifdtype
isint
or"int"
(np.dtype(int) == np.dtype("int") == np.dtype("int64"))
so users need to explicitly requestnp.int64
.
- Raise
- Add documentation page to link in warnings/errors
- Provide
- In NiBabel 5.0.0 (September 2022):
img.to_filename(dtype=None)
to raise exception ifimg.get_data_dtype()
is (u)int64
cc @matthew-brett @jbteves @neurolabusc @mrneont @jeromedockes @NicolasGensollen
Please add anything I've missed or let me know if anything needs adjustment.