Skip to content

Commit

Permalink
Merge pull request #1 from martinvonk/dev
Browse files Browse the repository at this point in the history
Update main to version 0.0.2
  • Loading branch information
martinvonk authored Mar 10, 2023
2 parents 624d8f3 + c480786 commit 1c44719
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 28 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -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/*
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

*.pyc

.mypy_cache/
.pytest_cache/
.ruff_cache/
.tox/

doc/examples/fig/
.tox/*
doc/literature/
dist/
src/pedon.egg-info/


38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file removed doc/literature/Cooper (2020) - Cosby.pdf
Binary file not shown.
Binary file not shown.
Binary file removed doc/literature/Genuchten (1991) - Manual RETC.pdf
Binary file not shown.
Binary file removed doc/literature/Heinen (2018) - Staringreeks.pdf
Binary file not shown.
Binary file not shown.
Binary file removed doc/literature/Wosten (2001) - Staringreeks.pdf
Binary file not shown.
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pedon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/pedon/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion src/pedon/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.2"
41 changes: 33 additions & 8 deletions src/pedon/soilmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from numpy import array
import pytest
from numpy import array

import pedon as pe


Expand Down
1 change: 1 addition & 0 deletions tests/test_ptf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

import pedon as pe


Expand Down
9 changes: 5 additions & 4 deletions tests/test_soilmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from numpy import logspace

import pedon as pe
from pedon._typing import FloatArray

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

0 comments on commit 1c44719

Please sign in to comment.