Validation

class groundhog.general.validation.Validator(validationspec, outputonerrorspec)[source]

The Validator has the following features

  • Automatic handling of validation errors

  • Automatic handling of function output upon errors

  • Possibility to override the default validation dictionary with custom validation

groundhog.general.validation.check_layer_overlap(df, raise_error=True, z_from_key=None, z_to_key=None)[source]

Checks possible overlap on a dataframe :param df: Dataframe with keys ‘z from [m]’ and ‘z to [m]’. Other keys can be used but then the arguments z_from_key and z_to_key need to be provided. :param raise_error: Boolean determining whether an error needs to be raised or whether a warning is sufficient (default behaviour is to raise an error warning) :param z_from_key: Key for start depth of the layer :param z_to_key: Key for end depth of the layer :return: Default behaviour: raises a warning if there are overlaps or gaps.

groundhog.general.validation.map_args(method, var, *args, **kwargs)[source]

Constructs a data structure with all parameters, their values and the validation parameters which need to be used during validation.

Parameters:
  • method – The function for which validation will be applied

  • var – The validation data structure, entered as argument of the function decorator

  • args – function arguments

  • kwargs – function keyword arguments

:returns dictionary var_validation which is a copy of the validation data structure

it is possible to override __min and __max arguments

groundhog.general.validation.validate_boolean(var_name, value)[source]

Validates whether a variable can be used as a boolean

groundhog.general.validation.validate_float(var_name, value, min_value=None, max_value=None)[source]

Validates whether a variable can be used as a floating point number and whether it is within specified bounds If a value equals one of the bounds, the validation passes

groundhog.general.validation.validate_integer(var_name, value, min_value=None, max_value=None)[source]

Validates whether a variable can be used as an integer and whether it is within specified bounds If a value equals one of the bounds, the validation passes

groundhog.general.validation.validate_list(var_name, value, elementtype=None, order=None, unique=None, empty_allowed=None)[source]

Validates whether a list contains numbers. It allows checking whether these numbers are ascending or descending and whether non-unique values exist

groundhog.general.validation.validate_string(var_name, value, options=None, regex=None)[source]

Validates whether a variable can be used as a string. The routine also allows checking whether the string is in a list of strings or whether it matches a specific regex pattern