From c261ee8145e2791be2c2cc944e5a55cf19ef1560 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Mon, 24 Jul 2023 15:13:21 +1200 Subject: [PATCH] refactor(Notebooks): apply pyformat and black QA tools (#1879) --- .docs/Notebooks/array_output_tutorial.py | 10 +-- .docs/Notebooks/dis_triangle_example.py | 10 +-- .docs/Notebooks/dis_voronoi_example.py | 14 ++--- .docs/Notebooks/drain_return_example.py | 10 +-- .docs/Notebooks/export_tutorial.py | 6 +- .docs/Notebooks/export_vtk_tutorial.py | 6 +- .../external_file_handling_tutorial.py | 24 +++---- .../Notebooks/feat_working_stack_examples.py | 8 +-- .../Notebooks/get_transmissivities_example.py | 8 +-- .docs/Notebooks/grid_intersection_example.py | 8 +-- .docs/Notebooks/gridgen_example.py | 28 ++++----- .../groundwater2023_watershed_example.py | 6 +- .../Notebooks/groundwater_paper_example_1.py | 6 +- .../groundwater_paper_uspb_example.py | 6 +- .docs/Notebooks/lake_example.py | 8 +-- .docs/Notebooks/lgr_tutorial01.py | 30 ++++----- .../Notebooks/load_swr_binary_data_example.py | 8 +-- .docs/Notebooks/mf6_complex_model_example.py | 42 ++++++------- .docs/Notebooks/mf6_data_tutorial10.py | 10 +-- .docs/Notebooks/mf6_mnw2_tutorial01.py | 10 +-- .docs/Notebooks/mf6_sfr_tutorial01.py | 2 +- .docs/Notebooks/mf6_simple_model_example.py | 22 +++---- .docs/Notebooks/mf6_support_example.py | 26 ++++---- .docs/Notebooks/mf_boundaries_tutorial.py | 4 +- .docs/Notebooks/mf_error_tutorial01.py | 2 +- .docs/Notebooks/mf_load_tutorial.py | 2 +- .../mf_watertable_recharge_example.py | 6 +- .docs/Notebooks/mfusg_conduit_examples.py | 16 ++--- .docs/Notebooks/mfusg_zaidel_example.py | 6 +- .docs/Notebooks/modelgrid_examples.py | 48 ++++++-------- .../modflow_postprocessing_example.py | 20 +++--- .docs/Notebooks/modpath6_example.py | 8 +-- .../modpath7_create_simulation_example.py | 28 ++++----- .../Notebooks/modpath7_structured_example.py | 24 +++---- .../modpath7_structured_transient_example.py | 12 ++-- .../modpath7_unstructured_example.py | 28 ++++----- .../modpath7_unstructured_lateral_example.py | 2 +- .docs/Notebooks/mt3d-usgs_example.py | 38 +++++------- .docs/Notebooks/mt3dms_examples.py | 62 +++++++++---------- .../Notebooks/mt3dms_sft_lkt_uzt_tutorial.py | 8 +-- .../Notebooks/mt3dms_ssm_package_tutorial.py | 8 +-- .docs/Notebooks/nwt_option_blocks_tutorial.py | 2 +- .docs/Notebooks/pest_tutorial01.py | 14 ++--- .docs/Notebooks/plot_array_example.py | 10 +-- .docs/Notebooks/plot_cross_section_example.py | 20 +++--- .docs/Notebooks/plot_map_view_example.py | 32 +++++----- .../Notebooks/raster_intersection_example.py | 32 +++++----- .../save_binary_data_file_example.py | 6 +- .docs/Notebooks/seawat_henry_example.py | 8 +-- .docs/Notebooks/sfrpackage_example.py | 8 +-- .docs/Notebooks/shapefile_export_example.py | 30 ++++----- .docs/Notebooks/shapefile_feature_examples.py | 6 +- .docs/Notebooks/swi2package_example1.py | 10 +-- .docs/Notebooks/swi2package_example4.py | 24 +++---- .docs/Notebooks/uzf_example.py | 10 +-- .docs/Notebooks/vtk_pathlines_example.py | 2 +- .docs/Notebooks/zonebudget_example.py | 30 +++++---- 57 files changed, 424 insertions(+), 450 deletions(-) diff --git a/.docs/Notebooks/array_output_tutorial.py b/.docs/Notebooks/array_output_tutorial.py index ac790a7af..b7780adbc 100644 --- a/.docs/Notebooks/array_output_tutorial.py +++ b/.docs/Notebooks/array_output_tutorial.py @@ -53,9 +53,9 @@ os.makedirs(modelpth) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + ml = flopy.modflow.Modflow.load( @@ -73,10 +73,10 @@ files = ["freyberg.hds", "freyberg.cbc"] for f in files: if os.path.isfile(os.path.join(modelpth, f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + [markdown] pycharm={"name": "#%% md\n"} diff --git a/.docs/Notebooks/dis_triangle_example.py b/.docs/Notebooks/dis_triangle_example.py index c140a9e9f..1691f9887 100644 --- a/.docs/Notebooks/dis_triangle_example.py +++ b/.docs/Notebooks/dis_triangle_example.py @@ -37,9 +37,9 @@ workspace = Path(temp_dir.name) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ## Creating Meshes with the Triangle Class @@ -247,8 +247,8 @@ def chdhead(x): chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdlist) oc = flopy.mf6.ModflowGwfoc( gwf, - budget_filerecord="{}.cbc".format(name), - head_filerecord="{}.hds".format(name), + budget_filerecord=f"{name}.cbc", + head_filerecord=f"{name}.hds", saverecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], printrecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], ) diff --git a/.docs/Notebooks/dis_voronoi_example.py b/.docs/Notebooks/dis_voronoi_example.py index b4b458bb4..98a9da54c 100644 --- a/.docs/Notebooks/dis_voronoi_example.py +++ b/.docs/Notebooks/dis_voronoi_example.py @@ -41,9 +41,9 @@ workspace = Path(temp_dir.name) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ### Use Triangle to Generate Points for Voronoi Grid @@ -164,8 +164,8 @@ chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdlist) oc = flopy.mf6.ModflowGwfoc( gwf, - budget_filerecord="{}.bud".format(name), - head_filerecord="{}.hds".format(name), + budget_filerecord=f"{name}.bud", + head_filerecord=f"{name}.hds", saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], ) @@ -229,8 +229,8 @@ fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=pd) oc = flopy.mf6.ModflowGwtoc( gwt, - budget_filerecord="{}.cbc".format(name), - concentration_filerecord="{}.ucn".format(name), + budget_filerecord=f"{name}.cbc", + concentration_filerecord=f"{name}.ucn", saverecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], ) diff --git a/.docs/Notebooks/drain_return_example.py b/.docs/Notebooks/drain_return_example.py index dfadc6554..c4c61de7c 100644 --- a/.docs/Notebooks/drain_return_example.py +++ b/.docs/Notebooks/drain_return_example.py @@ -29,9 +29,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + # temporary directory @@ -78,7 +78,7 @@ raise ValueError("Failed to run.") # plot heads for the drt model -hds = flopy.utils.HeadFile(os.path.join(m.model_ws, m.name + ".hds")) +hds = flopy.utils.HeadFile(os.path.join(m.model_ws, f"{m.name}.hds")) hds.plot(colorbar=True) # remove the drt package and create a standard drain file @@ -98,7 +98,7 @@ raise ValueError("Failed to run.") # plot the heads for the model with the drain -hds = flopy.utils.HeadFile(os.path.join(m.model_ws, m.name + ".hds")) +hds = flopy.utils.HeadFile(os.path.join(m.model_ws, f"{m.name}.hds")) hds.plot(colorbar=True) try: diff --git a/.docs/Notebooks/export_tutorial.py b/.docs/Notebooks/export_tutorial.py index c87ba88ad..79e4efceb 100644 --- a/.docs/Notebooks/export_tutorial.py +++ b/.docs/Notebooks/export_tutorial.py @@ -27,7 +27,7 @@ import flopy print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # Load our old friend...the Freyberg model @@ -60,12 +60,12 @@ pth = temp_dir.name # export the whole model (inputs and outputs) -fnc = ml.export(os.path.join(pth, ml.name + ".in.nc")) +fnc = ml.export(os.path.join(pth, f"{ml.name}.in.nc")) # export outputs using spatial reference info hds = flopy.utils.HeadFile(os.path.join(model_ws, "freyberg.hds")) flopy.export.utils.output_helper( - os.path.join(pth, ml.name + ".out.nc"), ml, {"hds": hds} + os.path.join(pth, f"{ml.name}.out.nc"), ml, {"hds": hds} ) # ### Export an array to netCDF or shapefile diff --git a/.docs/Notebooks/export_vtk_tutorial.py b/.docs/Notebooks/export_vtk_tutorial.py index 03e0f37f6..cdaaaac92 100644 --- a/.docs/Notebooks/export_vtk_tutorial.py +++ b/.docs/Notebooks/export_vtk_tutorial.py @@ -41,7 +41,7 @@ import notebook_utils print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # load model for examples @@ -384,10 +384,10 @@ files = ["mp7p2.hds", "mp7p2.cbb"] for f in files: if os.path.isfile(modelpth / f): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + diff --git a/.docs/Notebooks/external_file_handling_tutorial.py b/.docs/Notebooks/external_file_handling_tutorial.py index 4967aafdc..f11e701ce 100644 --- a/.docs/Notebooks/external_file_handling_tutorial.py +++ b/.docs/Notebooks/external_file_handling_tutorial.py @@ -32,8 +32,8 @@ from flopy.utils import flopy_io print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"flopy version: {flopy.__version__}") # + # make a model @@ -57,7 +57,7 @@ vka = np.zeros_like(hk) fnames = [] for i, h in enumerate(hk): - fname = os.path.join(array_dir, "hk_{0}.ref".format(i + 1)) + fname = os.path.join(array_dir, f"hk_{i + 1}.ref") fnames.append(fname) np.savetxt(fname, h) vka[i] = i + 1 @@ -84,7 +84,7 @@ # We see that a copy of the ``hk`` files as well as the important recharge file were made in the ```model_ws```.Let's looks at the ```lpf``` file -open(os.path.join(ml.model_ws, ml.name + ".lpf"), "r").readlines()[:20] +open(os.path.join(ml.model_ws, f"{ml.name}.lpf")).readlines()[:20] # We see that the ```open/close``` approach was used - this is because ``ml.array_free_format`` is ``True``. Notice that ```vka``` is written internally @@ -137,7 +137,7 @@ vka = np.zeros_like(hk) fnames = [] for i, h in enumerate(hk): - fname = os.path.join(array_dir, "hk_{0}.ref".format(i + 1)) + fname = os.path.join(array_dir, f"hk_{i + 1}.ref") fnames.append(fname) np.savetxt(fname, h) vka[i] = i + 1 @@ -189,7 +189,7 @@ vka = np.zeros_like(hk) fnames = [] for i, h in enumerate(hk): - fname = os.path.join(array_dir, "hk_{0}.ref".format(i + 1)) + fname = os.path.join(array_dir, f"hk_{i + 1}.ref") fnames.append(fname) np.savetxt(fname, h) vka[i] = i + 1 @@ -206,16 +206,16 @@ # We see that now the external arrays are being handled through the name file. Let's look at the name file -open(os.path.join(ml.model_ws, ml.name + ".nam"), "r").readlines() +open(os.path.join(ml.model_ws, f"{ml.name}.nam")).readlines() # ### Free and binary format ml.dis.botm[0].format.binary = True ml.write_input() -open(os.path.join(ml.model_ws, ml.name + ".nam"), "r").readlines() +open(os.path.join(ml.model_ws, f"{ml.name}.nam")).readlines() -open(os.path.join(ml.model_ws, ml.name + ".dis"), "r").readlines() +open(os.path.join(ml.model_ws, f"{ml.name}.dis")).readlines() # ### The ```.how``` attribute # ```Util2d``` includes a ```.how``` attribute that gives finer grained control of how arrays will written @@ -240,11 +240,11 @@ ml.write_input() -open(os.path.join(ml.model_ws, ml.name + ".dis"), "r").readlines() +open(os.path.join(ml.model_ws, f"{ml.name}.dis")).readlines() -open(os.path.join(ml.model_ws, ml.name + ".lpf"), "r").readlines() +open(os.path.join(ml.model_ws, f"{ml.name}.lpf")).readlines() -open(os.path.join(ml.model_ws, ml.name + ".nam"), "r").readlines() +open(os.path.join(ml.model_ws, f"{ml.name}.nam")).readlines() try: # ignore PermissionError on Windows diff --git a/.docs/Notebooks/feat_working_stack_examples.py b/.docs/Notebooks/feat_working_stack_examples.py index baafb26ab..2bf6fd210 100644 --- a/.docs/Notebooks/feat_working_stack_examples.py +++ b/.docs/Notebooks/feat_working_stack_examples.py @@ -40,10 +40,10 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("pandas version: {}".format(pd.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"pandas version: {pd.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ### Model Inputs diff --git a/.docs/Notebooks/get_transmissivities_example.py b/.docs/Notebooks/get_transmissivities_example.py index eea454bc8..19203e3bf 100644 --- a/.docs/Notebooks/get_transmissivities_example.py +++ b/.docs/Notebooks/get_transmissivities_example.py @@ -39,9 +39,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ### Make up some open interval tops and bottoms and some heads @@ -104,7 +104,7 @@ fig, ax = plt.subplots() plt.plot(m.dis.top.array[r, c], label="model top") for i, l in enumerate(m.dis.botm.array[:, r, c]): - label = "layer {} bot".format(i + 1) + label = f"layer {i + 1} bot" if i == m.nlay - 1: label = "model bot" plt.plot(l, label=label) diff --git a/.docs/Notebooks/grid_intersection_example.py b/.docs/Notebooks/grid_intersection_example.py index e553a9f5f..48176f47c 100644 --- a/.docs/Notebooks/grid_intersection_example.py +++ b/.docs/Notebooks/grid_intersection_example.py @@ -60,10 +60,10 @@ from flopy.utils import GridIntersect print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) -print("shapely version: {}".format(shapely.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") +print(f"shapely version: {shapely.__version__}") # - # ## [GridIntersect Class](#top) diff --git a/.docs/Notebooks/gridgen_example.py b/.docs/Notebooks/gridgen_example.py index 55d896f1f..c02616408 100644 --- a/.docs/Notebooks/gridgen_example.py +++ b/.docs/Notebooks/gridgen_example.py @@ -45,9 +45,9 @@ from flopy.utils.gridgen import Gridgen print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # The Flopy GRIDGEN module requires that the gridgen executable can be called using subprocess **(i.e., gridgen is in your path)**. @@ -62,9 +62,7 @@ print(msg) else: print( - "gridgen executable was found at: {}".format( - flopy_io.relpath_safe(gridgen_exe) - ) + f"gridgen executable was found at: {flopy_io.relpath_safe(gridgen_exe)}" ) # + @@ -75,8 +73,8 @@ gridgen_ws = os.path.join(model_ws, "gridgen") if not os.path.exists(gridgen_ws): os.makedirs(gridgen_ws, exist_ok=True) -print("Model workspace is : {}".format(flopy_io.scrub_login(model_ws))) -print("Gridgen workspace is : {}".format(flopy_io.scrub_login(gridgen_ws))) +print(f"Model workspace is : {flopy_io.scrub_login(model_ws)}") +print(f"Gridgen workspace is : {flopy_io.scrub_login(gridgen_ws)}") # - # ## Basic Gridgen Operations @@ -276,8 +274,8 @@ gwf, xt3doptions=True, save_specific_discharge=True ) chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdspd) -budget_file = name + ".bud" -head_file = name + ".hds" +budget_file = f"{name}.bud" +head_file = f"{name}.hds" oc = flopy.mf6.ModflowGwfoc( gwf, budget_filerecord=budget_file, @@ -378,8 +376,8 @@ gwf, xt3doptions=True, save_specific_discharge=True ) chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdspd) -budget_file = name + ".bud" -head_file = name + ".hds" +budget_file = f"{name}.bud" +head_file = f"{name}.hds" oc = flopy.mf6.ModflowGwfoc( gwf, budget_filerecord=budget_file, @@ -406,7 +404,7 @@ pmv.contour_array( head, levels=[0.2, 0.4, 0.6, 0.8], linewidths=3.0, vmin=vmin, vmax=vmax ) - ax.set_title("Layer {}".format(ilay + 1)) + ax.set_title(f"Layer {ilay + 1}") pmv.plot_vector(spdis["qx"], spdis["qy"], color="white") # - @@ -452,7 +450,7 @@ raise ValueError("Failed to run.") # head is returned as a list of head arrays for each layer -head_file = os.path.join(ws, name + ".hds") +head_file = os.path.join(ws, f"{name}.hds") head = flopy.utils.HeadUFile(head_file).get_data() # MODFLOW-USG does not have vertices, so we need to create @@ -472,7 +470,7 @@ pmv.plot_array(head[ilay], cmap="jet", vmin=vmin, vmax=vmax) pmv.plot_grid(colors="k", alpha=0.1) pmv.contour_array(head[ilay], levels=[0.2, 0.4, 0.6, 0.8], linewidths=3.0) - ax.set_title("Layer {}".format(ilay + 1)) + ax.set_title(f"Layer {ilay + 1}") # - try: diff --git a/.docs/Notebooks/groundwater2023_watershed_example.py b/.docs/Notebooks/groundwater2023_watershed_example.py index 947b08560..686520926 100644 --- a/.docs/Notebooks/groundwater2023_watershed_example.py +++ b/.docs/Notebooks/groundwater2023_watershed_example.py @@ -39,9 +39,9 @@ from flopy.utils.voronoi import VoronoiGrid print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # import all plot style information from defaults.py sys.path.append("../common") diff --git a/.docs/Notebooks/groundwater_paper_example_1.py b/.docs/Notebooks/groundwater_paper_example_1.py index 08619db18..97edf357b 100644 --- a/.docs/Notebooks/groundwater_paper_example_1.py +++ b/.docs/Notebooks/groundwater_paper_example_1.py @@ -40,9 +40,9 @@ import flopy.utils as fpu print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Create a MODFLOW model object. Here, the MODFLOW model object is stored in a Python variable called {\tt model}, but this can be an arbitrary name. This object name is important as it will be used as a reference to the model in the remainder of the FloPy script. In addition, a {\tt modelname} is specified when the MODFLOW model object is created. This {\tt modelname} is used for all the files that are created by FloPy for this model. diff --git a/.docs/Notebooks/groundwater_paper_uspb_example.py b/.docs/Notebooks/groundwater_paper_uspb_example.py index 813a8b5a0..423d3bcb7 100644 --- a/.docs/Notebooks/groundwater_paper_uspb_example.py +++ b/.docs/Notebooks/groundwater_paper_uspb_example.py @@ -36,9 +36,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - ws = os.path.join("temp") diff --git a/.docs/Notebooks/lake_example.py b/.docs/Notebooks/lake_example.py index 480330051..fc2ebbf2f 100644 --- a/.docs/Notebooks/lake_example.py +++ b/.docs/Notebooks/lake_example.py @@ -40,9 +40,9 @@ workspace = temp_dir.name print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # We are creating a square model with a specified head equal to `h1` along all boundaries. The head at the cell in the center in the top layer is fixed to `h2`. First, set the name of the model and the parameters of the model: the number of layers `Nlay`, the number of rows and columns `N`, lengths of the sides of the model `L`, aquifer thickness `H`, hydraulic conductivity `k` @@ -109,7 +109,7 @@ # Once the model has terminated normally, we can read the heads file. First, a link to the heads file is created with `HeadFile`. The link can then be accessed with the `get_data` function, by specifying, in this case, the step number and period number for which we want to retrieve data. A three-dimensional array is returned of size `nlay, nrow, ncol`. Matplotlib contouring functions are used to make contours of the layers or a cross-section. -hds = flopy.utils.HeadFile(os.path.join(workspace, name + ".hds")) +hds = flopy.utils.HeadFile(os.path.join(workspace, f"{name}.hds")) h = hds.get_data(kstpkper=(0, 0)) x = y = np.linspace(0, L, N) c = plt.contour(x, y, h[0], np.arange(90, 100.1, 0.2)) diff --git a/.docs/Notebooks/lgr_tutorial01.py b/.docs/Notebooks/lgr_tutorial01.py index 8ca4673c5..687477ae2 100644 --- a/.docs/Notebooks/lgr_tutorial01.py +++ b/.docs/Notebooks/lgr_tutorial01.py @@ -42,9 +42,9 @@ os.makedirs(workspace, exist_ok=True) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ## LGR basics @@ -256,8 +256,8 @@ chd = flopy.mf6.ModflowGwfchd(gwfp, stress_period_data=chdspd) oc = flopy.mf6.ModflowGwfoc( gwfp, - budget_filerecord=pname + ".bud", - head_filerecord=pname + ".hds", + budget_filerecord=f"{pname}.bud", + head_filerecord=f"{pname}.hds", saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], ) @@ -270,8 +270,8 @@ npf = flopy.mf6.ModflowGwfnpf(gwfc, save_specific_discharge=True) oc = flopy.mf6.ModflowGwfoc( gwfc, - budget_filerecord=cname + ".bud", - head_filerecord=cname + ".hds", + budget_filerecord=f"{cname}.bud", + head_filerecord=f"{cname}.hds", saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], ) @@ -436,8 +436,8 @@ chd = flopy.mf6.ModflowGwfchd(gwfp, stress_period_data=chdspd) oc = flopy.mf6.ModflowGwfoc( gwfp, - budget_filerecord=pname + ".bud", - head_filerecord=pname + ".hds", + budget_filerecord=f"{pname}.bud", + head_filerecord=f"{pname}.hds", saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], ) @@ -450,8 +450,8 @@ npf = flopy.mf6.ModflowGwfnpf(gwfc, save_specific_discharge=True) oc = flopy.mf6.ModflowGwfoc( gwfc, - budget_filerecord=cname + ".bud", - head_filerecord=cname + ".hds", + budget_filerecord=f"{cname}.bud", + head_filerecord=f"{cname}.hds", saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], ) # - @@ -495,8 +495,8 @@ ssm = flopy.mf6.ModflowGwtssm(gwtp) oc = flopy.mf6.ModflowGwtoc( gwtp, - budget_filerecord=pname + ".bud", - concentration_filerecord=pname + ".ucn", + budget_filerecord=f"{pname}.bud", + concentration_filerecord=f"{pname}.ucn", saverecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], ) @@ -514,8 +514,8 @@ cnc = flopy.mf6.ModflowGwtcnc(gwtc, stress_period_data=cncspd) oc = flopy.mf6.ModflowGwtoc( gwtc, - budget_filerecord=cname + ".bud", - concentration_filerecord=cname + ".ucn", + budget_filerecord=f"{cname}.bud", + concentration_filerecord=f"{cname}.ucn", saverecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], printrecord=[("CONCENTRATION", "LAST"), ("BUDGET", "ALL")], ) diff --git a/.docs/Notebooks/load_swr_binary_data_example.py b/.docs/Notebooks/load_swr_binary_data_example.py index 0a286e056..499e61251 100644 --- a/.docs/Notebooks/load_swr_binary_data_example.py +++ b/.docs/Notebooks/load_swr_binary_data_example.py @@ -37,9 +37,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + # Set the paths @@ -202,7 +202,7 @@ edgecolor="none", step="pre", ) - ax.set_title("{} hours".format(times[v])) + ax.set_title(f"{times[v]} hours") ax.set_ylim(-0.5, 4.5) # ## Summary diff --git a/.docs/Notebooks/mf6_complex_model_example.py b/.docs/Notebooks/mf6_complex_model_example.py index 51f21f2d5..5b6da56ea 100644 --- a/.docs/Notebooks/mf6_complex_model_example.py +++ b/.docs/Notebooks/mf6_complex_model_example.py @@ -39,9 +39,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # For this example, we will set up a temporary workspace. @@ -75,7 +75,7 @@ # create gwf model gwf = flopy.mf6.ModflowGwf( - sim, modelname=model_name, model_nam_file="{}.nam".format(model_name) + sim, modelname=model_name, model_nam_file=f"{model_name}.nam" ) gwf.name_file.save_flows = True @@ -114,12 +114,12 @@ delc=500.0, top=50.0, botm=[5.0, -10.0, botlay2], - filename="{}.dis".format(model_name), + filename=f"{model_name}.dis", ) # initial conditions ic = flopy.mf6.ModflowGwfic( - gwf, pname="ic", strt=50.0, filename="{}.ic".format(model_name) + gwf, pname="ic", strt=50.0, filename=f"{model_name}.ic" ) # node property flow @@ -136,8 +136,8 @@ oc = flopy.mf6.ModflowGwfoc( gwf, pname="oc", - budget_filerecord="{}.cbb".format(model_name), - head_filerecord="{}.hds".format(model_name), + budget_filerecord=f"{model_name}.cbb", + head_filerecord=f"{model_name}.hds", headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "FIRST"), ("HEAD", "LAST"), ("BUDGET", "LAST")], @@ -274,7 +274,7 @@ stress_period_data=ghb_period, ) ts_recarray = [] -fd = open(os.path.join(data_pth, "tides.txt"), "r") +fd = open(os.path.join(data_pth, "tides.txt")) for line in fd: line_list = line.strip().split(",") ts_recarray.append((float(line_list[0]), float(line_list[1]))) @@ -295,7 +295,7 @@ ], } ghb.obs.initialize( - filename="{}.ghb.obs".format(model_name), + filename=f"{model_name}.ghb.obs", print_input=True, continuous=obs_recarray, ) @@ -316,7 +316,7 @@ obs_package = flopy.mf6.ModflowUtlobs( gwf, pname="head_obs", - filename="{}.obs".format(model_name), + filename=f"{model_name}.obs", print_input=True, continuous=obs_recarray, ) @@ -351,7 +351,7 @@ pname="riv", print_input=True, print_flows=True, - save_flows="{}.cbc".format(model_name), + save_flows=f"{model_name}.cbc", boundnames=True, maxbound=20, stress_period_data=riv_period, @@ -407,7 +407,7 @@ ], } riv.obs.initialize( - filename="{}.riv.obs".format(model_name), + filename=f"{model_name}.riv.obs", print_input=True, continuous=obs_recarray, ) @@ -443,7 +443,7 @@ rch1_period[0] = rch1_period_array rch1 = flopy.mf6.ModflowGwfrch( gwf, - filename="{}_1.rch".format(model_name), + filename=f"{model_name}_1.rch", pname="rch_1", fixed_cell=True, auxiliary="MULTIPLIER", @@ -496,7 +496,7 @@ rch2_period[0] = rch2_period_array rch2 = flopy.mf6.ModflowGwfrch( gwf, - filename="{}_2.rch".format(model_name), + filename=f"{model_name}_2.rch", pname="rch_2", fixed_cell=True, auxiliary="MULTIPLIER", @@ -544,7 +544,7 @@ rch3_period[0] = rch3_period_array rch3 = flopy.mf6.ModflowGwfrch( gwf, - filename="{}_3.rch".format(model_name), + filename=f"{model_name}_3.rch", pname="rch_3", fixed_cell=True, auxiliary="MULTIPLIER", @@ -616,7 +616,7 @@ # # MODFLOW 6 writes a binary grid file, which contains information about the model grid. MODFLOW 6 also writes a binary budget file, which contains flow information. Both of these files can be read using FloPy methods. The `MfGrdFile` class in FloPy can be used to read the binary grid file, which contains the cell connectivity (`ia` and `ja`). The `output.budget()` method in FloPy can be used to read the binary budget file written by MODFLOW 6. -fname = os.path.join(workspace, "{}.dis.grb".format(model_name)) +fname = os.path.join(workspace, f"{model_name}.dis.grb") bgf = flopy.mf6.utils.MfGrdFile(fname) ia, ja = bgf.ia, bgf.ja @@ -632,14 +632,10 @@ cell_nodes = gwf.modelgrid.get_node([(k, i, j)]) for celln in cell_nodes: - print("Printing flows for cell {}".format(celln)) + print(f"Printing flows for cell {celln}") for ipos in range(ia[celln] + 1, ia[celln + 1]): cellm = ja[ipos] - print( - "Cell {} flow with cell {} is {}".format( - celln, cellm, flowja[ipos] - ) - ) + print(f"Cell {celln} flow with cell {cellm} is {flowja[ipos]}") # - # ### Post-Process Head Observations diff --git a/.docs/Notebooks/mf6_data_tutorial10.py b/.docs/Notebooks/mf6_data_tutorial10.py index 92f11d672..049332286 100644 --- a/.docs/Notebooks/mf6_data_tutorial10.py +++ b/.docs/Notebooks/mf6_data_tutorial10.py @@ -46,8 +46,8 @@ model_name = "child_pkgs" print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"flopy version: {flopy.__version__}") # + # create simulation @@ -60,7 +60,7 @@ sim, time_units="DAYS", nper=4, perioddata=tdis_rc ) model = flopy.mf6.ModflowGwf( - sim, modelname=model_name, model_nam_file="{}.nam".format(model_name) + sim, modelname=model_name, model_nam_file=f"{model_name}.nam" ) ims_package = flopy.mf6.modflow.mfims.ModflowIms( sim, @@ -88,10 +88,10 @@ delc=500.0, top=50.0, botm=[5.0, -10.0, {"factor": 1.0, "data": bot_data}], - filename="{}.dis".format(model_name), + filename=f"{model_name}.dis", ) ic_package = flopy.mf6.modflow.mfgwfic.ModflowGwfic( - model, strt=50.0, filename="{}.ic".format(model_name) + model, strt=50.0, filename=f"{model_name}.ic" ) npf_package = flopy.mf6.modflow.mfgwfnpf.ModflowGwfnpf( model, diff --git a/.docs/Notebooks/mf6_mnw2_tutorial01.py b/.docs/Notebooks/mf6_mnw2_tutorial01.py index e7aa2dbf1..f07e4ec38 100644 --- a/.docs/Notebooks/mf6_mnw2_tutorial01.py +++ b/.docs/Notebooks/mf6_mnw2_tutorial01.py @@ -38,12 +38,12 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) +print(f"numpy version: {np.__version__}") try: - print("pandas version: {}".format(pd.__version__)) + print(f"pandas version: {pd.__version__}") except: pass -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # ### Make an MNW2 package from scratch @@ -221,7 +221,9 @@ path = os.path.join("..", "..", "examples", "data", "mnw2_examples") m = flopy.modflow.Modflow("br", model_ws=model_ws) -mnw2 = flopy.modflow.ModflowMnw2.load(path + "/BadRiver_cal.mnw2", m) +mnw2 = flopy.modflow.ModflowMnw2.load( + os.path.join(path, "BadRiver_cal.mnw2"), m +) df = pd.DataFrame(mnw2.node_data) df.loc[:, df.sum(axis=0) != 0] diff --git a/.docs/Notebooks/mf6_sfr_tutorial01.py b/.docs/Notebooks/mf6_sfr_tutorial01.py index e60938811..41ce0d250 100644 --- a/.docs/Notebooks/mf6_sfr_tutorial01.py +++ b/.docs/Notebooks/mf6_sfr_tutorial01.py @@ -30,7 +30,7 @@ import flopy print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # Create a model instance diff --git a/.docs/Notebooks/mf6_simple_model_example.py b/.docs/Notebooks/mf6_simple_model_example.py index 730a4a547..8c00e30ca 100644 --- a/.docs/Notebooks/mf6_simple_model_example.py +++ b/.docs/Notebooks/mf6_simple_model_example.py @@ -39,9 +39,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # For this example, we will set up a temporary workspace. @@ -83,7 +83,7 @@ ) # Create the Flopy groundwater flow (gwf) model object -model_nam_file = "{}.nam".format(name) +model_nam_file = f"{name}.nam" gwf = flopy.mf6.ModflowGwf(sim, modelname=name, model_nam_file=model_nam_file) # Create the Flopy iterative model solver (ims) Package object @@ -159,13 +159,13 @@ ilay = 0 plt.imshow(ibd[ilay, :, :], interpolation="none") -plt.title("Layer {}: Constant Head Cells".format(ilay + 1)) +plt.title(f"Layer {ilay + 1}: Constant Head Cells") # - # Create the output control package -headfile = "{}.hds".format(name) +headfile = f"{name}.hds" head_filerecord = [headfile] -budgetfile = "{}.cbb".format(name) +budgetfile = f"{name}.cbb" budget_filerecord = [budgetfile] saverecord = [("HEAD", "ALL"), ("BUDGET", "ALL")] printrecord = [("HEAD", "LAST")] @@ -271,7 +271,7 @@ # + # read the binary grid file -fname = os.path.join(workspace, "{}.dis.grb".format(name)) +fname = os.path.join(workspace, f"{name}.dis.grb") bgf = flopy.mf6.utils.MfGrdFile(fname) # data read from the binary grid file is stored in a dictionary @@ -279,7 +279,7 @@ # + # read the cell budget file -fname = os.path.join(workspace, "{}.cbb".format(name)) +fname = os.path.join(workspace, f"{name}.cbb") cbb = flopy.utils.CellBudgetFile(fname, precision="double") cbb.list_records() @@ -294,10 +294,10 @@ j = 50 celln = k * N * N + i * N + j ia, ja = bgf.ia, bgf.ja -print("Printing flows for cell {}".format(celln)) +print(f"Printing flows for cell {celln}") for ipos in range(ia[celln] + 1, ia[celln + 1]): cellm = ja[ipos] - print("Cell {} flow with cell {} is {}".format(celln, cellm, flowja[ipos])) + print(f"Cell {celln} flow with cell {cellm} is {flowja[ipos]}") try: # ignore PermissionError on Windows diff --git a/.docs/Notebooks/mf6_support_example.py b/.docs/Notebooks/mf6_support_example.py index 346690685..957b0a743 100644 --- a/.docs/Notebooks/mf6_support_example.py +++ b/.docs/Notebooks/mf6_support_example.py @@ -87,7 +87,7 @@ model_name = "example_model" model = flopy.mf6.ModflowGwf( - sim, modelname=model_name, model_nam_file="{}.nam".format(model_name) + sim, modelname=model_name, model_nam_file=f"{model_name}.nam" ) # Next create one or more Iterative Model Solution (IMS) files. @@ -129,7 +129,7 @@ delc=500.0, top=100.0, botm=[50.0, 20.0], - filename="{}.dis".format(model_name), + filename=f"{model_name}.dis", ) # ## Accessing namefiles @@ -260,7 +260,7 @@ "binary": "True", } ic_package = flopy.mf6.ModflowGwfic( - model, pname="ic", strt=strt, filename="{}.ic".format(model_name) + model, pname="ic", strt=strt, filename=f"{model_name}.ic" ) # move external file data into model folder icv_data_path = os.path.join( @@ -380,8 +380,8 @@ oc_package = flopy.mf6.ModflowGwfoc( model, pname="oc", - budget_filerecord=[("{}.cbc".format(model_name),)], - head_filerecord=[("{}.hds".format(model_name),)], + budget_filerecord=[(f"{model_name}.cbc",)], + head_filerecord=[(f"{model_name}.hds",)], saverecord=saverec_dict, printrecord=printrec_tuple_list, ) @@ -547,17 +547,17 @@ # + # get the data without applying any factor hk_data_no_factor = hk.get_data() -print("Data without factor:\n{}\n".format(hk_data_no_factor)) +print(f"Data without factor:\n{hk_data_no_factor}\n") # get data with factor applied hk_data_factor = hk.array -print("Data with factor:\n{}\n".format(hk_data_factor)) +print(f"Data with factor:\n{hk_data_factor}\n") # - # Data can also be retrieved from the data object using []. For unlayered data the [] can be used to slice the data. # slice layer one row two -print("SY slice of layer on row two\n{}\n".format(sy[0, :, 2])) +print(f"SY slice of layer on row two\n{sy[0, :, 2]}\n") # For layered data specify the layer number within the brackets. This will return a "LayerStorage" object which let's you change attributes of an individual layer. @@ -566,8 +566,8 @@ # change the print code and factor for layer one hk_layer_one.iprn = "2" hk_layer_one.factor = 1.1 -print("Layer one data without factor:\n{}\n".format(hk_layer_one.get_data())) -print("Data with new factor:\n{}\n".format(hk.array)) +print(f"Layer one data without factor:\n{hk_layer_one.get_data()}\n") +print(f"Data with new factor:\n{hk.array}\n") # ## Modifying Data # @@ -577,13 +577,13 @@ hk_layer_one.set_data( [120.0, 100.0, 80.0, 70.0, 60.0, 50.0, 40.0, 30.0, 25.0, 20.0] ) -print("New HK data no factor:\n{}\n".format(hk.get_data())) +print(f"New HK data no factor:\n{hk.get_data()}\n") # set data attribute to new data ic_package.strt = 150.0 -print("New strt values:\n{}\n".format(ic_package.strt.array)) +print(f"New strt values:\n{ic_package.strt.array}\n") # call set_data sto_package.ss.set_data([0.000003, 0.000004]) -print("New ss values:\n{}\n".format(sto_package.ss.array)) +print(f"New ss values:\n{sto_package.ss.array}\n") # ## Modifying the Simulation Path # diff --git a/.docs/Notebooks/mf_boundaries_tutorial.py b/.docs/Notebooks/mf_boundaries_tutorial.py index 121a1b34a..44dbb940c 100644 --- a/.docs/Notebooks/mf_boundaries_tutorial.py +++ b/.docs/Notebooks/mf_boundaries_tutorial.py @@ -52,8 +52,8 @@ workspace = os.path.join(temp_dir.name) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ## List of Boundaries diff --git a/.docs/Notebooks/mf_error_tutorial01.py b/.docs/Notebooks/mf_error_tutorial01.py index 0f140f500..63365aac5 100644 --- a/.docs/Notebooks/mf_error_tutorial01.py +++ b/.docs/Notebooks/mf_error_tutorial01.py @@ -30,7 +30,7 @@ import flopy print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # #### Set the working directory diff --git a/.docs/Notebooks/mf_load_tutorial.py b/.docs/Notebooks/mf_load_tutorial.py index 4395bac9c..6f787a599 100644 --- a/.docs/Notebooks/mf_load_tutorial.py +++ b/.docs/Notebooks/mf_load_tutorial.py @@ -32,7 +32,7 @@ import flopy print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # ## The `load()` method diff --git a/.docs/Notebooks/mf_watertable_recharge_example.py b/.docs/Notebooks/mf_watertable_recharge_example.py index 2438718a6..814e2f6fa 100644 --- a/.docs/Notebooks/mf_watertable_recharge_example.py +++ b/.docs/Notebooks/mf_watertable_recharge_example.py @@ -39,9 +39,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Set name of MODFLOW exe diff --git a/.docs/Notebooks/mfusg_conduit_examples.py b/.docs/Notebooks/mfusg_conduit_examples.py index 5bb2b6c3c..8d5b5d2a5 100644 --- a/.docs/Notebooks/mfusg_conduit_examples.py +++ b/.docs/Notebooks/mfusg_conduit_examples.py @@ -274,7 +274,7 @@ raise ValueError("Failed to run.") # + -head_file = os.path.join(mf.model_ws, modelname + ".clnhd") +head_file = os.path.join(mf.model_ws, f"{modelname}.clnhd") headobj = flopy.utils.HeadFile(head_file) simtimes = headobj.get_times() @@ -298,7 +298,7 @@ ax.legend() # + -cbb_file = os.path.join(mf.model_ws, modelname + ".clncb") +cbb_file = os.path.join(mf.model_ws, f"{modelname}.clncb") cbb = flopy.utils.CellBudgetFile(cbb_file) # cbb.list_records() @@ -371,7 +371,7 @@ raise ValueError("Failed to run.") # + -head_file = os.path.join(mf.model_ws, modelname + ".clnhd") +head_file = os.path.join(mf.model_ws, f"{modelname}.clnhd") headobj = flopy.utils.HeadFile(head_file) simtimes = headobj.get_times() @@ -393,7 +393,7 @@ ax.set_title("MODFLOW USG Ex3b Conduit Unconfined") # + -cbb_file = os.path.join(mf.model_ws, modelname + ".clncb") +cbb_file = os.path.join(mf.model_ws, f"{modelname}.clncb") cbb = flopy.utils.CellBudgetFile(cbb_file) # cbb.list_records() @@ -467,7 +467,7 @@ raise ValueError("Failed to run.") # + -head_file = os.path.join(mf.model_ws, modelname + ".clnhd") +head_file = os.path.join(mf.model_ws, f"{modelname}.clnhd") headobj = flopy.utils.HeadFile(head_file) simtimes = headobj.get_times() @@ -491,7 +491,7 @@ ax.legend() # + -cbb_file = os.path.join(mf.model_ws, modelname + ".clncb") +cbb_file = os.path.join(mf.model_ws, f"{modelname}.clncb") cbb = flopy.utils.CellBudgetFile(cbb_file) # cbb.list_records() @@ -562,7 +562,7 @@ raise ValueError("Failed to run.") # + -head_file = os.path.join(mf.model_ws, modelname + ".clnhd") +head_file = os.path.join(mf.model_ws, f"{modelname}.clnhd") headobj = flopy.utils.HeadFile(head_file) simtimes = headobj.get_times() @@ -576,7 +576,7 @@ head_case4 = np.squeeze(simhead) # + -cbb_file = os.path.join(mf.model_ws, modelname + ".clncb") +cbb_file = os.path.join(mf.model_ws, f"{modelname}.clncb") cbb = flopy.utils.CellBudgetFile(cbb_file) # cbb.list_records() diff --git a/.docs/Notebooks/mfusg_zaidel_example.py b/.docs/Notebooks/mfusg_zaidel_example.py index b20c71025..61d961412 100644 --- a/.docs/Notebooks/mfusg_zaidel_example.py +++ b/.docs/Notebooks/mfusg_zaidel_example.py @@ -39,9 +39,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Set temporary workspace and MODFLOW executable diff --git a/.docs/Notebooks/modelgrid_examples.py b/.docs/Notebooks/modelgrid_examples.py index da0fc8658..ffb654159 100644 --- a/.docs/Notebooks/modelgrid_examples.py +++ b/.docs/Notebooks/modelgrid_examples.py @@ -51,9 +51,9 @@ from flopy.discretization import StructuredGrid, UnstructuredGrid, VertexGrid print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # set the names of our modflow executables @@ -147,9 +147,7 @@ proj4 = modelgrid.proj4 print( - "xoff: {}\nyoff: {}\nangrot: {}\nepsg: {}\nproj4: {}".format( - xoff, yoff, angrot, epsg, proj4 - ) + f"xoff: {xoff}\nyoff: {yoff}\nangrot: {angrot}\nepsg: {epsg}\nproj4: {proj4}" ) # - @@ -159,14 +157,12 @@ # + # show the coordinate info before setting it -print("Before: {}\n".format(modelgrid1)) +print(f"Before: {modelgrid1}\n") # set reference infromation -modelgrid1.set_coord_info( - xoff=xoff, yoff=yoff, angrot=angrot, crs=epsg -) +modelgrid1.set_coord_info(xoff=xoff, yoff=yoff, angrot=angrot, crs=epsg) -print("After: {}".format(modelgrid1)) +print(f"After: {modelgrid1}") # - # *__The user can also set individual parts of the coordinate information if they do not want to supply all of the fields__* @@ -196,7 +192,7 @@ modelgrid1.set_coord_info(angrot=rotation[ix]) pmv = flopy.plot.PlotMapView(modelgrid=modelgrid1, ax=ax) pmv.plot_grid() - ax.set_title("Modelgrid: {} degrees rotation".format(rotation[ix])) + ax.set_title(f"Modelgrid: {rotation[ix]} degrees rotation") # - # The grid lines can also be plotted directly from the modelgrid object @@ -443,7 +439,7 @@ def load_verts(fname): def load_iverts(fname): - f = open(fname, "r") + f = open(fname) iverts = [] xc = [] yc = [] @@ -501,8 +497,8 @@ def load_iverts(fname): ncpl = np.array(3 * [len(iverts)]) nnodes = np.sum(ncpl) -top = np.ones((nnodes)) -botm = np.ones((nnodes)) +top = np.ones(nnodes) +botm = np.ones(nnodes) # set top and botm elevations i0 = 0 @@ -604,9 +600,9 @@ def load_iverts(fname): # + # print grid info properties if modelgrid.is_valid and modelgrid.is_complete: - print("{} modelgrid is valid and complete\n".format(modelgrid.grid_type)) + print(f"{modelgrid.grid_type} modelgrid is valid and complete\n") -print("lenuni: {}, units: {}\n".format(modelgrid.lenuni, modelgrid.units)) +print(f"lenuni: {modelgrid.lenuni}, units: {modelgrid.units}\n") print( "lower left corner: ({0}, {2}), upper right corner: ({1}, {3})".format( @@ -626,15 +622,11 @@ def load_iverts(fname): # - `prjfile` : returns the path to the modelgrid projection file if it is set # Access and print some of these properties +print(f"xoffset: {modelgrid.xoffset}, yoffset: {modelgrid.yoffset}\n") print( - "xoffset: {}, yoffset: {}\n".format(modelgrid.xoffset, modelgrid.yoffset) -) -print( - "rotation (deg): {:.1f}, (rad): {:.4f}\n".format( - modelgrid.angrot, modelgrid.angrot_radians - ) + f"rotation (deg): {modelgrid.angrot:.1f}, (rad): {modelgrid.angrot_radians:.4f}\n" ) -print("proj4_str: {}".format(modelgrid.proj4)) +print(f"proj4_str: {modelgrid.proj4}") # #### Model discretization properties # @@ -656,9 +648,9 @@ def load_iverts(fname): # + # look at some model discretization information -print("Grid shape: {}\n".format(modelgrid.shape)) -print("number of cells per layer: {}\n".format(modelgrid.ncpl)) -print("number of cells in model: {}".format(modelgrid.nnodes)) +print(f"Grid shape: {modelgrid.shape}\n") +print(f"number of cells per layer: {modelgrid.ncpl}\n") +print(f"number of cells in model: {modelgrid.nnodes}") # + # plot the model cell vertices and cell centers @@ -701,7 +693,7 @@ def load_iverts(fname): ) pmv.plot_grid() pmv.plot_inactive() - ax.set_title("Modelgrid: {}".format(labels[ix])) + ax.set_title(f"Modelgrid: {labels[ix]}") plt.colorbar(pc) # - diff --git a/.docs/Notebooks/modflow_postprocessing_example.py b/.docs/Notebooks/modflow_postprocessing_example.py index 82c54f6c3..98259ce3a 100644 --- a/.docs/Notebooks/modflow_postprocessing_example.py +++ b/.docs/Notebooks/modflow_postprocessing_example.py @@ -37,9 +37,9 @@ ) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + mfnam = "EXAMPLE.nam" @@ -68,18 +68,18 @@ grid = m.modelgrid for i, hdslayer in enumerate(hds): im = axes[i].imshow(hdslayer, vmin=hds.min(), vmax=hds.max()) - axes[i].set_title("Layer {}".format(i + 1)) + axes[i].set_title(f"Layer {i + 1}") ctr = axes[i].contour(hdslayer, colors="k", linewidths=0.5) # export head rasters # (GeoTiff export requires the rasterio package; for ascii grids, just change the extension to *.asc) flopy.export.utils.export_array( - grid, os.path.join(workspace, "heads{}.tif".format(i + 1)), hdslayer + grid, os.path.join(workspace, f"heads{i + 1}.tif"), hdslayer ) # export head contours to a shapefile flopy.export.utils.export_array_contours( - grid, os.path.join(workspace, "heads{}.shp".format(i + 1)), hdslayer + grid, os.path.join(workspace, f"heads{i + 1}.shp"), hdslayer ) fig.delaxes(axes[-1]) @@ -100,9 +100,7 @@ grid, os.path.join(workspace, "heads5_rot.tif"), hdslayer, nodata=nodata ) -results = np.loadtxt( - os.path.join(workspace, "heads5_rot.asc".format(i + 1)), skiprows=6 -) +results = np.loadtxt(os.path.join(workspace, f"heads5_rot.asc"), skiprows=6) results[results == nodata] = np.nan plt.imshow(results) plt.colorbar() @@ -128,9 +126,7 @@ for i, vertical_gradient in enumerate(grad): im = axes[i].imshow(vertical_gradient, vmin=grad.min(), vmax=grad.max()) - axes[i].set_title( - "Vertical gradient\nbetween Layers {} and {}".format(i + 1, i + 2) - ) + axes[i].set_title(f"Vertical gradient\nbetween Layers {i + 1} and {i + 2}") ctr = axes[i].contour( vertical_gradient, levels=[-0.1, -0.05, 0.0, 0.05, 0.1], diff --git a/.docs/Notebooks/modpath6_example.py b/.docs/Notebooks/modpath6_example.py index 286820479..018d9a649 100644 --- a/.docs/Notebooks/modpath6_example.py +++ b/.docs/Notebooks/modpath6_example.py @@ -43,10 +43,10 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("pandas version: {}".format(pd.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"pandas version: {pd.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Load the MODFLOW model, then switch to a temporary working directory. diff --git a/.docs/Notebooks/modpath7_create_simulation_example.py b/.docs/Notebooks/modpath7_create_simulation_example.py index 4dc05b911..4e1d9644f 100644 --- a/.docs/Notebooks/modpath7_create_simulation_example.py +++ b/.docs/Notebooks/modpath7_create_simulation_example.py @@ -40,9 +40,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # temporary directory temp_dir = TemporaryDirectory() @@ -98,7 +98,7 @@ def get_nodes(locs): ) # Create the Flopy groundwater flow (gwf) model object -model_nam_file = "{}.nam".format(nm) +model_nam_file = f"{nm}.nam" gwf = flopy.mf6.ModflowGwf( sim, modelname=nm, model_nam_file=model_nam_file, save_flows=True ) @@ -148,9 +148,9 @@ def get_nodes(locs): rd.append([(0, i, ncol - 1), riv_h, riv_c, riv_z]) flopy.mf6.modflow.mfgwfriv.ModflowGwfriv(gwf, stress_period_data={0: rd}) # Create the output control package -headfile = "{}.hds".format(nm) +headfile = f"{nm}.hds" head_record = [headfile] -budgetfile = "{}.cbb".format(nm) +budgetfile = f"{nm}.cbb" budget_record = [budgetfile] saverecord = [("HEAD", "ALL"), ("BUDGET", "ALL")] oc = flopy.mf6.modflow.mfgwfoc.ModflowGwfoc( @@ -182,7 +182,7 @@ def get_nodes(locs): # + # create modpath files -mpnamf = nm + "_mp_forward" +mpnamf = f"{nm}_mp_forward" # create basic forward tracking modpath simulation mp = flopy.modpath.Modpath7.create_mp7( @@ -210,7 +210,7 @@ def get_nodes(locs): # + # create modpath files -mpnamb = nm + "_mp_backward" +mpnamb = f"{nm}_mp_backward" # create basic forward tracking modpath simulation mp = flopy.modpath.Modpath7.create_mp7( @@ -241,14 +241,14 @@ def get_nodes(locs): # Load forward tracking pathline data -fpth = os.path.join(ws, mpnamf + ".mppth") +fpth = os.path.join(ws, f"{mpnamf}.mppth") p = flopy.utils.PathlineFile(fpth) pw = p.get_destination_pathline_data(dest_cells=nodew) pr = p.get_destination_pathline_data(dest_cells=nodesr) # Load forward tracking endpoint data -fpth = os.path.join(ws, mpnamf + ".mpend") +fpth = os.path.join(ws, f"{mpnamf}.mpend") e = flopy.utils.EndpointFile(fpth) # Get forward particles that terminate in the well @@ -273,7 +273,7 @@ def get_nodes(locs): for k in range(nlay): ax = axes[idax] ax.set_aspect("equal") - ax.set_title("Well pathlines - Layer {}".format(k + 1)) + ax.set_title(f"Well pathlines - Layer {k + 1}") mm = flopy.plot.PlotMapView(model=gwf, ax=ax) mm.plot_grid(lw=0.5) mm.plot_pathline(pw, layer=k, colors=colors[k], lw=0.75) @@ -282,7 +282,7 @@ def get_nodes(locs): for k in range(nlay): ax = axes[idax] ax.set_aspect("equal") - ax.set_title("River pathlines - Layer {}".format(k + 1)) + ax.set_title(f"River pathlines - Layer {k + 1}") mm = flopy.plot.PlotMapView(model=gwf, ax=ax) mm.plot_grid(lw=0.5) mm.plot_pathline(pr, layer=k, colors=colors[k], lw=0.75) @@ -316,14 +316,14 @@ def get_nodes(locs): # # Load backward tracking pathlines -fpth = os.path.join(ws, mpnamb + ".mppth") +fpth = os.path.join(ws, f"{mpnamb}.mppth") p = flopy.utils.PathlineFile(fpth) pwb = p.get_destination_pathline_data(dest_cells=nodew) prb = p.get_destination_pathline_data(dest_cells=nodesr) # Load backward tracking endpoints -fpth = os.path.join(ws, mpnamb + ".mpend") +fpth = os.path.join(ws, f"{mpnamb}.mpend") e = flopy.utils.EndpointFile(fpth) ewb = e.get_destination_endpoint_data(dest_cells=nodew, source=True) erb = e.get_destination_endpoint_data(dest_cells=nodesr, source=True) diff --git a/.docs/Notebooks/modpath7_structured_example.py b/.docs/Notebooks/modpath7_structured_example.py index 6bb638f0f..ebf561190 100644 --- a/.docs/Notebooks/modpath7_structured_example.py +++ b/.docs/Notebooks/modpath7_structured_example.py @@ -40,9 +40,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # temporary directory temp_dir = TemporaryDirectory() @@ -176,7 +176,7 @@ # create modpath files exe_name = "mp7" mp = flopy.modpath.Modpath7( - modelname=nm + "_mp", flowmodel=m, exe_name=exe_name, model_ws=ws + modelname=f"{nm}_mp", flowmodel=m, exe_name=exe_name, model_ws=ws ) mpbas = flopy.modpath.Modpath7Bas(mp, porosity=0.1, defaultiface=defaultiface) mpsim = flopy.modpath.Modpath7Sim( @@ -216,7 +216,7 @@ # Pathline data -fpth = os.path.join(ws, nm + "_mp.mppth") +fpth = os.path.join(ws, f"{nm}_mp.mppth") p = flopy.utils.PathlineFile(fpth) pw0 = p.get_destination_pathline_data(nodew, to_recarray=True) pr0 = p.get_destination_pathline_data(nodesr, to_recarray=True) @@ -225,7 +225,7 @@ # # Get particles that terminate in the well -fpth = os.path.join(ws, nm + "_mp.mpend") +fpth = os.path.join(ws, f"{nm}_mp.mpend") e = flopy.utils.EndpointFile(fpth) well_epd = e.get_destination_endpoint_data(dest_cells=nodew) well_epd.shape @@ -270,7 +270,7 @@ ) # Create the Flopy groundwater flow (gwf) model object -model_nam_file = "{}.nam".format(nm) +model_nam_file = f"{nm}.nam" gwf = flopy.mf6.ModflowGwf( sim, modelname=nm, model_nam_file=model_nam_file, save_flows=True ) @@ -320,9 +320,9 @@ rd.append([(0, i, ncol - 1), riv_h, riv_c, riv_z]) flopy.mf6.modflow.mfgwfriv.ModflowGwfriv(gwf, stress_period_data={0: rd}) # Create the output control package -headfile = "{}.hds".format(nm) +headfile = f"{nm}.hds" head_record = [headfile] -budgetfile = "{}.cbb".format(nm) +budgetfile = f"{nm}.cbb" budget_record = [budgetfile] saverecord = [("HEAD", "ALL"), ("BUDGET", "ALL")] oc = flopy.mf6.modflow.mfgwfoc.ModflowGwfoc( @@ -348,7 +348,7 @@ # create modpath files exe_name = "mp7" mp = flopy.modpath.Modpath7( - modelname=nm + "_mp", flowmodel=gwf, exe_name=exe_name, model_ws=ws + modelname=f"{nm}_mp", flowmodel=gwf, exe_name=exe_name, model_ws=ws ) mpbas = flopy.modpath.Modpath7Bas(mp, porosity=0.1, defaultiface=defaultiface6) mpsim = flopy.modpath.Modpath7Sim( @@ -382,7 +382,7 @@ # # Pathline data -fpth = os.path.join(ws, nm + "_mp.mppth") +fpth = os.path.join(ws, f"{nm}_mp.mppth") p = flopy.utils.PathlineFile(fpth) pw1 = p.get_destination_pathline_data(nodew, to_recarray=True) pr1 = p.get_destination_pathline_data(nodesr, to_recarray=True) @@ -391,7 +391,7 @@ # # Get particles that terminate in the well -fpth = os.path.join(ws, nm + "_mp.mpend") +fpth = os.path.join(ws, f"{nm}_mp.mpend") e = flopy.utils.EndpointFile(fpth) well_epd = e.get_destination_endpoint_data(dest_cells=nodew) diff --git a/.docs/Notebooks/modpath7_structured_transient_example.py b/.docs/Notebooks/modpath7_structured_transient_example.py index dac6f53c6..717b77a3e 100644 --- a/.docs/Notebooks/modpath7_structured_transient_example.py +++ b/.docs/Notebooks/modpath7_structured_transient_example.py @@ -53,9 +53,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") temp_dir = TemporaryDirectory() sim_name = "mp7_ex03a_mf6" @@ -165,7 +165,7 @@ def fill_zone_1(): ) # groundwater flow (gwf) model -model_nam_file = "{}.nam".format(sim_name) +model_nam_file = f"{sim_name}.nam" gwf = flopy.mf6.ModflowGwf( sim, modelname=sim_name, model_nam_file=model_nam_file, save_flows=True ) @@ -231,9 +231,9 @@ def no_flow(w): drn = flopy.mf6.modflow.mfgwfdrn.ModflowGwfdrn(gwf, stress_period_data={0: dd}) # output control -headfile = "{}.hds".format(sim_name) +headfile = f"{sim_name}.hds" head_record = [headfile] -budgetfile = "{}.cbb".format(sim_name) +budgetfile = f"{sim_name}.cbb" budget_record = [budgetfile] saverecord = [("HEAD", "ALL"), ("BUDGET", "ALL")] oc = flopy.mf6.modflow.mfgwfoc.ModflowGwfoc( diff --git a/.docs/Notebooks/modpath7_unstructured_example.py b/.docs/Notebooks/modpath7_unstructured_example.py index ca69fa873..8842954b2 100644 --- a/.docs/Notebooks/modpath7_unstructured_example.py +++ b/.docs/Notebooks/modpath7_unstructured_example.py @@ -44,9 +44,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # temporary directory temp_dir = TemporaryDirectory() @@ -206,7 +206,7 @@ # create gwf model gwf = flopy.mf6.ModflowGwf( - sim, modelname=model_name, model_nam_file="{}.nam".format(model_name) + sim, modelname=model_name, model_nam_file=f"{model_name}.nam" ) gwf.name_file.save_flows = True @@ -277,8 +277,8 @@ oc = flopy.mf6.ModflowGwfoc( gwf, pname="oc", - budget_filerecord="{}.cbb".format(model_name), - head_filerecord="{}.hds".format(model_name), + budget_filerecord=f"{model_name}.cbb", + head_filerecord=f"{model_name}.hds", headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], @@ -300,7 +300,7 @@ # Plot the boundary conditions on the grid. -fname = os.path.join(model_ws, model_name + ".disv.grb") +fname = os.path.join(model_ws, f"{model_name}.disv.grb") grd = flopy.mf6.utils.MfGrdFile(fname, verbose=False) mg = grd.modelgrid ibd = np.zeros((ncpl), dtype=int) @@ -321,7 +321,7 @@ pc = pmv.plot_array(ibd, cmap=cmap, edgecolor="gray") t = ax.set_title("Boundary Conditions\n") -fname = os.path.join(model_ws, model_name + ".hds") +fname = os.path.join(model_ws, f"{model_name}.hds") hdobj = flopy.utils.HeadFile(fname) head = hdobj.get_data() head.shape @@ -340,9 +340,7 @@ cs = mm.contour_array(head[:, 0, :], colors="white", levels=levels) plt.clabel(cs, fmt="%.1f", colors="white", fontsize=11) cb = plt.colorbar(pc, shrink=0.5) -t = ax.set_title( - "Model Layer {}; hmin={:6.2f}, hmax={:6.2f}".format(ilay + 1, hmin, hmax) -) +t = ax.set_title(f"Model Layer {ilay + 1}; hmin={hmin:6.2f}, hmax={hmax:6.2f}") # Inspect model cells and vertices. @@ -379,8 +377,8 @@ # # Define names for the MODPATH 7 simulations. -mp_namea = model_name + "a_mp" -mp_nameb = model_name + "b_mp" +mp_namea = f"{model_name}a_mp" +mp_nameb = f"{model_name}b_mp" # Create particles for the pathline and timeseries analysis. @@ -419,7 +417,7 @@ ) # create backward particle group -fpth = mp_namea + ".sloc" +fpth = f"{mp_namea}.sloc" pga = flopy.modpath.ParticleGroup( particlegroupname="BACKWARD1", particledata=pa, filename=fpth ) @@ -444,7 +442,7 @@ ) pb = flopy.modpath.NodeParticleData(subdivisiondata=facedata, nodes=nodew) # create forward particle group -fpth = mp_nameb + ".sloc" +fpth = f"{mp_nameb}.sloc" pgb = flopy.modpath.ParticleGroupNodeTemplate( particlegroupname="BACKWARD2", particledata=pb, filename=fpth ) diff --git a/.docs/Notebooks/modpath7_unstructured_lateral_example.py b/.docs/Notebooks/modpath7_unstructured_lateral_example.py index 56e325654..b201dfd53 100644 --- a/.docs/Notebooks/modpath7_unstructured_lateral_example.py +++ b/.docs/Notebooks/modpath7_unstructured_lateral_example.py @@ -525,7 +525,7 @@ # + mp = flopy.modpath.Modpath7( - modelname=sim_name + "_mp", + modelname=f"{sim_name}_mp", flowmodel=gwf, exe_name="mp7", model_ws=workspace, diff --git a/.docs/Notebooks/mt3d-usgs_example.py b/.docs/Notebooks/mt3d-usgs_example.py index 51eb38a18..54abb150f 100644 --- a/.docs/Notebooks/mt3d-usgs_example.py +++ b/.docs/Notebooks/mt3d-usgs_example.py @@ -52,9 +52,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + temp_dir = TemporaryDirectory() @@ -302,15 +302,15 @@ def calc_strtElev(X, Y): # remember that lay, row, col need to be zero-based and are adjusted accordingly by flopy # layer + row + col + iseg + irch + rchlen + strtop + slope + strthick + strmbed K - s1 += "0,{}".format(1) - s1 += ",{}".format(y) - s1 += ",{}".format(iseg) - s1 += ",{}".format(irch) - s1 += ",{}".format(delr) - s1 += ",{}".format(strmBed_Elev[y]) - s1 += ",{}".format(0.0001) - s1 += ",{}".format(0.50) - s1 += ",{}\n".format(strhc1) + s1 += f"0,{1}" + s1 += f",{y}" + s1 += f",{iseg}" + s1 += f",{irch}" + s1 += f",{delr}" + s1 += f",{strmBed_Elev[y]}" + s1 += f",{0.0001}" + s1 += f",{0.50}" + s1 += f",{strhc1}\n" fpth = os.path.join(modelpth, "s1.csv") @@ -331,10 +331,7 @@ def calc_strtElev(X, Y): ("strhc1", " (3, 0): - f = open(fpth, "rb") -else: - f = open(fpth, "r") +f = open(fpth, "rb") reach_data = np.genfromtxt(f, delimiter=",", names=True, dtype=dtype) f.close() @@ -352,10 +349,7 @@ def calc_strtElev(X, Y): f.write(s2) f.close() -if sys.version_info > (3, 0): - f = open(fpth, "rb") -else: - f = open(fpth, "r") +f = open(fpth, "rb") segment_data = np.genfromtxt(f, delimiter=",", names=True) f.close() @@ -557,7 +551,7 @@ def calc_strtElev(X, Y): # + # Define a function to read SFT output file def load_ts_from_SFT_output(fname, nd=1): - f = open(fname, "r") + f = open(fname) iline = 0 lst = [] for line in f: @@ -576,7 +570,7 @@ def load_ts_from_SFT_output(fname, nd=1): # Also define a function to read OTIS output file def load_ts_from_otis(fname, iobs=1): - f = open(fname, "r") + f = open(fname) iline = 0 lst = [] for line in f: diff --git a/.docs/Notebooks/mt3dms_examples.py b/.docs/Notebooks/mt3dms_examples.py index 8d1627e81..51352e412 100644 --- a/.docs/Notebooks/mt3dms_examples.py +++ b/.docs/Notebooks/mt3dms_examples.py @@ -64,9 +64,9 @@ workdir = temp_dir.name print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - @@ -99,7 +99,7 @@ def p01(dirname, al, retardation, lambda1, mixelm): rhob = 0.25 kd = (retardation - 1.0) * prsity / rhob - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -132,7 +132,7 @@ def p01(dirname, al, retardation, lambda1, mixelm): else: raise ValueError("Failed to run.") - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -289,7 +289,7 @@ def p02(dirname, isothm, sp1, sp2, mixelm): laytyp = 0 rhob = 1.587 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -317,7 +317,7 @@ def p02(dirname, isothm, sp1, sp2, mixelm): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -407,7 +407,7 @@ def p02(dirname, isothm, sp1, sp2, mixelm): plt.legend() for beta in [0, 2.0e-3, 1.0e-2, 20.0]: - lbl = "beta={}".format(beta) + lbl = f"beta={beta}" mf, mt, conc, cvt, mvt = p02("nonequilibrium", 4, 0.933, beta, -1) x = cvt["time"] y = cvt["(1, 1, 51)"] / 0.05 @@ -444,7 +444,7 @@ def p03(dirname, mixelm): hk = 1.0 laytyp = 0 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -473,7 +473,7 @@ def p03(dirname, mixelm): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -580,7 +580,7 @@ def p04(dirname, mixelm): hk = 1.0 laytyp = 0 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -616,7 +616,7 @@ def p04(dirname, mixelm): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -738,7 +738,7 @@ def p05(dirname, mixelm, dt0, ttsmult): hk = 1.0 laytyp = 0 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -765,7 +765,7 @@ def p05(dirname, mixelm, dt0, ttsmult): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -883,7 +883,7 @@ def p06(dirname, mixelm, dt0): hk = 0.005 * 86400 laytyp = 0 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -912,7 +912,7 @@ def p06(dirname, mixelm, dt0): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -1031,7 +1031,7 @@ def p07(dirname, mixelm): hk = 0.5 laytyp = 0 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -1060,7 +1060,7 @@ def p07(dirname, mixelm): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -1131,7 +1131,7 @@ def p07(dirname, mixelm): plt.clabel(cs) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {}".format(ilay + 1)) +plt.title(f"LAYER {ilay + 1}") ax = fig.add_subplot(3, 1, 2, aspect="equal") ilay = 5 @@ -1142,7 +1142,7 @@ def p07(dirname, mixelm): plt.clabel(cs) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {}".format(ilay + 1)) +plt.title(f"LAYER {ilay + 1}") ax = fig.add_subplot(3, 1, 3, aspect="equal") ilay = 6 @@ -1153,7 +1153,7 @@ def p07(dirname, mixelm): plt.clabel(cs) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {}".format(ilay + 1)) +plt.title(f"LAYER {ilay + 1}") plt.plot(grid.xcellcenters[7, 2], grid.ycellcenters[7, 2], "ko") plt.tight_layout() @@ -1189,7 +1189,7 @@ def p08(dirname, mixelm): hk[11:19, :, 36:] = k2 laytyp = 6 * [1] + 21 * [0] - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -1220,7 +1220,7 @@ def p08(dirname, mixelm): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -1355,7 +1355,7 @@ def p09(dirname, mixelm, nadvfd): hk = k1 * np.ones((nlay, nrow, ncol), dtype=float) hk[:, 5:8, 1:8] = k2 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -1387,7 +1387,7 @@ def p09(dirname, mixelm, nadvfd): mf.write_input() mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -1558,7 +1558,7 @@ def p10(dirname, mixelm, perlen=1000, isothm=1, sp2=0.0, ttsmult=1.2): vka = 0.1 laytyp = 0 - modelname_mf = dirname + "_mf" + modelname_mf = f"{dirname}_mf" mf = flopy.modflow.Modflow( modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf ) @@ -1613,7 +1613,7 @@ def p10(dirname, mixelm, perlen=1000, isothm=1, sp2=0.0, ttsmult=1.2): os.remove(fname) mf.run_model(silent=True) - modelname_mt = dirname + "_mt" + modelname_mt = f"{dirname}_mt" mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, @@ -1717,7 +1717,7 @@ def p10(dirname, mixelm, perlen=1000, isothm=1, sp2=0.0, ttsmult=1.2): plt.ylim(9100, 9100 + 45 * 50) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {} INITIAL CONCENTRATION".format(3)) +plt.title(f"LAYER {3} INITIAL CONCENTRATION") for k, i, j, q in mf.wel.stress_period_data[0]: plt.plot(grid.xcellcenters[i, j], grid.ycellcenters[i, j], "ks") @@ -1732,7 +1732,7 @@ def p10(dirname, mixelm, perlen=1000, isothm=1, sp2=0.0, ttsmult=1.2): plt.ylim(9100, 9100 + 45 * 50) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {} TIME = 500 DAYS".format(3)) +plt.title(f"LAYER {3} TIME = 500 DAYS") for k, i, j, q in mf.wel.stress_period_data[0]: plt.plot(grid.xcellcenters[i, j], grid.ycellcenters[i, j], "ks") @@ -1747,7 +1747,7 @@ def p10(dirname, mixelm, perlen=1000, isothm=1, sp2=0.0, ttsmult=1.2): plt.ylim(9100, 9100 + 45 * 50) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {} TIME = 750 DAYS".format(3)) +plt.title(f"LAYER {3} TIME = 750 DAYS") for k, i, j, q in mf.wel.stress_period_data[0]: plt.plot(grid.xcellcenters[i, j], grid.ycellcenters[i, j], "ks") @@ -1762,7 +1762,7 @@ def p10(dirname, mixelm, perlen=1000, isothm=1, sp2=0.0, ttsmult=1.2): plt.ylim(9100, 9100 + 45 * 50) plt.xlabel("DISTANCE ALONG X-AXIS, IN METERS") plt.ylabel("DISTANCE ALONG Y-AXIS, IN METERS") -plt.title("LAYER {} TIME = 1000 DAYS".format(3)) +plt.title(f"LAYER {3} TIME = 1000 DAYS") for k, i, j, q in mf.wel.stress_period_data[0]: plt.plot(grid.xcellcenters[i, j], grid.ycellcenters[i, j], "ks") diff --git a/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py b/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py index e37df9ee7..4b91941de 100644 --- a/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py +++ b/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py @@ -47,9 +47,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Create a MODFLOW model and store it, in this case in the variable 'mf'. @@ -441,7 +441,7 @@ bdlknc_lyr1 = LakArr_lyr1.copy() bdlknc_lyr2 = LakArr_lyr1.copy() -bdlknc_lyr3 = np.zeros((LakArr_lyr1.shape)) +bdlknc_lyr3 = np.zeros(LakArr_lyr1.shape) # Need to expand bdlknc_lyr1 non-zero values by 1 in either direction # (left/right and up/down) diff --git a/.docs/Notebooks/mt3dms_ssm_package_tutorial.py b/.docs/Notebooks/mt3dms_ssm_package_tutorial.py index 05f3c0398..292bb66e5 100644 --- a/.docs/Notebooks/mt3dms_ssm_package_tutorial.py +++ b/.docs/Notebooks/mt3dms_ssm_package_tutorial.py @@ -37,8 +37,8 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"flopy version: {flopy.__version__}") # - # First, we will create a simple model structure @@ -156,8 +156,8 @@ # And finally, modify the ```vdf``` package to fix ```indense```. -fname = modelname + ".vdf" -f = open(os.path.join(model_ws, fname), "r") +fname = f"{modelname}.vdf" +f = open(os.path.join(model_ws, fname)) lines = f.readlines() f.close() f = open(os.path.join(model_ws, fname), "w") diff --git a/.docs/Notebooks/nwt_option_blocks_tutorial.py b/.docs/Notebooks/nwt_option_blocks_tutorial.py index 48ff4a736..e57063a52 100644 --- a/.docs/Notebooks/nwt_option_blocks_tutorial.py +++ b/.docs/Notebooks/nwt_option_blocks_tutorial.py @@ -38,7 +38,7 @@ from flopy.utils import OptionBlock print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # + load_ws = os.path.join("..", "..", "examples", "data", "options", "sagehen") diff --git a/.docs/Notebooks/pest_tutorial01.py b/.docs/Notebooks/pest_tutorial01.py index 02775a2d6..02e36e75b 100644 --- a/.docs/Notebooks/pest_tutorial01.py +++ b/.docs/Notebooks/pest_tutorial01.py @@ -33,8 +33,8 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"flopy version: {flopy.__version__}") # - # This notebook will work with a simple model using the dimensions below @@ -87,7 +87,7 @@ # At this point, the lpf template file will have been created. The following block will print the template file. -lines = open(os.path.join(workspace, "mymodel.lpf.tpl"), "r").readlines() +lines = open(os.path.join(workspace, "mymodel.lpf.tpl")).readlines() for l in lines: print(l.strip()) @@ -114,7 +114,7 @@ tw.write_template() # - -lines = open(os.path.join(workspace, "mymodel.lpf.tpl"), "r").readlines() +lines = open(os.path.join(workspace, "mymodel.lpf.tpl")).readlines() for l in lines: print(l.strip()) @@ -160,7 +160,7 @@ tw.write_template() # Print contents of template file -lines = open(os.path.join(workspace, "mymodel.lpf.tpl"), "r").readlines() +lines = open(os.path.join(workspace, "mymodel.lpf.tpl")).readlines() for l in lines: print(l.strip()) @@ -210,7 +210,7 @@ tw.write_template() # Print the results -lines = open(os.path.join(workspace, "mymodel.rch.tpl"), "r").readlines() +lines = open(os.path.join(workspace, "mymodel.rch.tpl")).readlines() for l in lines: print(l.strip()) @@ -260,7 +260,7 @@ tw.write_template() # Print the results -lines = open(os.path.join(workspace, "mymodel.rch.tpl"), "r").readlines() +lines = open(os.path.join(workspace, "mymodel.rch.tpl")).readlines() for l in lines: print(l.strip()) # - diff --git a/.docs/Notebooks/plot_array_example.py b/.docs/Notebooks/plot_array_example.py index a2bd4f3e6..92a4f81c7 100644 --- a/.docs/Notebooks/plot_array_example.py +++ b/.docs/Notebooks/plot_array_example.py @@ -41,9 +41,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + # Set name of MODFLOW exe @@ -82,10 +82,10 @@ # confirm that the model files have been created for f in files: if os.path.isfile(os.path.join(modelpth, f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # - diff --git a/.docs/Notebooks/plot_cross_section_example.py b/.docs/Notebooks/plot_cross_section_example.py index a17f1b12f..910c532d2 100644 --- a/.docs/Notebooks/plot_cross_section_example.py +++ b/.docs/Notebooks/plot_cross_section_example.py @@ -45,9 +45,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + pycharm={"name": "#%%\n"} # Set names of the MODFLOW exes @@ -83,10 +83,10 @@ files = ["freyberg.hds", "freyberg.cbc"] for f in files: if os.path.isfile(os.path.join(str(modelpth), f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + [markdown] pycharm={"name": "#%% md\n"} @@ -438,10 +438,10 @@ files = ["freyberg.hds", "freyberg.cbc"] for f in files: if os.path.isfile(os.path.join(str(modelpth), f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + [markdown] pycharm={"name": "#%% md\n"} @@ -537,10 +537,10 @@ files = ["mp7p2.hds", "mp7p2.cbb"] for f in files: if os.path.isfile(os.path.join(modelpth, f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + pycharm={"name": "#%%\n"} @@ -754,7 +754,7 @@ with styles.USGSPlot(): fig, axes = plt.subplots(3, 1, figsize=(15, 9), tight_layout=True) for ix, totim in enumerate(plot_times): - heading = "Time = {}".format(totim) + heading = f"Time = {totim}" conc = cobj.get_data(totim=totim) ax = axes[ix] xsect = flopy.plot.PlotCrossSection(model=gwf6, ax=ax, line={"row": 0}) diff --git a/.docs/Notebooks/plot_map_view_example.py b/.docs/Notebooks/plot_map_view_example.py index d24854c7a..837e790a5 100644 --- a/.docs/Notebooks/plot_map_view_example.py +++ b/.docs/Notebooks/plot_map_view_example.py @@ -47,9 +47,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + pycharm={"name": "#%%\n"} # Set name of MODFLOW exe @@ -86,10 +86,10 @@ files = ["freyberg.hds", "freyberg.cbc"] for f in files: if os.path.isfile(os.path.join(modelpth, f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + [markdown] pycharm={"name": "#%% md\n"} @@ -437,7 +437,7 @@ # construct maximum travel time to plot (200 years - MODFLOW time unit is seconds) travel_time_max = 200.0 * 365.25 * 24.0 * 60.0 * 60.0 -ctt = "<={}".format(travel_time_max) +ctt = f"<={travel_time_max}" # plot the pathlines mapview.plot_pathline(plines, layer="all", colors="red", travel_time=ctt) @@ -607,10 +607,10 @@ files = ["freyberg.hds", "freyberg.cbc"] for f in files: if os.path.isfile(os.path.join(modelpth, f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + [markdown] pycharm={"name": "#%% md\n"} @@ -716,10 +716,10 @@ files = ["mp7p2.hds", "mp7p2.cbb"] for f in files: if os.path.isfile(os.path.join(modelpth, f)): - msg = "Output file located: {}".format(f) + msg = f"Output file located: {f}" print(msg) else: - errmsg = "Error. Output file cannot be found: {}".format(f) + errmsg = f"Error. Output file cannot be found: {f}" print(errmsg) # + pycharm={"name": "#%%\n"} @@ -820,11 +820,11 @@ # + pycharm={"name": "#%%\n"} # load the MODPATH-7 results mp_namea = "mp7p2a_mp" -fpth = os.path.join(modelpth, mp_namea + ".mppth") +fpth = os.path.join(modelpth, f"{mp_namea}.mppth") p = flopy.utils.PathlineFile(fpth) p0 = p.get_alldata() -fpth = os.path.join(modelpth, mp_namea + ".timeseries") +fpth = os.path.join(modelpth, f"{mp_namea}.timeseries") ts = flopy.utils.TimeseriesFile(fpth) ts0 = ts.get_alldata() @@ -899,7 +899,7 @@ def load_verts(fname): def load_iverts(fname): - f = open(fname, "r") + f = open(fname) iverts = [] xc = [] yc = [] @@ -926,11 +926,11 @@ def load_iverts(fname): # + pycharm={"name": "#%%\n"} # Print the first 5 entries in verts and iverts for ivert, v in enumerate(verts[:5]): - print("Vertex coordinate pair for vertex {}: {}".format(ivert, v)) + print(f"Vertex coordinate pair for vertex {ivert}: {v}") print("...\n") for icell, vertlist in enumerate(iverts[:5]): - print("List of vertices for cell {}: {}".format(icell, vertlist)) + print(f"List of vertices for cell {icell}: {vertlist}") # + [markdown] pycharm={"name": "#%% md\n"} # A flopy `UnstructuredGrid` object can now be created using the vertices and incidence list. The `UnstructuredGrid` object is a key part of the plotting capabilities in flopy. In addition to the vertex information, the `UnstructuredGrid` object also needs to know how many cells are in each layer. This is specified in the ncpl variable, which is a list of cells per layer. @@ -954,7 +954,7 @@ def load_iverts(fname): # Create a random array for layer 0, and then plot it with a color flood and contours f = plt.figure(figsize=(10, 10)) -a = np.random.random((ncpl[0])) * 100 +a = np.random.random(ncpl[0]) * 100 levels = np.arange(0, 100, 30) mapview = flopy.plot.PlotMapView(modelgrid=umg) diff --git a/.docs/Notebooks/raster_intersection_example.py b/.docs/Notebooks/raster_intersection_example.py index 599ce8bc9..da466c67d 100644 --- a/.docs/Notebooks/raster_intersection_example.py +++ b/.docs/Notebooks/raster_intersection_example.py @@ -47,11 +47,11 @@ from flopy.utils import Raster print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("pandas version: {}".format(pd.__version__)) -print("shapely version: {}".format(shapely.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"pandas version: {pd.__version__}") +print(f"shapely version: {shapely.__version__}") +print(f"flopy version: {flopy.__version__}") # - # temporary directory @@ -151,7 +151,7 @@ ax = pmv.plot_array( dem_data, masked_values=rio.nodatavals, vmin=vmin, vmax=vmax ) -plt.title("Resample time, nearest neighbor: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, nearest neighbor: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # - @@ -170,7 +170,7 @@ ax = pmv.plot_array( dem_data, masked_values=rio.nodatavals, vmin=vmin, vmax=vmax ) -plt.title("Resample time, bi-linear: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, bi-linear: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # - @@ -189,7 +189,7 @@ ax = pmv.plot_array( dem_data, masked_values=rio.nodatavals, vmin=vmin, vmax=vmax ) -plt.title("Resample time, bi-cubic: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, bi-cubic: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # - @@ -211,7 +211,7 @@ ax = pmv.plot_array( dem_data, masked_values=rio.nodatavals, vmin=vmin, vmax=vmax ) -plt.title("Resample time, median: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, median: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # - @@ -279,7 +279,7 @@ vmin=vmin, vmax=vmax, ) -plt.title("Resample time, nearest neighbor: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, nearest neighbor: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # + @@ -303,7 +303,7 @@ vmin=vmin, vmax=vmax, ) -plt.title("Resample time, bi-linear: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, bi-linear: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # + @@ -329,7 +329,7 @@ vmin=vmin, vmax=vmax, ) -plt.title("Resample time, median: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, median: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # - @@ -431,7 +431,7 @@ ax = rio.plot(ax=ax, vmin=vmin, vmax=vmax) ax.plot(shape.T[0], shape.T[1], "r-") -plt.title("Cropping time: {:.3f} sec".format(crop_time)) +plt.title(f"Cropping time: {crop_time:.3f} sec") plt.colorbar(ax.images[0], shrink=0.7) # - @@ -459,7 +459,7 @@ vmax=vmax, ) plt.plot(shape.T[0], shape.T[1], "r-") -plt.title("Resample time, nearest neighbor: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, nearest neighbor: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # + @@ -484,7 +484,7 @@ vmax=vmax, ) plt.plot(shape.T[0], shape.T[1], "r-") -plt.title("Resample time, bi-linear: {:.3f} sec".format(resample_time)) +plt.title(f"Resample time, bi-linear: {resample_time:.3f} sec") plt.colorbar(ax, shrink=0.7) # - @@ -533,7 +533,7 @@ shape = np.array(polygon).T plt.plot(shape[0], shape[1], "r-") -plt.title("Cropped Arbitrary Polygon: {:.3f} sec".format(crop_time)) +plt.title(f"Cropped Arbitrary Polygon: {crop_time:.3f} sec") plt.colorbar(ax.images[0], shrink=0.7) # - diff --git a/.docs/Notebooks/save_binary_data_file_example.py b/.docs/Notebooks/save_binary_data_file_example.py index 051d502e2..ff7d0a3fe 100644 --- a/.docs/Notebooks/save_binary_data_file_example.py +++ b/.docs/Notebooks/save_binary_data_file_example.py @@ -39,9 +39,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + nlay, nrow, ncol = 1, 20, 10 diff --git a/.docs/Notebooks/seawat_henry_example.py b/.docs/Notebooks/seawat_henry_example.py index 9d68ab030..417e20b04 100644 --- a/.docs/Notebooks/seawat_henry_example.py +++ b/.docs/Notebooks/seawat_henry_example.py @@ -33,8 +33,8 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"flopy version: {flopy.__version__}") # + pycharm={"name": "#%%\n"} # temporary directory @@ -152,8 +152,8 @@ # Try to delete the output files, to prevent accidental use of older files try: os.remove(os.path.join(workspace, "MT3D001.UCN")) - os.remove(os.path.join(workspace, modelname + ".hds")) - os.remove(os.path.join(workspace, modelname + ".cbc")) + os.remove(os.path.join(workspace, f"{modelname}.hds")) + os.remove(os.path.join(workspace, f"{modelname}.cbc")) except: pass diff --git a/.docs/Notebooks/sfrpackage_example.py b/.docs/Notebooks/sfrpackage_example.py index 517a1cdb8..292f7d6fe 100644 --- a/.docs/Notebooks/sfrpackage_example.py +++ b/.docs/Notebooks/sfrpackage_example.py @@ -50,10 +50,10 @@ mpl.rcParams["figure.figsize"] = (11, 8.5) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("pandas version: {}".format(pd.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"pandas version: {pd.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Set name of MODFLOW exe diff --git a/.docs/Notebooks/shapefile_export_example.py b/.docs/Notebooks/shapefile_export_example.py index 95377b71f..8026c86d2 100644 --- a/.docs/Notebooks/shapefile_export_example.py +++ b/.docs/Notebooks/shapefile_export_example.py @@ -38,9 +38,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # + # temporary directory @@ -71,7 +71,7 @@ # ## Declarative export using attached `.export()` methods # #### Export the whole model to a single shapefile -fname = "{}/model.shp".format(outdir) +fname = f"{outdir}/model.shp" m.export(fname) ax = plt.subplot(1, 1, 1, aspect="equal") @@ -81,7 +81,7 @@ ax.set_ylim(extents[2], extents[3]) ax.set_title(fname) -fname = "{}/wel.shp".format(outdir) +fname = f"{outdir}/wel.shp" m.wel.export(fname) # ### Export a package to a shapefile @@ -90,8 +90,8 @@ m.lpf.hk -fname = "{}/hk.shp".format(outdir) -m.lpf.hk.export("{}/hk.shp".format(outdir)) +fname = f"{outdir}/hk.shp" +m.lpf.hk.export(f"{outdir}/hk.shp") ax = plt.subplot(1, 1, 1, aspect="equal") extents = grid.extent @@ -103,14 +103,14 @@ m.riv.stress_period_data -m.riv.stress_period_data.export("{}/riv_spd.shp".format(outdir)) +m.riv.stress_period_data.export(f"{outdir}/riv_spd.shp") # ### MfList.export() exports the whole grid by default, regardless of the locations of the boundary cells # `sparse=True` only exports the boundary cells in the MfList -m.riv.stress_period_data.export("{}/riv_spd.shp".format(outdir), sparse=True) +m.riv.stress_period_data.export(f"{outdir}/riv_spd.shp", sparse=True) -m.wel.stress_period_data.export("{}/wel_spd.shp".format(outdir), sparse=True) +m.wel.stress_period_data.export(f"{outdir}/wel_spd.shp", sparse=True) # ## Ad-hoc exporting using `recarray2shp` # * The main idea is to create a recarray with all of the attribute information, and a list of geometry features (one feature per row in the recarray) @@ -142,7 +142,7 @@ # ##### write the shapefile -fname = "{}/bcs.shp".format(outdir) +fname = f"{outdir}/bcs.shp" recarray2shp(spd.to_records(), geoms=polygons, shpname=fname, crs=grid.epsg) ax = plt.subplot(1, 1, 1, aspect="equal") @@ -172,7 +172,7 @@ geoms = [Point(x, y) for x, y in zip(welldata.x_utm, welldata.y_utm)] -fname = "{}/wel_data.shp".format(outdir) +fname = f"{outdir}/wel_data.shp" recarray2shp(welldata.to_records(), geoms=geoms, shpname=fname, crs=grid.epsg) # - @@ -202,7 +202,7 @@ rivdata = pd.DataFrame(m.riv.stress_period_data[0]) rivdata["reach"] = np.arange(len(lines)) -lines_shapefile = "{}/riv_reaches.shp".format(outdir) +lines_shapefile = f"{outdir}/riv_reaches.shp" recarray2shp( rivdata.to_records(index=False), geoms=lines, @@ -271,12 +271,12 @@ ) # exporting an entire model -m.export("{}/freyberg.shp".format(outdir), modelgrid=modelgrid) +m.export(f"{outdir}/freyberg.shp", modelgrid=modelgrid) # - # And for a specific parameter the method is the same -fname = "{}/hk.shp".format(outdir) +fname = f"{outdir}/hk.shp" m.lpf.hk.export(fname, modelgrid=modelgrid) ax = plt.subplot(1, 1, 1, aspect="equal") diff --git a/.docs/Notebooks/shapefile_feature_examples.py b/.docs/Notebooks/shapefile_feature_examples.py index c43a08d62..4d0bf9ff7 100644 --- a/.docs/Notebooks/shapefile_feature_examples.py +++ b/.docs/Notebooks/shapefile_feature_examples.py @@ -45,9 +45,9 @@ warnings.simplefilter("ignore", UserWarning) print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # ### write a numpy record array to a shapefile diff --git a/.docs/Notebooks/swi2package_example1.py b/.docs/Notebooks/swi2package_example1.py index 7f9ac1c1e..4241716e6 100644 --- a/.docs/Notebooks/swi2package_example1.py +++ b/.docs/Notebooks/swi2package_example1.py @@ -40,9 +40,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Define model name of your model and the location of MODFLOW executable. All MODFLOW files and output will be stored in the subdirectory defined by the workspace. Create a model named `ml` and specify that this is a MODFLOW-2005 model. @@ -147,11 +147,11 @@ # Load the head and zeta data from the file # read model heads -hfile = flopy.utils.HeadFile(os.path.join(ml.model_ws, modelname + ".hds")) +hfile = flopy.utils.HeadFile(os.path.join(ml.model_ws, f"{modelname}.hds")) head = hfile.get_alldata() # read model zeta zfile = flopy.utils.CellBudgetFile( - os.path.join(ml.model_ws, modelname + ".zta") + os.path.join(ml.model_ws, f"{modelname}.zta") ) kstpkper = zfile.get_kstpkper() zeta = [] diff --git a/.docs/Notebooks/swi2package_example4.py b/.docs/Notebooks/swi2package_example4.py index 48db513d9..5ecac1b63 100644 --- a/.docs/Notebooks/swi2package_example4.py +++ b/.docs/Notebooks/swi2package_example4.py @@ -45,9 +45,9 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Define model name of your model and the location of MODFLOW executable. All MODFLOW files and output will be stored in the subdirectory defined by the workspace. Create a model named `ml` and specify that this is a MODFLOW-2005 model. @@ -307,7 +307,7 @@ # read base model zeta zfile = flopy.utils.CellBudgetFile( - os.path.join(ml.model_ws, modelname + ".zta") + os.path.join(ml.model_ws, f"{modelname}.zta") ) kstpkper = zfile.get_kstpkper() zeta = [] @@ -316,14 +316,14 @@ zeta = np.array(zeta) # read swi obs zobs = np.genfromtxt( - os.path.join(ml.model_ws, modelname + ".zobs.out"), names=True + os.path.join(ml.model_ws, f"{modelname}.zobs.out"), names=True ) # Load the simulation 2 `ZETA` data and `ZETA` observations. # read saltwater well model zeta zfile2 = flopy.utils.CellBudgetFile( - os.path.join(ml2.model_ws, modelname2 + ".zta") + os.path.join(ml2.model_ws, f"{modelname2}.zta") ) kstpkper = zfile2.get_kstpkper() zeta2 = [] @@ -332,7 +332,7 @@ zeta2 = np.array(zeta2) # read swi obs zobs2 = np.genfromtxt( - os.path.join(ml2.model_ws, modelname2 + ".zobs.out"), names=True + os.path.join(ml2.model_ws, f"{modelname2}.zobs.out"), names=True ) # Create arrays for the x-coordinates and the output years @@ -379,7 +379,7 @@ drawstyle="steps-mid", linewidth=0.5, color=cc[idx], - label="{:2d} years".format(years[idx]), + label=f"{years[idx]:2d} years", ) # layer 2 ax.plot( @@ -437,7 +437,7 @@ drawstyle="steps-mid", linewidth=0.5, color=cc[idx - 5], - label="{:2d} years".format(years[idx]), + label=f"{years[idx]:2d} years", ) # layer 2 ax.plot( @@ -495,7 +495,7 @@ drawstyle="steps-mid", linewidth=0.5, color=cc[idx - 5], - label="{:2d} years".format(years[idx]), + label=f"{years[idx]:2d} years", ) # layer 2 ax.plot( @@ -613,14 +613,14 @@ zeta[4, :, :, :], colors=colors, ax=ax, edgecolors="none" ) linecollection = modelxsect.plot_grid(ax=ax) -ax.set_title("Recharge year {}".format(years[4])) +ax.set_title(f"Recharge year {years[4]}") ax = fig.add_subplot(1, 2, 2) ax.set_xlim(0, 3050) ax.set_ylim(-50, -10) modelxsect.plot_fill_between(zeta[-1, :, :, :], colors=colors, ax=ax) linecollection = modelxsect.plot_grid(ax=ax) -ax.set_title("Scenario year {}".format(years[-1])) +ax.set_title(f"Scenario year {years[-1]}") # - try: diff --git a/.docs/Notebooks/uzf_example.py b/.docs/Notebooks/uzf_example.py index 529d6fa20..67f934d0a 100644 --- a/.docs/Notebooks/uzf_example.py +++ b/.docs/Notebooks/uzf_example.py @@ -52,10 +52,10 @@ from flopy.utils import flopy_io print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("pandas version: {}".format(pd.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"pandas version: {pd.__version__}") +print(f"flopy version: {flopy.__version__}") # - # Set name of MODFLOW exe @@ -240,7 +240,7 @@ uzfbdobjct = flopy.utils.CellBudgetFile(fpth) uzfbdobjct.list_records() else: - print('"{}" is not available'.format(fpth)) + print(f'"{fpth}" is not available') if success and avail: r = uzfbdobjct.get_data(text="UZF RECHARGE") diff --git a/.docs/Notebooks/vtk_pathlines_example.py b/.docs/Notebooks/vtk_pathlines_example.py index ec649fa9d..647c8d56f 100644 --- a/.docs/Notebooks/vtk_pathlines_example.py +++ b/.docs/Notebooks/vtk_pathlines_example.py @@ -29,7 +29,7 @@ import flopy print(sys.version) -print("flopy version: {}".format(flopy.__version__)) +print(f"flopy version: {flopy.__version__}") # - # Load the Freyberg MF6 groundwater flow model. diff --git a/.docs/Notebooks/zonebudget_example.py b/.docs/Notebooks/zonebudget_example.py index 4ec326c67..fa48a8a17 100644 --- a/.docs/Notebooks/zonebudget_example.py +++ b/.docs/Notebooks/zonebudget_example.py @@ -43,10 +43,10 @@ import flopy print(sys.version) -print("numpy version: {}".format(np.__version__)) -print("matplotlib version: {}".format(mpl.__version__)) -print("pandas version: {}".format(pd.__version__)) -print("flopy version: {}".format(flopy.__version__)) +print(f"numpy version: {np.__version__}") +print(f"matplotlib version: {mpl.__version__}") +print(f"pandas version: {pd.__version__}") +print(f"flopy version: {flopy.__version__}") # + # temporary workspace @@ -119,9 +119,9 @@ rowidx = np.in1d(cmdbud["name"], names) colidx = "ZONE_1" -print("{:,.1f} cubic meters/day".format(cmdbud[rowidx][colidx][0])) -print("{:,.1f} cubic feet/day".format(cfdbud[rowidx][colidx][0])) -print("{:,.1f} inches/year".format(inyrbud[rowidx][colidx][0])) +print(f"{cmdbud[rowidx][colidx][0]:,.1f} cubic meters/day") +print(f"{cfdbud[rowidx][colidx][0]:,.1f} cubic feet/day") +print(f"{inyrbud[rowidx][colidx][0]:,.1f} inches/year") # - cmd is cfd @@ -205,7 +205,7 @@ print(pd.read_csv(f_out).to_string(index=False)) except: - with open(f_out, "r") as f: + with open(f_out) as f: for line in f.readlines(): print("\t".join(line.split(","))) # - @@ -236,7 +236,7 @@ # + def tick_label_formatter_comma_sep(x, pos): - return "{:,.0f}".format(x) + return f"{x:,.0f}" def volumetric_budget_bar_plot(values_in, values_out, labels, **kwargs): @@ -268,7 +268,7 @@ def volumetric_budget_bar_plot(values_in, values_out, labels, **kwargs): plt.ylim([ymin, ymax * 1.25]) for i, rect in enumerate(rects_in): - label = "{:,.0f}".format(values_in[i]) + label = f"{values_in[i]:,.0f}" height = values_in[i] x = rect.get_x() + rect.get_width() / 2 y = height + (0.02 * ymax) @@ -284,7 +284,7 @@ def volumetric_budget_bar_plot(values_in, values_out, labels, **kwargs): ) for i, rect in enumerate(rects_out): - label = "{:,.0f}".format(values_out[i]) + label = f"{values_out[i]:,.0f}" height = values_out[i] x = rect.get_x() + rect.get_width() / 2 y = height + (0.02 * ymin) @@ -325,10 +325,8 @@ def volumetric_budget_bar_plot(values_in, values_out, labels, **kwargs): ) recname = "STORAGE" - values_in = zb.get_dataframes(names="FROM_{}".format(recname)).T.squeeze() - values_out = ( - zb.get_dataframes(names="TO_{}".format(recname)).T.squeeze() * -1 - ) + values_in = zb.get_dataframes(names=f"FROM_{recname}").T.squeeze() + values_out = zb.get_dataframes(names=f"TO_{recname}").T.squeeze() * -1 labels = values_in.index.tolist() rects_in, rects_out = volumetric_budget_bar_plot( @@ -336,7 +334,7 @@ def volumetric_budget_bar_plot(values_in, values_out, labels, **kwargs): ) plt.ylabel("Volumetric rate, in Mgal/d") - plt.title("{} @ totim = {}".format(recname, t)) + plt.title(f"{recname} @ totim = {t}") plt.tight_layout() plt.show()