Repository navigation
Use _construct_direct in UxDataArray.to_xarray() and UxDataset.to_xarray()
#1860
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
Merged
+387
−12
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7f55482
arr and ds.to_xarray() use _construct_direct()
Sevans711 9ecb999
add TestUxDatasetToXarray, fix small encoding bug
Sevans711 aa332ef
add TestUxDataArrayToXarray, fix deepcopy bug
Sevans711 1a9a0f5
add to_xarray() benchmarks
Sevans711 0fe0051
Merge branch 'main' into sevans/to_xarray-_construct_direct
Sevans711 6a22c15
Merge branch 'main' into sevans/to_xarray-_construct_direct
Sevans711 ebcdd1f
fix new test failing on old numpy due to nan!=nan
Sevans711 5674072
Apply batched suggestions from code review
Sevans711 11c196e
Merge branch 'main' into sevans/to_xarray-_construct_direct
Sevans711 de7db43
tiny refactor to speed up ds.to_xarray("HEALPix")
Sevans711 f940366
fix ds._close in in to_xarray _construct_direct
Sevans711 406075b
empty commit to retry CI
Sevans711 4181c73
Merge branch 'main' into sevans/to_xarray-_construct_direct
cmdupuis3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """Benchmarks for to_xarray() methods, | ||
| like UxDataset.to_xarray() and UxDataArray.to_xarray(). | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import uxarray as ux | ||
|
|
||
|
|
||
| def _assign_coords(obj, n_coords): | ||
| n_face = obj.sizes["n_face"] | ||
| return obj.assign_coords( | ||
| {f"c{i}": ("n_face", np.arange(n_face, dtype=float)) for i in range(n_coords)} | ||
| ) | ||
|
|
||
|
|
||
| class UxDatasetToXarray: | ||
| """Benchmark ``UxDataset.to_xarray()``, which is dominated by per-variable overhead.""" | ||
|
|
||
| params = [[(100, 10), (1000, 100)]] | ||
| param_names = ["n_vars_and_n_coords"] | ||
|
|
||
| def setup(self, n_vars_and_n_coords): | ||
| n_vars, n_coords = n_vars_and_n_coords | ||
| uxds = ux.tutorial.open_dataset("outCSne30-vortex") | ||
| uxds = uxds.assign({f"v{i}": uxds["psi"]+i for i in range(n_vars-1)}) | ||
| self.uxds = _assign_coords(uxds, n_coords) | ||
|
|
||
| def time_to_xarray(self, n_vars_and_n_coords): | ||
| self.uxds.to_xarray() | ||
|
|
||
| def time_to_xarray_healpix(self, n_vars_and_n_coords): | ||
| self.uxds.to_xarray("HEALPix") | ||
|
|
||
|
|
||
| class UxDataArrayToXarray: | ||
| """Benchmark ``UxDataArray.to_xarray()`` with many (n_face-sized) coords.""" | ||
|
|
||
| params = [[10]] | ||
| param_names = ["n_coords"] | ||
|
|
||
| def setup(self, n_coords): | ||
| uxds = ux.tutorial.open_dataset("outCSne30-vortex") | ||
| self.uxda = _assign_coords(uxds["psi"], n_coords) | ||
|
|
||
| def time_to_xarray(self, n_coords): | ||
| self.uxda.to_xarray() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.