swn.modflow.SwnModflow.write_package_period#

SwnModflow.write_package_period(package: str, fname, auxiliary=[])#

Write PERIOD file for MODFLOW packages, to be used within OPEN/CLOSE.

Parameters:
packagestr

MODFLOW package name, such as “drn” for DRAIN.

fnamestr or path-like

Output file name, with str formatting for stress period number which starts numbering from 1. For example, “drn_sp{:02d}.txt” to create “drn_sp01.txt” for the first stress period.

auxiliarystr, list, optional

String or list of auxiliary variable names. Default [].

Returns:
None

See also

SwnModflow.package_period_frame

Dataframe generator.

SwnModflow.flopy_package_period

Dict of lists of lists for flopy.

Examples

>>> import flopy
>>> import geopandas
>>> import pandas as pd
>>> import swn
>>> from tempfile import TemporaryDirectory
>>> from pathlib import Path
>>> lines = geopandas.GeoSeries.from_wkt([
...    "LINESTRING (60 100, 60  80)",
...    "LINESTRING (40 130, 60 100)",
...    "LINESTRING (70 130, 60 100)"])
>>> lines.index += 100
>>> n = swn.SurfaceWaterNetwork.from_lines(lines)
>>> tmp_dir_obj = TemporaryDirectory()
>>> dir = Path(tmp_dir_obj.name)
>>> m = flopy.modflow.Modflow("model", version="mf2005", model_ws=str(dir))
>>> _ = flopy.modflow.ModflowDis(
...     m, nrow=3, ncol=2, delr=20.0, delc=20.0, xul=30.0, yul=130.0,
...     top=15.0, botm=10.0)
>>> _ = flopy.modflow.ModflowBas(m)
>>> nm = swn.modflow.SwnModflow.from_swn_flopy(n, m)
>>> nm.set_reach_data_from_array("elev", m.dis.top.array)
>>> nm.reaches["dlen"] = nm.reaches.length.round(2)
>>> nm.reaches["cond"] = (nm.reaches.length * 10.0).round(2)
>>> fname_tpl = dir / "model_drn_{:02d}.dat"
>>> fname_01 = dir / "model_drn_01.dat"
>>> nm.write_package_period("drn", fname_tpl, auxiliary="dlen")
>>> print(fname_01.read_text(), end="")
1 1 1 15.0 180.28 18.03
1 1 2 15.0  60.09  6.01
1 2 2 15.0 120.19 12.02
1 1 2 15.0 210.82 21.08
1 2 2 15.0 105.41 10.54
1 2 2 15.0 100.00 10.00
1 3 2 15.0 100.00 10.00
>>> drn = flopy.modflow.ModflowDrn(
...     m, stress_period_data={
...         0: flopy.modflow.ModflowDrn.get_empty(len(nm.reaches))})
>>> m.write_input()
>>> with open(dir / "model.drn", "w") as fp:
...     _ = fp.write("7 0 AUX DLEN\n")
...     _ = fp.write("7 0\n")
...     _ = fp.write("OPEN/CLOSE model_drn_01.dat\n")
>>> success, buff = m.run_model()  
>>> tmp_dir_obj.cleanup()