Commit Graph
42 Commits
Author SHA1 Message Date
Magne Sjaastad 7222d6360e Scripting: read GeoMech time steps, result names and values 2026-10-23 09:28:19 +02:00
Kristian Bendiksen 54c5ef7dad #14772 Python: Add GeoMechCase.create_well_bore_stability_plot as object method and forward createWellBoreStabilityPlot to it
RimGeoMechCase_createWellBoreStabilityPlot takes a WellPath object and
a time step and returns the plot. WBS parameters cannot be passed as a
method argument (child objects are not supported as gRPC method
parameters), so the C++ setter is available for the Ricf forwarder and
the Python wrapper copies a WbsParameters object into the created
plot's Parameters child instead.

The Python wrapper moves from Case to GeoMechCase, accepts both a
WellPath object and (deprecated) a well path name, and keeps the
optional parameters argument.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen 147a60ceec #14772 Python: Add Project.import_formation_names and Case.set_formation_names as object methods and forward importFormationNames to them
The legacy command combined import and assignment with an applyToCaseId.
This is split into RimProject_importFormationNames (returns the
FormationNames object) and RimCase_setFormationNames (takes the
object). RimFormationNames is made scriptable so it can be returned and
passed. RicfImportFormationNames forwards to both.

Project.import_formation_names() in Python keeps its signature, now
returns the FormationNames object, and gains an apply_to_all_cases
flag (default True, matching the old behavior).
Case.import_formation_names() is kept and emits a DeprecationWarning.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen cc1f09b665 #14772 Python: Add EclipseCase.create_saturation_pressure_plots as object method and forward createSaturationPressurePlots to it
RimEclipseResultCase_createSaturationPressurePlots exposes the time step
(the legacy command hardcodes 0) and returns an error when no plots
could be created. It only shows the plot window when a GUI is running;
the legacy code dereferenced RiaGuiApplication::instance()
unconditionally. RicfCreateSaturationPressurePlots resolves the cases
and loops, treating per-case failures as warnings as before.

The hand-written Case.create_saturation_pressure_plots() Python wrapper
is removed since the generated EclipseCase method shadows it.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen dbd9e50f5f #14772 Python: Add EclipseCase.export_flow_characteristics as object method and forward exportFlowCharacteristics to it
RimEclipseResultCase_exportFlowCharacteristics has the same arguments
as the legacy command (lists only, no scalar shorthand).
RicfExportFlowCharacteristics forwards to it.

The hand-written Case.export_flow_characteristics() Python wrapper is
removed: the generated EclipseCase method has the same name and
argument names and shadows it for all cases the command applies to.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen 6e3e6e738f #14772 Python: Add Reservoir.create_multiple_fractures as object method and forward createMultipleFractures to it
RimEclipseCase_createMultipleFractures takes WellPath objects and a
FractureTemplate object instead of names and ids. The
MultipleFractures::Action enum is moved from the Ricf header to
RicCreateMultipleFracturesFeature.h so the object method does not
depend on CommandFileInterface, and is registered as the Python
StrEnum MultipleFracturesAction.

Add RicfForwarding::findFractureTemplate(). RicfCreateMultipleFractures
resolves names/ids and forwards to the object method.

The hand-written Case.create_multiple_fractures(template_id=...,
well_path_names=...) Python wrapper is removed: the generated
Reservoir method has the same name and shadows it. The test is updated
to the object based signature.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen e54363133e #14772 Python: Add Reservoir.create_lgr_for_completions and export_lgr_for_completions as object methods
RimEclipseCase_createLgrForCompletions and
RimEclipseCase_exportLgrForCompletions take WellPath objects and
expose refinement and split type. Lgr::SplitType is registered as the
Python StrEnum LgrSplitType. RicfCreateLgrForCompletions forwards to
the create method. Case.create_lgr_for_completion() in Python is kept
and emits a DeprecationWarning.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen b40d19f55f #14772 Python: Add Reservoir.export_msw_completions as object method and forward exportMsw to it
RimEclipseCase_exportMswCompletions takes WellPath objects and an
explicit export folder. RicfExportMsw resolves the well path name and
export folder and forwards to it. Case.export_msw() in Python is kept
and emits a DeprecationWarning.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen afe8f39f6b #14772 Python: Add Reservoir.export_completions as object method and forward exportWellPathCompletions to it
RimEclipseCase_exportCompletions takes WellPath objects (empty list
means all visible well paths) and an explicit export folder, and
exposes all completion export settings. The existing enums
ExportSplit, CompdatExport and PressureDepletionWBHPSource are
registered as Python StrEnums CompletionExportSplit,
CompdatExportType and TransScalingWbhpSource.

