Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jan 15, 2025
1 parent bcaaade commit 7fcdc3c
Show file tree
Hide file tree
Showing 88 changed files with 563 additions and 490 deletions.
24 changes: 12 additions & 12 deletions autotest/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ def _compare_output(self, compare):
rclose = get_rclose(self.workspace)
cmp_path = self.workspace / compare
if "mf6_regression" in compare:
assert self._compare_heads(
extensions=HDS_EXT, htol=htol
), "head comparison failed"
assert self._compare_budgets(
extensions=CBC_EXT, rclose=rclose
), "budget comparison failed"
assert self._compare_concentrations(
htol=htol
), "concentration comparison failed"
assert self._compare_heads(extensions=HDS_EXT, htol=htol), (
"head comparison failed"
)
assert self._compare_budgets(extensions=CBC_EXT, rclose=rclose), (
"budget comparison failed"
)
assert self._compare_concentrations(htol=htol), (
"concentration comparison failed"
)
else:
assert self._compare_heads(
cpth=cmp_path,
Expand Down Expand Up @@ -562,9 +562,9 @@ def _run_sim_or_model(
# make sure executable exists and framework knows about it
tgt = Path(shutil.which(target))
assert tgt.is_file(), f"Target executable not found: {target}"
assert (
tgt in self.targets.values()
), "Targets must be explicitly registered with the test framework"
assert tgt in self.targets.values(), (
"Targets must be explicitly registered with the test framework"
)

if self.verbose:
print(f"Running {target} in {workspace}")
Expand Down
12 changes: 6 additions & 6 deletions autotest/test_chf_dfw_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ def check_output(idx, test):
diff = obsvals["REACH14"] - answer["STAGE0000000014"]
print(diff)
print(diff.max(), diff.min())
assert np.allclose(
diff, 0.0, atol=0.06
), f"Max diff with swr is {diff.min(), diff.max()}"
assert np.allclose(diff, 0.0, atol=0.06), (
f"Max diff with swr is {diff.min(), diff.max()}"
)

# read the binary grid file
fpth = test.workspace / f"{name}.disv1d.grb"
Expand Down Expand Up @@ -524,9 +524,9 @@ def check_output(idx, test):
f"residual for cell {n + 1} is {qresidual[n]} "
f"in position {ia[n] + 1} {passfail}"
)
assert np.allclose(
qresidual, 0.0, atol=atol
), "residual in flowja diagonal is not zero"
assert np.allclose(qresidual, 0.0, atol=atol), (
"residual in flowja diagonal is not zero"
)

return

Expand Down
24 changes: 12 additions & 12 deletions autotest/test_chf_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,22 @@ def check_grb_disv1d(fpth):
assert grb.xorigin == xorigin, "xorigin in grb file is not correct"
assert grb.yorigin == yorigin, "yorigin in grb file is not correct"
assert grb.angrot == angrot, "angrot in grb file is not correct"
assert np.allclose(
grb.bot.reshape((nodes,)), np.zeros((nodes,))
), "grb botm not correct"
assert np.allclose(grb.bot.reshape((nodes,)), np.zeros((nodes,))), (
"grb botm not correct"
)
cellx = np.linspace(dx / 2, nreach * dx - dx / 2, nreach)
celly = np.zeros(nreach)
assert np.allclose(grb._datadict["CELLX"], cellx.flatten()), "cellx is not right"
assert np.allclose(grb._datadict["CELLY"], celly.flatten()), "celly is not right"
assert grb._datadict["IAVERT"].shape[0] == nodes + 1, "iavert size not right"
assert (
grb._datadict["IAVERT"][-1] - 1 == grb._datadict["JAVERT"].shape[0]
), "javert size not right"
assert grb._datadict["IAVERT"][-1] - 1 == grb._datadict["JAVERT"].shape[0], (
"javert size not right"
)
assert grb.ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"
assert grb.ja.shape[0] == grb.nja, "ja in grb file is not correct size"
assert np.allclose(
grb.idomain.reshape((nodes,)), idomain.reshape((nodes,))
), "grb idomain not correct"
assert np.allclose(grb.idomain.reshape((nodes,)), idomain.reshape((nodes,))), (
"grb idomain not correct"
)


def check_output(idx, test):
Expand All @@ -198,9 +198,9 @@ def check_output(idx, test):
fpth = test.workspace / f"{modelname}.stage"
sobj = flopy.utils.HeadFile(fpth, precision="double", text="STAGE")
stage = sobj.get_data().reshape((nodes,))
assert np.allclose(
stage[idomain == 0], 3.0e30
), "stage should have nodata values where idomain is zero"
assert np.allclose(stage[idomain == 0], 3.0e30), (
"stage should have nodata values where idomain is zero"
)
assert stage[idomain == 1].max() == 1.0, "maximum stage should be 1.0"
assert stage[idomain == 1].min() == 0.5, "minimum stage should be 0.5"

Expand Down
18 changes: 9 additions & 9 deletions autotest/test_chf_dis_fdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,22 @@ def check_grb_disv1d(fpth):
assert grb.xorigin == xorigin, "xorigin in grb file is not correct"
assert grb.yorigin == yorigin, "yorigin in grb file is not correct"
assert grb.angrot == angrot, "angrot in grb file is not correct"
assert np.allclose(
grb.bot.reshape((nodes,)), np.zeros((nodes,))
), "grb botm not correct"
assert np.allclose(grb.bot.reshape((nodes,)), np.zeros((nodes,))), (
"grb botm not correct"
)
cellx = np.array([0.0, 2 * dx]) # node centers pushed all the way to left and right
celly = np.zeros(nreach)
assert np.allclose(grb._datadict["CELLX"], cellx.flatten()), "cellx is not right"
assert np.allclose(grb._datadict["CELLY"], celly.flatten()), "celly is not right"
assert grb._datadict["IAVERT"].shape[0] == nodes + 1, "iavert size not right"
assert (
grb._datadict["IAVERT"][-1] - 1 == grb._datadict["JAVERT"].shape[0]
), "javert size not right"
assert grb._datadict["IAVERT"][-1] - 1 == grb._datadict["JAVERT"].shape[0], (
"javert size not right"
)
assert grb.ia.shape[0] == grb.ncells + 1, "ia in grb file is not correct size"
assert grb.ja.shape[0] == grb.nja, "ja in grb file is not correct size"
assert np.allclose(
grb.idomain.reshape((nodes,)), idomain.reshape((nodes,))
), "grb idomain not correct"
assert np.allclose(grb.idomain.reshape((nodes,)), idomain.reshape((nodes,))), (
"grb idomain not correct"
)


def check_output(idx, test):
Expand Down
48 changes: 24 additions & 24 deletions autotest/test_gwe_drycell_cnd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ def check_output(idx, test):

# Check heads satisfy problem set up (i.e., all of row 2 is dry)
hdsr1 = hds[0, 0, 0, :]
assert np.all(
hdsr1 < bot_r2
), "heads in row 1 should be below bottom elevation of row 2"
assert np.all(hdsr1 < bot_r2), (
"heads in row 1 should be below bottom elevation of row 2"
)
assert np.all(hds[0, 0, 1, :] < 0), "row 2 is not dry"

# Starting temperatures after steady flow period should be 4.0 degrees
Expand All @@ -575,39 +575,39 @@ def check_output(idx, test):
"Steady state temperatures not as expected",
)
# Same with concentrations in non-dry cells
assert np.all(
np.isclose(conc1[0, :, 0], strt_conc[:, 0])
), "Steady state concentrations not as expected"
assert np.all(np.isclose(conc1[0, :, 0], strt_conc[:, 0])), (
"Steady state concentrations not as expected"
)
# Unlike GWE, GWT will not keep dry cells active and output should reflect this
assert np.all(
conc1[:, :, 1, :] < 0
), "Concentrations should be set to 'inactive' (-1.e+30) in row 2"
assert np.all(conc1[:, :, 1, :] < 0), (
"Concentrations should be set to 'inactive' (-1.e+30) in row 2"
)

