Skip to main content

Simple soil profile for hydrological modelling (particularily SWAP).

Project description

simplesoilprofile

Release Build status codecov Commit activity License

A Python package for working with soil profile data in hydrological modeling applications, particularly focused on SWAP model integration.

Features

  • Object-oriented representation of soil layers and profiles with Pydantic validation
  • Support for van Genuchten parameters and physical soil properties
  • Integration with the SWAP model input format
  • API integration framework with example implementation for Belgian DOV
  • Visualization tools for soil profile display

Quick Start

Creating a Soil Profile

from simplesoilprofile import SoilLayer, SoilProfile

# Create soil layers
topsoil = SoilLayer(
    name="Topsoil",
    description="Sandy loam topsoil",
    theta_res=0.02,
    theta_sat=0.4,
    alpha=0.02,
    n=1.5,
    k_sat=10.0,
    texture_class="sandy loam",
    clay_content=10.0,
    silt_content=20.0,
    sand_content=70.0,
)

subsoil = SoilLayer(
    name="Subsoil",
    description="Clay loam subsoil",
    theta_res=0.05,
    theta_sat=0.45,
    alpha=0.01,
    n=1.3,
    k_sat=5.0,
    texture_class="clay loam",
    clay_content=30.0,
    silt_content=35.0,
    sand_content=35.0,
)

# Create a profile
profile = SoilProfile(
    name="Test Profile",
    layers=[topsoil, subsoil],
    layer_depths={
        0: (0, 30),    # Topsoil from 0-30 cm
        1: (30, 100),  # Subsoil from 30-100 cm
    },
    x=100.0,
    y=200.0,
    z=5.0,
)

Generating SWAP Input

from simplesoilprofile.models.swap import write_swap_soil_file

# Write to a SWAP soil file
with open("soil.swp", "w") as f:
    write_swap_soil_file(profile, f)

Fetching Data from DOV API

from simplesoilprofile.api import DOVClient

# Create a client
client = DOVClient()

# Fetch a profile
profile = client.fetch_profile("profile_id")

Visualizing a Profile

import matplotlib.pyplot as plt
from simplesoilprofile.plotting import plot_profile

# Create a new figure
fig, ax = plt.subplots(figsize=(8, 12))

# Plot the profile
plot_profile(profile, ax=ax, show_properties=True)
plt.show()

API Integration

The package includes a flexible API integration framework that can be configured using YAML files. Here's an example configuration for a new data source:

base_url: "https://api.example.com"
endpoint: "/soil-data"
method: "GET"
response_type: "json"
layer_path: "$.data.layers"

field_mappings:
  name: "$.id"
  description: "$.description"
  texture_class: "$.texture"
  clay_content: "$.clay_percentage"
  silt_content: "$.silt_percentage"
  sand_content: "$.sand_percentage"

Contributing

First, create a repository on GitHub with the same name as this project, and then run the following commands:

git init -b main
git add .
git commit -m "init commit"
git remote add origin git@github.com:zawadzkim/simplesoilprofile.git
git push -u origin main

Finally, install the environment and the pre-commit hooks with

make install

You are now ready to start development on your project! The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.

To finalize the set-up for publishing to PyPI or Artifactory, see here. For activating the automatic documentation with MkDocs, see here. To enable the code coverage reports, see here.

Releasing a new version

  • Create an API Token on PyPI.
  • Add the API Token to your projects secrets with the name PYPI_TOKEN by visiting this page.
  • Create a new release on Github.
  • Create a new tag in the form *.*.*.
  • For more details, see here.

Repository initiated with fpgmaas/cookiecutter-poetry.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplesoilprofile-0.0.2.tar.gz (258.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplesoilprofile-0.0.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file simplesoilprofile-0.0.2.tar.gz.

File metadata

  • Download URL: simplesoilprofile-0.0.2.tar.gz
  • Upload date:
  • Size: 258.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for simplesoilprofile-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0e47fe94b17873703285329f593404efc6de9cd014d761e38e4ff80d5cfd1261
MD5 d6f91ab114ea9e41c74512b18522f4fd
BLAKE2b-256 7764a0678b7de00fddae30c6b84d04f30789da5648fda6434d40ed1c64154bf5

See more details on using hashes here.

File details

Details for the file simplesoilprofile-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for simplesoilprofile-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41a3238dc8cf15893af56af90a2a6ba3757832ec8c73969f213c229811dadac2
MD5 8dbfc479e76eac3cb6c8ef51a7dcb014
BLAKE2b-256 599ae4af39e2dc6d349fc2417b0358b2ecad6b18ca999d910ca4a8763f7a0786

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page