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

Adds support for parametric vertical coordinate #528

Merged
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
94a0ce0
Adds initial parametric functions
jasonb5 May 24, 2024
4bb4c02
Updates parametric module and adds tests
jasonb5 Jun 7, 2024
49838e6
Adds function to help transpose outputs
jasonb5 Jun 18, 2024
2bacb6f
Removes hardcoded dims
jasonb5 Jul 17, 2024
e37173a
Fixes optional argument bug and handling case insensitive terms
jasonb5 Jul 18, 2024
622d8a4
Merge branch 'main' into adds-parametric-vertical-coordinate
jasonb5 Jul 18, 2024
24aa5df
Moves from function to class based implementation of transforms
jasonb5 Aug 17, 2024
c76828b
Fixes failing test
jasonb5 Aug 20, 2024
2e02ef9
Removes extras spaces in text
jasonb5 Aug 20, 2024
08170d1
Fixes formatting
jasonb5 Aug 20, 2024
80d1214
Resolves mypy errors
jasonb5 Aug 20, 2024
381ea30
Removes redundant code
jasonb5 Aug 21, 2024
54f6492
Fixes global variable case
jasonb5 Aug 21, 2024
32eae7e
Updates _derive_ocean_stdname
jasonb5 Aug 21, 2024
9d22976
Moves to dataclass
jasonb5 Aug 21, 2024
9396ef8
Fixes passing variables to class constructor
jasonb5 Aug 21, 2024
9c16996
Removes redundant code
jasonb5 Aug 21, 2024
4f3886a
Merge branch 'main' into adds-parametric-vertical-coordinate
dcherian Aug 21, 2024
cfd919e
Fixes handling unknown standard names
jasonb5 Aug 21, 2024
1c5d49f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 21, 2024
f3a6928
Merge remote-tracking branch 'upstream/main' into adds-parametric-ver…
jasonb5 Oct 10, 2024
a966919
Removes squeeze and fixes constants
jasonb5 Oct 11, 2024
ca33c67
Adds entry to CITATIONS.cff
jasonb5 Oct 11, 2024
978948f
cleanup
dcherian Oct 22, 2024
c9849f6
tweak docs
dcherian Oct 22, 2024
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
Prev Previous commit
Next Next commit
Removes redundant code
jasonb5 committed Aug 21, 2024
commit 9c16996ebb664f210d9ed0918aa8cee81c68fea9
13 changes: 3 additions & 10 deletions cf_xarray/parametric.py
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@
try:
search_term = f"{search_term}{y['standard_name']}"
except TypeError:
raise ValueError(

Check warning on line 77 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L77

Added line #L77 was not covered by tests
f"The values for {', '.join(sorted(search_vars.keys()))} cannot be `None`."
) from None
except KeyError:
@@ -116,16 +116,16 @@
@classmethod
@abstractmethod
def from_terms(cls, terms: dict):
pass

Check warning on line 119 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L119

Added line #L119 was not covered by tests

@abstractmethod
def decode(self):
pass

Check warning on line 123 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L123

Added line #L123 was not covered by tests

@property
@abstractmethod
def computed_standard_name(self):
pass

Check warning on line 128 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L128

Added line #L128 was not covered by tests


@dataclass
@@ -252,17 +252,17 @@

def __post_init__(self):
if self.a is None and self.ap is None:
raise KeyError(

Check warning on line 255 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L255

Added line #L255 was not covered by tests
"Optional terms 'a', 'ap' are absent in the dataset, atleast one must be present."
)

if self.a is not None and self.ap is not None:
raise Exception(

Check warning on line 260 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L260

Added line #L260 was not covered by tests
"Both optional terms 'a' and 'ap' are present in the dataset, please drop one of them."
)

if self.a is not None and self.p0 is None:
raise KeyError(

Check warning on line 265 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L265

Added line #L265 was not covered by tests
"Optional term 'a' is present but 'p0' is absent in the dataset."
)

@@ -336,8 +336,8 @@

if orog_stdname == "surface_altitude":
out_stdname = "altitude"
elif orog_stdname == "surface_height_above_geopotential_datum":
out_stdname = "height_above_geopotential_datum"

Check warning on line 340 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L339-L340

Added lines #L339 - L340 were not covered by tests
jasonb5 marked this conversation as resolved.
Show resolved Hide resolved

return out_stdname

@@ -400,10 +400,10 @@

if ztop_stdname == "altitude_at_top_of_atmosphere_model":
out_stdname = "altitude"
elif (

Check warning on line 403 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L403

Added line #L403 was not covered by tests
ztop_stdname == "height_above_geopotential_datum_at_top_of_atmosphere_model"
):
out_stdname = "height_above_geopotential_datum"

Check warning on line 406 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L406

Added line #L406 was not covered by tests
jasonb5 marked this conversation as resolved.
Show resolved Hide resolved

return out_stdname

@@ -567,21 +567,21 @@
xr.DataArray
Decoded parametric vertical coordinate.
"""
S = self.depth_c * self.s + (self.depth - self.depth_c) * self.c

Check warning on line 570 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L570

Added line #L570 was not covered by tests

z = S + self.eta * (1 + self.s / self.depth)

Check warning on line 572 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L572

Added line #L572 was not covered by tests

return z.squeeze().assign_attrs(standard_name=self.computed_standard_name)

Check warning on line 574 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L574

Added line #L574 was not covered by tests

@property
def computed_standard_name(self) -> str:
"""Computes coordinate standard name."""
return _derive_ocean_stdname(eta=self.eta.attrs, depth=self.depth.attrs)

Check warning on line 579 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L579

Added line #L579 was not covered by tests

@classmethod
def from_terms(cls, terms: dict):
"""Create coordinate from terms."""
return cls(**get_terms(terms, "s", "c", "eta", "depth", "depth_c"))

Check warning on line 584 in cf_xarray/parametric.py

Codecov / codecov/patch

cf_xarray/parametric.py#L584

Added line #L584 was not covered by tests


@dataclass
@@ -757,17 +757,10 @@
2 * self.a / (self.z1 - self.z2) * (self.depth - self.href)
)

# shape k, j, i
z_shape = self.sigma.shape + self.depth.shape

z_dims = self.sigma.dims + self.depth.dims

z = xr.DataArray(np.empty(z_shape), dims=z_dims, name="z")

z = xr.where(self.sigma.k <= self.k_c, self.sigma * f, z)

z = xr.where(
self.sigma.k > self.k_c, f + (self.sigma - 1) * (self.depth - f), z
self.sigma.k <= self.k_c,
self.sigma * f,
f + (self.sigma - 1) * (self.depth - f),
)

return z.squeeze().assign_attrs(standard_name=self.computed_standard_name)
dcherian marked this conversation as resolved.
Show resolved Hide resolved

Unchanged files with check annotations Beta

try:
transform = parametric.TRANSFORM_FROM_STDNAME[stdname]
except KeyError:

Check warning on line 2793 in cf_xarray/accessor.py

Codecov / codecov/patch

cf_xarray/accessor.py#L2793

Added line #L2793 was not covered by tests
# Should occur since stdname is check before
raise NotImplementedError(
f"Coordinate function for {stdname!r} not implmented yet. Contributions welcome!"