Skip to main content

GEOLIB

The GEOLIB is a publicly available Python library developed by Deltares. The GEOLIB provides functionality for the following Deltares software:

  • DFoundations
  • DSettlement
  • DSheetPiling
  • DStability
note

The GEOLIB replaces VIKTOR's D-Series bindings. These bindings won't be removed for now, but there won't follow any updates anymore.

Using GEOLIB

To make use of the GEOLIB, add the following to your requirements.txt:

d-geolib==0.1.6  # or any other available version

For more information on how to use the GEOLIB, see the online documentation.

Executing jobs

All GEOLIB models have an execute() method. However, it's not possible to use this in a VIKTOR app. Fortunately, there is still a way to execute your model, making use of VIKTOR's corresponding analysis class and worker, by serializing your model into VIKTOR's writable File object:

from geolib import DSettlementModel
from pathlib import Path
import viktor as vkt

...
model = DSettlementModel()
# build up your model
...
file = vkt.File() # create a writable file (GEOLIB is going to write to it)
path = Path(file.source) # source returns the path in `str`, GEOLIB requires (in most cases) a Path object
model.serialize(path) # let GEOLIB write the serialized model to the file
dsettlement_analysis = vkt.dsettlement.DSettlementAnalysis(input_file=file) # pass the input file to the analysis as usual
dsettlement_analysis.execute() # requires a worker

The GEOLIB can be used in conjunction with the following VIKTOR analysis classes and workers:

Parsing in-memory data

GEOLIB also features the parsing of output files for the different models. It does however work with paths and includes a check on the file's suffix. If you have in-memory data (e.g. StringIO or BytesIO), you can convert it to a path with suffix by creating a temporary file with NamedTemporaryFile:

note

Creating a temporary path with VIKTOR's File.from_data(...).copy() does not work here, because GEOLIB requires the file path to have a valid suffix.

import os
from geolib import DSettlementModel
from pathlib import Path
from tempfile import NamedTemporaryFile

...
temp_file = NamedTemporaryFile(suffix='.sld', delete=False, mode='wb') # create a temporary file with correct suffix; don't delete on close(); remove mode 'b' in case of StringIO/str
temp_file.write(my_bytesio.getvalue()) # write in-memory content (bytes in this case) to file
temp_file.close() # close (does not delete) the file to ensure the data is actually written to file (instead of kept in buffer)
path = Path(temp_file.name) # name returns the path in `str`, GEOLIB requires (in most cases) a Path object
dsettlement_model = DSettlementModel() # create empty model
dsettlement_model.parse(path) # parse file into DSettlementModel() model
os.remove(temp_file.name) # remove the temporary file to avoid cluttering of files