Skip to content

Commit

Permalink
chore: reformat multi-line statements (#2379)
Browse files Browse the repository at this point in the history
Refactor some multi-line statements. This was mostly automated by temporarily toggling this control in pyproject.toml:

[tool.ruff.format]
skip-magic-trailing-comma = true

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. Class constructors or instantiations of some classes with many parameters are kept as multi-line.

Note that while there are over 2300 fewer lines with this changeset, there are no functional changes.
  • Loading branch information
mwtoews authored Nov 25, 2024
1 parent 4c1bf6c commit 080b965
Show file tree
Hide file tree
Showing 157 changed files with 619 additions and 3,000 deletions.
51 changes: 5 additions & 46 deletions .docs/Notebooks/export_vtk_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,7 @@

## add recharge to the VTK object
recharge = ml.rch.rech.transient_2ds
vtkobj.add_transient_array(
recharge,
"recharge",
masked_values=[
0,
],
)
vtkobj.add_transient_array(recharge, "recharge", masked_values=[0])

## write vtk files
vtkobj.write(output_dir / "tr_array_example" / "recharge.vtu")
Expand All @@ -242,12 +236,7 @@

## add well fluxes to the VTK object
spd = ml.wel.stress_period_data
vtkobj.add_transient_list(
spd,
masked_values=[
0,
],
)
vtkobj.add_transient_list(spd, masked_values=[0])

## write vtk files
vtkobj.write(output_dir / "tr_list_example" / "wel_flux.vtu")
Expand Down Expand Up @@ -412,53 +401,23 @@ def run_vertex_grid_example(ws):
xmax = 12 * delr
ymin = 8 * delc
ymax = 13 * delc
rfpoly = [
[
[
(xmin, ymin),
(xmax, ymin),
(xmax, ymax),
(xmin, ymax),
(xmin, ymin),
]
]
]
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
g.add_refinement_features(rfpoly, "polygon", 1, range(nlay))

rf1shp = os.path.join(gridgen_ws, "rf1")
xmin = 8 * delr
xmax = 11 * delr
ymin = 9 * delc
ymax = 12 * delc
rfpoly = [
[
[
(xmin, ymin),
(xmax, ymin),
(xmax, ymax),
(xmin, ymax),
(xmin, ymin),
]
]
]
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
g.add_refinement_features(rfpoly, "polygon", 2, range(nlay))

rf2shp = os.path.join(gridgen_ws, "rf2")
xmin = 9 * delr
xmax = 10 * delr
ymin = 10 * delc
ymax = 11 * delc
rfpoly = [
[
[
(xmin, ymin),
(xmax, ymin),
(xmax, ymax),
(xmin, ymax),
(xmin, ymin),
]
]
]
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
g.add_refinement_features(rfpoly, "polygon", 3, range(nlay))

g.build(verbose=False)
Expand Down
6 changes: 1 addition & 5 deletions .docs/Notebooks/get_transmissivities_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@
plt.plot(heads[0], label="piezometric surface", color="b", linestyle=":")
for iw in range(len(sctop)):
ax.fill_between(
[iw - 0.25, iw + 0.25],
scbot[iw],
sctop[iw],
facecolor="None",
edgecolor="k",
[iw - 0.25, iw + 0.25], scbot[iw], sctop[iw], facecolor="None", edgecolor="k"
)
ax.legend(loc=2)

Expand Down
25 changes: 3 additions & 22 deletions .docs/Notebooks/grid_intersection_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@
import matplotlib.pyplot as plt
import numpy as np
import shapely
from shapely.geometry import (
LineString,
MultiLineString,
MultiPoint,
Point,
Polygon,
)
from shapely.geometry import LineString, MultiLineString, MultiPoint, Point, Polygon

import flopy
import flopy.discretization as fgrid
Expand Down Expand Up @@ -110,15 +104,7 @@
# Polygon to intersect with:

p = Polygon(
shell=[
(15, 15),
(20, 50),
(35, 80.0),
(80, 50),
(80, 40),
(40, 5),
(15, 12),
],
shell=[(15, 15), (20, 50), (35, 80.0), (80, 50), (80, 40), (40, 5), (15, 12)],
holes=[[(25, 25), (25, 45), (45, 45), (45, 25)]],
)

Expand Down Expand Up @@ -261,12 +247,7 @@
# MultiPoint to intersect with

mp = MultiPoint(
points=[
Point(50.0, 0.0),
Point(45.0, 45.0),
Point(10.0, 10.0),
Point(150.0, 100.0),
]
points=[Point(50.0, 0.0), Point(45.0, 45.0), Point(10.0, 10.0), Point(150.0, 100.0)]
)

# For points and linestrings there is a keyword argument `return_all_intersections` which will return multiple intersection results for points or (parts of) linestrings on cell boundaries. As an example, the difference is shown with the MultiPoint intersection. Note the number of red "+" symbols indicating the centroids of intersected cells, in the bottom left case, there are 4 results because the point lies exactly on the intersection between 4 grid cells.
Expand Down
113 changes: 15 additions & 98 deletions .docs/Notebooks/groundwater2023_watershed_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,7 @@ def set_idomain(grid, boundary):
pmv = flopy.plot.PlotMapView(modelgrid=struct_grid)
ax.set_aspect("equal")
pmv.plot_array(top_sg)
pmv.plot_array(
intersection_sg,
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
)
pmv.plot_array(intersection_sg, masked_values=[0], alpha=0.2, cmap="Reds_r")
pmv.plot_grid(lw=0.25, color="0.5")
cg = pmv.contour_array(top_sg, levels=levels, linewidths=0.3, colors="0.75")
pmv.plot_inactive()
Expand Down Expand Up @@ -314,14 +307,7 @@ def set_idomain(grid, boundary):
pmv = flopy.plot.PlotMapView(modelgrid=struct_vrc_grid)
ax.set_aspect("equal")
pmv.plot_array(top_sg_vrc)
pmv.plot_array(
intersection_sg_vrc,
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
)
pmv.plot_array(intersection_sg_vrc, masked_values=[0], alpha=0.2, cmap="Reds_r")
cg = pmv.contour_array(top_sg_vrc, levels=levels, linewidths=0.3, colors="0.75")
pmv.plot_inactive()

Expand Down Expand Up @@ -437,14 +423,7 @@ def set_idomain(grid, boundary):
pmv = flopy.plot.PlotMapView(modelgrid=struct_gridp, extent=extent)
pmv.plot_inactive()
pmv.plot_array(top_ngp, vmin=vmin, vmax=vmax)
pmv.plot_array(
intersection_nested_grid[0],
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
)
pmv.plot_array(intersection_nested_grid[0], masked_values=[0], alpha=0.2, cmap="Reds_r")
cgp = pmv.contour_array(top_ngp, levels=levels, linewidths=0.3, colors="0.75")
pmv.plot_inactive(zorder=100)
ax.set_aspect("equal")
Expand All @@ -453,12 +432,7 @@ def set_idomain(grid, boundary):
# pmvc.plot_grid()
pmvc.plot_array(top_ngc, vmin=vmin, vmax=vmax)
pmvc.plot_array(
intersection_nested_grid[1],
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
intersection_nested_grid[1], masked_values=[0], alpha=0.2, cmap="Reds_r"
)
cgc = pmvc.contour_array(top_ngc, levels=levels, linewidths=0.3, colors="0.75")

Expand Down Expand Up @@ -532,14 +506,7 @@ def set_idomain(grid, boundary):
ax = fig.add_subplot()
pmv = flopy.plot.PlotMapView(modelgrid=quadtree_grid)
pmv.plot_array(top_qg, ec="0.75")
pmv.plot_array(
intersection_qg,
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
)
pmv.plot_array(intersection_qg, masked_values=[0], alpha=0.2, cmap="Reds_r")
cg = pmv.contour_array(top_qg, levels=levels, linewidths=0.3, colors="white")
pmv.plot_inactive(zorder=100)
ax.set_aspect("equal")
Expand Down Expand Up @@ -615,14 +582,7 @@ def set_idomain(grid, boundary):
pmv = flopy.plot.PlotMapView(modelgrid=triangular_grid)

pmv.plot_array(top_tg, ec="0.75")
pmv.plot_array(
intersection_tg,
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
)
pmv.plot_array(intersection_tg, masked_values=[0], alpha=0.2, cmap="Reds_r")
cg = pmv.contour_array(top_tg, levels=levels, linewidths=0.3, colors="white")
ax.clabel(cg, cg.levels, inline=True, fmt="%1.0f", fontsize=10)

Expand Down Expand Up @@ -670,14 +630,7 @@ def set_idomain(grid, boundary):
pmv = flopy.plot.PlotMapView(modelgrid=voronoi_grid)
ax.set_aspect("equal")
pmv.plot_array(top_vg)
pmv.plot_array(
intersection_vg,
masked_values=[
0,
],
alpha=0.2,
cmap="Reds_r",
)
pmv.plot_array(intersection_vg, masked_values=[0], alpha=0.2, cmap="Reds_r")
pmv.plot_inactive()
ax.plot(bp[:, 0], bp[:, 1], "k-")
for sg in sgs:
Expand Down Expand Up @@ -789,29 +742,10 @@ def set_idomain(grid, boundary):
ax.set_ylim(0, 1)
ax.set_axis_off()

ax.axhline(
xy0[0],
color="black",
lw=2,
label="Basin boundary",
)
ax.axhline(
xy0[0],
**river_dict,
label="River",
)
ax.axhline(
xy0[0],
color=contour_color,
lw=0.5,
ls="--",
label="Elevation contour",
)
ax.axhline(
xy0[0],
label="Grid refinement area",
**refinement_dict,
)
ax.axhline(xy0[0], color="black", lw=2, label="Basin boundary")
ax.axhline(xy0[0], **river_dict, label="River")
ax.axhline(xy0[0], color=contour_color, lw=0.5, ls="--", label="Elevation contour")
ax.axhline(xy0[0], label="Grid refinement area", **refinement_dict)
ax.axhline(
xy0[0],
marker="s",
Expand Down Expand Up @@ -844,23 +778,10 @@ def set_idomain(grid, boundary):
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_axis_off()
cax = ax.inset_axes(
cbar_axis,
)
cax = ax.inset_axes(cbar_axis)
# cax.set_axisbelow(False)
cbar = plt.colorbar(
v,
orientation="vertical",
cax=cax,
ticks=[25, 50, 75, 100],
)
cbar.ax.tick_params(
labelsize=5,
labelcolor="black",
color="black",
length=9,
pad=2,
)
cbar = plt.colorbar(v, orientation="vertical", cax=cax, ticks=[25, 50, 75, 100])
cbar.ax.tick_params(labelsize=5, labelcolor="black", color="black", length=9, pad=2)
cbar.ax.set_title("Elevation (m)", pad=2.5, loc="center", fontdict=font_dict)
# -

Expand Down Expand Up @@ -971,11 +892,7 @@ def set_idomain(grid, boundary):
ax.set_axis_off()

ax.axhline(xy0[0], **river_dict, label="River")
ax.axhline(
xy0[0],
label="Grid refinement area",
**refinement_dict,
)
ax.axhline(xy0[0], label="Grid refinement area", **refinement_dict)
ax.axhline(
xy0[0],
marker="s",
Expand Down
18 changes: 3 additions & 15 deletions .docs/Notebooks/groundwater_paper_uspb_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
os.makedirs(ws)

fn = os.path.join(
"..",
"groundwater_paper",
"uspb",
"results",
"USPB_capture_fraction_04_01.dat",
"..", "groundwater_paper", "uspb", "results", "USPB_capture_fraction_04_01.dat"
)
cf = np.loadtxt(fn)
print(cf.shape)
Expand Down Expand Up @@ -86,11 +82,7 @@
label="Maximum active model extent",
)
plt.plot(
[-10000, 0],
[-10000, 0],
color="purple",
lw=0.75,
label="STR reaches (all layers)",
[-10000, 0], [-10000, 0], color="purple", lw=0.75, label="STR reaches (all layers)"
)
leg = plt.legend(loc="upper left", numpoints=1, prop={"size": 6})
leg.draw_frame(False)
Expand Down Expand Up @@ -200,11 +192,7 @@
# -

fn = os.path.join(
"..",
"groundwater_paper",
"uspb",
"results",
"USPB_capture_fraction_04_10.dat",
"..", "groundwater_paper", "uspb", "results", "USPB_capture_fraction_04_10.dat"
)
cf = np.loadtxt(fn)
cf2 = scipy.ndimage.zoom(cf, 4, order=0)
Expand Down
5 changes: 1 addition & 4 deletions .docs/Notebooks/load_swr_binary_data_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@
stage = np.extract(iprof, s["stage"])
xs = flopy.plot.PlotCrossSection(model=ml, line={"Row": 0})
xs.plot_fill_between(
stage.reshape(1, 1, 12),
colors=["none", "blue"],
ax=ax,
edgecolors="none",
stage.reshape(1, 1, 12), colors=["none", "blue"], ax=ax, edgecolors="none"
)
linecollection = xs.plot_grid(ax=ax, zorder=10)
ax.fill_between(
Expand Down
Loading

0 comments on commit 080b965

Please sign in to comment.