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

rewrote the subset selector for sgrid, added test based on example notebook #61

Merged
merged 9 commits into from
Sep 13, 2024

Conversation

jay-hennen
Copy link
Contributor

No description provided.

Copy link
Collaborator

@ChrisBarker-NOAA ChrisBarker-NOAA left a comment

Choose a reason for hiding this comment

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

we need to clean up the tests and examples before merging.

And there should be a notebook example -- is there one already? hopefully with some graphics. See: xarray_subset_grid/visualization/mpl_plotting.py

We should add somenthing there for SGRIDS.

See:

'''
This is a basic integration test for the subsetting of a ROMS sgrid dataset using a polygon.
'''
fs = fsspec.filesystem(
Copy link
Collaborator

Choose a reason for hiding this comment

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

we need a test (or more) that doesn't rely on that server being alive ....

See PR comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the arakawa_c_test_grid from gridded for future tests. Will add another offline test soon

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks!


node_lon: xr.DataArray | None = None
node_lat: xr.DataArray | None = None
for c in node_coords:
Copy link
Collaborator

@ChrisBarker-NOAA ChrisBarker-NOAA Sep 9, 2024

Choose a reason for hiding this comment

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

hmm -- doesn't the spec say it should always be lon, lat order? -- but I suppose this is a bit safer anyway.

elif 'lat' in c:
node_lat = ds[c]
if node_lon is None or node_lat is None:
raise ValueError(f"Could not find lon and lat for dimension {node_dims}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is specifically the node_coordinates -- yes? If so, the error message should be clear on that.

@@ -151,3 +151,29 @@ def compute_2d_subset_mask(
polygon_mask = np.where(polygon_mask > 1, True, False)

return xr.DataArray(polygon_mask, dims=mask_dims)

def parse_padding_string(dim_string):
Copy link
Collaborator

Choose a reason for hiding this comment

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

it'd be nice to have a unit test for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

also -- is it really this complex ? that surprises me -- though I haven't followed all the logic. If any of the logic is to deal with non-compliant files, then that should go elsewhere. maybe it's not.

import pytest
import glob

from .get_remote_data import get_datafile
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

from .get_remote_data import get_datafile


def get_test_file_dir():
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

test_file_dir = Path(__file__).parent / 'test_data')`

ds_subset = ds.xsg.subset_polygon(polygon)

breakpoint()
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't want this in there :-)

from xarray_subset_grid.utils import get_test_file_dir

from gridded import Variable, VectorVariable

Copy link
Collaborator

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'

@ChrisBarker-NOAA
Copy link
Collaborator

are the tests running / passing in your repo?

Check the "actions" tab in the project page.

If not -- I wonder why not?

@ChrisBarker-NOAA
Copy link
Collaborator

Looks good--- thanks!

I'd love to see more examples and tests, and plotting, but for now this is an improvement.

@ChrisBarker-NOAA ChrisBarker-NOAA merged commit f2bd644 into asascience-open:main Sep 13, 2024
9 checks passed
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.

2 participants