Skip to content

Commit

Permalink
Merge pull request #6 from hydroframe/test_1pt_1hr
Browse files Browse the repository at this point in the history
add scenario for test_1pt_1hr to compare local,remote with smallest size
  • Loading branch information
wh3248 authored Jan 16, 2025
2 parents 6d3a146 + 3c527a5 commit e050b76
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-performance-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
pytest -s performance/test_hydrogen_forcing.py --wy 1985 --cache=hot --users=-4
pytest -s performance/test_cw3e_subset.py --wy 2019 --cache=cold
pytest -s performance/test_cw3e_subset.py --wy 2019 --cache=hot
pytest -s performance/test_1pt_1h.py --wy=1995 --cache=cold
pytest -s performance/test_1pt_1h.py --wy=1995 --cache=hot
echo "Show ./artifacts/log_artifact.csv file"
Expand Down
45 changes: 45 additions & 0 deletions performance/test_1pt_1h.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Performance test for the scenario to 1 point for 1 hour of CONUS2
using hf_hydrodata.
"""

# pylint: disable=C0301,W1514,R0914

import time
import hf_hydrodata as hf
import utils


def test_scenario(request):
"""
Test the scenario to get 1 hour of 1 point and
create logging artifact with performance information.
"""

local_remote = utils.register_email_pin("public")
(start_time_str, end_time_str) = utils.get_1h_duration(request)

t0 = time.time()
_execute_scenario(start_time_str, end_time_str)
t1 = time.time()
duration = round(t1 - t0, 2)
scenario_name = "read_1_hour_1_point"
utils.write_log(scenario_name, request, local_remote, duration)


def _execute_scenario(start_time_str, end_time_str):
"""Execute the scenario to be tested"""

bounds = [4057, 1914, 4058, 1915]
options = {
"dataset": "CW3E",
"period": "hourly",
"dataset_version": "1.0",
"variable": "precipitation",
"start_time": start_time_str,
"end_time": end_time_str,
"grid_bounds": bounds,
"nomask": "true",
}
data = hf.get_gridded_data(options)
assert data.shape == (1, 1, 1)
20 changes: 20 additions & 0 deletions performance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,23 @@ def get_wy_duration(request):
start_time_str = start_time.strftime("%Y-%m-%d")
end_time_str = end_time.strftime("%Y-%m-%d")
return (start_time_str, end_time_str)

def get_1h_duration(request):
"""
Get the start/end time of one hour of data for the water year specified in the configuration options.
Returns:
Tuple (start_time_str, end_time_str)
"""
start_time_str = ""
end_time_str = ""
wy = int(request.config.getoption("--wy"))
wy_month = int(request.config.getoption("--wy_month"))

start_time = datetime.datetime.strptime(f"{wy}-06-01", "%Y-%m-%d")
if wy_month:
start_time = start_time.replace(month=int(wy_month))
end_time = start_time.replace(hour=1)
start_time_str = start_time.strftime("%Y-%m-%d %H:%M:%S")
end_time_str = end_time.strftime("%Y-%m-%d %H:%M:%S")

return (start_time_str, end_time_str)

0 comments on commit e050b76

Please sign in to comment.