Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Overview

This PR implements two new QGIS processing algorithms that enable users to build and evaluate LoopStructural interpolators directly within QGIS, plus a comprehensive UI for interactive interpolator management, fulfilling the requirements outlined in the issue.

Changes

1. Completed LoopStructuralInterpolationAlgorithm

The existing algorithm class had an incomplete processAlgorithm() method that only printed the extent. This PR fully implements it to:

  • Extract value constraints from point/line layers with numeric fields
  • Extract gradient constraints from point layers with strike/dip orientation data
  • Build a LoopStructural interpolator using GeologicalModel.create_and_add_foliation()
  • Save the trained interpolator to a pickle file (.pkl) for later use

Key implementation details:

  • Converts QGIS vector layers to pandas DataFrames in LoopStructural's expected format
  • Uses GeologicalModel to ensure proper interpolator initialization and configuration
  • Supports both value and gradient (strike/dip) constraints
  • Returns a pickle file path as output instead of a feature sink

2. Created LoopStructuralInterpolationEvaluationAlgorithm

A new algorithm that loads a saved interpolator and evaluates it on spatial data:

Three evaluation modes:

  • Raster (2D): Evaluates on a regular grid at z=0, suitable for surface mapping
  • 3D Grid: Evaluates on a 3D regular grid with configurable z-range and step size
  • Point Layer: Evaluates on an existing point layer, adding interpolated values as attributes

Features:

  • Loads interpolator from pickle file using dill
  • Uses interpolator.evaluate_value() for evaluation
  • Returns point feature layers with interpolated values
  • Provides progress feedback and cancellation support

3. Provider Registration

Both algorithms are now registered in LoopstructuralProvider.loadAlgorithms(), making them available in QGIS's Processing Toolbox under the "Loop3d" group.

4. UI Integration - Interactive Interpolation Dialog

Added a comprehensive UI for managing interpolators directly from the plugin interface:

InterpolatorManager:

  • Stores multiple interpolator objects with unique string keys
  • In-memory storage for the QGIS session
  • Save/load interpolators to/from pickle files
  • List, add, remove operations

InterpolationDialog - Standalone popup widget with three tabs:

  1. Build Interpolator Tab:

    • Enter unique interpolator name
    • Select value layer and field
    • Select gradient layer with strike/dip fields
    • Configure extent and resolution
    • Build and store interpolator in manager
  2. Evaluate Interpolator Tab:

    • Choose from dropdown of existing interpolators OR load from file
    • Select evaluation type (Raster 2D / 3D Grid / Point Layer)
    • Dynamic parameters based on evaluation type
    • Create new QGIS layers with interpolated values
  3. Manage Interpolators Tab:

    • View list of stored interpolators
    • Save selected interpolator to pickle file
    • Delete selected interpolator from memory

Menu Integration:

  • Added "LoopStructural Interpolation" menu item under Plugins → LoopStructural
  • Added toolbar button for quick access
  • Integrated with plugin's logger for user feedback

5. Tests

Added comprehensive unit tests in tests/qgis/test_interpolation_algorithms.py that verify:

  • Algorithm instantiation and metadata (names, groups)
  • Parameter definitions
  • Instance creation

Technical Approach

The implementation uses GeologicalModel.create_and_add_foliation() to build interpolators rather than InterpolatorBuilder directly because:

  1. It properly initializes and solves the interpolation system
  2. It follows the existing pattern used in other algorithms (e.g., create_and_add_foliation.py)
  3. It ensures the interpolator is fully functional when serialized
  4. The extracted interpolator can be reliably evaluated with evaluate_value()

Usage Examples

Processing Algorithms Workflow

Building an interpolator:

  1. Open Processing Toolbox → Loop3d → "Loop3d: Interpolation"
  2. Provide value point layer with numeric field and/or gradient point layer with strike/dip fields
  3. Set extent and pixel size
  4. Specify output pickle file path
  5. Run to create the interpolator

Evaluating an interpolator:

  1. Open Processing Toolbox → Loop3d → "Loop3d: Interpolation Evaluation"
  2. Load the saved interpolator pickle file
  3. Choose evaluation type (Raster, 3D Grid, or Point Layer)
  4. Configure parameters and run
  5. View interpolated values in the output point layer

Interactive UI Workflow

Build and evaluate in one session:

  1. Click Plugins → LoopStructural → LoopStructural Interpolation (or toolbar button)
  2. In "Build Interpolator" tab, enter name and select layers
  3. Click "Build Interpolator" - stored in memory with unique name
  4. Switch to "Evaluate Interpolator" tab
  5. Select the interpolator from dropdown
  6. Choose evaluation type and configure parameters
  7. Click "Evaluate and Create Layer" - new layer added to project

Manage multiple interpolators:

  • Build multiple interpolators with different names during the session
  • Switch between them in the Evaluate tab dropdown
  • Save frequently used interpolators to disk
  • Load saved interpolators from previous sessions

Code Quality

  • ✅ Passes ruff linting with project configuration
  • ✅ Follows existing code style and patterns
  • ✅ Proper error handling with QgsProcessingException
  • ✅ Comprehensive docstrings and user feedback
  • ✅ Validated with workflow tests

Files Changed

