Skip to content

Commit

Permalink
Structure Python packages (#123)
Browse files Browse the repository at this point in the history
Moves ribasim_lumping from scripts to src, adds pyproject.toml and
readme. For the other packages we now all switch to using hatchling
building, and adding them all as editable dependencies to pixi.

Only ribasim_lumping doesn't load yet due to #122. Though this is good
to merge.
  • Loading branch information
visr authored Aug 6, 2024
1 parent 6ea29f2 commit c64ec7e
Show file tree
Hide file tree
Showing 37 changed files with 5,359 additions and 188 deletions.
1 change: 0 additions & 1 deletion open-vscode-dev.bat

This file was deleted.

1 change: 0 additions & 1 deletion open-vscode.bat

This file was deleted.

5,251 changes: 5,128 additions & 123 deletions pixi.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ app = "bokeh serve web_app --show --dev --port 5007"

[feature.common.dependencies]
bokeh = ">=3.0"
contextily = "*"
fiona = "*"
geocube = "*"
geopandas = "*"
Expand Down Expand Up @@ -67,18 +68,21 @@ shapely = ">=2"
tomli = "*"
tomli-w = "*"
types-requests = "*"
xugrid = "*"

[feature.common.pypi-dependencies]
bokeh_helpers = { path = "src/bokeh_helpers", editable = true }
hydamo = { path = "src/hydamo", editable = true }
peilbeheerst_model = { path = "src/peilbeheerst_model", editable = true }
ribasim_lumping = { path = "src/ribasim_lumping", editable = true }
ribasim_nl = { path = "src/ribasim_nl", editable = true }
bokeh_helpers = { path = "src/bokeh_helpers", editable = true }

# [feature.dev.pypi-dependencies]
# ribasim = { path = "../Ribasim/python/ribasim", editable = true }
[feature.dev.pypi-dependencies]
ribasim = { path = "../Ribasim/python/ribasim", editable = true }

[feature.prod.dependencies]
ribasim = "==2024.10.0"

[environments]
default = { features = ["common", "prod"] }
# dev = { features = ["common", "dev"] }
dev = { features = ["common", "dev"] }
1 change: 1 addition & 0 deletions src/bokeh_helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Helpers for building Bokeh dashboards.
2 changes: 1 addition & 1 deletion src/bokeh_helpers/bokeh_helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.1.0"
16 changes: 5 additions & 11 deletions src/bokeh_helpers/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "bokeh-helpers"
name = "bokeh_helpers"
description = "helpers for building bokeh dashboards"
readme = "README.md"
authors = [
Expand All @@ -20,11 +20,5 @@ dynamic = ["version"]
[project.optional-dependencies]
tests = ["pytest"]

[tool.setuptools]
zip-safe = true

[tool.setuptools.dynamic]
version = { attr = "bokeh_helpers.__version__" }

[tool.setuptools.packages.find]
include = ["bokeh_helpers"]
[tool.hatch.version]
path = "bokeh_helpers/__init__.py"
17 changes: 4 additions & 13 deletions src/hydamo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "hydamo"
Expand All @@ -20,17 +20,8 @@ dynamic = ["version"]
[project.optional-dependencies]
tests = ["pytest"]

[tool.setuptools]
zip-safe = true

[tool.setuptools.dynamic]
version = { attr = "hydamo.__version__" }

[tool.setuptools.packages.find]
include = ["hydamo"]

[tool.setuptools.package-data]
"hydamo" = ["**/*.csv", "**/*.qml", "**/*.sld", "**/*.json"]
[tool.hatch.version]
path = "hydamo/__init__.py"

[project.urls]
Documentation = "https://deltares.github.io/Ribasim-NL/HyDAMO"
Expand Down
28 changes: 7 additions & 21 deletions src/peilbeheerst_model/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "peilbeheerst_model"
description = "functions to derive a Ribasim network from a hydro-dataset"
readme = "README.md"
authors = [
{ name = "Guy Dupuits", email = "[email protected]" },
{ name = "Jerom Aerts", email = "[email protected]" },
{ name = "Ron Bruijns", email = "[email protected]" },
{ name = "Jerom Aerts", email = "[email protected]" },
{ name = "Ron Bruijns", email = "[email protected]" },
]
license = { text = "MIT" }

requires-python = ">=3.10"
dependencies = [
"geopandas",
"numpy",
"pandas",
"pydantic",
"shapely",
"tqdm",
]
dependencies = ["geopandas", "numpy", "pandas", "pydantic", "shapely", "tqdm"]
dynamic = ["version"]

[project.optional-dependencies]
tests = ["pytest"]

[tool.setuptools]
zip-safe = true

[tool.setuptools.dynamic]
version = { attr = "peilbeheerst_model.__version__" }

[tool.setuptools.packages.find]
include = ["peilbeheerst_model"]

[tool.hatch.version]
path = "peilbeheerst_model/__init__.py"

[project.urls]
Documentation = "https://deltares.github.io/Ribasim-NL/Peilbeheerst-model"
Expand Down
136 changes: 136 additions & 0 deletions src/ribasim_lumping/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# PyCharm .idea-folder
.idea/*

# Windows command-files
*.cmd
*.bat
29 changes: 29 additions & 0 deletions src/ribasim_lumping/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ribasim-lumping

This python package is used to develop an aggregated Ribasim network (Deltares, https://github.com/Deltares/Ribasim). Documentation: https://deltares.github.io/Ribasim/

This code was integrated into the Ribasim-NL repository after development in https://github.com/harm-nomden-sweco/ribasim_lumping.

### Objective
This python-package provides functions to translate a D-Hydro or a HyDAMO network into a simplified (aggregated/lumped) Ribasim-network:
- The user provides a list of locations where the network should be split, resulting into sub-networks which are called 'basins'';
- For these basins relations regarding waterlevel-watersurface-watervolume are calculated;
- Exchange of watervolume (flow) between basins takes place via these split locations.
- Stage-discharge relations are generated to define flow-rates between basins.

### Dependencies
Most important dependencies:
- NETWORKX (https://networkx.org/, Hagberg et al., 2008)
- UGRID (https://github.com/Deltares/UGridPy)
- XUGRID (https://github.com/Deltares/xugrid)

### Installation
We will make this package accessible via pypi. It is recommended to clone this repository because it is under development and it includes some example notebooks. We are still working on tests and test data, etc.

### Development, contributions and licences
This package is developed by Sweco (contributors: Harm Nomden and Tessa Andringa) when working on a TKI-project (top consortia for knowledge and innovation) within the NHI programme (Dutch Hydrological Instruments programme). This focuses on the development, testing and application of the new Ribasim-model (https://tkideltatechnologie.nl/project/oppervlaktewatermodule-nhi/).
It is possible to contribute, create issues, start discussions. We will respond as soon as possible.
This package is developed under the MIT license. Reference to this package: Ribasim-Lumping (Sweco, 2023).

### References:
Aric A. Hagberg, Daniel A. Schult and Pieter J. Swart, “Exploring network structure, dynamics, and function using NetworkX”, in Proceedings of the 7th Python in Science Conference (SciPy2008), Gäel Varoquaux, Travis Vaught, and Jarrod Millman (Eds), (Pasadena, CA USA), pp. 11–15, Aug 2008
32 changes: 32 additions & 0 deletions src/ribasim_lumping/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ribasim_lumping"
description = "Aggregate a HyDAMO or D-Hydro network into a simplified Ribasim network"
readme = "README.md"
authors = [
{ name = "Harm Nomden", email = "[email protected]" },
{ name = "Tessa Andringa", email = "[email protected]" },
]
license = { text = "MIT" }

requires-python = ">=3.10"
dependencies = [
"contextily",
"geopandas",
"matplotlib",
"networkx",
"numpy",
"pandas",
"pydantic",
"ribasim",
"shapely",
"xarray",
"xugrid",
]
dynamic = ["version"]

[tool.hatch.version]
path = "ribasim_lumping/__init__.py"
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__version__ = "0.1.0"

from ribasim_lumping.ribasim_lumping import create_ribasim_lumping_network

__all__ = ["create_ribasim_lumping_network"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 5 additions & 12 deletions src/ribasim_nl/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ribasim_nl"
description = "functions to work with python classes you typically find in hydro-datasets"
readme = "README.md"
authors = [
{ name = "Daniel Tollenaar", email = "[email protected]" },
{ name = "Martijn Visser", email = "[email protected]" }
{ name = "Martijn Visser", email = "[email protected]" }
]
license = { text = "MIT" }

Expand All @@ -21,15 +21,8 @@ dynamic = ["version"]
[project.optional-dependencies]
tests = ["pytest"]

[tool.setuptools]
zip-safe = true

[tool.setuptools.dynamic]
version = { attr = "ribasim_nl.__version__" }

[tool.setuptools.packages.find]
include = ["ribasim_nl"]

[tool.hatch.version]
path = "ribasim_nl/__init__.py"

[project.urls]
Documentation = "https://deltares.github.io/Ribasim-NL"
Expand Down
2 changes: 1 addition & 1 deletion src/ribasim_nl/ribasim_nl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.1"
__version__ = "0.1.0"

from ribasim_nl.cloud import CloudStorage
from ribasim_nl.model import Model
Expand Down

0 comments on commit c64ec7e

Please sign in to comment.