# Starting in the transient stress period, the water entering in the
# 'through' row is warmed to 30.0 C. First check that this is the case
assert np.all(
temp1[-1] > temp1[0]
), "Transient period temperature increase does not appear to have kicked in"
assert np.all(temp1[-1] > temp1[0]), (
"Transient period temperature increase does not appear to have kicked in"
)
# Dry cell temperatures are only warmed through conduction with neighboring
# 'through' cells and shouldn't be as warm as wet cells at the end of the
# warming period
assert np.all(
temp1[-1, :, 0] > temp1[-1, 0, 1]
), "Cells with water should be warmer than dry cells"
assert np.all(temp1[-1, :, 0] > temp1[-1, 0, 1]), (
"Cells with water should be warmer than dry cells"
)

# None of the cells should reach the temperature of the incoming water
# during the simulation period owing to the thermal bleeding that occurs
# to the adjacent dry cells.
assert np.all(
temp1[-1] < ghb_temp_warmup
), "Cells should not reach the temperature of the incoming water"
assert np.all(temp1[-1] < ghb_temp_warmup), (
"Cells should not reach the temperature of the incoming water"
)

# An increasing amount of thermal bleeding should occur moving in the
# direction of flow since the thickness of the dry cells increases in the
# downstream direction
assert np.all(
np.diff(temp1[-1, :, 0, :-1]) < 0
), "Temperature change in the downstream direction should be negative"
assert np.all(np.diff(temp1[-1, :, 0, :-1]) < 0), (
"Temperature change in the downstream direction should be negative"
)
assert isMonotonic(np.diff(temp1[-1, :, 0, :-1])), (
"A monotonic increase in the amount of heat lost to neighboring dry "
"cells is expected"
Expand Down Expand Up @@ -640,9 +640,9 @@ def check_output(idx, test):
# in the dry cell should remain inactive (i.e., no "molecular diffusion")
# and greater than their GWE counterpart temperatures since there is
# no "retardation" of concentration (temperature) owing to conduction
assert np.all(
conc1[:, :, 1, :] < 0
), "The dry cells should never have a non-inactive concentration value"
assert np.all(conc1[:, :, 1, :] < 0), (
"The dry cells should never have a non-inactive concentration value"
)


# - No need to change any code below
Expand Down
3 changes: 1 addition & 2 deletions autotest/test_gwe_esl02.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ def check_output(idx, test):
# Energy source loading was crafted such that each cell in
# the simulation would rise by 1 degree at the end of the simulation.
msg0 = (
"Grid cell temperatures do not reflect the expected difference"
"in stress period "
"Grid cell temperatures do not reflect the expected differencein stress period "
)
answer = ncol[idx]
assert np.isclose(np.sum(temps[-1]), answer), msg0 + str(idx)
Expand Down
12 changes: 6 additions & 6 deletions autotest/test_gwe_esl_analyt_sln.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ def check_output(idx, test, ener_input):
analytical_temps.append(T)

analytical_temps = np.array(analytical_temps)
assert np.allclose(
analytical_temps, sim_temps[sp, 0, 0, :], atol=0.005
), "simulated solution is whacked"
assert np.allclose(analytical_temps, sim_temps[sp, 0, 0, :], atol=0.005), (
"simulated solution is whacked"
)
# plt.plot(cell_centroids, analytical_temps, "r-", label="Analytical Solution") # noqa
# plt.plot(cell_centroids, sim_temps[sp, 0, 0, :], "b--", label="GWE")
# plt.axhline(0.0, color='black')
Expand Down Expand Up @@ -530,9 +530,9 @@ def check_output(idx, test, ener_input):
else:
atol = 0.47

assert np.allclose(
analytical_temps, sim_temps[sp, 0, 0, :], atol=atol
), "simulated solution is whacked"
assert np.allclose(analytical_temps, sim_temps[sp, 0, 0, :], atol=atol), (
"simulated solution is whacked"
)

# plt.plot(cell_centroids, analytical_temps, "r-", label="Analytical Solution") # noqa
# plt.plot(cell_centroids, sim_temps[sp, 0, 0, :], "b--", label="GWE")
Expand Down
9 changes: 4 additions & 5 deletions autotest/test_gwe_lke_conduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ def check_output(idx, test):

# Retrieve budget
T_in, T_out, in_bud_lst, out_bud_lst = get_bud(fname, srchStr)
assert np.isclose(
T_in, T_out, atol=0.1
), "There is a heat budget discrepancy where there shouldn't be"
assert np.isclose(T_in, T_out, atol=0.1), (
"There is a heat budget discrepancy where there shouldn't be"
)

msg1 = "Budget item 'GWF' should be 0.0 for this scenario"
msg2 = (
Expand All @@ -686,8 +686,7 @@ def check_output(idx, test):
)
msg4 = "There should be a warming trend in the groundwater adjacent to the lake"
msg5 = (
"Budget item 'GWF' should reflect heat entering the lake "
"(via gw/sw exchange)"
"Budget item 'GWF' should reflect heat entering the lake (via gw/sw exchange)"
)
msg6 = "Budget item 'GWF' should reflect heat exiting the lake (via gw/sw exchange)"

Expand Down
6 changes: 3 additions & 3 deletions autotest/test_gwe_mwe_conduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ def check_output(idx, test):
"MWE-1 BUDGET FOR ENTIRE MODEL AT END OF TIME STEP 1, STRESS PERIOD 1"
)
T_in, T_out, in_bud_lst, out_bud_lst = get_bud(fname, srchStr)
assert np.isclose(
T_in, T_out, atol=0.1
), "There is a heat budget discrepancy where there shouldn't be"
assert np.isclose(T_in, T_out, atol=0.1), (
"There is a heat budget discrepancy where there shouldn't be"
)