RicfExportWellPathCompletions resolves well path names to objects and
the export folder from the command file executor, then forwards to the
object method. Case.export_well_path_completions() in Python is kept
and emits a DeprecationWarning.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen d2078613a8 #14772 Python: Add Reservoir.export_property as object method and forward exportProperty to it
RimEclipseCase_exportProperty writes a cell property to a GRDECL style
text file and requires an explicit export file. RicfExportProperty
resolves the default file name from the command file executor's
PROPERTIES export folder and forwards to it.

The hand-written Case.export_property() wrapper is removed. The
generated Reservoir.export_property() has the same argument names and
shadows the base class wrapper anyway, so a deprecation shim would
never be reached.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen 77c32a3fa5 #14772 Python: Add snapshot export object methods and forward exportSnapshots to them
- Add RimViewWindow_exportSnapshot on RimViewWindow (3D views and
  plots) with explicit ExportFolder, Prefix, Width, Height and
  FileFormat parameters. Generated as ViewWindow.export_snapshot().
- Add RimProject_exportSnapshots for exporting all views and/or plots
  with a ContentType parameter. Generated as Project.export_snapshots().
- Add RiaDefines::SnapshotFileFormat and SnapshotContentType enums,
  registered as Python StrEnums.
- Extract single-item exportSnapshotOfView()/exportSnapshotOfPlot()
  from the RicSnapshotAll*ToFileFeature loops so the object methods
  and the legacy loops share the implementation.
- RicfExportSnapshots resolves the export folder from the command file
  executor and forwards to the object methods.

Python: the hand-written ViewWindow.export_snapshot() wrapper is
removed (generated method is compatible). PlotWindow.export_snapshot()
and Project.export_snapshots() keep their legacy argument names
(file_prefix, output_format, snapshot_type, plot_format) as deprecated
aliases. Case.export_snapshots_of_all_views() is deprecated in favor
of View.export_snapshot().

Also fix Case.views(), which compared the view id to the case id and
therefore never returned any views.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen bdef98203b #14772 Python: Add Case.create_view as object method and forward createView to it
RimCase_createView creates a 3D view in an Eclipse or GeoMech case and
returns it. RicfCreateView forwards to it and wraps the view id in the
legacy createViewResult. The hand-written Python create_view() wrapper
is removed since the generated method has the same name and signature.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen 3eb63c0b8e #14772 Python: Add Case.replace_grid and forward replaceCase to it
First step in modernizing the command file interface: move the
implementation of legacy Ricf commands into object-oriented Rimc
methods, and let the Ricf command forward to them.

- Add RimCase_replaceGrid (PdmVoidObjectMethod on RimCase) with
  NewGridFile and optional ProjectFile parameters. Works for both
  Eclipse result cases and GeoMech cases. Generated in Python as
  Case.replace_grid().
- Add RicfCommandForwarding helpers for resolving ids to objects and
  converting std::expected results to PdmScriptResponse.
- RicfSingleCaseReplace::execute() now resolves the case and the
  executor's last project path, then forwards to RimCase_replaceGrid.
  Command file syntax and Commands.proto are unchanged.
- Case.replace() in Python is kept as a thin wrapper over
  replace_grid() and emits a DeprecationWarning.
2026-09-22 14:19:23 +02:00
Kristian Bendiksen 01ceb57323 #14001 Python: Drop hand-written PropertyType, use auto-generated PropertyType
Consolidate the hand-written PropertyType / NNCPropertyType enums in
enums.py into the auto-generated StrEnum classes that already exist in
generated_classes.py. enums.py and all its imports are removed.

