-
Notifications
You must be signed in to change notification settings - Fork 4
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
rewrote the subset selector for sgrid, added test based on example notebook #61
Changes from 1 commit
b52b12e
36df925
1e6d620
06b3843
02fc924
e8692f8
d17517a
338a1f7
83ad4af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,14 @@ | |
import xarray_subset_grid.accessor # noqa: F401 | ||
from xarray_subset_grid.utils import ray_tracing_numpy | ||
# open dataset as zarr object using fsspec reference file system and xarray | ||
|
||
from xarray_subset_grid.utils import get_test_file_dir | ||
|
||
from gridded import Variable, VectorVariable | ||
|
||
test_dir = get_test_file_dir() | ||
sample_sgrid_file = os.path.join(test_dir, 'arakawa_c_test_grid.nc') | ||
|
||
def test_polygon_subset(): | ||
''' | ||
This is a basic integration test for the subsetting of a ROMS sgrid dataset using a polygon. | ||
|
@@ -51,4 +59,18 @@ def test_polygon_subset(): | |
#Note that this needs to be better generalized; it's not trivial to write a test that works in all potential cases. | ||
assert ds_subset['lon_rho'][0,0] < ds_subset['lon_psi'][0,0] and ds_subset['lon_rho'][0,1] > ds_subset['lon_psi'][0,0] | ||
|
||
#ds_subset.temp_sur.isel(ocean_time=0).plot(x="lon_rho", y="lat_rho") | ||
#ds_subset.temp_sur.isel(ocean_time=0).plot(x="lon_rho", y="lat_rho") | ||
|
||
def test_polygon_subset_2(): | ||
ds = xr.open_dataset(sample_sgrid_file) | ||
polygon = np.array( | ||
[6.5, 37.5], | ||
[6.5, 39.5], | ||
[9.5, 40.5], | ||
[8.5, 37.5], | ||
[6.5, 37.5] | ||
) | ||
ds_subset = ds.xsg.subset_polygon(polygon) | ||
|
||
breakpoint() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want this in there :-) |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Assorted utilities useful for the tests. | ||
""" | ||
|
||
import os | ||
import contextlib | ||
|
||
try: | ||
import urllib.request as urllib_request # for python 3 | ||
except ImportError: | ||
import urllib2 as urllib_request # for python 2 | ||
|
||
import pytest | ||
import glob | ||
|
||
from .get_remote_data import get_datafile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want to put this in xarray_subset_grid. I imagine we will put something like this in libgoods, or maybe gridded, but not here. |
||
|
||
|
||
def get_test_file_dir(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can just put this in the test file directly -- or maybe make it a fixture. And pathlib is great: from pathlib import Path
|
||
""" | ||
returns the test file dir path | ||
""" | ||
test_file_dir = os.path.join(os.path.dirname(__file__), 'test_data') | ||
return test_file_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to put this inline:
TEST_DIR = Path(__file__).parent.parent / 'test_data'
sample_sgrid_file = TEST_DIR / 'arakawa_c_test_grid.nc'