#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.
This commit is contained in:
Kristian Bendiksen committed 2026-05-13 13:47:40 +02:00
1 parent 79914f2a00
commit 1424a6dc53
1 file changed
+154 -119
+154 -119
View File
@@ -37,7 +37,7 @@ result
import grpc
import uuid
from typing import List, Tuple
from typing import Any, Iterable, Iterator, List, Optional, Tuple, Union
import Case_pb2
import Case_pb2_grpc
@@ -73,7 +73,9 @@ import rips.project # full name import due to circular dependency
@add_method(Case)
def __custom_init__(self, pb2_object, channel):
def __custom_init__(
self, pb2_object: PdmObject_pb2.PdmObject, channel: grpc.Channel
) -> None:
self.__case_stub = Case_pb2_grpc.CaseStub(self._channel)
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(self._channel)
@@ -95,12 +97,16 @@ def __grid_count(self) -> int:
@add_method(Case)
def __request(self):
def __request(self) -> Case_pb2.CaseRequest:
return Case_pb2.CaseRequest(id=self.id)
@add_method(Case)
def __generate_property_input_iterator(self, values_iterator, parameters):
def __generate_property_input_iterator(
self,
values_iterator: Iterable[List[float]],
parameters: Properties_pb2.PropertyRequest,
) -> Iterator[Properties_pb2.PropertyInputChunk]:
chunk = Properties_pb2.PropertyInputChunk()
chunk.params.CopyFrom(parameters)
yield chunk
@@ -112,7 +118,9 @@ def __generate_property_input_iterator(self, values_iterator, parameters):
@add_method(Case)
def __generate_property_input_chunks(self, array, parameters):
def __generate_property_input_chunks(
self, array: List[float], parameters: Properties_pb2.PropertyRequest
) -> Iterator[Properties_pb2.PropertyInputChunk]:
index = -1
while index < len(array):
chunk = Properties_pb2.PropertyInputChunk()
@@ -161,7 +169,7 @@ def grids(self) -> List[Grid]:
@add_method(Case)
def replace(self, new_grid_file):
def replace(self, new_grid_file: str) -> None:
"""Replace the current case grid with a new grid loaded from file
Arguments:
@@ -178,7 +186,7 @@ def replace(self, new_grid_file):
@add_method(Case)
def cell_count(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
) -> int:
) -> Case_pb2.CellCount:
"""Get a cell count object containing number of active cells and total number of cells
Arguments:
@@ -207,7 +215,7 @@ def cell_count(
@add_method(Case)
def cell_info_for_active_cells_async(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
):
) -> Iterator[Case_pb2.CellInfoArray]:
"""Get Stream of cell info objects for current case
Arguments:
@@ -229,7 +237,7 @@ def cell_info_for_active_cells_async(
@add_method(Case)
def cell_info_for_active_cells(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
):
) -> List[Case_pb2.CellInfo]:
"""Get list of cell info objects for current case
Arguments:
@@ -269,7 +277,7 @@ def cell_info_for_active_cells(
@add_method(Case)
def time_steps(self):
def time_steps(self) -> List[Case_pb2.TimeStepDate]:
"""Get a list containing all time steps
The time steps are defined by the class **TimeStepDate**
@@ -291,7 +299,7 @@ def time_steps(self):
@add_method(Case)
def reservoir_boundingbox(self):
def reservoir_boundingbox(self) -> Case_pb2.BoundingBox:
"""Get the reservoir bounding box
Returns:
@@ -314,7 +322,9 @@ def reservoir_boundingbox(self):
@add_method(Case)
def distance_to_closest_fault(self, x: float, y: float, z: float):
def distance_to_closest_fault(
self, x: float, y: float, z: float
) -> Tuple[str, float, str]:
"""Find the closest fault to the given point and return the distance, fault name and fault face"""
request = Case_pb2.ClosestFaultRequest(
case_request=self.__request(), point=Definitions_pb2.Vec3d(x=x, y=y, z=z)
@@ -336,13 +346,13 @@ def reservoir_depth_range(self) -> Tuple[float, float]:
@add_method(Case)
def days_since_start(self):
def days_since_start(self) -> List[float]:
"""Get a list of decimal values representing days since the start of the simulation"""
return self.__case_stub.GetDaysSinceStart(self.__request()).day_decimals
@add_method(Case)
def view(self, view_id):
def view(self, view_id: int) -> Optional[View]:
"""Get a particular view belonging to a case by providing view id
Arguments:
@@ -360,7 +370,7 @@ def view(self, view_id):
@add_method(Case)
def views(self):
def views(self) -> List[View]:
"""Get all views of a case
Returns:
@@ -376,7 +386,7 @@ def views(self):
@add_method(Case)
def create_view(self):
def create_view(self) -> Optional[View]:
"""Create a new view in the current case
Returns:
@@ -390,7 +400,9 @@ def create_view(self):
@add_method(Case)
def export_snapshots_of_all_views(self, prefix="", export_folder=""):
def export_snapshots_of_all_views(
self, prefix: str = "", export_folder: str = ""
) -> Any:
"""Export snapshots for all views in the case
Arguments:
@@ -412,17 +424,17 @@ def export_snapshots_of_all_views(self, prefix="", export_folder=""):
@add_method(Case)
def export_well_path_completions(
self,
time_step,
well_path_names,
file_split,
compdat_export="TRANSMISSIBILITIES",
include_perforations=True,
include_fishbones=True,
fishbones_exclude_main_bore=True,
export_welspec=True,
export_comments=True,
custom_file_name="",
):
time_step: int,
well_path_names: Union[str, List[str]],
file_split: str,
compdat_export: str = "TRANSMISSIBILITIES",
include_perforations: bool = True,
include_fishbones: bool = True,
fishbones_exclude_main_bore: bool = True,
export_welspec: bool = True,
export_comments: bool = True,
custom_file_name: str = "",
) -> Any:
"""
Export well path completions for the current case to file
@@ -476,7 +488,7 @@ def export_well_path_completions(
@add_method(Case)
def export_msw(self, well_path):
def export_msw(self, well_path: str) -> Any:
"""
Export Eclipse Multi-segment-well model to file
@@ -491,15 +503,15 @@ def export_msw(self, well_path):
@add_method(Case)
def create_multiple_fractures(
self,
template_id,
well_path_names,
min_dist_from_well_td,
max_fractures_per_well,
top_layer,
base_layer,
spacing,
action,
):
template_id: int,
well_path_names: Union[str, List[str]],
min_dist_from_well_td: float,
max_fractures_per_well: int,
top_layer: int,
base_layer: int,
spacing: float,
action: str,
) -> Any:
"""
Create Multiple Fractures in one go
@@ -537,13 +549,13 @@ def create_multiple_fractures(
@add_method(Case)
def create_lgr_for_completion(
self,
time_step,
well_path_names,
refinement_i,
refinement_j,
refinement_k,
split_type,
):
time_step: int,
well_path_names: Union[str, List[str]],
refinement_i: int,
refinement_j: int,
refinement_k: int,
split_type: str,
) -> Any:
"""
Create a local grid refinement for the completions on the given well paths
@@ -583,7 +595,7 @@ def create_lgr_for_completion(
@add_method(Case)
def create_saturation_pressure_plots(self):
def create_saturation_pressure_plots(self) -> Any:
"""
Create saturation pressure plots for the current case
"""
@@ -596,13 +608,13 @@ def create_saturation_pressure_plots(self):
@add_method(Case)
def export_flow_characteristics(
self,
time_steps,
injectors,
producers,
file_name,
minimum_communication=0.0,
aquifer_cell_threshold=0.1,
):
time_steps: Union[int, List[int]],
injectors: Union[str, List[str]],
producers: Union[str, List[str]],
file_name: str,
minimum_communication: float = 0.0,
aquifer_cell_threshold: float = 0.1,
) -> Any:
"""Export Flow Characteristics data to text file in CSV format
**Parameters**::
@@ -641,7 +653,7 @@ def available_properties(
self,
property_type: PropertyType,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> List[str]:
"""Get a list of available properties
For argument details, see :ref:`Result Definition <result-definition-label>`
@@ -665,10 +677,10 @@ def available_properties(
def active_cell_property_async(
self,
property_type: PropertyType,
property_name,
time_step,
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> Iterator[Properties_pb2.PropertyChunk]:
"""Get a cell property for all active cells. Async, so returns an iterator. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -698,10 +710,10 @@ def active_cell_property_async(
def active_cell_property(
self,
property_type: PropertyType,
property_name,
time_step,
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> List[float]:
"""Get a cell property for all active cells. Sync, so returns a list. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -728,10 +740,10 @@ def active_cell_property(
def selected_cell_property_async(
self,
property_type: PropertyType,
property_name,
time_step,
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> Iterator[Properties_pb2.PropertyChunk]:
"""Get a cell property for all selected cells. Async, so returns an iterator. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -761,10 +773,10 @@ def selected_cell_property_async(
def selected_cell_property(
self,
property_type: PropertyType,
property_name,
time_step,
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> List[float]:
"""Get a cell property for all selected cells. Sync, so returns a list. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -791,11 +803,11 @@ def selected_cell_property(
def grid_property_async(
self,
property_type: PropertyType,
property_name,
time_step,
grid_index=0,
property_name: str,
time_step: int,
grid_index: int = 0,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> Iterator[Properties_pb2.PropertyChunk]:
"""Get a cell property for all grid cells. Async, so returns an iterator. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -827,11 +839,11 @@ def grid_property_async(
def grid_property(
self,
property_type: PropertyType,
property_name,
time_step,
grid_index=0,
property_name: str,
time_step: int,
grid_index: int = 0,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> List[float]:
"""Get a cell property for all grid cells. Synchronous, so returns a list. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -857,13 +869,13 @@ def grid_property(
@add_method(Case)
def set_active_cell_property_async(
self,
values_iterator,
values_iterator: Iterable[List[float]],
property_type: PropertyType,
property_name,
time_step,
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
data_type: PropertyDataType = PropertyDataType.FLOAT,
):
) -> None:
"""Set cell property for all active cells Async. Takes an iterator to the input values. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -893,13 +905,13 @@ def set_active_cell_property_async(
@add_method(Case)
def set_active_cell_property(
self,
values,
values: List[float],
property_type: PropertyType,
property_name,
time_step,
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
data_type: PropertyDataType = PropertyDataType.FLOAT,
):
) -> None:
"""Set a cell property for all active cells. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -930,14 +942,14 @@ def set_active_cell_property(
@add_method(Case)
def set_grid_property(
self,
values,
values: List[float],
property_type: PropertyType,
property_name,
time_step,
grid_index=0,
property_name: str,
time_step: int,
grid_index: int = 0,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
data_type: PropertyDataType = PropertyDataType.FLOAT,
):
) -> None:
"""Set a cell property for all grid cells. For argument details, see :ref:`Result Definition <result-definition-label>`
Arguments:
@@ -970,12 +982,12 @@ def set_grid_property(
@add_method(Case)
def export_property(
self,
time_step,
property_name,
eclipse_keyword=property,
undefined_value=0.0,
export_file=property,
):
time_step: int,
property_name: str,
eclipse_keyword: Any = property,
undefined_value: float = 0.0,
export_file: Any = property,
) -> Any:
"""Export an Eclipse property
Arguments:
@@ -998,7 +1010,12 @@ def export_property(
@add_method(Case)
def create_well_bore_stability_plot(self, well_path, time_step, parameters=None):
def create_well_bore_stability_plot(
self,
well_path: str,
time_step: int,
parameters: Optional[WbsParameters] = None,
) -> Optional[WellBoreStabilityPlot]:
"""Create a new well bore stability plot
Arguments:
@@ -1027,7 +1044,9 @@ def create_well_bore_stability_plot(self, well_path, time_step, parameters=None)
@add_method(Case)
def import_formation_names(self, formation_files=None):
def import_formation_names(
self, formation_files: Optional[Union[str, List[str]]] = None
) -> None:
"""Import formation names into project and apply it to the current case
Arguments:
@@ -1047,7 +1066,7 @@ def import_formation_names(self, formation_files=None):
@add_method(Case)
def simulation_wells(self):
def simulation_wells(self) -> List[SimulationWell]:
"""Get a list of all simulation wells for a case
Returns:
@@ -1063,7 +1082,7 @@ def simulation_wells(self):
@add_method(Case)
def active_cell_centers_async(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
):
) -> Iterator[Definitions_pb2.CellCenters]:
"""Get a cell centers for all active cells. Async, so returns an iterator
Arguments:
@@ -1083,7 +1102,7 @@ def active_cell_centers_async(
@add_method(Case)
def active_cell_centers(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
):
) -> List[Definitions_pb2.Vec3d]:
"""Get a cell centers for all active cells. Synchronous, so returns a list.
Arguments:
@@ -1103,7 +1122,7 @@ def active_cell_centers(
@add_method(Case)
def active_cell_corners_async(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
):
) -> Iterator[Definitions_pb2.CellCornersArray]:
"""Get a cell corners for all active cells. Async, so returns an iterator
Arguments:
@@ -1123,7 +1142,7 @@ def active_cell_corners_async(
@add_method(Case)
def active_cell_corners(
self, porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL
):
) -> List[Definitions_pb2.CellCorners]:
"""Get a cell corners for all active cells. Synchronous, so returns a list.
Arguments:
@@ -1153,7 +1172,7 @@ def active_cell_corners(
@add_method(Case)
def selected_cells_async(self):
def selected_cells_async(self) -> Iterator[Case_pb2.SelectedCells]:
"""Get the selected cells. Async, so returns an iterator.
Returns:
@@ -1164,7 +1183,7 @@ def selected_cells_async(self):
@add_method(Case)
def selected_cells(self):
def selected_cells(self) -> List[Case_pb2.SelectedCell]:
"""Get the selected cells. Synchronous, so returns a list.
Returns:
@@ -1179,7 +1198,7 @@ def selected_cells(self):
@add_method(Case)
def coarsening_info(self):
def coarsening_info(self) -> List[Case_pb2.CoarseningInfo]:
"""Get a coarsening information for all grids in the case.
Returns:
@@ -1190,7 +1209,7 @@ def coarsening_info(self):
@add_method(Case)
def available_nnc_properties(self):
def available_nnc_properties(self) -> List[NNCProperties_pb2.AvailableNNCProperty]:
"""Get a list of available NNC properties
**NNCConnection class description**::
@@ -1209,7 +1228,7 @@ def available_nnc_properties(self):
@add_method(Case)
def nnc_connections_async(self):
def nnc_connections_async(self) -> Iterator[NNCProperties_pb2.NNCConnections]:
"""Get the NNC connections. Async, so returns an iterator.
Returns:
@@ -1220,7 +1239,7 @@ def nnc_connections_async(self):
@add_method(Case)
def nnc_connections(self):
def nnc_connections(self) -> List[NNCProperties_pb2.NNCConnection]:
"""Get the NNC connection. Synchronous, so returns a list.
Returns:
@@ -1235,7 +1254,9 @@ def nnc_connections(self):
@add_method(Case)
def __nnc_connections_values_async(self, property_name, property_type, time_step):
def __nnc_connections_values_async(
self, property_name: str, property_type: int, time_step: int
) -> Iterator[NNCProperties_pb2.NNCValues]:
request = NNCProperties_pb2.NNCValuesRequest(
case_id=self.id,
property_name=property_name,
@@ -1246,7 +1267,9 @@ def __nnc_connections_values_async(self, property_name, property_type, time_step
@add_method(Case)
def __nnc_values_generator_to_list(self, generator):
def __nnc_values_generator_to_list(
self, generator: Iterable[NNCProperties_pb2.NNCValues]
) -> List[float]:
"""Converts a NNC values generator to a list."""
vals = []
for chunk in generator:
@@ -1256,7 +1279,9 @@ def __nnc_values_generator_to_list(self, generator):
@add_method(Case)
def nnc_connections_static_values_async(self, property_name):
def nnc_connections_static_values_async(
self, property_name: str
) -> Iterator[NNCProperties_pb2.NNCValues]:
"""Get the static NNC values. Async, so returns an iterator.
Returns:
@@ -1272,7 +1297,7 @@ def nnc_connections_static_values_async(self, property_name):
@add_method(Case)
def nnc_connections_static_values(self, property_name):
def nnc_connections_static_values(self, property_name: str) -> List[float]:
"""Get the static NNC values.
Returns:
@@ -1285,7 +1310,9 @@ def nnc_connections_static_values(self, property_name):
@add_method(Case)
def nnc_connections_dynamic_values_async(self, property_name, time_step):
def nnc_connections_dynamic_values_async(
self, property_name: str, time_step: int
) -> Iterator[NNCProperties_pb2.NNCValues]:
"""Get the dynamic NNC values. Async, so returns an iterator.
Returns:
@@ -1301,7 +1328,9 @@ def nnc_connections_dynamic_values_async(self, property_name, time_step):
@add_method(Case)
def nnc_connections_dynamic_values(self, property_name, time_step):
def nnc_connections_dynamic_values(
self, property_name: str, time_step: int
) -> List[float]:
"""Get the dynamic NNC values.
Returns:
@@ -1314,7 +1343,9 @@ def nnc_connections_dynamic_values(self, property_name, time_step):
@add_method(Case)
def nnc_connections_generated_values_async(self, property_name, time_step):
def nnc_connections_generated_values_async(
self, property_name: str, time_step: int
) -> Iterator[NNCProperties_pb2.NNCValues]:
"""Get the generated NNC values. Async, so returns an iterator.
Returns:
@@ -1330,7 +1361,9 @@ def nnc_connections_generated_values_async(self, property_name, time_step):
@add_method(Case)
def nnc_connections_generated_values(self, property_name, time_step):
def nnc_connections_generated_values(
self, property_name: str, time_step: int
) -> List[float]:
"""Get the generated NNC values.
Returns:
@@ -1343,7 +1376,9 @@ def nnc_connections_generated_values(self, property_name, time_step):
@add_method(Case)
def __generate_nnc_property_input_chunks(self, array, parameters):
def __generate_nnc_property_input_chunks(
self, array: List[float], parameters: NNCProperties_pb2.NNCValuesInputRequest
) -> Iterator[NNCProperties_pb2.NNCValuesChunk]:
index = -1
while index < len(array):
chunk = NNCProperties_pb2.NNCValuesChunk()
@@ -1368,11 +1403,11 @@ def __generate_nnc_property_input_chunks(self, array, parameters):
@add_method(Case)
def set_nnc_connections_values(
self,
values,
property_name,
time_step,
values: List[float],
property_name: str,
time_step: int,
porosity_model: PorosityModelType = PorosityModelType.MATRIX_MODEL,
):
) -> None:
"""Set nnc connection values for all connections..
Arguments: