From 4118618a1c4632cecfc701c179a4bd9750606ed3 Mon Sep 17 00:00:00 2001 From: w-bonelli Date: Thu, 23 Feb 2023 00:15:08 -0500 Subject: [PATCH] feat(pathlike): support pathlike throughout public interface --- autotest/regression/test_mf6.py | 464 +++++++++--------- autotest/regression/test_mf6_examples.py | 6 +- autotest/regression/test_mfnwt.py | 14 +- autotest/regression/test_modflow.py | 66 +-- autotest/regression/test_str.py | 14 +- autotest/regression/test_swi2.py | 2 +- autotest/regression/test_wel.py | 12 +- autotest/test_binaryfile.py | 80 ++- autotest/test_binarygrid_util.py | 12 +- autotest/test_cbc_full3D.py | 10 +- autotest/test_compare.py | 2 +- autotest/test_conftest.py | 16 - autotest/test_copy.py | 4 +- autotest/test_export.py | 173 +++---- autotest/test_flopy_module.py | 8 +- autotest/test_formattedfile.py | 8 +- autotest/test_gage.py | 16 +- autotest/test_grid.py | 40 +- autotest/test_gridgen.py | 52 +- autotest/test_gridintersect.py | 12 +- autotest/test_headufile.py | 9 +- autotest/test_hydmodfile.py | 14 +- autotest/test_lake_connections.py | 40 +- autotest/test_lgr.py | 6 +- autotest/test_listbudget.py | 46 +- autotest/test_mf6.py | 38 +- autotest/test_mfnwt.py | 18 +- autotest/test_mnw.py | 4 +- autotest/test_modflow.py | 84 ++-- autotest/test_modpathfile.py | 12 +- autotest/test_mp5.py | 4 +- autotest/test_mp6.py | 91 ++-- autotest/test_mp6_cases.py | 6 +- autotest/test_mp7.py | 58 +-- autotest/test_mp7_cases.py | 6 +- autotest/test_mt3d.py | 180 +++---- autotest/test_nwt_ag.py | 16 +- autotest/test_obs.py | 20 +- autotest/test_pcg.py | 2 +- autotest/test_plot.py | 40 +- autotest/test_postprocessing.py | 22 +- autotest/test_seawat.py | 16 +- autotest/test_sfr.py | 86 ++-- autotest/test_specific_discharge.py | 38 +- autotest/test_str.py | 6 +- autotest/test_subwt.py | 10 +- autotest/test_swr_binaryread.py | 12 +- autotest/test_template_writer.py | 12 +- autotest/test_usg.py | 86 ++-- autotest/test_util_2d_and_3d.py | 52 +- autotest/test_uzf.py | 80 +-- autotest/test_zonbud_utility.py | 84 ++-- .../modflow6data/tutorial08_mf6_data.py | 6 +- flopy/discretization/structuredgrid.py | 5 +- flopy/discretization/unstructuredgrid.py | 5 +- flopy/export/netcdf.py | 3 + flopy/export/utils.py | 45 +- flopy/mbase.py | 216 ++++---- flopy/modflow/mf.py | 9 +- flopy/utils/compare.py | 68 +-- flopy/utils/mfreadnam.py | 9 +- flopy/utils/rasters.py | 9 +- flopy/utils/util_array.py | 4 +- flopy/utils/zonbud.py | 3 +- 64 files changed, 1241 insertions(+), 1350 deletions(-) diff --git a/autotest/regression/test_mf6.py b/autotest/regression/test_mf6.py index fb55913b44..f46e47193e 100644 --- a/autotest/regression/test_mf6.py +++ b/autotest/regression/test_mf6.py @@ -61,13 +61,13 @@ def test_np001(function_tmpdir, example_data_path): test_ex_name = "np001" model_name = "np001_mod" data_path = example_data_path / "mf6" / "create_tests" / test_ex_name - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" # copy example data into working directory shutil.copytree(data_path, ws) - expected_output_folder = str(data_path / "expected_output") - expected_head_file = os.path.join(expected_output_folder, "np001_mod.hds") - expected_cbc_file = os.path.join(expected_output_folder, "np001_mod.cbc") + expected_output_folder = data_path / "expected_output" + expected_head_file = expected_output_folder / "np001_mod.hds" + expected_cbc_file = expected_output_folder / "np001_mod.cbc" # model tests test_sim = MFSimulation( @@ -112,10 +112,10 @@ def test_np001(function_tmpdir, example_data_path): sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(data_path), + sim_ws=data_path, write_headers=False, ) - sim.set_sim_path(str(ws)) + sim.set_sim_path(ws) tdis_rc = [(6.0, 2, 1.0), (6.0, 3, 1.0)] tdis_package = ModflowTdis( sim, time_units="DAYS", nper=1, perioddata=[(2.0, 1, 1.0)] @@ -395,7 +395,7 @@ def test_np001(function_tmpdir, example_data_path): # inspect cells cell_list = [(0, 0, 0), (0, 0, 4), (0, 0, 9)] - out_file = str(function_tmpdir / "inspect_test_np001.csv") + out_file = function_tmpdir / "inspect_test_np001.csv" model.inspect_cells(cell_list, output_file_path=out_file, stress_period=0) # get expected results @@ -408,8 +408,8 @@ def test_np001(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) # budget_frf = sim.simulation_data.mfdata[(model_name, "CBC", "RIV")] @@ -431,7 +431,7 @@ def test_np001(function_tmpdir, example_data_path): wel_path = os.path.join(ws, md_folder, "well_folder", f"{model_name}.wel") assert os.path.exists(wel_path) # test data file was recreated by set_all_data_external - riv_path = str( + riv_path = ( function_tmpdir / "data" / "np001_mod.riv_stress_period_data_1.txt" ) assert os.path.exists(riv_path) @@ -452,8 +452,8 @@ def test_np001(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -630,12 +630,12 @@ def test_np002(function_tmpdir, example_data_path): test_ex_name = "np002" model_name = "np002_mod" data_folder = example_data_path / "mf6" / "create_tests" / test_ex_name - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" # copy example data into working directory shutil.copytree(data_folder, ws) expected_output_folder = data_folder / "expected_output" - expected_head_file = str(expected_output_folder / "np002_mod.hds") - expected_cbc_file = str(expected_output_folder / "np002_mod.cbc") + expected_head_file = expected_output_folder / "np002_mod.hds" + expected_cbc_file = expected_output_folder / "np002_mod.cbc" # create simulation sim = MFSimulation( @@ -795,7 +795,7 @@ def test_np002(function_tmpdir, example_data_path): sim.run_simulation() cell_list = [(0, 0, 0), (0, 0, 3), (0, 0, 4), (0, 0, 9)] - out_file = str(function_tmpdir / "inspect_test_np002.csv") + out_file = function_tmpdir / "inspect_test_np002.csv" model.inspect_cells(cell_list, output_file_path=out_file) sim2 = MFSimulation.load(sim_ws=ws) @@ -809,8 +809,8 @@ def test_np002(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -884,11 +884,11 @@ def test_np002(function_tmpdir, example_data_path): # test paths sim_path_test = Path(ws) / "sim_path" - sim.set_sim_path(str(sim_path_test)) + sim.set_sim_path(sim_path_test) model.set_model_relative_path("model") # make external data folder path relative to simulation folder sim_data = sim_path_test / "data" - sim.set_all_data_external(external_data_folder=str(sim_data)) + sim.set_all_data_external(external_data_folder=sim_data) sim.write_simulation() # test assert Path(sim_data, "np002_mod.dis_botm.txt").exists() @@ -903,10 +903,8 @@ def test021_twri(function_tmpdir, example_data_path): # init paths test_ex_name = "test021_twri" model_name = "twri" - data_folder = str( - example_data_path / "mf6" / "create_tests" / test_ex_name - ) - ws = str(function_tmpdir / "ws") + data_folder = example_data_path / "mf6" / "create_tests" / test_ex_name + ws = function_tmpdir / "ws" # copy example data into working directory shutil.copytree(data_folder, ws) @@ -921,7 +919,7 @@ def test021_twri(function_tmpdir, example_data_path): exe_name="mf6", sim_ws=data_folder, ) - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) tdis_rc = [(86400.0, 1, 1.0)] tdis_package = ModflowTdis( sim, time_units="SECONDS", nper=1, perioddata=tdis_rc @@ -1111,8 +1109,8 @@ def test021_twri(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -1129,11 +1127,11 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path): model_name = "AdvGW_tidal" pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = pth / "expected_output" - expected_head_file = str(expected_output_folder / "AdvGW_tidal.hds") + expected_head_file = expected_output_folder / "AdvGW_tidal.hds" # create simulation sim = MFSimulation( - sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=str(pth) + sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=pth ) # test tdis package deletion tdis_package = ModflowTdis( @@ -1642,14 +1640,14 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() sim.write_simulation() # test time series data file with relative path to simulation path - ts_path = str(function_tmpdir / "well-rates" / "well-rates.ts") + ts_path = function_tmpdir / "well-rates" / "well-rates.ts" assert os.path.exists(ts_path) # run simulation @@ -1657,17 +1655,17 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path): # inspect cells cell_list = [(2, 3, 2), (0, 4, 2), (0, 2, 4), (0, 5, 5), (0, 9, 9)] - out_file = str(function_tmpdir / "inspect_AdvGW_tidal.csv") + out_file = function_tmpdir / "inspect_AdvGW_tidal.csv" model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(function_tmpdir / "AdvGW_tidal.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "AdvGW_tidal.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -1681,12 +1679,12 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path): assert filename == f"new_name.{package.package_type}" package_type_dict[package.package_type] = 1 sim.write_simulation() - name_file = str(function_tmpdir / "new_name.nam") + name_file = function_tmpdir / "new_name.nam" assert os.path.exists(name_file) - dis_file = str(function_tmpdir / "new_name.dis") + dis_file = function_tmpdir / "new_name.dis" assert os.path.exists(dis_file) # test time series data file with relative path to simulation path - ts_path = str(function_tmpdir / "well-rates" / "new_name.ts") + ts_path = function_tmpdir / "well-rates" / "new_name.ts" assert os.path.exists(ts_path) sim.rename_all_packages("all_files_same_name") @@ -1700,14 +1698,14 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path): for ims_file in sim._solution_files.values(): assert ims_file.filename == "all_files_same_name.ims" sim.write_simulation() - name_file = str(function_tmpdir / "all_files_same_name.nam") + name_file = function_tmpdir / "all_files_same_name.nam" assert os.path.exists(name_file) - dis_file = str(function_tmpdir / "all_files_same_name.dis") + dis_file = function_tmpdir / "all_files_same_name.dis" assert os.path.exists(dis_file) - tdis_file = str(function_tmpdir / "all_files_same_name.tdis") + tdis_file = function_tmpdir / "all_files_same_name.tdis" assert os.path.exists(tdis_file) # test time series data file with relative path to simulation path - ts_path = str(function_tmpdir / "well-rates" / "all_files_same_name.ts") + ts_path = function_tmpdir / "well-rates" / "all_files_same_name.ts" assert os.path.exists(ts_path) # load simulation @@ -1752,7 +1750,7 @@ def test004_create_tests_bcfss(function_tmpdir, example_data_path): # init paths test_ex_name = "test004_bcfss" model_name = "bcf2ss" - pth = str(example_data_path / "mf6" / "create_tests" / test_ex_name) + pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "bcf2ss.hds") @@ -1917,7 +1915,7 @@ def test004_create_tests_bcfss(function_tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() @@ -1927,13 +1925,13 @@ def test004_create_tests_bcfss(function_tmpdir, example_data_path): sim.run_simulation() # compare output to expected results - head_new = os.path.join(str(function_tmpdir), "bcf2ss.hds") - outfile = os.path.join(str(function_tmpdir), "head_compare.dat") + head_new = function_tmpdir / "bcf2ss.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -1947,7 +1945,7 @@ def test035_create_tests_fhb(function_tmpdir, example_data_path): # init paths test_ex_name = "test035_fhb" model_name = "fhb2015" - pth = str(example_data_path / "mf6" / "create_tests" / test_ex_name) + pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join( expected_output_folder, "fhb2015_fhb.hds" @@ -2057,7 +2055,7 @@ def test035_create_tests_fhb(function_tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() @@ -2067,13 +2065,13 @@ def test035_create_tests_fhb(function_tmpdir, example_data_path): sim.run_simulation() # compare output to expected results - head_new = str(function_tmpdir / "fhb2015_fhb.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "fhb2015_fhb.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -2090,16 +2088,16 @@ def test006_create_tests_gwf3_disv(function_tmpdir, example_data_path): model_name = "flow" data_path = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = data_path / "expected_output" - expected_head_file = str(expected_output_folder / "flow.hds") + expected_head_file = expected_output_folder / "flow.hds" # create simulation sim = MFSimulation( sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(data_path), + sim_ws=data_path, ) - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) tdis_rc = [(1.0, 1, 1.0)] tdis_package = ModflowTdis( sim, time_units="DAYS", nper=1, perioddata=tdis_rc @@ -2339,7 +2337,7 @@ def test006_create_tests_gwf3_disv(function_tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.write_simulation() @@ -2349,17 +2347,17 @@ def test006_create_tests_gwf3_disv(function_tmpdir, example_data_path): # inspect cells cell_list = [(0, 0), (0, 7), (0, 17)] - out_file = str(function_tmpdir / "inspect_test_gwf3_disv.csv") + out_file = function_tmpdir / "inspect_test_gwf3_disv.csv" model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(function_tmpdir / "flow.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "flow.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -2367,7 +2365,7 @@ def test006_create_tests_gwf3_disv(function_tmpdir, example_data_path): # model.export(os.path.join(run_folder, "test006_gwf3.nc")) # export to shape file - model.export(str(function_tmpdir / "test006_gwf3.shp")) + model.export(function_tmpdir / "test006_gwf3.shp") # clean up sim.delete_output_files() @@ -2380,7 +2378,7 @@ def test006_create_tests_2models_gnc(function_tmpdir, example_data_path): test_ex_name = "test006_2models_gnc" model_name_1 = "model1" model_name_2 = "model2" - pth = str(example_data_path / "mf6" / "create_tests" / test_ex_name) + pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_1 = os.path.join(expected_output_folder, "model1.hds") @@ -2645,50 +2643,50 @@ def test006_create_tests_2models_gnc(function_tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.write_simulation() # test gnc file was created in correct location - gnc_full_path = str(function_tmpdir / gnc_path) + gnc_full_path = function_tmpdir / gnc_path assert os.path.exists(gnc_full_path) # run simulation sim.run_simulation() # compare output to expected results - head_new = str(function_tmpdir / "model1.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "model1.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file_1, - files2=head_new, + files1=[expected_head_file_1], + files2=[head_new], outfile=outfile, ) # compare output to expected results - head_new = str(function_tmpdir / "model2.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "model2.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file_2, - files2=head_new, + files1=[expected_head_file_2], + files2=[head_new], outfile=outfile, ) # test external file paths - sim_path = str(function_tmpdir / "path_test") + sim_path = function_tmpdir / "path_test" sim.set_sim_path(sim_path) model_1.set_model_relative_path("model1") model_2.set_model_relative_path("model2") sim.set_all_data_external(external_data_folder=function_tmpdir / "data") sim.write_simulation() - ext_file_path_1 = str(function_tmpdir / "data" / "model1.dis_botm.txt") + ext_file_path_1 = function_tmpdir / "data" / "model1.dis_botm.txt" assert os.path.exists(ext_file_path_1) - ext_file_path_2 = str(function_tmpdir / "data" / "model2.dis_botm.txt") + ext_file_path_2 = function_tmpdir / "data" / "model2.dis_botm.txt" assert os.path.exists(ext_file_path_2) # test gnc file was created in correct location gnc_full_path = os.path.join(sim_path, gnc_path) @@ -2698,7 +2696,7 @@ def test006_create_tests_2models_gnc(function_tmpdir, example_data_path): sim.delete_output_files() # test rename all packages - rename_folder = str(function_tmpdir / "rename") + rename_folder = function_tmpdir / "rename" sim.rename_all_packages("file_rename") sim.set_sim_path(rename_folder) sim.write_simulation() @@ -2719,11 +2717,11 @@ def test050_create_tests_circle_island(function_tmpdir, example_data_path): model_name = "ci" pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = pth / "expected_output" - expected_head_file = str(expected_output_folder / "ci.output.hds") + expected_head_file = expected_output_folder / "ci.output.hds" # create simulation sim = MFSimulation( - sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=str(pth) + sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=pth ) tdis_rc = [(1.0, 1, 1.0)] tdis_package = ModflowTdis( @@ -2784,7 +2782,7 @@ def test050_create_tests_circle_island(function_tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() @@ -2794,13 +2792,13 @@ def test050_create_tests_circle_island(function_tmpdir, example_data_path): sim.run_simulation() # compare output to expected results - head_new = str(function_tmpdir / "ci.output.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "ci.output.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) @@ -2820,11 +2818,11 @@ def test028_create_tests_sfr(function_tmpdir, example_data_path): model_name = "test1tr" pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = pth / "expected_output" - expected_head_file = str(expected_output_folder / "test1tr.hds") + expected_head_file = expected_output_folder / "test1tr.hds" # create simulation sim = MFSimulation( - sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=str(pth) + sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=pth ) sim.name_file.continue_.set_data(True) tdis_rc = [(1577889000, 50, 1.1), (1577889000, 50, 1.1)] @@ -2991,13 +2989,13 @@ def test028_create_tests_sfr(function_tmpdir, example_data_path): assert sfr_package.connectiondata.get_data()[2][1] == 1.0 assert sfr_package.packagedata.get_data()[1][1].lower() == "none" - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) sim.write_simulation() sim.load( sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) model = sim.get_model(model_name) sfr_package = model.get_package("sfr") @@ -3061,17 +3059,17 @@ def test028_create_tests_sfr(function_tmpdir, example_data_path): # inspect cells cell_list = [(0, 2, 3), (0, 3, 4), (0, 4, 5)] - out_file = str(function_tmpdir / "inspect_test028_sfr.csv") + out_file = function_tmpdir / "inspect_test028_sfr.csv" model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(function_tmpdir / "test1tr.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "test1tr.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, htol=10.0, ) @@ -3088,8 +3086,8 @@ def test_create_tests_transport(function_tmpdir, example_data_path): name = "mst03" pth = example_data_path / "mf6" / "create_tests" / test_ex_name expected_output_folder = pth / "expected_output" - expected_head_file = str(expected_output_folder / "gwf_mst03.hds") - expected_conc_file = str(expected_output_folder / "gwt_mst03.unc") + expected_head_file = expected_output_folder / "gwf_mst03.hds" + expected_conc_file = expected_output_folder / "gwt_mst03.unc" laytyp = [1] ss = [1.0e-10] @@ -3120,7 +3118,7 @@ def test_create_tests_transport(function_tmpdir, example_data_path): sim_name=name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) # create tdis package tdis = ModflowTdis(sim, time_units="DAYS", nper=nper, perioddata=tdis_rc) @@ -3289,22 +3287,22 @@ def test_create_tests_transport(function_tmpdir, example_data_path): cell_list = [ (0, 0, 0), ] - out_file = str(function_tmpdir / "inspect_transport_gwf.csv") + out_file = function_tmpdir / "inspect_transport_gwf.csv" gwf.inspect_cells(cell_list, output_file_path=out_file) - out_file = str(function_tmpdir / "inspect_transport_gwt.csv") + out_file = function_tmpdir / "inspect_transport_gwt.csv" gwt.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(function_tmpdir / "gwf_mst03.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "gwf_mst03.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file, - files2=head_new, + files1=[expected_head_file], + files2=[head_new], outfile=outfile, ) - conc_new = str(function_tmpdir / "gwt_mst03.ucn") + conc_new = function_tmpdir / "gwt_mst03.ucn" assert compare_concentrations( None, None, @@ -3326,7 +3324,7 @@ def test001a_tharmonic(function_tmpdir, example_data_path): test_ex_name = "test001a_Tharmonic" model_name = "flow15" - pth = str(example_data_path / "mf6" / test_ex_name) + pth = example_data_path / "mf6" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( expected_output_folder, "flow15_flow_unch.hds" @@ -3353,13 +3351,13 @@ def test001a_tharmonic(function_tmpdir, example_data_path): verify_data=True, write_headers=False, ) - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external(external_data_folder="data") sim.write_simulation(silent=True) # verify external data written to correct location - data_folder = str(function_tmpdir / "data" / "flow15.dis_botm.txt") + data_folder = function_tmpdir / "data" / "flow15.dis_botm.txt" assert os.path.exists(data_folder) # model export test model = sim.get_model(model_name) @@ -3382,9 +3380,9 @@ def test001a_tharmonic(function_tmpdir, example_data_path): ) # compare output to expected results - head_new = str(function_tmpdir / "flow15_flow.hds") + head_new = function_tmpdir / "flow15_flow.hds" assert compare_heads( - None, None, files1=expected_head_file_a, files2=head_new + None, None, files1=[expected_head_file_a], files2=[head_new] ) budget_frf = sim.simulation_data.mfdata[ @@ -3422,7 +3420,7 @@ def test001a_tharmonic(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -3436,9 +3434,9 @@ def test001a_tharmonic(function_tmpdir, example_data_path): ) # compare output to expected results - head_new = os.path.join(str(save_folder), "flow15_flow.hds") + head_new = os.path.join(save_folder, "flow15_flow.hds") assert compare_heads( - None, None, files1=expected_head_file_b, files2=head_new + None, None, files1=[expected_head_file_b], files2=[head_new] ) budget_frf = sim.simulation_data.mfdata[ @@ -3455,20 +3453,20 @@ def test003_gwfs_disv(function_tmpdir, example_data_path): model_name = "gwf_1" data_folder = example_data_path / "mf6" / test_ex_name expected_output_folder = data_folder / "expected_output" - expected_head_file_a = str(expected_output_folder / "model_unch.hds") - expected_head_file_b = str(expected_output_folder / "model_adj.hds") - expected_cbc_file_a = str(expected_output_folder / "model_unch.cbc") - expected_cbc_file_b = str(expected_output_folder / "model_adj.cbc") + expected_head_file_a = expected_output_folder / "model_unch.hds" + expected_head_file_b = expected_output_folder / "model_adj.hds" + expected_cbc_file_a = expected_output_folder / "model_unch.cbc" + expected_cbc_file_b = expected_output_folder / "model_adj.cbc" array_util = PyListUtil() # load simulation sim = MFSimulation.load( - model_name, "mf6", "mf6", str(data_folder), verify_data=True + model_name, "mf6", "mf6", data_folder, verify_data=True ) # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.simulation_data.max_columns_of_data = 10 @@ -3484,9 +3482,9 @@ def test003_gwfs_disv(function_tmpdir, example_data_path): budget_obj.get_data(text=" FLOW JA FACE", full3D=True) ) - head_new = os.path.join(str(function_tmpdir), "model.hds") + head_new = os.path.join(function_tmpdir, "model.hds") assert compare_heads( - None, None, files1=expected_head_file_a, files2=head_new + None, None, files1=[expected_head_file_a], files2=[head_new] ) budget_frf = sim.simulation_data.mfdata[ @@ -3495,7 +3493,7 @@ def test003_gwfs_disv(function_tmpdir, example_data_path): assert array_util.array_comp(budget_fjf_valid, budget_frf) model = sim.get_model(model_name) - model.export(str(function_tmpdir / f"{test_ex_name}.shp")) + model.export(function_tmpdir / f"{test_ex_name}.shp") # change some settings chd_head_left = model.get_package("CHD_LEFT") @@ -3512,7 +3510,7 @@ def test003_gwfs_disv(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -3526,9 +3524,9 @@ def test003_gwfs_disv(function_tmpdir, example_data_path): ) # compare output to expected results - head_new = os.path.join(str(save_folder), "model.hds") + head_new = os.path.join(save_folder, "model.hds") assert compare_heads( - None, None, files1=expected_head_file_b, files2=head_new + None, None, files1=[expected_head_file_b], files2=[head_new] ) budget_frf = sim.simulation_data.mfdata[ @@ -3544,7 +3542,7 @@ def test005_advgw_tidal(function_tmpdir, example_data_path): # init paths test_ex_name = "test005_advgw_tidal" model_name = "gwf_1" - pth = str(example_data_path / "mf6" / test_ex_name) + pth = example_data_path / "mf6" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( expected_output_folder, "AdvGW_tidal_unch.hds" @@ -3580,7 +3578,7 @@ def test005_advgw_tidal(function_tmpdir, example_data_path): ghb.stress_period_data.set_data(spd) # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() @@ -3591,13 +3589,13 @@ def test005_advgw_tidal(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = os.path.join(str(function_tmpdir), "advgw_tidal.hds") - outfile = os.path.join(str(function_tmpdir), "head_compare.dat") + head_new = os.path.join(function_tmpdir, "advgw_tidal.hds") + outfile = os.path.join(function_tmpdir, "head_compare.dat") assert compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], outfile=outfile, ) @@ -3610,18 +3608,16 @@ def test006_gwf3(function_tmpdir, example_data_path): model_name = "gwf_1" pth = example_data_path / "mf6" / test_ex_name expected_output_folder = pth / "expected_output" - expected_head_file_a = str(expected_output_folder / "flow_unch.hds") - expected_head_file_b = str(expected_output_folder / "flow_adj.hds") - expected_cbc_file_a = str(expected_output_folder / "flow_unch.cbc") - expected_cbc_file_b = str(expected_output_folder / "flow_adj.cbc") + expected_head_file_a = expected_output_folder / "flow_unch.hds" + expected_head_file_b = expected_output_folder / "flow_adj.hds" + expected_cbc_file_a = expected_output_folder / "flow_unch.cbc" + expected_cbc_file_b = expected_output_folder / "flow_adj.cbc" array_util = PyListUtil() # load simulation - sim = MFSimulation.load( - model_name, "mf6", "mf6", str(pth), verify_data=True - ) - sim.set_sim_path(str(function_tmpdir)) + sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) + sim.set_sim_path(function_tmpdir) model = sim.get_model() disu = model.get_package("disu") # test switching disu array to internal array @@ -3639,7 +3635,7 @@ def test006_gwf3(function_tmpdir, example_data_path): } # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() sim.write_simulation() @@ -3650,7 +3646,7 @@ def test006_gwf3(function_tmpdir, example_data_path): # inspect cells cell_list = [(0,), (7,), (14,)] - out_file = str(function_tmpdir / "inspect_test006_gwf3.csv") + out_file = function_tmpdir / "inspect_test006_gwf3.csv" model.inspect_cells(cell_list, output_file_path=out_file) budget_obj = CellBudgetFile(expected_cbc_file_a, precision="double") @@ -3661,12 +3657,12 @@ def test006_gwf3(function_tmpdir, example_data_path): budget_fjf_valid.shape = (-1, jaentries) # compare output to expected results - head_new = os.path.join(str(function_tmpdir), "flow.hds") + head_new = function_tmpdir / "flow.hds" assert compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], ) budget_fjf = np.array( @@ -3692,7 +3688,7 @@ def test006_gwf3(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -3712,8 +3708,8 @@ def test006_gwf3(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], ) budget_fjf = np.array( @@ -3726,7 +3722,7 @@ def test006_gwf3(function_tmpdir, example_data_path): # confirm that files did move save_folder = function_tmpdir / "save02" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) # write with "copy_external_files" turned off so external files do not get copied to new location sim.write_simulation(ext_file_action=ExtFileAction.copy_none) @@ -3760,8 +3756,8 @@ def test006_gwf3(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], ) budget_fjf = np.array( @@ -3790,7 +3786,7 @@ def test045_lake1ss_table(function_tmpdir, example_data_path): # init paths test_ex_name = "test045_lake1ss_table" model_name = "lakeex1b" - pth = str(example_data_path / "mf6" / test_ex_name) + pth = example_data_path / "mf6" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( expected_output_folder, "lakeex1b_unch.hds" @@ -3808,7 +3804,7 @@ def test045_lake1ss_table(function_tmpdir, example_data_path): ) # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.write_simulation() @@ -3818,13 +3814,13 @@ def test045_lake1ss_table(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(function_tmpdir / "lakeex1b.hds") - outfile = str(function_tmpdir / "headcompare_a.txt") + head_new = function_tmpdir / "lakeex1b.hds" + outfile = function_tmpdir / "headcompare_a.txt" success = compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], outfile=outfile, ) assert success @@ -3840,7 +3836,7 @@ def test045_lake1ss_table(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -3848,13 +3844,13 @@ def test045_lake1ss_table(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} rerun did not run" # compare output to expected results - head_new = str(save_folder / "lakeex1b.hds") - outfile = str(function_tmpdir / "headcompare_b.txt") + head_new = save_folder / "lakeex1b.hds" + outfile = function_tmpdir / "headcompare_b.txt" success = compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], outfile=outfile, ) assert success @@ -3874,19 +3870,19 @@ def test006_2models_mvr(function_tmpdir, example_data_path): shutil.copytree(data_folder, ws) expected_output_folder = ws / "expected_output" - expected_head_file_a = str(expected_output_folder / "model1_unch.hds") - expected_head_file_aa = str(expected_output_folder / "model2_unch.hds") - expected_cbc_file_a = str(expected_output_folder / "model1_unch.cbc") - expected_head_file_b = str(expected_output_folder / "model1_adj.hds") - expected_head_file_bb = str(expected_output_folder / "model2_adj.hds") + expected_head_file_a = expected_output_folder / "model1_unch.hds" + expected_head_file_aa = expected_output_folder / "model2_unch.hds" + expected_cbc_file_a = expected_output_folder / "model1_unch.cbc" + expected_head_file_b = expected_output_folder / "model1_adj.hds" + expected_head_file_bb = expected_output_folder / "model2_adj.hds" # load simulation sim = MFSimulation.load( - sim_name, "mf6", "mf6", str(data_folder), verify_data=True + sim_name, "mf6", "mf6", data_folder, verify_data=True ) # make temp folder to save simulation - sim.set_sim_path(str(ws)) + sim.set_sim_path(ws) # write simulation to new location sim.set_all_data_external() @@ -3897,20 +3893,20 @@ def test006_2models_mvr(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(ws / "model1.hds") + head_new = ws / "model1.hds" assert compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], ) - head_new = str(ws / "model2.hds") + head_new = ws / "model2.hds" assert compare_heads( None, None, - files1=expected_head_file_aa, - files2=head_new, + files1=[expected_head_file_aa], + files2=[head_new], ) budget_obj = CellBudgetFile( @@ -3972,7 +3968,7 @@ def test006_2models_mvr(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -3980,7 +3976,7 @@ def test006_2models_mvr(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} rerun did not run" cell_list = [(0, 3, 1)] - out_file = str(ws / "inspect_test006_2models_mvr.csv") + out_file = ws / "inspect_test006_2models_mvr.csv" models[0].inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results @@ -3988,16 +3984,16 @@ def test006_2models_mvr(function_tmpdir, example_data_path): assert compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], ) head_new = os.path.join(save_folder, "model2.hds") assert compare_heads( None, None, - files1=expected_head_file_bb, - files2=head_new, + files1=[expected_head_file_bb], + files2=[head_new], ) # test load_only @@ -4009,7 +4005,7 @@ def test006_2models_mvr(function_tmpdir, example_data_path): ] for load_only in load_only_lists: sim = MFSimulation.load( - sim_name, "mf6", "mf6", str(data_folder), load_only=load_only + sim_name, "mf6", "mf6", data_folder, load_only=load_only ) for model_name in model_names: model = sim.get_model(model_name) @@ -4028,7 +4024,7 @@ def test006_2models_mvr(function_tmpdir, example_data_path): # load package by name load_only_list = ["ic6", "maw", "npf_p1", "oc_p2", "ims"] sim = MFSimulation.load( - sim_name, "mf6", "mf6", str(data_folder), load_only=load_only_list + sim_name, "mf6", "mf6", data_folder, load_only=load_only_list ) model_parent = sim.get_model("parent") model_child = sim.get_model("child") @@ -4039,9 +4035,9 @@ def test006_2models_mvr(function_tmpdir, example_data_path): # test running a runnable load_only case sim = MFSimulation.load( - sim_name, "mf6", "mf6", str(data_folder), load_only=load_only_lists[0] + sim_name, "mf6", "mf6", data_folder, load_only=load_only_lists[0] ) - sim.set_sim_path(str(ws)) + sim.set_sim_path(ws) success, buff = sim.run_simulation() assert success, f"simulation {sim.name} did not run" @@ -4056,12 +4052,10 @@ def test001e_uzf_3lay(function_tmpdir, example_data_path): pth = example_data_path / "mf6" / test_ex_name # load simulation - sim = MFSimulation.load( - model_name, "mf6", "mf6", str(pth), verify_data=True - ) + sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.write_simulation() @@ -4082,7 +4076,7 @@ def test001e_uzf_3lay(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -4091,7 +4085,7 @@ def test001e_uzf_3lay(function_tmpdir, example_data_path): # inspect cells cell_list = [(0, 0, 1), (0, 0, 2), (2, 0, 8)] - out_file = str(function_tmpdir / "inspect_test001e_uzf_3lay.csv") + out_file = function_tmpdir / "inspect_test001e_uzf_3lay.csv" model.inspect_cells(cell_list, output_file_path=out_file) # test load_only @@ -4104,9 +4098,9 @@ def test001e_uzf_3lay(function_tmpdir, example_data_path): ] for load_only in load_only_lists: sim = MFSimulation.load( - model_name, "mf6", "mf6", str(pth), load_only=load_only + model_name, "mf6", "mf6", pth, load_only=load_only ) - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) model = sim.get_model() for package in model_package_check: assert (package in model.package_type_dict) == ( @@ -4114,21 +4108,19 @@ def test001e_uzf_3lay(function_tmpdir, example_data_path): ) # test running a runnable load_only case sim = MFSimulation.load( - model_name, "mf6", "mf6", str(pth), load_only=load_only_lists[0] + model_name, "mf6", "mf6", pth, load_only=load_only_lists[0] ) - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) success, buff = sim.run_simulation() assert success, f"simulation {sim.name} from load did not run" cbc = CellBudgetFile( - str(function_tmpdir / "test001e_UZF_3lay.uzf.cbc"), precision="auto" + function_tmpdir / "test001e_UZF_3lay.uzf.cbc", precision="auto" ) data = cbc.get_data(text="GWF", full3D=False) assert data[2].node[0] == 1, "Budget precision error for imeth 6" - sim = MFSimulation.load( - "mfsim", sim_ws=str(function_tmpdir), exe_name="mf6" - ) + sim = MFSimulation.load("mfsim", sim_ws=function_tmpdir, exe_name="mf6") ims = sim.ims sim.remove_package(ims) @@ -4155,16 +4147,14 @@ def test045_lake2tr(function_tmpdir, example_data_path): model_name = "lakeex2a" pth = example_data_path / "mf6" / test_ex_name expected_output_folder = pth / "expected_output" - expected_head_file_a = str(expected_output_folder / "lakeex2a_unch.hds") - expected_head_file_b = str(expected_output_folder / "lakeex2a_adj.hds") + expected_head_file_a = expected_output_folder / "lakeex2a_unch.hds" + expected_head_file_b = expected_output_folder / "lakeex2a_adj.hds" # load simulation - sim = MFSimulation.load( - model_name, "mf6", "mf6", str(pth), verify_data=True - ) + sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) # write simulation to new location - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) sim.write_simulation() # run simulation @@ -4172,12 +4162,12 @@ def test045_lake2tr(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(function_tmpdir / "lakeex2a.hds") + head_new = function_tmpdir / "lakeex2a.hds" assert compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], htol=10.0, ) @@ -4195,7 +4185,7 @@ def test045_lake2tr(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -4204,16 +4194,16 @@ def test045_lake2tr(function_tmpdir, example_data_path): # inspect cells cell_list = [(0, 6, 5), (0, 8, 5), (1, 18, 6)] - out_file = str(function_tmpdir / "inspect_test045_lake2tr.csv") + out_file = function_tmpdir / "inspect_test045_lake2tr.csv" model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(save_folder / "lakeex2a.hds") + head_new = save_folder / "lakeex2a.hds" assert compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], htol=10.0, ) @@ -4224,7 +4214,7 @@ def test036_twrihfb(function_tmpdir, example_data_path): # init paths test_ex_name = "test036_twrihfb" model_name = "twrihfb2015" - pth = str(example_data_path / "mf6" / test_ex_name) + pth = example_data_path / "mf6" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( expected_output_folder, "twrihfb2015_output_unch.hds" @@ -4237,7 +4227,7 @@ def test036_twrihfb(function_tmpdir, example_data_path): sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() @@ -4248,12 +4238,12 @@ def test036_twrihfb(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(function_tmpdir / "twrihfb2015_output.hds") + head_new = function_tmpdir / "twrihfb2015_output.hds" assert compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], ) # change some settings @@ -4282,7 +4272,7 @@ def test036_twrihfb(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -4290,12 +4280,12 @@ def test036_twrihfb(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} rerun did not run" # compare output to expected results - head_new = str(save_folder / "twrihfb2015_output.hds") + head_new = save_folder / "twrihfb2015_output.hds" assert compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], ) @@ -4306,7 +4296,7 @@ def test027_timeseriestest(function_tmpdir, example_data_path): # init paths test_ex_name = "test027_TimeseriesTest" model_name = "gwf_1" - pth = str(example_data_path / "mf6" / test_ex_name) + pth = example_data_path / "mf6" / test_ex_name expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( expected_output_folder, "timeseriestest_unch.hds" @@ -4319,7 +4309,7 @@ def test027_timeseriestest(function_tmpdir, example_data_path): sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) # make temp folder to save simulation - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write simulation to new location sim.set_all_data_external() @@ -4327,7 +4317,7 @@ def test027_timeseriestest(function_tmpdir, example_data_path): # reload sim sim = MFSimulation.load( - model_name, "mf6", "mf6", str(function_tmpdir), verify_data=True + model_name, "mf6", "mf6", function_tmpdir, verify_data=True ) sim.write_simulation() @@ -4336,13 +4326,13 @@ def test027_timeseriestest(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(function_tmpdir / "timeseriestest.hds") - outfile = str(function_tmpdir / "head_compare.dat") + head_new = function_tmpdir / "timeseriestest.hds" + outfile = function_tmpdir / "head_compare.dat" assert compare_heads( None, None, - files1=expected_head_file_a, - files2=head_new, + files1=[expected_head_file_a], + files2=[head_new], outfile=outfile, htol=10.0, ) @@ -4358,7 +4348,7 @@ def test027_timeseriestest(function_tmpdir, example_data_path): # write simulation again save_folder = function_tmpdir / "save" save_folder.mkdir() - sim.set_sim_path(str(save_folder)) + sim.set_sim_path(save_folder) sim.write_simulation() # run simulation @@ -4366,12 +4356,12 @@ def test027_timeseriestest(function_tmpdir, example_data_path): assert success, f"simulation {sim.name} rerun did not run" # compare output to expected results - head_new = os.path.join(str(save_folder), "timeseriestest.hds") + head_new = os.path.join(save_folder, "timeseriestest.hds") assert compare_heads( None, None, - files1=expected_head_file_b, - files2=head_new, + files1=[expected_head_file_b], + files2=[head_new], htol=10.0, ) @@ -4388,7 +4378,7 @@ def test099_create_tests_int_ext(function_tmpdir, example_data_path): sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) sim.name_file.continue_.set_data(True) tdis_rc = [(1577889000, 50, 1.1), (1577889000, 50, 1.1)] @@ -4474,7 +4464,7 @@ def test099_create_tests_int_ext(function_tmpdir, example_data_path): sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) sim_2.set_sim_path(os.path.join(function_tmpdir, "sim_2")) model = sim_2.get_model(model_name) @@ -4492,7 +4482,7 @@ def test099_create_tests_int_ext(function_tmpdir, example_data_path): sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) model = sim_3.get_model(model_name) npf_package = model.get_package("npf") @@ -4512,7 +4502,7 @@ def test099_create_tests_int_ext(function_tmpdir, example_data_path): sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) model = sim_4.get_model(model_name) npf_package = model.get_package("npf") diff --git a/autotest/regression/test_mf6_examples.py b/autotest/regression/test_mf6_examples.py index 9a14a365f0..a956622f96 100644 --- a/autotest/regression/test_mf6_examples.py +++ b/autotest/regression/test_mf6_examples.py @@ -59,7 +59,7 @@ def run_models(): # load simulation sim = MFSimulation.load( - namfile_name, version="mf6", exe_name="mf6", sim_ws=str(wrkdir) + namfile_name, version="mf6", exe_name="mf6", sim_ws=wrkdir ) assert isinstance(sim, MFSimulation) @@ -68,7 +68,7 @@ def run_models(): assert success # change to comparison workspace - sim.simulation_data.mfpath.set_sim_path(str(cmpdir)) + sim.simulation_data.mfpath.set_sim_path(cmpdir) # write simulation files and rerun sim.write_simulation() @@ -87,7 +87,7 @@ def run_models(): text="head", files1=[str(p) for p in headfiles1], files2=[str(p) for p in headfiles2], - outfile=str(cmpdir / "head_compare.dat"), + outfile=cmpdir / "head_compare.dat", ) run_models() diff --git a/autotest/regression/test_mfnwt.py b/autotest/regression/test_mfnwt.py index d2b48bf53b..4a57a8266d 100644 --- a/autotest/regression/test_mfnwt.py +++ b/autotest/regression/test_mfnwt.py @@ -24,7 +24,7 @@ def get_nfnwt_namfiles(): if "WEL" in value.filetype: wel = True if lpf and wel: - namfiles.append(str(namfile)) + namfiles.append(namfile) return namfiles @@ -107,16 +107,16 @@ def test_run_mfnwt_model(function_tmpdir, namfile): wel.iunitramp = 2 # change workspace and write MODFLOW-NWT model - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.write_input() success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" - fn0 = str(function_tmpdir / namfile) + fn0 = function_tmpdir / namfile # reload the model just written m = Modflow.load( namfile, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, version="mfnwt", verbose=True, check=False, @@ -126,17 +126,17 @@ def test_run_mfnwt_model(function_tmpdir, namfile): assert m.load_fail is False # change workspace and write MODFLOW-NWT model - pthf = str(function_tmpdir / "flopy") + pthf = function_tmpdir / "flopy" m.change_model_ws(pthf) m.write_input() success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" fn1 = os.path.join(pthf, namfile) - fsum = str(function_tmpdir / f"{base_name}.head.out") + fsum = function_tmpdir / f"{base_name}.head.out" assert compare_heads(fn0, fn1, outfile=fsum), "head comparison failure" - fsum = str(function_tmpdir / f"{base_name}.budget.out") + fsum = function_tmpdir / f"{base_name}.budget.out" assert compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ), "budget comparison failure" diff --git a/autotest/regression/test_modflow.py b/autotest/regression/test_modflow.py index 2dc957a082..84eada048f 100644 --- a/autotest/regression/test_modflow.py +++ b/autotest/regression/test_modflow.py @@ -26,7 +26,7 @@ def uzf_example_path(example_data_path): @pytest.mark.regression def test_uzf_unit_numbers(function_tmpdir, uzf_example_path): mfnam = "UZFtest2.nam" - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" copytree(uzf_example_path, ws) m = Modflow.load( @@ -73,7 +73,7 @@ def test_uzf_unit_numbers(function_tmpdir, uzf_example_path): fn1 = join(model_ws2, mfnam) # compare budget terms - fsum = join(str(function_tmpdir), f"{splitext(mfnam)[0]}.budget.out") + fsum = join(function_tmpdir, f"{splitext(mfnam)[0]}.budget.out") success = compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -85,7 +85,7 @@ def test_uzf_unit_numbers(function_tmpdir, uzf_example_path): @pytest.mark.regression def test_unitnums(function_tmpdir, mf2005_test_path): mfnam = "testsfr2_tab.nam" - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" copytree(mf2005_test_path, ws) m = Modflow.load(mfnam, verbose=True, model_ws=ws, exe_name="mf2005") @@ -125,9 +125,9 @@ def test_gage(function_tmpdir, example_data_path): """ test043 load and write of MODFLOW-2005 GAGE example problem """ - pth = str(example_data_path / "mf2005_test") + pth = example_data_path / "mf2005_test" fpth = join(pth, "testsfr2_tab.nam") - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" copytree(pth, ws) # load the modflow model @@ -169,7 +169,7 @@ def test_gage(function_tmpdir, example_data_path): @pytest.mark.parametrize( "namfile", [ - str(__example_data_path / "pcgn_test" / nf) + __example_data_path / "pcgn_test" / nf for nf in ["twri.nam", "MNW2.nam"] ], ) @@ -180,7 +180,7 @@ def test_mf2005pcgn(function_tmpdir, namfile): m = Modflow.load( nf, - model_ws=str(ws), + model_ws=ws, verbose=True, exe_name="mf2005", ) @@ -192,22 +192,22 @@ def test_mf2005pcgn(function_tmpdir, namfile): success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" - fn0 = str(ws / nf) + fn0 = ws / nf # rewrite files ws2 = function_tmpdir / "ws2" - m.change_model_ws(str(ws2)) + m.change_model_ws(ws2) m.write_input() success, buff = m.run_model(silent=False) assert success, "new model run did not terminate successfully" - fn1 = str(ws2 / nf) + fn1 = ws2 / nf - fsum = str(function_tmpdir / f"{Path(namfile).stem}.head.out") + fsum = function_tmpdir / f"{Path(namfile).stem}.head.out" success = compare_heads(fn0, fn1, outfile=fsum, htol=0.005) assert success, "head comparison failure" - fsum = str(function_tmpdir / f"{Path(namfile).stem}.budget.out") + fsum = function_tmpdir / f"{Path(namfile).stem}.budget.out" success = compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -218,7 +218,7 @@ def test_mf2005pcgn(function_tmpdir, namfile): @pytest.mark.slow @pytest.mark.regression @pytest.mark.parametrize( - "namfile", [str(__example_data_path / "secp" / nf) for nf in ["secp.nam"]] + "namfile", [__example_data_path / "secp" / nf for nf in ["secp.nam"]] ) def test_mf2005gmg(function_tmpdir, namfile): ws = function_tmpdir / "ws" @@ -227,7 +227,7 @@ def test_mf2005gmg(function_tmpdir, namfile): m = Modflow.load( namfile, - model_ws=str(ws), + model_ws=ws, verbose=True, exe_name="mf2005", ) @@ -235,21 +235,21 @@ def test_mf2005gmg(function_tmpdir, namfile): success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" - fn0 = str(ws / nf) + fn0 = ws / nf # rewrite files - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.write_input() success, buff = m.run_model(silent=False) assert success, "new model run did not terminate successfully" - fn1 = str(function_tmpdir / nf) + fn1 = function_tmpdir / nf - fsum = str(function_tmpdir / f"{Path(namfile).stem}.head.out") + fsum = function_tmpdir / f"{Path(namfile).stem}.head.out" success = compare_heads(fn0, fn1, outfile=fsum) assert success, "head comparison failure" - fsum = str(function_tmpdir / f"{Path(namfile).stem}.budget.out") + fsum = function_tmpdir / f"{Path(namfile).stem}.budget.out" success = compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -260,7 +260,7 @@ def test_mf2005gmg(function_tmpdir, namfile): @pytest.mark.regression @pytest.mark.parametrize( "namfile", - [str(__example_data_path / "freyberg" / nf) for nf in ["freyberg.nam"]], + [__example_data_path / "freyberg" / nf for nf in ["freyberg.nam"]], ) def test_mf2005(function_tmpdir, namfile): """ @@ -268,11 +268,11 @@ def test_mf2005(function_tmpdir, namfile): """ compth = function_tmpdir / "flopy" ws = function_tmpdir / "ws" - copytree(Path(namfile).parent, str(ws)) + copytree(Path(namfile).parent, ws) m = Modflow.load( Path(namfile).name, - model_ws=str(ws), + model_ws=ws, verbose=True, exe_name="mf2005", ) @@ -280,7 +280,7 @@ def test_mf2005(function_tmpdir, namfile): success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" - fn0 = str(ws / Path(namfile).name) + fn0 = ws / Path(namfile).name # change model workspace m.change_model_ws(compth) @@ -304,20 +304,20 @@ def test_mf2005(function_tmpdir, namfile): success, buff = m.run_model() assert success, "new model run did not terminate successfully" - fn1 = str(compth / Path(namfile).name) + fn1 = compth / Path(namfile).name # compare heads - fsum = str(ws / f"{Path(namfile).stem}.head.out") + fsum = ws / f"{Path(namfile).stem}.head.out" success = compare_heads(fn0, fn1, outfile=fsum) assert success, "head comparison failure" # compare heads - fsum = str(ws / f"{Path(namfile).stem}.ddn.out") + fsum = ws / f"{Path(namfile).stem}.ddn.out" success = compare_heads(fn0, fn1, outfile=fsum, text="drawdown") assert success, "head comparison failure" # compare budgets - fsum = str(ws / f"{Path(namfile).stem}.budget.out") + fsum = ws / f"{Path(namfile).stem}.budget.out" success = compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -325,7 +325,7 @@ def test_mf2005(function_tmpdir, namfile): mf2005_namfiles = [ - str(__example_data_path / "mf2005_test" / nf) + __example_data_path / "mf2005_test" / nf for nf in [ "fhb.nam", "l1a2k.nam", @@ -341,7 +341,7 @@ def test_mf2005(function_tmpdir, namfile): @pytest.mark.regression @pytest.mark.parametrize("namfile", mf2005_namfiles) def test_mf2005fhb(function_tmpdir, namfile): - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" copytree(Path(namfile).parent, ws) m = Modflow.load( @@ -354,12 +354,12 @@ def test_mf2005fhb(function_tmpdir, namfile): fn0 = join(ws, Path(namfile).name) # rewrite files - m.change_model_ws(str(function_tmpdir), reset_external=True) + m.change_model_ws(function_tmpdir, reset_external=True) m.write_input() success, buff = m.run_model() assert success, "new model run did not terminate successfully" - fn1 = join(str(function_tmpdir), Path(namfile).name) + fn1 = join(function_tmpdir, Path(namfile).name) fsum = join(ws, f"{Path(namfile).stem}.head.out") success = compare_heads(fn0, fn1, outfile=fsum) @@ -377,12 +377,12 @@ def test_mf2005fhb(function_tmpdir, namfile): @pytest.mark.regression @pytest.mark.parametrize("namfile", mf2005_namfiles) def test_mf2005_lake(function_tmpdir, namfile, mf2005_test_path): - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" copytree(mf2005_test_path, ws) m = Modflow.load( Path(namfile).name, - model_ws=str(ws), + model_ws=ws, verbose=True, forgive=False, exe_name="mf2005", diff --git a/autotest/regression/test_str.py b/autotest/regression/test_str.py index 3758cf07d1..9f9aab3c6c 100644 --- a/autotest/regression/test_str.py +++ b/autotest/regression/test_str.py @@ -21,11 +21,11 @@ def test_str_fixed_free(function_tmpdir, example_data_path): m = Modflow.load( str_items[0]["mfnam"], exe_name="mf2005", - model_ws=str(mf2005_model_path), + model_ws=mf2005_model_path, verbose=False, check=False, ) - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) # get pointer to str package mstr = m.str @@ -81,7 +81,7 @@ def test_str_fixed_free(function_tmpdir, example_data_path): m2 = Modflow.load( str_items[0]["mfnam"], exe_name="mf2005", - model_ws=str(mf2005_model_path), + model_ws=mf2005_model_path, verbose=False, check=False, ) @@ -95,7 +95,7 @@ def test_str_fixed_free(function_tmpdir, example_data_path): for p in function_tmpdir.glob("*"): p.unlink() - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.set_ifrefm() m.write_input() @@ -107,7 +107,7 @@ def test_str_fixed_free(function_tmpdir, example_data_path): m2 = Modflow.load( str_items[0]["mfnam"], exe_name="mf2005", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=False, check=False, ) @@ -119,8 +119,8 @@ def test_str_fixed_free(function_tmpdir, example_data_path): ), "could not load the free format model with aux variables" # compare the fixed and free format head files - fn1 = str(function_tmpdir / "str.nam") - fn2 = str(function_tmpdir / "str.nam") + fn1 = function_tmpdir / "str.nam" + fn2 = function_tmpdir / "str.nam" assert compare_heads( fn1, fn2, verbose=True ), "fixed and free format input output head files are different" diff --git a/autotest/regression/test_swi2.py b/autotest/regression/test_swi2.py index 045cfc0603..c1d870c845 100644 --- a/autotest/regression/test_swi2.py +++ b/autotest/regression/test_swi2.py @@ -21,7 +21,7 @@ def swi_path(example_data_path): ) def test_mf2005swi2(function_tmpdir, swi_path, namfile): name = namfile.replace(".nam", "") - ws = str(function_tmpdir / "ws") + ws = function_tmpdir / "ws" shutil.copytree(swi_path, ws) m = Modflow.load(namfile, model_ws=ws, verbose=True, exe_name="mf2005") diff --git a/autotest/regression/test_wel.py b/autotest/regression/test_wel.py index 4a9af3dad8..0c4a6cc0fd 100644 --- a/autotest/regression/test_wel.py +++ b/autotest/regression/test_wel.py @@ -25,7 +25,7 @@ def test_binary_well(function_tmpdir): mfnam = "t1" ml = Modflow( modelname=mfnam, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, exe_name="mf2005", ) @@ -60,12 +60,12 @@ def test_binary_well(function_tmpdir): # run the modflow-2005 model success, buff = ml.run_model(silent=False) assert success, "could not run MODFLOW-2005 model" - fn0 = os.path.join(str(function_tmpdir), f"{mfnam}.nam") + fn0 = os.path.join(function_tmpdir, f"{mfnam}.nam") # load the model m = Modflow.load( f"{mfnam}.nam", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, exe_name="mf2005", ) @@ -77,7 +77,7 @@ def test_binary_well(function_tmpdir): ) # change model work space - pth = os.path.join(str(function_tmpdir), "flopy") + pth = os.path.join(function_tmpdir, "flopy") m.change_model_ws(new_pth=pth) # remove the existing well package @@ -98,12 +98,12 @@ def test_binary_well(function_tmpdir): # compare the files fsum = os.path.join( - str(function_tmpdir), f"{os.path.splitext(mfnam)[0]}.head.out" + function_tmpdir, f"{os.path.splitext(mfnam)[0]}.head.out" ) assert compare_heads(fn0, fn1, outfile=fsum), "head comparison failure" fsum = os.path.join( - str(function_tmpdir), f"{os.path.splitext(mfnam)[0]}.budget.out" + function_tmpdir, f"{os.path.splitext(mfnam)[0]}.budget.out" ) assert compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum diff --git a/autotest/test_binaryfile.py b/autotest/test_binaryfile.py index 69ee4f89a3..bb6795b708 100644 --- a/autotest/test_binaryfile.py +++ b/autotest/test_binaryfile.py @@ -39,9 +39,9 @@ def zonbud_model_path(example_data_path): def test_binaryfile_writeread(function_tmpdir, nwt_model_path): model = "Pr3_MFNWT_lower.nam" - ml = Modflow.load(model, version="mfnwt", model_ws=str(nwt_model_path)) + ml = Modflow.load(model, version="mfnwt", model_ws=nwt_model_path) # change the model work space - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) # ncol = ml.dis.ncol nrow = ml.dis.nrow @@ -62,7 +62,7 @@ def test_binaryfile_writeread(function_tmpdir, nwt_model_path): kper=1, ) b = ml.dis.botm.array[0, :, :].astype(np.float64) - pth = str(function_tmpdir / "bottom.hds") + pth = function_tmpdir / "bottom.hds" Util2d.write_bin(b.shape, pth, b, header_data=header) bo = HeadFile(pth, precision=precision) @@ -92,7 +92,7 @@ def test_binaryfile_writeread(function_tmpdir, nwt_model_path): kper=1, ) b = ml.dis.botm.array[0, :, :].astype(np.float32) - pth = str(function_tmpdir / "bottom_single.hds") + pth = function_tmpdir / "bottom_single.hds" Util2d.write_bin(b.shape, pth, b, header_data=header) bo = HeadFile(pth, precision=precision) @@ -109,7 +109,7 @@ def test_binaryfile_writeread(function_tmpdir, nwt_model_path): def test_load_cell_budget_file_timeseries(example_data_path): cbf = CellBudgetFile( - str(example_data_path / "mf2005_test" / "swiex1.gitzta"), + example_data_path / "mf2005_test" / "swiex1.gitzta", precision="single", ) ts = cbf.get_ts(text="ZETASRF 1", idx=(0, 0, 24)) @@ -121,12 +121,12 @@ def test_load_cell_budget_file_timeseries(example_data_path): def test_load_binary_head_file(example_data_path): mpath = example_data_path / "freyberg" - hf = HeadFile(str(mpath / "freyberg.githds")) + hf = HeadFile(mpath / "freyberg.githds") assert isinstance(hf, HeadFile) def test_plot_binary_head_file(example_data_path): - hf = HeadFile(str(example_data_path / "freyberg" / "freyberg.githds")) + hf = HeadFile(example_data_path / "freyberg" / "freyberg.githds") hf.mg.set_coord_info(xoff=1000.0, yoff=200.0, angrot=15.0) assert isinstance(hf.plot(), Axes) @@ -134,7 +134,7 @@ def test_plot_binary_head_file(example_data_path): def test_headu_file_data(function_tmpdir, example_data_path): - fname = str(example_data_path / "unstructured" / "headu.githds") + fname = example_data_path / "unstructured" / "headu.githds" headobj = HeadUFile(fname) assert isinstance(headobj, HeadUFile) assert headobj.nlay == 3 @@ -199,19 +199,17 @@ def test_headufile_get_ts(example_data_path): def test_get_headfile_precision(example_data_path): precision = get_headfile_precision( - str(example_data_path / "freyberg" / "freyberg.githds") + example_data_path / "freyberg" / "freyberg.githds" ) assert precision == "single" precision = get_headfile_precision( - str( - example_data_path - / "mf6" - / "create_tests" - / "test005_advgw_tidal" - / "expected_output" - / "AdvGW_tidal.hds" - ) + example_data_path + / "mf6" + / "create_tests" + / "test005_advgw_tidal" + / "expected_output" + / "AdvGW_tidal.hds" ) assert precision == "double" @@ -222,16 +220,13 @@ def test_get_headfile_precision(example_data_path): @pytest.mark.parametrize( "path", [ - str(p) - for p in [ - _example_data_path / "mf2005_test" / "swiex1.gitzta", - _example_data_path / "mp6" / "EXAMPLE.BUD", - _example_data_path - / "mfusg_test" - / "01A_nestedgrid_nognc" - / "output" - / "flow.cbc", - ] + _example_data_path / "mf2005_test" / "swiex1.gitzta", + _example_data_path / "mp6" / "EXAMPLE.BUD", + _example_data_path + / "mfusg_test" + / "01A_nestedgrid_nognc" + / "output" + / "flow.cbc", ], ) def test_budgetfile_detect_precision_single(path): @@ -242,14 +237,11 @@ def test_budgetfile_detect_precision_single(path): @pytest.mark.parametrize( "path", [ - str(p) - for p in [ - _example_data_path - / "mf6" - / "test006_gwf3" - / "expected_output" - / "flow_adj.cbc", - ] + _example_data_path + / "mf6" + / "test006_gwf3" + / "expected_output" + / "flow_adj.cbc", ], ) def test_budgetfile_detect_precision_double(path): @@ -295,7 +287,7 @@ def test_write_budget(function_tmpdir): def test_binaryfile_read(function_tmpdir, freyberg_model_path): - h = HeadFile(str(freyberg_model_path / "freyberg.githds")) + h = HeadFile(freyberg_model_path / "freyberg.githds") assert isinstance(h, HeadFile) times = h.get_times() @@ -322,7 +314,7 @@ def test_binaryfile_read(function_tmpdir, freyberg_model_path): h.close() # Check error when reading empty file - fname = str(function_tmpdir / "empty.githds") + fname = function_tmpdir / "empty.githds" with open(fname, "w"): pass with pytest.raises(ValueError): @@ -332,7 +324,7 @@ def test_binaryfile_read(function_tmpdir, freyberg_model_path): def test_binaryfile_read_context(freyberg_model_path): - hds_path = str(freyberg_model_path / "freyberg.githds") + hds_path = freyberg_model_path / "freyberg.githds" with HeadFile(hds_path) as h: data = h.get_data() assert data.max() > 0, data.max() @@ -346,7 +338,7 @@ def test_binaryfile_read_context(freyberg_model_path): def test_cellbudgetfile_read_context(example_data_path): mf2005_model_path = example_data_path / "mf2005_test" - cbc_path = str(mf2005_model_path / "mnw1.gitcbc") + cbc_path = mf2005_model_path / "mnw1.gitcbc" with CellBudgetFile(cbc_path) as v: data = v.get_data(text="DRAINS")[0] assert data.min() < 0, data.min() @@ -360,7 +352,7 @@ def test_cellbudgetfile_read_context(example_data_path): def test_cellbudgetfile_read(example_data_path): mf2005_model_path = example_data_path / "mf2005_test" - v = CellBudgetFile(str(mf2005_model_path / "mnw1.gitcbc")) + v = CellBudgetFile(mf2005_model_path / "mnw1.gitcbc") assert isinstance(v, CellBudgetFile) kstpkper = v.get_kstpkper() @@ -381,7 +373,7 @@ def test_cellbudgetfile_read(example_data_path): def test_cellbudgetfile_position(function_tmpdir, zonbud_model_path): - fpth = str(zonbud_model_path / "freyberg.gitcbc") + fpth = zonbud_model_path / "freyberg.gitcbc" v = CellBudgetFile(fpth) assert isinstance(v, CellBudgetFile) @@ -434,7 +426,7 @@ def test_cellbudgetfile_position(function_tmpdir, zonbud_model_path): assert np.array_equal(d1, d2), msg # Check error when reading empty file - fname = str(function_tmpdir / "empty.gitcbc") + fname = function_tmpdir / "empty.gitcbc" with open(fname, "w"): pass with pytest.raises(ValueError): @@ -443,7 +435,7 @@ def test_cellbudgetfile_position(function_tmpdir, zonbud_model_path): def test_cellbudgetfile_readrecord(example_data_path): mf2005_model_path = example_data_path / "mf2005_test" - cbc_fname = str(mf2005_model_path / "test1tr.gitcbc") + cbc_fname = mf2005_model_path / "test1tr.gitcbc" v = CellBudgetFile(cbc_fname) assert isinstance(v, CellBudgetFile) @@ -503,7 +495,7 @@ def test_cellbudgetfile_readrecord(example_data_path): def test_cellbudgetfile_readrecord_waux(example_data_path): mf2005_model_path = example_data_path / "mf2005_test" - cbc_fname = str(mf2005_model_path / "test1tr.gitcbc") + cbc_fname = mf2005_model_path / "test1tr.gitcbc" v = CellBudgetFile(cbc_fname) assert isinstance(v, CellBudgetFile) diff --git a/autotest/test_binarygrid_util.py b/autotest/test_binarygrid_util.py index 995cee9036..4c79aaf7d8 100644 --- a/autotest/test_binarygrid_util.py +++ b/autotest/test_binarygrid_util.py @@ -16,7 +16,7 @@ def mfgrd_test_path(example_data_path): def test_mfgrddis_MfGrdFile(mfgrd_test_path): - grb = MfGrdFile(str(mfgrd_test_path / "nwtp3.dis.grb"), verbose=True) + grb = MfGrdFile(mfgrd_test_path / "nwtp3.dis.grb", verbose=True) nodes = grb.nodes ia = grb.ia shape = ia.shape[0] @@ -32,7 +32,7 @@ def test_mfgrddis_MfGrdFile(mfgrd_test_path): def test_mfgrddis_modelgrid(mfgrd_test_path): - fn = str(mfgrd_test_path / "nwtp3.dis.grb") + fn = mfgrd_test_path / "nwtp3.dis.grb" modelgrid = StructuredGrid.from_binary_grid_file(fn, verbose=True) assert isinstance(modelgrid, StructuredGrid), "invalid grid type" @@ -67,7 +67,7 @@ def test_mfgrddis_modelgrid(mfgrd_test_path): def test_mfgrddisv_MfGrdFile(mfgrd_test_path): - fn = str(mfgrd_test_path / "flow.disv.grb") + fn = mfgrd_test_path / "flow.disv.grb" grb = MfGrdFile(fn, verbose=True) nodes = grb.nodes @@ -124,7 +124,7 @@ def test_mfgrddisv_modelgrid(mfgrd_test_path): def test_mfgrddisu_MfGrdFile(mfgrd_test_path): - fn = str(mfgrd_test_path / "keating.disu.grb") + fn = mfgrd_test_path / "keating.disu.grb" grb = MfGrdFile(fn, verbose=True) nodes = grb.nodes @@ -142,13 +142,13 @@ def test_mfgrddisu_MfGrdFile(mfgrd_test_path): def test_mfgrddisu_modelgrid_fail(mfgrd_test_path): - fn = str(mfgrd_test_path / "flow.disu.grb") + fn = mfgrd_test_path / "flow.disu.grb" with pytest.raises(TypeError): mg = UnstructuredGrid.from_binary_grid_file(fn, verbose=True) def test_mfgrddisu_modelgrid(mfgrd_test_path): - fn = str(mfgrd_test_path / "keating.disu.grb") + fn = mfgrd_test_path / "keating.disu.grb" mg = UnstructuredGrid.from_binary_grid_file(fn, verbose=True) assert isinstance(mg, UnstructuredGrid), f"invalid grid type ({type(mg)})" diff --git a/autotest/test_cbc_full3D.py b/autotest/test_cbc_full3D.py index 581d17b1ce..9f983be5dc 100644 --- a/autotest/test_cbc_full3D.py +++ b/autotest/test_cbc_full3D.py @@ -25,7 +25,7 @@ def load_mf2005(path, ws_out): name_file = f"{Path(path).name}.nam" ml = Modflow.load( name_file, - model_ws=str(path), + model_ws=path, exe_name="mf2005", check=False, ) @@ -47,7 +47,7 @@ def load_mf6(path, ws_out): sim = MFSimulation.load( sim_name=Path(path).name, exe_name="mf6", - sim_ws=str(path), + sim_ws=path, ) # change work space @@ -124,7 +124,7 @@ def cbc_eval(cbcobj, nnodes, shape3d, modelgrid): @pytest.mark.mf6 @pytest.mark.parametrize("path", mf6_paths) def test_cbc_full3D_mf6(function_tmpdir, path): - sim = load_mf6(path, str(function_tmpdir)) + sim = load_mf6(path, function_tmpdir) # write the simulation sim.write_simulation() @@ -147,7 +147,7 @@ def test_cbc_full3D_mf6(function_tmpdir, path): @requires_exe("mf2005") @pytest.mark.parametrize("path", mf2005_paths) def test_cbc_full3D_mf2005(function_tmpdir, path): - ml = load_mf2005(path, str(function_tmpdir)) + ml = load_mf2005(path, function_tmpdir) # write the model ml.write_input() @@ -159,7 +159,7 @@ def test_cbc_full3D_mf2005(function_tmpdir, path): nnodes, shape3d = ml.modelgrid.nnodes, ml.modelgrid.shape # get the cell by cell object - fpth = os.path.join(str(function_tmpdir), f"{Path(path).name}.cbc") + fpth = function_tmpdir / f"{Path(path).name}.cbc" cbc = CellBudgetFile(fpth) # evaluate the full3D option diff --git a/autotest/test_compare.py b/autotest/test_compare.py index 1e33bc9592..18e64e207b 100644 --- a/autotest/test_compare.py +++ b/autotest/test_compare.py @@ -33,7 +33,7 @@ def test_eval_bud_diff(example_data_path): # get ia from grdfile mfgrd_test_path = example_data_path / "mfgrd_test" grb_path = mfgrd_test_path / "nwtp3.dis.grb" - grb = MfGrdFile(str(grb_path), verbose=True) + grb = MfGrdFile(grb_path, verbose=True) ia = grb._datadict["IA"] - 1 # TODO: create/run minimal model, then compare budget files diff --git a/autotest/test_conftest.py b/autotest/test_conftest.py index 1085e59ba1..8121ada022 100644 --- a/autotest/test_conftest.py +++ b/autotest/test_conftest.py @@ -1,23 +1,8 @@ -import inspect -import os -import platform -from pathlib import Path -from shutil import which - -import pytest -from _pytest.config import ExitCode from autotest.conftest import get_example_data_path, get_project_root_path -from modflow_devtools.markers import ( - excludes_platform, - requires_exe, - requires_pkg, - requires_platform, -) def test_get_project_root_path(): root = get_project_root_path() - assert root.is_dir() contents = [p.name for p in root.glob("*")] @@ -32,5 +17,4 @@ def test_get_example_data_path(): def test_get_paths(): example_data = get_example_data_path() project_root = get_project_root_path() - assert example_data.parent.parent == project_root diff --git a/autotest/test_copy.py b/autotest/test_copy.py index 7e8d9e1469..10668bbdd7 100644 --- a/autotest/test_copy.py +++ b/autotest/test_copy.py @@ -219,7 +219,7 @@ def list_is_copy(mflist1, mflist2): def test_mf2005_copy(example_data_path): m = Modflow.load( "freyberg.nam", - model_ws=str(example_data_path / "freyberg_multilayer_transient"), + model_ws=example_data_path / "freyberg_multilayer_transient", ) m_c = copy.copy(m) m_dc = copy.deepcopy(m) @@ -232,7 +232,7 @@ def test_mf6_copy(example_data_path): sim = MFSimulation.load( "mfsim.nam", "mf6", - sim_ws=str(example_data_path / "mf6" / "test045_lake2tr"), + sim_ws=example_data_path / "mf6" / "test045_lake2tr", ) m = sim.get_model("lakeex2a") m_c = copy.copy(m) diff --git a/autotest/test_export.py b/autotest/test_export.py index bef95b6908..d24963bd2c 100644 --- a/autotest/test_export.py +++ b/autotest/test_export.py @@ -63,15 +63,13 @@ def namfiles() -> List[Path]: @requires_pkg("shapefile") def test_output_helper_shapefile_export(function_tmpdir, example_data_path): - ml = Modflow.load( - "freyberg.nam", - model_ws=str(example_data_path / "freyberg_multilayer_transient"), - ) - head = HeadFile(os.path.join(ml.model_ws, "freyberg.hds")) - cbc = CellBudgetFile(os.path.join(ml.model_ws, "freyberg.cbc")) + ws = example_data_path / "freyberg_multilayer_transient" + ml = Modflow.load("freyberg.nam", model_ws=ws) + head = HeadFile(ws / "freyberg.hds") + cbc = CellBudgetFile(ws / "freyberg.cbc") flopy.export.utils.output_helper( - os.path.join(function_tmpdir, "test.shp"), + function_tmpdir / "test.shp", ml, {"HDS": head, "cbc": cbc}, mflay=1, @@ -85,7 +83,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): # steady state name = "freyberg" namfile = f"{name}.nam" - ws = str(example_data_path / name) + ws = example_data_path / name m = flopy.modflow.Modflow.load( namfile, model_ws=ws, check=False, verbose=False ) @@ -99,7 +97,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): # transient # (doesn't work at model level because the total size of # the attribute fields exceeds the shapefile limit) - ws = str(example_data_path / "freyberg_multilayer_transient") + ws = example_data_path / "freyberg_multilayer_transient" m = flopy.modflow.Modflow.load( namfile, model_ws=ws, @@ -108,7 +106,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): ) # test export without instantiating an sr shape = function_tmpdir / f"{name}_drn_sparse.shp" - m.drn.stress_period_data.export(str(shape), sparse=True) + m.drn.stress_period_data.export(shape, sparse=True) for suffix in [".dbf", ".shp", ".shx"]: part = shape.with_suffix(suffix) assert part.exists() @@ -119,7 +117,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): delc=m.dis.delc.array, delr=m.dis.delr.array, epsg=3070 ) # test export with an sr, regardless of whether or not wkt was found - m.drn.stress_period_data.export(str(shape), sparse=True) + m.drn.stress_period_data.export(shape, sparse=True) for suffix in [".dbf", ".prj", ".shp", ".shx"]: part = shape.with_suffix(suffix) assert part.exists() @@ -144,7 +142,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): if wkt is not None: # test default package export shape = function_tmpdir / f"{name}_dis.shp" - m.dis.export(str(shape)) + m.dis.export(shape) for suffix in [".dbf", ".prj", ".shp", ".shx"]: part = shape.with_suffix(suffix) assert part.exists() @@ -156,7 +154,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): # test sparse package export shape = function_tmpdir / f"{name}_drn_sparse.shp" - m.drn.stress_period_data.export(str(shape), sparse=True) + m.drn.stress_period_data.export(shape, sparse=True) for suffix in [".dbf", ".prj", ".shp", ".shx"]: part = shape.with_suffix(suffix) assert part.exists() @@ -166,9 +164,7 @@ def test_freyberg_export(function_tmpdir, example_data_path): @requires_pkg("netCDF4", "pyproj") def test_export_output(function_tmpdir, example_data_path): - ml = Modflow.load( - "freyberg.nam", model_ws=str(example_data_path / "freyberg") - ) + ml = Modflow.load("freyberg.nam", model_ws=example_data_path / "freyberg") hds_pth = os.path.join(ml.model_ws, "freyberg.githds") hds = flopy.utils.HeadFile(hds_pth) @@ -303,7 +299,7 @@ def test_export_array(function_tmpdir, example_data_path): model_ws = example_data_path / "freyberg" m = flopy.modflow.Modflow.load( namfile, - model_ws=str(model_ws), + model_ws=model_ws, verbose=False, load_only=["DIS", "BAS6"], ) @@ -315,12 +311,12 @@ def test_export_array(function_tmpdir, example_data_path): m.dis.top.array, nodata=nodata, ) - arr = np.loadtxt(os.path.join(function_tmpdir, "fb.asc"), skiprows=6) + arr = np.loadtxt(function_tmpdir / "fb.asc", skiprows=6) - m.modelgrid.write_shapefile(os.path.join(function_tmpdir, "grid.shp")) + m.modelgrid.write_shapefile(function_tmpdir / "grid.shp") # check bounds - with open(os.path.join(function_tmpdir, "fb.asc")) as src: + with open(function_tmpdir / "fb.asc") as src: for line in src: if "xllcorner" in line.lower(): val = float(line.strip().split()[-1]) @@ -346,11 +342,11 @@ def test_export_array(function_tmpdir, example_data_path): export_array( m.modelgrid, - os.path.join(function_tmpdir, "fb.tif"), + function_tmpdir / "fb.tif", m.dis.top.array, nodata=nodata, ) - with rasterio.open(os.path.join(function_tmpdir, "fb.tif")) as src: + with rasterio.open(function_tmpdir / "fb.tif") as src: arr = src.read(1) assert src.shape == (m.nrow, m.ncol) # TODO: these tests currently fail -- fix is in progress @@ -366,15 +362,15 @@ def test_netcdf_classmethods(function_tmpdir, example_data_path): model_ws = example_data_path / "freyberg_multilayer_transient" ml = flopy.modflow.Modflow.load( namfile, - model_ws=str(model_ws), + model_ws=model_ws, check=False, verbose=True, load_only=[], ) - f = ml.export(os.path.join(function_tmpdir, "freyberg.nc")) + f = ml.export(function_tmpdir / "freyberg.nc") v1_set = set(f.nc.variables.keys()) - fnc = os.path.join(function_tmpdir, "freyberg.new.nc") + fnc = function_tmpdir / "freyberg.new.nc" new_f = flopy.export.NetCdf.zeros_like(f, output_filename=fnc) v2_set = set(new_f.nc.variables.keys()) diff = v1_set.symmetric_difference(v2_set) @@ -429,7 +425,7 @@ def test_shapefile_ibound(function_tmpdir, example_data_path): model_ws = example_data_path / "freyberg_multilayer_transient" ml = flopy.modflow.Modflow.load( namfile, - model_ws=str(model_ws), + model_ws=model_ws, check=False, verbose=True, load_only=["bas6"], @@ -450,14 +446,14 @@ def test_shapefile(function_tmpdir, namfile): from shapefile import Reader model = flopy.modflow.Modflow.load( - namfile.name, model_ws=str(namfile.parent), verbose=False + namfile.name, model_ws=namfile.parent, verbose=False ) assert model, f"Could not load namefile {namfile}" msg = f"Could not load {namfile} model" assert isinstance(model, flopy.modflow.Modflow), msg - fnc_name = os.path.join(function_tmpdir, f"{model.name}.shp") + fnc_name = function_tmpdir / f"{model.name}.shp" fnc = model.export(fnc_name) # fnc2 = m.export(fnc_name, package_names=None) # fnc3 = m.export(fnc_name, package_names=['DIS']) @@ -495,7 +491,7 @@ def test_shapefile_export_modelgrid_override(function_tmpdir, namfile): assert model, f"Could not load namefile {namfile}" assert isinstance(model, flopy.modflow.Modflow) - fnc_name = os.path.join(function_tmpdir, f"{model.name}.shp") + fnc_name = function_tmpdir / f"{model.name}.shp" model.export(fnc_name, modelgrid=modelgrid) # TODO: do we want to test exports with package_names options too? @@ -514,7 +510,7 @@ def test_export_netcdf(function_tmpdir, namfile): from netCDF4 import Dataset model = flopy.modflow.Modflow.load( - namfile.name, model_ws=str(namfile.parent), verbose=False + namfile.name, model_ws=namfile.parent, verbose=False ) if model.dis.lenuni == 0: model.dis.lenuni = 1 @@ -526,9 +522,9 @@ def test_export_netcdf(function_tmpdir, namfile): assert model, f"Could not load namefile {namfile}" assert isinstance(model, flopy.modflow.Modflow) - fnc = model.export(os.path.join(function_tmpdir, f"{model.name}.nc")) + fnc = model.export(function_tmpdir / f"{model.name}.nc") fnc.write() - fnc_name = os.path.join(function_tmpdir, f"{model.name}.nc") + fnc_name = function_tmpdir / f"{model.name}.nc" fnc = model.export(fnc_name) fnc.write() @@ -580,7 +576,7 @@ def test_export_array_contours(function_tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1 ) - filename = os.path.join(function_tmpdir, "myarraycontours1.shp") + filename = function_tmpdir / "myarraycontours1.shp" a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array_contours(modelgrid, filename, a) assert os.path.isfile(filename), "did not create contour shapefile" @@ -589,7 +585,7 @@ def test_export_array_contours(function_tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1, epsg=epsg ) - filename = os.path.join(function_tmpdir, "myarraycontours2.shp") + filename = function_tmpdir / "myarraycontours2.shp" a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array_contours(modelgrid, filename, a) assert os.path.isfile(filename), "did not create contour shapefile" @@ -598,7 +594,7 @@ def test_export_array_contours(function_tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1 ) - filename = os.path.join(function_tmpdir, "myarraycontours3.shp") + filename = function_tmpdir / "myarraycontours3.shp" a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array_contours(modelgrid, filename, a, epsg=epsg) assert os.path.isfile(filename), "did not create contour shapefile" @@ -608,10 +604,10 @@ def test_export_array_contours(function_tmpdir): def test_export_contourf(function_tmpdir, example_data_path): from shapefile import Reader - filename = os.path.join(function_tmpdir, "myfilledcontours.shp") + filename = function_tmpdir / "myfilledcontours.shp" mpath = example_data_path / "freyberg" ml = Modflow.load("freyberg.nam", model_ws=mpath) - hds_pth = os.path.join(ml.model_ws, "freyberg.githds") + hds_pth = ml.model_ws / "freyberg.githds" hds = flopy.utils.HeadFile(hds_pth) head = hds.get_data() levels = np.arange(10, 30, 0.5) @@ -639,10 +635,10 @@ def test_export_contourf(function_tmpdir, example_data_path): def test_export_contours(function_tmpdir, example_data_path): from shapefile import Reader - filename = os.path.join(function_tmpdir, "mycontours.shp") + filename = function_tmpdir / "mycontours.shp" mpath = example_data_path / "freyberg" ml = Modflow.load("freyberg.nam", model_ws=mpath) - hds_pth = os.path.join(ml.model_ws, "freyberg.githds") + hds_pth = ml.model_ws / "freyberg.githds" hds = flopy.utils.HeadFile(hds_pth) head = hds.get_data() levels = np.arange(10, 30, 0.5) @@ -680,7 +676,7 @@ def test_mf6_grid_shp_export(function_tmpdir): m = flopy.modflow.Modflow( "junk", version="mfnwt", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis = flopy.modflow.ModflowDis( m, @@ -724,7 +720,7 @@ def test_mf6_grid_shp_export(function_tmpdir): sim_name=mf6name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) tdis = flopy.mf6.modflow.mftdis.ModflowTdis( sim, pname="tdis", time_units="DAYS", nper=nper, perioddata=perioddata @@ -767,12 +763,12 @@ def cellid(k, i, j, nrow, ncol): return # rch6.export('{}/mf6.shp'.format(baseDir)) - m.export(str(function_tmpdir / "mfnwt.shp")) - gwf.export(str(function_tmpdir / "mf6.shp")) + m.export(function_tmpdir / "mfnwt.shp") + gwf.export(function_tmpdir / "mf6.shp") # check that the two shapefiles are the same - ra = shp2recarray(str(function_tmpdir / "mfnwt.shp")) - ra6 = shp2recarray(str(function_tmpdir / "mf6.shp")) + ra = shp2recarray(function_tmpdir / "mfnwt.shp") + ra6 = shp2recarray(function_tmpdir / "mf6.shp") # check first and last exported cells assert ra.geometry[0] == ra6.geometry[0] @@ -811,7 +807,7 @@ def test_export_huge_shapefile(function_tmpdir): botm = np.zeros((nlay, nrow, ncol)) m = flopy.modflow.Modflow( - "junk", version="mfnwt", model_ws=str(function_tmpdir) + "junk", version="mfnwt", model_ws=function_tmpdir ) flopy.modflow.ModflowDis( m, @@ -826,14 +822,13 @@ def test_export_huge_shapefile(function_tmpdir): botm=botm, ) - m.export(str(function_tmpdir / "huge.shp")) + m.export(function_tmpdir / "huge.shp") @requires_pkg("netCDF4", "pyproj") def test_polygon_from_ij(function_tmpdir): """test creation of a polygon from an i, j location using get_vertices().""" - ws = str(function_tmpdir) - m = Modflow("toy_model", model_ws=ws) + m = Modflow("toy_model", model_ws=function_tmpdir) botm = np.zeros((2, 10, 10)) botm[0, :, :] = 1.5 @@ -843,14 +838,14 @@ def test_polygon_from_ij(function_tmpdir): nrow=10, ncol=10, nlay=2, delr=100, delc=100, top=3, botm=botm, model=m ) - fname = os.path.join(ws, "toy.model.nc") + fname = function_tmpdir / "toy.model.nc" ncdf = NetCdf(fname, m) ncdf.write() - fname = os.path.join(ws, "toy_model_two.nc") + fname = function_tmpdir / "toy_model_two.nc" m.export(fname) - fname = os.path.join(ws, "toy_model_dis.nc") + fname = function_tmpdir / "toy_model_dis.nc" dis.export(fname) mg = m.modelgrid @@ -891,7 +886,7 @@ def test_polygon_from_ij(function_tmpdir): @requires_pkg("netCDF4", "pyproj") @requires_spatial_reference def test_polygon_from_ij_with_epsg(function_tmpdir): - ws = str(function_tmpdir) + ws = function_tmpdir m = Modflow("toy_model", model_ws=ws) botm = np.zeros((2, 10, 10)) @@ -902,14 +897,14 @@ def test_polygon_from_ij_with_epsg(function_tmpdir): nrow=10, ncol=10, nlay=2, delr=100, delc=100, top=3, botm=botm, model=m ) - fname = os.path.join(ws, "toy.model.nc") + fname = ws / "toy.model.nc" ncdf = NetCdf(fname, m) ncdf.write() - fname = os.path.join(ws, "toy_model_two.nc") + fname = ws / "toy_model_two.nc" m.export(fname) - fname = os.path.join(ws, "toy_model_dis.nc") + fname = ws / "toy_model_dis.nc" dis.export(fname) mg = m.modelgrid @@ -989,19 +984,19 @@ def is_binary_file(filepath): @requires_pkg("vtk") def test_vtk_export_array2d(function_tmpdir, example_data_path): # test mf 2005 freyberg - mpath = str(example_data_path / "freyberg_multilayer_transient") + mpath = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" m = Modflow.load( namfile, model_ws=mpath, verbose=False, load_only=["dis", "bas6"] ) # export and check - m.dis.top.export(str(function_tmpdir), name="top", fmt="vtk", binary=False) + m.dis.top.export(function_tmpdir, name="top", fmt="vtk", binary=False) assert count_lines_in_file(function_tmpdir / "top.vtk") == 17615 # with smoothing m.dis.top.export( - str(function_tmpdir), + function_tmpdir, fmt="vtk", name="top_smooth", binary=False, @@ -1013,7 +1008,7 @@ def test_vtk_export_array2d(function_tmpdir, example_data_path): @requires_pkg("vtk") def test_vtk_export_array3d(function_tmpdir, example_data_path): # test mf 2005 freyberg - mpath = str(example_data_path / "freyberg_multilayer_transient") + mpath = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" m = Modflow.load( namfile, @@ -1023,12 +1018,12 @@ def test_vtk_export_array3d(function_tmpdir, example_data_path): ) # export and check - m.upw.hk.export(str(function_tmpdir), fmt="vtk", name="hk", binary=False) + m.upw.hk.export(function_tmpdir, fmt="vtk", name="hk", binary=False) assert count_lines_in_file(function_tmpdir / "hk.vtk") == 17615 # with point scalars m.upw.hk.export( - str(function_tmpdir), + function_tmpdir, fmt="vtk", name="hk_points", point_scalars=True, @@ -1038,7 +1033,7 @@ def test_vtk_export_array3d(function_tmpdir, example_data_path): # with point scalars and binary m.upw.hk.export( - str(function_tmpdir), + function_tmpdir, fmt="vtk", name="hk_points_bin", point_scalars=True, @@ -1049,8 +1044,8 @@ def test_vtk_export_array3d(function_tmpdir, example_data_path): @requires_pkg("vtk") def test_vtk_transient_array_2d(function_tmpdir, example_data_path): # test mf 2005 freyberg - ws = str(function_tmpdir) - mpath = str(example_data_path / "freyberg_multilayer_transient") + ws = function_tmpdir + mpath = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" m = Modflow.load( namfile, @@ -1077,8 +1072,8 @@ def test_vtk_transient_array_2d(function_tmpdir, example_data_path): @pytest.mark.slow def test_vtk_export_packages(function_tmpdir, example_data_path): # test mf 2005 freyberg - ws = str(function_tmpdir) - mpath = str(example_data_path / "freyberg_multilayer_transient") + ws = function_tmpdir + mpath = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" m = Modflow.load( namfile, @@ -1122,7 +1117,7 @@ def test_vtk_export_packages(function_tmpdir, example_data_path): @requires_pkg("vtk") def test_vtk_mf6(function_tmpdir, example_data_path): # test mf6 - mf6expth = str(example_data_path / "mf6") + mf6expth = example_data_path / "mf6" mf6sims = [ "test045_lake1ss_table", "test036_twrihfb", @@ -1132,14 +1127,14 @@ def test_vtk_mf6(function_tmpdir, example_data_path): for simnm in mf6sims: print(simnm) - simpth = os.path.join(mf6expth, simnm) + simpth = mf6expth / simnm loaded_sim = MFSimulation.load(simnm, "mf6", "mf6", simpth) sim_models = loaded_sim.model_names print(sim_models) for mname in sim_models: print(mname) m = loaded_sim.get_model(mname) - m.export(str(function_tmpdir), fmt="vtk", binary=False) + m.export(function_tmpdir, fmt="vtk", binary=False) # check one filetocheck = function_tmpdir / "twrihfb2015_000000.vtk" @@ -1152,9 +1147,9 @@ def test_vtk_mf6(function_tmpdir, example_data_path): @pytest.mark.slow def test_vtk_binary_head_export(function_tmpdir, example_data_path): # test mf 2005 freyberg - mpth = str(example_data_path / "freyberg_multilayer_transient") + mpth = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" - hdsfile = os.path.join(mpth, "freyberg.hds") + hdsfile = mpth / "freyberg.hds" heads = HeadFile(hdsfile) m = Modflow.load( namfile, model_ws=mpth, verbose=False, load_only=["dis", "bas6"] @@ -1199,8 +1194,7 @@ def test_vtk_binary_head_export(function_tmpdir, example_data_path): def test_vtk_cbc(function_tmpdir, example_data_path): # test mf 2005 freyberg - ws = str(function_tmpdir) - mpth = str(example_data_path / "freyberg_multilayer_transient") + mpth = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" cbcfile = os.path.join(mpth, "freyberg.cbc") cbc = CellBudgetFile(cbcfile) @@ -1231,7 +1225,7 @@ def test_vtk_cbc(function_tmpdir, example_data_path): @pytest.mark.slow def test_vtk_vector(function_tmpdir, example_data_path): # test mf 2005 freyberg - mpth = str(example_data_path / "freyberg_multilayer_transient") + mpth = example_data_path / "freyberg_multilayer_transient" namfile = "freyberg.nam" cbcfile = os.path.join(mpth, "freyberg.cbc") hdsfile = os.path.join(mpth, "freyberg.hds") @@ -1349,7 +1343,7 @@ def test_vtk_vertex(function_tmpdir, example_data_path): from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader # disv test - workspace = str(example_data_path / "mf6" / "test003_gwfs_disv") + workspace = example_data_path / "mf6" / "test003_gwfs_disv" # outfile = os.path.join("vtk_transient_test", "vtk_pacakages") sim = MFSimulation.load(sim_ws=workspace) gwf = sim.get_model("gwf_1") @@ -1384,17 +1378,20 @@ def test_vtk_pathline(function_tmpdir, example_data_path): from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader # pathline test for vtk - ws = str(example_data_path / "freyberg") - ml = Modflow.load("freyberg.nam", model_ws=ws, exe_name="mf2005") + ml = Modflow.load( + "freyberg.nam", + model_ws=example_data_path / "freyberg", + exe_name="mf2005", + ) - ml.change_model_ws(new_pth=str(function_tmpdir)) + ml.change_model_ws(new_pth=function_tmpdir) ml.write_input() ml.run_model() mpp = Modpath6( "freybergmpp", modflowmodel=ml, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, exe_name="mp6", ) mpbas = Modpath6Bas( @@ -1512,9 +1509,7 @@ def test_vtk_export_model_without_packages_names(function_tmpdir): from flopy.export.vtk import Vtk name = "mymodel" - sim = MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" - ) + sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name="mf6") tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1569,9 +1564,7 @@ def test_vtk_export_disv1_model(function_tmpdir): from flopy.export.vtk import Vtk name = "mymodel" - sim = MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" - ) + sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name="mf6") tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1644,9 +1637,7 @@ def test_vtk_export_disv2_model(function_tmpdir): # in this case, test for iverts that do not explicitly close the cell polygons name = "mymodel" - sim = MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" - ) + sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name="mf6") tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1925,9 +1916,7 @@ def test_vtk_export_disu_model(function_tmpdir): gridprops = g.get_gridprops_disu6() - sim = MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" - ) + sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name="mf6") tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) diff --git a/autotest/test_flopy_module.py b/autotest/test_flopy_module.py index 9e12c949ee..bc623c2b9a 100644 --- a/autotest/test_flopy_module.py +++ b/autotest/test_flopy_module.py @@ -42,7 +42,7 @@ def test_modflow(): def test_modflow_unstructured(function_tmpdir): import flopy - mf = flopy.mfusg.MfUsg(structured=False, model_ws=str(function_tmpdir)) + mf = flopy.mfusg.MfUsg(structured=False, model_ws=function_tmpdir) assert isinstance(mf, flopy.mfusg.MfUsg) disu = flopy.mfusg.MfUsgDisU( @@ -74,14 +74,14 @@ def test_modflow_unstructured(function_tmpdir): wel.write_file() wel_path = Path(function_tmpdir / f"{mf.name}.wel") assert wel_path.is_file() - wel2 = flopy.mfusg.MfUsgWel.load(str(wel_path), mf) + wel2 = flopy.mfusg.MfUsgWel.load(wel_path, mf) assert wel2.stress_period_data[0] == wel.stress_period_data[0] # write ghb file ghb.write_file(check=False) ghb_path = Path(function_tmpdir / f"{mf.name}.ghb") assert ghb_path.is_file() is True - ghb2 = flopy.modflow.ModflowGhb.load(str(ghb_path), mf) + ghb2 = flopy.modflow.ModflowGhb.load(ghb_path, mf) def test_mflist_reference(function_tmpdir): @@ -162,7 +162,7 @@ def test_pyinstaller_flopy_runs_without_dfn_folder( # run built executable sim_path = example_data_path / "mf6" / "test006_gwf3" - flopy.mf6.MFSimulation.load(sim_ws=str(sim_path)) + flopy.mf6.MFSimulation.load(sim_ws=sim_path) finally: if exists and rename_path.exists(): os.rename(rename_path, dfn_path) diff --git a/autotest/test_formattedfile.py b/autotest/test_formattedfile.py index fc567b9ecd..84cd88b5ee 100644 --- a/autotest/test_formattedfile.py +++ b/autotest/test_formattedfile.py @@ -12,9 +12,7 @@ def freyberg_model_path(example_data_path): def test_formattedfile_reference(example_data_path): - h = FormattedHeadFile( - str(example_data_path / "mf2005_test" / "test1tr.githds") - ) + h = FormattedHeadFile(example_data_path / "mf2005_test" / "test1tr.githds") assert isinstance(h, FormattedHeadFile) h.mg.set_coord_info(xoff=1000.0, yoff=200.0, angrot=15.0) @@ -24,7 +22,7 @@ def test_formattedfile_reference(example_data_path): def test_formattedfile_read(function_tmpdir, example_data_path): mf2005_model_path = example_data_path / "mf2005_test" - h = FormattedHeadFile(str(mf2005_model_path / "test1tr.githds")) + h = FormattedHeadFile(mf2005_model_path / "test1tr.githds") assert isinstance(h, FormattedHeadFile) times = h.get_times() @@ -51,7 +49,7 @@ def test_formattedfile_read(function_tmpdir, example_data_path): h.close() # Check error when reading empty file - fname = str(function_tmpdir / "empty.githds") + fname = function_tmpdir / "empty.githds" with open(fname, "w"): pass with pytest.raises(ValueError): diff --git a/autotest/test_gage.py b/autotest/test_gage.py index 35a2778981..04d3879b06 100644 --- a/autotest/test_gage.py +++ b/autotest/test_gage.py @@ -44,7 +44,7 @@ def get_namefile_entries(fpth): def test_gage(function_tmpdir): mnam = "gage_test" - m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) + m = Modflow(modelname=mnam, model_ws=function_tmpdir) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -65,7 +65,7 @@ def test_gage(function_tmpdir): m.write_input() # check that the gage output units entries are in the name file - fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") + fpth = function_tmpdir / f"{mnam}.nam" entries = get_namefile_entries(fpth) for idx, g in enumerate(gages): if g[0] < 0: @@ -85,7 +85,7 @@ def test_gage(function_tmpdir): def test_gage_files(function_tmpdir): mnam = "gage_test_files" - m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) + m = Modflow(modelname=mnam, model_ws=function_tmpdir) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -107,7 +107,7 @@ def test_gage_files(function_tmpdir): m.write_input() # check that the gage output file entries are in the name file - fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") + fpth = function_tmpdir / f"{mnam}.nam" entries = get_namefile_entries(fpth) for idx, f in enumerate(files): found = False @@ -129,7 +129,7 @@ def test_gage_files(function_tmpdir): def test_gage_filenames0(function_tmpdir): mnam = "gage_test_filenames0" - m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) + m = Modflow(modelname=mnam, model_ws=function_tmpdir) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -151,7 +151,7 @@ def test_gage_filenames0(function_tmpdir): m.write_input() # check that the gage output units entries are in the name file - fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") + fpth = function_tmpdir / f"{mnam}.nam" entries = get_namefile_entries(fpth) for idx, g in enumerate(gages): if g[0] < 0: @@ -171,7 +171,7 @@ def test_gage_filenames0(function_tmpdir): def test_gage_filenames(function_tmpdir): mnam = "gage_test_filenames" - m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) + m = Modflow(modelname=mnam, model_ws=function_tmpdir) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -193,7 +193,7 @@ def test_gage_filenames(function_tmpdir): m.write_input() # check that the gage output file entries are in the name file - fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") + fpth = function_tmpdir / f"{mnam}.nam" entries = get_namefile_entries(fpth) for idx, f in enumerate(filenames[1:]): found = False diff --git a/autotest/test_grid.py b/autotest/test_grid.py index 1ccdb92ce1..0bd5242340 100644 --- a/autotest/test_grid.py +++ b/autotest/test_grid.py @@ -256,7 +256,7 @@ def test_intersection(dis_model, disv_model): def test_structured_xyz_intersect(example_data_path): ml = Modflow.load( "freyberg.nam", - model_ws=str(example_data_path / "freyberg_multilayer_transient"), + model_ws=example_data_path / "freyberg_multilayer_transient", ) mg = ml.modelgrid @@ -279,7 +279,7 @@ def test_structured_xyz_intersect(example_data_path): def test_vertex_xyz_intersect(example_data_path): sim = MFSimulation.load( - sim_ws=str(example_data_path / "mf6" / "test003_gwfs_disv") + sim_ws=example_data_path / "mf6" / "test003_gwfs_disv" ) ml = sim.get_model(list(sim.model_names)[0]) mg = ml.modelgrid @@ -300,11 +300,11 @@ def test_vertex_xyz_intersect(example_data_path): def test_unstructured_xyz_intersect(example_data_path): - ws = str(example_data_path / "unstructured") - name = os.path.join(ws, "ugrid_verts.dat") + ws = example_data_path / "unstructured" + name = ws / "ugrid_verts.dat" verts = load_verts(name) - name = os.path.join(ws, "ugrid_iverts.dat") + name = ws / "ugrid_iverts.dat" iverts, xc, yc = load_iverts(name) # create a 3 layer model grid @@ -356,7 +356,7 @@ def test_unstructured_xyz_intersect(example_data_path): def test_structured_neighbors(example_data_path): - ws = str(example_data_path / "freyberg") + ws = example_data_path / "freyberg" ml = Modflow.load("freyberg.nam", model_ws=ws) modelgrid = ml.modelgrid k, i, j = 0, 5, 5 @@ -374,7 +374,7 @@ def test_structured_neighbors(example_data_path): def test_vertex_neighbors(example_data_path): - ws = str(example_data_path / "mf6" / "test003_gwfs_disv") + ws = example_data_path / "mf6" / "test003_gwfs_disv" sim = MFSimulation.load(sim_ws=ws) gwf = sim.get_model("gwf_1") modelgrid = gwf.modelgrid @@ -393,7 +393,7 @@ def test_vertex_neighbors(example_data_path): def test_unstructured_neighbors(example_data_path): - ws = str(example_data_path / "mf6" / "test006_gwf3") + ws = example_data_path / "mf6" / "test006_gwf3" sim = MFSimulation.load(sim_ws=ws) gwf = sim.get_model("gwf_1") modelgrid = gwf.modelgrid @@ -405,7 +405,7 @@ def test_unstructured_neighbors(example_data_path): @pytest.mark.parametrize("spc_file", ["grd.spc", "grdrot.spc"]) def test_structured_from_gridspec(example_data_path, spc_file): - fn = str(example_data_path / "specfile" / spc_file) + fn = example_data_path / "specfile" / spc_file modelgrid = StructuredGrid.from_gridspec(fn) assert isinstance(modelgrid, StructuredGrid) @@ -417,7 +417,7 @@ def test_structured_from_gridspec(example_data_path, spc_file): extents = modelgrid.extent theta = modelgrid.angrot_radians - if "rot" in fn: + if "rot" in str(fn): assert theta != 0, "rotation missing" rotated_extents = ( 0, # xmin @@ -450,10 +450,10 @@ def test_structured_from_gridspec(example_data_path, spc_file): @requires_pkg("shapely") def test_unstructured_from_argus_mesh(example_data_path): - datapth = str(example_data_path / "unstructured") + datapth = example_data_path / "unstructured" fnames = [fname for fname in os.listdir(datapth) if fname.endswith(".exp")] for fname in fnames: - fname = os.path.join(datapth, fname) + fname = datapth / fname print(f"Loading Argus mesh ({fname}) into UnstructuredGrid") g = UnstructuredGrid.from_argus_export(fname) print(f" Number of nodes: {g.nnodes}") @@ -462,7 +462,7 @@ def test_unstructured_from_argus_mesh(example_data_path): def test_unstructured_from_verts_and_iverts( function_tmpdir, example_data_path ): - datapth = str(example_data_path / "unstructured") + datapth = example_data_path / "unstructured" # simple functions to load vertices and incidence lists def load_verts(fname): @@ -487,11 +487,11 @@ def load_iverts(fname): return iverts, np.array(xc), np.array(yc) # load vertices - fname = os.path.join(datapth, "ugrid_verts.dat") + fname = datapth / "ugrid_verts.dat" verts = load_verts(fname) # load the incidence list into iverts - fname = os.path.join(datapth, "ugrid_iverts.dat") + fname = datapth / "ugrid_iverts.dat" iverts, xc, yc = load_iverts(fname) ncpl = np.array(5 * [len(iverts)]) @@ -505,7 +505,7 @@ def load_iverts(fname): def test_unstructured_from_gridspec(example_data_path): model_path = example_data_path / "freyberg_usg" - spec_path = str(model_path / "freyberg.usg.gsf") + spec_path = model_path / "freyberg.usg.gsf" grid = UnstructuredGrid.from_gridspec(spec_path) with open(spec_path) as file: @@ -805,7 +805,7 @@ def test_triangle_unstructured_grid(function_tmpdir): tri = Triangle( maximum_area=maximum_area, angle=30, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) tri.add_polygon(domainpoly) tri.build(verbose=False) @@ -832,9 +832,7 @@ def test_voronoi_vertex_grid(function_tmpdir): ymin = 0.0 ymax = 1.0 area_max = 0.05 - tri = Triangle( - maximum_area=area_max, angle=30, model_ws=str(function_tmpdir) - ) + tri = Triangle(maximum_area=area_max, angle=30, model_ws=function_tmpdir) poly = np.array(((xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax))) tri.add_polygon(poly) tri.build(verbose=False) @@ -888,7 +886,7 @@ def test_voronoi_grid(request, function_tmpdir, grid_info): grid.ycellcenters[invalid_cells], "ro", ) - plt.savefig(os.path.join(str(function_tmpdir), f"{name}.png")) + plt.savefig(function_tmpdir / f"{name}.png") assert ncpl == gridprops["ncpl"] or almost_right assert ( diff --git a/autotest/test_gridgen.py b/autotest/test_gridgen.py index b1c690f512..b718a9f2fd 100644 --- a/autotest/test_gridgen.py +++ b/autotest/test_gridgen.py @@ -31,7 +31,7 @@ def test_mf6disv(function_tmpdir): # Create a dummy model and regular grid to use as the base grid for gridgen sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + sim_name=name, sim_ws=function_tmpdir, exe_name="mf6" ) gwf = flopy.mf6.ModflowGwf(sim, modelname=name) @@ -47,7 +47,7 @@ def test_mf6disv(function_tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(gwf.modelgrid, model_ws=str(function_tmpdir)) + g = Gridgen(gwf.modelgrid, model_ws=function_tmpdir) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, range(nlay)) g.build() @@ -64,7 +64,7 @@ def test_mf6disv(function_tmpdir): # build run and post-process the MODFLOW 6 model name = "mymodel" sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + sim_name=name, sim_ws=function_tmpdir, exe_name="mf6" ) tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim, linear_acceleration="bicgstab") @@ -88,9 +88,9 @@ def test_mf6disv(function_tmpdir): gwf.modelgrid.set_coord_info(angrot=15) # write grid and model shapefiles - fname = os.path.join(str(function_tmpdir), "grid.shp") + fname = function_tmpdir / "grid.shp" gwf.modelgrid.write_shapefile(fname) - fname = os.path.join(str(function_tmpdir), "model.shp") + fname = function_tmpdir / "model.shp" gwf.export(fname) sim.run_simulation(silent=True) @@ -116,7 +116,7 @@ def test_mf6disv(function_tmpdir): ax.set_title(f"Layer {ilay + 1}") pmv.plot_vector(spdis["qx"], spdis["qy"], color="white") fname = "results.png" - fname = os.path.join(str(function_tmpdir), fname) + fname = function_tmpdir / fname plt.savefig(fname) plt.close("all") @@ -127,7 +127,7 @@ def test_mf6disv(function_tmpdir): sim_name=name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) # get gwf model gwf = sim.get_model(name) @@ -170,7 +170,7 @@ def test_mf6disu(function_tmpdir): # Create a dummy model and regular grid to use as the base grid for gridgen sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + sim_name=name, sim_ws=function_tmpdir, exe_name="mf6" ) gwf = flopy.mf6.ModflowGwf(sim, modelname=name) @@ -186,7 +186,7 @@ def test_mf6disu(function_tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(gwf.modelgrid, model_ws=str(function_tmpdir)) + g = Gridgen(gwf.modelgrid, model_ws=function_tmpdir) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, layers=[0]) g.build() @@ -201,7 +201,7 @@ def test_mf6disu(function_tmpdir): # build run and post-process the MODFLOW 6 model name = "mymodel" sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + sim_name=name, sim_ws=function_tmpdir, exe_name="mf6" ) tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim, linear_acceleration="bicgstab") @@ -231,9 +231,9 @@ def test_mf6disu(function_tmpdir): assert np.allclose(gwf.modelgrid.ncpl, np.array([436, 184, 112])) # write grid and model shapefiles - fname = os.path.join(str(function_tmpdir), "grid.shp") + fname = function_tmpdir / "grid.shp" gwf.modelgrid.write_shapefile(fname) - fname = os.path.join(str(function_tmpdir), "model.shp") + fname = function_tmpdir / "model.shp" gwf.export(fname) sim.run_simulation(silent=True) @@ -260,7 +260,7 @@ def test_mf6disu(function_tmpdir): ax.set_title(f"Layer {ilay + 1}") pmv.plot_vector(spdis["qx"], spdis["qy"], color="white") fname = "results.png" - fname = os.path.join(str(function_tmpdir), fname) + fname = function_tmpdir / fname plt.savefig(fname) plt.close("all") @@ -295,7 +295,7 @@ def test_mf6disu(function_tmpdir): sim_name=name, version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) gwf = sim.get_model(name) @@ -340,7 +340,7 @@ def test_mfusg(function_tmpdir): botm = [top - k * dz for k in range(1, nlay + 1)] # create dummy model and dis package for gridgen - m = flopy.modflow.Modflow(modelname=name, model_ws=str(function_tmpdir)) + m = flopy.modflow.Modflow(modelname=name, model_ws=function_tmpdir) dis = flopy.modflow.ModflowDis( m, nlay=nlay, @@ -353,7 +353,7 @@ def test_mfusg(function_tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(m.modelgrid, model_ws=str(function_tmpdir)) + g = Gridgen(m.modelgrid, model_ws=function_tmpdir) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, layers=[0]) g.build() @@ -371,7 +371,7 @@ def test_mfusg(function_tmpdir): name = "mymodel" m = flopy.mfusg.MfUsg( modelname=name, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, exe_name="mfusg", structured=False, ) @@ -393,7 +393,7 @@ def test_mfusg(function_tmpdir): m.run_model() # head is returned as a list of head arrays for each layer - head_file = os.path.join(str(function_tmpdir), f"{name}.hds") + head_file = function_tmpdir / f"{name}.hds" head = flopy.utils.HeadUFile(head_file).get_data() f = plt.figure(figsize=(10, 10)) @@ -411,7 +411,7 @@ def test_mfusg(function_tmpdir): ax.set_title(f"Layer {ilay + 1}") # pmv.plot_specific_discharge(spdis, color='white') fname = "results.png" - fname = os.path.join(str(function_tmpdir), fname) + fname = function_tmpdir / fname plt.savefig(fname) plt.close("all") @@ -447,7 +447,7 @@ def test_mfusg(function_tmpdir): # also test load of unstructured LPF with keywords lpf2 = flopy.mfusg.MfUsgLpf.load( - os.path.join(str(function_tmpdir), f"{name}.lpf"), m, check=False + function_tmpdir / f"{name}.lpf", m, check=False ) msg = "NOCVCORRECTION and NOVFC should be in lpf options but at least one is not." assert ( @@ -456,10 +456,10 @@ def test_mfusg(function_tmpdir): ), msg # test disu, bas6, lpf shapefile export for mfusg unstructured models - m.disu.export(os.path.join(str(function_tmpdir), f"{name}_disu.shp")) - m.bas6.export(os.path.join(str(function_tmpdir), f"{name}_bas6.shp")) - m.lpf.export(os.path.join(str(function_tmpdir), f"{name}_lpf.shp")) - m.export(os.path.join(str(function_tmpdir), f"{name}.shp")) + m.disu.export(function_tmpdir / f"{name}_disu.shp") + m.bas6.export(function_tmpdir / f"{name}_bas6.shp") + m.lpf.export(function_tmpdir / f"{name}_lpf.shp") + m.export(function_tmpdir / f"{name}.shp") @pytest.mark.slow @@ -506,7 +506,7 @@ def test_gridgen(function_tmpdir): ms_u = flopy.mfusg.MfUsg( modelname="mymfusgmodel", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis_usg = flopy.modflow.ModflowDis( ms_u, @@ -520,7 +520,7 @@ def test_gridgen(function_tmpdir): ) gridgen = Path(which("gridgen")).name - ws = str(function_tmpdir) + ws = function_tmpdir g = Gridgen(ms.modelgrid, model_ws=ws, exe_name=gridgen) g6 = Gridgen(gwf.modelgrid, model_ws=ws, exe_name=gridgen) gu = Gridgen( diff --git a/autotest/test_gridintersect.py b/autotest/test_gridintersect.py index 39ba5df388..aef7bd55c8 100644 --- a/autotest/test_gridintersect.py +++ b/autotest/test_gridintersect.py @@ -1222,10 +1222,10 @@ def test_polygon_offset_rot_structured_grid_shapely(rtree): @requires_pkg("rasterstats", "scipy") def test_rasters(example_data_path): - ws = str(example_data_path / "options") + ws = example_data_path / "options" raster_name = "dem.img" - rio = Raster.load(os.path.join(ws, "dem", raster_name)) + rio = Raster.load(ws / "dem" / raster_name) ml = Modflow.load( "sagehen.nam", version="mfnwt", model_ws=os.path.join(ws, "sagehen") @@ -1284,14 +1284,12 @@ def test_rasters(example_data_path): @pytest.mark.slow @requires_pkg("rasterstats") def test_raster_sampling_methods(example_data_path): - ws = str(example_data_path / "options") + ws = example_data_path / "options" raster_name = "dem.img" - rio = Raster.load(os.path.join(ws, "dem", raster_name)) + rio = Raster.load(ws / "dem" / raster_name) - ml = Modflow.load( - "sagehen.nam", version="mfnwt", model_ws=os.path.join(ws, "sagehen") - ) + ml = Modflow.load("sagehen.nam", version="mfnwt", model_ws=ws / "sagehen") xoff = 214110 yoff = 4366620 ml.modelgrid.set_coord_info(xoff, yoff) diff --git a/autotest/test_headufile.py b/autotest/test_headufile.py index 7f767c5f97..f275d5ff7b 100644 --- a/autotest/test_headufile.py +++ b/autotest/test_headufile.py @@ -32,7 +32,7 @@ def mfusg_model(module_tmpdir): botm = [top - k * dz for k in range(1, nlay + 1)] # create dummy model and dis package for gridgen - m = Modflow(modelname=name, model_ws=str(module_tmpdir)) + m = Modflow(modelname=name, model_ws=module_tmpdir) dis = ModflowDis( m, nlay=nlay, @@ -45,7 +45,7 @@ def mfusg_model(module_tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(m.modelgrid, model_ws=str(module_tmpdir)) + g = Gridgen(m.modelgrid, model_ws=module_tmpdir) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, layers=[0]) @@ -64,7 +64,7 @@ def mfusg_model(module_tmpdir): name = "mymodel" m = MfUsg( modelname=name, - model_ws=str(module_tmpdir), + model_ws=module_tmpdir, exe_name="mfusg", structured=False, ) @@ -86,8 +86,7 @@ def mfusg_model(module_tmpdir): m.run_model() # head contains a list of head arrays for each layer - head_file_path = Path(module_tmpdir / f"{name}.hds") - return m, HeadUFile(str(head_file_path)) + return m, HeadUFile(module_tmpdir / f"{name}.hds") @requires_exe("mfusg", "gridgen") diff --git a/autotest/test_hydmodfile.py b/autotest/test_hydmodfile.py index 25f33afeb7..8e459a8241 100644 --- a/autotest/test_hydmodfile.py +++ b/autotest/test_hydmodfile.py @@ -20,10 +20,10 @@ def hydmod_model_path(example_data_path): def test_hydmodfile_create(function_tmpdir): - m = Modflow("test", model_ws=str(function_tmpdir)) + m = Modflow("test", model_ws=function_tmpdir) hyd = ModflowHyd(m) m.hyd.write_file() - pth = str(function_tmpdir / "test.hyd") + pth = function_tmpdir / "test.hyd" hydload = ModflowHyd.load(pth, m) assert np.array_equal( hyd.obsdata, hydload.obsdata @@ -55,17 +55,17 @@ def test_hydmodfile_create(function_tmpdir): def test_hydmodfile_load(function_tmpdir, hydmod_model_path): model = "test1tr.nam" m = Modflow.load( - model, version="mf2005", model_ws=str(hydmod_model_path), verbose=True + model, version="mf2005", model_ws=hydmod_model_path, verbose=True ) hydref = m.hyd assert isinstance( hydref, ModflowHyd ), "Did not load hydmod package...test1tr.hyd" - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.hyd.write_file() - pth = str(hydmod_model_path / "test1tr.hyd") + pth = hydmod_model_path / "test1tr.hyd" hydload = ModflowHyd.load(pth, m) assert np.array_equal( hydref.obsdata, hydload.obsdata @@ -73,7 +73,7 @@ def test_hydmodfile_load(function_tmpdir, hydmod_model_path): def test_hydmodfile_read(hydmod_model_path): - pth = str(hydmod_model_path / "test1tr.hyd.gitbin") + pth = hydmod_model_path / "test1tr.hyd.gitbin" h = HydmodObs(pth) assert isinstance(h, HydmodObs) @@ -148,7 +148,7 @@ def test_mf6obsfile_read(mf6_obs_model_path): binfile = [True, False] for idx in range(len(files)): - pth = str(mf6_obs_model_path / files[idx]) + pth = mf6_obs_model_path / files[idx] h = Mf6Obs(pth, isBinary=binfile[idx]) assert isinstance(h, Mf6Obs) diff --git a/autotest/test_lake_connections.py b/autotest/test_lake_connections.py index 7469f54791..6bc926b1c4 100644 --- a/autotest/test_lake_connections.py +++ b/autotest/test_lake_connections.py @@ -143,11 +143,11 @@ def test_base_run(function_tmpdir, example_data_path): mpath = example_data_path / "mf6-freyberg" sim = MFSimulation().load( sim_name="freyberg", - sim_ws=str(mpath), + sim_ws=mpath, exe_name="mf6", verbosity_level=0, ) - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # remove the well package gwf = sim.get_model("freyberg") @@ -162,20 +162,20 @@ def test_base_run(function_tmpdir, example_data_path): bot = gwf.dis.botm.array.squeeze() export_ascii_grid( gwf.modelgrid, - str(function_tmpdir / "bot.asc"), + function_tmpdir / "bot.asc", bot, ) top = gwf.output.head().get_data().squeeze() + 2.0 top = np.where(gwf.dis.idomain.array.squeeze() < 1.0, 0.0, top) export_ascii_grid( gwf.modelgrid, - str(function_tmpdir / "top.asc"), + function_tmpdir / "top.asc", top, ) k11 = gwf.npf.k.array.squeeze() export_ascii_grid( gwf.modelgrid, - str(function_tmpdir / "k11.asc"), + function_tmpdir / "k11.asc", k11, ) @@ -184,19 +184,19 @@ def test_base_run(function_tmpdir, example_data_path): @requires_pkg("rasterio", "rasterstats") def test_lake(function_tmpdir, example_data_path): mpath = example_data_path / "mf6-freyberg" - top = Raster.load(str(mpath / "top.asc")) - bot = Raster.load(str(mpath / "bot.asc")) - k11 = Raster.load(str(mpath / "k11.asc")) + top = Raster.load(mpath / "top.asc") + bot = Raster.load(mpath / "bot.asc") + k11 = Raster.load(mpath / "k11.asc") sim = MFSimulation().load( sim_name="freyberg", - sim_ws=str(mpath), + sim_ws=mpath, exe_name="mf6", verbosity_level=0, ) # change the workspace - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # get groundwater flow model gwf = sim.get_model("freyberg") @@ -352,7 +352,7 @@ def test_embedded_lak_ex01(function_tmpdir, example_data_path): mpath = example_data_path / "mf2005_test" ml = Modflow.load( "l1a2k.nam", - model_ws=str(mpath), + model_ws=mpath, load_only=["EVT"], check=False, ) @@ -395,7 +395,7 @@ def test_embedded_lak_ex01(function_tmpdir, example_data_path): sim = MFSimulation( sim_name=name, exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) tdis = ModflowTdis( sim, @@ -515,8 +515,8 @@ def test_embedded_lak_prudic(example_data_path): shape3d = (nlay, nrow, ncol) # load data from text files - data_ws = str(example_data_path / "mf6_test") - fname = os.path.join(data_ws, "prudic2004t2_bot1.dat") + data_ws = example_data_path / "mf6_test" + fname = data_ws / "prudic2004t2_bot1.dat" bot0 = np.loadtxt(fname) botm = np.array( [bot0] @@ -525,10 +525,10 @@ def test_embedded_lak_prudic(example_data_path): for k in range(1, nlay) ] ) - fname = os.path.join(data_ws, "prudic2004t2_idomain1.dat") + fname = data_ws / "prudic2004t2_idomain1.dat" idomain0 = np.loadtxt(fname, dtype=np.int32) idomain = np.array(nlay * [idomain0], dtype=np.int32) - fname = os.path.join(data_ws, "prudic2004t2_lakibd.dat") + fname = data_ws / "prudic2004t2_lakibd.dat" lakibd = np.loadtxt(fname, dtype=int) lake_map = np.ones(shape3d, dtype=np.int32) * -1 lake_map[0, :, :] = lakibd[:, :] - 1 @@ -618,8 +618,8 @@ def test_embedded_lak_prudic_mixed(example_data_path): shape3d = (nlay, nrow, ncol) # load data from text files - data_ws = str(example_data_path / "mf6_test") - fname = os.path.join(data_ws, "prudic2004t2_bot1.dat") + data_ws = example_data_path / "mf6_test" + fname = data_ws / "prudic2004t2_bot1.dat" bot0 = np.loadtxt(fname) botm = np.array( [bot0] @@ -628,10 +628,10 @@ def test_embedded_lak_prudic_mixed(example_data_path): for k in range(1, nlay) ] ) - fname = os.path.join(data_ws, "prudic2004t2_idomain1.dat") + fname = data_ws / "prudic2004t2_idomain1.dat" idomain0 = np.loadtxt(fname, dtype=np.int32) idomain = np.array(nlay * [idomain0], dtype=np.int32) - fname = os.path.join(data_ws, "prudic2004t2_lakibd.dat") + fname = data_ws / "prudic2004t2_lakibd.dat" lakibd = np.loadtxt(fname, dtype=int) lake_map = np.ones(shape3d, dtype=np.int32) * -1 lake_map[0, :, :] = lakibd[:, :] - 1 diff --git a/autotest/test_lgr.py b/autotest/test_lgr.py index edc0acccaa..2c72b68740 100644 --- a/autotest/test_lgr.py +++ b/autotest/test_lgr.py @@ -237,7 +237,7 @@ def test_simple_lgrmodel_from_scratch(function_tmpdir): yul_c, proj4_str, "mflgr", - rundir=str(function_tmpdir), + rundir=function_tmpdir, welInfo=welInfo, startingHead=-2.0, ) @@ -267,7 +267,7 @@ def test_simple_lgrmodel_from_scratch(function_tmpdir): yul_m, proj4_str, "mflgr", - rundir=str(function_tmpdir), + rundir=function_tmpdir, welInfo=welInfo, startingHead=-2.0, ) @@ -309,7 +309,7 @@ def test_simple_lgrmodel_from_scratch(function_tmpdir): parent=mother, children=[child], children_data=childData, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, external_path=None, verbose=False, ) diff --git a/autotest/test_listbudget.py b/autotest/test_listbudget.py index e8060c1fbf..ffc4a094a3 100644 --- a/autotest/test_listbudget.py +++ b/autotest/test_listbudget.py @@ -15,8 +15,8 @@ def test_mflistfile(example_data_path): - pth = str(example_data_path / "freyberg") - list_file = os.path.join(pth, "freyberg.gitlist") + pth = example_data_path / "freyberg" + list_file = pth / "freyberg.gitlist" assert os.path.exists(list_file) mflist = MfListBudget(list_file) @@ -72,19 +72,17 @@ def test_mflist_reducedpumping(example_data_path): """ test reading reduced pumping data from list file """ - pth = str( + pth = ( example_data_path / "mfusg_test" / "03B_conduit_unconfined" / "output" ) - list_file = os.path.join(pth, "ex3B.lst") + list_file = pth / "ex3B.lst" mflist = MfusgListBudget(list_file) assert isinstance(mflist.get_reduced_pumping(), np.recarray) def test_mf6listfile(example_data_path): - pth = str( - example_data_path / "mf6" / "test005_advgw_tidal" / "expected_output" - ) - list_file = os.path.join(pth, "AdvGW_tidal.gitlist") + pth = example_data_path / "mf6" / "test005_advgw_tidal" / "expected_output" + list_file = pth / "AdvGW_tidal.gitlist" assert os.path.exists(list_file) mflist = Mf6ListBudget(list_file) names = mflist.get_record_names() @@ -105,10 +103,10 @@ def test_mflist_reducedpumping_fail(example_data_path): """ test failure for reading reduced pumping data from list file """ - pth = str( + pth = ( example_data_path / "mfusg_test" / "03A_conduit_unconfined" / "output" ) - list_file = os.path.join(pth, "ex3A.lst") + list_file = pth / "ex3A.lst" # Catch before flopy to avoid masking file not found assert if not os.path.isfile(list_file): raise FileNotFoundError(f"{list_file} not found") @@ -121,31 +119,31 @@ def test_mflist_reducedpumping_fail(example_data_path): def test_mtlist(example_data_path): import pandas as pd - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "mcomp.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "mcomp.list") df_gw, df_sw = mt.parse(forgive=False, diff=False, start_datetime=None) - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "CrnkNic.mt3d.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "CrnkNic.mt3d.list") df_gw, df_sw = mt.parse(forgive=False, diff=True, start_datetime=None) - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "mcomp.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "mcomp.list") df_gw, df_sw = mt.parse(forgive=False, start_datetime=None) - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "mcomp.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "mcomp.list") df_gw, df_sw = mt.parse(forgive=False, start_datetime="1-1-1970") - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "mt3d_imm_sor.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "mt3d_imm_sor.list") df_gw, df_sw = mt.parse(forgive=False, start_datetime="1-1-1970") with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "mcomp_fail1.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "mcomp_fail1.list") df_gw, df_sw = mt.parse(forgive=True, start_datetime="1-1-1970") assert len(w) == 1, len(w) @@ -155,8 +153,8 @@ def test_mtlist(example_data_path): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - mt_dir = str(example_data_path / "mt3d_test") - mt = MtListBudget(os.path.join(mt_dir, "mcomp_fail2.list")) + mt_dir = example_data_path / "mt3d_test" + mt = MtListBudget(mt_dir / "mcomp_fail2.list") df_gw, df_sw = mt.parse(forgive=True, start_datetime="1-1-1970") assert len(w) == 1, len(w) diff --git a/autotest/test_mf6.py b/autotest/test_mf6.py index 8824b621c1..c0d6a136dc 100644 --- a/autotest/test_mf6.py +++ b/autotest/test_mf6.py @@ -1031,13 +1031,14 @@ def test_output_add_observation(function_tmpdir, example_data_path): sfr_obs, Mf6Obs ), "remove and add observation test (Mf6Output) failed" + @requires_exe("mf6") def test_sfr_connections(function_tmpdir, example_data_path): - '''MODFLOW just warns if any reaches are unconnected - flopy fails to load model if reach 1 is unconnected, fine with other unconnected''' + """MODFLOW just warns if any reaches are unconnected + flopy fails to load model if reach 1 is unconnected, fine with other unconnected""" data_path = example_data_path / "mf6" / "test666_sfrconnections" sim_ws = function_tmpdir - for test in ['sfr0', 'sfr1']: + for test in ["sfr0", "sfr1"]: sim_name = "test_sfr" model_name = "test_sfr" tdis_name = f"{sim_name}.tdis" @@ -1079,31 +1080,34 @@ def test_sfr_connections(function_tmpdir, example_data_path): k=50.0, ) - cnfile = f'mf6_{test}_connection.txt' - pkfile = f'mf6_{test}_package.txt' + cnfile = f"mf6_{test}_connection.txt" + pkfile = f"mf6_{test}_package.txt" - with open(data_path / pkfile, 'r') as f: + with open(data_path / pkfile, "r") as f: nreaches = len(f.readlines()) - sfr = ModflowGwfsfr(model, - packagedata={'filename': str(data_path / pkfile)}, - connectiondata={'filename': str(data_path / cnfile)}, - nreaches=nreaches, - pname='sfr', - unit_conversion=86400 - ) + sfr = ModflowGwfsfr( + model, + packagedata={"filename": str(data_path / pkfile)}, + connectiondata={"filename": str(data_path / cnfile)}, + nreaches=nreaches, + pname="sfr", + unit_conversion=86400, + ) sim.set_all_data_external() sim.write_simulation() success, buff = sim.run_simulation() assert success, f"simulation {sim.name} did not run" - #reload simulation + # reload simulation sim2 = MFSimulation.load(sim_ws=sim_ws) sim.set_all_data_external() sim.write_simulation() success, buff = sim.run_simulation() - assert success, f"simulation {sim.name} did not run after being reloaded" - - + assert ( + success + ), f"simulation {sim.name} did not run after being reloaded" + + @requires_exe("mf6") def test_array(function_tmpdir): # get_data diff --git a/autotest/test_mfnwt.py b/autotest/test_mfnwt.py index cc2c23dad9..0366dc3529 100644 --- a/autotest/test_mfnwt.py +++ b/autotest/test_mfnwt.py @@ -54,14 +54,14 @@ def test_nwt_pack_load(function_tmpdir, nwtfile): assert isinstance(nwt, ModflowNwt), msg # write the new file in the working directory - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) nwt.write_file() - fn = os.path.join(str(function_tmpdir), ml.name + ".nwt") + fn = function_tmpdir / (ml.name + ".nwt") msg = f"{os.path.basename(nwtfile)} write unsuccessful" assert os.path.isfile(fn), msg - ml2 = Modflow(model_ws=str(function_tmpdir), version="mfnwt") + ml2 = Modflow(model_ws=function_tmpdir, version="mfnwt") nwt2 = ModflowNwt.load(fn, ml2) lst = [ a @@ -85,11 +85,11 @@ def test_nwt_model_load(function_tmpdir, namfile): assert isinstance(ml, Modflow), msg # change the model work space and rewrite the files - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) ml.write_input() # reload the model that was just written - ml2 = Modflow.load(f, model_ws=str(function_tmpdir)) + ml2 = Modflow.load(f, model_ws=function_tmpdir) # check that the data are the same for pn in ml.get_package_list(): @@ -103,7 +103,7 @@ def test_nwt_model_load(function_tmpdir, namfile): for l in lst: msg = ( "{}.{} data instantiated from {} load is not the same as " - "written to {}".format(pn, l, model_ws, str(function_tmpdir)) + "written to {}".format(pn, l, model_ws, function_tmpdir) ) assert p[l] == p2[l], msg @@ -176,7 +176,7 @@ def test_mfnwt_run(function_tmpdir): mf = Modflow( modelname=modelname, exe_name="mfnwt", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, version="mfnwt", ) dis = ModflowDis( @@ -211,7 +211,7 @@ def test_mfnwt_run(function_tmpdir): # Read the simulated MODFLOW-2005 model results # Create the headfile object - headfile = str(function_tmpdir / f"{modelname}.hds") + headfile = function_tmpdir / f"{modelname}.hds" headobj = HeadFile(headfile, precision="single") times = headobj.get_times() head = headobj.get_data(totim=times[-1]) @@ -240,4 +240,4 @@ def test_mfnwt_run(function_tmpdir): ax.set_xlabel("Horizontal distance, in m") ax.set_ylabel("Percent Error") - fig.savefig(str(function_tmpdir / f"{modelname}.png")) + fig.savefig(function_tmpdir / f"{modelname}.png") diff --git a/autotest/test_mnw.py b/autotest/test_mnw.py index d7e0dbd492..e3f060ec4e 100644 --- a/autotest/test_mnw.py +++ b/autotest/test_mnw.py @@ -353,9 +353,7 @@ def test_mnw2_create_file(function_tmpdir): mnwmax=len(wells), mnw=wells, itmp=list( - (np.ones(len(stress_period_data.index)) * len(wellids)).astype( - int - ) + (np.ones(len(stress_period_data.index)) * len(wellids)).astype(int) ), ) diff --git a/autotest/test_modflow.py b/autotest/test_modflow.py index 5975397d90..bced74961d 100644 --- a/autotest/test_modflow.py +++ b/autotest/test_modflow.py @@ -51,9 +51,9 @@ def parameters_model_path(example_data_path): def test_modflow_load(namfile, example_data_path): mpath = Path(example_data_path / namfile).parent model = Modflow.load( - str(mpath / namfile.name), + mpath / namfile.name, verbose=True, - model_ws=str(mpath), + model_ws=mpath, check=False, ) @@ -230,7 +230,7 @@ def test_free_format_flag(function_tmpdir): def test_sr(function_tmpdir): - ws = str(function_tmpdir) + ws = function_tmpdir m = Modflow( "test", model_ws=ws, @@ -257,7 +257,7 @@ def test_sr(function_tmpdir): def test_mf6_update_grid(example_data_path): ml_path = example_data_path / "mf6" / "test001a_Tharmonic" - sim = MFSimulation.load(sim_ws=str(ml_path)) + sim = MFSimulation.load(sim_ws=ml_path) gwf = sim.get_model("flow15") mg = gwf.modelgrid gwf.dis.top = 12 @@ -268,7 +268,7 @@ def test_mf6_update_grid(example_data_path): # disv ml_path = example_data_path / "mf6" / "test003_gwfs_disv" - sim = MFSimulation.load(sim_ws=str(ml_path)) + sim = MFSimulation.load(sim_ws=ml_path) gwf = sim.get_model("gwf_1") mg = gwf.modelgrid gwf.disv.top = 6.12 @@ -279,7 +279,7 @@ def test_mf6_update_grid(example_data_path): # disu ml_path = example_data_path / "mf6" / "test006_gwf3" - sim = MFSimulation.load(sim_ws=str(ml_path)) + sim = MFSimulation.load(sim_ws=ml_path) gwf = sim.get_model("gwf_1") mg = gwf.modelgrid gwf.disu.top = 101 @@ -292,7 +292,7 @@ def test_mf6_update_grid(example_data_path): def test_load_twri_grid(example_data_path): mpath = example_data_path / "mf2005_test" name = "twri.nam" - ml = Modflow.load(name, model_ws=str(mpath), check=False) + ml = Modflow.load(name, model_ws=mpath, check=False) mg = ml.modelgrid assert isinstance( mg, StructuredGrid @@ -420,7 +420,7 @@ def test_namfile_readwrite(function_tmpdir, example_data_path): nlay, nrow, ncol = 1, 30, 5 delr, delc = 250, 500 xll, yll = 272300, 5086000 - ws = str(function_tmpdir) + ws = function_tmpdir m = Modflow(modelname="junk", model_ws=ws) dis = ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc) m.modelgrid = StructuredGrid( @@ -452,7 +452,7 @@ def test_namfile_readwrite(function_tmpdir, example_data_path): ml = Modflow.load( "freyberg.nam", - model_ws=str(example_data_path / "freyberg_multilayer_transient"), + model_ws=example_data_path / "freyberg_multilayer_transient", verbose=False, check=False, exe_name="mfnwt", @@ -481,7 +481,7 @@ def test_read_usgs_model_reference(function_tmpdir, model_reference_path): else: continue - ws = str(function_tmpdir) + ws = function_tmpdir m = Modflow(modelname="junk", model_ws=ws) # feet and days dis = ModflowDis( @@ -552,7 +552,7 @@ def parameters_model_namfiles(): def test_mf2005_test_models_load(example_data_path, namfile): assert not Modflow.load( namfile, - model_ws=str(example_data_path / "mf2005_test"), + model_ws=example_data_path / "mf2005_test", version="mf2005", verbose=True, ).load_fail @@ -563,7 +563,7 @@ def test_mf2005_test_models_load(example_data_path, namfile): def test_parameters_models_load(parameters_model_path, namfile): assert not Modflow.load( namfile, - model_ws=str(parameters_model_path), + model_ws=parameters_model_path, version="mf2005", verbose=True, ).load_fail @@ -572,8 +572,8 @@ def test_parameters_models_load(parameters_model_path, namfile): @pytest.mark.parametrize("namfile", mf2005_model_namfiles()) def test_mf2005_test_models_loadonly(example_data_path, namfile): assert not Modflow.load( - str(namfile), - model_ws=str(example_data_path / "mf2005_test"), + namfile, + model_ws=example_data_path / "mf2005_test", version="mf2005", verbose=True, load_only=["bas6"], @@ -587,7 +587,7 @@ def test_write_irch(function_tmpdir, example_data_path): nam_file = "freyberg.nam" m = Modflow.load( nam_file, - model_ws=str(mpath), + model_ws=mpath, check=False, forgive=False, verbose=True, @@ -606,12 +606,12 @@ def test_write_irch(function_tmpdir, example_data_path): d = arr - aarr assert np.abs(d).sum() == 0 - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.write_input() mm = Modflow.load( nam_file, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, forgive=False, verbose=True, check=False, @@ -627,7 +627,7 @@ def test_mflist_external(function_tmpdir): ext = function_tmpdir / "ws" ml = Modflow( "mflist_test", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, external_path=ext.name, ) @@ -637,12 +637,12 @@ def test_mflist_external(function_tmpdir): 1: [[0, 0, 0, -2], [1, 1, 1, -1]], } wel = ModflowWel(ml, stress_period_data=wel_data) - ml.change_model_ws(str(ext)) + ml.change_model_ws(ext) ml.write_input() ml1 = Modflow.load( "mflist_test.nam", - model_ws=str(ext), + model_ws=ext, verbose=True, forgive=False, check=False, @@ -684,7 +684,7 @@ def test_mflist_external(function_tmpdir): def test_single_mflist_entry_load(function_tmpdir, example_data_path): m = Modflow.load( "freyberg.nam", - model_ws=str(example_data_path / "freyberg"), + model_ws=example_data_path / "freyberg", load_only=["WEL"], check=False, ) @@ -692,12 +692,12 @@ def test_single_mflist_entry_load(function_tmpdir, example_data_path): spd = w.stress_period_data ModflowWel(m, stress_period_data={0: [0, 0, 0, 0.0]}) m.external_path = "external" - m.change_model_ws(str(function_tmpdir), reset_external=True) + m.change_model_ws(function_tmpdir, reset_external=True) m.write_input() mm = Modflow.load( "freyberg.nam", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, forgive=False, ) assert mm.wel.stress_period_data @@ -749,7 +749,7 @@ def test_checker_on_load(namfile): def test_bcs_check(function_tmpdir): - mf = Modflow(version="mf2005", model_ws=str(function_tmpdir)) + mf = Modflow(version="mf2005", model_ws=function_tmpdir) # test check for isolated cells dis = ModflowDis(mf, nlay=2, nrow=3, ncol=3, top=100, botm=95) @@ -788,7 +788,7 @@ def test_bcs_check(function_tmpdir): def test_properties_check(function_tmpdir): mf = Modflow( version="mf2005", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis = ModflowDis( mf, @@ -902,7 +902,7 @@ def test_rchload(function_tmpdir): nper = 2 # create model 1 - ws = str(function_tmpdir) + ws = function_tmpdir m1 = Modflow("rchload1", model_ws=ws) dis1 = ModflowDis(m1, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) a = np.random.random((nrow, ncol)) @@ -939,7 +939,7 @@ def test_rchload(function_tmpdir): def test_default_oc_stress_period_data(function_tmpdir): - m = Modflow(model_ws=str(function_tmpdir), verbose=True) + m = Modflow(model_ws=function_tmpdir, verbose=True) dis = ModflowDis(m, nper=10, perlen=10.0, nstp=5) bas = ModflowBas(m) lpf = ModflowLpf(m, ipakcb=100) @@ -958,7 +958,7 @@ def test_default_oc_stress_period_data(function_tmpdir): def test_mfcbc(function_tmpdir): - m = Modflow(verbose=True, model_ws=str(function_tmpdir)) + m = Modflow(verbose=True, model_ws=function_tmpdir) dis = ModflowDis(m) bas = ModflowBas(m) lpf = ModflowLpf(m, ipakcb=100) @@ -972,7 +972,7 @@ def test_mfcbc(function_tmpdir): nlay = 3 nrow = 3 ncol = 3 - ml = Modflow(modelname="t1", model_ws=str(function_tmpdir), verbose=True) + ml = Modflow(modelname="t1", model_ws=function_tmpdir, verbose=True) dis = ModflowDis( ml, nlay=nlay, nrow=nrow, ncol=ncol, top=0, botm=[-1.0, -2.0, -3.0] ) @@ -1028,7 +1028,7 @@ def test_load_with_list_reader(function_tmpdir): m = Modflow( modelname="original", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, exe_name="mf2005", ) dis = ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) @@ -1044,7 +1044,7 @@ def test_load_with_list_reader(function_tmpdir): m.write_input() # rewrite ghb - fname = os.path.join(str(function_tmpdir), "original.ghb") + fname = os.path.join(function_tmpdir, "original.ghb") with open(fname, "w") as f: f.write(f"{ghbra.shape[0]} 0\n") for kper in range(nper): @@ -1053,14 +1053,14 @@ def test_load_with_list_reader(function_tmpdir): # write ghb list sfacghb = 5 - fname = os.path.join(str(function_tmpdir), "original.ghb.dat") + fname = os.path.join(function_tmpdir, "original.ghb.dat") with open(fname, "w") as f: f.write(f"sfac {sfacghb}\n") for k, i, j, stage, cond in ghbra: f.write(f"{k + 1} {i + 1} {j + 1} {stage} {cond}\n") # rewrite drn - fname = os.path.join(str(function_tmpdir), "original.drn") + fname = os.path.join(function_tmpdir, "original.drn") with open(fname, "w") as f: f.write(f"{drnra.shape[0]} 0\n") for kper in range(nper): @@ -1069,7 +1069,7 @@ def test_load_with_list_reader(function_tmpdir): # write drn list sfacdrn = 1.5 - fname = os.path.join(str(function_tmpdir), "original.drn.dat") + fname = os.path.join(function_tmpdir, "original.drn.dat") with open(fname, "w") as f: for kper in range(nper): f.write(f"sfac {sfacdrn}\n") @@ -1077,7 +1077,7 @@ def test_load_with_list_reader(function_tmpdir): f.write(f"{k + 1} {i + 1} {j + 1} {stage} {cond}\n") # rewrite wel - fname = os.path.join(str(function_tmpdir), "original.wel") + fname = os.path.join(function_tmpdir, "original.wel") with open(fname, "w") as f: f.write(f"{drnra.shape[0]} 0\n") for kper in range(nper): @@ -1097,7 +1097,7 @@ def test_load_with_list_reader(function_tmpdir): welra = np.recarray(2, dtype=weldt) welra[0] = (1, 2, 2, -5.0) welra[1] = (1, nrow - 2, ncol - 2, -10.0) - fname = os.path.join(str(function_tmpdir), "original.wel.bin") + fname = os.path.join(function_tmpdir, "original.wel.bin") with open(fname, "wb") as f: welra.tofile(f) welra.tofile(f) @@ -1110,7 +1110,7 @@ def test_load_with_list_reader(function_tmpdir): # the m2 model will load all of these external files, possibly using sfac # and just create regular list input files for wel, drn, and ghb fname = "original.nam" - m2 = Modflow.load(fname, model_ws=str(function_tmpdir), verbose=False) + m2 = Modflow.load(fname, model_ws=function_tmpdir, verbose=False) m2.name = "new" m2.write_input() @@ -1177,25 +1177,23 @@ def get_basic_modflow_model(ws, name): @pytest.mark.slow def test_model_init_time(function_tmpdir, benchmark): name = inspect.getframeinfo(inspect.currentframe()).function - benchmark( - lambda: get_basic_modflow_model(ws=str(function_tmpdir), name=name) - ) + benchmark(lambda: get_basic_modflow_model(ws=function_tmpdir, name=name)) @pytest.mark.slow def test_model_write_time(function_tmpdir, benchmark): name = inspect.getframeinfo(inspect.currentframe()).function - model = get_basic_modflow_model(ws=str(function_tmpdir), name=name) + model = get_basic_modflow_model(ws=function_tmpdir, name=name) benchmark(lambda: model.write_input()) @pytest.mark.slow def test_model_load_time(function_tmpdir, benchmark): name = inspect.getframeinfo(inspect.currentframe()).function - model = get_basic_modflow_model(ws=str(function_tmpdir), name=name) + model = get_basic_modflow_model(ws=function_tmpdir, name=name) model.write_input() benchmark( lambda: Modflow.load( - f"{name}.nam", model_ws=str(function_tmpdir), check=False + f"{name}.nam", model_ws=function_tmpdir, check=False ) ) diff --git a/autotest/test_modpathfile.py b/autotest/test_modpathfile.py index 27944b2f49..4fe25dc2fd 100644 --- a/autotest/test_modpathfile.py +++ b/autotest/test_modpathfile.py @@ -182,7 +182,7 @@ def get_nodes(locs): @pytest.fixture(scope="module") def mp7_small(module_tmpdir): return __create_simulation( - ws=str(module_tmpdir / "mp7_small"), + ws=module_tmpdir / "mp7_small", name="mp7_small", nper=1, nstp=1, @@ -210,7 +210,7 @@ def mp7_small(module_tmpdir): @pytest.fixture(scope="module") def mp7_large(module_tmpdir): return __create_simulation( - ws=str(module_tmpdir / "mp7_large"), + ws=module_tmpdir / "mp7_large", name="mp7_large", nper=1, nstp=1, @@ -243,12 +243,12 @@ def test_pathline_file_sorts_in_ctor( ws = function_tmpdir / "ws" # copytree(sim.simulation_data.mfpath.get_sim_path(), ws) - copytree(str(module_tmpdir / "mp7_small"), ws) + copytree(module_tmpdir / "mp7_small", ws) forward_path = ws / f"{forward_model_name}.mppth" assert forward_path.is_file() - pathline_file = PathlineFile(str(forward_path)) + pathline_file = PathlineFile(forward_path) assert np.all( pathline_file._data[:-1]["particleid"] <= pathline_file._data[1:]["particleid"] @@ -273,7 +273,7 @@ def test_get_destination_pathline_data( assert backward_path.is_file() pathline_file = PathlineFile( - str(backward_path) if direction == "backward" else str(forward_path) + backward_path if direction == "backward" else forward_path ) benchmark( lambda: pathline_file.get_destination_pathline_data( @@ -300,7 +300,7 @@ def test_get_destination_endpoint_data( assert backward_end.is_file() endpoint_file = EndpointFile( - str(backward_end) if direction == "backward" else str(forward_end) + backward_end if direction == "backward" else forward_end ) benchmark( lambda: endpoint_file.get_destination_endpoint_data( diff --git a/autotest/test_mp5.py b/autotest/test_mp5.py index 6e93c20aaf..9101d0809d 100644 --- a/autotest/test_mp5.py +++ b/autotest/test_mp5.py @@ -17,7 +17,7 @@ def test_mp5_load(function_tmpdir, example_data_path): # load the modflow files for model map m = Modflow.load( "freyberg.nam", - model_ws=str(freyberg_ws), + model_ws=freyberg_ws, check=False, verbose=True, forgive=False, @@ -63,7 +63,7 @@ def test_mp5_load(function_tmpdir, example_data_path): mm.plot_grid(lw=0.5) mm.plot_ibound() - fpth = os.path.join(str(function_tmpdir), "mp5.pathline.png") + fpth = function_tmpdir / "mp5.pathline.png" plt.savefig(fpth, dpi=300) plt.close() diff --git a/autotest/test_mp6.py b/autotest/test_mp6.py index 136e341f83..8937d5597e 100644 --- a/autotest/test_mp6.py +++ b/autotest/test_mp6.py @@ -32,27 +32,26 @@ def copy_modpath_files(source, model_ws, baseName): files = [ file for file in os.listdir(source) - if file.startswith(baseName) - and os.path.isfile(os.path.join(source, file)) + if file.startswith(baseName) and os.path.isfile(source / file) ] for file in files: - src = str(get_example_data_path() / "mp6" / file) - dst = os.path.join(model_ws, file) + src = get_example_data_path() / "mp6" / file + dst = model_ws / file print(f"copying {src} -> {dst}") shutil.copy(src, dst) def test_mpsim(function_tmpdir, mp6_test_path): - copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE.") + copy_modpath_files(mp6_test_path, function_tmpdir, "EXAMPLE.") - m = Modflow.load("EXAMPLE.nam", model_ws=str(function_tmpdir)) + m = Modflow.load("EXAMPLE.nam", model_ws=function_tmpdir) m.get_package_list() mp = Modpath6( modelname="ex6", exe_name="mp6", modflowmodel=m, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, dis_file=f"{m.name}.dis", head_file=f"{m.name}.hed", budget_file=f"{m.name}.bud", @@ -122,7 +121,7 @@ def test_mpsim(function_tmpdir, mp6_test_path): stldata[1]["yloc0"] = 0.2 stl.data = stldata mp.write_input() - stllines = open(os.path.join(str(function_tmpdir), "ex6.loc")).readlines() + stllines = open(function_tmpdir / "ex6.loc").readlines() assert stllines[3].strip() == "group1" assert int(stllines[4].strip()) == 2 assert stllines[6].strip().split()[-1] == "p2" @@ -130,10 +129,10 @@ def test_mpsim(function_tmpdir, mp6_test_path): @requires_pkg("pandas", "shapefile") def test_get_destination_data(function_tmpdir, mp6_test_path): - copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE.") - copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE-3.") + copy_modpath_files(mp6_test_path, function_tmpdir, "EXAMPLE.") + copy_modpath_files(mp6_test_path, function_tmpdir, "EXAMPLE-3.") - m = Modflow.load("EXAMPLE.nam", model_ws=str(function_tmpdir)) + m = Modflow.load("EXAMPLE.nam", model_ws=function_tmpdir) mg1 = m.modelgrid mg1.set_coord_info( @@ -150,10 +149,10 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): ) # test deprecation - m.dis.export(str(function_tmpdir / "dis.shp")) + m.dis.export(function_tmpdir / "dis.shp") - pthld = PathlineFile(str(function_tmpdir / "EXAMPLE-3.pathline")) - epd = EndpointFile(str(function_tmpdir / "EXAMPLE-3.endpoint")) + pthld = PathlineFile(function_tmpdir / "EXAMPLE-3.pathline") + epd = EndpointFile(function_tmpdir / "EXAMPLE-3.endpoint") well_epd = epd.get_destination_endpoint_data(dest_cells=[(4, 12, 12)]) well_pthld = pthld.get_destination_pathline_data( @@ -178,12 +177,12 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): epd.write_shapefile( well_epd, direction="starting", - shpname=str(function_tmpdir / "starting_locs.shp"), + shpname=function_tmpdir / "starting_locs.shp", mg=m.modelgrid, ) # test writing shapefile of pathlines - fpth = str(function_tmpdir / "pathlines_1per.shp") + fpth = function_tmpdir / "pathlines_1per.shp" pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -191,7 +190,7 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): mg=m.modelgrid, shpname=fpth, ) - fpth = str(function_tmpdir / "pathlines_1per_end.shp") + fpth = function_tmpdir / "pathlines_1per_end.shp" pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -200,7 +199,7 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): shpname=fpth, ) # test writing shapefile of pathlines - fpth = str(function_tmpdir / "pathlines_1per2.shp") + fpth = function_tmpdir / "pathlines_1per2.shp" pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -209,7 +208,7 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): shpname=fpth, ) # test writing shapefile of pathlines - fpth = str(function_tmpdir / "pathlines_1per2_ll.shp") + fpth = function_tmpdir / "pathlines_1per2_ll.shp" pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -217,13 +216,13 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): mg=mg, shpname=fpth, ) - fpth = str(function_tmpdir / "pathlines.shp") + fpth = function_tmpdir / "pathlines.shp" pthld.write_shapefile( well_pthld, one_per_particle=False, mg=m.modelgrid, shpname=fpth ) # test that endpoints were rotated and written correctly - ra = shp2recarray(str(function_tmpdir / "starting_locs.shp")) + ra = shp2recarray(function_tmpdir / "starting_locs.shp") p3 = ra.geometry[ra.particleid == 4][0] xorig, yorig = m.modelgrid.get_coords(well_epd.x0[0], well_epd.y0[0]) assert p3.x - xorig + p3.y - yorig < 1e-4 @@ -233,16 +232,16 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): ) # this also checks for 1-based # test that particle attribute information is consistent with pathline file - ra = shp2recarray(str(function_tmpdir / "pathlines.shp")) + ra = shp2recarray(function_tmpdir / "pathlines.shp") inds = (ra.particleid == 8) & (ra.i == 12) & (ra.j == 12) assert ra.time[inds][0] - 20181.7 < 0.1 assert ra.xloc[inds][0] - 0.933 < 0.01 # test that k, i, j are correct for single geometry pathlines, forwards # and backwards - ra = shp2recarray(str(function_tmpdir / "pathlines_1per.shp")) + ra = shp2recarray(function_tmpdir / "pathlines_1per.shp") assert ra.i[0] == 4, ra.j[0] == 5 - ra = shp2recarray(str(function_tmpdir / "pathlines_1per_end.shp")) + ra = shp2recarray(function_tmpdir / "pathlines_1per_end.shp") assert ra.i[0] == 13, ra.j[0] == 13 # test use of arbitrary spatial reference and offset @@ -253,7 +252,7 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): epsg=mg.epsg, proj4=mg.proj4, ) - ra = shp2recarray(str(function_tmpdir / "pathlines_1per2.shp")) + ra = shp2recarray(function_tmpdir / "pathlines_1per2.shp") p3_2 = ra.geometry[ra.particleid == 4][0] test1 = mg1.xcellcenters[3, 4] test2 = mg1.ycellcenters[3, 4] @@ -268,7 +267,7 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): ) # arbitrary spatial reference with ll specified instead of ul - ra = shp2recarray(str(function_tmpdir / "pathlines_1per2_ll.shp")) + ra = shp2recarray(function_tmpdir / "pathlines_1per2_ll.shp") p3_2 = ra.geometry[ra.particleid == 4][0] mg.set_coord_info(xoff=mg.xoffset, yoff=mg.yoffset, angrot=30.0) assert ( @@ -284,7 +283,7 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): xul = 3628793 yul = 21940389 - m = Modflow.load("EXAMPLE.nam", model_ws=str(function_tmpdir)) + m = Modflow.load("EXAMPLE.nam", model_ws=function_tmpdir) mg4 = m.modelgrid mg4.set_coord_info( @@ -295,18 +294,18 @@ def test_get_destination_data(function_tmpdir, mp6_test_path): proj4=mg4.proj4, ) - fpth = str(function_tmpdir / "dis2.shp") + fpth = function_tmpdir / "dis2.shp" m.dis.export(fpth) - pthobj = PathlineFile(str(function_tmpdir / "EXAMPLE-3.pathline")) - fpth = str(function_tmpdir / "pathlines_1per3.shp") + pthobj = PathlineFile(function_tmpdir / "EXAMPLE-3.pathline") + fpth = function_tmpdir / "pathlines_1per3.shp" pthobj.write_shapefile(shpname=fpth, direction="ending", mg=mg4) @requires_pkg("pandas") def test_loadtxt(function_tmpdir, mp6_test_path): - copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE-3.") + copy_modpath_files(mp6_test_path, function_tmpdir, "EXAMPLE-3.") - pthfile = str(function_tmpdir / "EXAMPLE-3.pathline") + pthfile = function_tmpdir / "EXAMPLE-3.pathline" pthld = PathlineFile(pthfile) ra = loadtxt(pthfile, delimiter=" ", skiprows=3, dtype=pthld.dtype) ra2 = loadtxt( @@ -326,14 +325,14 @@ def test_modpath(function_tmpdir, example_data_path): m = Modflow.load( mfnam, - model_ws=str(pth), + model_ws=pth, verbose=True, exe_name="mf2005", check=False, ) assert m.load_fail is False - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.write_input() success, buff = m.run_model(silent=False) @@ -345,7 +344,7 @@ def test_modpath(function_tmpdir, example_data_path): mpnam, exe_name="mp6", modflowmodel=m, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) mpbas = Modpath6Bas( mp, @@ -373,7 +372,7 @@ def test_modpath(function_tmpdir, example_data_path): mpnam, exe_name="mp6", modflowmodel=m, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) mpbas = Modpath6Bas( mpp, @@ -398,8 +397,8 @@ def test_modpath(function_tmpdir, example_data_path): # load modpath output files if success: - endfile = os.path.join(str(function_tmpdir), mp.sim.endpoint_file) - pthfile = os.path.join(str(function_tmpdir), mpp.sim.pathline_file) + endfile = function_tmpdir / mp.sim.endpoint_file + pthfile = function_tmpdir / mpp.sim.pathline_file # load the endpoint data try: @@ -423,14 +422,14 @@ def test_modpath(function_tmpdir, example_data_path): mfnam = "freyberg.nam" m = Modflow.load( mfnam, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, forgive=False, exe_name="mf2005", ) # load modpath output files - pthfile = os.path.join(str(function_tmpdir), "freybergmpp.mppth") + pthfile = function_tmpdir / "freybergmpp.mppth" # load the pathline data pthobj = PathlineFile(pthfile) @@ -448,7 +447,7 @@ def test_modpath(function_tmpdir, example_data_path): # plot the grid and ibound array mm.plot_grid() mm.plot_ibound() - fpth = os.path.join(str(function_tmpdir), "pathline.png") + fpth = function_tmpdir / "pathline.png" plt.savefig(fpth) plt.close() @@ -459,7 +458,7 @@ def test_modpath(function_tmpdir, example_data_path): mm.plot_grid() mm.plot_ibound() - fpth = os.path.join(str(function_tmpdir), "pathline2.png") + fpth = function_tmpdir / "pathline2.png" plt.savefig(fpth) plt.close() @@ -470,18 +469,16 @@ def test_modpath(function_tmpdir, example_data_path): mm.plot_grid() mm.plot_ibound() - fpth = os.path.join(str(function_tmpdir), "pathline3.png") + fpth = function_tmpdir / "pathline3.png" plt.savefig(fpth) plt.close() @requires_pkg("pandas") def test_mp6_timeseries_load(example_data_path): - pth = str(example_data_path / "mp5") + pth = example_data_path / "mp5" files = [ - os.path.join(pth, name) - for name in sorted(os.listdir(pth)) - if ".timeseries" in name + pth / name for name in sorted(os.listdir(pth)) if ".timeseries" in name ] for file in files: print(file) diff --git a/autotest/test_mp6_cases.py b/autotest/test_mp6_cases.py index 907a94fda3..ceae0a672c 100644 --- a/autotest/test_mp6_cases.py +++ b/autotest/test_mp6_cases.py @@ -37,7 +37,7 @@ def case_1(self, function_tmpdir): namefile_ext="nam", version="mf2005", exe_name="mf2005", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) # dis @@ -117,7 +117,7 @@ def case_2(self, function_tmpdir): namefile_ext="nam", version="mf2005", exe_name="mf2005", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) # dis @@ -225,7 +225,7 @@ def case_1(self, function_tmpdir): namefile_ext="nam", version="mf2005", exe_name="mf2005", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) # dis diff --git a/autotest/test_mp7.py b/autotest/test_mp7.py index c0158620df..e520c1e10b 100644 --- a/autotest/test_mp7.py +++ b/autotest/test_mp7.py @@ -68,7 +68,7 @@ def ex01b_mf6_model(function_tmpdir): sim_name=ex01b_mf6_model_name, exe_name="mf6", version="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) # Create the Flopy temporal discretization object @@ -246,7 +246,7 @@ def test_default_modpath(ex01b_mf6_model): mpnam = f"{ex01b_mf6_model_name}_mp_default" pg = ParticleGroup(particlegroupname="DEFAULT") build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -295,21 +295,19 @@ def test_faceparticles_is1(ex01b_mf6_model): particlegroupname="T1NODEPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, ) # set base file name - fpth0 = os.path.join( - str(function_tmpdir), "ex01b_mf6_mp_face_t1node.mpend" - ) + fpth0 = function_tmpdir / "ex01b_mf6_mp_face_t1node.mpend" # get list of node endpath files epf = [ - os.path.join(str(function_tmpdir), name) - for name in os.listdir(str(function_tmpdir)) + function_tmpdir / name + for name in os.listdir(function_tmpdir) if ".mpend" in name and "_face_" in name and "_t2a" not in name ] epf.remove(fpth0) @@ -351,7 +349,7 @@ def test_facenode_is3(ex01b_mf6_model): particlegroupname="T3NODEPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -397,7 +395,7 @@ def test_facenode_is3a(ex01b_mf6_model): particlegroupname="T3ANODEPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -435,7 +433,7 @@ def test_facenode_is2a(ex01b_mf6_model): particlegroupname="T2ANODEPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -465,21 +463,19 @@ def test_cellparticles_is1(ex01b_mf6_model): particlegroupname="T1NODEPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, ) # set base file name - fpth0 = os.path.join( - str(function_tmpdir), "ex01b_mf6_mp_cell_t1node.mpend" - ) + fpth0 = function_tmpdir / "ex01b_mf6_mp_cell_t1node.mpend" # get list of node endpath files epf = [ - os.path.join(str(function_tmpdir), name) - for name in os.listdir(str(function_tmpdir)) + function_tmpdir / name + for name in os.listdir(function_tmpdir) if ".mpend" in name and "_cell_" in name and "_t2a" not in name ] epf.remove(fpth0) @@ -508,7 +504,7 @@ def test_cellparticleskij_is1(ex01b_mf6_model): particlegroupname="T1KIJPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -541,7 +537,7 @@ def test_cellnode_is3(ex01b_mf6_model): particlegroupname="T3CELLPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -588,7 +584,7 @@ def test_cellnode_is3a(ex01b_mf6_model): particlegroupname="T3ACELLPG", particledata=p, filename=fpth ) build_modpath( - str(function_tmpdir), + function_tmpdir, mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid, @@ -621,7 +617,7 @@ def test_cellnode_is2a(ex01b_mf6_model): particlegroupname="T2ACELLPG", particledata=p, filename=fpth ) - build_modpath(str(function_tmpdir), mpnam, pg, grid) + build_modpath(function_tmpdir, mpnam, pg, grid) ex01_mf6_model_name = "ex01_mf6" @@ -638,7 +634,7 @@ def ex01_mf6_model(function_tmpdir): sim_name=ex01_mf6_model_name, exe_name="mf6", version="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) # model data @@ -735,7 +731,7 @@ def test_forward(ex01_mf6_model): mpnam = f"{ex01_mf6_model_name}_mp_forward" # load the MODFLOW 6 model - sim = MFSimulation.load("mf6mod", "mf6", "mf6", str(function_tmpdir)) + sim = MFSimulation.load("mf6mod", "mf6", "mf6", function_tmpdir) gwf = sim.get_model(ex01_mf6_model_name) mp = Modpath7.create_mp7( @@ -743,7 +739,7 @@ def test_forward(ex01_mf6_model): trackdir="forward", flowmodel=gwf, exe_name="mp7", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, rowcelldivisions=1, columncelldivisions=1, layercelldivisions=1, @@ -767,7 +763,7 @@ def test_backward(ex01_mf6_model): mpnam = f"{ex01_mf6_model_name}_mp_backward" # load the MODFLOW 6 model - sim = MFSimulation.load("mf6mod", "mf6", "mf6", str(function_tmpdir)) + sim = MFSimulation.load("mf6mod", "mf6", "mf6", function_tmpdir) gwf = sim.get_model(ex01_mf6_model_name) mp = Modpath7.create_mp7( @@ -775,7 +771,7 @@ def test_backward(ex01_mf6_model): trackdir="backward", flowmodel=gwf, exe_name="mp7", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, rowcelldivisions=1, columncelldivisions=1, layercelldivisions=1, @@ -800,12 +796,12 @@ def test_pathline_output(function_tmpdir): success, buff = case_mf6.run_model() assert success, f"modpath model ({case_mf6.name}) did not run" - fpth0 = os.path.join(case_mf2005.model_ws, "ex01_mf2005_mp.mppth") + fpth0 = case_mf2005.model_ws / "ex01_mf2005_mp.mppth" p = PathlineFile(fpth0) maxtime0 = p.get_maxtime() maxid0 = p.get_maxid() p0 = p.get_alldata() - fpth1 = os.path.join(case_mf6.model_ws, "ex01_mf6_mp.mppth") + fpth1 = case_mf6.model_ws / "ex01_mf6_mp.mppth" p = PathlineFile(fpth1) maxtime1 = p.get_maxtime() maxid1 = p.get_maxid() @@ -832,13 +828,13 @@ def test_endpoint_output(function_tmpdir): assert success, f"modpath model ({case_mf6.name}) did not run" # if models not run then there will be no output - fpth0 = os.path.join(case_mf2005.model_ws, "ex01_mf2005_mp.mpend") + fpth0 = case_mf2005.model_ws / "ex01_mf2005_mp.mpend" e = EndpointFile(fpth0) maxtime0 = e.get_maxtime() maxid0 = e.get_maxid() maxtravel0 = e.get_maxtraveltime() e0 = e.get_alldata() - fpth1 = os.path.join(case_mf6.model_ws, "ex01_mf6_mp.mpend") + fpth1 = case_mf6.model_ws / "ex01_mf6_mp.mpend" e = EndpointFile(fpth1) maxtime1 = e.get_maxtime() maxid1 = e.get_maxid() @@ -881,7 +877,7 @@ def test_pathline_plotting(function_tmpdir): modelgrid = ml.flowmodel.modelgrid nodes = list(range(modelgrid.nnodes)) - fpth1 = os.path.join(ml.model_ws, "ex01_mf6_mp.mppth") + fpth1 = ml.model_ws / "ex01_mf6_mp.mppth" p = PathlineFile(fpth1) p1 = p.get_alldata() pls = p.get_destination_data(nodes) diff --git a/autotest/test_mp7_cases.py b/autotest/test_mp7_cases.py index 42ef384b50..636722d3f4 100644 --- a/autotest/test_mp7_cases.py +++ b/autotest/test_mp7_cases.py @@ -1,5 +1,3 @@ -from os.path import join - import numpy as np from flopy.mf6 import ( @@ -81,7 +79,7 @@ def mf6(function_tmpdir): MODPATH 7 example 1 for MODFLOW 6 """ - ws = join(str(function_tmpdir), "mf6") + ws = function_tmpdir / "mf6" nm = "ex01_mf6" # Create the Flopy simulation object @@ -218,7 +216,7 @@ def mf2005(function_tmpdir): MODPATH 7 example 1 for MODFLOW-2005 """ - ws = join(str(function_tmpdir), "mf2005") + ws = function_tmpdir / "mf2005" nm = "ex01_mf2005" iu_cbc = 130 m = Modflow(nm, model_ws=ws, exe_name="mf2005") diff --git a/autotest/test_mt3d.py b/autotest/test_mt3d.py index eb410f3e37..27dfafff9a 100644 --- a/autotest/test_mt3d.py +++ b/autotest/test_mt3d.py @@ -61,12 +61,11 @@ def mfnwtmt3d_model_path(mt3d_test_model_path): @requires_exe("mf2005", "mt3dms") def test_mf2005_p07(function_tmpdir, mf2005mt3d_model_path): - pth = str(mf2005mt3d_model_path / "P07") + pth = mf2005mt3d_model_path / "P07" namfile = "p7mf2005.nam" mf = Modflow.load(namfile, model_ws=pth, verbose=True, exe_name="mf2005") - cpth = str(function_tmpdir / "P07") + cpth = function_tmpdir / "P07" mf.model_ws = cpth - mf.write_input() success, buff = mf.run_model(silent=False) @@ -87,16 +86,15 @@ def test_mf2005_p07(function_tmpdir, mf2005mt3d_model_path): success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") def test_mf2000_p07(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "P07") + pth = mf2kmt3d_model_path / "P07" namfile = "p7mf2k.nam" mf = Modflow.load(namfile, model_ws=pth, verbose=True, exe_name="mf2000") - cpth = str(function_tmpdir / "P07_2K") + cpth = function_tmpdir / "P07_2K" mf.model_ws = cpth mf.write_input() @@ -112,18 +110,17 @@ def test_mf2000_p07(function_tmpdir, mf2kmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") def test_mf2000_HSSTest(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "HSSTest") + pth = mf2kmt3d_model_path / "HSSTest" namfile = "hsstest_mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(function_tmpdir / "HSSTest") + cpth = function_tmpdir / "HSSTest" mf.model_ws = cpth mf.write_input() @@ -139,7 +136,6 @@ def test_mf2000_HSSTest(function_tmpdir, mf2kmt3d_model_path): success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") @@ -147,11 +143,11 @@ def test_mf2000_mnw(function_tmpdir, mf2kmt3d_model_path): # cannot run this model because it uses mnw1 and there is no load for mnw1 # this model includes block format data in the btn file - pth = str(mf2kmt3d_model_path / "mnw") + pth = mf2kmt3d_model_path / "mnw" namfile = "t5mf2k.nam" mf = Modflow.load(namfile, model_ws=pth, verbose=True) - cpth = str(function_tmpdir / "MNW") + cpth = function_tmpdir / "MNW" mf.model_ws = cpth namfile = "t5mt.nam" @@ -163,13 +159,13 @@ def test_mf2000_mnw(function_tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") def test_mf2000_MultiDiffusion(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "MultiDiffusion") + pth = mf2kmt3d_model_path / "MultiDiffusion" namfile = "p7mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(function_tmpdir / "MultiDiffusion") + cpth = function_tmpdir / "MultiDiffusion" mf.model_ws = cpth mf.write_input() @@ -183,18 +179,17 @@ def test_mf2000_MultiDiffusion(function_tmpdir, mf2kmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") def test_mf2000_reinject(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "reinject") + pth = mf2kmt3d_model_path / "reinject" namfile = "p3mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(function_tmpdir / "reinject") + cpth = function_tmpdir / "reinject" mf.model_ws = cpth mf.write_input() @@ -210,18 +205,17 @@ def test_mf2000_reinject(function_tmpdir, mf2kmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") def test_mf2000_SState(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "SState") + pth = mf2kmt3d_model_path / "SState" namfile = "SState_mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(function_tmpdir / "SState") + cpth = function_tmpdir / "SState" mf.model_ws = cpth mf.write_input() @@ -237,18 +231,17 @@ def test_mf2000_SState(function_tmpdir, mf2kmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") def test_mf2000_tob(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "tob") + pth = mf2kmt3d_model_path / "tob" namfile = "p7mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(function_tmpdir / "tob") + cpth = function_tmpdir / "tob" mf.model_ws = cpth mf.lmt6.output_file_header = "extended" @@ -267,18 +260,17 @@ def test_mf2000_tob(function_tmpdir, mf2kmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @requires_exe("mf2000", "mt3dms") def test_mf2000_zeroth(function_tmpdir, mf2kmt3d_model_path): - pth = str(mf2kmt3d_model_path / "zeroth") + pth = mf2kmt3d_model_path / "zeroth" namfile = "z0mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(function_tmpdir / "zeroth") + cpth = function_tmpdir / "zeroth" mf.model_ws = cpth mf.write_input() @@ -293,7 +285,6 @@ def test_mf2000_zeroth(function_tmpdir, mf2kmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @flaky(max_runs=3) @@ -302,7 +293,7 @@ def test_mf2000_zeroth(function_tmpdir, mf2kmt3d_model_path): "Windows", ci_only=True ) # TODO remove once fixed in MT3D-USGS def test_mfnwt_CrnkNic(function_tmpdir, mfnwtmt3d_model_path): - pth = str(mfnwtmt3d_model_path / "sft_crnkNic") + pth = mfnwtmt3d_model_path / "sft_crnkNic" namefile = "CrnkNic.nam" mf = Modflow.load( namefile, @@ -312,7 +303,7 @@ def test_mfnwt_CrnkNic(function_tmpdir, mfnwtmt3d_model_path): exe_name="mfnwt", ) - cpth = str(function_tmpdir / "SFT_CRNKNIC") + cpth = function_tmpdir / "SFT_CRNKNIC" mf.model_ws = cpth mf.write_input() @@ -335,13 +326,12 @@ def test_mfnwt_CrnkNic(function_tmpdir, mfnwtmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @pytest.mark.slow @requires_exe("mfnwt", "mt3dusgs") def test_mfnwt_LKT(function_tmpdir, mfnwtmt3d_model_path): - pth = str(mfnwtmt3d_model_path / "lkt") + pth = mfnwtmt3d_model_path / "lkt" namefile = "lkt_mf.nam" mf = Modflow.load( namefile, @@ -354,7 +344,7 @@ def test_mfnwt_LKT(function_tmpdir, mfnwtmt3d_model_path): assert not mf.load_fail, "MODFLOW model did not load" - cpth = str(function_tmpdir / "LKT") + cpth = function_tmpdir / "LKT" mf.model_ws = cpth # write modflow-nwt files @@ -383,13 +373,12 @@ def test_mfnwt_LKT(function_tmpdir, mfnwtmt3d_model_path): success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) @pytest.mark.slow @requires_exe("mfnwt", "mt3dusgs") def test_mfnwt_keat_uzf(function_tmpdir, mfnwtmt3d_model_path): - pth = str(mfnwtmt3d_model_path / "keat_uzf") + pth = mfnwtmt3d_model_path / "keat_uzf" namefile = "Keat_UZF_mf.nam" mf = Modflow.load( namefile, @@ -399,7 +388,7 @@ def test_mfnwt_keat_uzf(function_tmpdir, mfnwtmt3d_model_path): exe_name="mfnwt", ) - cpth = str(function_tmpdir / "KEAT_UZF") + cpth = function_tmpdir / "KEAT_UZF" mf.model_ws = cpth mf.write_input() @@ -427,11 +416,10 @@ def test_mfnwt_keat_uzf(function_tmpdir, mfnwtmt3d_model_path): mt.write_input() success, buff = mt.run_model(silent=False, normal_msg="program completed.") assert success, f"{mt.name} did not run" - os.remove(os.path.join(cpth, ftlfile)) def test_mt3d_create_withmfmodel(function_tmpdir): - model_ws = str(function_tmpdir) + model_ws = function_tmpdir # Create a MODFLOW model mf = Modflow(model_ws=model_ws) @@ -452,40 +440,17 @@ def test_mt3d_create_withmfmodel(function_tmpdir): mt.write_input() # confirm that MT3D files exist - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{btn.extension[0]}")) - is True - ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{adv.extension[0]}")) - is True - ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{dsp.extension[0]}")) - is True - ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{ssm.extension[0]}")) - is True - ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{gcg.extension[0]}")) - is True - ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{rct.extension[0]}")) - is True - ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{tob.extension[0]}")) - is True - ) - - return + assert os.path.isfile(model_ws / f"{mt.name}.{btn.extension[0]}") + assert os.path.isfile(model_ws / f"{mt.name}.{adv.extension[0]}") + assert os.path.isfile(model_ws / f"{mt.name}.{dsp.extension[0]}") + assert os.path.isfile(model_ws / f"{mt.name}.{ssm.extension[0]}") + assert os.path.isfile(model_ws / f"{mt.name}.{gcg.extension[0]}") + assert os.path.isfile(model_ws / f"{mt.name}.{rct.extension[0]}") + assert os.path.isfile(model_ws / f"{mt.name}.{tob.extension[0]}") def test_mt3d_create_woutmfmodel(function_tmpdir): - model_ws = str(function_tmpdir) + model_ws = function_tmpdir # Create MT3D model mt = Mt3dms(model_ws=model_ws) @@ -535,41 +500,32 @@ def test_mt3d_create_woutmfmodel(function_tmpdir): mt.write_input() # confirm that MT3D files exist - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{btn.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{btn.extension[0]}") ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{adv.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{adv.extension[0]}") ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{dsp.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{dsp.extension[0]}") ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{ssm.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{ssm.extension[0]}") ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{gcg.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{gcg.extension[0]}") ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{rct.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{rct.extension[0]}") ) - assert ( - os.path.isfile(os.path.join(model_ws, f"{mt.name}.{tob.extension[0]}")) - is True + assert os.path.isfile( + os.path.join(model_ws, f"{mt.name}.{tob.extension[0]}") ) - return - def test_mt3d_pht3d(function_tmpdir): # Note: this test is incomplete! - model_ws = str(function_tmpdir) + model_ws = function_tmpdir # Create MT3D model mt = Mt3dms(model_ws=model_ws) @@ -593,7 +549,7 @@ def test_mt3d_multispecies(function_tmpdir): nper = 10 mf = Modflow( modelname=modelname, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis = ModflowDis(mf, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) lpf = ModflowLpf(mf) @@ -606,7 +562,7 @@ def test_mt3d_multispecies(function_tmpdir): mt = Mt3dms( modelname=modelname, modflowmodel=mf, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, ) sconc3 = np.random.random((nrow, ncol)) @@ -638,7 +594,7 @@ def test_mt3d_multispecies(function_tmpdir): modelname2 = "multispecies2" mf2 = Modflow( modelname=modelname2, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis2 = ModflowDis(mf2, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) @@ -646,7 +602,7 @@ def test_mt3d_multispecies(function_tmpdir): fname = f"{modelname}.nam" mt2 = Mt3dms.load( fname, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, ) # check obs I/O @@ -663,7 +619,7 @@ def test_lkt_with_multispecies(function_tmpdir): mf = Modflow( modelname=modelname, exe_name="mfnwt", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, version="mfnwt", ) @@ -17781,7 +17737,7 @@ def test_lkt_with_multispecies(function_tmpdir): mt = Mt3dms( modflowmodel=mf, modelname=modelname, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, version="mt3d-usgs", namefile_ext="mtnam", exe_name="mt3dusgs", @@ -17902,7 +17858,7 @@ def test_lkt_with_multispecies(function_tmpdir): namfile = f"{modelname}.nam" mf = Modflow.load( namfile, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, version="mfnwt", verbose=True, exe_name="mfnwt", @@ -17910,7 +17866,7 @@ def test_lkt_with_multispecies(function_tmpdir): namfile = f"{modelname}.mtnam" mt = Mt3dms.load( namfile, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, version="mt3d-usgs", exe_name="mt3dusgs", @@ -17935,7 +17891,7 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(function_tmpdir): # creating MODFLOW model modelname = "model_mf" - mf = Modflow(modelname, model_ws=str(function_tmpdir), exe_name="mf2005") + mf = Modflow(modelname, model_ws=function_tmpdir, exe_name="mf2005") dis = ModflowDis( mf, nlay=nlay, @@ -17994,7 +17950,7 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(function_tmpdir): mt = Mt3dms( modflowmodel=mf, modelname=modelname, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, exe_name="mt3dms", ) btn = Mt3dBtn(mt, sconc=0, ncomp=2, sconc2=50.0) @@ -18012,14 +17968,14 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(function_tmpdir): success, buff = mt.run_model(report=True, normal_msg="Program completed.") assert success, "MT3D did not run" - ws = str(function_tmpdir / "ws2") + ws = function_tmpdir / "ws2" mf2 = Modflow.load( - "model_mf.nam", model_ws=str(function_tmpdir), exe_name="mf2005" + "model_mf.nam", model_ws=function_tmpdir, exe_name="mf2005" ) mf2.change_model_ws(ws) mt2 = Mt3dms.load( "model_mt.nam", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, verbose=True, exe_name="mt3dms", ) @@ -18031,9 +17987,7 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(function_tmpdir): success, buff = mt2.run_model(report=True, normal_msg="Program completed.") assert success, "MT3D did not run" - conca = UcnFile( - os.path.join(str(function_tmpdir), "MT3D001.UCN") - ).get_alldata() + conca = UcnFile(os.path.join(function_tmpdir, "MT3D001.UCN")).get_alldata() concb = UcnFile(os.path.join(ws, "MT3D001.UCN")).get_alldata() assert np.allclose(conca, concb) @@ -18044,7 +17998,7 @@ def test_none_spdtype(function_tmpdir): # ensure that -1 and None work as valid list entries in the # stress period dictionary - mf = Modflow(model_ws=str(function_tmpdir), exe_name="mf2005") + mf = Modflow(model_ws=function_tmpdir, exe_name="mf2005") dis = ModflowDis(mf, nper=2) bas = ModflowBas(mf) lpf = ModflowLpf(mf) @@ -18053,7 +18007,7 @@ def test_none_spdtype(function_tmpdir): pcg = ModflowPcg(mf) mf.write_input() mf2 = Modflow.load( - "modflowtest.nam", model_ws=str(function_tmpdir), verbose=True + "modflowtest.nam", model_ws=function_tmpdir, verbose=True ) success, buff = mf.run_model(report=True) assert success @@ -18074,14 +18028,14 @@ def test_ssm_readwrite(function_tmpdir, example_data_path): btn = Mt3dBtn(mt) # Point to ssm file for test load and write - pth = str(example_data_path / "ssm_load_test") - fl = os.path.join(pth, "tran_v1_b1.ssm") + pth = example_data_path / "ssm_load_test" + fl = pth / "tran_v1_b1.ssm" # Check that example input file with no data specified for crch works # (file comes from: https://github.com/modflowpy/flopy/issues/743) ssm = Mt3dSsm.load(fl, mt) - mt.change_model_ws(str(function_tmpdir)) + mt.change_model_ws(function_tmpdir) # Ensure file is writeable ssm.write_file() diff --git a/autotest/test_nwt_ag.py b/autotest/test_nwt_ag.py index 3da5146151..5dc285ca93 100644 --- a/autotest/test_nwt_ag.py +++ b/autotest/test_nwt_ag.py @@ -14,7 +14,7 @@ def test_load_write_agwater(function_tmpdir, example_data_path): agfile = "Agwater1.ag" ml = Modflow("Agwater1", version="mfnwt") mpath = example_data_path / "ag_test" - ag1 = ModflowAg.load(str(mpath / agfile), ml, nper=49, ext_unit_dict={}) + ag1 = ModflowAg.load(mpath / agfile, ml, nper=49, ext_unit_dict={}) loaded = False for pak in ml.packagelist: @@ -24,15 +24,15 @@ def test_load_write_agwater(function_tmpdir, example_data_path): assert loaded - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) ag1.write_file() ml2 = Modflow( "Agwater1", version="mfnwt", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) - ag2 = ModflowAg.load(str(function_tmpdir / agfile), ml2, nper=49) + ag2 = ModflowAg.load(function_tmpdir / agfile, ml2, nper=49) assert repr(ag1) == repr(ag2), "comparison failed" @@ -42,7 +42,7 @@ def test_load_write_agwater_uzf(function_tmpdir, example_data_path): ml = Modflow("Agwater1", version="mfnwt") dis = ModflowDis(ml, nlay=1, nrow=15, ncol=10, nper=49) mpath = example_data_path / "ag_test" - uzf1 = ModflowUzf1.load(str(mpath / uzffile), ml) + uzf1 = ModflowUzf1.load(mpath / uzffile, ml) loaded = False for pak in ml.packagelist: @@ -52,16 +52,16 @@ def test_load_write_agwater_uzf(function_tmpdir, example_data_path): assert loaded - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) uzf1.write_file() ml2 = Modflow( "Agwater1", version="mfnwt", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis2 = ModflowDis(ml2, nlay=1, nrow=15, ncol=10, nper=49) - uzf2 = ModflowUzf1.load(str(function_tmpdir / uzffile), ml2) + uzf2 = ModflowUzf1.load(function_tmpdir / uzffile, ml2) assert np.allclose( uzf1.air_entry.array, uzf2.air_entry.array diff --git a/autotest/test_obs.py b/autotest/test_obs.py index 828c120c55..80df8f0cfd 100644 --- a/autotest/test_obs.py +++ b/autotest/test_obs.py @@ -25,7 +25,7 @@ def test_hob_simple(function_tmpdir): test041 create and run a simple MODFLOW-2005 OBS example """ modelname = "hob_simple" - ws = str(function_tmpdir) + ws = function_tmpdir nlay, nrow, ncol = 1, 11, 11 shape3d = (nlay, nrow, ncol) shape2d = (nrow, ncol) @@ -112,14 +112,14 @@ def test_obs_load_and_write(function_tmpdir, example_data_path): test041 load and write of MODFLOW-2005 OBS example problem """ - pth = str(example_data_path / "mf2005_obs") - ws = str(function_tmpdir) + pth = example_data_path / "mf2005_obs" + ws = function_tmpdir # copy the original files files = os.listdir(pth) for file in files: - src = os.path.join(pth, file) - dst = os.path.join(ws, file) + src = pth / file + dst = ws / file shutil.copyfile(src, dst) # load the modflow model @@ -254,7 +254,7 @@ def test_obs_single_time(function_tmpdir): test reading a mf6 observation file with a single time """ - pth = str(function_tmpdir / "single.csv") + pth = function_tmpdir / "single.csv" with open(pth, "w") as file: file.write("time,obs01,obs02\n1.0,10.0,20.0\n") @@ -273,14 +273,14 @@ def test_obs_create_and_write(function_tmpdir, example_data_path): test041 create and write of MODFLOW-2005 OBS example problem """ - pth = str(example_data_path / "mf2005_obs") - ws = str(function_tmpdir) + pth = example_data_path / "mf2005_obs" + ws = function_tmpdir # copy the original files files = os.listdir(pth) for file in files: - src = os.path.join(pth, file) - dst = os.path.join(ws, file) + src = pth / file + dst = ws / file shutil.copyfile(src, dst) # load the modflow model diff --git a/autotest/test_pcg.py b/autotest/test_pcg.py index ac26421bd6..4ec1782760 100644 --- a/autotest/test_pcg.py +++ b/autotest/test_pcg.py @@ -10,7 +10,7 @@ def test_pcg_fmt(example_data_path): - pcg_fname = str(example_data_path / "pcg_fmt_test" / "fixfmt.pcg") + pcg_fname = example_data_path / "pcg_fmt_test" / "fixfmt.pcg" # mf2k container - this will pass m2k = Modflow(version="mf2k") m2k.pcg = ModflowPcg.load(model=m2k, f=pcg_fname) diff --git a/autotest/test_plot.py b/autotest/test_plot.py index 300b9b62bb..ffb6f5bac5 100644 --- a/autotest/test_plot.py +++ b/autotest/test_plot.py @@ -77,7 +77,7 @@ def check_vertices(): @pytest.mark.xfail(reason="sometimes get wrong collection type") def test_map_view_bc_gwfs_disv(example_data_path): mpath = example_data_path / "mf6" / "test003_gwfs_disv" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("gwf_1") ml6.modelgrid.set_coord_info(angrot=-14) mapview = flopy.plot.PlotMapView(model=ml6) @@ -97,7 +97,7 @@ def test_map_view_bc_gwfs_disv(example_data_path): @pytest.mark.xfail(reason="sometimes get wrong collection type") def test_map_view_bc_lake2tr(example_data_path): mpath = example_data_path / "mf6" / "test045_lake2tr" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("lakeex2a") mapview = flopy.plot.PlotMapView(model=ml6) mapview.plot_bc("LAK") @@ -117,7 +117,7 @@ def test_map_view_bc_lake2tr(example_data_path): @pytest.mark.xfail(reason="sometimes get wrong collection type") def test_map_view_bc_2models_mvr(example_data_path): mpath = example_data_path / "mf6" / "test006_2models_mvr" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("parent") ml6c = sim.get_model("child") ml6c.modelgrid.set_coord_info(xoff=700, yoff=0, angrot=0) @@ -144,7 +144,7 @@ def test_map_view_bc_2models_mvr(example_data_path): @pytest.mark.xfail(reason="sometimes get wrong collection type") def test_map_view_bc_UZF_3lay(example_data_path): mpath = example_data_path / "mf6" / "test001e_UZF_3lay" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("gwf_1") mapview = flopy.plot.PlotMapView(model=ml6) @@ -166,7 +166,7 @@ def test_map_view_bc_UZF_3lay(example_data_path): ) def test_cross_section_bc_gwfs_disv(example_data_path): mpath = example_data_path / "mf6" / "test003_gwfs_disv" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("gwf_1") xc = flopy.plot.PlotCrossSection(ml6, line={"line": ([0, 5.5], [10, 5.5])}) xc.plot_bc("CHD") @@ -186,7 +186,7 @@ def test_cross_section_bc_gwfs_disv(example_data_path): ) def test_cross_section_bc_lake2tr(example_data_path): mpath = example_data_path / "mf6" / "test045_lake2tr" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("lakeex2a") xc = flopy.plot.PlotCrossSection(ml6, line={"row": 10}) xc.plot_bc("LAK") @@ -207,7 +207,7 @@ def test_cross_section_bc_lake2tr(example_data_path): ) def test_cross_section_bc_2models_mvr(example_data_path): mpath = example_data_path / "mf6" / "test006_2models_mvr" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("parent") xc = flopy.plot.PlotCrossSection(ml6, line={"column": 1}) xc.plot_bc("MAW") @@ -227,7 +227,7 @@ def test_cross_section_bc_2models_mvr(example_data_path): ) def test_cross_section_bc_UZF_3lay(example_data_path): mpath = example_data_path / "mf6" / "test001e_UZF_3lay" - sim = MFSimulation.load(sim_ws=str(mpath)) + sim = MFSimulation.load(sim_ws=mpath) ml6 = sim.get_model("gwf_1") xc = flopy.plot.PlotCrossSection(ml6, line={"row": 0}) @@ -286,7 +286,7 @@ def test_vertex_model_dot_plot(example_data_path): # load up the vertex example problem sim = MFSimulation.load( - sim_ws=str(example_data_path / "mf6" / "test003_gwftri_disv") + sim_ws=example_data_path / "mf6" / "test003_gwftri_disv" ) disv_ml = sim.get_model("gwf_1") ax = disv_ml.plot() @@ -300,7 +300,7 @@ def test_vertex_model_dot_plot(example_data_path): def test_model_dot_plot(function_tmpdir, example_data_path): loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( - "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False + "ibs2k.nam", "mf2k", model_ws=loadpth, check=False ) ax = ml.plot() assert isinstance(ax, list), "ml.plot() ax is is not a list" @@ -310,7 +310,7 @@ def test_model_dot_plot(function_tmpdir, example_data_path): def test_dataset_dot_plot(function_tmpdir, example_data_path): loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( - "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False + "ibs2k.nam", "mf2k", model_ws=loadpth, check=False ) # plot specific dataset @@ -326,7 +326,7 @@ def test_dataset_dot_plot_nlay_ne_plottable( loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( - "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False + "ibs2k.nam", "mf2k", model_ws=loadpth, check=False ) # special case where nlay != plottable ax = ml.bcf6.vcont.plot() @@ -338,7 +338,7 @@ def test_dataset_dot_plot_nlay_ne_plottable( def test_model_dot_plot_export(function_tmpdir, example_data_path): loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( - "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False + "ibs2k.nam", "mf2k", model_ws=loadpth, check=False ) fh = os.path.join(function_tmpdir, "ibs2k") @@ -361,8 +361,8 @@ def test_pathline_plot_xc(function_tmpdir, example_data_path): # test with multi-layer example load_ws = example_data_path / "mp6" - ml = Modflow.load("EXAMPLE.nam", model_ws=str(load_ws), exe_name="mf2005") - ml.change_model_ws(str(function_tmpdir)) + ml = Modflow.load("EXAMPLE.nam", model_ws=load_ws, exe_name="mf2005") + ml.change_model_ws(function_tmpdir) ml.write_input() ml.run_model() @@ -370,7 +370,7 @@ def test_pathline_plot_xc(function_tmpdir, example_data_path): modelname="ex6", exe_name="mp6", modflowmodel=ml, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) mpb = Modpath6Bas( @@ -387,7 +387,7 @@ def test_pathline_plot_xc(function_tmpdir, example_data_path): mp.run_model(silent=False) - pthobj = PathlineFile(os.path.join(str(function_tmpdir), "ex6.mppth")) + pthobj = PathlineFile(os.path.join(function_tmpdir, "ex6.mppth")) well_pathlines = pthobj.get_destination_pathline_data( dest_cells=[(4, 12, 12)] ) @@ -405,7 +405,7 @@ def test_pathline_plot_xc(function_tmpdir, example_data_path): @pytest.fixture def quasi3d_model(function_tmpdir): - mf = Modflow("model_mf", model_ws=str(function_tmpdir), exe_name="mf2005") + mf = Modflow("model_mf", model_ws=function_tmpdir, exe_name="mf2005") # Model domain and grid definition Lx = 1000.0 @@ -493,7 +493,7 @@ def test_map_plot_with_quasi3d_layers(quasi3d_model): mv.plot_ibound() mv.plot_bc("wel") mv.plot_vector(frf, fff) - plt.savefig(os.path.join(str(quasi3d_model.model_ws), "plt01.png")) + plt.savefig(os.path.join(quasi3d_model.model_ws, "plt01.png")) @requires_exe("mf2005") @@ -522,7 +522,7 @@ def test_cross_section_with_quasi3d_layers(quasi3d_model): cs.plot_ibound() cs.plot_bc("wel") cs.plot_vector(frf, fff, flf, head=head) - plt.savefig(os.path.join(str(quasi3d_model.model_ws), "plt02.png")) + plt.savefig(os.path.join(quasi3d_model.model_ws, "plt02.png")) plt.close() diff --git a/autotest/test_postprocessing.py b/autotest/test_postprocessing.py index 0b67cd6113..83f7d8e7af 100644 --- a/autotest/test_postprocessing.py +++ b/autotest/test_postprocessing.py @@ -37,11 +37,11 @@ def test_faceflows(function_tmpdir, mf6_freyberg_path): sim = MFSimulation.load( sim_name="freyberg", exe_name="mf6", - sim_ws=str(mf6_freyberg_path), + sim_ws=mf6_freyberg_path, ) # change the simulation workspace - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write the model simulation files sim.write_simulation() @@ -59,7 +59,7 @@ def test_faceflows(function_tmpdir, mf6_freyberg_path): frf, fff, flf = get_structured_faceflows( flowja, - grb_file=str(function_tmpdir / "freyberg.dis.grb"), + grb_file=function_tmpdir / "freyberg.dis.grb", ) Qx, Qy, Qz = get_specific_discharge( (frf, fff, flf), @@ -105,11 +105,11 @@ def test_flowja_residuals(function_tmpdir, mf6_freyberg_path): sim = MFSimulation.load( sim_name="freyberg", exe_name="mf6", - sim_ws=str(mf6_freyberg_path), + sim_ws=mf6_freyberg_path, ) # change the simulation workspace - sim.set_sim_path(str(function_tmpdir)) + sim.set_sim_path(function_tmpdir) # write the model simulation files sim.write_simulation() @@ -119,7 +119,7 @@ def test_flowja_residuals(function_tmpdir, mf6_freyberg_path): # get output gwf = sim.get_model("freyberg") - grb_file = str(function_tmpdir / "freyberg.dis.grb") + grb_file = function_tmpdir / "freyberg.dis.grb" cbc = gwf.output.budget() spdis = cbc.get_data(text="DATA-SPDIS")[0] @@ -151,9 +151,7 @@ def test_flowja_residuals(function_tmpdir, mf6_freyberg_path): @requires_exe("mf6") def test_structured_faceflows_3d(function_tmpdir): name = "mymodel" - sim = MFSimulation( - sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" - ) + sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name="mf6") tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -181,7 +179,7 @@ def test_structured_faceflows_3d(function_tmpdir): flowja = bud.get_data(text="FLOW-JA-FACE")[0] frf, fff, flf = get_structured_faceflows( flowja, - grb_file=str(function_tmpdir / "mymodel.dis.grb"), + grb_file=function_tmpdir / "mymodel.dis.grb", ) assert ( frf.shape == head.shape @@ -212,7 +210,7 @@ def test_get_transmissivities(function_tmpdir): for i in range(nl): botm[nl - i - 1, :, :] = i - m = Modflow("junk", version="mfnwt", model_ws=str(function_tmpdir)) + m = Modflow("junk", version="mfnwt", model_ws=function_tmpdir) dis = ModflowDis(m, nlay=nl, nrow=nr, ncol=nc, botm=botm, top=top) upw = ModflowUpw(m, hk=hk) @@ -287,7 +285,7 @@ def test_get_sat_thickness_gradients(function_tmpdir): botm[0, :, :] = 3.0 botm[1, :, :] = 2.0 - m = Modflow("junk", version="mfnwt", model_ws=str(function_tmpdir)) + m = Modflow("junk", version="mfnwt", model_ws=function_tmpdir) dis = ModflowDis(m, nlay=nl, nrow=nr, ncol=nc, botm=botm, top=top) lpf = ModflowLpf(m, laytyp=np.ones(nl)) diff --git a/autotest/test_seawat.py b/autotest/test_seawat.py index 46aa59f37b..4337be778b 100644 --- a/autotest/test_seawat.py +++ b/autotest/test_seawat.py @@ -52,7 +52,7 @@ def test_seawat_henry(function_tmpdir): # SEAWAT model from a modflow model and an mt3d model modelname = "henry" - mf = Modflow(modelname, exe_name="swtv4", model_ws=str(function_tmpdir)) + mf = Modflow(modelname, exe_name="swtv4", model_ws=function_tmpdir) # shortened perlen to 0.1 to make this run faster -- should be about 0.5 dis = ModflowDis( mf, @@ -79,7 +79,7 @@ def test_seawat_henry(function_tmpdir): ) # Create the basic MT3DMS model structure - mt = Mt3dms(modelname, "nam_mt3dms", mf, model_ws=str(function_tmpdir)) + mt = Mt3dms(modelname, "nam_mt3dms", mf, model_ws=function_tmpdir) btn = Mt3dBtn( mt, nprs=-5, @@ -102,7 +102,7 @@ def test_seawat_henry(function_tmpdir): "nam_swt", mf, mt, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, exe_name="swtv4", ) vdf = SeawatVdf( @@ -132,7 +132,7 @@ def test_seawat2_henry(function_tmpdir): m = Seawat( modelname, "nam", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, exe_name="swtv4", ) dis = ModflowDis( @@ -205,10 +205,8 @@ def swt4_namfiles(): @pytest.mark.parametrize("binary", [True, False]) def test_seawat_load_and_write(function_tmpdir, namfile, binary): model_name = Path(namfile).name - m = Seawat.load( - model_name, model_ws=str(Path(namfile).parent), verbose=True - ) - m.change_model_ws(str(function_tmpdir), reset_external=True) + m = Seawat.load(model_name, model_ws=Path(namfile).parent, verbose=True) + m.change_model_ws(function_tmpdir, reset_external=True) if binary: skip_bcf6 = False @@ -243,7 +241,7 @@ def test_vdf_vsc(function_tmpdir): nrow = 4 ncol = 5 nper = 3 - m = Seawat(modelname="vdftest", model_ws=str(function_tmpdir)) + m = Seawat(modelname="vdftest", model_ws=function_tmpdir) dis = ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) vdf = SeawatVdf(m) diff --git a/autotest/test_sfr.py b/autotest/test_sfr.py index 83b7492da9..29008499d0 100644 --- a/autotest/test_sfr.py +++ b/autotest/test_sfr.py @@ -127,7 +127,7 @@ def sfr_data(): @pytest.mark.parametrize("case", list(sfr_models().values())[:-1]) def test_load_sfr(case, mf2005_model_path): m = Modflow() - sfr = ModflowSfr2.load(str(mf2005_model_path / case["sfrfile"]), m) + sfr = ModflowSfr2.load(mf2005_model_path / case["sfrfile"], m) def test_sfr(function_tmpdir, mf2005_model_path, sfr_test_model_path): @@ -230,7 +230,7 @@ def interpolate_to_reaches(sfr): # trout lake example (only sfr file is included) # can add tests for sfr connection with lak package - sfr = ModflowSfr2.load(str(sfr_test_model_path / "TL2009.sfr"), Modflow()) + sfr = ModflowSfr2.load(sfr_test_model_path / "TL2009.sfr", Modflow()) # convert sfr package to reach input sfr.reachinput = True sfr.isfropt = 1 @@ -378,27 +378,25 @@ def test_export(function_tmpdir, sfr_data): m = Modflow() dis = ModflowDis(m, 1, 10, 10, lenuni=2, itmuni=4) - m.export(str(function_tmpdir / "grid.shp")) + m.export(function_tmpdir / "grid.shp") r, d = sfr_data sfr = ModflowSfr2(m, reach_data=r, segment_data={0: d}) sfr.segment_data[0]["flow"][-1] = 1e4 - sfr.stress_period_data.export( - str(function_tmpdir / "sfr.shp"), sparse=True - ) - sfr.export_linkages(str(function_tmpdir / "linkages.shp")) - sfr.export_outlets(str(function_tmpdir / "outlets.shp")) - sfr.export_transient_variable(str(function_tmpdir / "inlets.shp"), "flow") + sfr.stress_period_data.export(function_tmpdir / "sfr.shp", sparse=True) + sfr.export_linkages(function_tmpdir / "linkages.shp") + sfr.export_outlets(function_tmpdir / "outlets.shp") + sfr.export_transient_variable(function_tmpdir / "inlets.shp", "flow") from flopy.export.shapefile_utils import shp2recarray - ra = shp2recarray(str(function_tmpdir / "inlets.shp")) + ra = shp2recarray(function_tmpdir / "inlets.shp") assert ra.flow0[0] == 1e4 - ra = shp2recarray(str(function_tmpdir / "outlets.shp")) + ra = shp2recarray(function_tmpdir / "outlets.shp") assert ra.iseg[0] + ra.ireach[0] == 5 - ra = shp2recarray(str(function_tmpdir / "linkages.shp")) + ra = shp2recarray(function_tmpdir / "linkages.shp") crds = np.array(list(ra.geometry[2].coords)) assert np.array_equal(crds, np.array([[2.5, 4.5], [3.5, 5.5]])) - ra = shp2recarray(str(function_tmpdir / "sfr.shp")) + ra = shp2recarray(function_tmpdir / "sfr.shp") assert ra.iseg.sum() == sfr.reach_data.iseg.sum() assert ra.ireach.sum() == sfr.reach_data.ireach.sum() y = np.concatenate([np.array(g.exterior)[:, 1] for g in ra.geometry]) @@ -418,7 +416,7 @@ def test_example(mf2005_model_path): "test1ss.nam", version="mf2005", exe_name="mf2005", - model_ws=str(mf2005_model_path), + model_ws=mf2005_model_path, load_only=["ghb", "evt", "rch", "dis", "bas6", "oc", "sip", "lpf"], ) reach_data = np.genfromtxt( @@ -546,7 +544,7 @@ def test_no_ds_6bc(function_tmpdir): "2.77 1.11 0.83 0 0.28 0.83 1.11 2.77\n" ) sfrfile = io.StringIO(sfrfiletxt) - m = Modflow("junk", model_ws=str(function_tmpdir)) + m = Modflow("junk", model_ws=function_tmpdir) sfr = ModflowSfr2.load(sfrfile, model=m) assert len(sfr.segment_data[0]) == 2 assert len(sfr.channel_geometry_data[0]) == 2 @@ -555,7 +553,7 @@ def test_no_ds_6bc(function_tmpdir): assert len(sfr.channel_geometry_data[0][1][i]) == 8 assert sum(sfr.channel_geometry_data[0][1][i]) > 0.0 - sfrfile2 = str(function_tmpdir / "junk.sfr") + sfrfile2 = function_tmpdir / "junk.sfr" sfr.write_file() sfr = ModflowSfr2.load(sfrfile2, model=m) assert len(sfr.segment_data[0]) == 2 @@ -567,11 +565,11 @@ def test_no_ds_6bc(function_tmpdir): def test_ds_6d_6e_disordered(function_tmpdir, hydmod_model_path): - m = Modflow.load("test1tr2.nam", model_ws=str(hydmod_model_path)) - m.change_model_ws(str(function_tmpdir)) + m = Modflow.load("test1tr2.nam", model_ws=hydmod_model_path) + m.change_model_ws(function_tmpdir) m.write_input() - m2 = Modflow.load("test1tr2.nam", model_ws=str(function_tmpdir)) + m2 = Modflow.load("test1tr2.nam", model_ws=function_tmpdir) sfr = m.get_package("SFR") sfr2 = m2.get_package("SFR") @@ -594,7 +592,7 @@ def test_ds_6d_6e_disordered(function_tmpdir, hydmod_model_path): def test_disordered_reachdata_fields(function_tmpdir, hydmod_model_path): - m = Modflow.load("test1tr2.nam", model_ws=str(hydmod_model_path)) + m = Modflow.load("test1tr2.nam", model_ws=hydmod_model_path) sfr = m.get_package("SFR") orig_reach_data = sfr.reach_data # build shuffled rec array @@ -608,28 +606,28 @@ def test_disordered_reachdata_fields(function_tmpdir, hydmod_model_path): formats.append(orig_reach_data.dtype[field].str) reach_data = np.rec.fromarrays(data, names=names, formats=formats) m.sfr.reach_data = reach_data - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.write_input() def test_transient_example(function_tmpdir, mf2005_model_path): - gpth = str(mf2005_model_path / "testsfr2.*") - for f in glob.glob(gpth): + gpth = mf2005_model_path / "testsfr2.*" + for f in glob.glob(str(gpth)): shutil.copy(f, function_tmpdir) - m = Modflow.load("testsfr2.nam", model_ws=str(function_tmpdir)) + m = Modflow.load("testsfr2.nam", model_ws=function_tmpdir) # test handling of unformatted output file m.sfr.istcb2 = -49 m.set_output_attribute(unit=abs(m.sfr.istcb2), attr={"binflag": True}) m.write_input() - m2 = Modflow.load("testsfr2.nam", model_ws=str(function_tmpdir)) + m2 = Modflow.load("testsfr2.nam", model_ws=function_tmpdir) assert m2.sfr.istcb2 == -49 assert m2.get_output_attribute(unit=abs(m2.sfr.istcb2), attr="binflag") @pytest.mark.skip("Pending https://github.com/modflowpy/flopy/issues/1471") def test_assign_layers(function_tmpdir): - m = Modflow(model_ws=str(function_tmpdir)) + m = Modflow(model_ws=function_tmpdir) m.dis = ModflowDis( nrow=1, ncol=6, @@ -687,7 +685,7 @@ def test_SfrFile(function_tmpdir, sfr_examples_path, mf2005_model_path): "width", "Cond", ] - sfrout = SfrFile(str(sfr_examples_path / "sfroutput2.txt")) + sfrout = SfrFile(sfr_examples_path / "sfroutput2.txt") assert sfrout.ncol == 18, sfrout.ncol assert sfrout.names == common_names + [ "Qwt", @@ -703,7 +701,7 @@ def test_SfrFile(function_tmpdir, sfr_examples_path, mf2005_model_path): assert df.Cond.values[0] == 74510.0 assert df.gw_head.values[3] == 1.288e03 - sfrout = SfrFile(str(sfr_examples_path / "test1tr.flw")) + sfrout = SfrFile(sfr_examples_path / "test1tr.flw") assert sfrout.ncol == 16, sfrout.ncol assert sfrout.names == common_names + ["gradient"], sfrout.names expected_times = [ @@ -745,13 +743,13 @@ def test_SfrFile(function_tmpdir, sfr_examples_path, mf2005_model_path): assert df.shape == (1080, 20) ml = Modflow.load( - "test1tr.nam", model_ws=str(mf2005_model_path), exe_name="mf2005" + "test1tr.nam", model_ws=mf2005_model_path, exe_name="mf2005" ) - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) ml.write_input() ml.run_model() - sfrout = SfrFile(str(function_tmpdir / "test1tr.flw")) + sfrout = SfrFile(function_tmpdir / "test1tr.flw") assert sfrout.ncol == 16, sfrout.ncol assert sfrout.names == common_names + ["gradient"], sfrout.names expected_times = [ @@ -792,7 +790,7 @@ def test_SfrFile(function_tmpdir, sfr_examples_path, mf2005_model_path): def test_sfr_plot(mf2005_model_path): m = Modflow.load( "test1ss.nam", - model_ws=str(mf2005_model_path), + model_ws=mf2005_model_path, verbose=False, check=False, ) @@ -810,12 +808,10 @@ def get_test_matrix(): def test_sfrcheck(function_tmpdir, mf2005_model_path): - m = Modflow.load( - "test1tr.nam", model_ws=str(mf2005_model_path), verbose=False - ) + m = Modflow.load("test1tr.nam", model_ws=mf2005_model_path, verbose=False) # run level=0 check - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir fpth = "SFRchecker_results.txt" m.sfr.check(fpth, level=0) @@ -882,11 +878,9 @@ def test_sfrcheck(function_tmpdir, mf2005_model_path): @pytest.mark.parametrize("i, case", list(sfr_models().items())) def test_sfrloadcheck(function_tmpdir, mf2005_model_path, i, case): - m = Modflow.load(case["mfnam"], model_ws=str(mf2005_model_path)) - m.model_ws = str(function_tmpdir) - checker_outfile = os.path.join( - str(function_tmpdir), f"SFRcheck_{m.name}.txt" - ) + m = Modflow.load(case["mfnam"], model_ws=mf2005_model_path) + m.model_ws = function_tmpdir + checker_outfile = os.path.join(function_tmpdir, f"SFRcheck_{m.name}.txt") chk = m.sfr.check(checker_outfile, level=1) @@ -906,7 +900,7 @@ def test_isfropt_icalc(function_tmpdir, example_data_path, isfropt, icalc): if sfr is None: raise AssertionError() - ws = os.path.join(str(function_tmpdir), f"sfrtest{isfropt}{icalc}") + ws = function_tmpdir / f"sfrtest{isfropt}{icalc}" ml.change_model_ws(ws) ml.write_input() success = ml.run_model()[0] @@ -926,8 +920,8 @@ def test_isfropt_icalc(function_tmpdir, example_data_path, isfropt, icalc): @pytest.mark.parametrize( "namfile", [ - str(__example_data_path / "mf2005_test" / "str.nam"), - str( + __example_data_path / "mf2005_test" / "str.nam", + ( __example_data_path.parent / "groundwater_paper" / "uspb" @@ -949,7 +943,7 @@ def test_mf2005(function_tmpdir, namfile): # rewrite files ws = function_tmpdir / "ws" - m.model_ws = str(ws) + m.model_ws = ws m.write_input() # attempt to run the model @@ -957,7 +951,7 @@ def test_mf2005(function_tmpdir, namfile): assert success # load files - pth = str(ws / f"{m.name}.str") + pth = ws / f"{m.name}.str" str2 = ModflowStr.load(pth, m) for name in str2.dtype.names: assert ( diff --git a/autotest/test_specific_discharge.py b/autotest/test_specific_discharge.py index 227afdc223..3ffe4c85e5 100644 --- a/autotest/test_specific_discharge.py +++ b/autotest/test_specific_discharge.py @@ -126,7 +126,7 @@ @pytest.fixture def mf2005_model(function_tmpdir): # create modflow model - mf = Modflow("mf2005", model_ws=str(function_tmpdir), exe_name="mf2005") + mf = Modflow("mf2005", model_ws=function_tmpdir, exe_name="mf2005") # cell by cell flow file unit number cbc_unit_nb = 53 @@ -192,7 +192,7 @@ def mf6_model(function_tmpdir): sim_name="mf6", version="mf6", exe_name="mf6", - sim_ws=str(function_tmpdir), + sim_ws=function_tmpdir, ) # create tdis package @@ -356,11 +356,11 @@ def local_balance_check(Qx_ext, Qy_ext, Qz_ext, hdsfile=None, model=None): def test_extended_budget_default(mf2005_model): # build and run MODFLOW 2005 model mf, function_tmpdir = mf2005_model - success, buff = mf.run_model() + mf.run_model() # load and postprocess Qx_ext, Qy_ext, Qz_ext = get_extended_budget( - str(function_tmpdir / "mf2005.cbc") + function_tmpdir / "mf2005.cbc" ) # basic check @@ -377,11 +377,11 @@ def test_extended_budget_default(mf2005_model): def extended_budget_comprehensive(function_tmpdir): # load and postprocess - mf = Modflow.load(str(function_tmpdir / "mf2005.nam"), check=False) + mf = Modflow.load(function_tmpdir / "mf2005.nam", check=False) Qx_ext, Qy_ext, Qz_ext = get_extended_budget( - str(function_tmpdir / "mf2005.cbc"), + function_tmpdir / "mf2005.cbc", boundary_ifaces=boundary_ifaces, - hdsfile=str(function_tmpdir / "mf2005.hds"), + hdsfile=function_tmpdir / "mf2005.hds", model=mf, ) @@ -390,7 +390,7 @@ def extended_budget_comprehensive(function_tmpdir): # local balance check local_balance_check( - Qx_ext, Qy_ext, Qz_ext, str(function_tmpdir / "mf2005.hds"), mf + Qx_ext, Qy_ext, Qz_ext, function_tmpdir / "mf2005.hds", mf ) # overall check @@ -400,8 +400,8 @@ def extended_budget_comprehensive(function_tmpdir): def specific_discharge_default(function_tmpdir): # load and postprocess - mf = Modflow.load(str(function_tmpdir / "mf2005.nam"), check=False) - cbc = bf.CellBudgetFile(str(function_tmpdir / "mf2005.cbc")) + mf = Modflow.load(function_tmpdir / "mf2005.nam", check=False) + cbc = bf.CellBudgetFile(function_tmpdir / "mf2005.cbc") keys = ["FLOW RIGHT FACE", "FLOW FRONT FACE", "FLOW LOWER FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] qx, qy, qz = get_specific_discharge(vectors, mf) @@ -412,14 +412,14 @@ def specific_discharge_default(function_tmpdir): def specific_discharge_comprehensive(function_tmpdir): - hds = bf.HeadFile(str(function_tmpdir / "mf2005.hds")) + hds = bf.HeadFile(function_tmpdir / "mf2005.hds") head = hds.get_data() # load and postprocess - mf = Modflow.load(str(function_tmpdir / "mf2005.nam"), check=False) + mf = Modflow.load(function_tmpdir / "mf2005.nam", check=False) Qx_ext, Qy_ext, Qz_ext = get_extended_budget( - str(function_tmpdir / "mf2005.cbc"), + function_tmpdir / "mf2005.cbc", boundary_ifaces=boundary_ifaces, - hdsfile=str(function_tmpdir / "mf2005.hds"), + hdsfile=function_tmpdir / "mf2005.hds", model=mf, ) @@ -456,7 +456,7 @@ def specific_discharge_comprehensive(function_tmpdir): plt.close() # plot discharge in cross-section view - hds = bf.HeadFile(str(function_tmpdir / "mf2005.hds"), precision="single") + hds = bf.HeadFile(function_tmpdir / "mf2005.hds", precision="single") head = hds.get_data() row = 0 xsect = PlotCrossSection(model=mf, line={"row": row}) @@ -502,12 +502,12 @@ def test_specific_discharge_mf6(mf6_model): # load and postprocess sim = MFSimulation.load( - sim_name="mf6", sim_ws=str(function_tmpdir), verbosity_level=0 + sim_name="mf6", sim_ws=function_tmpdir, verbosity_level=0 ) gwf = sim.get_model("mf6") - hds = bf.HeadFile(str(function_tmpdir / "mf6.hds")) + hds = bf.HeadFile(function_tmpdir / "mf6.hds") head = hds.get_data() - cbc = bf.CellBudgetFile(str(function_tmpdir / "mf6.cbc")) + cbc = bf.CellBudgetFile(function_tmpdir / "mf6.cbc") spdis = cbc.get_data(text="SPDIS")[0] qx, qy, qz = get_specific_discharge(spdis, gwf, head) @@ -541,7 +541,7 @@ def test_specific_discharge_mf6(mf6_model): plt.close() # plot discharge in cross-section view - hds = bf.HeadFile(str(function_tmpdir / "mf6.hds"), precision="double") + hds = bf.HeadFile(function_tmpdir / "mf6.hds", precision="double") head = hds.get_data() row = 0 xsect = PlotCrossSection(model=gwf, line={"row": row}) diff --git a/autotest/test_str.py b/autotest/test_str.py index 8a6cec82eb..b54149137a 100644 --- a/autotest/test_str.py +++ b/autotest/test_str.py @@ -20,12 +20,12 @@ def test_str_issue1164(function_tmpdir, example_data_path): m = Modflow.load( str_items[0]["mfnam"], exe_name="mf2005", - model_ws=str(mf2005_model_path), + model_ws=mf2005_model_path, verbose=False, check=False, ) - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) # adjust stress period data spd0 = m.str.stress_period_data[0] @@ -38,7 +38,7 @@ def test_str_issue1164(function_tmpdir, example_data_path): assert success, "could not run base model" # get the budget - lst_pth = str(function_tmpdir / str_items[0]["lstfile"]) + lst_pth = function_tmpdir / str_items[0]["lstfile"] base_wb = MfListBudget(lst_pth).get_dataframes()[0] # set the model to free format diff --git a/autotest/test_subwt.py b/autotest/test_subwt.py index 5b436919e5..da649c19b9 100644 --- a/autotest/test_subwt.py +++ b/autotest/test_subwt.py @@ -27,7 +27,7 @@ def ibound_path(example_data_path): @pytest.mark.slow @requires_exe("mf2005") def test_subwt(function_tmpdir, ibound_path): - ws = str(function_tmpdir) + ws = function_tmpdir ml = Modflow("subwt_mf2005", model_ws=ws, exe_name="mf2005") perlen = [1.0, 60.0 * 365.25, 60 * 365.25] nstp = [1, 60, 60] @@ -114,21 +114,21 @@ def test_subwt(function_tmpdir, ibound_path): # contents = [f for f in function_tmpdir.glob("*.hds")] hds_geo = HeadFile( - str(function_tmpdir / f"{ml.name}.swt_geostatic_stress.hds"), + function_tmpdir / f"{ml.name}.swt_geostatic_stress.hds", text="stress", ).get_alldata() hds_eff = HeadFile( - str(function_tmpdir / f"{ml.name}.swt_eff_stress.hds"), + function_tmpdir / f"{ml.name}.swt_eff_stress.hds", text="effective stress", ).get_alldata() hds_sub = HeadFile( - str(function_tmpdir / f"{ml.name}.swt_subsidence.hds"), + function_tmpdir / f"{ml.name}.swt_subsidence.hds", text="subsidence", ).get_alldata() hds_comp = HeadFile( - str(function_tmpdir / f"{ml.name}.swt_total_comp.hds"), + function_tmpdir / f"{ml.name}.swt_total_comp.hds", text="layer compaction", ).get_alldata() diff --git a/autotest/test_swr_binaryread.py b/autotest/test_swr_binaryread.py index a4270da4d5..228127a12b 100644 --- a/autotest/test_swr_binaryread.py +++ b/autotest/test_swr_binaryread.py @@ -29,7 +29,7 @@ def swr_test_path(example_data_path): @pytest.mark.parametrize("ipos", [0]) def test_swr_binary_stage(swr_test_path, ipos): - fswr_test_path = str(swr_test_path / files[ipos]) + fswr_test_path = swr_test_path / files[ipos] sobj = SwrStage(fswr_test_path) assert isinstance(sobj, SwrStage), "SwrStage object not created" @@ -98,7 +98,7 @@ def test_swr_binary_stage(swr_test_path, ipos): @pytest.mark.parametrize("ipos", [1]) def test_swr_binary_budget(swr_test_path, ipos): - fswr_test_path = str(swr_test_path / files[ipos]) + fswr_test_path = swr_test_path / files[ipos] sobj = SwrBudget(fswr_test_path) assert isinstance(sobj, SwrBudget), "SwrBudget object not created" @@ -170,7 +170,7 @@ def test_swr_binary_budget(swr_test_path, ipos): @pytest.mark.parametrize("ipos", [2]) def test_swr_binary_qm(swr_test_path, ipos): - fswr_test_path = str(swr_test_path / files[ipos]) + fswr_test_path = swr_test_path / files[ipos] sobj = SwrFlow(fswr_test_path) assert isinstance(sobj, SwrFlow), "SwrFlow object not created" @@ -249,7 +249,7 @@ def test_swr_binary_qm(swr_test_path, ipos): @pytest.mark.parametrize("ipos", [3]) def test_swr_binary_qaq(swr_test_path, ipos): - fswr_test_path = str(swr_test_path / files[ipos]) + fswr_test_path = swr_test_path / files[ipos] sobj = SwrExchange(fswr_test_path, verbose=True) assert isinstance(sobj, SwrExchange), "SwrExchange object not created" @@ -321,7 +321,7 @@ def test_swr_binary_qaq(swr_test_path, ipos): @pytest.mark.parametrize("ipos", [4]) def test_swr_binary_structure(swr_test_path, ipos): - fswr_test_path = str(swr_test_path / files[ipos]) + fswr_test_path = swr_test_path / files[ipos] sobj = SwrStructure(fswr_test_path, verbose=True) assert isinstance(sobj, SwrStructure), "SwrStructure object not created" @@ -392,7 +392,7 @@ def test_swr_binary_structure(swr_test_path, ipos): @pytest.mark.parametrize("ipos", [5]) def test_swr_binary_obs(swr_test_path, ipos): - fswr_test_path = str(swr_test_path / files[ipos]) + fswr_test_path = swr_test_path / files[ipos] sobj = SwrObs(fswr_test_path) assert isinstance(sobj, SwrObs), "SwrObs object not created" diff --git a/autotest/test_template_writer.py b/autotest/test_template_writer.py index 52e769c297..f6e7ae39c9 100644 --- a/autotest/test_template_writer.py +++ b/autotest/test_template_writer.py @@ -13,7 +13,7 @@ def test_tpl_constant(function_tmpdir): ncol = 20 # Create the flopy model object and add the dis and lpf packages - m = Modflow(modelname="tpl1", model_ws=str(function_tmpdir)) + m = Modflow(modelname="tpl1", model_ws=function_tmpdir) dis = ModflowDis(m, nlay, nrow, ncol) lpf = ModflowLpf(m, hk=10.0) @@ -38,7 +38,7 @@ def test_tpl_constant(function_tmpdir): tw = TemplateWriter(m, [p]) tw.write_template() - tplfile = str(function_tmpdir / "tpl1.lpf.tpl") + tplfile = function_tmpdir / "tpl1.lpf.tpl" assert os.path.isfile(tplfile) @@ -48,7 +48,7 @@ def test_tpl_layered(function_tmpdir): ncol = 20 # Create the flopy model object and add the dis and lpf packages - m = Modflow(modelname="tpl2", model_ws=str(function_tmpdir)) + m = Modflow(modelname="tpl2", model_ws=function_tmpdir) dis = ModflowDis(m, nlay, nrow, ncol) lpf = ModflowLpf(m, hk=10.0) @@ -69,7 +69,7 @@ def test_tpl_layered(function_tmpdir): tw = TemplateWriter(m, [p]) tw.write_template() - tplfile = str(function_tmpdir / "tpl2.lpf.tpl") + tplfile = function_tmpdir / "tpl2.lpf.tpl" assert os.path.isfile(tplfile) @@ -79,7 +79,7 @@ def test_tpl_zoned(function_tmpdir): ncol = 20 # Create the flopy model object and add the dis and lpf packages - m = Modflow(modelname="tpl3", model_ws=str(function_tmpdir)) + m = Modflow(modelname="tpl3", model_ws=function_tmpdir) dis = ModflowDis(m, nlay, nrow, ncol) lpf = ModflowLpf(m, hk=10.0) @@ -130,5 +130,5 @@ def test_tpl_zoned(function_tmpdir): tw = TemplateWriter(m, plist) tw.write_template() - tplfile = str(function_tmpdir / "tpl3.lpf.tpl") + tplfile = function_tmpdir / "tpl3.lpf.tpl" assert os.path.isfile(tplfile) diff --git a/autotest/test_usg.py b/autotest/test_usg.py index 9258338230..7a2208c12a 100644 --- a/autotest/test_usg.py +++ b/autotest/test_usg.py @@ -35,7 +35,7 @@ def freyberg_usg_model_path(example_data_path): @requires_exe("mfusg") def test_usg_disu_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): - fname = str(mfusg_01A_nestedgrid_nognc_model_path / "flow.disu") + fname = mfusg_01A_nestedgrid_nognc_model_path / "flow.disu" assert os.path.isfile(fname), f"disu file not found {fname}" # Create the model @@ -46,7 +46,7 @@ def test_usg_disu_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): assert isinstance(disu, MfUsgDisU) # Change where model files are written - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir # Write the disu file disu.write_file() @@ -69,7 +69,7 @@ def test_usg_disu_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): @requires_exe("mfusg") def test_usg_sms_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): - fname = str(mfusg_01A_nestedgrid_nognc_model_path / "flow.sms") + fname = mfusg_01A_nestedgrid_nognc_model_path / "flow.sms" assert os.path.isfile(fname), f"sms file not found {fname}" # Create the model @@ -80,7 +80,7 @@ def test_usg_sms_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): assert isinstance(sms, MfUsgSms) # Change where model files are written - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir # Write the sms file sms.write_file() @@ -101,7 +101,7 @@ def test_usg_model(function_tmpdir): mf = MfUsg( version="mfusg", structured=True, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, modelname="simple", exe_name="mfusg", ) @@ -142,18 +142,18 @@ def test_usg_load_01B(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): "loading: 01A_nestedgrid_nognc.nam" ) - fname = str(mfusg_01A_nestedgrid_nognc_model_path / "flow.nam") + fname = mfusg_01A_nestedgrid_nognc_model_path / "flow.nam" assert os.path.isfile(fname), f"nam file not found {fname}" # Create the model m = MfUsg( modelname="usgload_1b", verbose=True, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) # Load the model, with checking - m = m.load(fname, check=True, model_ws=str(function_tmpdir)) + m = m.load(fname, check=True, model_ws=function_tmpdir) # assert disu, lpf, bas packages have been loaded msg = "flopy failed on loading mfusg disu package" @@ -172,15 +172,15 @@ def test_usg_load_01B(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): def test_usg_load_45usg(function_tmpdir, example_data_path): print("testing 3-layer unstructured mfusg model loading: 45usg.nam") - pthusgtest = str(example_data_path / "mfusg_test" / "45usg") + pthusgtest = example_data_path / "mfusg_test" / "45usg" fname = os.path.abspath(os.path.join(pthusgtest, "45usg.nam")) assert os.path.isfile(fname), f"nam file not found {fname}" # Create the model - m = MfUsg(modelname="45usg", verbose=True, model_ws=str(function_tmpdir)) + m = MfUsg(modelname="45usg", verbose=True, model_ws=function_tmpdir) # Load the model, with checking. - m = m.load(fname, check=True, model_ws=str(function_tmpdir)) + m = m.load(fname, check=True, model_ws=function_tmpdir) # assert disu, lpf, bas packages have been loaded msg = "flopy failed on loading mfusg disu package" @@ -208,12 +208,10 @@ def test_usg_rch_evt_models01(function_tmpdir, mfusg_rch_evt_model_path): ) nam = "usg_rch_evt.nam" - m = MfUsg.load( - nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=mfusg_rch_evt_model_path, exe_name="mfusg") m.riv.check() - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -228,11 +226,9 @@ def test_usg_rch_evt_models02(function_tmpdir, mfusg_rch_evt_model_path): ) nam = "usg_rch_evt_nrchop2.nam" - m = MfUsg.load( - nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=mfusg_rch_evt_model_path, exe_name="mfusg") - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -248,11 +244,9 @@ def test_usg_rch_evt_models02a(function_tmpdir, mfusg_rch_evt_model_path): ) nam = "usg_rch_evt_nrchop2a.nam" - m = MfUsg.load( - nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=mfusg_rch_evt_model_path, exe_name="mfusg") - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -266,17 +260,17 @@ def test_usg_ss_to_tr(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): nam = "flow.nam" m = MfUsg.load( nam, - model_ws=str(mfusg_01A_nestedgrid_nognc_model_path), + model_ws=mfusg_01A_nestedgrid_nognc_model_path, exe_name="mfusg", ) - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.disu.steady = [False] m.write_input() success, buff = m.run_model() assert success - m = MfUsg.load(nam, model_ws=str(function_tmpdir), exe_name="mfusg") + m = MfUsg.load(nam, model_ws=function_tmpdir, exe_name="mfusg") success, buff = m.run_model() assert success @@ -287,11 +281,9 @@ def test_usg_str(function_tmpdir, mfusg_rch_evt_model_path): print("testing unstructured mfusg with STR: usg_rch_evt_str.nam") nam = "usg_rch_evt_str.nam" - m = MfUsg.load( - nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=mfusg_rch_evt_model_path, exe_name="mfusg") - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -303,11 +295,9 @@ def test_usg_lak(function_tmpdir, mfusg_rch_evt_model_path): print("testing unstructured mfusg with LAK: usg_rch_evt_lak.nam") nam = "usg_rch_evt_lak.nam" - m = MfUsg.load( - nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=mfusg_rch_evt_model_path, exe_name="mfusg") - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -319,11 +309,9 @@ def test_usg_hfb(function_tmpdir, mfusg_rch_evt_model_path): print("testing unstructured mfusg with HFB6: usg_rch_evt_hfb.nam") nam = "usg_rch_evt_hfb.nam" - m = MfUsg.load( - nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=mfusg_rch_evt_model_path, exe_name="mfusg") - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -338,11 +326,9 @@ def test_freyburg_usg(function_tmpdir, freyberg_usg_model_path): print("testing usg nrchop 3: freyburg.usg.nam") nam = "freyberg.usg.nam" - m = MfUsg.load( - nam, model_ws=str(freyberg_usg_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=freyberg_usg_model_path, exe_name="mfusg") - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() success, buff = m.run_model() assert success @@ -357,11 +343,9 @@ def test_freyburg_usg_external(function_tmpdir, freyberg_usg_model_path): print("testing usg external files: freyburg.usg.nam") nam = "freyberg.usg.nam" - m = MfUsg.load( - nam, model_ws=str(freyberg_usg_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=freyberg_usg_model_path, exe_name="mfusg") # convert to all open/close - ext_model_ws = str(function_tmpdir) + ext_model_ws = function_tmpdir m.external_path = "." # reduce nper to speed this test up a bit m.disu.nper = 3 @@ -379,9 +363,7 @@ def test_flat_array_to_util3d_usg(function_tmpdir, freyberg_usg_model_path): print("testing usg flat arrays to layer property constructor") nam = "freyberg.usg.nam" - m = MfUsg.load( - nam, model_ws=str(freyberg_usg_model_path), exe_name="mfusg" - ) + m = MfUsg.load(nam, model_ws=freyberg_usg_model_path, exe_name="mfusg") custom_array = m.lpf.hk.array @@ -396,7 +378,7 @@ def test_flat_array_to_util3d_usg(function_tmpdir, freyberg_usg_model_path): assert (lpf_new.hk[1][:2] == 999.9).all(), msg # ensure we can still write the lpf file - m.model_ws = str(function_tmpdir) + m.model_ws = function_tmpdir m.write_input() @@ -411,12 +393,12 @@ def test_load_usg(function_tmpdir, fpth): m = MfUsg.load( namfile, - model_ws=str(namfile.parent), + model_ws=namfile.parent, verbose=True, check=False, ) assert m, f"Could not load namefile {namfile}" assert m.load_fail is False - m.change_model_ws(str(function_tmpdir)) + m.change_model_ws(function_tmpdir) m.write_input() diff --git a/autotest/test_util_2d_and_3d.py b/autotest/test_util_2d_and_3d.py index 105ca77bab..ea262202fb 100644 --- a/autotest/test_util_2d_and_3d.py +++ b/autotest/test_util_2d_and_3d.py @@ -73,7 +73,7 @@ def test_transient3d(): def test_util2d(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir)) + ml = Modflow(model_ws=function_tmpdir) u2d = Util2d(ml, (10, 10), np.float32, 10.0, "test") a1 = u2d.array a2 = np.ones((10, 10), dtype=np.float32) * 10.0 @@ -82,40 +82,40 @@ def test_util2d(function_tmpdir): # test external filenames - ascii and binary ascii = function_tmpdir / "test_a.dat" bin = function_tmpdir / "test_b.dat" - np.savetxt(str(ascii), a1, fmt="%15.6E") - u2d.write_bin(a1.shape, str(bin), a1, bintype="head") + np.savetxt(ascii, a1, fmt="%15.6E") + u2d.write_bin(a1.shape, bin, a1, bintype="head") dis = ModflowDis(ml, 2, 10, 10) - lpf = ModflowLpf(ml, hk=[str(ascii), str(bin)]) + lpf = ModflowLpf(ml, hk=[ascii, bin]) ml.lpf.hk[1].fmtin = "(BINARY)" assert np.array_equal(lpf.hk[0].array, a1) assert np.array_equal(lpf.hk[1].array, a1) # test external filenames - ascii and binary with model_ws and external_path ml = Modflow( - model_ws=str(function_tmpdir), - external_path=str(function_tmpdir / "ref"), + model_ws=function_tmpdir, + external_path=function_tmpdir / "ref", ) u2d = Util2d(ml, (10, 10), np.float32, 10.0, "test") ascii = function_tmpdir / "test_a.dat" bin = function_tmpdir / "test_b.dat" - np.savetxt(str(ascii), a1, fmt="%15.6E") - u2d.write_bin(a1.shape, str(bin), a1, bintype="head") + np.savetxt(ascii, a1, fmt="%15.6E") + u2d.write_bin(a1.shape, bin, a1, bintype="head") dis = ModflowDis(ml, 2, 10, 10) - lpf = ModflowLpf(ml, hk=[str(ascii), str(bin)]) + lpf = ModflowLpf(ml, hk=[ascii, bin]) ml.lpf.hk[1].fmtin = "(BINARY)" assert np.array_equal(lpf.hk[0].array, a1) assert np.array_equal(lpf.hk[1].array, a1) # bin read write test bin = function_tmpdir / "test.bin" - u2d.write_bin((10, 10), str(bin), u2d.array) - a3 = u2d.load_bin((10, 10), str(bin), u2d.dtype)[1] + u2d.write_bin((10, 10), bin, u2d.array) + a3 = u2d.load_bin((10, 10), bin, u2d.dtype)[1] assert np.array_equal(a3, a1) # ascii read write test ascii = function_tmpdir / "text.dat" - u2d.write_txt((10, 10), str(ascii), u2d.array) - a4 = u2d.load_txt((10, 10), str(ascii), u2d.dtype, "(FREE)") + u2d.write_txt((10, 10), ascii, u2d.array) + a4 = u2d.load_txt((10, 10), ascii, u2d.dtype, "(FREE)") assert np.array_equal(a1, a4) # fixed format read/write with touching numbers - yuck! @@ -256,7 +256,7 @@ def stress_util2d_for_joe_the_file_king(ml, nlay, nrow, ncol): def test_util2d_external_free(function_tmpdir): - ws = str(function_tmpdir) + ws = function_tmpdir ml = Modflow(model_ws=ws) stress_util2d(ws, ml, 1, 1, 1) stress_util2d(ws, ml, 10, 1, 1) @@ -269,7 +269,7 @@ def test_util2d_external_free(function_tmpdir): def test_util2d_external_free_path(function_tmpdir): - ws = str(function_tmpdir) + ws = function_tmpdir ml = Modflow(model_ws=ws, external_path="ref") stress_util2d(ws, ml, 1, 1, 1) @@ -283,7 +283,7 @@ def test_util2d_external_free_path(function_tmpdir): def test_util2d_external_free_path_a(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir), external_path="ref") + ml = Modflow(model_ws=function_tmpdir, external_path="ref") stress_util2d_for_joe_the_file_king(ml, 1, 1, 1) stress_util2d_for_joe_the_file_king(ml, 10, 1, 1) @@ -296,7 +296,7 @@ def test_util2d_external_free_path_a(function_tmpdir): def test_util2d_external_fixed(function_tmpdir): - ws = str(function_tmpdir) + ws = function_tmpdir ml = Modflow(model_ws=ws) ml.array_free_format = False @@ -312,7 +312,7 @@ def test_util2d_external_fixed(function_tmpdir): @pytest.mark.slow def test_util2d_external_fixed_path(function_tmpdir): - ws = str(function_tmpdir) + ws = function_tmpdir ml = Modflow(model_ws=ws, external_path="ref") ml.array_free_format = False @@ -327,7 +327,7 @@ def test_util2d_external_fixed_path(function_tmpdir): def test_util3d(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir)) + ml = Modflow(model_ws=function_tmpdir) u3d = Util3d(ml, (10, 10, 10), np.float32, 10.0, "test") a1 = u3d.array a2 = np.ones((10, 10, 10), dtype=np.float32) * 10.0 @@ -347,7 +347,7 @@ def test_util3d(function_tmpdir): def test_arrayformat(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir)) + ml = Modflow(model_ws=function_tmpdir) u2d = Util2d(ml, (15, 2), np.float32, np.ones((15, 2)), "test") fmt_fort = u2d.format.fortran @@ -402,7 +402,7 @@ def test_arrayformat(function_tmpdir): def test_new_get_file_entry(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir)) + ml = Modflow(model_ws=function_tmpdir) u2d = Util2d(ml, (5, 2), np.float32, np.ones((5, 2)), "test", locat=99) print(u2d.get_file_entry(how="internal")) print(u2d.get_file_entry(how="constant")) @@ -424,7 +424,7 @@ def test_new_get_file_entry(function_tmpdir): def test_append_mflist(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir)) + ml = Modflow(model_ws=function_tmpdir) dis = ModflowDis(ml, 10, 10, 10, 10) sp_data1 = {3: [1, 1, 1, 1.0], 5: [1, 2, 4, 4.0]} sp_data2 = {0: [1, 1, 3, 3.0], 8: [9, 2, 4, 4.0]} @@ -441,7 +441,7 @@ def test_append_mflist(function_tmpdir): @requires_pkg("pandas") def test_mflist(function_tmpdir, example_data_path): - model = Modflow(model_ws=str(function_tmpdir)) + model = Modflow(model_ws=function_tmpdir) dis = ModflowDis(model, 10, 10, 10, 10) sp_data = { 0: [[1, 1, 1, 1.0], [1, 1, 2, 2.0], [1, 1, 3, 3.0]], @@ -486,7 +486,7 @@ def test_mflist(function_tmpdir, example_data_path): assert np.array_equal(sp_data[9], model.wel.stress_period_data[1]) model = Modflow.load( - str(example_data_path / "mf2005_test" / "swi2ex4sww.nam"), + example_data_path / "mf2005_test" / "swi2ex4sww.nam", check=False, verbose=True, ) @@ -587,7 +587,7 @@ def test_mflist(function_tmpdir, example_data_path): def test_how(function_tmpdir): - ml = Modflow(model_ws=str(function_tmpdir)) + ml = Modflow(model_ws=function_tmpdir) ml.array_free_format = False dis = ModflowDis(ml, nlay=2, nrow=10, ncol=10) @@ -630,7 +630,7 @@ def test_mflist_fromfile(function_tmpdir): nwt_model = Modflow( "nwt_testmodel", verbose=True, - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis = ModflowDis( nwt_model, diff --git a/autotest/test_uzf.py b/autotest/test_uzf.py index ca4e0295a7..5c83df6c36 100644 --- a/autotest/test_uzf.py +++ b/autotest/test_uzf.py @@ -38,7 +38,7 @@ def options_path(example_data_path): def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): # copy the test files - ws = str(function_tmpdir) + ws = function_tmpdir for f in mf2005_test_path.glob("UZFtest2.*"): shutil.copy(f, ws) @@ -65,7 +65,7 @@ def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): f for i, f in enumerate(m.external_output) if not rm[i] ] - datpth = str(uzf_test_path) + datpth = uzf_test_path irnbndpth = os.path.join(datpth, "irunbnd.dat") irunbnd = np.loadtxt(irnbndpth) @@ -167,7 +167,7 @@ def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): version="mf2005", exe_name="mf2005", verbose=True, - model_ws=str(mf2005_test_path), + model_ws=mf2005_test_path, forgive=False, ) # verify that all of the arrays in the created UZF package are the same @@ -191,8 +191,8 @@ def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): # load in the test problem m = Modflow("UZFtest2", model_ws=ws, verbose=True) - dis = ModflowDis.load(str(mf2005_test_path / "UZFtest2.dis"), m) - uzf = ModflowUzf1.load(str(mf2005_test_path / "UZFtest2.uzf"), m) + dis = ModflowDis.load(mf2005_test_path / "UZFtest2.dis", m) + uzf = ModflowUzf1.load(mf2005_test_path / "UZFtest2.uzf", m) assert np.sum(uzf.iuzfbnd.array) == 116 assert np.array_equal(np.unique(uzf.irunbnd.array), np.arange(9)) assert np.abs(np.sum(uzf.vks.array) / uzf.vks.cnstnt - 116.0) < 1e-5 @@ -227,7 +227,7 @@ def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): assert a == l2[i] # load uzf test problem for nwt model with 'nwt_11_fmt'-style options and 'open/close' array types - tpth = str(uzf_test_path / "load_uzf_for_nwt") + tpth = uzf_test_path / "load_uzf_for_nwt" [ shutil.copy(os.path.join(tpth, f), os.path.join(ws, f)) for f in os.listdir(tpth) @@ -244,7 +244,7 @@ def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): @requires_exe("mfnwt") def test_uzf_surfk(function_tmpdir, uzf_test_path): - ws = str(uzf_test_path) + ws = uzf_test_path uzf_name = "UZFtest4.uzf" dis_name = "UZFtest2.dis" ml = Modflow(modelname="UZFtest4", version="mfnwt") @@ -254,18 +254,18 @@ def test_uzf_surfk(function_tmpdir, uzf_test_path): assert uzf.options.seepsurfk assert abs(np.unique(uzf.surfk.array)[0] - 0.099) < 1e-06 - ml.change_model_ws(str(function_tmpdir)) + ml.change_model_ws(function_tmpdir) dis.write_file() uzf.write_file() ml2 = Modflow(version="mfnwt") dis2 = ModflowDis.load( - os.path.join(str(function_tmpdir), "UZFtest4.dis"), + os.path.join(function_tmpdir, "UZFtest4.dis"), ml2, ext_unit_dict={}, ) uzf2 = ModflowUzf1.load( - os.path.join(str(function_tmpdir), uzf_name), ml2, ext_unit_dict={} + os.path.join(function_tmpdir, uzf_name), ml2, ext_unit_dict={} ) assert uzf2.options.seepsurfk @@ -295,7 +295,7 @@ def test_read_write_nwt_options(function_tmpdir): assert repr(uzfopt) == uzfstr assert repr(sfropt) == sfrstr - ws = str(function_tmpdir) + ws = function_tmpdir welopt.write_options(os.path.join(ws, "welopt.txt")) welopt2.write_options(os.path.join(ws, "welopt2.txt")) uzfopt.write_options(os.path.join(ws, "uzfopt.txt")) @@ -321,13 +321,13 @@ def test_read_write_nwt_options(function_tmpdir): def test_load_write_sfr_option_block(function_tmpdir, options_path): - data_path = str(options_path) + data_path = options_path sfr_name = "sagehen_ob.sfr" ml = Modflow(modelname="optionblock", version="mfnwt", verbose=False) dis = ModflowDis.load( - os.path.join(str(data_path), "sagehen.dis"), + os.path.join(data_path, "sagehen.dis"), model=ml, ext_unit_dict={}, check=False, @@ -338,11 +338,11 @@ def test_load_write_sfr_option_block(function_tmpdir, options_path): ) sfr_name2 = "sagehen_ob2.sfr" - sfr.write_file(filename=os.path.join(str(function_tmpdir), sfr_name2)) + sfr.write_file(filename=os.path.join(function_tmpdir, sfr_name2)) ml.remove_package("SFR") sfr2 = ModflowSfr2.load( - os.path.join(str(function_tmpdir), sfr_name2), + os.path.join(function_tmpdir, sfr_name2), ml, nper=2, ext_unit_dict={}, @@ -359,11 +359,11 @@ def test_load_write_sfr_option_block(function_tmpdir, options_path): sfr2.options.strhc1kh = False sfr2.options.strhc1kv = False - sfr2.write_file(os.path.join(str(function_tmpdir), sfr_name2)) + sfr2.write_file(os.path.join(function_tmpdir, sfr_name2)) ml.remove_package("SFR") sfr3 = ModflowSfr2.load( - os.path.join(str(function_tmpdir), sfr_name2), + os.path.join(function_tmpdir, sfr_name2), ml, nper=2, ext_unit_dict={}, @@ -374,7 +374,7 @@ def test_load_write_sfr_option_block(function_tmpdir, options_path): def test_load_write_sfr_option_line(function_tmpdir, options_path): - data_path = str(options_path) + data_path = options_path sfr_name = "sagehen.sfr" # test with modflow-nwt @@ -392,11 +392,11 @@ def test_load_write_sfr_option_line(function_tmpdir, options_path): ) sfr_name2 = "sagehen2.sfr" - sfr.write_file(os.path.join(str(function_tmpdir), sfr_name2)) + sfr.write_file(os.path.join(function_tmpdir, sfr_name2)) ml.remove_package("SFR") sfr2 = ModflowSfr2.load( - os.path.join(str(function_tmpdir), sfr_name2), + os.path.join(function_tmpdir, sfr_name2), ml, nper=2, ext_unit_dict={}, @@ -422,11 +422,11 @@ def test_load_write_sfr_option_line(function_tmpdir, options_path): ) sfr_name2 = "sagehen2.sfr" - sfr.write_file(os.path.join(str(function_tmpdir), sfr_name2)) + sfr.write_file(os.path.join(function_tmpdir, sfr_name2)) ml.remove_package("SFR") sfr2 = ModflowSfr2.load( - os.path.join(str(function_tmpdir), sfr_name2), + os.path.join(function_tmpdir, sfr_name2), ml, nper=2, ext_unit_dict={}, @@ -436,7 +436,7 @@ def test_load_write_sfr_option_line(function_tmpdir, options_path): def test_load_write_uzf_option_block(function_tmpdir, options_path): - data_path = str(options_path) + data_path = options_path uzf_name = "sagehen_ob.uzf" ml = Modflow(modelname="optionblock", version="mfnwt", verbose=False) @@ -453,11 +453,11 @@ def test_load_write_uzf_option_block(function_tmpdir, options_path): ) uzf_name2 = "sagehen_ob2.uzf" - uzf.write_file(os.path.join(str(function_tmpdir), uzf_name2)) + uzf.write_file(os.path.join(function_tmpdir, uzf_name2)) ml.remove_package("UZF") uzf2 = ModflowUzf1.load( - os.path.join(str(function_tmpdir), uzf_name2), + os.path.join(function_tmpdir, uzf_name2), ml, ext_unit_dict=None, check=False, @@ -470,11 +470,11 @@ def test_load_write_uzf_option_block(function_tmpdir, options_path): uzf2.smoothfact = 0.4 - uzf2.write_file(os.path.join(str(function_tmpdir), uzf_name2)) + uzf2.write_file(os.path.join(function_tmpdir, uzf_name2)) ml.remove_package("UZF") uzf3 = ModflowUzf1.load( - os.path.join(str(function_tmpdir), uzf_name2), ml, check=False + os.path.join(function_tmpdir, uzf_name2), ml, check=False ) assert uzf3.options.smoothfact == 0.4 @@ -483,7 +483,7 @@ def test_load_write_uzf_option_block(function_tmpdir, options_path): def test_load_write_uzf_option_line(function_tmpdir, options_path): - data_path = str(options_path) + data_path = options_path uzf_name = "sagehen.uzf" # test with modflow-nwt @@ -504,11 +504,11 @@ def test_load_write_uzf_option_line(function_tmpdir, options_path): assert uzf.options.savefinf uzf_name2 = "sagehen2.uzf" - uzf.write_file(os.path.join(str(function_tmpdir), uzf_name2)) + uzf.write_file(os.path.join(function_tmpdir, uzf_name2)) ml.remove_package("UZF") uzf2 = ModflowUzf1.load( - os.path.join(str(function_tmpdir), uzf_name2), ml, check=False + os.path.join(function_tmpdir, uzf_name2), ml, check=False ) assert uzf2.nosurfleak @@ -519,7 +519,7 @@ def test_load_write_uzf_option_line(function_tmpdir, options_path): def test_load_write_wel_option_block(function_tmpdir, options_path): - ws = str(options_path) + ws = options_path wel_name = "sagehen_ob.wel" ml = Modflow(modelname="optionblock", version="mfnwt", verbose=False) @@ -528,11 +528,11 @@ def test_load_write_wel_option_block(function_tmpdir, options_path): ) wel_name2 = "sagehen_ob2.wel" - wel.write_file(os.path.join(str(function_tmpdir), wel_name2)) + wel.write_file(os.path.join(function_tmpdir, wel_name2)) ml.remove_package("WEL") wel2 = ModflowWel.load( - os.path.join(str(function_tmpdir), wel_name2), + os.path.join(function_tmpdir, wel_name2), ml, nper=2, ext_unit_dict={}, @@ -546,11 +546,11 @@ def test_load_write_wel_option_block(function_tmpdir, options_path): wel2.options.tabfiles = False wel2.phiramp = 0.4 - wel2.write_file(os.path.join(str(function_tmpdir), wel_name2)) + wel2.write_file(os.path.join(function_tmpdir, wel_name2)) ml.remove_package("WEL") wel3 = ModflowWel.load( - os.path.join(str(function_tmpdir), wel_name2), + os.path.join(function_tmpdir, wel_name2), ml, nper=2, ext_unit_dict={}, @@ -563,7 +563,7 @@ def test_load_write_wel_option_block(function_tmpdir, options_path): def test_load_write_wel_option_line(function_tmpdir, options_path): - ws = str(options_path) + ws = options_path wel_name = "sagehen.wel" # test with modflow-nwt @@ -580,11 +580,11 @@ def test_load_write_wel_option_line(function_tmpdir, options_path): wel.iunitramp = 20 wel_name2 = "sagehen2.wel" - wel.write_file(os.path.join(str(function_tmpdir), wel_name2)) + wel.write_file(os.path.join(function_tmpdir, wel_name2)) ml.remove_package("WEL") wel2 = ModflowWel.load( - os.path.join(str(function_tmpdir), wel_name2), + os.path.join(function_tmpdir, wel_name2), ml, nper=2, ext_unit_dict={}, @@ -603,7 +603,7 @@ def test_uzf_negative_iuzfopt(function_tmpdir): modelname="uzf_neg", version="mfnwt", exe_name="mfnwt", - model_ws=str(function_tmpdir), + model_ws=function_tmpdir, ) dis = ModflowDis( ml, @@ -647,7 +647,7 @@ def test_uzf_negative_iuzfopt(function_tmpdir): raise AssertionError("UZF model with -1 iuzfopt failed to run") ml2 = Modflow.load( - "uzf_neg.nam", version="mfnwt", model_ws=str(function_tmpdir) + "uzf_neg.nam", version="mfnwt", model_ws=function_tmpdir ) pet = ml2.uzf.pet.array diff --git a/autotest/test_zonbud_utility.py b/autotest/test_zonbud_utility.py index f08acfe125..57b3a7d49f 100644 --- a/autotest/test_zonbud_utility.py +++ b/autotest/test_zonbud_utility.py @@ -100,12 +100,12 @@ def test_compare2zonebudget(cbc_f, zon_f, zbud_f, rtol): t039 Compare output from zonbud.exe to the budget calculated by zonbud utility using the multilayer transient freyberg model. """ - zba = read_zonebudget_file(str(zbud_f)) + zba = read_zonebudget_file(zbud_f) zonenames = [n for n in zba.dtype.names if "ZONE" in n] times = np.unique(zba["totim"]) - zon = ZoneBudget.read_zone_file(str(zon_f)) - zb = ZoneBudget(str(cbc_f), zon, totim=times, verbose=False) + zon = ZoneBudget.read_zone_file(zon_f) + zb = ZoneBudget(cbc_f, zon, totim=times, verbose=False) fpa = zb.get_budget() for time in times: @@ -138,8 +138,8 @@ def test_zonbud_get_record_names(cbc_f, zon_f): """ t039 Test zonbud get_record_names method """ - zon = ZoneBudget.read_zone_file(str(zon_f)) - zb = ZoneBudget(str(cbc_f), zon, kstpkper=(0, 0)) + zon = ZoneBudget.read_zone_file(zon_f) + zb = ZoneBudget(cbc_f, zon, kstpkper=(0, 0)) recnames = zb.get_record_names() assert len(recnames) > 0, "No record names returned." recnames = zb.get_record_names(stripped=True) @@ -150,10 +150,10 @@ def test_zonbud_aliases(cbc_f, zon_f): """ t039 Test zonbud aliases """ - zon = ZoneBudget.read_zone_file(str(zon_f)) + zon = ZoneBudget.read_zone_file(zon_f) aliases = {1: "Trey", 2: "Mike", 4: "Wilson", 0: "Carini"} zb = ZoneBudget( - str(cbc_f), zon, kstpkper=(0, 1096), aliases=aliases, verbose=True + cbc_f, zon, kstpkper=(0, 1096), aliases=aliases, verbose=True ) bud = zb.get_budget() assert bud[bud["name"] == "FROM_Mike"].shape[0] > 0, "No records returned." @@ -163,9 +163,9 @@ def test_zonbud_to_csv(function_tmpdir, cbc_f, zon_f): """ t039 Test zonbud export to csv file method """ - zon = ZoneBudget.read_zone_file(str(zon_f)) - zb = ZoneBudget(str(cbc_f), zon, kstpkper=[(0, 1094), (0, 1096)]) - f_out = os.path.join(str(function_tmpdir), "test.csv") + zon = ZoneBudget.read_zone_file(zon_f) + zb = ZoneBudget(cbc_f, zon, kstpkper=[(0, 1094), (0, 1096)]) + f_out = function_tmpdir / "test.csv" zb.to_csv(f_out) with open(f_out) as f: lines = f.readlines() @@ -176,8 +176,8 @@ def test_zonbud_math(cbc_f, zon_f): """ t039 Test zonbud math methods """ - zon = ZoneBudget.read_zone_file(str(zon_f)) - cmd = ZoneBudget(str(cbc_f), zon, kstpkper=(0, 1096)) + zon = ZoneBudget.read_zone_file(zon_f) + cmd = ZoneBudget(cbc_f, zon, kstpkper=(0, 1096)) cmd / 35.3147 cmd * 12.0 cmd + 1e6 @@ -188,8 +188,8 @@ def test_zonbud_copy(cbc_f, zon_f): """ t039 Test zonbud copy """ - zon = ZoneBudget.read_zone_file(str(zon_f)) - cfd = ZoneBudget(str(cbc_f), zon, kstpkper=(0, 1096)) + zon = ZoneBudget.read_zone_file(zon_f) + cfd = ZoneBudget(cbc_f, zon, kstpkper=(0, 1096)) cfd2 = cfd.copy() assert cfd is not cfd2, "Copied object is a shallow copy." @@ -199,30 +199,26 @@ def test_zonbud_readwrite_zbarray(function_tmpdir): t039 Test zonbud read write """ x = np.random.randint(100, 200, size=(5, 150, 200)) + ZoneBudget.write_zone_file(function_tmpdir / "randint", x) ZoneBudget.write_zone_file( - os.path.join(str(function_tmpdir), "randint"), x - ) - ZoneBudget.write_zone_file( - os.path.join(str(function_tmpdir), "randint"), x, fmtin=35, iprn=2 - ) - z = ZoneBudget.read_zone_file( - os.path.join(str(function_tmpdir), "randint") + function_tmpdir / "randint", x, fmtin=35, iprn=2 ) + z = ZoneBudget.read_zone_file(function_tmpdir / "randint") assert np.array_equal(x, z), "Input and output arrays do not match." @requires_pkg("pandas") def test_dataframes(cbc_f, zon_f): - zon = ZoneBudget.read_zone_file(str(zon_f)) - cmd = ZoneBudget(str(cbc_f), zon, totim=1095.0) + zon = ZoneBudget.read_zone_file(zon_f) + cmd = ZoneBudget(cbc_f, zon, totim=1095.0) df = cmd.get_dataframes() assert len(df) > 0, "Output DataFrames empty." def test_get_budget(cbc_f, zon_f): - zon = ZoneBudget.read_zone_file(str(zon_f)) + zon = ZoneBudget.read_zone_file(zon_f) aliases = {1: "Trey", 2: "Mike", 4: "Wilson", 0: "Carini"} - zb = ZoneBudget(str(cbc_f), zon, kstpkper=(0, 0), aliases=aliases) + zb = ZoneBudget(cbc_f, zon, kstpkper=(0, 0), aliases=aliases) zb.get_budget(names="FROM_CONSTANT_HEAD", zones=1) zb.get_budget(names=["FROM_CONSTANT_HEAD"], zones=[1, 2]) zb.get_budget(net=True) @@ -230,8 +226,8 @@ def test_get_budget(cbc_f, zon_f): def test_get_model_shape(cbc_f, zon_f): ZoneBudget( - str(cbc_f), - ZoneBudget.read_zone_file(str(zon_f)), + cbc_f, + ZoneBudget.read_zone_file(zon_f), kstpkper=(0, 0), verbose=True, ).get_model_shape() @@ -243,7 +239,7 @@ def test_zonbud_active_areas_zone_zero(loadpth, cbc_f, rtol): import pandas as pd # Read ZoneBudget executable output and reformat - zbud_f = os.path.join(str(loadpth), "zonef_mlt_active_zone_0.2.csv") + zbud_f = loadpth / "zonef_mlt_active_zone_0.2.csv" zbud = pd.read_csv(zbud_f) zbud.columns = [c.strip() for c in zbud.columns] zbud.columns = ["_".join(c.split()) for c in zbud.columns] @@ -252,9 +248,9 @@ def test_zonbud_active_areas_zone_zero(loadpth, cbc_f, rtol): zbud = zbud[cols] # Run ZoneBudget utility and reformat output - zon_f = os.path.join(str(loadpth), "zonef_mlt_active_zone_0.zbr") + zon_f = loadpth / "zonef_mlt_active_zone_0.zbr" zon = ZoneBudget.read_zone_file(zon_f) - zb = ZoneBudget(str(cbc_f), zon, kstpkper=(0, 1096)) + zb = ZoneBudget(cbc_f, zon, kstpkper=(0, 1096)) fpbud = zb.get_dataframes().reset_index() fpbud = fpbud[["name"] + [c for c in fpbud.columns if "ZONE" in c]] fpbud = fpbud.set_index("name").T @@ -278,7 +274,7 @@ def test_read_zone_file(function_tmpdir): " 0 1 1 1\n" " 0" ) - name = os.path.join(str(function_tmpdir), "zonefiletest.txt") + name = function_tmpdir / "zonefiletest.txt" with open(name, "w") as foo: foo.write(zf) zones = ZoneBudget.read_zone_file(name) @@ -296,21 +292,21 @@ def test_zonebudget_6(function_tmpdir, example_data_path): zb_exe_name = "zbud6" sim_ws = example_data_path / "mf6" / "test001e_UZF_3lay" - sim = MFSimulation.load(sim_ws=str(sim_ws), exe_name=exe_name) - sim.simulation_data.mfpath.set_sim_path(str(function_tmpdir)) + sim = MFSimulation.load(sim_ws=sim_ws, exe_name=exe_name) + sim.simulation_data.mfpath.set_sim_path(function_tmpdir) sim.write_simulation() success, _ = sim.run_simulation() - grb_file = os.path.join(str(function_tmpdir), "test001e_UZF_3lay.dis.grb") - cbc_file = os.path.join(str(function_tmpdir), "test001e_UZF_3lay.cbc") + grb_file = function_tmpdir / "test001e_UZF_3lay.dis.grb" + cbc_file = function_tmpdir / "test001e_UZF_3lay.cbc" ml = sim.get_model("gwf_1") idomain = np.ones(ml.modelgrid.shape, dtype=int) - zb = ZoneBudget6(model_ws=str(function_tmpdir), exe_name=zb_exe_name) + zb = ZoneBudget6(model_ws=function_tmpdir, exe_name=zb_exe_name) zf = ZoneFile6(zb, idomain) - zb.grb = grb_file - zb.cbc = cbc_file + zb.grb = str(grb_file) + zb.cbc = str(cbc_file) zb.write_input(line_length=21) success, _ = zb.run_model() @@ -321,7 +317,7 @@ def test_zonebudget_6(function_tmpdir, example_data_path): assert isinstance(df, pd.DataFrame) zb_pkg = ml.uzf.output.zonebudget(idomain) - zb_pkg.change_model_ws(str(function_tmpdir)) + zb_pkg.change_model_ws(function_tmpdir) zb_pkg.name = "uzf_zonebud" zb_pkg.write_input() success, _ = zb_pkg.run_model(exe_name=zb_exe_name) @@ -333,10 +329,10 @@ def test_zonebudget_6(function_tmpdir, example_data_path): assert isinstance(df, pd.DataFrame) # test aliases - zb = ZoneBudget6(model_ws=str(function_tmpdir), exe_name=zb_exe_name) + zb = ZoneBudget6(model_ws=function_tmpdir, exe_name=zb_exe_name) zf = ZoneFile6(zb, idomain, aliases={1: "test alias", 2: "test pop"}) - zb.grb = grb_file - zb.cbc = cbc_file + zb.grb = str(grb_file) + zb.cbc = str(cbc_file) zb.write_input(line_length=5) success, _ = zb.run_model() @@ -354,8 +350,8 @@ def test_zonebudget6_from_output_method(function_tmpdir, example_data_path): zb_exe_name = "zbud6" sim_ws = example_data_path / "mf6" / "test001e_UZF_3lay" - sim = MFSimulation.load(sim_ws=str(sim_ws), exe_name=exe_name) - sim.simulation_data.mfpath.set_sim_path(str(function_tmpdir)) + sim = MFSimulation.load(sim_ws=sim_ws, exe_name=exe_name) + sim.simulation_data.mfpath.set_sim_path(function_tmpdir) sim.write_simulation() success, _ = sim.run_simulation() diff --git a/examples/Tutorials/modflow6data/tutorial08_mf6_data.py b/examples/Tutorials/modflow6data/tutorial08_mf6_data.py index 601434cb3b..684cecc6a7 100644 --- a/examples/Tutorials/modflow6data/tutorial08_mf6_data.py +++ b/examples/Tutorials/modflow6data/tutorial08_mf6_data.py @@ -263,8 +263,10 @@ # unless either the data or the file path has changed. # store lak period data in external text files -period = {0: {"filename": "lak_sp1.txt", "data": [(0, "STAGE", 10.0)]}, - 1: {"filename": "lak_sp2.txt", "data": [(0, "STAGE", 15.0)]}} +period = { + 0: {"filename": "lak_sp1.txt", "data": [(0, "STAGE", 10.0)]}, + 1: {"filename": "lak_sp2.txt", "data": [(0, "STAGE", 15.0)]}, +} lakpd = [(0, -2.0, 1)] lakecn = [(0, 0, (0, 1, 0), "HORIZONTAL", 1.0, -5.0, 0.0, 10.0, 10.0)] lak = flopy.mf6.ModflowGwflak( diff --git a/flopy/discretization/structuredgrid.py b/flopy/discretization/structuredgrid.py index b53f56941e..dd2c750dc9 100644 --- a/flopy/discretization/structuredgrid.py +++ b/flopy/discretization/structuredgrid.py @@ -1,6 +1,7 @@ import copy import inspect import os.path +from typing import Union import numpy as np @@ -1707,13 +1708,13 @@ def from_binary_grid_file(cls, file_path, verbose=False): ) @classmethod - def from_gridspec(cls, file_path, lenuni=0): + def from_gridspec(cls, file_path: Union[str, os.PathLike], lenuni=0): """ Instantiate a StructuredGrid from grid specification file. Parameters ---------- - file_path: Path-like + file_path: str or PathLike Path to the grid specification file lenuni: int Length unit code diff --git a/flopy/discretization/unstructuredgrid.py b/flopy/discretization/unstructuredgrid.py index 7877b5555d..38ff1efea4 100644 --- a/flopy/discretization/unstructuredgrid.py +++ b/flopy/discretization/unstructuredgrid.py @@ -1,6 +1,7 @@ import copy import inspect import os +from typing import Union import numpy as np from matplotlib.path import Path @@ -952,13 +953,13 @@ def from_binary_grid_file(cls, file_path, verbose=False): ) @classmethod - def from_gridspec(cls, file_path): + def from_gridspec(cls, file_path: Union[str, os.PathLike]): """ Create an UnstructuredGrid from a grid specification file. Parameters ---------- - file_path : Path-like + file_path : str or PathLike Path to the grid specification file Returns diff --git a/flopy/export/netcdf.py b/flopy/export/netcdf.py index b687e568ee..94fea148ec 100644 --- a/flopy/export/netcdf.py +++ b/flopy/export/netcdf.py @@ -5,6 +5,7 @@ import socket import time from datetime import datetime +from pathlib import Path import numpy as np @@ -152,6 +153,8 @@ def __init__( forgive=False, **kwargs, ): + if isinstance(output_filename, Path): + output_filename = str(output_filename.absolute()) assert output_filename.lower().endswith(".nc") if verbose is None: verbose = model.verbose diff --git a/flopy/export/utils.py b/flopy/export/utils.py index 5fbe64a0a8..053366638e 100644 --- a/flopy/export/utils.py +++ b/flopy/export/utils.py @@ -1,6 +1,9 @@ import os +from pathlib import Path +from typing import Union import numpy as np +import pylab as p from ..datbase import DataInterface, DataListInterface, DataType from ..mbase import BaseModel, ModelInterface @@ -284,14 +287,16 @@ def _add_output_nc_zonebudget_variable(f, array, var_name, flux, logger=None): var[:] = array -def output_helper(f, ml, oudic, **kwargs): +def output_helper( + f: Union[str, os.PathLike, NetCdf, dict], ml, oudic, **kwargs +): """ Export model outputs using the model spatial reference info. Parameters ---------- - f : filepath to write output to (must have .shp or .nc extension) - or NetCDF object or dict + f : str or PathLike or NetCdf or dict + filepath to write output to (must have .shp or .nc extension), NetCDF object, or dictionary ml : flopy.mbase.ModelInterface derived type oudic : dict output_filename,flopy datafile/cellbudgetfile instance @@ -386,6 +391,9 @@ def output_helper(f, ml, oudic, **kwargs): else: print(msg) times = [t for t in common_times[::stride]] + + if isinstance(f, Path): + f = str(f.absolute()) if isinstance(f, str) and f.lower().endswith(".nc"): f = NetCdf( f, ml, time_values=times, logger=logger, forgive=forgive, **kwargs @@ -558,15 +566,16 @@ def output_helper(f, ml, oudic, **kwargs): return f -def model_export(f, ml, fmt=None, **kwargs): +def model_export( + f: Union[str, os.PathLike, NetCdf, dict], ml, fmt=None, **kwargs +): """ Method to export a model to a shapefile or netcdf file Parameters ---------- - f : str - file path (".nc" for netcdf or ".shp" for shapefile) - or NetCDF object or dict + f : str or PathLike or NetCdf or dict + file path (".nc" for netcdf or ".shp" for shapefile) or NetCDF object or dictionary ml : flopy.modflow.mbase.ModelInterface object flopy model object fmt : str @@ -587,6 +596,9 @@ def model_export(f, ml, fmt=None, **kwargs): if package_names is None: package_names = [pak.name[0] for pak in ml.packagelist] + if isinstance(f, Path): + f = str(f.absolute()) + if isinstance(f, str) and f.lower().endswith(".nc"): f = NetCdf(f, ml, **kwargs) @@ -637,15 +649,16 @@ def model_export(f, ml, fmt=None, **kwargs): raise NotImplementedError(f"unrecognized export argument:{f}") -def package_export(f, pak, fmt=None, **kwargs): +def package_export( + f: Union[str, os.PathLike, NetCdf, dict], pak, fmt=None, **kwargs +): """ Method to export a package to shapefile or netcdf Parameters ---------- - f : str - output file path (extension .shp for shapefile or .nc for netcdf) - or NetCDF object or dict + f : str or PathLike or NetCdf or dict + output file path (extension .shp for shapefile or .nc for netcdf) or NetCDF object or dictionary pak : flopy.pakbase.Package object package to export fmt : str @@ -667,6 +680,9 @@ def package_export(f, pak, fmt=None, **kwargs): """ assert isinstance(pak, PackageInterface) + if isinstance(f, Path): + f = str(f.absolute()) + if isinstance(f, str) and f.lower().endswith(".nc"): f = NetCdf(f, pak.parent, **kwargs) @@ -830,13 +846,13 @@ def generic_array_export( return f -def mflist_export(f, mfl, **kwargs): +def mflist_export(f: Union[str, os.PathLike, NetCdf], mfl, **kwargs): """ export helper for MfList instances Parameters ----------- - f : str + f : str or PathLike or NetCdf file path or existing export instance type (NetCdf only for now) mfl : MfList instance **kwargs : keyword arguments @@ -855,6 +871,9 @@ def mflist_export(f, mfl, **kwargs): if "modelgrid" in kwargs: modelgrid = kwargs.pop("modelgrid") + if isinstance(f, Path): + f = str(f.absolute()) + if isinstance(f, str) and f.lower().endswith(".nc"): f = NetCdf(f, mfl.model, **kwargs) diff --git a/flopy/mbase.py b/flopy/mbase.py index 41819be9ab..57c11c1efc 100644 --- a/flopy/mbase.py +++ b/flopy/mbase.py @@ -15,6 +15,7 @@ from datetime import datetime from shutil import which from subprocess import PIPE, STDOUT, Popen +from typing import Union import numpy as np @@ -219,14 +220,7 @@ def _check(self, chk, level=1): Parameters ---------- - f : str or file handle - String defining file name or file handle for summary file - of check method output. If a string is passed a file handle - is created. If f is None, check method does not write - results to a summary file. (default is None) - verbose : bool - Boolean flag used to determine if check method results are - written to the screen + chk : the check object level : int Check method analysis level. If level=0, summary checks are performed. If level=1, full checks are performed. @@ -236,7 +230,7 @@ def _check(self, chk, level=1): Returns ------- - None + Check object Examples -------- @@ -303,9 +297,9 @@ class BaseModel(ModelInterface): Name of the model, which is also used for model file names. namefile_ext : str, default "nam" Name file extension, without "." - exe_name : str, default "mf2005" - Name of the modflow executable. - model_ws : str, optional + exe_name : str or PathLike, default "mf2005" + Path of the modflow executable. + model_ws : str or PathLike, optional Path to the model workspace. Model files will be created in this directory. Default is None, in which case model_ws is assigned to the current working directory. @@ -327,8 +321,8 @@ def __init__( self, modelname="modflowtest", namefile_ext="nam", - exe_name="mf2005", - model_ws=None, + exe_name: Union[str, os.PathLike] = "mf2005", + model_ws: Union[str, os.PathLike] = None, structured=True, verbose=False, **kwargs, @@ -546,15 +540,15 @@ def next_ext_unit(self): self._next_ext_unit += 1 return next_unit - def export(self, f, **kwargs): + def export(self, f: Union[str, os.PathLike], **kwargs): """ Method to export a model to netcdf or shapefile based on the extension of the file name (.shp for shapefile, .nc for netcdf) Parameters ---------- - f : str - filename + f : str or PathLike + The file path kwargs : keyword arguments modelgrid : flopy.discretization.Grid instance user supplied modelgrid which can be used for exporting @@ -693,7 +687,11 @@ def __getattr__(self, item): raise AttributeError(item) def get_ext_dict_attr( - self, ext_unit_dict=None, unit=None, filetype=None, pop_key=True + self, + ext_unit_dict: Union[str, os.PathLike] = None, + unit=None, + filetype=None, + pop_key=True, ): iu = None fname = None @@ -724,7 +722,12 @@ def _output_msg(self, i, add=True): ) def add_output_file( - self, unit, fname=None, extension="cbc", binflag=True, package=None + self, + unit, + fname: Union[str, os.PathLike] = None, + extension="cbc", + binflag=True, + package=None, ): """ Add an ascii or binary output file for a package @@ -732,18 +735,16 @@ def add_output_file( Parameters ---------- unit : int - unit number of external array - fname : str - filename of external array. (default is None) + Unit number of external array + fname : str or PathLike, optional + Path of external array, default is None extension : str - extension to use for the cell-by-cell file. Only used if fname - is None. (default is cbc) + Extension to use for the cell-by-cell file. Only used if fname + is None, default is cbc binflag : bool - boolean flag indicating if the output file is a binary file. - Default is True + Whether the output file is a binary file, efault is True package : str - string that defines the package the output file is attached to. - Default is None + The package the output file is attached to, default is None """ add_cbc = False @@ -787,9 +788,10 @@ def add_output_file( else: fname = os.path.basename(fname) self.add_output(fname, unit, binflag=binflag, package=package) - return - def add_output(self, fname, unit, binflag=False, package=None): + def add_output( + self, fname: Union[str, os.PathLike], unit, binflag=False, package=None + ): """ Assign an external array so that it will be listed as a DATA or DATA(BINARY) entry in the name file. This will allow an outside @@ -830,20 +832,19 @@ def add_output(self, fname, unit, binflag=False, package=None): if self.verbose: self._output_msg(-1, add=True) - return - - def remove_output(self, fname=None, unit=None): + def remove_output( + self, fname: Union[str, os.PathLike, None] = None, unit=None + ): """ Remove an output file from the model by specifying either the file name or the unit number. Parameters ---------- - fname : str - filename of output array - unit : int - unit number of output array - + fname : str or PathLike, optional + Path of output array + unit : int, optional + Unit number of output array """ if fname is not None: for i, e in enumerate(self.output_fnames): @@ -866,20 +867,20 @@ def remove_output(self, fname=None, unit=None): else: msg = " either fname or unit must be passed to remove_output()" raise Exception(msg) - return - def get_output(self, fname=None, unit=None): + def get_output( + self, fname: Union[str, os.PathLike, None] = None, unit=None + ): """ Get an output file from the model by specifying either the file name or the unit number. Parameters ---------- - fname : str - filename of output array - unit : int - unit number of output array - + fname : str or PathLike, optional + Path of output array + unit : int, optional + Unit number of output array """ if fname is not None: for i, e in enumerate(self.output_fnames): @@ -894,9 +895,10 @@ def get_output(self, fname=None, unit=None): else: msg = " either fname or unit must be passed to get_output()" raise Exception(msg) - return - def set_output_attribute(self, fname=None, unit=None, attr=None): + def set_output_attribute( + self, fname: Union[str, os.PathLike, None] = None, unit=None, attr=None + ): """ Set a variable in an output file from the model by specifying either the file name or the unit number and a dictionary with attributes @@ -904,11 +906,10 @@ def set_output_attribute(self, fname=None, unit=None, attr=None): Parameters ---------- - fname : str - filename of output array - unit : int - unit number of output array - + fname : str or PathLike, optional + Path of output array + unit : int, optional + Unit number of output array """ idx = None if fname is not None: @@ -939,18 +940,19 @@ def set_output_attribute(self, fname=None, unit=None, attr=None): self.output_units[idx] = value return - def get_output_attribute(self, fname=None, unit=None, attr=None): + def get_output_attribute( + self, fname: Union[str, os.PathLike, None] = None, unit=None, attr=None + ): """ - Get a attribute for an output file from the model by specifying either + Get an attribute of a model output file by specifying either the file name or the unit number. Parameters ---------- - fname : str - filename of output array - unit : int - unit number of output array - + fname : str or PathLike, optional + path of output array + unit : int, optional + Unit number of output array """ idx = None if fname is not None: @@ -980,21 +982,22 @@ def get_output_attribute(self, fname=None, unit=None, attr=None): v = self.output_units[idx] return v - def add_external(self, fname, unit, binflag=False, output=False): + def add_external( + self, fname: Union[str, os.PathLike], unit, binflag=False, output=False + ): """ Assign an external array so that it will be listed as a DATA or - DATA(BINARY) entry in the name file. This will allow an outside + DATA(BINARY) entry in the name file. This will allow an outside file package to refer to it. Parameters ---------- - fname : str - filename of external array + fname : str or PathLike + Path of external array unit : int - unit number of external array - binflag : boolean - binary or not. (default is False) - + Unit number of external array + binflag : boolean, optional + Binary or not, default is False """ if fname in self.external_fnames: if self.verbose: @@ -1021,20 +1024,20 @@ def add_external(self, fname, unit, binflag=False, output=False): self.external_units.append(unit) self.external_binflag.append(binflag) self.external_output.append(output) - return - def remove_external(self, fname=None, unit=None): + def remove_external( + self, fname: Union[str, os.PathLike, None] = None, unit=None + ): """ Remove an external file from the model by specifying either the file name or the unit number. Parameters ---------- - fname : str - filename of external array - unit : int - unit number of external array - + fname : str or PathLike, optional + Path of external array + unit : int, optional + Unit number of external array """ plist = [] if fname is not None: @@ -1057,10 +1060,12 @@ def remove_external(self, fname=None, unit=None): self.external_binflag.pop(ipos) self.external_output.pop(ipos) j += 1 - return def add_existing_package( - self, filename, ptype=None, copy_to_model_ws=True + self, + filename: Union[str, os.PathLike], + ptype=None, + copy_to_model_ws=True, ): """ Add an existing package to a model instance. @@ -1068,13 +1073,13 @@ def add_existing_package( Parameters ---------- - filename : str - the name of the file to add as a package + filename : str or PathLike + Path of the file to add as a package ptype : optional - the model package type (e.g. "lpf", "wel", etc). If None, + Model package type (e.g. "lpf", "wel", etc). If None then the file extension of the filename arg is used copy_to_model_ws : bool - flag to copy the package file into the model_ws directory. + Copy the package file into the model workspace. Returns ------- @@ -1197,16 +1202,20 @@ def set_version(self, version): return None - def change_model_ws(self, new_pth=None, reset_external=False): + def change_model_ws( + self, + new_pth: Union[str, os.PathLike, None] = os.curdir, + reset_external=False, + ): """ Change the model work space. Parameters ---------- - new_pth : str - Location of new model workspace. If this path does not exist, - it will be created. (default is None, which will be assigned to - the present working directory). + new_pth : str or PathLike + Path of the new model workspace. If this path does not exist, + it will be created. If no value (None) is given, the default + is the present working directory. Returns ------- @@ -1216,7 +1225,7 @@ def change_model_ws(self, new_pth=None, reset_external=False): """ if new_pth is None: - new_pth = os.getcwd() + new_pth = os.curdir if not os.path.exists(new_pth): try: print( @@ -1499,13 +1508,15 @@ def add_pop_key_list(self, key): if key not in self.pop_key_list: self.pop_key_list.append(key) - def check(self, f=None, verbose=True, level=1): + def check( + self, f: Union[str, os.PathLike, None] = None, verbose=True, level=1 + ): """ Check model data for common errors. Parameters ---------- - f : str or file handle + f : str or PathLike String defining file name or file handle for summary file of check method output. If a string is passed a file handle is created. If f is None, check method does not write @@ -1608,7 +1619,9 @@ def plot(self, SelPackList=None, **kwargs): ) return axes - def to_shapefile(self, filename, package_names=None, **kwargs): + def to_shapefile( + self, filename: Union[str, os.PathLike], package_names=None, **kwargs + ): """ Wrapper function for writing a shapefile for the model grid. If package_names is not None, then search through the requested packages @@ -1616,8 +1629,8 @@ def to_shapefile(self, filename, package_names=None, **kwargs): Parameters ---------- - filename : string - name of the shapefile to write + filename : str or PathLike + Path of the shapefile to write package_names : list of package names (e.g. ["dis","lpf"]) Packages to export data arrays to shapefile. (default is None) @@ -1634,13 +1647,12 @@ def to_shapefile(self, filename, package_names=None, **kwargs): """ warnings.warn("to_shapefile() is deprecated. use .export()") self.export(filename, package_names=package_names) - return def run_model( - exe_name, - namefile, - model_ws="./", + exe_name: Union[str, os.PathLike], + namefile: Union[str, os.PathLike], + model_ws: Union[str, os.PathLike] = os.curdir, silent=False, pause=False, report=False, @@ -1655,15 +1667,15 @@ def run_model( Parameters ---------- - exe_name : str - Executable name (with path, if necessary) to run. - namefile : str - Namefile of model to run. The namefile must be the + exe_name : str or PathLike + Executable name (or path, if necessary) to run. + namefile : str or PathLike + Path to the namefile of model to run. The namefile must be the filename of the namefile without the path. Namefile can be None to allow programs that do not require a control file (name file) to be passed as a command line argument. - model_ws : str - Path to the location of the namefile. (default is the + model_ws : str or PathLike + Path to the parent directory of the namefile. (default is the current working directory - './') silent : boolean Echo run information to screen (default is True). @@ -1734,7 +1746,7 @@ def q_output(output, q): # create a list of arguments to pass to Popen argv = [exe_name] if namefile is not None: - argv.append(namefile) + argv.append(str(namefile)) # add additional arguments to Popen arguments if cargs is not None: diff --git a/flopy/modflow/mf.py b/flopy/modflow/mf.py index 9da0ae23a8..2a49839627 100644 --- a/flopy/modflow/mf.py +++ b/flopy/modflow/mf.py @@ -7,6 +7,7 @@ import os import warnings from inspect import getfullargspec +from typing import Union import flopy @@ -648,11 +649,11 @@ def load_results(self, **kwargs): @classmethod def load( cls, - f, + f: Union[str, os.PathLike], version="mf2005", exe_name="mf2005", verbose=False, - model_ws=".", + model_ws: Union[str, os.PathLike] = os.curdir, load_only=None, forgive=False, check=True, @@ -662,7 +663,7 @@ def load( Parameters ---------- - f : str + f : str or PathLike Path to MODFLOW name file to load. version : str, default "mf2005" MODFLOW version. Choose one of: "mf2k", "mf2005" (default), @@ -672,7 +673,7 @@ def load( MODFLOW executable name. verbose : bool, default False Show messages that can be useful for debugging. - model_ws : str, default "." + model_ws : str or PathLike, default "." Model workspace path. Default is the current directory. load_only : list, str or None List of case insensitive packages to load, e.g. ["bas6", "lpf"]. diff --git a/flopy/utils/compare.py b/flopy/utils/compare.py index 4b20296413..c9ecd38141 100644 --- a/flopy/utils/compare.py +++ b/flopy/utils/compare.py @@ -1,8 +1,11 @@ import os import textwrap +from typing import List, Union import numpy as np +from flopy.modflow import ModflowOc +from flopy.utils import FormattedHeadFile, HeadFile, HeadUFile from flopy.utils.mfreadnam import get_entries_from_namefile @@ -474,18 +477,18 @@ def compare_swrbudget( def compare_heads( - namefile1, - namefile2, + namefile1: Union[str, os.PathLike, None], + namefile2: Union[str, os.PathLike, None], precision="auto", text="head", text2=None, htol=0.001, - outfile=None, - files1=None, - files2=None, + outfile: Union[str, os.PathLike, None] = None, + files1: Union[str, os.PathLike, List[Union[str, os.PathLike]]] = None, + files2: Union[str, os.PathLike, List[Union[str, os.PathLike]]] = None, difftol=False, verbose=False, - exfile=None, + exfile: Union[str, os.PathLike, None] = None, exarr=None, maxerr=None, ): @@ -493,24 +496,24 @@ def compare_heads( Parameters ---------- - namefile1 : str + namefile1 : str or PathLike namefile path for base model - namefile2 : str + namefile2 : str or PathLike namefile path for comparison model precision : str precision for binary head file ("auto", "single", or "double") default is "auto" htol : float maximum allowed head difference (default is 0.001) - outfile : str + outfile : str or PathLike head comparison output file name. If outfile is None, no comparison output is saved. (default is None) - files1 : str - base model output file. If files1 is not None, results + files1 : str or PathLike, or List of str or PathLike + base model output files. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None) - files2 : str - comparison model output file. If files2 is not None, results + files2 : str or PathLike, or List of str or PathLike + comparison model output files. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None) difftol : bool @@ -519,7 +522,7 @@ def compare_heads( verbose : bool boolean indicating if verbose output should be written to the terminal (default is False) - exfile : str + exfile : str or PathLike path to a file with exclusion array data. Head differences will not be evaluated where exclusion array values are greater than zero. (default is None) @@ -537,11 +540,6 @@ def compare_heads( boolean indicating if the head differences are less than htol. """ - try: - import flopy - except: - msg = "flopy not available - cannot use compare_heads" - raise ValueError(msg) if text2 is None: text2 = text @@ -557,9 +555,7 @@ def compare_heads( if not any(ocf1) is None: return True - hu1, hfpth1, du1, _ = flopy.modflow.ModflowOc.get_ocoutput_units( - ocf1[0][0] - ) + hu1, hfpth1, du1, _ = ModflowOc.get_ocoutput_units(ocf1[0][0]) if text.lower() == "head": iut = hu1 elif text.lower() == "drawdown": @@ -601,9 +597,7 @@ def compare_heads( if not any(ocf2): return True - hu2, hfpth2, du2, dfpth2 = flopy.modflow.ModflowOc.get_ocoutput_units( - ocf2[0][0] - ) + hu2, hfpth2, du2, dfpth2 = ModflowOc.get_ocoutput_units(ocf2[0][0]) if text.lower() == "head": iut = hu2 elif text.lower() == "drawdown": @@ -709,7 +703,7 @@ def compare_heads( status1 = status1.upper() unstructured1 = False if status1 == dbs: - headobj1 = flopy.utils.HeadFile( + headobj1 = HeadFile( hfpth1, precision=precision, verbose=verbose, text=text ) txt = headobj1.recordarray["text"][0] @@ -717,18 +711,14 @@ def compare_heads( txt = txt.decode("utf-8") if "HEADU" in txt: unstructured1 = True - headobj1 = flopy.utils.HeadUFile( - hfpth1, precision=precision, verbose=verbose - ) + headobj1 = HeadUFile(hfpth1, precision=precision, verbose=verbose) else: - headobj1 = flopy.utils.FormattedHeadFile( - hfpth1, verbose=verbose, text=text - ) + headobj1 = FormattedHeadFile(hfpth1, verbose=verbose, text=text) status2 = status2.upper() unstructured2 = False if status2 == dbs: - headobj2 = flopy.utils.HeadFile( + headobj2 = HeadFile( hfpth2, precision=precision, verbose=verbose, text=text2 ) txt = headobj2.recordarray["text"][0] @@ -736,13 +726,9 @@ def compare_heads( txt = txt.decode("utf-8") if "HEADU" in txt: unstructured2 = True - headobj2 = flopy.utils.HeadUFile( - hfpth2, precision=precision, verbose=verbose - ) + headobj2 = HeadUFile(hfpth2, precision=precision, verbose=verbose) else: - headobj2 = flopy.utils.FormattedHeadFile( - hfpth2, verbose=verbose, text=text2 - ) + headobj2 = FormattedHeadFile(hfpth2, verbose=verbose, text=text2) # get times times1 = headobj1.get_times() @@ -955,7 +941,7 @@ def compare_concentrations( if ufpth1 is None: ufpth1 = os.path.join(os.path.dirname(namefile1), "MT3D001.UCN") else: - if isinstance(files1, str): + if isinstance(files1, (str, os.PathLike)): files1 = [files1] for file in files1: for ext in valid_ext: @@ -975,7 +961,7 @@ def compare_concentrations( if ufpth2 is None: ufpth2 = os.path.join(os.path.dirname(namefile2), "MT3D001.UCN") else: - if isinstance(files2, str): + if isinstance(files2, (str, os.PathLike)): files2 = [files2] for file in files2: for ext in valid_ext: diff --git a/flopy/utils/mfreadnam.py b/flopy/utils/mfreadnam.py index 5dc78a403e..27c34963b2 100644 --- a/flopy/utils/mfreadnam.py +++ b/flopy/utils/mfreadnam.py @@ -10,7 +10,7 @@ import os from os import PathLike from pathlib import Path, PurePosixPath, PureWindowsPath -from typing import List, Tuple +from typing import List, Tuple, Union class NamData: @@ -272,14 +272,17 @@ def attribs_from_namfile_header(namefile): def get_entries_from_namefile( - path: PathLike, ftype: str = None, unit: int = None, extension: str = None + path: Union[str, PathLike], + ftype: str = None, + unit: int = None, + extension: str = None, ) -> List[Tuple]: """Get entries from an MF6 namefile. Can select using FTYPE, UNIT, or file extension. This function only supports MF6 namefiles. Parameters ---------- - path : str + path : str or PathLike path to a MODFLOW-based model name file ftype : str package type diff --git a/flopy/utils/rasters.py b/flopy/utils/rasters.py index aa223f5185..dbba705108 100644 --- a/flopy/utils/rasters.py +++ b/flopy/utils/rasters.py @@ -1,4 +1,6 @@ +import os import warnings +from typing import Union import numpy as np @@ -737,18 +739,19 @@ def write(self, name): foo.write(arr, band) @staticmethod - def load(raster): + def load(raster: Union[str, os.PathLike]): """ Static method to load a raster file into the raster object Parameters ---------- - raster : str + raster : str or PathLike + The path to the raster file Returns ------- - Raster object + A Raster object """ rasterio = import_optional_dependency("rasterio") diff --git a/flopy/utils/util_array.py b/flopy/utils/util_array.py index 95574b9450..2fe0d8cc4e 100644 --- a/flopy/utils/util_array.py +++ b/flopy/utils/util_array.py @@ -2745,9 +2745,9 @@ def parse_value(self, value): raise Exception( "Util2d:value type is bool, but dtype not set as bool" ) - elif isinstance(value, str): + elif isinstance(value, (str, os.PathLike)): if os.path.exists(value): - self.__value = value + self.__value = str(value) return elif self.dtype == np.int32: try: diff --git a/flopy/utils/zonbud.py b/flopy/utils/zonbud.py index b5f92ded91..e670a94a80 100644 --- a/flopy/utils/zonbud.py +++ b/flopy/utils/zonbud.py @@ -1,6 +1,7 @@ import copy import os from itertools import groupby +from pathlib import Path import numpy as np @@ -59,7 +60,7 @@ def __init__( if isinstance(cbc_file, CellBudgetFile): self.cbc = cbc_file - elif isinstance(cbc_file, str) and os.path.isfile(cbc_file): + elif isinstance(cbc_file, (str, Path)) and os.path.isfile(cbc_file): self.cbc = CellBudgetFile(cbc_file) else: raise Exception(f"Cannot load cell budget file: {cbc_file}.")