Skip to content
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

[WIP] add DataTree.to_netcdf #26

Merged
merged 5 commits into from
Aug 25, 2021
Merged

[WIP] add DataTree.to_netcdf #26

merged 5 commits into from
Aug 25, 2021

Conversation

jhamman
Copy link

@jhamman jhamman commented Aug 25, 2021

This addresses #16.

I've filled in _datatree_to_netcdf to support writing a DataTree to a NETCDF4 file. I have a few questions for @TomNicholas that I'll highlight with comments on the changes.

datatree/io.py Outdated Show resolved Hide resolved
datatree/io.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks @jhamman. The only thing I can think of to add would be some kind of test that netcdf -> xarray.DataTree -> netcdf roundtripping works. That would probably require committing a small data file though.

(This can of course wait for another PR though)

datatree/io.py Outdated Show resolved Hide resolved
datatree/io.py Outdated Show resolved Hide resolved
datatree/io.py Outdated Show resolved Hide resolved
datatree/tests/test_datatree.py Outdated Show resolved Hide resolved
datatree/io.py Outdated Show resolved Hide resolved
datatree/tests/test_datatree.py Outdated Show resolved Hide resolved
Co-authored-by: Tom Nicholas <35968931+TomNicholas@users.noreply.github.com>
Copy link
Collaborator

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one last problem with dataless nodes - see suggestion.

(Also this would have been easier if I had written an assert_tree_equal function)

@jhamman
Copy link
Author

jhamman commented Aug 25, 2021

@TomNicholas - I think this is ready to go. I've special cased the empty node in read and write now. Easy to update in the future if the data model evolves a bit.

@jhamman jhamman marked this pull request as ready for review August 25, 2021 22:12
Copy link
Collaborator

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent @jhamman - thank you!

I might make minor changes (e.g. call a dedicated assert_tree_equal function) later, but this looks solid for now :)

@TomNicholas TomNicholas merged commit 84f472a into xarray-contrib:main Aug 25, 2021
@TomNicholas TomNicholas mentioned this pull request Aug 25, 2021
@jhamman jhamman mentioned this pull request Aug 26, 2021
flamingbear pushed a commit to flamingbear/rewritten-datatree that referenced this pull request Jan 19, 2024
* first attempt at to_netcdf

* lint

* add test for roundtrip and support empty nodes

* Apply suggestions from code review

Co-authored-by: Tom Nicholas <35968931+TomNicholas@users.noreply.github.com>

* update roundtrip test, improves empty node handling in IO

Co-authored-by: Tom Nicholas <35968931+TomNicholas@users.noreply.github.com>
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.

None yet

2 participants