Skip to content

added another kwargs for read in #384

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

Closed
wants to merge 2 commits into from
Closed

Conversation

kthyng
Copy link
Contributor

@kthyng kthyng commented Jul 18, 2023

Overview

When trying to read in FVCOM model output, the necessary kwargs are not passed forward in the open function.

Expected Usage

Without this change

import uxarray as ux
url = "https://opendap.co-ops.nos.noaa.gov/thredds/dodsC/NOAA/SFBOFS/MODELS/2023/07/18/nos.sfbofs.fields.f000.20230718.t03z.nc"
uxds = uxr.open_dataset(url, url, drop_variables=["siglay","siglev"])

Returns the following because the dropped variables are not being dropped.

MissingDimensionsError: 'siglay' has more than 1-dimension and the same name as one of its dimensions ('siglay', 'node'). xarray disallows such variables because they conflict with the coordinates used to label dimensions.

With the change in the PR, the same code returns the following, which appears to be the correct error for the inputs at this time:

``` --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[3], line 2 1 url = "https://opendap.co-ops.nos.noaa.gov/thredds/dodsC/NOAA/SFBOFS/MODELS/2023/07/18/nos.sfbofs.fields.f000.20230718.t03z.nc" ----> 2 uxds = uxr.open_dataset(url, url, drop_variables=["siglay","siglev"])

File ~/packages/uxarray/uxarray/core/api.py:165, in open_dataset(grid_filename_or_obj, filename_or_obj, gridspec, vertices, islatlon, isconcave, use_dual, **kwargs)
109 """Wraps xarray.open_dataset(), given a grid topology definition with a
110 single dataset file or object with corresponding data.
111
(...)
161 >>> ux_ds = ux.open_dataset("grid_filename.g", "grid_filename_vortex.nc")
162 """
164 ## Grid definition
--> 165 uxgrid = open_grid(grid_filename_or_obj,
166 gridspec=gridspec,
167 vertices=vertices,
168 islatlon=islatlon,
169 isconcave=isconcave,
170 use_dual=use_dual,
171 **kwargs)
173 ## UxDataset
174 ds = xr.open_dataset(filename_or_obj, decode_times=False,
175 **kwargs) # type: ignore

File ~/packages/uxarray/uxarray/core/api.py:90, in open_grid(grid_filename_or_obj, gridspec, vertices, islatlon, isconcave, use_dual, **kwargs)
85 else:
86 grid_ds = xr.open_dataset(grid_filename_or_obj,
87 decode_times=False,
88 **kwargs) # type: ignore
---> 90 uxgrid = Grid(grid_ds,
91 gridspec=gridspec,
92 vertices=vertices,
93 islatlon=islatlon,
94 isconcave=isconcave,
95 source_grid=str(grid_filename_or_obj),
96 use_dual=use_dual)
98 return uxgrid

File ~/packages/uxarray/uxarray/core/grid.py:100, in Grid.init(self, input_obj, **kwargs)
97 # check if initializing from string
98 # TODO: re-add gridspec initialization when implemented
99 elif isinstance(input_obj, xr.Dataset):
--> 100 self.mesh_type = parse_grid_type(input_obj)
101 self.from_ds(dataset=input_obj)
102 else:

File ~/packages/uxarray/uxarray/utils/helpers.py:48, in parse_grid_type(dataset)
46 mesh_type = "mpas"
47 else:
---> 48 raise RuntimeError(f"Could not recognize dataset format.")
49 return mesh_type
51 # check mesh topology and dimension

RuntimeError: Could not recognize dataset format.

</details>

cc @rajeeja 

@@ -167,7 +167,8 @@ def open_dataset(grid_filename_or_obj: str,
vertices=vertices,
islatlon=islatlon,
isconcave=isconcave,
use_dual=use_dual)
use_dual=use_dual,
**kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Hi @kthyng

This is a great catch! I would be careful passing through these kwargs into open_grid, since these kwargs would be "double dipping" when they open up the data file and grid file. In your case this doesn't cause an issue because you are using the same file for both the data and grid, however if our mesh and data were stored as separate files, this would break.

grid_ds = xr.open_dataset(grid_filename_or_obj,
decode_times=False,
**kwargs) # type: ignore

uxarray/uxarray/core/api.py

Lines 172 to 174 in af232ea

## UxDataset
ds = xr.open_dataset(filename_or_obj, decode_times=False,
**kwargs) # type: ignore

We could add another parameter to open_dataset, **grid_kwargs or similar which would be separate from the dataset's **kwargs

I can take a look into this today

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, makes sense.

@philipc2
Copy link
Member

@kthyng

Do you mind if I push directly to this branch in your fork? (would need permission)

@kthyng
Copy link
Contributor Author

kthyng commented Jul 19, 2023

@philipc2 I'm not familiar with that direction workflow but amenable to whatever is easiest! Just tell me what to do.

@philipc2
Copy link
Member

Moving this over to #390

@philipc2 philipc2 closed this Jul 19, 2023
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.

Add additional **kwargs for opening a grid file with ux.open_dataset Get uxarray running with FVCOM model output
2 participants