Skip to main content

Threedigrid: The 3Di grid admin framework

The Python package for the threedigrid administration.

Github Actions status Documentation Status PyPI Anaconda

Overview

Features

  • access to the threedicore administration by a single instance of the GridH5Admin object

  • query the model data by pre-defined subsets and django style filters

  • export model data to gis formats like shapefile, geopackage

  • serialize model data as geojson

Quick start

The standard threedigrid distribution is pretty lightweight, installing as little dependencies as possible. If you want to make use of all capabilities threedigrid has to ofter (e.g. spatial operations and command line tools) install like this:

$ pip install threedigrid[geo,results]

Console scripts

Using the 3digrid_explore shortcut, simply run:

$ 3digrid_explore --grid-file=<path to grid file> --ipy

This will invoke an ipython session with a GridH5Admin instance already loaded.

To get a quick overview of the threedimodels meta data omit the --ipy option or explicitly run:

$ 3digrid_explore --grid-file=<the to grid file> --no-ipy

This will give you output like this:

Overview of model specifics:

model slug:              v2_bergermeer-v2_bergermeer_bres_maalstop-58-b1f8179f1f3c2333adb08c9e6933fa7b9a8cd163
threedicore version:     0-20180315-3578e9b-1
threedi version:         1.63.dev0
has 1d:                  True
has 2d:                  True
has groundwater:         True
has levees:              True
has breaches:            True
has pumpstations:        True

(I)Python shell

Get a grid admin instance:

from threedigrid.admin.gridadmin import GridH5Admin

f = 'gridadmin.h5'
ga = GridH5Admin(f)

The grid admin directly holds some model specific attributes like whether the model has a 1D or 2D or groundwater section:

In [4]: ga.has_groundwater
Out[4]: False

In [5]: ga.has_1d
Out[5]: True

There are different types of filters but a filter, generally speaking, acts on field. That means you can filter by value. If you have a line model instance you can filter the data by the kcu field:

ga.lines.filter(kcu__in=[100,102])

or by the lik value:

ga.lines.filter(lik__eq=4)

The filtering is lazy, that is, to retrieve data you have to call data explicitly:

ga.lines.filter(lik__eq=4).data  # will return an ordered dict

The structure control actions netcdf can also be analyzed and exported using threedigrid:

from threedigrid.admin.gridresultadmin import GridH5StructureControl
from threedigrid.admin.structure_controls.exporters import structure_control_actions_to_csv

gst = GridH5StructureControl("gridadmin.h5", "structure_control_actions_3di.nc")
gst.table_control
structure_control_actions_to_csv(gst, "test.csv")

Remote procedure calls

Currently only the client-side is included. The server-side might be added in a later stage. Note: this is an advanced feature used inside the 3Di stack, probably you don’t need this. Note2: you need Python 3.7 or higher for this to work.

Installation:

$ pip install threedigrid[rpc]

Basic usage:

ga = GridH5ResultAdmin('rpc://REDIS_HOST/SIMULATION_ID', 'rpc://REDIS_HOST/SIMULATION_ID')
# Replace REDIS_HOST and SIMULATION_ID with actual values.
future_result = ga.nodes.filter(lik__eq=4).data
data = await future_result.resolve()

Subscription usage:

subscription = await future_result.subscribe()

async for item in subscription.enumerate():
      # do something with item

Local development

In order to set up a virtual environment, perform the following steps:

Clone the repo and fetch the LFS objects:

git lfs fetch origin refs/remotes/origin/master
git lfs checkout

Install platform dependencies:

sudo apt-get update && sudo apt-get install --yes --no-install-recommends libgdal-dev

Create and activate a virtual environment:

python -m venv ./venv
source ./venv/bin/activate

Install the dependencies. For your distribution, check the dependency matrix in .github/workflows/test.yml. For Python 3.12 on Ubuntu 24:

pip install --disable-pip-version-check --upgrade pip setuptools wheel
pip install -e .[geo,results] GDAL==$(gdal-config --version).* ipython pytest

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Release files for threedigrid 2.3.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for threedigrid 2.3.9
File Size Uploaded
threedigrid-2.3.9.tar.gz 123.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for threedigrid 2.3.9
File Interpreter ABI Platform
threedigrid-2.3.9-py3-none-any.whl Python 3 none any Details

Total release size: 248.9 kB

Release files / threedigrid-2.3.9.tar.gz

Download URL threedigrid-2.3.9.tar.gz
Size 123.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fc6461a09cb1c2559941db74d027ae26552c6a8e5999c4806763761e0f752db2
BLAKE2b-256 checksum
How to use checksums
2aed771eb6b0cf71da7ce45c9fd300638b086be95802a4bbb67247323695e100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / threedigrid-2.3.9-py3-none-any.whl

Download URL threedigrid-2.3.9-py3-none-any.whl
Size 125.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f07760b0ac2bdff25eb419b436e31f32836d60c5fea17e5d690d1d196f48ec1
BLAKE2b-256 checksum
How to use checksums
8e6d1b45212a69f907862789c4fb2a65c1b8c295549143d089f9d9ab5819de4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

2.3.9 This release

2 release files

2.3.8

2 release files

2.3.7

2 release files

2.3.6

2 release files

2.3.5

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.11

2 release files

2.2.10

2 release files

2.2.9

2 release files

2.2.8

2 release files

2.2.7

2 release files

2.2.6

2 release files

2.2.5

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.2

2 release files

2.1.0

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.14

2 release files

1.1.12

2 release files

1.1.10

1 release file

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.27

2 release files

1.0.25

2 release files

1.0.21

2 release files

1.0.20

2 release files

1.0.19

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.14

2 release files

1.0.12

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

0.1.6

2 release files

0.1.5

1 release file

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page