sec_interp.core.validation package

class sec_interp.core.validation.ProjectValidator

Bases: object

Orchestrates validation of project parameters independent of the GUI.

Level 2: Business Logic Validation. Uses ValidationContext to accumulate errors and verify cross-field dependencies.

classmethod crs_compatibility_warning(params: ValidationParams) → str

Return a CRS-mismatch warning for the configured layers, or "".

Non-blocking: QGIS reprojects on the fly, but a mismatch can degrade accuracy (and, for rasters, sampling intervals expressed in the wrong CRS). The first valid configured layer is used as reference, so the DEM (if present) leads the comparison.

classmethod crs_plausibility_error(params: ValidationParams) → str

Return a blocking message for mislabelled-CRS suspects, or "".

Best-effort heuristic on layer extents (see crs_plausibility). A wrong CRS label produces silently wrong profiles, so it is treated as a hard error rather than a warning.

classmethod is_dem_complete(params: ValidationParams) → bool

Check if DEM configuration is complete.

classmethod is_drillhole_complete(params: ValidationParams) → bool

Check if required fields are filled if drillhole layers are selected.

classmethod is_geology_complete(params: ValidationParams) → bool

Check if geology configuration is complete.

classmethod is_structure_complete(params: ValidationParams) → bool

Check if structural configuration is complete.

classmethod section_geometry_error(params: ValidationParams) → str

Return the section-line geometry error, or an empty string.

Shared by the core pipeline and the GUI gating (semaphore / preview enablement) so both stay on the same rule.

classmethod validate_all(params: ValidationParams) → bool

Perform a comprehensive validation of all project parameters.

classmethod validate_preview_requirements(params: ValidationParams) → bool

Validate only the minimum requirements needed to generate a preview.

class sec_interp.core.validation.ValidationParams(raster_layer: LayerMetadata | None = None, band_number: int | None = None, line_layer: LayerMetadata | None = None, line_vertex_count: int | None = None, line_length: float | None = None, section_feature_id: int | None = None, output_path: str = '', scale: float = 1.0, vert_exag: float = 1.0, buffer_dist: float = 0.0, outcrop_layer: LayerMetadata | None = None, outcrop_field: str | None = None, struct_layer: LayerMetadata | None = None, struct_dip_field: str | None = None, struct_strike_field: str | None = None, dip_scale_factor: float = 1.0, collar_layer: LayerMetadata | None = None, collar_id: str | None = None, collar_use_geom: bool = True, collar_x: str | None = None, collar_y: str | None = None, survey_layer: LayerMetadata | None = None, survey_id: str | None = None, survey_depth: str | None = None, survey_azim: str | None = None, survey_incl: str | None = None, interval_layer: LayerMetadata | None = None, interval_id: str | None = None, interval_from: str | None = None, interval_to: str | None = None, interval_lith: str | None = None)

Bases: object

Data container for all parameters that need cross-layer validation.

Layers are held as detached LayerMetadata produced by the GUI ValidationExtractor adapter.

band_number: int | None = None
buffer_dist: float = 0.0
collar_id: str | None = None
collar_layer: LayerMetadata | None = None
collar_use_geom: bool = True
collar_x: str | None = None
collar_y: str | None = None
dip_scale_factor: float = 1.0
interval_from: str | None = None
interval_id: str | None = None
interval_layer: LayerMetadata | None = None
interval_lith: str | None = None
interval_to: str | None = None
line_layer: LayerMetadata | None = None
line_length: float | None = None
line_vertex_count: int | None = None
outcrop_field: str | None = None
outcrop_layer: LayerMetadata | None = None
output_path: str = ''
raster_layer: LayerMetadata | None = None
scale: float = 1.0
section_feature_id: int | None = None
struct_dip_field: str | None = None
struct_layer: LayerMetadata | None = None
struct_strike_field: str | None = None
survey_azim: str | None = None
survey_depth: str | None = None
survey_id: str | None = None
survey_incl: str | None = None
survey_layer: LayerMetadata | None = None
vert_exag: float = 1.0
sec_interp.core.validation.implausible_crs_reason(metadata: LayerMetadata | None) → str

Return a human-readable reason if the CRS looks mislabelled, else "".

Parameters:

metadata – Detached layer metadata (extent populated by the GUI extractor).

Returns:

A message describing the mismatch, or an empty string when the CRS is plausible or cannot be judged.

