-
Notifications
You must be signed in to change notification settings - Fork 43
Add UxDataset.isel()
#1352
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
Add UxDataset.isel()
#1352
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
beaf419
first rev
philipc2 0277c07
add tests
philipc2 2bfbf64
Merge branch 'main' into ds-isel
philipc2 142edb1
Merge branch 'main' into ds-isel
philipc2 f372c08
implement ds.isel
philipc2 6299373
Merge branch 'main' into ds-isel
philipc2 ba24024
add docstring
philipc2 c8aa559
Merge branch 'ds-isel' of https://github.com/UXARRAY/uxarray into ds-…
philipc2 11c5754
Merge branch 'main' into ds-isel
philipc2 d1ef09e
Merge branch 'ds-isel' of https://github.com/UXARRAY/uxarray into ds-…
philipc2 242e17f
move test_isel to core
philipc2 eecae44
remove isel test from test_inheritance in favor of seperate module
philipc2 ce51984
add isel to api
philipc2 baf194f
Merge branch 'main' into ds-isel
philipc2 8bacf93
move tests into test_inheritance, reogranize tests
philipc2 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,70 @@ | ||
import pytest | ||
import uxarray as ux | ||
import numpy as np | ||
|
||
@pytest.fixture() | ||
def ds(): | ||
uxgrid = ux.Grid.from_healpix(zoom=1) | ||
t_var = ux.UxDataArray(data=np.ones((3,)), dims=['time'], uxgrid=uxgrid) | ||
fc_var = ux.UxDataArray(data=np.ones((3, uxgrid.n_face)), dims=['time', 'n_face'], uxgrid=uxgrid) | ||
nc_var = ux.UxDataArray(data=np.ones((3, uxgrid.n_node)), dims=['time', 'n_node'], uxgrid=uxgrid) | ||
|
||
uxds = ux.UxDataset({"fc": fc_var, "nc": nc_var, "t": t_var}, uxgrid=uxgrid) | ||
|
||
uxds["fc"] = uxds["fc"].assign_coords(face_id=("n_face", np.arange(uxgrid.n_face))) | ||
uxds["nc"] = uxds["nc"].assign_coords(node_id=("n_node", np.arange(uxgrid.n_node))) | ||
uxds["t"] = uxds["t"].assign_coords(time_id=("time", np.arange(uxds.dims["time"]))) | ||
|
||
|
||
return uxds | ||
|
||
|
||
class TestDataset: | ||
|
||
def test_isel_face_dim(self, ds): | ||
ds_f_single = ds.isel(n_face=0) | ||
|
||
assert len(ds_f_single.coords) == 3 | ||
|
||
assert ds_f_single.uxgrid != ds.uxgrid | ||
assert ds_f_single.sizes['n_face'] == 1 | ||
assert ds_f_single.sizes['n_node'] >= 4 | ||
|
||
ds_f_multi = ds.isel(n_face=[0, 1]) | ||
|
||
assert len(ds_f_multi.coords) == 3 | ||
|
||
assert ds_f_multi.uxgrid != ds.uxgrid | ||
assert ds_f_multi.sizes['n_face'] == 2 | ||
assert ds_f_multi.sizes['n_node'] >= 4 | ||
|
||
|
||
def test_isel_node_dim(self, ds): | ||
ds_n_single = ds.isel(n_node=0) | ||
|
||
assert len(ds_n_single.coords) == 3 | ||
|
||
assert ds_n_single.uxgrid != ds.uxgrid | ||
assert ds_n_single.sizes['n_face'] >= 1 | ||
|
||
ds_n_multi = ds.isel(n_node=[0, 1]) | ||
|
||
assert len(ds_n_multi.coords) == 3 | ||
|
||
assert ds_n_multi.uxgrid != ds.uxgrid | ||
assert ds_n_multi.uxgrid.sizes['n_face'] >= 1 | ||
|
||
def test_isel_non_grid_dim(self, ds): | ||
ds_t_single = ds.isel(time=0) | ||
|
||
assert len(ds_t_single.coords) == 3 | ||
|
||
assert ds_t_single.uxgrid == ds.uxgrid | ||
assert "time" not in ds_t_single.sizes | ||
|
||
ds_t_multi = ds.isel(time=[0, 1]) | ||
|
||
assert len(ds_t_multi.coords) == 3 | ||
|
||
assert ds_t_multi.uxgrid == ds.uxgrid | ||
assert ds_t_multi.sizes['time'] == 2 |
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
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.
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.