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

Ability to generate planar metric terms and addition of test_eta.py unit test #65

Merged
merged 21 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1bda968
Added conditional to MetricTerms init to allow for metric term genera…
fmalatino Aug 20, 2024
b18880b
Changes to support testing in pace for eta file specification
fmalatino Aug 22, 2024
104076f
Merge branch 'develop' into feature/no_eta
fmalatino Aug 22, 2024
ba28f33
Moved test_eta.py from pace/tests/main/grid into NDSL/tests/grid, add…
fmalatino Aug 27, 2024
20ed73d
Merge branch 'feature/no_eta' of github.com:fmalatino/NDSL into featu…
fmalatino Aug 27, 2024
9cafe2e
Amending unit_tests.yaml to reflect addition of tests/grid/test_eta.py
fmalatino Aug 27, 2024
9cb8f14
Amending file path for test_eta.py
fmalatino Aug 27, 2024
a0c4992
Another attempt to get the workflow to generate the test eta_files
fmalatino Aug 27, 2024
10942b2
Linting
fmalatino Aug 27, 2024
712a385
Use of f-string in ValueError statement of _load_ak_bk_from_file
fmalatino Aug 29, 2024
37872f0
Amending pytest.fail statement in test_eta.py
fmalatino Aug 29, 2024
c76a486
Amended generation.py to define hybrid pressure variables appropriately
fmalatino Aug 30, 2024
1082b62
Amended test_eta.py docstrings to reflect updated testing methods and…
fmalatino Sep 5, 2024
8a236a7
Merge branch 'develop' into feature/no_eta
fmalatino Sep 5, 2024
71bcb56
Merge branch 'develop' into feature/no_eta
fmalatino Sep 6, 2024
3649691
Linting
fmalatino Sep 6, 2024
1102b75
Merge branch 'develop' into feature/no_eta
fmalatino Sep 12, 2024
1318b56
Amended generation.py to set default eta_file to None
fmalatino Sep 12, 2024
49ebd43
Merged most recent changes of NDSL as of 12 Sept 2024
fmalatino Sep 12, 2024
a1010dd
Changed type hinting of eta_file in generation.py to reflect optional…
fmalatino Sep 12, 2024
069f056
Merge branch 'develop' into feature/no_eta
fmalatino Sep 16, 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
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the behavior we want? I thought we'd rather raise a ValueError or something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ValueError is raised deeper in when the file specified is either non-existent, and even lower if the values do not fit the size passed in the config. My thought was that we could still have hybrid pressure values; zero valued if no file passed, or specified when passed.

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
Loading