Skip to content

Commit

Permalink
chore: reformat multi-line statements (#2070)
Browse files Browse the repository at this point in the history
Refactor some multi-line statements. This was mostly automated by temporarily toggling skip-magic-trailing-comma = true in ruff.toml, then selecting some commits that condense multi-line statements to single, while rejecting other statements that are better represented over multiple lines. There was no exact rule-of-thumb for the process, except to try and maintain the same style in surrounding code blocks.

Note that while there are fewer lines, there are no functional changes.
  • Loading branch information
mwtoews authored Nov 25, 2024
1 parent 387cd5d commit cc7f930
Show file tree
Hide file tree
Showing 139 changed files with 331 additions and 1,829 deletions.
5 changes: 1 addition & 4 deletions .hpc/sstat_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ def _run_command(
+ "by specifying the format argument "
+ "(--format=JobID,AveCPU,AveRSS,MaxRSS,...)."
)
parser = argparse.ArgumentParser(
"sstat_poll",
description=description,
)
parser = argparse.ArgumentParser("sstat_poll", description=description)
parser.add_argument("jobid", help="SLURM JobID", type=int)
parser.add_argument(
"--format",
Expand Down
36 changes: 4 additions & 32 deletions autotest/cross_section_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,7 @@ def get_depths(
depths = np.zeros(flows.shape, dtype=float)
for idx, q in enumerate(flows):
depths[idx] = qtodepth(
x,
h,
q,
roughness=roughness,
slope=slope,
conv=conv,
dd=dd,
verbose=False,
x, h, q, roughness=roughness, slope=slope, conv=conv, dd=dd, verbose=False
)

return depths
Expand All @@ -303,42 +296,21 @@ def qtodepth(
verbose=False,
):
h0 = 0.0
q0 = manningsq(
x,
h,
h0,
roughness=roughness,
slope=slope,
conv=conv,
)
q0 = manningsq(x, h, h0, roughness=roughness, slope=slope, conv=conv)
r = q0 - q

iter = 0
if verbose:
print(f"iteration {iter:>2d} - residual={r}")
while abs(r) > 1e-12:
q1 = manningsq(
x,
h,
h0 + dd,
roughness=roughness,
slope=slope,
conv=conv,
)
q1 = manningsq(x, h, h0 + dd, roughness=roughness, slope=slope, conv=conv)
dq = q1 - q0
if dq != 0.0:
derv = dd / (q1 - q0)
else:
derv = 0.0
h0 -= derv * r
q0 = manningsq(
x,
h,
h0,
roughness=roughness,
slope=slope,
conv=conv,
)
q0 = manningsq(x, h, h0, roughness=roughness, slope=slope, conv=conv)
r = q0 - q

iter += 1
Expand Down
5 changes: 1 addition & 4 deletions autotest/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,7 @@ def _compare_heads(
if len(exfiles) > 0:
exfile = exfiles[i]
if exfile is not None:
print(
f"Exclusion file {i + 1}",
os.path.basename(exfile),
)
print(f"Exclusion file {i + 1}", os.path.basename(exfile))

# make comparison
success = compare_heads(
Expand Down
4 changes: 1 addition & 3 deletions autotest/get_exes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def test_rebuild_release(rebuilt_bin_path: Path):
# download the release
download_path = Path(td)
download_and_unzip(
asset["browser_download_url"],
path=download_path,
verbose=True,
asset["browser_download_url"], path=download_path, verbose=True
)

# update IDEVELOPMODE
Expand Down
15 changes: 3 additions & 12 deletions autotest/test_chf_dfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def build_models(idx, test):
idcxs=0,
)

sto = flopy.mf6.ModflowChfsto(
chf,
save_flows=True,
)
sto = flopy.mf6.ModflowChfsto(chf, save_flows=True)

ic = flopy.mf6.ModflowChfic(chf, strt=1.0)

Expand Down Expand Up @@ -116,19 +113,13 @@ def build_models(idx, test):

# Save to external binary file or into flw package depending on binary keyword
binary = True
flw_list = [
(1, 100),
] # one-based cell numbers here
flw_list = [(1, 100)] # one-based cell numbers here
maxbound = len(flw_list)
if binary:
ra = np.array(flw_list, dtype=[("irch", "<i4"), ("q", "<f8")])
ra.tofile(os.path.join(sim_ws, "flw0.bin"))
flw_spd = {
0: {
"filename": "flw0.bin",
"binary": True,
"data": None,
},
0: {"filename": "flw0.bin", "binary": True, "data": None},
}
else:
flw_spd = {0: flw_list}
Expand Down
13 changes: 2 additions & 11 deletions autotest/test_chf_dfw_beg2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,7 @@ def make_plot(test, mfsim):
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(1, 1, 1)
ax.plot(times / 60.0 / 60.0, qinflow, "r-", label="Inflow")
ax.plot(
times / 60.0 / 60.0,
df_hecras["Flow Flow (CMS)"],
"b-",
label="HEC-RAS",
)
ax.plot(times / 60.0 / 60.0, df_hecras["Flow Flow (CMS)"], "b-", label="HEC-RAS")
x = df_mfswr["TOTTIME"] - 86400.0
x = x / 60.0 / 60.0
ax.plot(x, -df_mfswr["QCRFLOW"], "go:", mfc="none", label="MODFLOW-SWR")
Expand All @@ -237,11 +232,7 @@ def make_plot(test, mfsim):
ax = fig.add_subplot(1, 1, 1)
ax.plot(times / 60.0 / 60.0, stage[:, 0, 0, 0], "r-", label="Upstream")
ax.plot(
times / 60.0 / 60.0,
stage[:, 0, 0, -1],
"bo",
mfc="none",
label="Downstream",
times / 60.0 / 60.0, stage[:, 0, 0, -1], "bo", mfc="none", label="Downstream"
)
# ax.set_xlim(0, 24.)
# ax.set_ylim(19, 26)
Expand Down
10 changes: 2 additions & 8 deletions autotest/test_chf_dfw_bowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,9 @@ def build_models(idx, test):
stress_period_data=spd,
)

sto = flopy.mf6.ModflowChfsto(
chf,
save_flows=True,
)
sto = flopy.mf6.ModflowChfsto(chf, save_flows=True)

ic = flopy.mf6.ModflowChfic(
chf,
strt=strt,
)
ic = flopy.mf6.ModflowChfic(chf, strt=strt)

xfraction = [0.0, 0.0, 1.0, 1.0]
height = [100.0, 0.0, 0.0, 100.0]
Expand Down
26 changes: 2 additions & 24 deletions autotest/test_chf_dfw_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,7 @@ def build_models(idx, test):
0.0,
]

idcxs = [
0,
0,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
2,
2,
2,
2,
2,
]
idcxs = [0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2]

# time, reach1, reach5 (cms)
reach_inflow = [
Expand Down Expand Up @@ -245,10 +226,7 @@ def build_models(idx, test):
idcxs=idcxs,
)

sto = flopy.mf6.ModflowChfsto(
chf,
save_flows=True,
)
sto = flopy.mf6.ModflowChfsto(chf, save_flows=True)

xfraction = (
[0.0, 10.0, 20.0, 30.0] + [0, 20.0, 40.0, 60.0] + [0.0, 15.0, 30.0, 45.0]
Expand Down
5 changes: 1 addition & 4 deletions autotest/test_chf_dfw_swrt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ def build_models(idx, test):
idcxs=None,
)

sto = flopy.mf6.ModflowChfsto(
chf,
save_flows=True,
)
sto = flopy.mf6.ModflowChfsto(chf, save_flows=True)

ic = flopy.mf6.ModflowChfic(
chf,
Expand Down
10 changes: 2 additions & 8 deletions autotest/test_chf_dfw_swrt2b.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,9 @@ def build_models(idx, test):
idcxs=None,
)

sto = flopy.mf6.ModflowChfsto(
chf,
save_flows=True,
)
sto = flopy.mf6.ModflowChfsto(chf, save_flows=True)

ic = flopy.mf6.ModflowChfic(
chf,
strt=2.05,
)
ic = flopy.mf6.ModflowChfic(chf, strt=2.05)

# output control
oc = flopy.mf6.ModflowChfoc(
Expand Down
5 changes: 1 addition & 4 deletions autotest/test_chf_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ def check_grb_disv1d(fpth):
assert grb.grid_type == "DISV1D", "grb grid type not DISV1D"
assert grb.ncells == nodes, "grb ncells is incorrect"
assert grb._datadict["NCELLS"] == nodes, "grb nodes is incorrect"
assert grb.verts.shape == (
nodes + 1,
2,
), "vertices shape is incorrect"
assert grb.verts.shape == (nodes + 1, 2), "vertices shape is incorrect"
assert grb.nja == 14, "nja in grb file is not 14"
assert grb.xorigin == xorigin, "xorigin in grb file is not correct"
assert grb.yorigin == yorigin, "yorigin in grb file is not correct"
Expand Down
5 changes: 1 addition & 4 deletions autotest/test_chf_dis_fdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ def check_grb_disv1d(fpth):
assert grb.grid_type == "DISV1D", "grb grid type not DISV1D"
assert grb.ncells == nodes, "grb ncells is incorrect"
assert grb._datadict["NCELLS"] == nodes, "grb nodes is incorrect"
assert grb.verts.shape == (
nodes + 1,
2,
), "vertices shape is incorrect"
assert grb.verts.shape == (nodes + 1, 2), "vertices shape is incorrect"
assert grb.nja == 4, "nja in grb file is not 4"
assert grb.xorigin == xorigin, "xorigin in grb file is not correct"
assert grb.yorigin == yorigin, "yorigin in grb file is not correct"
Expand Down
9 changes: 2 additions & 7 deletions autotest/test_chf_gwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ def add_chf_model(sim):
idcxs=0,
)

sto = flopy.mf6.ModflowChfsto(
chf,
save_flows=True,
)
sto = flopy.mf6.ModflowChfsto(chf, save_flows=True)

ic = flopy.mf6.ModflowChfic(chf, strt=1.0)

Expand Down Expand Up @@ -143,9 +140,7 @@ def add_chf_model(sim):
],
)

