forked from NOAA-OWP/ngen-forcing
-
Notifications
You must be signed in to change notification settings - Fork 3
Geo test pre refactor #125
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
cafd4c2
format/fix docstrings
mdeshotel dec3956
format docstrings in conftest
mdeshotel 4b76797
add tests for geomod and inputforcing
mdeshotel 4e5ef0b
add arg to allow new attributes in actual results
mdeshotel 4f0e102
add grid type arg to dynamically get the correct bmi model class
mdeshotel 61a3ede
add method to convert class attibutes and properties to a dictionary
mdeshotel 93308a1
rename wrf_hydro_geo_meta to geometa
mdeshotel 0b81d4f
map old variable names to new names
mdeshotel 4f3a3aa
add support for serializing functions as string
mdeshotel 2067920
use ordered dict
mdeshotel 02e9f55
add read me for test
mdeshotel aae9450
add rank and number of processors to test json filename
mdeshotel a3dea19
repalce np.empty with np.full
mdeshotel 4cf93f1
add new arg to control the mapping of old variable names to new
mdeshotel 25eaa39
update expected test data
mdeshotel 39d4443
replace remaning np.empty with np.full
mdeshotel 105a756
fix ewts acronym in tests readme.
mdeshotel e051b17
mention inthe readme that tests should be ran in dev container
mdeshotel 8199b9a
revert geometa naming
mdeshotel 269dee1
fix map_old_to_new_var_names logic
mdeshotel 584c021
update readme to be more verbose about the initial expected data setup.
mdeshotel 026d78b
add type hints
mdeshotel 74e3b34
change config locations to test dir
mdeshotel 18c02ce
compare dict items and report misaligned items
mdeshotel e20bfd0
update configs and expected results
mdeshotel 9adf42f
replace symlink with actual file
mdeshotel 7db68e5
fix typo
mdeshotel 6818ea6
update gpkg
mdeshotel 5c880fd
updated expected test results
mdeshotel f1ea03f
fix boolean from pytest arg issue
mdeshotel cd91046
fix boolean for map_old_to_new_var_names 2.0
mdeshotel ab1a6ed
add dtype to np.full calls
mdeshotel da48fa2
add copy_and_stringify_functions
mdeshotel 7aa1322
add class_to_dict function
mdeshotel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
940 changes: 940 additions & 0 deletions
940
NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| # Tests README | ||
mxkpp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| This directory contains tests for the NextGen Forcing BMI Engine. | ||
|
|
||
| ## Initial test data | ||
|
|
||
| Tests data is included in the `test_data` directory and includes configs, gpkgs, esmf_meshes, expected results and actual results. While the configs, gpkgs, esmf_meshes and expectd results are included in the repo and can be used as is, the following steps can be taken to re-create these test inputs. | ||
|
|
||
| --- | ||
| The initial test data was generated using `nwm-rte` to create a calibration realization | ||
| for gage 01123000, starting at time 2013-07-01 00:00:00, and running for 3 timesteps, | ||
| using `nwm-rte's` run_suite.sh. See RETRO_FORCING_CONFIG_FILE__AORC_CONUS. | ||
|
|
||
| More specifically the initial expected test data was developed with these specific configurations in `config.bashrc`. | ||
| ``` | ||
| REPO_TAG_FCST_MGR="856fc0e1201076df909e56c7cd384f58e82965a2" | ||
| REPO_TAG_MSW_MGR="693c206a22b5e9ffcca3103166c0ca59e2b11b25" | ||
| REPO_TAG_CAL_MGR="7e56bf01477ea77e72dfb25a166ac26ff6090ecb" | ||
| REPO_TAG_NGEN_FORCING="LOCAL" | ||
| NGEN_SOURCE_MODE="ghcr" | ||
| NGEN_BASE__REMOTE_GHCR_TAG="844c5f6" | ||
| ``` | ||
|
|
||
| And these two commands in `nwm-rte's` `run_suite.sh`: | ||
| ```bash | ||
| docker_run python "/ngen-app/bin/bin_mounted/run_calibration.py" -n 2 -fsrc "aorc" -start "2013-07-01 00:00:00" -dur 3 | ||
|
|
||
| docker_run python "/ngen-app/bin/bin_mounted/run_forecast.py" -fconfig "short_range" -dt "2025-07-10 04:00:00" -rname "fcst_run1_short_range" | ||
| ``` | ||
| ## Test Structure | ||
|
|
||
| The test suite is organized into the following modules: | ||
|
|
||
| - **`esmf_regrid/`** - Tests for ESMF regridding functionality | ||
| - **`geomod/`** - Tests for geomod components | ||
| - **`input_forcing/`** - Tests for input forcing data processing | ||
| - **`nextgen_forcings_ewts/`** - Tests for EWTS (Error, Warning, and Trapping System) forcings | ||
| - **`test_utils.py`** - Shared test utilities and fixtures | ||
| - **`conftest.py`** - Pytest configuration and shared fixtures | ||
|
|
||
| ## Prerequisites | ||
| ### Setup requirements: | ||
| 1. Create the forcing config.yml files using RTE. | ||
| 2. Enter the RTE devcontainer. | ||
|
|
||
| ### Required Dependencies | ||
|
|
||
| The test suite requires Python 3.11 or higher. Install the package with test dependencies inside of the `dev container`: | ||
|
|
||
| ```bash | ||
| # From the repository root directory | ||
| pip install -e ".[develop]" | ||
| ``` | ||
|
|
||
| Or install pytest directly inside of the `dev container`: | ||
|
|
||
| ```bash | ||
| pip install pytest | ||
| ``` | ||
|
|
||
| ### Additional Requirements | ||
|
|
||
| Ensure all main package dependencies are installed inside of the `dev container` (this typically should happen when the `dev container` is built): | ||
|
|
||
| ```bash | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ### Run All Tests From the Dev Container | ||
|
|
||
| ```bash | ||
| Single processor: (cd src/ngen-forcing && pytest ) | ||
| Multiple processors: ( cd src/ngen-forcing && mpirun -n 2 pytest ) | ||
| ``` | ||
| ### Run Specific Test Modules From the Dev Container | ||
|
|
||
| Run tests for a specific module: | ||
|
|
||
| ```bash | ||
| # ESMF regridding tests | ||
| Single processor: ( cd src/ngen-forcing && pytest tests/esmf_regrid) | ||
| Multiple processors: ( cd src/ngen-forcing && mpirun -n 2 pytest tests/esmf_regrid) | ||
|
|
||
| # GeoMod tests | ||
| Single processor: ( cd src/ngen-forcing && pytest tests/geomod) | ||
| Multiple processors: ( cd src/ngen-forcing && mpirun -n 2 pytest tests/geomod) | ||
|
|
||
| # Input forcing tests | ||
| Single processor: ( cd src/ngen-forcing && pytest tests/input_forcing) | ||
| Multiple processors: ( cd src/ngen-forcing && mpirun -n 2 pytest tests/input_forcing) | ||
| ``` | ||
|
|
||
| Create new test output data (creates expected outputs for subsequent tests) | ||
| ```bash | ||
| # ESMF regridding tests | ||
| Single processor: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true pytest tests/esmf_regrid) | ||
| Multiple processors: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true mpirun -n 2 pytest tests/esmf_regrid) | ||
|
|
||
| # GeoMod tests | ||
| Single processor: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true pytest tests/geomod) | ||
| Multiple processors: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true mpirun -n 2 pytest tests/geomod) | ||
|
|
||
| # Input forcing tests | ||
| Single processor: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true pytest tests/input_forcing) | ||
| Multiple processors: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true mpirun -n 2 pytest tests/input_forcing) | ||
| ``` | ||
|
|
||
| In the rare case where you want to create new `expected` data and run the tests using `old` variable names use the following for `Input Forcing Tests`: | ||
| ```bash | ||
| # Input forcing tests | ||
| Single processor: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true pytest tests/input_forcing --map_old_to_new_var_names False) | ||
| Multiple processors: ( cd src/ngen-forcing && FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true mpirun -n 2 pytest tests/input_forcing --map_old_to_new_var_names False) | ||
| ``` | ||
| ## Test Configuration | ||
|
|
||
| The test suite is configured via `pytest.ini` at the repository root: | ||
|
|
||
| - **Python path**: Set to repository root (`.`) | ||
| - **Logging**: Enabled with INFO level (DEBUG available by uncommenting) | ||
| - **Verbosity**: Full trace with verbose output (`-vv`) | ||
| - **Test paths**: Pre-configured to discover tests in `esmf_regrid`, `geomod`, and `input_forcing` | ||
|
|
||
|
|
||
| ## Test Data | ||
|
|
||
| Test data is stored in the `test_data/` directory. Tests may reference files from this location for input data and expected results validation. | ||
|
|
||
| ## Writing New Tests | ||
|
|
||
| When adding new tests: | ||
|
|
||
| 1. Place test files in the appropriate subdirectory | ||
| 2. Name test files with the `test_*.py` prefix | ||
| 3. Name test functions with the `test_*` prefix | ||
| 4. Use fixtures from `conftest.py` for common setup | ||
| 5. Place test data files in `test_data/` with descriptive names | ||
|
|
||
| Example test structure: | ||
|
|
||
| ```python | ||
| import pytest | ||
|
|
||
| def test_my_feature(): | ||
| """Test description.""" | ||
| # Arrange | ||
| input_data = ... | ||
|
|
||
| # Act | ||
| result = function_under_test(input_data) | ||
|
|
||
| # Assert | ||
| assert result == expected_output | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.