Skip to content

Commit a9e51f7

Browse files
black format
1 parent b81e9ee commit a9e51f7

1 file changed

Lines changed: 91 additions & 44 deletions

File tree

test_suite/test_smscg.py

Lines changed: 91 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,56 @@
66
import os
77
import xarray as xr
88
import datetime
9-
from vtools import elapsed_datetime,datetime_elapsed,days
9+
from vtools import elapsed_datetime, datetime_elapsed, days
1010
import pandas as pd
1111
import numpy as np
1212

1313

1414
@pytest.fixture(scope="module")
1515
def smscg_dfs(sim_dir, params):
16-
""" Reads the three montezuma .th files """
16+
"""Reads the three montezuma .th files"""
1717
start = params.run_start
18-
boat = pd.read_csv(os.path.join(sim_dir,"montezuma_boat_lock.th"),index_col=0,sep=r'\s+',header=None,comment="#")
19-
flash = pd.read_csv(os.path.join(sim_dir,"montezuma_flash.th"),index_col=0,sep=r'\s+',header=None,comment="#")
20-
radial = pd.read_csv(os.path.join(sim_dir,"montezuma_radial.th"),index_col=0,sep=r'\s+',header=None,comment="#")
21-
return [elapsed_datetime(x,reftime=start) for x in (boat, flash, radial)]
18+
boat = pd.read_csv(
19+
os.path.join(sim_dir, "montezuma_boat_lock.th"),
20+
index_col=0,
21+
sep=r"\s+",
22+
header=None,
23+
comment="#",
24+
)
25+
flash = pd.read_csv(
26+
os.path.join(sim_dir, "montezuma_flash.th"),
27+
index_col=0,
28+
sep=r"\s+",
29+
header=None,
30+
comment="#",
31+
)
32+
radial = pd.read_csv(
33+
os.path.join(sim_dir, "montezuma_radial.th"),
34+
index_col=0,
35+
sep=r"\s+",
36+
header=None,
37+
comment="#",
38+
)
39+
return [elapsed_datetime(x, reftime=start) for x in (boat, flash, radial)]
40+
2241

2342
def align_dfs(boat, flash, radial):
24-
""" Ensures alignment of the three dataframes and fills to radial index """
43+
"""Ensures alignment of the three dataframes and fills to radial index"""
2544
org_indices = sorted(set(pd.concat([boat, flash, radial]).index))
2645
boat = extend_idx(boat, org_indices[0], org_indices[-1])
2746
flash = extend_idx(flash, org_indices[0], org_indices[-1])
2847
radial = extend_idx(radial, org_indices[0], org_indices[-1])
2948

30-
boat = boat.resample('1min').asfreq().ffill()
31-
flash = boat.resample('1min').asfreq().ffill()
32-
radial = boat.resample('1min').asfreq().ffill()
49+
boat = boat.resample("1min").asfreq().ffill()
50+
flash = boat.resample("1min").asfreq().ffill()
51+
radial = boat.resample("1min").asfreq().ffill()
3352

3453
# Get rid of unecessary (unchanged) timestamps
3554
boat = boat.loc[org_indices]
3655
flash = flash.loc[org_indices]
3756
radial = radial.loc[org_indices]
38-
return [boat, flash, radial]
57+
return [boat, flash, radial]
58+
3959

4060
def extend_idx(df, start, end):
4161
start_row = df.iloc[0].to_frame().T
@@ -47,64 +67,91 @@ def extend_idx(df, start, end):
4767

4868
@pytest.mark.prerun
4969
def test_smscg_boatlock(sim_dir, params, smscg_dfs):
50-
""" Checks that the boatlock is open whenever the radial gates are operated tidally (op_up=0) """
70+
"""Checks that the boatlock is open whenever the radial gates are operated tidally (op_up=0)"""
5171

52-
boat, flash, radial = smscg_dfs
72+
boat, flash, radial = smscg_dfs
5373
boat, flash, radial = align_dfs(boat, flash, radial)
5474

5575
# Compare the 4th column (op_up) of `boat` with `radial`
56-
matches = (radial.iloc[:, 3]==0) & (boat.iloc[:,3]==0)
57-
matches_seconds = datetime_elapsed(matches,reftime=params.run_start)
58-
76+
matches = (radial.iloc[:, 3] == 0) & (boat.iloc[:, 3] == 0)
77+
matches_seconds = datetime_elapsed(matches, reftime=params.run_start)
78+
5979
print("Boatlock Error Times ----------------")
60-
for match, sec in zip(matches.index[matches].values, matches_seconds.index[matches].values):
61-
print(f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}, Boatlock op_up: {boat.loc[match].iloc[3]}")
62-
assert (~matches).all(), f"montezuma_boat_lock should not be closed when montezuma_radial is in tidal operation."
80+
for match, sec in zip(
81+
matches.index[matches].values, matches_seconds.index[matches].values
82+
):
83+
print(
84+
f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}, Boatlock op_up: {boat.loc[match].iloc[3]}"
85+
)
86+
assert (
87+
~matches
88+
).all(), f"montezuma_boat_lock should not be closed when montezuma_radial is in tidal operation."
89+
6390