sec_interp.core.validation.validate_angle_range(value: float, field_name: str, min_angle: float = 0.0, max_angle: float = 360.0) → tuple[bool, str]

Validate that an angle value is within the expected range.

Parameters:
  • value – The angle value to validate.

  • field_name – Name of the field for error messages.

  • min_angle – Minimum allowed angle (default 0.0).

  • max_angle – Maximum allowed angle (default 360.0).

Returns:

(is_valid, error_message)

Return type:

tuple

sec_interp.core.validation.validate_crs_compatibility(metadata_list: list[LayerMetadata]) → tuple[bool, str]

Validate that a list of layers have compatible Coordinate Reference Systems.

If layers have different CRSs, it returns a warning message instead of an error.

sec_interp.core.validation.validate_field_exists(metadata: LayerMetadata, field_name: str | None) → tuple[bool, str]

Validate that a specific field exists in a layer.

Parameters:
  • metadata – The detached layer metadata.

  • field_name – The name of the field to search for.

Returns:

(is_valid, error_message)

Return type:

tuple

sec_interp.core.validation.validate_field_type(metadata: LayerMetadata, field_name: str, expected_types: list[FieldType]) → tuple[bool, str]

Validate that a field in a layer has one of the expected data types.

Parameters:
  • metadata – The detached layer metadata.

  • field_name – The name of the field to check.

  • expected_types – List of allowed FieldType values.

Returns:

(is_valid, error_message)

Return type:

tuple

sec_interp.core.validation.validate_integer_input(value: str, min_val: int | None = None, max_val: int | None = None, field_name: str = 'Value', allow_empty: bool = False) → tuple[bool, str, int | None]

Validate an integer input string from a text field.

Parameters:
  • value – The string value to validate.

  • min_val – Optional minimum value allowed.

  • max_val – Optional maximum value allowed.

  • field_name – Name of the field for error messages.

  • allow_empty – Whether to allow an empty string.

Returns:

(is_valid, error_message, int_value)

Return type:

tuple

sec_interp.core.validation.validate_layer_geometry(metadata: LayerMetadata, expected_type: str) → tuple[bool, str]

Validate that a vector layer matches the expected geometry type.

sec_interp.core.validation.validate_layer_has_features(metadata: LayerMetadata) → tuple[bool, str]

Validate that a vector layer contains at least one feature.

sec_interp.core.validation.validate_numeric_input(value: str, min_val: float | None = None, max_val: float | None = None, field_name: str = 'Value', allow_empty: bool = False) → tuple[bool, str, float | None]

Validate a numeric input string from a text field.

Parameters:
  • value – The string value to validate.

  • min_val – Optional minimum value allowed.

  • max_val – Optional maximum value allowed.

  • field_name – Name of the field for error messages.

  • allow_empty – Whether to allow an empty string.

Returns:

(is_valid, error_message, float_value)

Return type:

tuple

sec_interp.core.validation.validate_output_path(path: str) → tuple[bool, str, Path | None]

Validate that an output path is a valid directory and currently writable.

This is a convenience wrapper around validate_safe_output_path() for general directory validation.

Parameters:

path – The path string to validate.

Returns:

(is_valid, error_message, resolved_path)
  • is_valid: True if the directory is valid and writable.

  • error_message: Error details if validation fails.

  • resolved_path: Absolute Path object if valid, else None.

Return type:

tuple

sec_interp.core.validation.validate_raster_band(metadata: LayerMetadata, band_number: int) → tuple[bool, str]

Validate that a specified band number exists in the raster layer.

sec_interp.core.validation.validate_reasonable_ranges(values: dict[str, Any]) → list[str]

Check for unreasonable or potentially erroneous parameter values.

This function does not return hard errors, but a list of warning strings to inform the user about extreme values (e.g., vertical exaggeration > 10).

Parameters:

values – Dictionary containing parameter names and their current values.

Returns:

A list of warning messages. If empty, all values are reasonable.

sec_interp.core.validation.validate_safe_output_path(path: str, base_dir: Path | None = None, must_exist: bool = False, create_if_missing: bool = False) → tuple[bool, str, Path | None]

Validate an output path string with security and path traversal protection.

sec_interp.core.validation.validate_structural_requirements(metadata: LayerMetadata, dip_field: str | None, strike_field: str | None, context: ValidationContext | None = None) → tuple[bool, str]

Validate structural layer requirements (geometry and attribute fields).

Submodules