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

Support simple SHOC datasets with no depth coordinate #126

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/releases/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ Next release (in development)
* Drop dependency on importlib_metadata.
This was only required to support Python 3.8, which was dropped in a previous release
(:issue:`122`, :pr:`125`).
* Fix an error with `ShocSimple.get_all_depth_names()`
when the dataset had no depth coordinates
(:issue:`123`, :pr:`126`).
10 changes: 8 additions & 2 deletions src/emsarray/conventions/shoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def get_depth_name(self) -> Hashable:
return name

def get_all_depth_names(self) -> List[Hashable]:
return ['z_centre', 'z_grid']
return [
name for name in ['z_centre', 'z_grid']
if name in self.dataset.variables]

def get_time_name(self) -> Hashable:
name = 't'
Expand Down Expand Up @@ -123,4 +125,8 @@ def get_depth_name(self) -> Hashable:
return name

def get_all_depth_names(self) -> List[Hashable]:
return [self.get_depth_name()]
name = 'zc'
if name in self.dataset.variables:
return [name]
else:
return []
11 changes: 11 additions & 0 deletions tests/conventions/test_cfgrid2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from emsarray.conventions import get_dataset_convention
from emsarray.conventions.grid import CFGrid2DTopology, CFGridKind
from emsarray.conventions.shoc import ShocSimple
from emsarray.exceptions import NoSuchCoordinateError
from emsarray.operations import geometry
from tests.utils import (
DiagonalShocGrid, ShocGridGenerator, ShocLayerGenerator,
Expand Down Expand Up @@ -175,6 +176,16 @@ def test_varnames():
assert dataset.ems.get_time_name() == 'time'


def test_no_depth_coordinate():
dataset = make_dataset(j_size=10, i_size=10)
dataset = dataset.isel({'k': -1}, drop=True)
print(dataset)

assert dataset.ems.get_all_depth_names() == []
with pytest.raises(NoSuchCoordinateError):
dataset.ems.get_depth_name()


@pytest.mark.parametrize(
['name', 'attrs'],
[
Expand Down
4 changes: 2 additions & 2 deletions tests/conventions/test_shoc_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def make_dataset(
corner_size: int = 0,
) -> xarray.Dataset:
"""
Make a dummy SHOC simple dataset of a particular size.
Make a dummy SHOC standard dataset of a particular size.
It will have a sheared grid of points located near (0, 0),
with increasing j moving north east, and increasing i moving south east.

Expand Down Expand Up @@ -187,7 +187,7 @@ def make_dataset(
def test_make_dataset():
dataset = make_dataset(j_size=5, i_size=9, corner_size=2)

# Check that this is recognised as a ShocSimple dataset
# Check that this is recognised as a ShocStandard dataset
assert get_dataset_convention(dataset) is ShocStandard

# Check that the correct convention is used
Expand Down
Loading