The auto-generated class for caf::AppEnum<RiaDefines::ResultCatType>
was named "ResultType" because the existing scriptable m_resultType
fields used keyword "ResultType". Switch those fields to
CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault, keeping the XML
keyword "ResultType" (so project files still load) but exposing the
script keyword as "PropertyType". The generator now emits a single
PropertyType StrEnum that:

- matches the proto PropertyType for setters (FLOAT/INTEGER aside, the
  members callers actually use are identical),
- gains ALLAN_DIAGRAMS that the C++ side already knew about,
- loses the proto-only REMOVED/UNDEFINED sentinels (unused in any
  Python caller).

rips.NNCPropertyType was exported but unreferenced anywhere — dropped.

Updated Python callers:
- rips.ResultType.X -> rips.PropertyType.X across examples and tests.
- result_type= kwarg / .result_type attribute -> property_type /
  .property_type (the script keyword change renamed those everywhere
  the affected PdmObject fields are accessed from Python).
- view.apply_cell_result's hand-written wrapper now takes property_type
  instead of result_type and forwards via cell_result.property_type.

All 271 Python tests pass, ruff and clang-format clean.
2026-05-26 08:23:28 +02:00
Kristian Bendiksen 8971ebfc9c #14001 Python: Auto-generate StrEnum return types for scriptable methods
Replace the hand-written PropertyDataType wrapper with first-class enum
return support in the code generator. Scriptable methods that derive
from the new caf::PdmEnumObjectMethod<T> template return a typed enum
value across the gRPC boundary; the Python generator emits a StrEnum
class with the texts pulled from the underlying caf::AppEnum<T> and
wraps the call site so callers receive `EnumClass(value)` directly.

caf::PdmDataContainerEnum is the small PdmObject the framework uses to
carry the enum text on the wire (single scriptable QString field).
RimcEclipseCase_propertyDataType becomes declarative: implement
executeEnum() returning the typed RiaDefines::ResultDataType and pick a
returnEnumScriptName() — the base handles serialization and reports
the four AppEnum members (UNKNOWN, FLOAT, DOUBLE, INTEGER) to the
generator.

Drop the hand-written PropertyDataType in enums.py — the generated one
in resinsight_classes is wire-equivalent and now the single source of
truth.
2026-05-26 08:23:28 +02:00
Kristian Bendiksen 740b59702b #14001 Python: Wrap property_data_type to return PropertyDataType enum
The auto-generated stub returns a DataContainerString, forcing call
sites to use .values[0]. Add a hand-written wrapper on Reservoir
(which both EclipseCase and the other reservoir types inherit from)
that unwraps the single-value container and returns the typed
PropertyDataType so a caller can simply write

    case.property_data_type(...) == rips.PropertyDataType.INTEGER

Update the round-trip tests to use the cleaner form.
2026-05-26 08:23:28 +02:00
Kristian Bendiksen ddcfef736b Python: Add filtered_cells API for evaluating a data filter on a case
Adds case.filtered_cells(filter, time_step, grid_index) which applies any
RimCellFilter to an Eclipse case and returns a per-cell 0/1 mask. The mask
length and ordering match case.grid_property(..., grid_index), so callers
can combine the two vectors element-wise.

Implemented as a scriptable Rimc method (PdmVoidObjectMethod) on
RimEclipseCase that writes the mask via the existing key-value store, with
a thin Python wrapper mirroring the visible_cells() pattern. No proto or
gRPC service changes.
2026-05-15 08:37:46 +02:00
Kristian Bendiksen 1424a6dc53 #13982 Python: Add type hints to remaining methods in case.py
Extend type annotations across the rest of rips.case beyond the property
and enum methods typed in the previous commit. Adds parameter and return
types to the command wrappers (replace, export_*, create_*, import_*),
the simple getters (time_steps, reservoir_boundingbox,
distance_to_closest_fault, days_since_start, view, views, create_view,
simulation_wells, coarsening_info), the selected-cells and NNC accessors
(selected_cells*, nnc_connections*, nnc_connections_{static,dynamic,
generated}_values*), and the private grpc helpers
(__custom_init__, __request, __generate_property_input_iterator,
__generate_property_input_chunks, __nnc_connections_values_async,
__nnc_values_generator_to_list, __generate_nnc_property_input_chunks).

