Skip to main content

Generate a 3Di simulation grid from a model schematisation.

Project description

threedigrid-builder

Github Actions status PyPI

Generate a 3Di simulation grid from a model schematisation.

Usage

This library converts a model schematisation to a 3Di simulation grid. This can be done using a single function that reads data from an SQLite and TIFF and then outputs the generated grid into a Geopackage or HDF5 file:

>>> from threedigrid_builder import make_gridadmin
>>> sqlite_path = "/path/to/model.sqlite"
>>> dem_path = "/path/to/dem.tiff"
>>> out_path = "grid.gpkg"  # or "something.h5" for HDF5 output
>>> make_gridadmin(sqlite_path, dem_path, out_path)

Alternatively, the generated grid can be output in-memory:

>>> make_gridadmin(sqlite_path, dem_path)
{'nodes': {'id': array([   1,    2,    3, ..., 7903, 7904, 7905], dtype=int32), ...}

Installation

This package is distributed as binary only, because its (Fortran) source code is proprietary. The currently supported platforms are Windows, Linux, and OSX, all 64 bit versions only.

First install sqlite and spatialite libraries, e.g. on Ubuntu:

$ sudo apt-get install sqlite3 libsqlite3-mod-spatialite

For raster input, there are two options: GDAL and rasterio. If you do not have GDAL (and its Python bindings) present, be sure to include the [rasters] extra dependency while installing threedigrid-builder. If you have GDAL present, this can be omitted.

Install the threedigrid-builder:

$ pip install threedigrid-builder[rasters]

For output into a file for the 3Di calculationcore, enable gridadmin output:

$ pip install threedigrid-builder[rasters,gridadmin]

For output into Geopackage for display in e.g. QGis, enable gpkg output:

$ pip install threedigrid-builder[rasters,gpkg]

Changelog of threedigrid-builder

0.12.0 (2021-12-27)

  • Add drain_level of manholes to gridadmin.

  • Bugfix: Set culvert calculation_type to isolated when not provided.

0.11.0 (2021-12-22)

  • Accept dist_calc_points <= 0; the effect is that there are no interpolated nodes.

  • Ignore grid refinements with NULLs in their type or geometry fields.

  • Ignore (impervious) surfaces, grid refinements, and dem averages areas with invalid geometries (mostly, polygons with self-intersections).

  • Set ds1d of 1d2d lines to 2d cell_width.

0.10.0 (2021-12-21)

  • Bugfix: Added support for refinement geometries within smallest Grid cell.

  • Reverse the order of coordinates in channel and culvert geometries if necessary.

0.9.2 (2021-12-17)

  • Temporarily disable groundwater.

  • Bugfix: Edge case with connected points.

0.9.1 (2021-12-16)

  • Bugfix: use DEM epsg_code for 2D models.

  • Bugfix: Small fix for lgrtot.

  • Bugfix: Small fix adding groundwater cells.

  • Bugfix: Fix pump.line remapping in case of embedded nodes.

  • Bugfix: Remap surface_map.cci on grid.sort().

  • Bugfix: also need to evaluate embedded nodes for connection node mapping for zero-d surface maps.

  • Added pixel_width to groundwater nodes.

0.9.0 (2021-12-15)

  • Add padding to area_mask for creating quadtree.

  • Added groundwater 2D nodes, 2D vertical lines, and 2D groundwater lines.

  • Bugfix: cross section tabulate used wrong width/height.

0.8.3 (2021-12-09)

  • Only process cross section definitions that are actually used.

  • Removed cross1 & cross2 in the in-memory or geopackage output and added cross_id1 and cross_id2.

  • Fixed bug where writing a single line geometry or geometries of equal size would result in an incorrect cast to a numpy object dtype.

  • Fixed bug with zero-d administration cci (index needs to be 1-based), removed cid field.

0.8.2 (2021-12-05)

  • Fixed the Linux wheel distribution. These are now built with manylinux2014 instead of manylinux2010.

0.8.1 (2021-12-05)

  • Added support for zero-d administration including surfaces and impervious surfaces.

  • Dropped support for Python 3.6.

  • Fixed __version__ attribute and “threedigrid_builder_version” HDF5 attribute.

  • Set the dpumax of a 1D line (channel, pipe, culvert, weir, orifice) always to the largest of its two invert levels. Previously, it was set to the largest of the two bottom_levels of the two adjacent nodes, which gave wrong results for lines attached to manholes.

  • Disable extrapolation for channel node/line attributes that are derived from crosssection locations.

  • Disable the SchematisationError when a Manhole has a bottom_level above a level of a connected object. Instead, emit a warning through the logger.

0.8.0 (2021-11-30)

  • Added has_max_infiltration_capacity flag.

  • Added breaches and levees.

  • Implement GDAL as an alternative to RasterIO.

  • Check the raster EPSG code and use it if the model does not have one.

  • Removed ‘model_area_path’ feature from application.

  • Added an in-memory output interface. Supply out_path=None to instead of writing the grid to a file, receive the grid as dictionaries of 1D ndarrays.

  • Removed the “sqlalchemy<1.4” constraint, this library is compatible with SQLAlchemy 1.4

0.7.0 (2021-11-25)

  • Raise SchematisationError on invalid settings.

  • Removed SchematisationError on tabulated rectangle cross section definition with zero first “width” value.

  • Add calculation_type for nodes to be Dem averaged.

0.6.1 (2021-11-10)

  • Fixed l1dtot (exclude 1D boundaries).

0.6.0 (2021-11-09)

  • Raise SchematisationError on embedding linear objects that begin/end outside of 2D domain. Added tests for edge cases.

  • Fixed exchange_level (dpumax) for 1D2D lines attached to non-manhole connection nodes. The exchange_level is now derived from the bank_levels of attached channels.

  • Add discharge_coefficients for structures.

  • Swap the order in lines.line for 1D2D lines. The order is now (2D, 1D).

  • Fixed kcu for lines attached to 1D boundary conditions.

  • Copy crest_level from v2_levee if a v2_connected_point refers to one.

0.5.2 (2021-11-02)

  • Consistently write NaN (and not -9999.0) in gridadmin float datasets.

  • Fix tests with GEOS 3.10.0

  • Make ‘meta’ group complete.

0.5.1 (2021-11-01)

  • Add storage_area to calculation nodes.

  • Added ds1d_half to nodes.

  • Added has_embedded to attrs.

0.5.0 (2021-10-21)

  • Fixed nodes.is_manhole in the gridadmin output.

  • Handle user-supplied 1D-2D lines (connected point / calculation point).

  • Write initial_waterlevel for 1D nodes and add ‘has_initial_waterlevels’ to meta.

0.4.0 (2021-09-23)

  • Added 1D boundary conditions.

  • Added 2D boundary conditions.

  • Enable compression in HDF5 output.

  • Fixed 2D lines that connect a larger to a smaller cell in south east direction.

0.3.1 (2021-08-16)

  • Handle embedded connection nodes. These are removed from the grid and written to a new dataset “nodes_embedded”.

  • Fixed bug with cross sections tables being None in Grid instance

  • Handle embedded channels, pipes and culverts. Embedded objects result in embedded nodes and and lines with kcu LINE_1D_EMBEDDED between between 2D cells.

  • Fixed a bug with lines that connect nodes to themselves in quadtree generation.

  • Fixed a bug with wrong usage of lines.ds1d in bottom level and cross section weights computation. The added attribute lines.s1d is now used, and for clarity nodes.ds1d was renamed to nodes.s1d.

  • Added invert_level_start_point and invert_level_end_point attributes to lines.

  • Fixed coordinate order in lines.line_geometries field in gridadmin.h5.

0.3.0 (2021-07-28)

  • Read and convert cross section definitions.

  • Solve gridadmin off-by-one errors for pumps.

  • Add ‘dmax’ to nodes output.

  • Changed external API function name to “make_gridadmin”.

0.2.1 (2021-07-20)

  • Fixed issue when reprojecting 0 grid refinements with pyproj 2.*

  • Fixed issue when writing 0 pumps with h5py 2.*

  • Fixed missing transpose when writing pumps.coordinates to HDF5.

  • Added obstacles.

0.2.0 (2021-07-15)

  • Added threedigrid_builder.grid.geo_utils with segmentize and line_substring functions. These are used to compute the Lines.line_geometries for channel lines.

  • Fixed a bug in the refinement areas code (Fortran) on Ubuntu 20.04.

  • Added the Pipes model that is able to compute Nodes & Lines from Pipes. Pipes are also included in the calculation_type and bottom_level computations.

  • Added 1D-2D lines for connection nodes, manholes, and channels.

  • Added culverts, orifices, and weirs.

  • Added pumps (pumpstations).

  • Settings and metadata are read from the SQLite. Some metadata (like model_slug) can also be provided via the main (make_grid) function. The metadata is written to the root ‘attrs’ of the output gridadmin.h5. The settings are written into datasets inside newly addres groups “grid_settings” and “tables_settings”.

  • Fixes for models with no channels.

  • Add an optional progress callback.

0.1.2 (2021-04-28)

  • Added public API with 1 function: threedigrid_builder.make_grid.

0.1.1 (2021-04-20)

  • Fixed automatic PyPI upload.

0.1.0 (2021-04-20)

  • Partially ported functionality from inpy (generate 3di files, makegrid): 1D channel grid (including calculation_type and bottom_level), and 2D open water grid.

  • Added gridadmin and geopackage output.

  • Breaking change: the interpolation between cross section locations (channels) now also extrapolates for lines and nodes that are not in between two connection nodes. This happens only if the channel has at least 2 cross section locations. When extrapolatic, the line.cross_weight is less than 0 or greater than 1.

  • Breaking change: missing or empty values in float datasets in the output gridadmin are now denoted by NaN (not-a-number) instead of -9999.0.

  • Breaking change: integers in the output gridadmin are now always 32-bit (instead of sometimes 32-bit and sometimes 64-bit).

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

threedigrid_builder-0.12.0-cp310-cp310-win_amd64.whl (872.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

threedigrid_builder-0.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

threedigrid_builder-0.12.0-cp310-cp310-macosx_10_9_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

threedigrid_builder-0.12.0-cp39-cp39-win_amd64.whl (870.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

threedigrid_builder-0.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

threedigrid_builder-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

threedigrid_builder-0.12.0-cp38-cp38-win_amd64.whl (889.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

threedigrid_builder-0.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

threedigrid_builder-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

threedigrid_builder-0.12.0-cp37-cp37m-win_amd64.whl (887.9 kB view details)

Uploaded CPython 3.7m Windows x86-64

threedigrid_builder-0.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

threedigrid_builder-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file threedigrid_builder-0.12.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 872.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 405130ef33f1f9d0a33d5bd3ce0594b83d5ac04076d18dc1c76da3e8aed4dc09
MD5 ed750910deddfa727714a29df3be4ea7
BLAKE2b-256 4fef0a8e670166a2d8d8a759d32f35bce415f2109b2fb07a6b5b90337b1d55a7

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for threedigrid_builder-0.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 508f03676fdefde4841edf49b7ae577c11f7e7b75a940dd994ea876e8bd4f8da
MD5 53554d722015b485a34d4336705b84e5
BLAKE2b-256 d53c6948095ea1955038ddff661cc072af6f6f3207a9e4397fb7b26f6aaafa9d

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a1d50c47be38f11c2a16be518589b2a1f4d7198affc14cc4817e9840958e0be4
MD5 0e2270d265573155b6085a53ff7646fb
BLAKE2b-256 19d699a7fb1026c82685085e562b33dc3bd2f4ba793f4a8a13853a2fa2bc7e25

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 870.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2abe0f0829bb8cc8a3cd3ef8a5b67fb8a613288cf11021e1f51b8623957ed67d
MD5 cda530e58281052ae4f426920e121836
BLAKE2b-256 a893aaae771fa59205a183e08610490e1fd5774f0758fafb2e6a15537e24224c

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for threedigrid_builder-0.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aeedfa3c949d1e8f0de1d0ea79cd93f7e96180c1d04e400f1c86ffd5eb076050
MD5 8ae8a120030fe263e3fa2e99a4f46038
BLAKE2b-256 5021cd7572f40444368e594e72a8b46d55c0163ed5d24aeaa71ac1d09776c763

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 77fd6d0b28f42f0e48711388b0e54e27c3178cbaf3f2a73d75fce7e563a0867e
MD5 e83373e29e6efa3184af4b1631ae167d
BLAKE2b-256 14b84e961b72dc75ff418fef20f4ac7f0f8a8e82a390eb0ee174243a4c5ea961

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 889.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5b0621fe9db494f73ed2d3f7fafbb7581dfa457967ad5dbb67f1e084fcb7f7b8
MD5 fecc6119a6bde970d830363cc33f8e56
BLAKE2b-256 7b51def35d0569dc74680ef0254e827f9a4b0bb5c7ea575d5f5a9d53481e980c

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for threedigrid_builder-0.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e899c248a7d64b5b73d91ac2ee8b6b288a8d2ceb48f8b73e864e3bf72976289
MD5 f4296540e5c110a87b911f9e7b5fdd43
BLAKE2b-256 646a9b6c7604b3e2a3abb9ebacb474f7ff75994bc000cea531277afb50d559bf

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2db2c2d06a1b70ed0665ac47cf904e3c6f30def54c0f26fd426a8244fc8ba04b
MD5 27f8367fb6115bbf3c4a2c1a59fc0833
BLAKE2b-256 5c2eaa5e1552158faee82532a64286f34e73a3b35520ac04016f9cd67450136e

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 887.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ff96d105cbab6c8ea0ff15da29d1ce38dd1b27e731672794cea3b32f5851975c
MD5 c60f0e1cc38465437f907ba11828bf46
BLAKE2b-256 6cb6baf30b3fab5250b5285bca37ec107ac7d61108a2f2d58325f28d855efa6b

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for threedigrid_builder-0.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e31e6a512fcdef8d02cf53447e25fdda550a02670328db810f2188eb523bd7c5
MD5 7fa0a5f8415c80ca5e7fed307ad73fff
BLAKE2b-256 bfd185fb5c8890fd827ebe413362706f0d2eeb80d6484e68013f3062ca212af2

See more details on using hashes here.

File details

Details for the file threedigrid_builder-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: threedigrid_builder-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for threedigrid_builder-0.12.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0cae8469f3a8a0648505433af0d52a75095a4f67a29a432b357506afbefb12a6
MD5 865b5830c54eb3254dae91fa2e2a8510
BLAKE2b-256 40dec0cd378972d0655562de90e4d71628750bb2e6fca97e09dbf65ac5cf4a1f

See more details on using hashes here.

Supported by

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