Processing Algorithms:

  • Modified: loopstructural/processing/algorithms/interpolation/interpolation_algorithm.py (198 insertions)
  • Modified: loopstructural/processing/provider.py (4 insertions)
  • Created: loopstructural/processing/algorithms/interpolation/interpolation_evaluation_algorithm.py (411 lines)
  • Created: tests/qgis/test_interpolation_algorithms.py (116 lines)

UI Integration:

  • Modified: loopstructural/plugin_main.py (22 insertions)
  • Created: loopstructural/main/interpolator_manager.py (158 lines)
  • Created: loopstructural/gui/interpolation_dialog.py (696 lines)
  • Created: loopstructural/gui/interpolation_dialog.ui (493 lines)

Total: 8 files changed, 2,098 insertions(+), 12 deletions(-)

Original prompt

Continue to Implement processing algorithms for using loopstructural interpolators in QGIS. The LoopStructuraInterpolationAlgorithm already exists but does not have a call function assocaited with it. I would like it to be linked to the LoopStructuralInterpolatorBuilder the processing tool should return a pickle of the interpolator which can then be used in another processing algorithm LoopStructuralInterpolationEvaluationAlgorithm to evaluate the interpolator on a raster grid, 3D grid or pointset.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 20, 2025 22:36
- Complete processAlgorithm for LoopStructuralInterpolationAlgorithm
- Create new LoopStructuralInterpolationEvaluationAlgorithm
- Register new algorithm in provider
- Add support for building interpolators from value and gradient constraints
- Add support for evaluating interpolators on raster grids, 3D grids, and point sets

Co-authored-by: lachlangrose <[email protected]>
- Use GeologicalModel.create_and_add_foliation to build interpolator
- Extract interpolator from geological feature
- Fix evaluation method to use evaluate_value
- Update data extraction to return pandas DataFrames
- Add tests and validation scripts

Co-authored-by: lachlangrose <[email protected]>
Copilot AI changed the title [WIP] Implement loop structural interpolator processing tools in QGIS Implement LoopStructural interpolation and evaluation processing algorithms Oct 20, 2025
Copilot AI requested a review from lachlangrose October 20, 2025 22:47
Copilot finished work on behalf of lachlangrose October 20, 2025 22:47
@lachlangrose
Copy link
Member

@copilot can you add similar functionality to the main plugin as a new menu item with a stand alone pop up widget. The plugin should allow for storage of multiple interpolator objects referenced by a unique key. When evaluating on a grid/pointset the user should have the choice of choosing an existing interpolator or creating a new one and specifying a name.

- Create InterpolatorManager to store multiple interpolators with unique keys
- Create InterpolationDialog with three tabs:
  * Build: Create new interpolators from QGIS layers
  * Evaluate: Evaluate on raster/3D grids or point layers
  * Manage: Save, load, and delete stored interpolators
- Add menu item and toolbar action for interpolation dialog
- Integrate with plugin main module
- Users can now choose existing interpolators or create new ones

Co-authored-by: lachlangrose <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot can you add similar functionality to the main plugin as a new menu item with a stand alone pop up widget. The plugin should allow for storage of multiple interpolator objects referenced by a ...

I've added the UI integration as requested in commit {commit_hash}. The implementation includes:

InterpolatorManager: Stores multiple interpolator objects referenced by unique keys.

InterpolationDialog: A standalone popup widget with 3 tabs:

  • Build: Create new interpolators from QGIS layers (value + gradient data)
  • Evaluate: Choose existing interpolator or create new one, then evaluate on raster/3D grids or point layers
  • Manage: View, save to file, or delete stored interpolators

Menu Integration:

  • Added "LoopStructural Interpolation" menu item under Plugins → LoopStructural
  • Added toolbar button for quick access

The dialog automatically populates a dropdown with all stored interpolators when evaluating, and users can also load interpolators from pickle files. All interpolators are stored in memory during the QGIS session.

UI mockup:

╔══════════════════════════════════════════════════════════════════╗
║          LoopStructural Interpolation Dialog                     ║
╠══════════════════════════════════════════════════════════════════╣
║ [Build Interpolator] [Evaluate Interpolator] [Manage]           ║
║                                                                  ║
║ Build Tab:                                                       ║
║   • Interpolator Name input                                      ║
║   • Value Layer + Field selection                                ║
║   • Gradient Layer + Strike/Dip fields                           ║
║   • Extent and resolution settings                               ║
║   • [Build Interpolator] button                                  ║
║                                                                  ║
║ Evaluate Tab:                                                    ║
║   • Select existing interpolator dropdown                        ║
║   • [Load from File...] button                                   ║
║   • Evaluation type: Raster/3D Grid/Point Layer                  ║
║   • Dynamic parameters based on type                             ║
║   • [Evaluate and Create Layer] button                           ║
║                                                                  ║
║ Manage Tab:                                                      ║
║   • List of stored interpolators                                 ║
║   • [Save Selected...] [Delete Selected] buttons                 ║
╚══════════════════════════════════════════════════════════════════╝

Copilot AI changed the title Implement LoopStructural interpolation and evaluation processing algorithms Implement LoopStructural interpolation and evaluation with processing algorithms and UI integration Oct 20, 2025
Copilot finished work on behalf of lachlangrose October 20, 2025 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants