-
Notifications
You must be signed in to change notification settings - Fork 258
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
Why not implementing __repr__ and __str__ for Nifti1Image? #1057
Comments
>>> print(nb.Nifti1Image(np.zeros((5,5,5)), np.eye(4)))
<class 'nibabel.nifti1.Nifti1Image'>
data shape (5, 5, 5)
affine:
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
metadata:
<class 'nibabel.nifti1.Nifti1Header'> object, endian='<'
sizeof_hdr : 348
data_type : b''
db_name : b''
extents : 0
session_error : 0
regular : b''
dim_info : 0
dim : [3 5 5 5 1 1 1 1]
intent_p1 : 0.0
intent_p2 : 0.0
intent_p3 : 0.0
intent_code : none
datatype : float64
bitpix : 64
slice_start : 0
pixdim : [1. 1. 1. 1. 1. 1. 1. 1.]
vox_offset : 0.0
scl_slope : nan
scl_inter : nan
slice_end : 0
slice_code : unknown
xyzt_units : 0
cal_max : 0.0
cal_min : 0.0
slice_duration : 0.0
toffset : 0.0
glmax : 0
glmin : 0
descrip : b''
aux_file : b''
qform_code : unknown
sform_code : aligned
quatern_b : 0.0
quatern_c : 0.0
quatern_d : 0.0
qoffset_x : 0.0
qoffset_y : 0.0
qoffset_z : 0.0
srow_x : [1. 0. 0. 0.]
srow_y : [0. 1. 0. 0.]
srow_z : [0. 0. 1. 0.]
intent_name : b''
magic : b'n+1' I would be open to improving the |
amazing!! I must've overlooked the str implementation. That's pretty good, thank you. Do you think it'd be possible to add some provenance info to it, such as whether the nifti was loaded directly from a file, and if so print its filename? If <80 characters then it'd be hard to have it output something that could be used to instantiate the object upon eval. But we could take inspiration from ANTsPy: |
Yeah, I wouldn't expect a |
Hi guys,
I was wondering whether there is a reason why the Nifti1Image class doesn't implement repr nor str. I think it'd be a great addition, and very informative for end users to be able to get simple info on the REPL instead of the default
<nibabel.nifti1.Nifti1Image at 0x17d895ab0>
. But maybe there is a motivation behind that?Perhaps topic for another issue, but it'd be lovely if that simple info printed on the str would be implemented as properties. So say we print dtype, voxel size and TR, then calling nifti_image.TR would also print the TR (and similarly nifti_image.TR = 3. would change it by adapting the header).
what do you think?!
Example:
Already improves things a lot:
The text was updated successfully, but these errors were encountered: