From 345712ffd064cbbb82030e348dfbc82ad15a9f91 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Tue, 16 May 2023 12:21:20 +0200 Subject: [PATCH 1/8] update test return none add extra test for list_names --- tests/test_datasets.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_datasets.py b/tests/test_datasets.py index 44fab47..b8c64d9 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -1,17 +1,21 @@ import pedon as pe -def test_sample_staring_2018(): +def test_sample_staring_2018() -> None: pe.soil.SoilSample().from_staring("B01", year="2018") -def test_sample_staring_2001(): +def test_sample_staring_2001() -> None: pe.soil.SoilSample().from_staring("B02", year="2001") -def test_soil_from_name(): +def test_soil_from_name() -> None: pe.soil.Soil("VS2D_Del Monte Sand").from_name(pe.Brooks) -def test_soil_from_staring(): +def test_soil_from_staring() -> None: pe.soil.Soil("O01").from_staring() + + +def test_soil_list_genuchten() -> None: + pe.soil.Soil.list_names(pe.Genuchten) From e1c56bedda230291e6f0ab40cc0279d90321fa57 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Tue, 16 May 2023 12:21:37 +0200 Subject: [PATCH 2/8] allow label as kwarg --- src/pedon/soilmodel.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index dc4ec18..513fdb7 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -33,7 +33,7 @@ def plot(self, ax: plt.Axes | None = None) -> plt.Axes: @dataclass class Genuchten: - """Mualem- van Genuchten Soil Model + """Mualem-van Genuchten Soil Model van Genuchten, M. Th. (1970) - A Closed-form Equation for Predicting the Hydraulic Conductivity of Unsaturated Soil @@ -294,7 +294,12 @@ def plot_swrc( else: sw = sm.theta(h=h) - ax.plot(sw, -h, label=sm.__class__.__name__, **kwargs) + if "label" in kwargs: + label = kwargs.pop("label") + else: + label = getattr(getattr(sm, "__class__"), "__name__") + + ax.plot(sw, -h, label=label, **kwargs) ax.set_ylim(1e-3, 1e6) ax.grid(True) return ax @@ -315,7 +320,12 @@ def plot_hcf( h = logspace(-6, 10, num=1000) k = sm.k(h=h) - ax.plot(k, h, label=sm.__class__.__name__, **kwargs) + if "label" in kwargs: + label = kwargs.pop("label") + else: + label = getattr(getattr(sm, "__class__"), "__name__") + + ax.plot(k, h, label=label, **kwargs) ax.set_ylim(1e-3, 1e6) ax.set_xlim() ax.grid(True) From c78f28bd379e5617c5abf07eb6c510d0ec35aa3c Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Fri, 11 Aug 2023 16:58:48 +0200 Subject: [PATCH 3/8] add methods to calculate the pressure head from theta only for van genuchten for now --- src/pedon/soilmodel.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index 513fdb7..41ed600 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -26,6 +26,10 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: """Method to calcualte the permeability from the pressure head h""" ... + def h(self, theta: FloatArray) -> FloatArray: + """Method to calcualte the pressure head h from the water content""" + ... + def plot(self, ax: plt.Axes | None = None) -> plt.Axes: """Method to plot the soil water retention curve""" ... @@ -68,6 +72,11 @@ def k_r(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) + def h(self, theta: FloatArray) -> FloatArray: + se = (theta - self.theta_r) / (self.theta_s - self.theta_r) + h = 1 / self.alpha * ((1 / se) ** (1 / self.m) - 1) ** (1 / self.n) + return h + def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -119,6 +128,9 @@ def k_r(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) + def h(self, theta: FloatArray) -> FloatArray: + pass + def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -152,6 +164,9 @@ def k_r(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) + def h(self, theta: FloatArray) -> FloatArray: + pass + def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -193,6 +208,11 @@ def k_r(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) + def h(self, theta: FloatArray) -> FloatArray: + se = (theta - self.theta_r) / (self.theta_s - self.theta_r) + h = 1 / self.alpha * ((1 / se) ** (1 / self.gamma) - 1) ** (1 / self.beta) + return h + def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -259,6 +279,9 @@ def theta_d( def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) + def h(self, theta: FloatArray) -> FloatArray: + pass + def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) From 2d64a2ae9b86faef62ebca5105a5f21fb1ffe149 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Tue, 3 Oct 2023 17:26:42 +0200 Subject: [PATCH 4/8] Update _version.py --- src/pedon/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pedon/_version.py b/src/pedon/_version.py index 27fdca4..81f0fde 100644 --- a/src/pedon/_version.py +++ b/src/pedon/_version.py @@ -1 +1 @@ -__version__ = "0.0.3" +__version__ = "0.0.4" From 7796b5ddf132c01cc06ba0d312b6cdd968e83a41 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Tue, 3 Oct 2023 17:27:20 +0200 Subject: [PATCH 5/8] different calculation for theta_fc use standard literature formula --- src/pedon/soilmodel.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index 41ed600..1f8f7b3 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -3,7 +3,7 @@ import matplotlib.pyplot as plt from numpy import abs as npabs -from numpy import exp, full, linspace, log, logspace +from numpy import exp, full, linspace, log, logspace, log10, ones from ._typing import FloatArray @@ -192,7 +192,11 @@ class Panday: def __post_init__(self): self.sr = self.theta_r / self.theta_s # theta_r / theta_s self.gamma = 1 - 1 / self.beta # m - self.sy = self.theta_s - self.theta_r - self.theta(10**2) + theta_fc = ( + self.beta ** -(0.60 * (2 + log10(self.k_s))) * (self.theta_s - self.theta_r) + + self.theta_r + ) + self.sy = self.theta_s - theta_fc def theta(self, h: FloatArray) -> FloatArray: return (self.sr + self.s(h) * (1 - self.sr)) * self.theta_s From e6cdfd0e7c6aace87e9dfb5799c6700189e331a5 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Wed, 4 Oct 2023 10:05:44 +0200 Subject: [PATCH 6/8] create inverse functions for brooks, garnder and fredlund --- src/pedon/soilmodel.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index 1f8f7b3..2f11621 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -129,7 +129,12 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) def h(self, theta: FloatArray) -> FloatArray: - pass + h = full(theta.shape, self.h_b) + mask = theta >= self.theta_r + h[mask] = self.h_b * ((theta[mask] - self.theta_r) / (self.s(theta[mask]))) ** ( + -1 / self.l + ) + return h def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -165,7 +170,7 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) def h(self, theta: FloatArray) -> FloatArray: - pass + return (abs(theta) / self.a) ** (-1 / self.b) def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -284,7 +289,9 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) def h(self, theta: FloatArray) -> FloatArray: - pass + return self.a * (exp ** (self.theta_s / theta) ** (1 / self.m) - exp(1)) ** ( + 1 / self.n + ) def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) From 9d2add929526c76a463535fedaaeaeea2ea52e37 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Wed, 4 Oct 2023 10:19:19 +0200 Subject: [PATCH 7/8] fix type hints --- src/pedon/soilmodel.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index 2f11621..4be12f4 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -3,7 +3,7 @@ import matplotlib.pyplot as plt from numpy import abs as npabs -from numpy import exp, full, linspace, log, logspace, log10, ones +from numpy import exp, full, linspace, log, logspace, log10, nan from ._typing import FloatArray @@ -129,12 +129,20 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) def h(self, theta: FloatArray) -> FloatArray: - h = full(theta.shape, self.h_b) - mask = theta >= self.theta_r - h[mask] = self.h_b * ((theta[mask] - self.theta_r) / (self.s(theta[mask]))) ** ( - -1 / self.l - ) - return h + if isinstance(theta, float): + if theta >= self.theta_r: + return self.h_b * ((theta - self.theta_r) / (self.s(theta))) ** ( + -1 / self.l + ) + else: + return self.h_b + else: + h = full(theta.shape, self.h_b) + mask = theta >= self.theta_r + h[mask] = self.h_b * ( + (theta[mask] - self.theta_r) / (self.s(theta[mask])) + ) ** (-1 / self.l) + return h def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -170,7 +178,7 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) def h(self, theta: FloatArray) -> FloatArray: - return (abs(theta) / self.a) ** (-1 / self.b) + return (npabs(theta) / self.a) ** (-1 / self.b) def plot(self, ax: plt.Axes | None = None) -> plt.Axes: return plot_swrc(self, ax=ax) @@ -289,7 +297,7 @@ def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: return self.k_s * self.k_r(h=h, s=s) def h(self, theta: FloatArray) -> FloatArray: - return self.a * (exp ** (self.theta_s / theta) ** (1 / self.m) - exp(1)) ** ( + return self.a * (exp(self.theta_s / theta) ** (1 / self.m) - exp(1)) ** ( 1 / self.n ) @@ -309,10 +317,7 @@ def get_soilmodel(soilmodel_name: str) -> Type[SoilModel]: def plot_swrc( - sm: SoilModel, - saturation: bool = False, - ax: plt.Axes | None = None, - **kwargs: dict, + sm: SoilModel, saturation: bool = False, ax: plt.Axes | None = None, **kwargs ) -> plt.Axes: """Plot soil water retention curve""" @@ -342,7 +347,7 @@ def plot_swrc( def plot_hcf( sm: SoilModel, ax: plt.Axes | None = None, - **kwargs: dict, + **kwargs, ) -> plt.Axes: """Plot the hydraulic conductivity function""" From 3b6e9a3526af51998eec4114b3c48c2cba88f0c0 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Wed, 4 Oct 2023 10:20:43 +0200 Subject: [PATCH 8/8] remove unused import --- src/pedon/soilmodel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index 4be12f4..a0f6286 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -3,7 +3,7 @@ import matplotlib.pyplot as plt from numpy import abs as npabs -from numpy import exp, full, linspace, log, logspace, log10, nan +from numpy import exp, full, linspace, log, logspace, log10 from ._typing import FloatArray