Uses Iterator[X] for grpc streaming responses, List[X] for collected
sequences, the proto message types from Case_pb2 / Properties_pb2 /
NNCProperties_pb2 / Definitions_pb2 for typed payloads, Optional and
Union[str, List[str]] for nullable or coerced-list parameters, and Any
for the heterogeneous _execute_command return values. No runtime
behavior changes; mypy --strict is clean on case.py.
2026-05-13 13:47:40 +02:00
Kristian Bendiksen 79914f2a00 #13982 Python: Type case API with StrEnum classes for proto enums
The previous commit auto-generated StrEnum classes for caf::AppEnum scriptable
fields, but the hand-written gRPC API in rips.case still accepted bare strings
for proto-backed enums (PropertyType, PropertyDataType, NNCPropertyType) and
the AppEnum-backed PorosityModelType.

Add a new rips.enums module with hand-written StrEnum classes for the three
proto-only enums and reuse the auto-generated PorosityModelType from
resinsight_classes. Re-export the new enums from the rips package and narrow
the parameter type hints across cell_count, cell_info_for_active_cells,
available_properties, active_cell_property, selected_cell_property,
grid_property, set_active_cell_property, set_grid_property,
active_cell_centers, active_cell_corners, set_nnc_connections_values, and
grid_property_for_positions (sync and async variants).

Existing string arguments keep working because StrEnum members are strings
and protobuf's EnumTypeWrapper.Value accepts both. A new
test_10k_grid_property_strenum asserts string and enum forms return the same
data.
2026-05-13 13:47:40 +02:00
Kristian Bendiksen f8d180f48d #9336 Python: Improve error reporting from gRPC to client
Surface gRPC failure context to Python script authors instead of
silently returning sentinel values or raising bare gRPC errors.

- RipsError now carries code/details/location and a from_rpc_error()
  helper. Existing single-arg construction stays valid.
- Stop swallowing grpc.RpcError in case.__grid_count for non-NOT_FOUND
  failures and in instance._check_connection_and_version, so the
  underlying status is propagated.
- pdmobject add_method decorator and _call_pdm_method_* attach
  code/details to the raised RipsError; existing message text is
  preserved so pytest match=... assertions keep working.
- Instance.start_heartbeat / stop_heartbeat / check_alive provide an
  opt-in background ping that flips a sticky lost-connection flag and
  raises a readable RipsError from check_alive() if the server dies.
- Server side: GetPdmObject in RiaGrpcAppService, RiaGrpcCaseService
  and RiaGrpcProjectService no longer return Status::OK with an empty
  reply when the underlying object is missing; they return NOT_FOUND
  / INTERNAL with a descriptive message. Other RiaGrpc*Service files
  audited and already return non-OK with text on error paths.
2026-05-04 20:03:39 +02:00
Magne Sjaastad 75c1cedaec #13806 Python: Add API for creating discrete grid properties
Add a data_type parameter to set_active_cell_property, set_active_cell_property_async
and set_grid_property so callers can upload INTEGER-typed discrete properties in
addition to the existing FLOAT properties. Previously a discrete property required
the result name to end with "NUM"; the explicit data type makes the intent
independent of the name.

