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

Feat swb rcn #152

Closed
wants to merge 21 commits into from
Closed
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
58a6572
rough draft of StorageVol subclass for SWB RCN
jmccreight Feb 1, 2023
21c1e0e
Merge branch 'EC-USGS:main' into feat_swb_rcn
smwesten-usgs Feb 3, 2023
74c22fa
add simple SWB Rootzone and netcdf conversion script
smwesten-usgs Mar 14, 2023
3924629
add SWBRootZone.py
smwesten-usgs Apr 27, 2023
4ed21b2
merge upstream/main
jmccreight Apr 27, 2023
704e625
just a temporary commit
jmccreight Apr 27, 2023
62aed0f
swb parameters in yaml working-ish
jmccreight Apr 27, 2023
fa8bacf
SWB plumbed
jmccreight Apr 28, 2023
2b8a4ad
SWB writes to netcdf good junk
jmccreight Apr 28, 2023
e3450b0
Merge branch 'EC-USGS:main' into feat_swb_rcn
smwesten-usgs May 15, 2023
4068cec
rename 'science_functions' to just 'functions'
smwesten-usgs May 25, 2023
ea1eb5b
Merge remote-tracking branch 'upstream/develop' into feat_swb_rcn
smwesten-usgs May 25, 2023
35769c9
first set of files working for swb2 application using hru_1 prcp, tmi…
smwesten-usgs Jun 8, 2023
02cd6b9
Merge branch 'EC-USGS:develop' into feat_swb_rcn
smwesten-usgs Jun 9, 2023
70da583
Merge branch 'EC-USGS:develop' into feat_swb_rcn
smwesten-usgs Jun 12, 2023
d48f46d
Add/move python and batch files for running/analyzing SWB test run fo…
smwesten-usgs Jun 12, 2023
2f875df
First attempt at complete rendition of SWB soil zone
smwesten-usgs Jun 13, 2023
f3c5eef
First (kind of) working version of SWB soil storage
smwesten-usgs Jun 14, 2023
873774b
Merge branch 'EC-USGS:develop' into feat_swb_rcn
smwesten-usgs Jun 28, 2023
93b6cbb
merge upstream/develop in to feat_swb_rcn
jmccreight Sep 8, 2023
b97b9ea
catch feat_swb_rcn up with v0.2.1
jmccreight Sep 8, 2023
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
1 change: 0 additions & 1 deletion autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import yaml


def pytest_addoption(parser):
parser.addoption(
"--domain_yaml",
Expand Down
1 change: 1 addition & 0 deletions autotest/run_swb_test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest --pdb --domain_yaml=../test_data/hru_1/hru_1.yaml test_swb_rootzone.py
85 changes: 85 additions & 0 deletions autotest/test_swb_rootzone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import pathlib as pl

import pytest

from pywatershed.base.control import Control
from pywatershed.hydrology.SWBRootZone import SWBRootZone

from pywatershed import Parameters
from pywatershed.utils.netcdf_utils import NetCdfCompare


def test_init(domain, tmp_path):
tmp_path = pl.Path(tmp_path)
params = Parameters.from_yaml(domain["swb_param_file"])

# TODO fix this. make it a data of DatasetDict.from_yaml()
# nc_file = tmp_path / "swb_params_hru_1.nc"
# params.to_netcdf(nc_file, use_xr=True)

# Set information from the control file
control = Control.load(domain["control_file"])

# load csv files into dataframes
swb_output_dir = domain["swb_output_dir"]
prms_output_dir = domain["prms_output_dir"]
input_variables = {}
for key in SWBRootZone.get_inputs():
nc_path = pl.Path(prms_output_dir) / f"{key}.nc"
input_variables[key] = nc_path

swb_rz = SWBRootZone(
control,
None,
params,
**input_variables,
budget_type="warn",
)

nc_parent = tmp_path / domain["domain_name"]
swb_rz.initialize_netcdf(nc_parent)

output_compare = {}
vars_compare = ("swb_soil_storage",)

for key in SWBRootZone.get_variables():
if key not in vars_compare:
continue

base_nc_path = (
pl.Path(swb_output_dir)
/ f"hru_1_5000__{key.removeprefix('swb_')}__1979-01-01_to_2019-12-31__1_by_1.nc"
)
compare_nc_path = tmp_path / domain["domain_name"] / f"{key}.nc"
output_compare[key] = (base_nc_path, compare_nc_path)

print(f"base_nc_path: {base_nc_path}")
print(f"compare_nc_path: {compare_nc_path}")

for istep in range(control.n_times):
control.advance()
swb_rz.advance()
swb_rz.calculate(float(istep))
swb_rz.output()

swb_rz.finalize()

# breakpoint()

assert_error = False
for key, (base, compare) in output_compare.items():
success, diff = NetCdfCompare(base, compare).compare()
breakpoint()
if not success:
print(
f"comparison for {key} failed: "
+ f"maximum error {diff[key][0]} "
+ f"(maximum allowed error {diff[key][1]}) "
+ f"in column {diff[key][2]}"
)
assert_error = True
assert not assert_error, "comparison failed"

# breakpoint()

return
Loading
Loading