Skip to content

ENH: Allow save-time passing of on-disk dtype to save functions #1083

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

Closed
wants to merge 2 commits into from

Conversation

effigies
Copy link
Member

A common idiom is to use a higher-precision internal data type before saving to a lower-precision on-disk data type. The set_data_dtype() method is a little clunky. This permits the following:

nii.to_filename(fname, dtype="int16")
nii.to_bytes(dtype="int16")
nb.save(nii, fname, dtype="int16")

Only implemented for Analyze-like images here. Related to discussion in #1046, but does not (currently) warn for int64 data being saved without a dtype argument.

@codecov
Copy link

codecov bot commented Feb 11, 2022

Codecov Report

Merging #1083 (325b658) into master (2937a3a) will decrease coverage by 0.00%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1083      +/-   ##
==========================================
- Coverage   92.32%   92.31%   -0.01%     
==========================================
  Files          99       99              
  Lines       12205    12221      +16     
  Branches     2388     2392       +4     
==========================================
+ Hits        11268    11282      +14     
- Misses        613      614       +1     
- Partials      324      325       +1     
Impacted Files Coverage Δ
nibabel/analyze.py 97.95% <66.66%> (-0.57%) ⬇️
nibabel/filebasedimages.py 89.36% <100.00%> (ø)
nibabel/loadsave.py 93.84% <100.00%> (ø)
nibabel/affines.py 100.00% <0.00%> (ø)
nibabel/streamlines/tractogram.py 99.68% <0.00%> (+<0.01%) ⬆️
nibabel/streamlines/array_sequence.py 97.97% <0.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2937a3a...325b658. Read the comment docs.

@effigies
Copy link
Member Author

Combining into #1082.

@effigies effigies closed this Feb 18, 2022
@effigies effigies deleted the enh/save_dtype branch February 18, 2022 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant