Skip to content

Commit

Permalink
Helpful error messages with open_dataset
Browse files Browse the repository at this point in the history
On non-cartesian meshes.
Fixes #65
  • Loading branch information
ashwinvis committed Nov 14, 2022
1 parent 8cf10ac commit 3704303
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 12 additions & 3 deletions pymech/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,18 @@ def _open_nek_dataset(path, drop_variables=None):

elements = field.elem
elem_stores = [_NekDataStore(elem) for elem in elements]
elem_dsets = [
xr.Dataset.load_store(store).set_coords(store.axes) for store in elem_stores
]
try:
elem_dsets = [
xr.Dataset.load_store(store).set_coords(store.axes) for store in elem_stores
]
except ValueError as err:
raise NotImplementedError(
"Opening dataset failed because you probably tried to open a field file "
"with an unsupported mesh. "
"The `pymech.open_dataset` function currently works only with cartesian "
"box meshes. For more details on this, see "
"https://github.com/eX-Mech/pymech/issues/31"
) from err

# See: https://github.com/MITgcm/xmitgcm/pull/200
ds = xr.combine_by_coords(elem_dsets, combine_attrs="drop")
Expand Down
2 changes: 1 addition & 1 deletion tests/data
12 changes: 11 additions & 1 deletion tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ def _check_channel_dset(ds):
assert math.isclose(ds.time, 0.2, abs_tol=1e-6)


def test_nekdataset(test_data_dir):
def test_channel_dataset(test_data_dir):
import pymech.dataset as pd

fname = f"{test_data_dir}/nek/channel3D_0.f00001"
ds = pd.open_dataset(fname)
_check_channel_dset(ds)


def test_phill_dataset(test_data_dir):
import pymech.dataset as pd

fname = f"{test_data_dir}/nek/phill0.f00010"
with pytest.raises(
NotImplementedError, match="currently works only with cartesian box meshes"
):
pd.open_dataset(fname)


@pytest.mark.parametrize("file_name", ["channel3D_0.f00001", "stsabl0.f00001"])
def test_dataset_coords(test_data_dir, file_name):
"""Check if the 1D coordinates match with the original 3D coordinate arrays"""
Expand Down

0 comments on commit 3704303

Please sign in to comment.