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 pathlib import Pathfrom viktor import Filefrom viktor.external.dsettlement import DSettlementAnalysisfrom geolib import DSettlementModel...model = DSettlementModel()# build up your model...file = 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 objectmodel.serialize(path)  # let GEOLIB write the serialized model to the filedsettlement_analysis = DSettlementAnalysis(input_file=file)  # pass the input file to the analysis as usualdsettlement_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 osfrom tempfile import NamedTemporaryFilefrom pathlib import Pathfrom geolib import DSettlementModel...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/strtemp_file.write(my_bytesio.getvalue())  # write in-memory content (bytes in this case) to filetemp_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 objectdsettlement_model = DSettlementModel() # create empty modeldsettlement_model.parse(path)  # parse file into DSettlementModel() modelos.remove(temp_file.name)  # remove the temporary file to avoid cluttering of files