diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..9e20ee3 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,30 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install wheel twine build + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python3 -m build + python3 -m twine upload --repository pypi dist/* diff --git a/.gitignore b/.gitignore index c4e8499..77f270c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ - *.pyc +.mypy_cache/ +.pytest_cache/ +.ruff_cache/ +.tox/ + doc/examples/fig/ -.tox/* +doc/literature/ +dist/ src/pedon.egg-info/ + diff --git a/README.md b/README.md index 0b18b63..6a938b1 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,35 @@ *from Greek: πέδον, pedon -> soil* -Python package for (unsaturated) soil properties including pedotransfer functions. This package takes an object-oriented approach to soils, soil samples and soil models. Soil models include: -- Mualem - Van Genuchten -- Brooks - Corey -- Fredlund & Xing -- Gardner -- Sorab Panday (Modflow-USG) +Python package for (unsaturated) soil properties including pedotransfer functions. This package takes an object-oriented approach to soils, soil samples and soil models. Soil models that are available in this package are: + - [Mualem-Van Genuchten](http://www.soilphysics.okstate.edu/teaching/soil-6583/references-folder/van%20Genuchten%201980.pdf) + - [Brooks-Corey](https://www.wipp.energy.gov/library/cra/2009_cra/references/Others/Brooks_Corey_1964_Hydraulic_Properties_ERMS241117.pdf) + - [Fredlund & Xing](http://projects.mans.edu.eg/heepf/ilppp/cources/12/pdf%20course/1/pressure/osmotic%20soilsalinity22.pdf) + - Gardner + - Panday ([Modflow-USG](https://www.gsienv.com/product/modflow-usg/)) + +This package can fit soil water retention curves and using least squares (same as [RETC](https://www.pc-progress.com/Documents/programs/retc.pdf)) to measurements. + +Measurements for different soil properties and parameters are available from these datasets: + - [HYDRUS](https://www2.pc-progress.com/downloads/Pgm_Hydrus3D5/HYDRUS_user_Manual_V5.pdf) + - [VS2D](https://pubs.usgs.gov/wri/1983/4099/report.pdf) + - Staring Series ([2001](https://edepot.wur.nl/43272) & [2018](https://edepot.wur.nl/512761)) + +Additionaly, there are pedotransfer functions implemented such as: + - Van Genuchten: [Wösten](https://www.sciencedirect.com/science/article/pii/S0016706198001323/pdfft?md5=6844f89c07deb81001c2a6eea6fc9e32&pid=1-s2.0-S0016706198001323-main.pdf) + - Van Genuchten: [Staring Series](https://edepot.wur.nl/43272) + - Brooks-Corey: [Cosby](https://hess.copernicus.org/articles/25/2445/2021/hess-25-2445-2021.pdf) + +## Installation +To get the latest stable version install using: + +`pip install pedon` + +To get the development version download the GitHub code to your computer. Use cd to get to the download directory and install using: + +`pip install -e .` + + +## Todo +- [ ] Rosetta Pedotransfer Function +- [ ] Other soil models such as Haverkamp diff --git a/doc/literature/Cooper (2020) - Cosby.pdf b/doc/literature/Cooper (2020) - Cosby.pdf deleted file mode 100644 index a1bb426..0000000 Binary files a/doc/literature/Cooper (2020) - Cosby.pdf and /dev/null differ diff --git a/doc/literature/Genuchten (1980) - A Closed-form Equation for Predicting the Hydraulic Conductivity of Unsaturated Soils.pdf b/doc/literature/Genuchten (1980) - A Closed-form Equation for Predicting the Hydraulic Conductivity of Unsaturated Soils.pdf deleted file mode 100644 index 7891d03..0000000 Binary files a/doc/literature/Genuchten (1980) - A Closed-form Equation for Predicting the Hydraulic Conductivity of Unsaturated Soils.pdf and /dev/null differ diff --git a/doc/literature/Genuchten (1991) - Manual RETC.pdf b/doc/literature/Genuchten (1991) - Manual RETC.pdf deleted file mode 100644 index ca3b28b..0000000 Binary files a/doc/literature/Genuchten (1991) - Manual RETC.pdf and /dev/null differ diff --git a/doc/literature/Heinen (2018) - Staringreeks.pdf b/doc/literature/Heinen (2018) - Staringreeks.pdf deleted file mode 100644 index 913ce94..0000000 Binary files a/doc/literature/Heinen (2018) - Staringreeks.pdf and /dev/null differ diff --git a/doc/literature/Woesten (1999) - Development and use of a database of hydraulic properties of European soils.pdf b/doc/literature/Woesten (1999) - Development and use of a database of hydraulic properties of European soils.pdf deleted file mode 100644 index eb84313..0000000 Binary files a/doc/literature/Woesten (1999) - Development and use of a database of hydraulic properties of European soils.pdf and /dev/null differ diff --git a/doc/literature/Wosten (2001) - Staringreeks.pdf b/doc/literature/Wosten (2001) - Staringreeks.pdf deleted file mode 100644 index 28df1df..0000000 Binary files a/doc/literature/Wosten (2001) - Staringreeks.pdf and /dev/null differ diff --git a/pyproject.toml b/pyproject.toml index 9d2572b..c16a3b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,11 +33,17 @@ pytesting = ["pytest>=7", "pytest-cov", "pytest-sugar"] coveraging = ["coverage"] dev = ["pedon[linting,formatting,typing,pytesting]", "tox"] +[tool.setuptools] +include-package-data = true + [tool.setuptools.dynamic] version = { attr = "pedon._version.__version__" } +[tool.setuptools.packages.find] +where = ["src"] + [tool.setuptools.package-data] -myModule = ["*.xlsx"] +"pedon.datasets" = ["*.xlsx"] [tool.black] line-length = 88 diff --git a/src/pedon/__init__.py b/src/pedon/__init__.py index 7cb327a..3677d6f 100644 --- a/src/pedon/__init__.py +++ b/src/pedon/__init__.py @@ -3,4 +3,4 @@ from . import _params, soil, soilmodel from ._version import __version__ from .soil import Soil, SoilSample -from .soilmodel import Brooks, Fredlund, Gardner, Genuchten, Sorab, plot_hcf, plot_swrc +from .soilmodel import Brooks, Fredlund, Gardner, Genuchten, Panday, plot_hcf, plot_swrc diff --git a/src/pedon/_params.py b/src/pedon/_params.py index 5a7b0a5..e61abaa 100644 --- a/src/pedon/_params.py +++ b/src/pedon/_params.py @@ -66,7 +66,7 @@ ].astype(float) pBrooks.loc[:, "swrc"] = pBrooks.loc[:, "swrc"].astype(bool) -pSorab = DataFrame( +pPanday = DataFrame( data={ "p_ini": { "k_s": 50.0, @@ -102,12 +102,12 @@ }, }, ) -pSorab.loc[:, ["p_ini", "p_min", "p_max"]] = pSorab.loc[ +pPanday.loc[:, ["p_ini", "p_min", "p_max"]] = pPanday.loc[ :, ["p_ini", "p_min", "p_max"] ].astype(float) -pSorab.loc[:, "swrc"] = pSorab.loc[:, "swrc"].astype(bool) +pPanday.loc[:, "swrc"] = pPanday.loc[:, "swrc"].astype(bool) def get_params(sm_name: str) -> DataFrame: - params = {"Genuchten": pGenuchten, "Brooks": pBrooks, "Sorab": pSorab} + params = {"Genuchten": pGenuchten, "Brooks": pBrooks, "Panday": pPanday} return params[sm_name].copy() diff --git a/src/pedon/_version.py b/src/pedon/_version.py index f102a9c..3b93d0b 100644 --- a/src/pedon/_version.py +++ b/src/pedon/_version.py @@ -1 +1 @@ -__version__ = "0.0.1" +__version__ = "0.0.2" diff --git a/src/pedon/soilmodel.py b/src/pedon/soilmodel.py index 87eb330..2ff1716 100644 --- a/src/pedon/soilmodel.py +++ b/src/pedon/soilmodel.py @@ -28,6 +28,12 @@ def plot(self): @dataclass class Genuchten: + """Mualem- van Genuchten Soil Model + + van Genuchten, M. Th. (1970) - A Closed-form Equation for Predicting the + Hydraulic Conductivity of Unsaturated Soil + """ + k_s: float theta_r: float theta_s: float @@ -60,6 +66,11 @@ def plot(self): @dataclass class Brooks: + """Brooks and Corey Soil Model + + Brooks, R.H. and Corey, A.T. (1964) - Hydraulic Properties of Porous Media + """ + k_s: float theta_r: float theta_s: float @@ -103,6 +114,11 @@ def plot(self): @dataclass class Gardner: + """Gardner Soil Model + + Gardner et al (1970) - Post-irrigation movement of soil water + """ + k_s: float theta_r: float theta_s: float @@ -111,25 +127,28 @@ class Gardner: m: float def theta(self, h: FloatArray) -> FloatArray: - return self.theta_r + (self.theta_s - self.theta_r) * self.s(h) + return self.a * npabs(h) ** -self.b def s(self, h: FloatArray) -> FloatArray: - return 1 / (1 + npabs(h / self.a) ** self.b) + return (self.theta(h) - self.theta_r) / (self.theta_s - self.theta_r) def k(self, h: FloatArray, s: FloatArray | None = None) -> FloatArray: if s is not None: - raise NotImplementedError( - "Can only calculate the hydraulic conductivity" - "using the pressure head, not the saturation" - ) - return self.k_s * exp(-self.a * h) + theta = s * (self.theta_s - self.theta_r) + self.theta_r + return self.k_s * self.a * theta**self.m + return self.k_s * (self.a / (self.b + npabs(h) ** self.m)) def plot(self): return plot_swrc(self) @dataclass -class Sorab: +class Panday: + """Panday Soil Model (MODFLOW-USG) + + Panday, S. - USG-Transport: Transport and other Enhancements to MODFLOW-USG + """ + k_s: float theta_r: float theta_s: float @@ -158,6 +177,12 @@ def plot(self): @dataclass class Fredlund: + """Fredlund and Xing Soil Model + + Fredlund, D.G. and Xing, A. (1994) - Equations for the soil-water + characteristic curve + """ + k_s: float theta_s: float a: float diff --git a/tests/test_fit.py b/tests/test_fit.py index 1722b3e..cf444a2 100644 --- a/tests/test_fit.py +++ b/tests/test_fit.py @@ -1,5 +1,6 @@ -from numpy import array import pytest +from numpy import array + import pedon as pe diff --git a/tests/test_ptf.py b/tests/test_ptf.py index e770103..07c1f5e 100644 --- a/tests/test_ptf.py +++ b/tests/test_ptf.py @@ -1,4 +1,5 @@ import pytest + import pedon as pe diff --git a/tests/test_soilmodel.py b/tests/test_soilmodel.py index 4b08aaf..2b97abc 100644 --- a/tests/test_soilmodel.py +++ b/tests/test_soilmodel.py @@ -1,5 +1,6 @@ import pytest from numpy import logspace + import pedon as pe from pedon._typing import FloatArray @@ -18,7 +19,7 @@ def bro() -> pe.soilmodel.SoilModel: @pytest.fixture def sor() -> pe.soilmodel.SoilModel: - return pe.Sorab(k_s=10, theta_r=0.01, theta_s=0.43, alpha=0.02, beta=1.1, brook=3) + return pe.Panday(k_s=10, theta_r=0.01, theta_s=0.43, alpha=0.02, beta=1.1, brook=3) def test_theta_genuchten(gen: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: @@ -45,13 +46,13 @@ def test_k_brooks(bro: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: bro.k(h=h) -def test_theta_sorab(sor: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: +def test_theta_panday(sor: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: sor.theta(h=h) -def test_s_sorab(sor: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: +def test_s_panday(sor: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: sor.s(h=h) -def test_k_sorab(sor: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: +def test_k_panday(sor: pe.soilmodel.SoilModel, h: FloatArray = h) -> None: sor.k(h=h)