Skip to content

Commit

Permalink
refactor: various cleanup/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Feb 27, 2023
1 parent 47bdd83 commit f09aba2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
4 changes: 3 additions & 1 deletion autotest/test_flopy_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def test_relpath_safe(function_tmpdir, scrub):
platform.system() == "Windows"
and splitdrive(function_tmpdir)[0] != splitdrive(getcwd())[0]
):
assert Path(relpath_safe(function_tmpdir)) == function_tmpdir.absolute()
assert (
Path(relpath_safe(function_tmpdir)) == function_tmpdir.absolute()
)
assert relpath_safe(which("mf6")) == str(Path(which("mf6")).absolute())
else:
assert Path(
Expand Down
2 changes: 1 addition & 1 deletion flopy/export/shapefile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def write_grid_shapefile(
nan_val=np.nan,
epsg=None,
prj: Union[str, os.PathLike] = None,
verbose=False
verbose=False,
):
"""
Method to write a shapefile of gridded input data
Expand Down
12 changes: 8 additions & 4 deletions flopy/export/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def output_helper(
ml,
oudic,
verbose=False,
**kwargs
**kwargs,
):
"""
Export model outputs using the model spatial reference info.
Expand Down Expand Up @@ -663,7 +663,7 @@ def package_export(
pak,
fmt=None,
verbose=False,
**kwargs
**kwargs,
):
"""
Method to export a package to shapefile or netcdf
Expand Down Expand Up @@ -1336,7 +1336,9 @@ def array3d_export(f: Union[str, os.PathLike], u3d, fmt=None, **kwargs):
raise NotImplementedError(f"unrecognized export argument:{f}")


def array2d_export(f: Union[str, os.PathLike], u2d, fmt=None, verbose=False, **kwargs):
def array2d_export(
f: Union[str, os.PathLike], u2d, fmt=None, verbose=False, **kwargs
):
"""
export helper for Util2d instances
Expand Down Expand Up @@ -1377,7 +1379,9 @@ def array2d_export(f: Union[str, os.PathLike], u2d, fmt=None, verbose=False, **k

if isinstance(f, str) and f.lower().endswith(".shp"):
name = shapefile_utils.shape_attr_name(u2d.name, keep_layer=True)
shapefile_utils.write_grid_shapefile(f, modelgrid, {name: u2d.array}, verbose=verbose)
shapefile_utils.write_grid_shapefile(
f, modelgrid, {name: u2d.array}, verbose=verbose
)
return

elif isinstance(f, str) and f.lower().endswith(".asc"):
Expand Down
68 changes: 34 additions & 34 deletions flopy/utils/compare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import textwrap
from typing import List, Union
from typing import List, Union, Optional

import numpy as np

Expand Down Expand Up @@ -79,13 +79,13 @@ def _difftol(v1, v2, tol):


def compare_budget(
namefile1,
namefile2,
namefile1: Optional[Union[str, os.PathLike]],
namefile2: Optional[Union[str, os.PathLike]],
max_cumpd=0.01,
max_incpd=0.01,
outfile=None,
files1=None,
files2=None,
outfile: Optional[Union[str, os.PathLike]] = None,
files1: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
files2: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
):
"""Compare the budget results from two simulations.
Expand Down Expand Up @@ -282,13 +282,13 @@ def compare_budget(


def compare_swrbudget(
namefile1,
namefile2,
namefile1: Optional[Union[str, os.PathLike]],
namefile2: Optional[Union[str, os.PathLike]],
max_cumpd=0.01,
max_incpd=0.01,
outfile=None,
files1=None,
files2=None,
outfile: Optional[Union[str, os.PathLike]] = None,
files1: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
files2: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
):
"""Compare the SWR budget results from two simulations.
Expand Down Expand Up @@ -477,18 +477,18 @@ def compare_swrbudget(


def compare_heads(
namefile1: Union[str, os.PathLike, None],
namefile2: Union[str, os.PathLike, None],
namefile1: Optional[Union[str, os.PathLike]],
namefile2: Optional[Union[str, os.PathLike]],
precision="auto",
text="head",
text2=None,
htol=0.001,
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,
outfile: Optional[Union[str, os.PathLike]] = None,
files1: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
files2: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
difftol=False,
verbose=False,
exfile: Union[str, os.PathLike, None] = None,
exfile: Optional[Union[str, os.PathLike]] = None,
exarr=None,
maxerr=None,
):
Expand Down Expand Up @@ -868,13 +868,13 @@ def compare_heads(


def compare_concentrations(
namefile1,
namefile2,
namefile1: Union[str, os.PathLike],
namefile2: Union[str, os.PathLike],
precision="auto",
ctol=0.001,
outfile=None,
files1=None,
files2=None,
outfile: Optional[Union[str, os.PathLike]] = None,
files1: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
files2: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
difftol=False,
verbose=False,
):
Expand Down Expand Up @@ -1098,12 +1098,12 @@ def compare_concentrations(


def compare_stages(
namefile1=None,
namefile2=None,
files1=None,
files2=None,
namefile1: Union[str, os.PathLike] = None,
namefile2: Union[str, os.PathLike] = None,
files1: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
files2: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
htol=0.001,
outfile=None,
outfile: Optional[Union[str, os.PathLike]] = None,
difftol=False,
verbose=False,
):
Expand Down Expand Up @@ -1310,16 +1310,16 @@ def compare_stages(


def compare(
namefile1,
namefile2,
namefile1: Union[str, os.PathLike] = None,
namefile2: Union[str, os.PathLike] = None,
precision="auto",
max_cumpd=0.01,
max_incpd=0.01,
htol=0.001,
outfile1=None,
outfile2=None,
files1=None,
files2=None,
outfile1: Optional[Union[str, os.PathLike]] = None,
outfile2: Optional[Union[str, os.PathLike]] = None,
files1: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
files2: Optional[Union[str, os.PathLike, List[Union[str, os.PathLike]]]] = None,
):
"""Compare the budget and head results for two MODFLOW-based model
simulations.
Expand Down Expand Up @@ -1389,7 +1389,7 @@ def compare(
return success


def eval_bud_diff(fpth, b0, b1, ia=None, dtol=1e-6):
def eval_bud_diff(fpth: Union[str, os.PathLike], b0, b1, ia=None, dtol=1e-6):
# To use this eval_bud_diff function on a gwf or gwt budget file,
# the function may need ia, in order to exclude comparison of the residual
# term, which is stored in the diagonal position of the flowja array.
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def to_shapefile(
totim=None,
mflay=None,
attrib_name="lf_data",
verbose=False
verbose=False,
):
"""
Export model output data to a shapefile at a specific location
Expand Down

0 comments on commit f09aba2

Please sign in to comment.