msg1 = "Conductive heat exchanges calculated explicitly and by MF6 do not match"
msg2 = (
Expand Down
12 changes: 6 additions & 6 deletions autotest/test_gwe_split_analyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ def check_output(idx, test):
analytical_temps.append(T)

analytical_temps = np.array(analytical_temps)
assert np.allclose(
analytical_temps, sim_temps[sp, 0, 0, :], atol=0.005
), "simulated solution is whacked"
assert np.allclose(analytical_temps, sim_temps[sp, 0, 0, :], atol=0.005), (
"simulated solution is whacked"
)
# plt.plot(cell_centroids, analytical_temps, "r-", label="Analytical Solution") # noqa
# plt.plot(cell_centroids, sim_temps[sp, 0, 0, :], "b--", label="GWE")
# plt.axhline(0.0, color='black')
Expand Down Expand Up @@ -605,9 +605,9 @@ def check_output(idx, test):
else:
atol = 0.47

assert np.allclose(
analytical_temps, sim_temps[sp, 0, 0, :], atol=atol
), "simulated solution isn't matching the analytical solution"
assert np.allclose(analytical_temps, sim_temps[sp, 0, 0, :], atol=atol), (
"simulated solution isn't matching the analytical solution"
)


# - No need to change any code below
Expand Down
18 changes: 9 additions & 9 deletions autotest/test_gwe_uze00.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,29 +500,29 @@ def check_output(idx, test):
"falling outside established bounds on day 10"
)
assert np.max(analytical_sln[10, :37] - temps[10, 0, 0, :37]) <= 0.15993441016, msg2
assert (
np.min(analytical_sln[10, :37] - temps[10, 0, 0, :37]) >= -0.22298707253
), msg2
assert np.min(analytical_sln[10, :37] - temps[10, 0, 0, :37]) >= -0.22298707253, (
msg2
)

