Skip to content

Commit

Permalink
Use ruff to format and lint (#114)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Huite authored Sep 25, 2024
1 parent 21b3467 commit be235cf
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 102 deletions.
6 changes: 5 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Migrate code style to black
998b86fc128e35f1506e3d4facb169c558679bde
998b86fc128e35f1506e3d4facb169c558679bde

# Migrate code style to ruff
a11f92ff2732d7fdc548559f15f009e4a3d5ea7a
571e4b5af45bd1ca6f025dd883b9ea800acb4aef
71 changes: 39 additions & 32 deletions examples/timml_notebook0_sol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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).
Expand All @@ -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,
)
Expand All @@ -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).

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()))


Expand All @@ -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()))


Expand All @@ -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
Expand All @@ -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")


Expand All @@ -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")


Expand Down
5 changes: 5 additions & 0 deletions examples/workshop_nhv/vlaketunnel_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
def test_import():
pass

print(timml.__version__)


if __name__ == "__main__":
test_import()
2 changes: 1 addition & 1 deletion tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
64 changes: 51 additions & 13 deletions timml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# --version number
__name__ = "timml"
__author__ = "Mark Bakker"

# Import all classes and functions
from . import bessel
from .circareasink import CircAreaSink
Expand All @@ -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,
Expand All @@ -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")
2 changes: 1 addition & 1 deletion timml/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
3 changes: 0 additions & 3 deletions timml/circareasink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit be235cf

Please sign in to comment.