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.

Download files

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

Source Distribution

threedigrid-2.3.9.tar.gz (123.2 kB view details)

Uploaded Source

Built Distribution

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

threedigrid-2.3.9-py3-none-any.whl (125.7 kB view details)

Uploaded Python 3

File details

Details for the file threedigrid-2.3.9.tar.gz.

File metadata

  • Download URL: threedigrid-2.3.9.tar.gz
  • Upload date:
  • Size: 123.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for threedigrid-2.3.9.tar.gz
Algorithm Hash digest
SHA256 fc6461a09cb1c2559941db74d027ae26552c6a8e5999c4806763761e0f752db2
MD5 1c3d150e2f443fb924f6f7ebabc5f25e
BLAKE2b-256 2aed771eb6b0cf71da7ce45c9fd300638b086be95802a4bbb67247323695e100

See more details on using hashes here.

File details

Details for the file threedigrid-2.3.9-py3-none-any.whl.

File metadata

  • Download URL: threedigrid-2.3.9-py3-none-any.whl
  • Upload date:
  • Size: 125.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for threedigrid-2.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 9f07760b0ac2bdff25eb419b436e31f32836d60c5fea17e5d690d1d196f48ec1
MD5 9c61499287d9b6fee0fbd27c478ab47d
BLAKE2b-256 8e6d1b45212a69f907862789c4fb2a65c1b8c295549143d089f9d9ab5819de4c

See more details on using hashes here.

Release history Release notifications | RSS feed

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