Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reformat Python code with line length = 88 #2056

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions autotest/build_exes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def test_meson_build(bin_path):


if __name__ == "__main__":
parser = argparse.ArgumentParser(
"Rebuild local development version of MODFLOW 6"
)
parser = argparse.ArgumentParser("Rebuild local development version of MODFLOW 6")
parser.add_argument(
"-p", "--path", help="path to bin directory", default=top_bin_path
)
Expand Down
12 changes: 3 additions & 9 deletions autotest/common_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,7 @@ def get_regression_files(
for extension in extensions:
if file_name.lower().endswith(extension):
files0.append(fpth0)
fpth1 = os.path.join(
workspace, "mf6_regression", file_name
)
fpth1 = os.path.join(workspace, "mf6_regression", file_name)
files1.append(fpth1)
break
return files0, files1
Expand Down Expand Up @@ -579,9 +577,7 @@ def setup_model(namefile, dst, remove_existing=True, extrafiles=None):
print(f"{srcf} does not exist")


def setup_mf6(
src, dst, mfnamefile="mfsim.nam", extrafiles=None, remove_existing=True
):
def setup_mf6(src, dst, mfnamefile="mfsim.nam", extrafiles=None, remove_existing=True):
"""
Setup an MF6 simulation test, copying input files from the source
to the destination workspace.
Expand Down Expand Up @@ -664,9 +660,7 @@ def setup_mf6(
return mf6inp, mf6outp


def setup_mf6_comparison(
src, dst, cmp_exe="mf6", overwrite=True, verbose=False
):
def setup_mf6_comparison(src, dst, cmp_exe="mf6", overwrite=True, verbose=False):
"""Setup an output comparison for MODFLOW 6 simulation.

Parameters
Expand Down
4 changes: 1 addition & 3 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def pytest_addoption(parser):

def pytest_collection_modifyitems(config, items):
if not config.getoption("--parallel"):
skip_parallel = pytest.mark.skip(
reason="need --parallel option to run"
)
skip_parallel = pytest.mark.skip(reason="need --parallel option to run")
for item in items:
if "parallel" in item.keywords:
item.add_marker(skip_parallel)
Expand Down
9 changes: 2 additions & 7 deletions autotest/cross_section_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ def wetted_area(

# write to screen
if verbose:
print(
f"{idx}->{idx + 1} ({x0},{x1}) - "
f"perimeter={x1 - x0} - area={a}"
)
print(f"{idx}->{idx + 1} ({x0},{x1}) - perimeter={x1 - x0} - area={a}")

return area

Expand Down Expand Up @@ -199,9 +196,7 @@ def is_neighb_vert(x, h, idx):

# Assess left neighbor first
if idx > 0:
if (
cnt > 2
): # only x-sections w/ 3 or more pts may host a vertical side
if cnt > 2: # only x-sections w/ 3 or more pts may host a vertical side
idxm1 = idx - 1
if x[idxm1] == x[idx] and h[idxm1] != h[idx]:
leftvert = True
Expand Down
72 changes: 18 additions & 54 deletions autotest/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def run_parallel(workspace, target, ncpus) -> Tuple[bool, List[str]]:
if get_ostag() in ["win64"]:
mpiexec_cmd = ["mpiexec", "-np", str(ncpus), target, "-p"]
else:
mpiexec_cmd = (
["mpiexec"] + oversubscribed + ["-np", str(ncpus), target, "-p"]
)
mpiexec_cmd = ["mpiexec"] + oversubscribed + ["-np", str(ncpus), target, "-p"]

proc = Popen(mpiexec_cmd, stdout=PIPE, stderr=STDOUT, cwd=workspace)

Expand Down Expand Up @@ -145,19 +143,15 @@ def write_input(*sims, overwrite: bool = True, verbose: bool = True):
warn("Workspace is not empty, not writing input files")
return
if verbose:
print(
f"Writing mf6 simulation '{sim.name}' to: {sim.sim_path}"
)
print(f"Writing mf6 simulation '{sim.name}' to: {sim.sim_path}")
sim.write_simulation()
elif isinstance(sim, flopy.mbase.BaseModel):
workspace = Path(sim.model_ws)
if any(workspace.glob("*")) and not overwrite:
warn("Workspace is not empty, not writing input files")
return
if verbose:
print(
f"Writing {type(sim)} model '{sim.name}' to: {sim.model_ws}"
)
print(f"Writing {type(sim)} model '{sim.name}' to: {sim.model_ws}")
sim.write_input()
else:
raise ValueError(f"Unsupported simulation/model type: {type(sim)}")
Expand Down Expand Up @@ -316,9 +310,7 @@ def _compare_heads(
file1 = files1[i]
ext = os.path.splitext(file1)[1][1:].lower()
outfile = os.path.splitext(os.path.basename(file1))[0]
outfile = os.path.join(
self.workspace, outfile + "." + ext + ".cmp.out"
)
outfile = os.path.join(self.workspace, outfile + "." + ext + ".cmp.out")
file2 = None if files2 is None else files2[i]

# set exfile
Expand Down Expand Up @@ -356,9 +348,7 @@ def _compare_heads(
extension = "hds"
for i, (fpth0, fpth1) in enumerate(zip(files0, files1)):
outfile = os.path.splitext(os.path.basename(fpth0))[0]
outfile = os.path.join(
self.workspace, outfile + f".{extension}.cmp.out"
)
outfile = os.path.join(self.workspace, outfile + f".{extension}.cmp.out")
success = compare_heads(
None,
None,
Expand Down Expand Up @@ -388,9 +378,7 @@ def _compare_concentrations(self, extensions="ucn", htol=0.001) -> bool:
extension = "ucn"
for i, (fpth0, fpth1) in enumerate(zip(files0, files1)):
outfile = os.path.splitext(os.path.basename(fpth0))[0]
outfile = os.path.join(
self.workspace, outfile + f".{extension}.cmp.out"
)
outfile = os.path.join(self.workspace, outfile + f".{extension}.cmp.out")
success = compare_heads(
None,
None,
Expand Down Expand Up @@ -422,23 +410,17 @@ def _compare_budgets(self, extensions="cbc", rclose=0.001) -> bool:
f"{EXTTEXT[extension]} comparison {i + 1}",
f"{self.name} ({os.path.basename(fpth0)})",
)
success = self._compare_budget_files(
extension, fpth0, fpth1, rclose
)
success = self._compare_budget_files(extension, fpth0, fpth1, rclose)
if not success:
return False
return True

def _compare_budget_files(
self, extension, fpth0, fpth1, rclose=0.001
) -> bool:
def _compare_budget_files(self, extension, fpth0, fpth1, rclose=0.001) -> bool:
success = True
if os.stat(fpth0).st_size * os.stat(fpth0).st_size == 0:
return success, ""
outfile = os.path.splitext(os.path.basename(fpth0))[0]
outfile = os.path.join(
self.workspace, outfile + f".{extension}.cmp.out"
)
outfile = os.path.join(self.workspace, outfile + f".{extension}.cmp.out")
fcmp = open(outfile, "w")
fcmp.write("Performing CELL-BY-CELL to CELL-BY-CELL comparison\n")
fcmp.write(f"{fpth0}\n")
Expand Down Expand Up @@ -608,9 +590,7 @@ def _run_sim_or_model(
elif "mf6" in target.name:
# parallel test if configured
if self.parallel and ncpus > 1:
print(
f"Parallel test {self.name} on {self.ncpus} processes"
)
print(f"Parallel test {self.name} on {self.ncpus} processes")
try:
success, buff = run_parallel(workspace, target, ncpus)
except Exception:
Expand Down Expand Up @@ -641,9 +621,7 @@ def _run_sim_or_model(
try:
nf_ext = ".mpsim" if "mp7" in target.name else ".nam"
namefile = next(iter(workspace.glob(f"*{nf_ext}")), None)
assert (
namefile
), f"Control file with extension {nf_ext} not found"
assert namefile, f"Control file with extension {nf_ext} not found"
success, buff = flopy.run_model(
target, namefile, workspace, report=True
)
Expand All @@ -660,9 +638,7 @@ def _run_sim_or_model(

except Exception:
success = False
warn(
f"Unhandled error in comparison model {self.name}:\n{format_exc()}"
)
warn(f"Unhandled error in comparison model {self.name}:\n{format_exc()}")

return success, buff

Expand Down Expand Up @@ -701,21 +677,15 @@ def run(self):
else:
self.sims = [MFSimulation.load(sim_ws=self.workspace)]
self.buffs = [None]
assert (
len(self.xfail) == 1
), "Invalid xfail: expected a single boolean"
assert (
len(self.ncpus) == 1
), "Invalid ncpus: expected a single integer"
assert len(self.xfail) == 1, "Invalid xfail: expected a single boolean"
assert len(self.ncpus) == 1, "Invalid ncpus: expected a single integer"

# run models/simulations
for i, sim_or_model in enumerate(self.sims):
tgts = self.targets
workspace = get_workspace(sim_or_model)
exe_path = (
Path(sim_or_model.exe_name)
if sim_or_model.exe_name
else tgts["mf6"]
Path(sim_or_model.exe_name) if sim_or_model.exe_name else tgts["mf6"]
)
target = (
exe_path
Expand All @@ -724,9 +694,7 @@ def run(self):
)
xfail = self.xfail[i]
ncpus = self.ncpus[i]
success, buff = self._run_sim_or_model(
workspace, target, xfail, ncpus
)
success, buff = self._run_sim_or_model(workspace, target, xfail, ncpus)
self.buffs[i] = buff # store model output for assertions later
assert success, (
f"{'Simulation' if 'mf6' in str(target) else 'Model'} "
Expand All @@ -736,9 +704,7 @@ def run(self):
# setup and run comparison model(s), if enabled
if self.compare:
# get expected output files from main simulation
_, self.outp = get_mf6_files(
self.workspace / "mfsim.nam", self.verbose
)
_, self.outp = get_mf6_files(self.workspace / "mfsim.nam", self.verbose)

# try to autodetect comparison type if enabled
if self.compare == "auto":
Expand Down Expand Up @@ -774,9 +740,7 @@ def run(self):
workspace = self.workspace / self.compare
success, _ = self._run_sim_or_model(
workspace,
self.targets.get(
self.compare, self.targets["mf6"]
),
self.targets.get(self.compare, self.targets["mf6"]),
)
assert success, f"Comparison model failed: {workspace}"

Expand Down
16 changes: 4 additions & 12 deletions autotest/get_exes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ def test_rebuild_release(rebuilt_bin_path: Path):
print(f"Rebuilding and installing last release to: {rebuilt_bin_path}")
release = get_release(repository)
assets = release["assets"]
asset = next(
iter([a for a in assets if a["name"] == get_asset_name(a)]), None
)
asset = next(iter([a for a in assets if a["name"] == get_asset_name(a)]), None)
if not asset:
warn(
f"Couldn't find asset for OS {get_ostag()}, available assets:\n{assets}"
)
warn(f"Couldn't find asset for OS {get_ostag()}, available assets:\n{assets}")

with TemporaryDirectory() as td:
# download the release
Expand All @@ -59,9 +55,7 @@ def test_rebuild_release(rebuilt_bin_path: Path):
)

# update IDEVELOPMODE
source_files_path = (
download_path / asset["name"].replace(".zip", "") / "src"
)
source_files_path = download_path / asset["name"].replace(".zip", "") / "src"
version_file_path = source_files_path / "Utilities" / "version.f90"
with open(version_file_path) as f:
lines = f.read().splitlines()
Expand Down Expand Up @@ -89,9 +83,7 @@ def test_get_executables(downloaded_bin_path: Path):


if __name__ == "__main__":
parser = argparse.ArgumentParser(
"Get executables needed for MODFLOW 6 testing"
)
parser = argparse.ArgumentParser("Get executables needed for MODFLOW 6 testing")
parser.add_argument("-p", "--path", help="path to top-level bin directory")
args = parser.parse_args()
bin_path = Path(args.path).resolve() if args.path else top_bin_path
Expand Down
4 changes: 1 addition & 3 deletions autotest/test_chf_dfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def build_models(idx, test):
outer_dvclose=1.0e-7,
inner_dvclose=1.0e-8,
)
chf = flopy.mf6.ModflowChf(
sim, modelname=name, save_flows=True, print_flows=True
)
chf = flopy.mf6.ModflowChf(sim, modelname=name, save_flows=True, print_flows=True)

dx = 1000.0
nreach = 3
Expand Down
4 changes: 1 addition & 3 deletions autotest/test_chf_dfw_beg2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ def make_plot(test, mfsim):
x = df_mfswr["TOTTIME"] - 86400.0
x = x / 60.0 / 60.0
ax.plot(x, -df_mfswr["QCRFLOW"], "go:", mfc="none", label="MODFLOW-SWR")
ax.plot(
times / 60.0 / 60.0, qoutflow, "bo:", mfc="none", label="MODFLOW 6"
)
ax.plot(times / 60.0 / 60.0, qoutflow, "bo:", mfc="none", label="MODFLOW 6")
ax.set_xlim(0, 24.0)
ax.set_ylim(19, 26)
plt.xlabel("time, in hours")
Expand Down
5 changes: 1 addition & 4 deletions autotest/test_chf_dfw_bowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ def check_output(idx, test):
for v in stage_all[-1].flatten():
print(f"{v:18.8f},")

msg = (
"Simulated stage does not match with the answer "
"stored from a previous run."
)
msg = "Simulated stage does not match with the answer stored from a previous run."
assert np.allclose(stage_all[-1].flatten(), stage_answer, atol=1.0e-5), msg


Expand Down
22 changes: 5 additions & 17 deletions autotest/test_chf_dfw_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,10 @@ def build_models(idx, test):
)

xfraction = (
[0.0, 10.0, 20.0, 30.0]
+ [0, 20.0, 40.0, 60.0]
+ [0.0, 15.0, 30.0, 45.0]
)
height = (
[10.0, 0.0, 0.0, 10.0]
+ [20.0, 0.0, 0.0, 20.0]
+ [15.0, 0.0, 0.0, 15.0]
)
mannfraction = (
[1.0, 1.0, 1.0, 1.0] + [1.0, 1.0, 1.0, 1.0] + [1.0, 1.0, 1.0, 1.0]
[0.0, 10.0, 20.0, 30.0] + [0, 20.0, 40.0, 60.0] + [0.0, 15.0, 30.0, 45.0]
)
height = [10.0, 0.0, 0.0, 10.0] + [20.0, 0.0, 0.0, 20.0] + [15.0, 0.0, 0.0, 15.0]
mannfraction = [1.0, 1.0, 1.0, 1.0] + [1.0, 1.0, 1.0, 1.0] + [1.0, 1.0, 1.0, 1.0]

cxsdata = list(zip(xfraction, height, mannfraction))
cxs = flopy.mf6.ModflowChfcxs(
Expand Down Expand Up @@ -398,12 +390,8 @@ def make_plot(test):
lw=0.0,
label="MF6 Gauge 5",
)
ax.plot(
answer_flow["TOTIME"], answer_flow["FLOW45"], "b-", label="SWR Gauge 4"
)
ax.plot(
answer_flow["TOTIME"], answer_flow["FLOW56"], "g-", label="SWR Gauge 5"
)
ax.plot(answer_flow["TOTIME"], answer_flow["FLOW45"], "b-", label="SWR Gauge 4")
ax.plot(answer_flow["TOTIME"], answer_flow["FLOW56"], "g-", label="SWR Gauge 5")
# ax.plot(obsvals["time"], answer["STAGE0000000014"], marker="o", mfc="none", mec="k", lw=0., label="swr")
ax.set_xscale("log")
plt.xlabel("time, in seconds")
Expand Down
16 changes: 4 additions & 12 deletions autotest/test_chf_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,13 @@ def check_grb_disv1d(fpth):
), "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 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.ia.shape[0] == grb.ncells + 1
), "ia in grb file is not correct size"
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 corect size"
assert np.allclose(
grb.idomain.reshape((nodes,)), idomain.reshape((nodes,))
Expand Down
Loading
Loading