The gRPC service now forwards the selected data type to
RigCaseCellResultsData::createCategoryResult, and the Python tests cover both
float and integer property uploads.
2026-04-20 18:55:36 +02:00
Kristian Bendiksen 633edd8bba #13313 Python: Add support for setting geometry on an existing case 2026-01-05 12:45:32 +01:00
JJ 225d034327 Fault distance from point (#13367)
* Add python interface for distance to closest fault
* Split up some older code into multiple files.
* Add python test
2025-12-20 09:50:51 +01:00
Magne Sjaastad e47a52b3d4 Remove obsolete combination_mode 2025-12-03 09:48:50 +01:00
Magne Sjaastad a23599cb5d Completion export cleanup
Use MSW as postfix to base name
Drop "Unified" for individual well export
Remove export option Individually/Combined
Remove SPLIT_ON_WELL_AND_COMPLETION_TYPE
2025-12-02 16:03:56 +01:00
Kristian Bendiksen 3c653b5880 #13081 Python: add grid_property_for_positions for RoffCase too.
Fixes #13081.
2025-11-24 15:44:26 +01:00
Magne Sjaastad 544e9eedd9 Improve spell checker using codespell
* Configures automated spell checking with codespell
Adds GitHub workflows and configuration files for automated spell checking using `codespell`.

This includes:
- A workflow for checking pull requests and preventing new typos
- A workflow for automatically fixing typos in the main codebase
- Configuration files for `codespell` to ignore specific terms and file types
- Documentation on how to use and configure the spell checking workflows.

* Corrects minor spelling and grammar errors.
2025-11-19 10:25:32 +01:00
Kristian Bendiksen 1271d6942d #12487 Python: add export from eclipse case to corner point grid.
Exports to zcorn, coords and actnum arrays.

Fixes #12487.
2025-09-25 10:56:04 +02:00
Magne Sjaastad ed246bb1fc #12758 Updates spacing field to double in proto
Updates spacing field to double in proto and add pytest test_create_multiple_fractures
2025-08-15 16:04:16 +02:00
Kristian Bendiksen e539170884 #12568 Python: add API for sampling given positions in a grid case 2025-08-08 08:58:31 +02:00
Kristian Bendiksen 7899736f05 Python ruff fixes
* Python: Clean up imports.
* Python: Clean up error handling example.
* Python: Remove unused local variables
* Python: Avoid comparing against True/False.
* Python: Remove unused name variable.
* Python: Reuse class definition type variable.
* Python: Fix more unused imports
* Black fixes
2025-05-16 15:46:45 +02:00
Magne Sjaastad cf2ae4ffb8 Python: Add support for manipulation of camera position
* Remove debug output in the views function
* Add scripting support for Mat4d
* Add scripting support to camera
* Separate updates for background color and font size
2025-02-17 18:27:16 +01:00
magnesj e8d10c4dfa Python code linting changes detected by black 2025-01-30 08:33:17 +01:00
Kristian Bendiksen b5666c333a Refactor connection between cases and views.
Eclipse grid views and contour maps are not longer a child of the case.
The views are not separate collections (one for grid and one for contour maps)
on root level.
2024-04-15 16:10:43 +02:00
Kristian Bendiksen 7aabe8c4a8 Python: add type hinting to python code.
Types are checked using mypy.

Fixes #10394.
2023-08-23 09:47:44 +02:00
Magne Sjaastad 0b327ca83b #8297 Python : Do not modify result container when reading grid result data
Avoid resize if data is already present
Improve functions for getting grid data and accessing single cell values
Add example for read and write of grid data
2021-12-01 16:27:28 +01:00
Magne Sjaastad 010e964ea8 #6878 Export Completion: Make subset of settings available from Python
Python code linting changes detected by black
2021-05-03 14:15:43 +02:00
Magne Sjaastad 1bacd41037 Add Python linting using black (#7276) 2021-01-26 20:48:01 +01:00
Gaute Lindkvist 0d3ea8ede1 Add new passthrough module for rips generated_classes and refactor imports 2021-01-21 20:10:14 +01:00
Gaute Lindkvist a2ee4c8fef Add a new pass-through module for resinsight_classes.py to aid documentation 2021-01-21 20:10:14 +01:00
Gaute Lindkvist 493f257e5e Fix wrong use of "is" and "is not" in Python if-statements 2021-01-12 11:23:30 +01:00
Gaute Lindkvist 2de5c9ce0b Move GrpcInterface into top level 2021-01-11 15:27:45 +01:00