6491
@pytest.mark.prerun
6592
def test_smscg_flash(sim_dir, params, smscg_dfs):
66-
""" Checks that the flashboards are closed when the radial gates are operated tidally (op_up=0) """
93+
"""Checks that the flashboards are closed when the radial gates are operated tidally (op_up=0)"""
6794

68-
boat, flash, radial = smscg_dfs
95+
boat, flash, radial = smscg_dfs
6996
boat, flash, radial = align_dfs(boat, flash, radial)
7097

7198
# Compare the 4th column (op_up) of `flash` with `radial`, ensuring that when radial gates are tidally operated, the flashboards are closed
72-
matches = (radial.iloc[:, 3]==0) & (flash.iloc[:,3]!=0)
73-
matches_seconds = datetime_elapsed(matches,reftime=params.run_start)
74-
99+
matches = (radial.iloc[:, 3] == 0) & (flash.iloc[:, 3] != 0)
100+
matches_seconds = datetime_elapsed(matches, reftime=params.run_start)
101+
75102
print("Flash Error Times ----------------")
76-
for match, sec in zip(matches.index[matches].values, matches_seconds.index[matches].values):
77-
print(f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}, Flash op_up: {flash.loc[match].iloc[3]}")
78-
assert (~matches).all(), f"montezuma_flash should not be open when montezuma_radial is in tidal operation."
103+
for match, sec in zip(
104+
matches.index[matches].values, matches_seconds.index[matches].values
105+
):
106+
print(
107+
f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}, Flash op_up: {flash.loc[match].iloc[3]}"
108+
)
109+
assert (
110+
~matches
111+
).all(), f"montezuma_flash should not be open when montezuma_radial is in tidal operation."
112+
79113

80114
@pytest.mark.prerun
81115
def test_smscg_radial_tides(sim_dir, params, smscg_dfs):
82-
""" Checks that the tidal radial operations make sense """
116+
"""Checks that the tidal radial operations make sense"""
83117

84-
boat, flash, radial = smscg_dfs
118+
boat, flash, radial = smscg_dfs
85119

86120
# Compare the 3rd and 4th columns (op_down and op_up) of radial, ensuring tidal operation
87-
matches = (radial.iloc[:, 3]==0) & (radial.iloc[:,2]==0)
88-
matches_seconds = datetime_elapsed(matches,reftime=params.run_start)
89-
121+
matches = (radial.iloc[:, 3] == 0) & (radial.iloc[:, 2] == 0)
122+
matches_seconds = datetime_elapsed(matches, reftime=params.run_start)
123+
90124
print("Tidal Radial Error Times ----------------")
91-
for match, sec in zip(matches.index[matches].values, matches_seconds.index[matches].values):
92-
print(f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}")
125+
for match, sec in zip(
126+
matches.index[matches].values, matches_seconds.index[matches].values
127+
):
128+
print(
129+
f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}"
130+
)
131+
132+
assert (
133+
~matches
134+
).all(), f"montezuma_radial tidal operation not correct. op_down should be 1.0 when op_up is 0.0."
93135

94-
assert (~matches).all(), f"montezuma_radial tidal operation not correct. op_down should be 1.0 when op_up is 0.0."
95136

96137
@pytest.mark.prerun
97138
def test_smscg_radial_open(sim_dir, params, smscg_dfs):
98-
""" Checks that the radial operations make sense """
139+
"""Checks that the radial operations make sense"""
99140

100-
boat, flash, radial = smscg_dfs
141+
boat, flash, radial = smscg_dfs
101142

102143
# Compare the 3rd and 4th columns (op_down and op_up) of radial, ensuring tidal operation
103-
matches = (radial.iloc[:, 3]==1) & (radial.iloc[:,2]!=1)
104-
matches_seconds = datetime_elapsed(matches,reftime=params.run_start)
105-
106-
print("Radial Error Times ----------------")
107-
for match, sec in zip(matches.index[matches].values, matches_seconds.index[matches].values):
108-
print(f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}")
144+
matches = (radial.iloc[:, 3] == 1) & (radial.iloc[:, 2] != 1)
145+
matches_seconds = datetime_elapsed(matches, reftime=params.run_start)
109146

110-
assert (~matches).all(), f"montezuma_radial open condition not correct. op_down should be 1.0 when op_up is 1.0."
147+
print("Radial Error Times ----------------")
148+
for match, sec in zip(
149+
matches.index[matches].values, matches_seconds.index[matches].values
150+
):
151+
print(
152+
f"Seconds: {sec}, Datetime: {match}, Radial op_down: {radial.loc[match].iloc[2]}, Radial op_up: {radial.loc[match].iloc[3]}"
153+
)
154+
155+
assert (
156+
~matches
157+
).all(), f"montezuma_radial open condition not correct. op_down should be 1.0 when op_up is 1.0."

0 commit comments

Comments
 (0)