# Ensure that the differences on day 50 fall within established bounds
msg3 = (
"Simulated fits to analytical solution are "
"falling outside established bounds on day 50"
)
assert np.max(analytical_sln[50, :82] - temps[50, 0, 0, :82]) <= 0.09327747258, msg3
assert (
np.min(analytical_sln[50, :82] - temps[50, 0, 0, :82]) >= -0.21182907402
), msg3
assert np.min(analytical_sln[50, :82] - temps[50, 0, 0, :82]) >= -0.21182907402, (
msg3
)

# Ensure that the differences on day 50 fall within established bounds
msg3 = (
"Simulated fits to analytical solution are "
"falling outside established bounds on day 50"
)
assert np.max(analytical_sln[50, :82] - temps[50, 0, 0, :82]) <= 0.09327747258, msg3
assert (
np.min(analytical_sln[50, :82] - temps[50, 0, 0, :82]) >= -0.21182907402
), msg3
assert np.min(analytical_sln[50, :82] - temps[50, 0, 0, :82]) >= -0.21182907402, (
msg3
)

# Ensure that the differences on day 100 fall within established bounds
msg4 = (
Expand Down
6 changes: 2 additions & 4 deletions autotest/test_gwe_uze_auxmult.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def run_single_sim(dir, exe):
sim = build_single_sim(idx, dir, exe)
sim.write_simulation()
success, buff = sim.run_simulation(silent=False)
errmsg = f"simulation should terminate with error message, but " f"did not.\n{buff}"
errmsg = f"simulation should terminate with error message, but did not.\n{buff}"
assert not success, errmsg


Expand Down Expand Up @@ -460,9 +460,7 @@ def run_separate_sims(dir, exe):
sim = build_gwe_sim_only(idx, dir, exe)
sim.write_simulation()
success, buff = sim.run_simulation(silent=False)
errmsg = (
f"GWE simulation should terminate with error message, but " f"did not.\n{buff}"
)
errmsg = f"GWE simulation should terminate with error message, but did not.\n{buff}"
assert not success, errmsg


Expand Down
6 changes: 3 additions & 3 deletions autotest/test_gwegwe_exchng_with_comp2gwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ def check_output(idx, test):
models = []
for mname in mf6_sim.model_names:
models.append(mf6_sim.get_model(mname))
assert (
len(models) == 6
), "Unexpected number of models encountered while loading simulation"
assert len(models) == 6, (
"Unexpected number of models encountered while loading simulation"
)

if plotModel:
# Create figure for scenario
Expand Down
Loading

0 comments on commit 7fcdc3c

Please sign in to comment.