From be235cfb79976d45c813cea0aec721f943ba3704 Mon Sep 17 00:00:00 2001 From: Huite Date: Wed, 25 Sep 2024 16:37:21 +0200 Subject: [PATCH] Use ruff to format and lint (#114) * Use ruff to format and lint, fix all issues that came up. * Git blame: ignore ruff style changes * Looks like ruff trivialized test_import * Do not exclude examples from ruff * Remove unused computation in StripAreaSink.changetrace * Add ruff format --check in linting step * Also format the examples * Add examples ruff format to git-blame-ignore --- .git-blame-ignore-revs | 6 +- examples/timml_notebook0_sol.py | 71 ++++++++++--------- .../workshop_nhv/vlaketunnel_functions.py | 5 ++ tests/test_import.py | 2 + tests/test_notebooks.py | 2 +- timml/__init__.py | 64 +++++++++++++---- timml/bessel.py | 2 +- timml/circareasink.py | 3 - timml/inhomogeneity.py | 63 +++++++++++----- timml/inhomogeneity1d.py | 12 +++- timml/linedoublet.py | 10 +-- timml/linesink.py | 34 +++++---- timml/model.py | 21 ++++-- timml/stripareasink.py | 7 +- timml/trace.py | 2 + timml/util.py | 10 +-- 16 files changed, 212 insertions(+), 102 deletions(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 2a2e5397..d4033ef4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,6 @@ # Migrate code style to black -998b86fc128e35f1506e3d4facb169c558679bde \ No newline at end of file +998b86fc128e35f1506e3d4facb169c558679bde + +# Migrate code style to ruff +a11f92ff2732d7fdc548559f15f009e4a3d5ea7a +571e4b5af45bd1ca6f025dd883b9ea800acb4aef \ No newline at end of file diff --git a/examples/timml_notebook0_sol.py b/examples/timml_notebook0_sol.py index 63015ec4..d4e8f407 100644 --- a/examples/timml_notebook0_sol.py +++ b/examples/timml_notebook0_sol.py @@ -4,33 +4,34 @@ # # TimML Notebook 0 # ## Single layer flow + # Consider uniform flow from East to West. The gradient is 0.001. # The hydraulic conductivity is $k=10$ m/d. The aquifer bottom and top are at 0 m # and 10 m. The head at $x=-1000$ m and $y=0$ is fixed at 41 m. # In[1]: +import numpy as np -from pylab import * +import timml -from timml import * # In[2]: -ml = ModelMaq(kaq=10, z=[10, 0]) +ml = timml.ModelMaq(kaq=10, z=[10, 0]) # In[3]: -rf = Constant(ml, xr=-1000, yr=0, hr=41) +rf = timml.Constant(ml, xr=-1000, yr=0, hr=41) # In[4]: -uf = Uflow(ml, slope=0.001, angle=0) +uf = timml.Uflow(ml, slope=0.001, angle=0) # In[5]: @@ -56,6 +57,7 @@ ) + # The default contour levels are not what we want for this example, so let's # specify the levels to go from 39 to 42 with steps of 0.1 (not all those levels # are present in the current window). @@ -70,7 +72,7 @@ y1=-500, y2=500, ny=50, - levels=arange(39, 42, 0.1), + levels=np.arange(39, 42, 0.1), labels=True, decimals=1, ) @@ -81,8 +83,8 @@ # In[8]: -w = Well(ml, xw=-400, yw=0, Qw=50.0, rw=0.2) +w = timml.Well(ml, xw=-400, yw=0, Qw=50.0, rw=0.2) # After the well is added (or any other elements), the model needs to be solved again. A contour plot is created and a 10 strace line are added. The stepsize is given in meters and represents the largest space step that is taken, but it is reduced when certain accuracy constraints are not met. Note that, after running the code cell below, for each trace line it is printed to the screen what the reason was that the traceline was aborted. In this case it was either because the trace line reached a well or reached the maximum number of steps (the default is 100 steps, but this can be changed by specifying the `nstepmax` keyword). @@ -91,7 +93,7 @@ ml.solve() ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1)) -ml.tracelines(-800 * ones(1), -200 * ones(1), zeros(1), hstepmax=20) +ml.tracelines(-800 * np.ones(1), -200 * np.ones(1), np.zeros(1), hstepmax=20) # ### Exercise a @@ -101,7 +103,7 @@ ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1)) -ml.tracelines(-800 * ones(10), linspace(-500, 500, 10), zeros(10), hstepmax=20) +ml.tracelines(-800 * np.ones(10), np.linspace(-500, 500, 10), np.zeros(10), hstepmax=20) # ### Exercise b @@ -110,13 +112,14 @@ # In[11]: -ml = ModelMaq(kaq=10, z=[10, 0]) -rf = Constant(ml, xr=-1000, yr=0, hr=41) -uf = Uflow(ml, slope=0.001, angle=0) -w = Well(ml, xw=-400, yw=0, Qw=200, rw=0.2) +ml = timml.ModelMaq(kaq=10, z=[10, 0]) +rf = timml.Constant(ml, xr=-1000, yr=0, hr=41) +uf = timml.Uflow(ml, slope=0.001, angle=0) +w = timml.Well(ml, xw=-400, yw=0, Qw=200, rw=0.2) ml.solve() ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1)) -ml.tracelines(-800 * ones(10), linspace(-500, 500, 10), zeros(10), hstepmax=20) +ml.tracelines(-800 * np.ones(10), np.linspace(-500, 500, 10), np.zeros(10), hstepmax=20) + print(("head at well:", w.headinside())) @@ -126,13 +129,13 @@ # In[12]: -ml = ModelMaq(kaq=10, z=[10, 0]) -rf = Constant(ml, xr=-1000, yr=0, hr=41) -uf = Uflow(ml, slope=0.001, angle=0) -w = Well(ml, xw=-400, yw=0, Qw=200, rw=0.2) -ls1 = HeadLineSink(ml, 0, -500, 0, 500, 40) +ml = timml.ModelMaq(kaq=10, z=[10, 0]) +rf = timml.Constant(ml, xr=-1000, yr=0, hr=41) +uf = timml.Uflow(ml, slope=0.001, angle=0) +w = timml.Well(ml, xw=-400, yw=0, Qw=200, rw=0.2) +ls1 = timml.HeadLineSink(ml, 0, -500, 0, 500, 40) ml.solve() -ml.contour(-1000, 100, 50, -500, 500, 50, levels=arange(39, 42, 0.1)) +ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1)) print(("head at well:", w.headinside())) @@ -142,19 +145,22 @@ # In[13]: -ml = ModelMaq(kaq=10, z=[10, 0]) -rf = Constant(ml, xr=-1000, yr=0, hr=41) -uf = Uflow(ml, slope=0.001, angle=0) -w = Well(ml, xw=-400, yw=0, Qw=200, rw=0.2) -xls = zeros(21) -yls = linspace(-800, 800, 21) -ls = HeadLineSinkString(ml, xy=list(zip(xls, yls)), hls=40, layers=0) +ml = timml.ModelMaq(kaq=10, z=[10, 0]) +rf = timml.Constant(ml, xr=-1000, yr=0, hr=41) +uf = timml.Uflow(ml, slope=0.001, angle=0) +w = timml.Well(ml, xw=-400, yw=0, Qw=200, rw=0.2) +xls = np.zeros(21) +yls = np.linspace(-800, 800, 21) +ls = timml.HeadLineSinkString(ml, xy=list(zip(xls, yls)), hls=40, layers=0) ml.solve() -ml.contour(-1000, 100, 50, -500, 500, 50, levels=arange(39, 42, 0.1)) +ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1)) ml.tracelines( - -800 * ones(10), linspace(-500, 500, 10), zeros(10), hstepmax=20, color="b" + -800 * np.ones(10), np.linspace(-500, 500, 10), np.zeros(10), hstepmax=20, color="b" +) +ml.tracelines( + -0.01 * np.ones(5), np.linspace(-150, 150, 5), np.zeros(5), hstepmax=20, color="r" ) -ml.tracelines(-0.01 * ones(5), linspace(-150, 150, 5), zeros(5), hstepmax=20, color="r") + # ### Capture zone @@ -163,7 +169,8 @@ # In[14]: -ml.contour(-1000, 100, 50, -500, 500, 50, levels=arange(39, 42, 0.1), layers=0) + +ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1), layers=0) w.plotcapzone(hstepmax=20, nt=20, zstart=0, tmax=5 * 365.25, color="b") @@ -173,7 +180,7 @@ # In[15]: -ml.contour(-1000, 100, 50, -500, 500, 50, levels=arange(39, 42, 0.1), layers=0) +ml.contour(-1000, 100, 50, -500, 500, 50, levels=np.arange(39, 42, 0.1), layers=0) w.plotcapzone(hstepmax=20, nt=20, zstart=0, tmax=20 * 365.25, color="b") diff --git a/examples/workshop_nhv/vlaketunnel_functions.py b/examples/workshop_nhv/vlaketunnel_functions.py index 43d636b2..dd0a1dea 100644 --- a/examples/workshop_nhv/vlaketunnel_functions.py +++ b/examples/workshop_nhv/vlaketunnel_functions.py @@ -39,6 +39,10 @@ def create_model( """ # create model + if c is None: + c = [1000.0, 2.0, 2.0, 2.0] + if kaq is None: + kaq = [0.1, 5.0, 15.0, 5.0] ml = tml.ModelMaq( kaq=kaq, z=[1.0, -3.0, -7.0, -7.0, -14.0, -14.0, -30.0, -30.0, -40.0], @@ -87,6 +91,7 @@ def create_model( c_channel = ml.aq.c.copy() c_channel[0] = c_channel_bot + # channel_0: tml.PolygonInhomMaq( kaq=ml.aq.kaq, diff --git a/tests/test_import.py b/tests/test_import.py index 6a8b37a0..07e3e633 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,6 +1,8 @@ def test_import(): pass + print(timml.__version__) + if __name__ == "__main__": test_import() diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index a34deb77..f9e00f2f 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -45,7 +45,7 @@ def get_jupyter_kernel(): return kernel -@pytest.mark.notebooks +@pytest.mark.notebooks() @pytest.mark.parametrize("pth", get_notebooks()) def test_notebook(pth): kernel = get_jupyter_kernel() diff --git a/timml/__init__.py b/timml/__init__.py index e35df4bd..a4ebb408 100644 --- a/timml/__init__.py +++ b/timml/__init__.py @@ -12,7 +12,6 @@ # --version number __name__ = "timml" __author__ = "Mark Bakker" - # Import all classes and functions from . import bessel from .circareasink import CircAreaSink @@ -25,15 +24,15 @@ PolygonInhom3D, PolygonInhomMaq, ) -from .inhomogeneity1d import StripInhom3D, StripInhomMaq -from .linedoublet import ( +from timml.inhomogeneity1d import StripInhom3D, StripInhomMaq +from timml.linedoublet import ( ImpLineDoublet, ImpLineDoubletString, LeakyLineDoublet, LeakyLineDoubletString, ) -from .linedoublet1d import ImpLineDoublet1D, LeakyLineDoublet1D -from .linesink import ( +from timml.linedoublet1d import ImpLineDoublet1D, LeakyLineDoublet1D +from timml.linesink import ( HeadLineSink, HeadLineSinkContainer, HeadLineSinkString, @@ -42,15 +41,54 @@ LineSinkDitch, LineSinkDitchString, ) -from .linesink1d import HeadLineSink1D, LineSink1D -from .model import Model, Model3D, ModelMaq -from .stripareasink import StripAreaSink -from .trace import timtraceline, timtracelines -from .uflow import Uflow -from .version import __version__ -from .well import HeadWell, LargeDiameterWell, Well, WellBase +from timml.linesink1d import HeadLineSink1D, LineSink1D +from timml.model import Model, Model3D, ModelMaq +from timml.stripareasink import StripAreaSink +from timml.trace import timtraceline, timtracelines +from timml.uflow import Uflow +from timml.version import __version__ +from timml.well import HeadWell, LargeDiameterWell, Well, WellBase -__all__ = [s for s in dir() if not s.startswith("_")] +__all__ = [ + "CircAreaSink", + "Constant", + "ConstantStar", + "BuildingPit3D", + "BuildingPitMaq", + "LeakyBuildingPit3D", + "LeakyBuildingPitMaq", + "PolygonInhom3D", + "PolygonInhomMaq", + "StripInhom3D", + "StripInhomMaq", + "ImpLineDoublet", + "ImpLineDoubletString", + "LeakyLineDoublet", + "LeakyLineDoubletString", + "ImpLineDoublet1D", + "LeakyLineDoublet1D", + "HeadLineSink", + "HeadLineSinkContainer", + "HeadLineSinkString", + "HeadLineSinkZero", + "LineSinkBase", + "LineSinkDitch", + "LineSinkDitchString", + "HeadLineSink1D", + "LineSink1D", + "Model", + "Model3D", + "ModelMaq", + "StripAreaSink", + "timtraceline", + "timtracelines", + "Uflow", + "__version__", + "HeadWell", + "LargeDiameterWell", + "Well", + "WellBase", +] # default bessel module is numba bessel.set_bessel_method(method="numba") diff --git a/timml/bessel.py b/timml/bessel.py index 23bc2d95..1daab442 100644 --- a/timml/bessel.py +++ b/timml/bessel.py @@ -12,7 +12,7 @@ def set_bessel_method(method="numba"): except ImportError: warn( "Cannot import compiled fortran bessel module! Defaulting to numba!", - stacklevel=1, + category=ImportWarning, ) bessel = import_module("timml.besselaesnumba.besselaesnumba") elif method == "numba": diff --git a/timml/circareasink.py b/timml/circareasink.py index ee877be5..1a65572f 100644 --- a/timml/circareasink.py +++ b/timml/circareasink.py @@ -247,8 +247,5 @@ def changetrace( u = u1 * (1.0 + eps) # Go just beyond circle else: u = u2 * (1.0 + eps) # Go just beyond circle - # xn = x1 + u * (x2 - x1) - # yn = y1 + u * (y2 - y1) - # zn = xyzt1[2] + u * (xyzt2[2] - xyzt1[2]) xyztnew = xyzt1 + u * (xyzt2 - xyzt1) return changed, terminate, xyztnew, message diff --git a/timml/inhomogeneity.py b/timml/inhomogeneity.py index 910f32a3..d6ce83ed 100644 --- a/timml/inhomogeneity.py +++ b/timml/inhomogeneity.py @@ -171,8 +171,8 @@ def __init__( model, xy, kaq=1, - z=[1, 0], - c=[], + z=None, + c=None, npor=0.3, topboundary="conf", hstar=None, @@ -180,6 +180,10 @@ def __init__( order=3, ndeg=3, ): + if c is None: + c = [] + if z is None: + z = [1, 0] if N is not None: assert ( topboundary[:4] == "conf" @@ -252,7 +256,7 @@ def __init__( model, xy, kaq=1, - z=[1, 0], + z=None, kzoverkh=1, npor=0.3, topboundary="conf", @@ -263,6 +267,8 @@ def __init__( order=3, ndeg=3, ): + if z is None: + z = [1, 0] if N is not None: assert ( topboundary[:4] == "conf" @@ -312,7 +318,7 @@ def __init__( npor=0.3, order=3, ndeg=3, - layers=[0], + layers=None, ): """Element to simulate a building pit with an impermeable wall. @@ -356,6 +362,8 @@ def __init__( layers: list or np.array layers in which impermeable wall is present. """ + if layers is None: + layers = [0] AquiferData.__init__(self, model, kaq, c, z, npor, ltype) self.order = order self.ndeg = ndeg @@ -502,14 +510,14 @@ def __init__( model, xy, kaq=1.0, - c=[], - z=[1, 0], + c=None, + z=None, topboundary="conf", hstar=None, npor=0.3, order=3, ndeg=3, - layers=[0], + layers=None, ): """Element to simulate a building pit with an impermeable wall in ModelMaq. @@ -555,6 +563,12 @@ def __init__( layers: list or np.array layers in which impermeable wall is present. """ + if layers is None: + layers = [0] + if z is None: + z = [1, 0] + if c is None: + c = [] (kaq, c, npor, ltype) = param_maq(kaq, z, c, npor, topboundary) super().__init__( model=model, @@ -578,7 +592,7 @@ def __init__( xy, kaq=1.0, kzoverkh=1.0, - z=[1, 0], + z=None, topboundary="conf", topres=0, topthick=0, @@ -586,7 +600,7 @@ def __init__( npor=0.3, order=3, ndeg=3, - layers=[0], + layers=None, ): """Element to simulate a building pit with an impermeable wall in Model3D. @@ -634,6 +648,10 @@ def __init__( layers: list or np.array layers in which impermeable wall is present. """ + if layers is None: + layers = [0] + if z is None: + z = [1, 0] (kaq, c, npor, ltype) = param_3d(kaq, z, kzoverkh, npor, topboundary, topres) if topboundary == "semi": z = np.hstack((z[0] + topthick, z)) @@ -665,7 +683,7 @@ def __init__( hstar=None, order=3, ndeg=3, - layers=[0], + layers=None, res=np.inf, ): """Element to simulate a building pit with a leaky wall. @@ -714,6 +732,9 @@ def __init__( shape (n_segments,) or (n_layers, n_segments). Default is np.inf, which simulates an impermeable wall. """ + if layers is None: + layers = [0] + super().__init__( model, xy, @@ -745,7 +766,7 @@ def __init__( warn( f"Found resistances smaller than {self.tiny}, " f"these were replaced by {self.tiny}.", - stacklevel=1, + category=UserWarning, ) self.res[self.res < self.tiny] = self.tiny @@ -896,16 +917,22 @@ def __init__( model, xy, kaq=1.0, - z=[1, 0], - c=[], + z=None, + c=None, npor=0.3, topboundary="conf", hstar=None, order=3, ndeg=3, - layers=[0], + layers=None, res=np.inf, ): + if layers is None: + layers = [0] + if c is None: + c = [] + if z is None: + z = [1, 0] (kaq, c, npor, ltype) = param_maq(kaq, z, c, npor, topboundary) super().__init__( model=model, @@ -929,7 +956,7 @@ def __init__( model, xy, kaq=1.0, - z=[1, 0], + z=None, kzoverkh=1.0, npor=0.3, topboundary="conf", @@ -938,7 +965,7 @@ def __init__( hstar=None, order=3, ndeg=3, - layers=[0], + layers=None, res=np.inf, ): """Element to simulate a building pit with a leaky wall in Model3D. @@ -991,6 +1018,10 @@ def __init__( shape (n_segments,) or (n_segments, n_layers). Default is np.inf, which simulates an impermeable wall. """ + if layers is None: + layers = [0] + if z is None: + z = [1, 0] (kaq, c, npor, ltype) = param_3d(kaq, z, kzoverkh, npor, topboundary, topres) if topboundary == "semi": z = np.hstack((z[0] + topthick, z)) diff --git a/timml/inhomogeneity1d.py b/timml/inhomogeneity1d.py index f84bdb61..9a125bd5 100644 --- a/timml/inhomogeneity1d.py +++ b/timml/inhomogeneity1d.py @@ -124,13 +124,17 @@ def __init__( x1, x2, kaq=1, - z=[1, 0], - c=[], + z=None, + c=None, npor=0.3, topboundary="conf", hstar=None, N=None, ): + if c is None: + c = [] + if z is None: + z = [1, 0] self.storeinput(inspect.currentframe()) ( kaq, @@ -193,7 +197,7 @@ def __init__( x1, x2, kaq, - z=[1, 0], + z=None, kzoverkh=1, npor=0.3, topboundary="conf", @@ -202,6 +206,8 @@ def __init__( topthick=0.0, N=None, ): + if z is None: + z = [1, 0] self.storeinput(inspect.currentframe()) ( kaq, diff --git a/timml/linedoublet.py b/timml/linedoublet.py index d498783d..a1e643df 100644 --- a/timml/linedoublet.py +++ b/timml/linedoublet.py @@ -439,7 +439,9 @@ class ImpLineDoubletString(LineDoubletStringBase, DisvecEquation): :class:`.ImpLineDoublet` """ - def __init__(self, model, xy=[(-1, 0), (1, 0)], layers=0, order=0, label=None): + def __init__(self, model, xy=None, layers=0, order=0, label=None): + if xy is None: + xy = [(-1, 0), (1, 0)] self.storeinput(inspect.currentframe()) LineDoubletStringBase.__init__( self, @@ -490,9 +492,9 @@ class LeakyLineDoubletString(LineDoubletStringBase, LeakyWallEquation): :class:`.ImpLineDoublet` """ - def __init__( - self, model, xy=[(-1, 0), (1, 0)], res=np.inf, layers=0, order=0, label=None - ): + def __init__(self, model, xy=None, res=np.inf, layers=0, order=0, label=None): + if xy is None: + xy = [(-1, 0), (1, 0)] self.storeinput(inspect.currentframe()) LineDoubletStringBase.__init__( self, diff --git a/timml/linesink.py b/timml/linesink.py index 1e755b56..6ae71786 100644 --- a/timml/linesink.py +++ b/timml/linesink.py @@ -820,9 +820,9 @@ def plot(self, layer=None): class HeadLineSinkStringOLd(LineSinkStringBase, HeadEquation): - def __init__( - self, model, xy=[(-1, 0), (1, 0)], hls=0.0, layers=0, order=0, label=None - ): + def __init__(self, model, xy=None, hls=0.0, layers=0, order=0, label=None): + if xy is None: + xy = [(-1, 0), (1, 0)] self.storeinput(inspect.currentframe()) LineSinkStringBase.__init__( self, @@ -1053,7 +1053,7 @@ class HeadLineSinkString(LineSinkStringBase2): def __init__( self, model, - xy=[(-1, 0), (1, 0)], + xy=None, hls=0, res=0, wh=1, @@ -1062,6 +1062,8 @@ def __init__( label=None, name="HeadLineSinkString", ): + if xy is None: + xy = [(-1, 0), (1, 0)] self.storeinput(inspect.currentframe()) LineSinkStringBase2.__init__( self, @@ -1201,7 +1203,7 @@ class LineSinkDitchString(HeadLineSinkString): def __init__( self, model, - xy=[(-1, 0), (1, 0)], + xy=None, Qls=1, res=0, wh=1, @@ -1209,6 +1211,8 @@ def __init__( layers=0, label=None, ): + if xy is None: + xy = [(-1, 0), (1, 0)] self.storeinput(inspect.currentframe()) HeadLineSinkString.__init__( self, @@ -1253,7 +1257,7 @@ class LineSinkContainer(Element): Required attributes: lslist: list of line-sinks - nls: total number of line-sinks + nls: total number of line-sinks. """ def __init__( @@ -1419,15 +1423,19 @@ class HeadLineSinkContainer(LineSinkContainer): def __init__( self, model, - xydict={0: [(-1, 0), (1, 0)]}, + xydict=None, hls=0, res=0, wh=1, order=0, - laydict={0: 0}, + laydict=None, label=None, name="HeadLineSinkContainer", ): + if laydict is None: + laydict = {0: 0} + if xydict is None: + xydict = {0: [(-1, 0), (1, 0)]} self.storeinput(inspect.currentframe()) LineSinkContainer.__init__( self, model, layers=0, order=order, name=name, label=label, aq=None @@ -1470,11 +1478,11 @@ def initialize(self): ) self.lslist.append(ls) self.nls = len(self.lslist) - # for i in range(self.nls): - # if self.label is not None: - # lslabel = self.label + "_" + str(i) - # else: - # lslabel = self.label + for i in range(self.nls): + if self.label is not None: + self.label + "_" + str(i) + else: + pass LineSinkContainer.initialize(self) def setparams(self, sol): diff --git a/timml/model.py b/timml/model.py index 9ae05d54..a56ab636 100644 --- a/timml/model.py +++ b/timml/model.py @@ -382,9 +382,10 @@ def velocity(self, x, y, z): def velocomp(self, x, y, z, aq=None, layer_ltype=None): if aq is None: aq = self.aq.find_aquifer_data(x, y) - assert (z <= aq.z[0]) & (z >= aq.z[-1]), "z value not inside aquifer" + if (z > aq.z[0]) or z < (aq.z[-1]): + raise ValueError("z value not inside aquifer") if layer_ltype is None: - layer, ltype, dummy = aq.findlayer(z) + layer, ltype, _ = aq.findlayer(z) else: layer, ltype = layer_ltype h = self.head(x, y, aq=aq) @@ -601,7 +602,11 @@ class ModelMaq(Model): >>> ml = ModelMaq(kaq=[10, 20], z=[20, 12, 10, 0], c=1000) """ - def __init__(self, kaq=1, z=[1, 0], c=[], npor=0.3, topboundary="conf", hstar=None): + def __init__(self, kaq=1, z=None, c=None, npor=0.3, topboundary="conf", hstar=None): + if c is None: + c = [] + if z is None: + z = [1, 0] self.storeinput(inspect.currentframe()) kaq, c, npor, ltype = param_maq(kaq, z, c, npor, topboundary) Model.__init__(self, kaq, c, z, npor, ltype) @@ -661,7 +666,7 @@ class Model3D(Model): def __init__( self, kaq=1, - z=[1, 0], + z=None, kzoverkh=1, npor=0.3, topboundary="conf", @@ -669,6 +674,14 @@ def __init__( topthick=0, hstar=0, ): + """Model3D. + for semi-confined aquifers, set top equal to 'semi' and provide + topres: resistance of top + tophick: thickness of top + hstar: head above top. + """ + if z is None: + z = [1, 0] self.storeinput(inspect.currentframe()) kaq, c, npor, ltype = param_3d(kaq, z, kzoverkh, npor, topboundary, topres) if topboundary == "semi": diff --git a/timml/stripareasink.py b/timml/stripareasink.py index 2dbdbcec..48b01292 100644 --- a/timml/stripareasink.py +++ b/timml/stripareasink.py @@ -118,9 +118,6 @@ def changetrace( u = u1 * (1.0 + eps) # Go just beyond circle else: u = u2 * (1.0 + eps) # Go just beyond circle - # xn = x1 + u * (x2 - x1) - # yn = y1 + u * (y2 - y1) - # zn = xyzt1[2] + u * (xyzt2[2] - xyzt1[2]) xyztnew = xyzt1 + u * (xyzt2 - xyzt1) return changed, terminate, xyztnew, message @@ -248,8 +245,6 @@ def changetrace( u = u1 * (1.0 + eps) # Go just beyond circle else: u = u2 * (1.0 + eps) # Go just beyond circle - # xn = x1 + u * (x2 - x1) - # yn = y1 + u * (y2 - y1) - # zn = xyzt1[2] + u * (xyzt2[2] - xyzt1[2]) + xyzt1[2] + u * (xyzt2[2] - xyzt1[2]) xyztnew = xyzt1 + u * (xyzt2 - xyzt1) return changed, terminate, xyztnew, message diff --git a/timml/trace.py b/timml/trace.py index f7951a75..31d64998 100644 --- a/timml/trace.py +++ b/timml/trace.py @@ -59,6 +59,8 @@ def timtraceline( - "message": termination message - "complete": True if terminated correctly """ + if win is None: + win = [-1e30, 1e30, -1e30, 1e30] verbose = False # used for debugging if win is None: win = [-1e30, 1e30, -1e30, 1e30] diff --git a/timml/util.py b/timml/util.py index 5cbab26c..9e7328f1 100644 --- a/timml/util.py +++ b/timml/util.py @@ -161,9 +161,9 @@ def contour( # color if color is None: c = plt.rcParams["axes.prop_cycle"].by_key()["color"] - elif type(color) is str: + elif isinstance(color, str): c = len(layers) * [color] - elif type(color) is list: + elif isinstance(color, list): c = color if len(c) < len(layers): n = np.ceil(self.aq.naq / len(c)) @@ -179,7 +179,7 @@ def contour( if labels: fmt = "%1." + str(decimals) + "f" plt.clabel(cs, fmt=fmt) - if type(legend) is list: + if isinstance(legend, list): plt.legend(cshandlelist, legend) elif legend: legendlist = ["layer " + str(i) for i in layers] @@ -327,9 +327,9 @@ def tracelines( win = [-1e30, 1e30, -1e30, 1e30] if color is None: c = plt.rcParams["axes.prop_cycle"].by_key()["color"] - elif type(color) is str: + elif isinstance(color, str): c = self.aq.naq * [color] - elif type(color) is list: + elif isinstance(color, list): c = color if len(c) < self.aq.naq: n = int(np.ceil(self.aq.naq / len(c)))