Skip to content

Commit 080b965

Browse files
authored
chore: reformat multi-line statements (#2379)
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.
1 parent 4c1bf6c commit 080b965

File tree

157 files changed

+619
-3000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+619
-3000
lines changed

.docs/Notebooks/export_vtk_tutorial.py

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,7 @@
216216

217217
## add recharge to the VTK object
218218
recharge = ml.rch.rech.transient_2ds
219-
vtkobj.add_transient_array(
220-
recharge,
221-
"recharge",
222-
masked_values=[
223-
0,
224-
],
225-
)
219+
vtkobj.add_transient_array(recharge, "recharge", masked_values=[0])
226220

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

243237
## add well fluxes to the VTK object
244238
spd = ml.wel.stress_period_data
245-
vtkobj.add_transient_list(
246-
spd,
247-
masked_values=[
248-
0,
249-
],
250-
)
239+
vtkobj.add_transient_list(spd, masked_values=[0])
251240

252241
## write vtk files
253242
vtkobj.write(output_dir / "tr_list_example" / "wel_flux.vtu")
@@ -412,53 +401,23 @@ def run_vertex_grid_example(ws):
412401
xmax = 12 * delr
413402
ymin = 8 * delc
414403
ymax = 13 * delc
415-
rfpoly = [
416-
[
417-
[
418-
(xmin, ymin),
419-
(xmax, ymin),
420-
(xmax, ymax),
421-
(xmin, ymax),
422-
(xmin, ymin),
423-
]
424-
]
425-
]
404+
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
426405
g.add_refinement_features(rfpoly, "polygon", 1, range(nlay))
427406

428407
rf1shp = os.path.join(gridgen_ws, "rf1")
429408
xmin = 8 * delr
430409
xmax = 11 * delr
431410
ymin = 9 * delc
432411
ymax = 12 * delc
433-
rfpoly = [
434-
[
435-
[
436-
(xmin, ymin),
437-
(xmax, ymin),
438-
(xmax, ymax),
439-
(xmin, ymax),
440-
(xmin, ymin),
441-
]
442-
]
443-
]
412+
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
444413
g.add_refinement_features(rfpoly, "polygon", 2, range(nlay))
445414

446415
rf2shp = os.path.join(gridgen_ws, "rf2")
447416
xmin = 9 * delr
448417
xmax = 10 * delr
449418
ymin = 10 * delc
450419
ymax = 11 * delc
451-
rfpoly = [
452-
[
453-
[
454-
(xmin, ymin),
455-
(xmax, ymin),
456-
(xmax, ymax),
457-
(xmin, ymax),
458-
(xmin, ymin),
459-
]
460-
]
461-
]
420+
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
462421
g.add_refinement_features(rfpoly, "polygon", 3, range(nlay))
463422

464423
g.build(verbose=False)

.docs/Notebooks/get_transmissivities_example.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@
106106
plt.plot(heads[0], label="piezometric surface", color="b", linestyle=":")
107107
for iw in range(len(sctop)):
108108
ax.fill_between(
109-
[iw - 0.25, iw + 0.25],
110-
scbot[iw],
111-
sctop[iw],
112-
facecolor="None",
113-
edgecolor="k",
109+
[iw - 0.25, iw + 0.25], scbot[iw], sctop[iw], facecolor="None", edgecolor="k"
114110
)
115111
ax.legend(loc=2)
116112

.docs/Notebooks/grid_intersection_example.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,7 @@
4444
import matplotlib.pyplot as plt
4545
import numpy as np
4646
import shapely
47-
from shapely.geometry import (
48-
LineString,
49-
MultiLineString,
50-
MultiPoint,
51-
Point,
52-
Polygon,
53-
)
47+
from shapely.geometry import LineString, MultiLineString, MultiPoint, Point, Polygon
5448

5549
import flopy
5650
import flopy.discretization as fgrid
@@ -110,15 +104,7 @@
110104
# Polygon to intersect with:
111105

112106
p = Polygon(
113-
shell=[
114-
(15, 15),
115-
(20, 50),
116-
(35, 80.0),
117-
(80, 50),
118-
(80, 40),
119-
(40, 5),
120-
(15, 12),
121-
],
107+
shell=[(15, 15), (20, 50), (35, 80.0), (80, 50), (80, 40), (40, 5), (15, 12)],
122108
holes=[[(25, 25), (25, 45), (45, 45), (45, 25)]],
123109
)
124110

@@ -261,12 +247,7 @@
261247
# MultiPoint to intersect with
262248

263249
mp = MultiPoint(
264-
points=[
265-
Point(50.0, 0.0),
266-
Point(45.0, 45.0),
267-
Point(10.0, 10.0),
268-
Point(150.0, 100.0),
269-
]
250+
points=[Point(50.0, 0.0), Point(45.0, 45.0), Point(10.0, 10.0), Point(150.0, 100.0)]
270251
)
271252

272253
# 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.

.docs/Notebooks/groundwater2023_watershed_example.py

Lines changed: 15 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,7 @@ def set_idomain(grid, boundary):
233233
pmv = flopy.plot.PlotMapView(modelgrid=struct_grid)
234234
ax.set_aspect("equal")
235235
pmv.plot_array(top_sg)
236-
pmv.plot_array(
237-
intersection_sg,
238-
masked_values=[
239-
0,
240-
],
241-
alpha=0.2,
242-
cmap="Reds_r",
243-
)
236+
pmv.plot_array(intersection_sg, masked_values=[0], alpha=0.2, cmap="Reds_r")
244237
pmv.plot_grid(lw=0.25, color="0.5")
245238
cg = pmv.contour_array(top_sg, levels=levels, linewidths=0.3, colors="0.75")
246239
pmv.plot_inactive()
@@ -314,14 +307,7 @@ def set_idomain(grid, boundary):
314307
pmv = flopy.plot.PlotMapView(modelgrid=struct_vrc_grid)
315308
ax.set_aspect("equal")
316309
pmv.plot_array(top_sg_vrc)
317-
pmv.plot_array(
318-
intersection_sg_vrc,
319-
masked_values=[
320-
0,
321-
],
322-
alpha=0.2,
323-
cmap="Reds_r",
324-
)
310+
pmv.plot_array(intersection_sg_vrc, masked_values=[0], alpha=0.2, cmap="Reds_r")
325311
cg = pmv.contour_array(top_sg_vrc, levels=levels, linewidths=0.3, colors="0.75")
326312
pmv.plot_inactive()
327313

@@ -437,14 +423,7 @@ def set_idomain(grid, boundary):
437423
pmv = flopy.plot.PlotMapView(modelgrid=struct_gridp, extent=extent)
438424
pmv.plot_inactive()
439425
pmv.plot_array(top_ngp, vmin=vmin, vmax=vmax)
440-
pmv.plot_array(
441-
intersection_nested_grid[0],
442-
masked_values=[
443-
0,
444-
],
445-
alpha=0.2,
446-
cmap="Reds_r",
447-
)
426+
pmv.plot_array(intersection_nested_grid[0], masked_values=[0], alpha=0.2, cmap="Reds_r")
448427
cgp = pmv.contour_array(top_ngp, levels=levels, linewidths=0.3, colors="0.75")
449428
pmv.plot_inactive(zorder=100)
450429
ax.set_aspect("equal")
@@ -453,12 +432,7 @@ def set_idomain(grid, boundary):
453432
# pmvc.plot_grid()
454433
pmvc.plot_array(top_ngc, vmin=vmin, vmax=vmax)
455434
pmvc.plot_array(
456-
intersection_nested_grid[1],
457-
masked_values=[
458-
0,
459-
],
460-
alpha=0.2,
461-
cmap="Reds_r",
435+
intersection_nested_grid[1], masked_values=[0], alpha=0.2, cmap="Reds_r"
462436
)
463437
cgc = pmvc.contour_array(top_ngc, levels=levels, linewidths=0.3, colors="0.75")
464438

@@ -532,14 +506,7 @@ def set_idomain(grid, boundary):
532506
ax = fig.add_subplot()
533507
pmv = flopy.plot.PlotMapView(modelgrid=quadtree_grid)
534508
pmv.plot_array(top_qg, ec="0.75")
535-
pmv.plot_array(
536-
intersection_qg,
537-
masked_values=[
538-
0,
539-
],
540-
alpha=0.2,
541-
cmap="Reds_r",
542-
)
509+
pmv.plot_array(intersection_qg, masked_values=[0], alpha=0.2, cmap="Reds_r")
543510
cg = pmv.contour_array(top_qg, levels=levels, linewidths=0.3, colors="white")
544511
pmv.plot_inactive(zorder=100)
545512
ax.set_aspect("equal")
@@ -615,14 +582,7 @@ def set_idomain(grid, boundary):
615582
pmv = flopy.plot.PlotMapView(modelgrid=triangular_grid)
616583

617584
pmv.plot_array(top_tg, ec="0.75")
618-
pmv.plot_array(
619-
intersection_tg,
620-
masked_values=[
621-
0,
622-
],
623-
alpha=0.2,
624-
cmap="Reds_r",
625-
)
585+
pmv.plot_array(intersection_tg, masked_values=[0], alpha=0.2, cmap="Reds_r")
626586
cg = pmv.contour_array(top_tg, levels=levels, linewidths=0.3, colors="white")
627587
ax.clabel(cg, cg.levels, inline=True, fmt="%1.0f", fontsize=10)
628588

@@ -670,14 +630,7 @@ def set_idomain(grid, boundary):
670630
pmv = flopy.plot.PlotMapView(modelgrid=voronoi_grid)
671631
ax.set_aspect("equal")
672632
pmv.plot_array(top_vg)
673-
pmv.plot_array(
674-
intersection_vg,
675-
masked_values=[
676-
0,
677-
],
678-
alpha=0.2,
679-
cmap="Reds_r",
680-
)
633+
pmv.plot_array(intersection_vg, masked_values=[0], alpha=0.2, cmap="Reds_r")
681634
pmv.plot_inactive()
682635
ax.plot(bp[:, 0], bp[:, 1], "k-")
683636
for sg in sgs:
@@ -789,29 +742,10 @@ def set_idomain(grid, boundary):
789742
ax.set_ylim(0, 1)
790743
ax.set_axis_off()
791744

792-
ax.axhline(
793-
xy0[0],
794-
color="black",
795-
lw=2,
796-
label="Basin boundary",
797-
)
798-
ax.axhline(
799-
xy0[0],
800-
**river_dict,
801-
label="River",
802-
)
803-
ax.axhline(
804-
xy0[0],
805-
color=contour_color,
806-
lw=0.5,
807-
ls="--",
808-
label="Elevation contour",
809-
)
810-
ax.axhline(
811-
xy0[0],
812-
label="Grid refinement area",
813-
**refinement_dict,
814-
)
745+
ax.axhline(xy0[0], color="black", lw=2, label="Basin boundary")
746+
ax.axhline(xy0[0], **river_dict, label="River")
747+
ax.axhline(xy0[0], color=contour_color, lw=0.5, ls="--", label="Elevation contour")
748+
ax.axhline(xy0[0], label="Grid refinement area", **refinement_dict)
815749
ax.axhline(
816750
xy0[0],
817751
marker="s",
@@ -844,23 +778,10 @@ def set_idomain(grid, boundary):
844778
ax.set_xlim(0, 1)
845779
ax.set_ylim(0, 1)
846780
ax.set_axis_off()
847-
cax = ax.inset_axes(
848-
cbar_axis,
849-
)
781+
cax = ax.inset_axes(cbar_axis)
850782
# cax.set_axisbelow(False)
851-
cbar = plt.colorbar(
852-
v,
853-
orientation="vertical",
854-
cax=cax,
855-
ticks=[25, 50, 75, 100],
856-
)
857-
cbar.ax.tick_params(
858-
labelsize=5,
859-
labelcolor="black",
860-
color="black",
861-
length=9,
862-
pad=2,
863-
)
783+
cbar = plt.colorbar(v, orientation="vertical", cax=cax, ticks=[25, 50, 75, 100])
784+
cbar.ax.tick_params(labelsize=5, labelcolor="black", color="black", length=9, pad=2)
864785
cbar.ax.set_title("Elevation (m)", pad=2.5, loc="center", fontdict=font_dict)
865786
# -
866787

@@ -971,11 +892,7 @@ def set_idomain(grid, boundary):
971892
ax.set_axis_off()
972893

973894
ax.axhline(xy0[0], **river_dict, label="River")
974-
ax.axhline(
975-
xy0[0],
976-
label="Grid refinement area",
977-
**refinement_dict,
978-
)
895+
ax.axhline(xy0[0], label="Grid refinement area", **refinement_dict)
979896
ax.axhline(
980897
xy0[0],
981898
marker="s",

.docs/Notebooks/groundwater_paper_uspb_example.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@
4242
os.makedirs(ws)
4343

4444
fn = os.path.join(
45-
"..",
46-
"groundwater_paper",
47-
"uspb",
48-
"results",
49-
"USPB_capture_fraction_04_01.dat",
45+
"..", "groundwater_paper", "uspb", "results", "USPB_capture_fraction_04_01.dat"
5046
)
5147
cf = np.loadtxt(fn)
5248
print(cf.shape)
@@ -86,11 +82,7 @@
8682
label="Maximum active model extent",
8783
)
8884
plt.plot(
89-
[-10000, 0],
90-
[-10000, 0],
91-
color="purple",
92-
lw=0.75,
93-
label="STR reaches (all layers)",
85+
[-10000, 0], [-10000, 0], color="purple", lw=0.75, label="STR reaches (all layers)"
9486
)
9587
leg = plt.legend(loc="upper left", numpoints=1, prop={"size": 6})
9688
leg.draw_frame(False)
@@ -200,11 +192,7 @@
200192
# -
201193

202194
fn = os.path.join(
203-
"..",
204-
"groundwater_paper",
205-
"uspb",
206-
"results",
207-
"USPB_capture_fraction_04_10.dat",
195+
"..", "groundwater_paper", "uspb", "results", "USPB_capture_fraction_04_10.dat"
208196
)
209197
cf = np.loadtxt(fn)
210198
cf2 = scipy.ndimage.zoom(cf, 4, order=0)

.docs/Notebooks/load_swr_binary_data_example.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@
182182
stage = np.extract(iprof, s["stage"])
183183
xs = flopy.plot.PlotCrossSection(model=ml, line={"Row": 0})
184184
xs.plot_fill_between(
185-
stage.reshape(1, 1, 12),
186-
colors=["none", "blue"],
187-
ax=ax,
188-
edgecolors="none",
185+
stage.reshape(1, 1, 12), colors=["none", "blue"], ax=ax, edgecolors="none"
189186
)
190187
linecollection = xs.plot_grid(ax=ax, zorder=10)
191188
ax.fill_between(

0 commit comments

Comments
 (0)