From 9639c7e6c84266cd014cece2cd2f8f97378ff045 Mon Sep 17 00:00:00 2001 From: emorway-usgs Date: Tue, 3 Dec 2024 12:28:17 -0800 Subject: [PATCH] ruff'led --- autotest/test_gwe_drycell_cnd3.py | 65 ++++++++++------------- autotest/test_gwf_sfrsft_gwdischrg.py | 30 ++++------- autotest/test_gwt_uztmvt2x1.py | 75 +++++++++++---------------- 3 files changed, 69 insertions(+), 101 deletions(-) diff --git a/autotest/test_gwe_drycell_cnd3.py b/autotest/test_gwe_drycell_cnd3.py index dc1515c2cb6..88cbee922b9 100644 --- a/autotest/test_gwe_drycell_cnd3.py +++ b/autotest/test_gwe_drycell_cnd3.py @@ -152,14 +152,14 @@ def add_gwf_model(sim, gwfname, newton=False): modelname=gwfname, newtonoptions="NEWTON", save_flows=True, - model_nam_file="{}.nam".format(gwfname), + model_nam_file=f"{gwfname}.nam", ) else: gwf = flopy.mf6.ModflowGwf( sim, modelname=gwfname, save_flows=True, - model_nam_file="{}.nam".format(gwfname), + model_nam_file=f"{gwfname}.nam", ) # Instantiating MODFLOW 6 solver for flow model @@ -176,7 +176,7 @@ def add_gwf_model(sim, gwfname, newton=False): scaling_method="NONE", reordering_method="NONE", relaxation_factor=relax, - filename="{}.ims".format(gwfname), + filename=f"{gwfname}.ims", ) sim.register_ims_package(imsgwf, [gwfname]) @@ -193,7 +193,7 @@ def add_gwf_model(sim, gwfname, newton=False): botm=bot, idomain=1, pname="DIS", - filename="{}.dis".format(gwfname), + filename=f"{gwfname}.dis", ) # Instantiating MODFLOW 6 storage package @@ -205,7 +205,7 @@ def add_gwf_model(sim, gwfname, newton=False): steady_state=steady, transient=transient, pname="STO", - filename="{}.sto".format(gwfname), + filename=f"{gwfname}.sto", ) # Instantiating MODFLOW 6 node-property flow package @@ -217,22 +217,22 @@ def add_gwf_model(sim, gwfname, newton=False): k33=k33, save_specific_discharge=True, pname="NPF", - filename="{}.npf".format(gwfname), + filename=f"{gwfname}.npf", ) # Instantiating MODFLOW 6 initial conditions package for flow model flopy.mf6.ModflowGwfic( gwf, strt=strthd, - filename="{}.ic".format(gwfname), + filename=f"{gwfname}.ic", ) # Instantiating MODFLOW 6 output control package for flow model flopy.mf6.ModflowGwfoc( gwf, pname="OC", - head_filerecord="{}.hds".format(gwfname), - budget_filerecord="{}.cbc".format(gwfname), + head_filerecord=f"{gwfname}.hds", + budget_filerecord=f"{gwfname}.cbc", headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], @@ -259,7 +259,7 @@ def add_gwf_model(sim, gwfname, newton=False): connectiondata=connectiondata, perioddata=sfr_perioddata, pname=pname, - filename="{}.sfr".format(gwfname), + filename=f"{gwfname}.sfr", ) fname = f"{gwfname}.sfr.obs" sfr_obs = { @@ -274,9 +274,7 @@ def add_gwf_model(sim, gwfname, newton=False): def add_gwe_model(sim, gwename): - gwe = flopy.mf6.ModflowGwe( - sim, modelname=gwename, model_nam_file="{}.nam".format(gwename) - ) + gwe = flopy.mf6.ModflowGwe(sim, modelname=gwename, model_nam_file=f"{gwename}.nam") gwe.name_file.save_flows = True imsgwe = flopy.mf6.ModflowIms( @@ -292,7 +290,7 @@ def add_gwe_model(sim, gwename): scaling_method="NONE", reordering_method="NONE", relaxation_factor=relax, - filename="{}.ims".format(gwename), + filename=f"{gwename}.ims", ) sim.register_ims_package(imsgwe, [gwe.name]) @@ -309,18 +307,14 @@ def add_gwe_model(sim, gwename): botm=bot, idomain=1, pname="DIS", - filename="{}.dis".format(gwename), + filename=f"{gwename}.dis", ) # Instantiating MODFLOW 6 transport initial concentrations - flopy.mf6.ModflowGweic( - gwe, strt=strt_temp, pname="IC", filename="{}.ic".format(gwename) - ) + flopy.mf6.ModflowGweic(gwe, strt=strt_temp, pname="IC", filename=f"{gwename}.ic") # Instantiating MODFLOW 6 transport advection package - flopy.mf6.ModflowGweadv( - gwe, scheme=scheme, pname="ADV", filename="{}.adv".format(gwename) - ) + flopy.mf6.ModflowGweadv(gwe, scheme=scheme, pname="ADV", filename=f"{gwename}.adv") # Instantiating MODFLOW 6 transport dispersion package flopy.mf6.ModflowGwecnd( @@ -331,10 +325,11 @@ def add_gwe_model(sim, gwename): ktw=ktw * 86400, kts=kts * 86400, pname="CND", - filename="{}.cnd".format(gwename), + filename=f"{gwename}.cnd", ) - # Instantiating MODFLOW 6 transport mass storage package (formerly "reaction" package in MT3DMS) + # Instantiating MODFLOW 6 transport mass storage package + # (formerly "reaction" package in MT3DMS) flopy.mf6.ModflowGweest( gwe, save_flows=True, @@ -345,7 +340,7 @@ def add_gwe_model(sim, gwename): heat_capacity_solid=cps, density_solid=rhos, pname="EST", - filename="{}.est".format(gwename), + filename=f"{gwename}.est", ) # Instantiating MODFLOW 6 source/sink mixing package for dealing with @@ -355,18 +350,16 @@ def add_gwe_model(sim, gwename): gwe, sources=sourcerecarray, pname="SSM", - filename="{}.ssm".format(gwename), + filename=f"{gwename}.ssm", ) # Instantiate MODFLOW 6 heat transport output control package flopy.mf6.ModflowGweoc( gwe, pname="OC", - budget_filerecord="{}.cbc".format(gwename), - temperature_filerecord="{}.ucn".format(gwename), - temperatureprintrecord=[ - ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") - ], + budget_filerecord=f"{gwename}.cbc", + temperature_filerecord=f"{gwename}.ucn", + temperatureprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("TEMPERATURE", "ALL"), ("BUDGET", "ALL")], printrecord=[("TEMPERATURE", "ALL"), ("BUDGET", "ALL")], ) @@ -393,7 +386,7 @@ def add_gwe_model(sim, gwename): reachperioddata=sfe_perioddata, flow_package_name=flwpckname, pname="SFE", - filename="{}.sfe".format(gwename), + filename=f"{gwename}.sfe", ) return sim @@ -404,7 +397,7 @@ def build_models(idx, test): ws = test.workspace name = cases[idx] - print("Building MF6 model...{}".format(name)) + print(f"Building MF6 model...{name}") # generate names for each model gwfname1 = "gwf-" + name + "nwt1" @@ -417,9 +410,7 @@ def build_models(idx, test): ) # Instantiating MODFLOW 6 time discretization - flopy.mf6.ModflowTdis( - sim, nper=nper, perioddata=tdis_rc, time_units=time_units - ) + flopy.mf6.ModflowTdis(sim, nper=nper, perioddata=tdis_rc, time_units=time_units) # Build two flow models, one with NWT, one without sim = add_gwf_model(sim, gwfname1, newton=True) @@ -436,7 +427,7 @@ def build_models(idx, test): exgmnamea=gwfname1, exgmnameb=gwename1, pname="GWFGWE1", - filename="{}.gwfgwe1".format(gwename1), + filename=f"{gwename1}.gwfgwe1", ) flopy.mf6.ModflowGwfgwe( @@ -445,7 +436,7 @@ def build_models(idx, test): exgmnamea=gwfname2, exgmnameb=gwename2, pname="GWFGWE2", - filename="{}.gwfgwe2".format(gwename2), + filename=f"{gwename2}.gwfgwe2", ) return sim, None diff --git a/autotest/test_gwf_sfrsft_gwdischrg.py b/autotest/test_gwf_sfrsft_gwdischrg.py index 11988a3d2e8..ede17238a02 100644 --- a/autotest/test_gwf_sfrsft_gwdischrg.py +++ b/autotest/test_gwf_sfrsft_gwdischrg.py @@ -23,9 +23,7 @@ def add_gwt_model(sim, gwtname): - gwt = flopy.mf6.ModflowGwt( - sim, modelname=gwtname, model_nam_file="{}.nam".format(gwtname) - ) + gwt = flopy.mf6.ModflowGwt(sim, modelname=gwtname, model_nam_file=f"{gwtname}.nam") gwt.name_file.save_flows = True imsgwt = flopy.mf6.ModflowIms( @@ -41,7 +39,7 @@ def add_gwt_model(sim, gwtname): scaling_method="NONE", reordering_method="NONE", relaxation_factor=relax, - filename="{}.ims".format(gwtname), + filename=f"{gwtname}.ims", ) sim.register_ims_package(imsgwt, [gwt.name]) @@ -65,7 +63,7 @@ def add_gwt_model(sim, gwtname): gwt, sources=sourcerecarray, pname="SSM", - filename="{}.ssm".format(gwtname), + filename=f"{gwtname}.ssm", ) # Instantiate Streamflow Transport package @@ -90,16 +88,14 @@ def add_gwt_model(sim, gwtname): reachperioddata=sft_perioddata, flow_package_name=flwpckname, pname="SFT", - filename="{}.sft".format(gwtname), + filename=f"{gwtname}.sft", ) flopy.mf6.ModflowGwtoc( gwt, budget_filerecord=f"{gwtname}.cbc", concentration_filerecord=f"{gwtname}.ucn", - concentrationprintrecord=[ - ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") - ], + concentrationprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], printrecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], ) @@ -150,10 +146,8 @@ def build_models(idx, test): ) # sfr data - # - package_data = [ - (0, (0, 0, 0), delr, 1.0, 1e-3, 0.0, 1.0, 1.0, 0.001, 0, 0.0, 0) - ] + # + package_data = [(0, (0, 0, 0), delr, 1.0, 1e-3, 0.0, 1.0, 1.0, 0.001, 0, 0.0, 0)] connection_data = [(0)] sfr_obs = { @@ -191,7 +185,7 @@ def build_models(idx, test): exgmnamea=name, exgmnameb=gwtname, pname="GWFGWT1", - filename="{}.gwfgwt1".format(gwtname), + filename=f"{gwtname}.gwfgwt1", ) return sim, None @@ -227,9 +221,7 @@ def check_output(idx, test): ) sim_conc_sft = cobj.get_alldata() except: - assert ( - False - ), f'could not load concentration data from "{sft_obs_fl}"' + assert False, f'could not load concentration data from "{sft_obs_fl}"' gwt_sim_conc = pl.Path(f"{test.workspace}/{gwtname}.ucn") try: @@ -240,9 +232,7 @@ def check_output(idx, test): ) conc_gw = cobj.get_alldata() except: - assert ( - False - ), f'could not load temperature data from "{sft_obs_fl}"' + assert False, f'could not load temperature data from "{sft_obs_fl}"' msg0 = "The simulation is not matching the established answer" msg1 = ( diff --git a/autotest/test_gwt_uztmvt2x1.py b/autotest/test_gwt_uztmvt2x1.py index c0b468344bc..821e36fba20 100644 --- a/autotest/test_gwt_uztmvt2x1.py +++ b/autotest/test_gwt_uztmvt2x1.py @@ -44,9 +44,7 @@ scheme = "UPSTREAM" # scheme = "TVD" -cases = [ - "uztmvt" -] # 2-cell model, horizontally connected with staggered alignment +cases = ["uztmvt"] # 2-cell model, horizontally connected with staggered alignment nrow = 2 ncol = 1 @@ -181,7 +179,7 @@ def build_models(idx, test): ws = test.workspace name = cases[idx] - print("Building MF6 model...{}".format(name)) + print(f"Building MF6 model...{name}") # generate names for each model gwfname = "gwf-" + name @@ -192,16 +190,14 @@ def build_models(idx, test): ) # Instantiating MODFLOW 6 time discretization - flopy.mf6.ModflowTdis( - sim, nper=nper, perioddata=tdis_rc, time_units=time_units - ) + flopy.mf6.ModflowTdis(sim, nper=nper, perioddata=tdis_rc, time_units=time_units) # Instantiating MODFLOW 6 groundwater flow model gwf = flopy.mf6.ModflowGwf( sim, modelname=gwfname, save_flows=True, - model_nam_file="{}.nam".format(gwfname), + model_nam_file=f"{gwfname}.nam", ) # Instantiating MODFLOW 6 solver for flow model @@ -218,7 +214,7 @@ def build_models(idx, test): scaling_method="NONE", reordering_method="NONE", relaxation_factor=relax, - filename="{}.ims".format(gwfname), + filename=f"{gwfname}.ims", ) sim.register_ims_package(imsgwf, [gwfname]) @@ -235,7 +231,7 @@ def build_models(idx, test): botm=bot, idomain=1, pname="DIS-1", - filename="{}.dis".format(gwfname), + filename=f"{gwfname}.dis", ) # Instantiating MODFLOW 6 storage package @@ -255,7 +251,7 @@ def build_models(idx, test): gwf, stress_period_data=chdlist, pname="CHD", - filename="{}.chd".format(gwfname), + filename=f"{gwfname}.chd", ) # Instantiating MODFLOW 6 node-property flow package @@ -267,7 +263,7 @@ def build_models(idx, test): k33=k33, save_specific_discharge=True, pname="NPF-1", - filename="{}.npf".format(gwfname), + filename=f"{gwfname}.npf", ) flopy.mf6.ModflowGwfsto( @@ -276,14 +272,14 @@ def build_models(idx, test): sy=sy, transient={0: True}, pname="STO", - filename="{}.sto".format(gwfname), + filename=f"{gwfname}.sto", ) # Instantiating MODFLOW 6 initial conditions package for flow model flopy.mf6.ModflowGwfic( gwf, strt=strthd, - filename="{}.ic".format(gwfname), + filename=f"{gwfname}.ic", ) # UZF @@ -322,7 +318,7 @@ def build_models(idx, test): connectiondata=conn_dat, perioddata=sfr_perdat, pname="SFR-1", - filename="{}.sfr".format(gwfname), + filename=f"{gwfname}.sfr", ) # MVR @@ -340,8 +336,8 @@ def build_models(idx, test): flopy.mf6.ModflowGwfoc( gwf, pname="OC-1", - head_filerecord="{}.hds".format(gwfname), - budget_filerecord="{}.cbc".format(gwfname), + head_filerecord=f"{gwfname}.hds", + budget_filerecord=f"{gwfname}.cbc", headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], @@ -350,9 +346,7 @@ def build_models(idx, test): # ---------------------------------------------------- # Instantiating MODFLOW 6 GWT model # ---------------------------------------------------- - gwt = flopy.mf6.ModflowGwt( - sim, modelname=gwtname, model_nam_file="{}.nam".format(gwtname) - ) + gwt = flopy.mf6.ModflowGwt(sim, modelname=gwtname, model_nam_file=f"{gwtname}.nam") gwt.name_file.save_flows = True imsgwt = flopy.mf6.ModflowIms( sim, @@ -367,7 +361,7 @@ def build_models(idx, test): scaling_method="NONE", reordering_method="NONE", relaxation_factor=relax, - filename="{}.ims".format(gwtname), + filename=f"{gwtname}.ims", ) sim.register_ims_package(imsgwt, [gwt.name]) @@ -384,17 +378,15 @@ def build_models(idx, test): botm=bot, idomain=1, pname="DIS-1", - filename="{}.dis".format(gwtname), + filename=f"{gwtname}.dis", ) # Instantiating MODFLOW 6 transport initial concentrations - flopy.mf6.ModflowGwtic( - gwt, strt=strt_conc, pname="IC-1", filename="{}.ic".format(gwtname) - ) + flopy.mf6.ModflowGwtic(gwt, strt=strt_conc, pname="IC-1", filename=f"{gwtname}.ic") # Instantiating MODFLOW 6 transport advection package flopy.mf6.ModflowGwtadv( - gwt, scheme=scheme, pname="ADV-2", filename="{}.adv".format(gwtname) + gwt, scheme=scheme, pname="ADV-2", filename=f"{gwtname}.adv" ) # Instantiating MODFLOW 6 transport dispersion package @@ -406,10 +398,11 @@ def build_models(idx, test): ath1=dispersivity, atv=dispersivity, pname="CND-1", - filename="{}.cnd".format(gwtname), + filename=f"{gwtname}.cnd", ) - # Instantiating MODFLOW 6 transport mass storage package (formerly "reaction" package in MT3DMS) + # Instantiating MODFLOW 6 transport mass storage package + # (formerly "reaction" package in MT3DMS) flopy.mf6.ModflowGwtmst( gwt, save_flows=True, @@ -418,7 +411,7 @@ def build_models(idx, test): bulk_density=rhob, distcoef=Kd, pname="MST-1", - filename="{}.mst".format(gwtname), + filename=f"{gwtname}.mst", ) flopy.mf6.modflow.ModflowGwtuzt( @@ -434,7 +427,7 @@ def build_models(idx, test): uztperioddata=uzt_perdat, flow_package_name="UZF-1", pname="UZT-1", - filename="{}.uzt".format(gwtname), + filename=f"{gwtname}.uzt", ) flopy.mf6.modflow.ModflowGwtsft( @@ -449,33 +442,29 @@ def build_models(idx, test): packagedata=sft_pkdat, reachperioddata=sft_perdat, pname="SFT-1", - filename="{}.sft".format(gwtname), + filename=f"{gwtname}.sft", ) flopy.mf6.modflow.ModflowGwtmvt( gwt, save_flows=True, budget_filerecord=gwtname + ".mvt.bud", - filename="{}.mvt".format(gwtname), + filename=f"{gwtname}.mvt", ) # Instantiate MODFLOW 6 heat transport output control package flopy.mf6.ModflowGwtoc( gwt, pname="OC-2", - budget_filerecord="{}.cbc".format(gwtname), - concentration_filerecord="{}.ucn".format(gwtname), - concentrationprintrecord=[ - ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") - ], + budget_filerecord=f"{gwtname}.cbc", + concentration_filerecord=f"{gwtname}.ucn", + concentrationprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], printrecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], ) sourcerecarray = [[]] - flopy.mf6.ModflowGwessm( - gwt, sources=sourcerecarray, filename="{}.ssm".format(gwtname) - ) + flopy.mf6.ModflowGwessm(gwt, sources=sourcerecarray, filename=f"{gwtname}.ssm") # Instantiating MODFLOW 6 flow-transport exchange mechanism flopy.mf6.ModflowGwfgwt( @@ -484,7 +473,7 @@ def build_models(idx, test): exgmnamea=gwfname, exgmnameb=gwtname, pname="GWFGWT", - filename="{}.gwfgwt".format(gwtname), + filename=f"{gwtname}.gwfgwt", ) return sim, None @@ -540,9 +529,7 @@ def check_output(idx, test): continue else: for z in np.arange(len(mvrdat[x + 1][y])): - assert np.isclose( - abs(mvrdat[x + 1][y][z][-1]), x + 1.0 - ), msg0 + assert np.isclose(abs(mvrdat[x + 1][y][z][-1]), x + 1.0), msg0 # Transport mover (MVT) amounts are known quantities msg1 = "Rejected infiltration transfer mass amount not as expected"