Skip to content

Commit

Permalink
Merge pull request #65 from fmalatino/feature/no_eta
Browse files Browse the repository at this point in the history
Ability to generate planar metric terms and addition of `test_eta.py` unit test
  • Loading branch information
fmalatino authored Sep 16, 2024
2 parents c355e85 + 069f056 commit 4a4c0c8
Show file tree
Hide file tree
Showing 5 changed files with 656 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
- name: Install Python packages
run: pip3 install .[test]

- name: prepare input eta files
run: |
python tests/grid/generate_eta_files.py
- name: Run serial-cpu tests
run: coverage run --rcfile=setup.cfg -m pytest -x tests

Expand Down
4 changes: 1 addition & 3 deletions ndsl/grid/eta.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class HybridPressureCoefficients:


def _load_ak_bk_from_file(eta_file: str) -> Tuple[np.ndarray, np.ndarray]:
if eta_file == "None":
raise ValueError("eta file not specified")
if not os.path.isfile(eta_file):
raise ValueError("file " + eta_file + " does not exist")
raise ValueError(f"eta file {eta_file} does not exist")

# read file into ak, bk arrays
data = xr.open_dataset(eta_file)
Expand Down
36 changes: 29 additions & 7 deletions ndsl/grid/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __init__(
dy_const: float = 1000.0,
deglat: float = 15.0,
extdgrid: bool = False,
eta_file: str = "None",
eta_file: Optional[str] = None,
ak: Optional[np.ndarray] = None,
bk: Optional[np.ndarray] = None,
):
Expand Down Expand Up @@ -297,12 +297,34 @@ def __init__(
self._dy_center = None
self._area = None
self._area_c = None
(
self._ks,
self._ptop,
self._ak,
self._bk,
) = self._set_hybrid_pressure_coefficients(eta_file, ak, bk)
if eta_file is not None:
(
self._ks,
self._ptop,
self._ak,
self._bk,
) = self._set_hybrid_pressure_coefficients(eta_file, ak, bk)
else:
self._ks = self.quantity_factory.zeros(
[],
"",
dtype=Float,
)
self._ptop = self.quantity_factory.zeros(
[],
"Pa",
dtype=Float,
)
self._ak = self.quantity_factory.zeros(
[Z_INTERFACE_DIM],
"Pa",
dtype=Float,
)
self._bk = self.quantity_factory.zeros(
[Z_INTERFACE_DIM],
"",
dtype=Float,
)
self._ec1 = None
self._ec2 = None
self._ew1 = None
Expand Down
Loading

0 comments on commit 4a4c0c8

Please sign in to comment.