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

Unexpected behavior with open_variable #97

Closed
pochedls opened this issue Aug 23, 2021 · 1 comment · Fixed by #98
Closed

Unexpected behavior with open_variable #97

pochedls opened this issue Aug 23, 2021 · 1 comment · Fixed by #98
Assignees
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@pochedls
Copy link
Collaborator

I am using PR #95, but I think this issue affects main. When I use open_dataset and open_variable an extra dimension is added to my DataArray, which I think is happening here.

import xarray as xr
from xcdat.dataset import open_dataset
from xcdat.variable import open_variable

# open file
fn = 'tas_Amon_CESM2_historical_r1i1p1f1_gn_185001-201412.nc'
ds = open_dataset(fn)
# show dataarray shape
print('original shape', ds.tas.shape)
# show dataarray shape after calling open_variable
tas = open_variable(ds, 'tas')
print('altered shape', tas.shape)
ds.close()

original shape (1980, 192, 288)
altered shape (2, 1980, 192, 288)

What were you expecting to happen?

It appears that an extraneous nbnd dimension is added to the dataarray (and should not be).

In: tas.dims
Out: ('nbnd', 'time', 'lat', 'lon')

Any other comments?

I assume this is related to this issue + fix.

@pochedls pochedls added the type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Aug 23, 2021
@tomvothecoder
Copy link
Collaborator

tomvothecoder commented Aug 23, 2021

This is actually an expected behavior. You need to have the bounds dimension set in the DataArray first before propagating the bounds from the parent Dataset. Otherwise, an xarray error is thrown: "ValueError: cannot add coordinates with new dimensions to a DataArray"

https://github.com/tomvothecoder/xcdat/blob/c9d0529963e5144bd05530f69fe2c27e463c3e0d/xcdat/bounds.py#L337-L340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants