Processing GEF files
Classes have been created to simplify usage of GEF files such as a data access class (GEFData
) that includes
visualization of GEF measurement data, or classification of soil layout. All classes and functions can be imported from
the viktor.geo
module. For more detailed examples, please check the docstring of the
functions.
GEFFile
class
The GEFFile
object is used to parse the file content of GEF files and convert the
data to dictionary or GEFData
object. The data is split into 'measurement_data' and 'headers' category. For
'measurement_data' the compulsory fields are 'Rf', 'qc' and 'elevation'. These are automatically always returned and
stored when parsing a GEF file. Additional columns can be requested from the controller by specifying them in the parse
call using the keyword "additional_columns". The height reference- and coordinate system are parsed from the gef file
and return in the properties "height_system" and "coordinate_system". Any property relating with a reference relates to
the height_system value. In general the following definitions (taken from the norm) are used:
- depth is always a positive number, denoting vertical distance from start of measurement to end
- length is always a positive number, denoting distance measured along path of measurement
- elevation is the vertical position of a measurement wrt to a reference datum. (so reference_datum_height - depth), can be partially positive and negative
GEFFile.parse
needs to be mocked within the
context of (automated) testing.
GEFData
class
GEFData
is a data class to simplify the usage of GEF data. A GEFData
object can
directly be initiated with the dictionary that is created by the GEFFile
class. All keys from 'measurement_data' and
'headers' are set as attributes of the GEFData
object, and are therefore directly accessible.
The measurement data can be used to determine the soil types with
classify(method: Type[ClassificationMethod], return_soil_layout_obj: bool = True)
. Currently, the
RobertsonMethod
and TableMethod
are supported for soil
classification. The properties of all possible soil types need to be provided when calling the classify
method in
order to create a SoilLayout
.
GEFData.classify
needs to be mocked within the
context of (automated) testing.
GEF visualization
For easy visualization of GEF data, a helper function is created. A code example is provide below:
import viktor as vkt
class Controller(vkt.Controller):
@vkt.ImageView("GEF plot", duration_guess=5)
def visualize(self, params, **kwargs):
gef_data = ...
soil_layout_original = ...
soil_layout_user = ...
svg_image = vkt.geo.gef_visualization(self.gef_data, self.soil_layout_original, self.soil_layout_user, as_file=True)
return vkt.ImageResult(svg_image)
If the standard helper function does not satisfy the requirements, it is possible to create your own matplotlib.
GEFData
has get_resistance_visualization(axes: matplotlib.pyplot.Axes)
and
get_cone_visualization(axes: matplotlib.pyplot.Axes)
functions, while SoilLayout
has
get_visualization(axes: matplotlib.pyplot.Axes)
. All functions require a matplotlib Axes
object that are stateful,
and therefore the visualization functions do not return. Example to use one of the visualization functions is shown
below:
import viktor as vkt
import matplotlib.pyplot as plt
class Controller(vkt.Controller):
@vkt.ImageView("GEF plot", duration_guess=5)
def visualize(self, params, **kwargs):
gef_data = ...
# Create main figure
fig = plt.figure(figsize=(8.27, 11.69))
# Define contour (rectangle) for cone visualization, and create Axes object that can be modified by functions
rect_cone = [0.1, 0.1, 0.4, 0.9] # [left, bottom, width, height]
cone_axes = plt.axes(rect_cone)
# Modify created Axes objects
gef_data.get_cone_visualization(cone_axes)
# Convert to SVG for visualization
svg_data = StringIO()
fig.savefig(svg_data, format='svg', bbox_inches='tight', pad_inches=0.8)
plt.close()
return vkt.ImageResult(svg_data)
Soil structure
A general purpose soil structure has been introduced that is being used by the GEF parser, namely Soil
, SoilLayer
and SoilLayout
. A SoilLayout
is a collection of SoilLayer
objects, which contain a Soil
, top and bottom of
layer as attributes. Extra properties can be added to the Soil
class to provide more (geotechnical) information.
Properties can be stored on Soil
and SoilLayer
object by calling update_properties
and providing a dict with the
relevant parameters.
A SoilLayout
can be manually created using the __init__(self, soil_layers: List[SoilLayer])
function, but in order
to simplify storage of the object in the database class methods have been created. To store the object in the database
the function serialize()
can be used. For re-initialization of SoilLayout
the function
from_dict(cls, soil_layout_dict: Dict[str, List])
can be used.