Skip to content

Commit 6046070

Browse files
committed
update tests to check timeseries output values
1 parent 198c588 commit 6046070

File tree

6 files changed

+203
-13
lines changed

6 files changed

+203
-13
lines changed

src/rashdf/plan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class TimeSeriesOutputVar(Enum):
119119
TimeSeriesOutputVar.FACE_TANGENTIAL_VELOCITY,
120120
TimeSeriesOutputVar.FACE_VELOCITY,
121121
TimeSeriesOutputVar.FACE_WATER_SURFACE,
122+
# TODO: investigate why "Face Wind Term" data gets written as a 1D array
122123
# TimeSeriesOutputVar.FACE_WIND_TERM,
123124
]
124125

@@ -830,6 +831,7 @@ def mesh_timeseries_output(
830831
raise ValueError(f"Invalid time series output variable: {var.value}")
831832
da = xr.DataArray(
832833
values,
834+
name=var.value,
833835
dims=["time", id_coord],
834836
coords={
835837
"time": times,
@@ -853,7 +855,7 @@ def _mesh_timeseries_outputs(
853855
continue
854856
da = self.mesh_timeseries_output(mesh_name, var)
855857
datasets[var.value] = da
856-
ds = xr.Dataset(datasets)
858+
ds = xr.Dataset(datasets, attrs={"mesh_name": mesh_name})
857859
return ds
858860

859861
def mesh_timeseries_output_cells(self, mesh_name: str) -> xr.Dataset:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
time,face_id,Face Velocity
2+
1999-01-01 12:00:00,678,0.0
3+
1999-01-01 14:00:00,678,0.0
4+
1999-01-01 16:00:00,678,0.0
5+
1999-01-01 18:00:00,678,0.0
6+
1999-01-01 20:00:00,678,0.0
7+
1999-01-01 22:00:00,678,0.0
8+
1999-01-02 00:00:00,678,0.0
9+
1999-01-02 02:00:00,678,0.0
10+
1999-01-02 04:00:00,678,0.0
11+
1999-01-02 06:00:00,678,0.0
12+
1999-01-02 08:00:00,678,0.0
13+
1999-01-02 10:00:00,678,0.0
14+
1999-01-02 12:00:00,678,0.0
15+
1999-01-02 14:00:00,678,0.0
16+
1999-01-02 16:00:00,678,0.0
17+
1999-01-02 18:00:00,678,0.0
18+
1999-01-02 20:00:00,678,0.0
19+
1999-01-02 22:00:00,678,0.0
20+
1999-01-03 00:00:00,678,0.0
21+
1999-01-03 02:00:00,678,0.0
22+
1999-01-03 04:00:00,678,0.0
23+
1999-01-03 06:00:00,678,-0.28543922
24+
1999-01-03 08:00:00,678,-0.94968337
25+
1999-01-03 10:00:00,678,-1.1934088
26+
1999-01-03 12:00:00,678,-1.3193293
27+
1999-01-03 14:00:00,678,-1.448421
28+
1999-01-03 16:00:00,678,-1.5487186
29+
1999-01-03 18:00:00,678,-1.6022989
30+
1999-01-03 20:00:00,678,-1.6255693
31+
1999-01-03 22:00:00,678,-1.6309046
32+
1999-01-04 00:00:00,678,-1.625484
33+
1999-01-04 02:00:00,678,-1.6135458
34+
1999-01-04 04:00:00,678,-1.5972468
35+
1999-01-04 06:00:00,678,-1.5781946
36+
1999-01-04 08:00:00,678,-1.5570217
37+
1999-01-04 10:00:00,678,-1.5398287
38+
1999-01-04 12:00:00,678,-1.5226055
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
time,cell_id,Water Surface
2+
1999-01-01 12:00:00,123,537.2959
3+
1999-01-01 14:00:00,123,537.2959
4+
1999-01-01 16:00:00,123,537.2959
5+
1999-01-01 18:00:00,123,537.2959
6+
1999-01-01 20:00:00,123,537.2959
7+
1999-01-01 22:00:00,123,537.2959
8+
1999-01-02 00:00:00,123,537.2959
9+
1999-01-02 02:00:00,123,537.2959
10+
1999-01-02 04:00:00,123,537.2959
11+
1999-01-02 06:00:00,123,537.2959
12+
1999-01-02 08:00:00,123,537.2959
13+
1999-01-02 10:00:00,123,537.2959
14+
1999-01-02 12:00:00,123,537.2959
15+
1999-01-02 14:00:00,123,537.2959
16+
1999-01-02 16:00:00,123,537.2959
17+
1999-01-02 18:00:00,123,537.2959
18+
1999-01-02 20:00:00,123,537.2959
19+
1999-01-02 22:00:00,123,537.2959
20+
1999-01-03 00:00:00,123,537.2959
21+
1999-01-03 02:00:00,123,537.2959
22+
1999-01-03 04:00:00,123,537.2959
23+
1999-01-03 06:00:00,123,537.39996
24+
1999-01-03 08:00:00,123,543.78345
25+
1999-01-03 10:00:00,123,546.0193
26+
1999-01-03 12:00:00,123,547.2876
27+
1999-01-03 14:00:00,123,548.71246
28+
1999-01-03 16:00:00,123,549.9208
29+
1999-01-03 18:00:00,123,550.59985
30+
1999-01-03 20:00:00,123,550.90826
31+
1999-01-03 22:00:00,123,550.9861
32+
1999-01-04 00:00:00,123,550.92456
33+
1999-01-04 02:00:00,123,550.7785
34+
1999-01-04 04:00:00,123,550.5764
35+
1999-01-04 06:00:00,123,550.3424
36+
1999-01-04 08:00:00,123,550.0916
37+
1999-01-04 10:00:00,123,549.85077
38+
1999-01-04 12:00:00,123,549.6207
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
time,face_id,Face Velocity
2+
1999-01-01 12:00:00,567,0.0
3+
1999-01-01 14:00:00,567,0.0
4+
1999-01-01 16:00:00,567,0.0
5+
1999-01-01 18:00:00,567,0.0
6+
1999-01-01 20:00:00,567,0.0
7+
1999-01-01 22:00:00,567,0.0
8+
1999-01-02 00:00:00,567,0.0
9+
1999-01-02 02:00:00,567,0.0
10+
1999-01-02 04:00:00,567,0.0
11+
1999-01-02 06:00:00,567,0.0
12+
1999-01-02 08:00:00,567,0.0
13+
1999-01-02 10:00:00,567,0.0
14+
1999-01-02 12:00:00,567,0.0
15+
1999-01-02 14:00:00,567,0.0
16+
1999-01-02 16:00:00,567,-0.08126567
17+
1999-01-02 18:00:00,567,-0.031525202
18+
1999-01-02 20:00:00,567,-0.05927151
19+
1999-01-02 22:00:00,567,-0.08731246
20+
1999-01-03 00:00:00,567,-0.10861763
21+
1999-01-03 02:00:00,567,-0.13474327
22+
1999-01-03 04:00:00,567,-0.15085366
23+
1999-01-03 06:00:00,567,-0.13912068
24+
1999-01-03 08:00:00,567,-0.16435227
25+
1999-01-03 10:00:00,567,-0.16623442
26+
1999-01-03 12:00:00,567,-0.16526061
27+
1999-01-03 14:00:00,567,-0.16261855
28+
1999-01-03 16:00:00,567,-0.15927659
29+
1999-01-03 18:00:00,567,-0.15739673
30+
1999-01-03 20:00:00,567,-0.15771057
31+
1999-01-03 22:00:00,567,-0.094285294
32+
1999-01-04 00:00:00,567,-0.069785364
33+
1999-01-04 02:00:00,567,-0.055208486
34+
1999-01-04 04:00:00,567,-0.04507809
35+
1999-01-04 06:00:00,567,-0.037555225
36+
1999-01-04 08:00:00,567,-0.031792343
37+
1999-01-04 10:00:00,567,-0.0249611
38+
1999-01-04 12:00:00,567,-0.021199187
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
time,cell_id,Water Surface
2+
1999-01-01 12:00:00,456,632.2363
3+
1999-01-01 14:00:00,456,632.2363
4+
1999-01-01 16:00:00,456,632.2363
5+
1999-01-01 18:00:00,456,632.2363
6+
1999-01-01 20:00:00,456,632.2363
7+
1999-01-01 22:00:00,456,632.6684
8+
1999-01-02 00:00:00,456,634.0546
9+
1999-01-02 02:00:00,456,635.6736
10+
1999-01-02 04:00:00,456,637.54553
11+
1999-01-02 06:00:00,456,639.678
12+
1999-01-02 08:00:00,456,642.2366
13+
1999-01-02 10:00:00,456,645.18005
14+
1999-01-02 12:00:00,456,648.437
15+
1999-01-02 14:00:00,456,651.93463
16+
1999-01-02 16:00:00,456,655.60315
17+
1999-01-02 18:00:00,456,659.2467
18+
1999-01-02 20:00:00,456,662.27795
19+
1999-01-02 22:00:00,456,664.529
20+
1999-01-03 00:00:00,456,666.1582
21+
1999-01-03 02:00:00,456,667.3115
22+
1999-01-03 04:00:00,456,668.081
23+
1999-01-03 06:00:00,456,668.5928
24+
1999-01-03 08:00:00,456,668.88885
25+
1999-01-03 10:00:00,456,669.04114
26+
1999-01-03 12:00:00,456,669.07465
27+
1999-01-03 14:00:00,456,668.9937
28+
1999-01-03 16:00:00,456,668.8436
29+
1999-01-03 18:00:00,456,668.656
30+
1999-01-03 20:00:00,456,668.4458
31+
1999-01-03 22:00:00,456,668.22107
32+
1999-01-04 00:00:00,456,667.9862
33+
1999-01-04 02:00:00,456,667.744
34+
1999-01-04 04:00:00,456,667.49695
35+
1999-01-04 06:00:00,456,667.2534
36+
1999-01-04 08:00:00,456,667.01154
37+
1999-01-04 10:00:00,456,666.7654
38+
1999-01-04 12:00:00,456,666.51526

tests/test_plan.py

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
from pathlib import Path
99

10+
import numpy as np
11+
import pandas as pd
12+
from pandas.testing import assert_frame_equal
1013
import pytest
1114

1215
from . import _create_hdf_with_group_attrs, _gdf_matches_json, get_sha1_hash
1316

1417
TEST_DATA = Path("./tests/data")
1518
TEST_JSON = TEST_DATA / "json"
19+
TEST_CSV = TEST_DATA / "csv"
1620
TEST_ATTRS = {"test_attribute1": "test_str1", "test_attribute2": 500}
1721
BALD_EAGLE_P18 = TEST_DATA / "ras/BaldEagleDamBrk.p18.hdf"
1822
BALD_EAGLE_P18_TIMESERIES = TEST_DATA / "ras/BaldEagleDamBrk.p18.timeseries.hdf"
@@ -186,19 +190,35 @@ def test_mesh_timeseries_output_cells():
186190
assert "time" in ds.coords
187191
assert "cell_id" in ds.coords
188192
assert "Water Surface" in ds.variables
189-
water_surface = ds["Water Surface"]
190-
assert water_surface.shape == (37, 3359)
191-
assert water_surface.attrs["units"] == "ft"
192-
assert water_surface.attrs["mesh_name"] == "BaldEagleCr"
193+
ws = ds["Water Surface"]
194+
assert ws.shape == (37, 3359)
195+
assert ws.attrs["units"] == "ft"
196+
assert ws.attrs["mesh_name"] == "BaldEagleCr"
197+
df = ws.sel(cell_id=123).to_dataframe()
198+
valid_df = pd.read_csv(
199+
TEST_CSV / "BaldEagleDamBrk.BaldEagleCr.ws.123.csv",
200+
index_col="time",
201+
parse_dates=True,
202+
dtype={"Water Surface": np.float32},
203+
)
204+
assert_frame_equal(df, valid_df)
193205

194206
ds = plan_hdf.mesh_timeseries_output_cells("Upper 2D Area")
195207
assert "time" in ds.coords
196208
assert "cell_id" in ds.coords
197209
assert "Water Surface" in ds.variables
198-
water_surface = ds["Water Surface"]
199-
assert water_surface.shape == (37, 1066)
200-
assert water_surface.attrs["units"] == "ft"
201-
assert water_surface.attrs["mesh_name"] == "Upper 2D Area"
210+
ws = ds["Water Surface"]
211+
assert ws.shape == (37, 1066)
212+
assert ws.attrs["units"] == "ft"
213+
assert ws.attrs["mesh_name"] == "Upper 2D Area"
214+
df = ws.sel(cell_id=456).to_dataframe()
215+
valid_df = pd.read_csv(
216+
TEST_CSV / "BaldEagleDamBrk.Upper2DArea.ws.456.csv",
217+
index_col="time",
218+
parse_dates=True,
219+
dtype={"Water Surface": np.float32},
220+
)
221+
assert_frame_equal(df, valid_df)
202222

203223

204224
def test_mesh_timeseries_output_faces():
@@ -207,10 +227,18 @@ def test_mesh_timeseries_output_faces():
207227
assert "time" in ds.coords
208228
assert "face_id" in ds.coords
209229
assert "Face Velocity" in ds.variables
210-
ws = ds["Face Velocity"]
211-
assert ws.shape == (37, 7295)
212-
assert ws.attrs["units"] == "ft/s"
213-
assert ws.attrs["mesh_name"] == "BaldEagleCr"
230+
v = ds["Face Velocity"]
231+
assert v.shape == (37, 7295)
232+
assert v.attrs["units"] == "ft/s"
233+
assert v.attrs["mesh_name"] == "BaldEagleCr"
234+
df = v.sel(face_id=678).to_dataframe()
235+
valid_df = pd.read_csv(
236+
TEST_CSV / "BaldEagleDamBrk.BaldEagleCr.v.678.csv",
237+
index_col="time",
238+
parse_dates=True,
239+
dtype={"Face Velocity": np.float32},
240+
)
241+
assert_frame_equal(df, valid_df)
214242

215243
ds = plan_hdf.mesh_timeseries_output_faces("Upper 2D Area")
216244
assert "time" in ds.coords
@@ -220,3 +248,11 @@ def test_mesh_timeseries_output_faces():
220248
assert v.shape == (37, 2286)
221249
assert v.attrs["units"] == "ft/s"
222250
assert v.attrs["mesh_name"] == "Upper 2D Area"
251+
df = v.sel(face_id=567).to_dataframe()
252+
valid_df = pd.read_csv(
253+
TEST_CSV / "BaldEagleDamBrk.Upper2DArea.v.567.csv",
254+
index_col="time",
255+
parse_dates=True,
256+
dtype={"Face Velocity": np.float32},
257+
)
258+
assert_frame_equal(df, valid_df)

0 commit comments

Comments
 (0)