flw_spd = [
(0, 100),
]
flw_spd = [(0, 100)]
maxbound = len(flw_spd)
flw = flopy.mf6.ModflowChfflw(
chf,
Expand Down
4 changes: 1 addition & 3 deletions autotest/test_gwe_drycell_cnd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ def add_gwf_model(sim, gwfname, newton=False):
# sfr file
connectiondata = [[0, -1], [1, 0]]

sfr_perioddata = [
[0, "inflow", 1.0],
]
sfr_perioddata = [[0, "inflow", 1.0]]

pname = "SFR-" + gwfname[-1]
sfr = flopy.mf6.ModflowGwfsfr(
Expand Down
4 changes: 1 addition & 3 deletions autotest/test_gwe_esl01.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ def build_models(idx, test):
# +1.0, +2.0, -1.0, and 0.0 degrees Celsius from stress period to stress
# period
esl_spd = {
0: [
[(0, 0, 0), Joules_added_for_1degC_rise],
],
0: [[(0, 0, 0), Joules_added_for_1degC_rise]],
1: [[(0, 0, 0), 2 * Joules_added_for_1degC_rise]],
2: [[(0, 0, 0), -1 * Joules_added_for_1degC_rise]],
3: [],
Expand Down
6 changes: 1 addition & 5 deletions autotest/test_gwe_lke_conduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ def trenddetector(list_of_index, array_of_data, order=1):
strt_lk_temp = [20.0, 20.0, 4.0]
lak_leakance = [0.0, 1.0, 1.0]
strt_lk_stg = [33.75, 33.75, 33.75]
lkbdthkcnd = [
0.0001,
0.0001,
0.0001,
] # Thickness to consider for feature/gw conduction
lkbdthkcnd = [0.0001, 0.0001, 0.0001] # Thickness to consider for feature/gw conduction

# Model units
length_units = "m"
Expand Down
35 changes: 6 additions & 29 deletions autotest/test_gwe_mve.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@
lhv = 2500.0
cps = 760.0
rhos = 1500.0
K_therm_strmbed = [
1.5,
1.75,
2.0,
] # Thermal conductivity of the streambed material ($W/m/C$)
# Thermal conductivity of the streambed material ($W/m/C$)
K_therm_strmbed = [1.5, 1.75, 2.0]
rbthcnd = 0.0001
prsity = sy
drn_depth = 2.0
Expand Down Expand Up @@ -292,20 +289,7 @@
if irno in [0, nrow - 1]:
ncon = 1
cellid = (0, irno, ncol - 1)
t = (
irno,
cellid,
rlen,
rwid,
rgrd,
rtp,
rbth,
rhk,
rman,
ncon,
ustrf,
ndv,
)
t = (irno, cellid, rlen, rwid, rgrd, rtp, rbth, rhk, rman, ncon, ustrf, ndv)
pak_data.append(t)

con_data = []
Expand Down Expand Up @@ -408,12 +392,7 @@ def build_mf6_model(idx, ws):
uzf_obs = {
f"{gwfname}.uzfobs": [
("uzf01_dpth=0.5", "water-content", "uzf01", 0.5),
(
"uzf01_dpth=1.5",
"water-content",
"uzf01",
1.5,
), # Relies on boundnames
("uzf01_dpth=1.5", "water-content", "uzf01", 1.5), # Relies on boundnames
("uzf01_dpth=2.5", "water-content", "uzf01", 2.5),
("uzf01_dpth=3.5", "water-content", "uzf01", 3.5),
("uzf01_dpth=4.49", "water-content", "uzf01", 4.49),
Expand Down Expand Up @@ -742,8 +721,7 @@ def check_output(idx, test):
itm[ct][-1], -1 * (finf0 - vks) + accum_runoff
), msg0
assert np.isclose(
itm_e[ct][-1],
(finf0 - vks) * rhow * cpw + accum_energy,
itm_e[ct][-1], (finf0 - vks) * rhow * cpw + accum_energy
), msg7
accum_runoff += -1 * (finf0 - vks)
accum_energy += (finf0 - vks) * rhow * cpw
Expand Down Expand Up @@ -791,8 +769,7 @@ def check_output(idx, test):
itm[ct][-1], -1 * (finf0 - vks) + accum_runoff
), msg0
assert np.isclose(
itm_e[ct][-1],
(finf0 - vks) * rhow * cpw + accum_energy,
itm_e[ct][-1], (finf0 - vks) * rhow * cpw + accum_energy
), msg7
accum_runoff += -1 * (finf0 - vks)
accum_energy += (finf0 - vks) * rhow * cpw
Expand Down
Loading

0 comments on commit cc7f930

Please sign in to comment.