WIP: Add kwargs to InferenceData.to_netcdf() #2410
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #2298, with solution broadly along the lines of that sketched out in the issue.
Added
**kwargs
toInferenceData.to_netcdf()
method, to allow any of the parameters that can be passed toxarray.Dataset.to_netcdf()
to get passed through.E.g. for my usage case I define an
encoding={'var_A' : {"dtype": "int16", "scale_factor" : 0.1}}
dict, so thatvar_A
samples get stored via 16-bit integers and to 1 decimal place precision, to economise on file size but with an inconsequential loss of precision. Note this would be done forvar_A
in any group in which it appears, e.g. bothposterior
andprior
groups if present.I've put in a placeholder for where a new unittest could be added, but am not so confident in defining this. What I envisage, which I've tested via a seperate script my end, is the following:
InferenceData
instance, reading fromnetcdf
file as I can see other unittests do alreadyencoding
settings for a couple of the RVs in the model to which the data relatesnetcdf
file but passingencoding
(and/or other params that would alter the behaviour ofDataset.to_netcdf
)Help welcome in setting up the latter! It would also be worthwhile verifying via tests that the handling code I've included (populating the
kwargs
dict based oncompress
andengine
parameters per previous) is working as intended and in a backwards compatible manner; it should! Perhaps existing tests are adequate to prove this though?Checklist
📚 Documentation preview 📚: https://arviz--2410.org.readthedocs.build/en/2410/