Make Python code use the new generated skeleton and rename ResInsight parameters to fit

This commit is contained in:
Gaute Lindkvist
2020-02-21 12:10:02 +01:00
parent ae3651ab30
commit 1f6e9513de
42 changed files with 2078 additions and 2085 deletions

View File

@@ -178,7 +178,9 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
"rips/instance.py"
"rips/pdmobject.py"
"rips/plot.py"
"rips/simulation_well.py"
"rips/view.py"
"rips/wellpath.py"
"rips/well_log_plot.py"
"rips/well_bore_stability_plot.py"
"rips/PythonExamples/instance_example.py"
@@ -209,6 +211,9 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
"rips/tests/test_project.py"
"rips/tests/conftest.py"
"rips/tests/dataroot.py"
"rips/tests/test_nnc_properties.py"
"rips/tests/test_simulation_wells.py"
"rips/tests/test_wells.py"
"requirements.txt"
"setup.py"
"README.md"

View File

@@ -14,10 +14,10 @@ if resinsight is not None:
print ("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case id: " + str(case.case_id))
print("Case id: " + str(case.id))
print("Case name: " + case.name)
print("Case type: " + case.type)
print("Case grid path: " + case.grid_path())
print("Case file name: " + case.file_path)
print("Case reservoir bounding box:", case.reservoir_boundingbox())
timesteps = case.time_steps()

View File

@@ -13,7 +13,7 @@ if resinsight is not None:
cases = resinsight.project.cases()
for case in cases:
print("Case id: " + str(case.case_id))
print("Case id: " + str(case.id))
print("Case name: " + case.name)
timesteps = case.time_steps()

View File

@@ -10,7 +10,7 @@ import rips
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
wells = resinsight.project.wells()
wells = resinsight.project.well_paths()
print ("Got " + str(len(wells)) + " wells: ")
for well in wells:

View File

@@ -16,14 +16,12 @@ case_group.print_object_info()
#stat_cases = caseGroup.statistics_cases()
#case_ids = []
#for stat_case in stat_cases:
# stat_case.set_value("DynamicPropertiesToCalculate", ["SWAT"])
# stat_case.update()
# case_ids.append(stat_case.get_value("CaseId"))
# stat_case.set_dynamic_properties_to_calculate(["SWAT"])
# case_ids.append(stat_case.id)
case_group.compute_statistics()
view = case_group.views()[0]
cell_result = view.set_cell_result()
cell_result.set_value("ResultVariable", "PRESSURE_DEV")
cell_result.update()
cell_result = view.cell_result()
cell_result.set_result_variable("PRESSURE_DEV")

View File

@@ -33,8 +33,8 @@ for case in cases:
if case.type == "GeoMechCase":
min_res_depth, max_res_depth = case.reservoir_depth_range()
print (case.case_id)
case_path = case.grid_path()
print (case.id)
case_path = case.file_path
folder_name = os.path.dirname(case_path)
case.import_formation_names(formation_files=['D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr'])
@@ -45,16 +45,19 @@ for case in cases:
for well_path in well_paths:
try:
# Create plot with parameters
wbsplot = case.create_well_bore_stability_plot(well_path=well_path, time_step=0, wbs_parameters=wbs_parameters)
wbsplot = case.create_well_bore_stability_plot(well_path=well_path.name, time_step=0, wbs_parameters=wbs_parameters)
# Example of setting parameters for existing plots
replace_params = wbsplot.parameters()
replace_params.user_poisson_ratio = 0.654321
replace_params.user_fg_shale = 1.0321
wbsplot.set_parameters(replace_params)
# Demonstrate altering general well log plot settings
min_depth, max_depth = wbsplot.depth_range()
wbsplot.set_depth_range(max(min_depth, min_res_depth), min(max_depth, max_res_depth))
#wbsplot.set_depth_type("TRUE_VERTICAL_DEPTH_RKB")
min_depth = max(wbsplot.minimum_depth, min_res_depth)
max_depth = min(wbsplot.maximum_depth, max_res_depth)
wbsplot.minimum_depth = min_depth
wbsplot.maximum_depth = max_depth
wbsplot.update()
#wbsplot.depth_type = "TRUE_VERTICAL_DEPTH_RKB"
wbsplot.export_snapshot(export_folder=dirname)

View File

@@ -15,7 +15,7 @@ print("Exporting to: " + export_folder)
for plot in plots:
plot.export_snapshot(export_folder=export_folder)
plot.export_snapshot(export_folder=export_folder, output_format='PDF')
well_log_plot = rips.WellLogPlot.from_pdm_object(plot)
well_log_plot = plot.cast(rips.WellLogPlot)
if well_log_plot is not None:
well_log_plot.export_data_as_las(export_folder=export_folder)
well_log_plot.export_data_as_ascii(export_folder=export_folder)

View File

@@ -18,9 +18,9 @@ property_list = ['SOIL', 'PRESSURE'] # list of parameter for snapshot
print ("Looping through cases")
for case in cases:
print("Case name: ", case.name)
print("Case id: ", case.case_id)
print("Case id: ", case.id)
# Get grid path and its folder name
case_path = case.grid_path()
case_path = case.file_path
folder_name = os.path.dirname(case_path)
# create a folder to hold the snapshots

View File

@@ -3,24 +3,24 @@ import rips
# Connect to ResInsight instance
resInsight = rips.Instance.find()
well_path_names = resInsight.project.import_well_paths(well_path_folder='D:/Projects/ResInsight-regression-test/ModelData/norne/wellpaths')
well_paths = resInsight.project.import_well_paths(well_path_folder='D:/Projects/ResInsight-regression-test/ModelData/norne/wellpaths')
if resInsight.project.has_warnings():
for warning in resInsight.project.warnings():
print(warning)
for well_path_name in well_path_names:
print("Imported from folder: " + well_path_name)
for well_path in well_paths:
print("Imported from folder: " + well_path.name)
well_path_names = resInsight.project.import_well_paths(well_path_files=['D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/E-3H.json',
well_paths = resInsight.project.import_well_paths(well_path_files=['D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/E-3H.json',
'D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/C-1H.json'])
if resInsight.project.has_warnings():
for warning in resInsight.project.warnings():
print(warning)
for well_path_name in well_path_names:
print("Imported from indivdual files: " + well_path_name)
for well_path in well_paths:
print("Imported from individual files: " + well_path.name)
well_path_names = resInsight.project.import_well_log_files(well_log_folder='D:/Projects/ResInsight-regression-test/ModelData/Norne_PLT_LAS')

View File

@@ -16,14 +16,14 @@ if resinsight is not None:
views = case.views()
for view in views:
# Set some parameters for the view
view.set_show_grid_box(not view.show_grid_box())
view.set_background_color("#3388AA")
view.show_grid_box = not view.show_grid_box
view.background_color = "#3388AA"
# Update the view in ResInsight
view.update()
# Clone the first view
new_view = views[0].clone()
view.set_show_grid_box(False)
new_view.set_background_color("#FFAA33")
new_view.background_color = "#FFAA33"
new_view.update()
view.show_grid_box = False
view.set_visible(False)
view.update()

View File

@@ -10,7 +10,9 @@ from rips.instance import Instance
from rips.pdmobject import PdmObject
from rips.view import View
from rips.project import Project
from rips.plot import Plot
from rips.plot import Plot, PlotWindow
from rips.contour_map import ContourMap, ContourMapType
from rips.well_log_plot import WellLogPlot
from rips.well_bore_stability_plot import WellBoreStabilityPlot, WbsParameters
from rips.simulation_well import SimulationWell
from rips.wellpath import WellPathBase

View File

@@ -7,6 +7,7 @@
Module containing the Case class
"""
import builtins
import grpc
import rips.generated.Case_pb2 as Case_pb2
@@ -16,18 +17,19 @@ import rips.generated.PdmObject_pb2 as PdmObject_pb2
import rips.generated.Properties_pb2 as Properties_pb2
import rips.generated.Properties_pb2_grpc as Properties_pb2_grpc
import rips.generated.NNCProperties_pb2 as NNCProperties_pb2
import rips.generated.NNCProperties_pb2_grpc as NNCProperties_pb2_grpc
from rips.generated.pdm_objects import Case
import rips.project
from rips.grid import Grid
from rips.pdmobject import PdmObject
from rips.pdmobject import add_method, PdmObject
from rips.view import View
from rips.contour_map import ContourMap, ContourMapType
from rips.well_bore_stability_plot import WellBoreStabilityPlot, WbsParameters
from rips.simulation_well import SimulationWell
class Case(PdmObject):
"""ResInsight case class
Operate on a ResInsight case specified by a Case Id integer.
@@ -44,27 +46,20 @@ class Case(PdmObject):
However we need overhead space, so the default is 8160.
This leaves 256B for overhead.
"""
def __init__(self, channel, case_id, project):
# Private properties
self.__channel = channel
self.__case_stub = Case_pb2_grpc.CaseStub(channel)
self.__request = Case_pb2.CaseRequest(id=case_id)
@add_method(Case)
def __custom_init__(self, pb2_object, channel):
self.__case_stub = Case_pb2_grpc.CaseStub(self._channel)
self.__request = Case_pb2.CaseRequest(id=self.id)
info = self.__case_stub.GetCaseInfo(self.__request)
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(
self.__channel)
self.__nnc_properties_stub = NNCProperties_pb2_grpc.NNCPropertiesStub(
self.__channel)
PdmObject.__init__(self, self.__case_stub.GetPdmObject(self.__request),
self.__channel, project)
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(self._channel)
self.__nnc_properties_stub = NNCProperties_pb2_grpc.NNCPropertiesStub(self._channel)
# Public properties
self.case_id = case_id
self.group_id = info.group_id
self.name = info.name
self.type = info.type
self.chunk_size = 8160
@add_method(Case)
def __grid_count(self):
"""Get number of grids in the case"""
try:
@@ -72,9 +67,9 @@ class Case(PdmObject):
except grpc.RpcError as exception:
if exception.code() == grpc.StatusCode.NOT_FOUND:
return 0
print("ERROR: ", exception)
return 0
@add_method(Case)
def __generate_property_input_iterator(self, values_iterator, parameters):
chunk = Properties_pb2.PropertyInputChunk()
chunk.params.CopyFrom(parameters)
@@ -85,6 +80,7 @@ class Case(PdmObject):
chunk.values.CopyFrom(valmsg)
yield chunk
@add_method(Case)
def __generate_property_input_chunks(self, array, parameters):
index = -1
while index < len(array):
@@ -104,13 +100,7 @@ class Case(PdmObject):
chunk = Properties_pb2.PropertyInputChunk()
yield chunk
def grid_path(self):
"""Get path of the current grid case
Returns: path string
"""
return self.get_value("CaseFileName")
@add_method(Case)
def grid(self, index):
"""Get Grid of a given index. Returns a rips Grid object
@@ -119,25 +109,30 @@ class Case(PdmObject):
Returns: Grid object
"""
return Grid(index, self, self.__channel)
return Grid(index, self, self.channel())
@add_method(Case)
def grids(self):
"""Get a list of all rips Grid objects in the case"""
grid_list = []
for i in range(0, self.__grid_count()):
grid_list.append(Grid(i, self, self.__channel))
grid_list.append(Grid(i, self, self.channel()))
return grid_list
@add_method(Case)
def replace(self, new_grid_file):
"""Replace the current case grid with a new grid loaded from file
Arguments:
new_egrid_file (str): path to EGRID file
"""
project = self.ancestor(rips.project.Project)
self._execute_command(replaceCase=Cmd.ReplaceCaseRequest(
newGridFile=new_grid_file, caseId=self.case_id))
self.__init__(self.__channel, self.case_id, self._project)
newGridFile=new_grid_file, caseId=self.id))
new_case = project.case(self.id)
self.copy_from(new_case)
@add_method(Case)
def cell_count(self, porosity_model="MATRIX_MODEL"):
"""Get a cell count object containing number of active cells and
total number of cells
@@ -155,6 +150,7 @@ class Case(PdmObject):
porosity_model=porosity_model_enum)
return self.__case_stub.GetCellCount(request)
@add_method(Case)
def cell_info_for_active_cells_async(self, porosity_model="MATRIX_MODEL"):
"""Get Stream of cell info objects for current case
@@ -172,6 +168,7 @@ class Case(PdmObject):
porosity_model=porosity_model_enum)
return self.__case_stub.GetCellInfoForActiveCells(request)
@add_method(Case)
def cell_info_for_active_cells(self, porosity_model="MATRIX_MODEL"):
"""Get list of cell info objects for current case
@@ -209,6 +206,7 @@ class Case(PdmObject):
received_active_cells.append(active_cell)
return received_active_cells
@add_method(Case)
def time_steps(self):
"""Get a list containing all time steps
@@ -227,12 +225,14 @@ class Case(PdmObject):
"""
return self.__case_stub.GetTimeSteps(self.__request).dates
@add_method(Case)
def reservoir_boundingbox(self):
"""Get the reservoir bounding box
Returns: A class with six double members: min_x, max_x, min_y, max_y, min_z, max_z
"""
return self.__case_stub.GetReservoirBoundingBox(self.__request)
@add_method(Case)
def reservoir_depth_range(self):
"""Get the reservoir depth range
Returns: A tuple with two members. The first is the minimum depth, the second is the maximum depth
@@ -240,23 +240,24 @@ class Case(PdmObject):
bbox = self.reservoir_boundingbox()
return -bbox.max_z, -bbox.min_z
@add_method(Case)
def days_since_start(self):
"""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 views(self):
"""Get a list of views belonging to a case"""
eclipse_pdm_objects = self.children("ReservoirViews")
geomech_pdm_objects = self.children("GeoMechViews")
pdm_objects = self.descendants("View")
view_list = []
for pdm_object in eclipse_pdm_objects:
view_list.append(View(pdm_object, self._project))
for pdm_object in geomech_pdm_objects:
view_list.append(View(pdm_object, self._project))
for pdm_object in pdm_objects:
view_object = pdm_object.cast(View)
view_list.append(view_object)
return view_list
@add_method(Case)
def view(self, view_id):
"""Get a particular view belonging to a case by providing view id
Arguments:
@@ -267,16 +268,18 @@ class Case(PdmObject):
"""
views = self.views()
for view_object in views:
if view_object.view_id == view_id:
if view_object.id == view_id:
return view_object
return None
@add_method(Case)
def create_view(self):
"""Create a new view in the current case"""
return self.view(
self._execute_command(createView=Cmd.CreateViewRequest(
caseId=self.case_id)).createViewResult.viewId)
caseId=self.id)).createViewResult.viewId)
@add_method(Case)
def contour_maps(self, map_type=ContourMapType.ECLIPSE):
""" Get a list of all contour maps belonging to a project
@@ -288,9 +291,10 @@ class Case(PdmObject):
pdm_objects = self.descendants(ContourMapType.get_identifier(map_type))
contour_maps = []
for pdm_object in pdm_objects:
contour_maps.append(ContourMap(pdm_object, self._project, map_type))
contour_maps.append(ContourMap(pdm_object, map_type))
return contour_maps
@add_method(Case)
def export_snapshots_of_all_views(self, prefix="", export_folder=""):
""" Export snapshots for all views in the case
@@ -301,8 +305,9 @@ class Case(PdmObject):
"""
return self._execute_command(
exportSnapshots=Cmd.ExportSnapshotsRequest(
type="VIEWS", prefix=prefix, caseId=self.case_id, viewId=-1, exportFolder=export_folder))
type="VIEWS", prefix=prefix, caseId=self.id, viewId=-1, exportFolder=export_folder))
@add_method(Case)
def export_well_path_completions(
self,
time_step,
@@ -355,7 +360,7 @@ class Case(PdmObject):
well_path_names = [well_path_names]
return self._execute_command(
exportWellPathCompletions=Cmd.ExportWellPathCompRequest(
caseId=self.case_id,
caseId=self.id,
timeStep=time_step,
wellPathNames=well_path_names,
fileSplit=file_split,
@@ -366,6 +371,7 @@ class Case(PdmObject):
combinationMode=combination_mode,
))
@add_method(Case)
def export_msw(self, well_path):
"""
Export Eclipse Multi-segment-well model to file
@@ -374,8 +380,9 @@ class Case(PdmObject):
well_path(str): Well path name
"""
return self._execute_command(exportMsw=Cmd.ExportMswRequest(
caseId=self.case_id, wellPath=well_path))
caseId=self.id, wellPath=well_path))
@add_method(Case)
def create_multiple_fractures(
self,
template_id,
@@ -405,7 +412,7 @@ class Case(PdmObject):
well_path_names = [well_path_names]
return self._execute_command(
createMultipleFractures=Cmd.MultipleFracRequest(
caseId=self.case_id,
caseId=self.id,
templateId=template_id,
wellPathNames=well_path_names,
minDistFromWellTd=min_dist_from_well_td,
@@ -416,6 +423,7 @@ class Case(PdmObject):
action=action,
))
@add_method(Case)
def create_lgr_for_completion(
self,
time_step,
@@ -450,7 +458,7 @@ class Case(PdmObject):
well_path_names = [well_path_names]
return self._execute_command(
createLgrForCompletions=Cmd.CreateLgrForCompRequest(
caseId=self.case_id,
caseId=self.id,
timeStep=time_step,
wellPathNames=well_path_names,
refinementI=refinement_i,
@@ -459,15 +467,17 @@ class Case(PdmObject):
splitType=split_type,
))
@add_method(Case)
def create_saturation_pressure_plots(self):
"""
Create saturation pressure plots for the current case
"""
case_ids = [self.case_id]
case_ids = [self.id]
return self._execute_command(
createSaturationPressurePlots=Cmd.CreateSatPressPlotRequest(
caseIds=case_ids))
@add_method(Case)
def export_flow_characteristics(
self,
time_steps,
@@ -497,7 +507,7 @@ class Case(PdmObject):
producers = [producers]
return self._execute_command(
exportFlowCharacteristics=Cmd.ExportFlowInfoRequest(
caseId=self.case_id,
caseId=self.id,
timeSteps=time_steps,
injectors=injectors,
producers=producers,
@@ -506,6 +516,7 @@ class Case(PdmObject):
aquiferCellThreshold=aquifer_cell_threshold,
))
@add_method(Case)
def available_properties(self,
property_type,
porosity_model="MATRIX_MODEL"):
@@ -535,6 +546,7 @@ class Case(PdmObject):
return self.__properties_stub.GetAvailableProperties(
request).property_names
@add_method(Case)
def active_cell_property_async(self,
property_type,
property_name,
@@ -564,6 +576,7 @@ class Case(PdmObject):
for chunk in self.__properties_stub.GetActiveCellProperty(request):
yield chunk
@add_method(Case)
def active_cell_property(self,
property_type,
property_name,
@@ -590,6 +603,7 @@ class Case(PdmObject):
all_values.append(value)
return all_values
@add_method(Case)
def selected_cell_property_async(self,
property_type,
property_name,
@@ -619,6 +633,7 @@ class Case(PdmObject):
for chunk in self.__properties_stub.GetSelectedCellProperty(request):
yield chunk
@add_method(Case)
def selected_cell_property(self,
property_type,
property_name,
@@ -645,14 +660,14 @@ class Case(PdmObject):
all_values.append(value)
return all_values
@add_method(Case)
def grid_property_async(
self,
property_type,
property_name,
time_step,
grid_index=0,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Get a cell property for all grid cells. Async, so returns an iterator
Arguments:
@@ -679,14 +694,14 @@ class Case(PdmObject):
for chunk in self.__properties_stub.GetGridProperty(request):
yield chunk
@add_method(Case)
def grid_property(
self,
property_type,
property_name,
time_step,
grid_index=0,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Get a cell property for all grid cells. Synchronous, so returns a list
Arguments:
@@ -708,14 +723,14 @@ class Case(PdmObject):
all_values.append(value)
return all_values
@add_method(Case)
def set_active_cell_property_async(
self,
values_iterator,
property_type,
property_name,
time_step,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Set cell property for all active cells Async. Takes an iterator to the input values
Arguments:
@@ -739,14 +754,14 @@ class Case(PdmObject):
values_iterator, request)
self.__properties_stub.SetActiveCellProperty(request_iterator)
@add_method(Case)
def set_active_cell_property(
self,
values,
property_type,
property_name,
time_step,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Set a cell property for all active cells.
Arguments:
@@ -771,6 +786,7 @@ class Case(PdmObject):
if reply.accepted_value_count < len(values):
raise IndexError
@add_method(Case)
def set_grid_property(
self,
values,
@@ -778,8 +794,7 @@ class Case(PdmObject):
property_name,
time_step,
grid_index=0,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Set a cell property for all grid cells.
Arguments:
@@ -806,14 +821,14 @@ class Case(PdmObject):
if reply.accepted_value_count < len(values):
raise IndexError
@add_method(Case)
def export_property(
self,
time_step,
property_name,
eclipse_keyword=property,
undefined_value=0.0,
export_file=property,
):
export_file=property):
""" Export an Eclipse property
Arguments:
@@ -824,7 +839,7 @@ class Case(PdmObject):
export_file (str): File name for export. Defaults to the value of property parameter
"""
return self._execute_command(exportProperty=Cmd.ExportPropertyRequest(
caseId=self.case_id,
caseId=self.id,
timeStep=time_step,
property=property_name,
eclipseKeyword=eclipse_keyword,
@@ -832,6 +847,7 @@ class Case(PdmObject):
exportFile=export_file,
))
@add_method(Case)
def create_well_bore_stability_plot(self, well_path, time_step, wbs_parameters=None):
""" Create a new well bore stability plot
@@ -842,18 +858,21 @@ class Case(PdmObject):
Returns:
A new plot object
"""
pdm_parameters = None
pb2_parameters = None
if wbs_parameters is not None:
assert(isinstance(wbs_parameters, WbsParameters))
pdm_parameters = PdmObject.create("WbsParameters", self.__channel, self._project)
wbs_parameters.to_pdm_object(pdm_parameters)
pb2_parameters = wbs_parameters.pb2_object()
plot_result = self._execute_command(createWellBoreStabilityPlot=Cmd.CreateWbsPlotRequest(caseId=self.case_id,
plot_result = self._execute_command(createWellBoreStabilityPlot=Cmd.CreateWbsPlotRequest(caseId=self.id,
wellPath=well_path,
timeStep=time_step,
wbsParameters=pdm_parameters.pb2_object()))
return WellBoreStabilityPlot(self._project.plot(view_id=plot_result.createWbsPlotResult.viewId))
wbsParameters=pb2_parameters))
project = self.ancestor(rips.project.Project)
plot = project.plot(view_id=plot_result.createWbsPlotResult.viewId)
assert(plot)
return plot.cast(WellBoreStabilityPlot)
@add_method(Case)
def import_formation_names(self, formation_files=None):
""" Import formation names into project and apply it to the current case
@@ -867,25 +886,22 @@ class Case(PdmObject):
formation_files = [formation_files]
res = self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files,
applyToCaseId=self.case_id))
applyToCaseId=self.id))
@add_method(Case)
def simulation_wells(self):
"""Get a list of all simulation wells for a case
Returns:
A list of rips SimulationWell objects
"""
pdm_objects = self.descendants("Well")
wells = []
for pdm_object in pdm_objects:
wells.append(SimulationWell(pdm_object.get_value("WellName"), self.case_id, pdm_object))
wells = self.descendants(SimulationWell)
return wells
@add_method(Case)
def active_cell_centers_async(
self,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Get a cell centers for all active cells. Async, so returns an iterator
Arguments:
@@ -900,10 +916,10 @@ class Case(PdmObject):
porosity_model=porosity_model_enum)
return self.__case_stub.GetCellCenterForActiveCells(request)
@add_method(Case)
def active_cell_centers(
self,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Get a cell centers for all active cells. Synchronous, so returns a list.
Arguments:
@@ -919,10 +935,10 @@ class Case(PdmObject):
cell_centers.append(value)
return cell_centers
@add_method(Case)
def active_cell_corners_async(
self,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Get a cell corners for all active cells. Async, so returns an iterator
Arguments:
@@ -937,10 +953,10 @@ class Case(PdmObject):
porosity_model=porosity_model_enum)
return self.__case_stub.GetCellCornersForActiveCells(request)
@add_method(Case)
def active_cell_corners(
self,
porosity_model="MATRIX_MODEL",
):
porosity_model="MATRIX_MODEL"):
"""Get a cell corners for all active cells. Synchronous, so returns a list.
Arguments:
@@ -956,6 +972,7 @@ class Case(PdmObject):
cell_corners.append(value)
return cell_corners
@add_method(Case)
def selected_cells_async(self):
"""Get the selected cells. Async, so returns an iterator.
Returns:
@@ -964,6 +981,7 @@ class Case(PdmObject):
"""
return self.__case_stub.GetSelectedCells(self.__request)
@add_method(Case)
def selected_cells(self):
"""Get the selected cells. Synchronous, so returns a list.
@@ -977,6 +995,7 @@ class Case(PdmObject):
cells.append(value)
return cells
@add_method(Case)
def coarsening_info(self):
"""Get a coarsening information for all grids in the case.
@@ -986,13 +1005,13 @@ class Case(PdmObject):
"""
return self.__case_stub.GetCoarseningInfoArray(self.__request).data
@add_method(Case)
def available_nnc_properties(self):
"""Get a list of available NNC properties
"""
return self.__nnc_properties_stub.GetAvailableNNCProperties(self.__request).properties
@add_method(Case)
def nnc_connections_async(self):
"""Get the NNC connections. Async, so returns an iterator.
Returns:
@@ -1001,6 +1020,7 @@ class Case(PdmObject):
"""
return self.__nnc_properties_stub.GetNNCConnections(self.__request)
@add_method(Case)
def nnc_connections(self):
"""Get the NNC connection. Synchronous, so returns a list.
@@ -1014,13 +1034,15 @@ class Case(PdmObject):
connections.append(value)
return connections
@add_method(Case)
def __nnc_connections_values_async(self, property_name, property_type, time_step):
request = NNCProperties_pb2.NNCValuesRequest(case_id=self.case_id,
request = NNCProperties_pb2.NNCValuesRequest(case_id=self.id,
property_name=property_name,
property_type=property_type,
time_step=time_step)
return self.__nnc_properties_stub.GetNNCValues(request)
@add_method(Case)
def __nnc_values_generator_to_list(self, generator):
"""Converts a NNC values generator to a list."""
vals = []
@@ -1029,6 +1051,7 @@ class Case(PdmObject):
vals.append(value)
return vals
@add_method(Case)
def nnc_connections_static_values_async(self, property_name):
"""Get the static NNC values. Async, so returns an iterator.
Returns:
@@ -1040,6 +1063,7 @@ class Case(PdmObject):
"""
return self.__nnc_connections_values_async(property_name, NNCProperties_pb2.NNC_STATIC, 0)
@add_method(Case)
def nnc_connections_static_values(self, property_name):
"""Get the static NNC values.
Returns:
@@ -1050,6 +1074,7 @@ class Case(PdmObject):
generator = self.nnc_connections_static_values_async(property_name)
return self.__nnc_values_generator_to_list(generator)
@add_method(Case)
def nnc_connections_dynamic_values_async(self, property_name, time_step):
"""Get the dynamic NNC values. Async, so returns an iterator.
Returns:
@@ -1061,6 +1086,7 @@ class Case(PdmObject):
"""
return self.__nnc_connections_values_async(property_name, NNCProperties_pb2.NNC_DYNAMIC, time_step)
@add_method(Case)
def nnc_connections_dynamic_values(self, property_name, time_step):
"""Get the dynamic NNC values.
Returns:
@@ -1071,6 +1097,7 @@ class Case(PdmObject):
generator = self.nnc_connections_dynamic_values_async(property_name, time_step)
return self.__nnc_values_generator_to_list(generator)
@add_method(Case)
def nnc_connections_generated_values_async(self, property_name, time_step):
"""Get the generated NNC values. Async, so returns an iterator.
Returns:
@@ -1082,6 +1109,7 @@ class Case(PdmObject):
"""
return self.__nnc_connections_values_async(property_name, NNCProperties_pb2.NNC_GENERATED, time_step)
@add_method(Case)
def nnc_connections_generated_values(self, property_name, time_step):
"""Get the generated NNC values.
Returns:

View File

@@ -27,9 +27,8 @@ class ContourMap(View):
view_id(int): View Id corresponding to the View Id in ResInsight project.
"""
def __init__(self, pdm_object, project, map_type):
View.__init__(self, pdm_object, project)
self.view_id = pdm_object.get_value("ViewId")
def __init__(self, pdm_object, map_type):
View.__init__(self, pdm_object)
self.map_type = map_type
@@ -48,4 +47,4 @@ class ContourMap(View):
exportLocalCoordinates=export_local_coordinates,
undefinedValueLabel=undefined_value_label,
excludeUndefinedValues=exclude_undefined_values,
viewId=self.view_id))
viewId=self.id))

View File

@@ -28,7 +28,7 @@ class Grid:
Returns:
Vec3i: class with integer attributes i, j, k giving extent in all three dimensions.
"""
case_request = Case_pb2.CaseRequest(id=self.case.case_id)
case_request = Case_pb2.CaseRequest(id=self.case.id)
return self.__stub.GetDimensions(
Grid_pb2.GridRequest(case_request=case_request,
grid_index=self.index)).dimensions
@@ -40,7 +40,7 @@ class Grid:
Returns:
Iterator to a list of Vec3d: class with double attributes x, y, x giving cell centers
"""
case_request = Case_pb2.CaseRequest(id=self.case.case_id)
case_request = Case_pb2.CaseRequest(id=self.case.id)
chunks = self.__stub.GetCellCenters(
Grid_pb2.GridRequest(case_request=case_request,
grid_index=self.index))
@@ -66,7 +66,7 @@ class Grid:
Returns:
iterator to a list of CellCorners: a class with Vec3d for each corner (c0, c1.., c7)
"""
case_request = Case_pb2.CaseRequest(id=self.case.case_id)
case_request = Case_pb2.CaseRequest(id=self.case.id)
chunks = self.__stub.GetCellCorners(
Grid_pb2.GridRequest(case_request=case_request,
grid_index=self.index))

View File

@@ -2,25 +2,14 @@
Grid Case Group statistics module
"""
from rips.pdmobject import PdmObject
from rips.pdmobject import PdmObject, add_method
from rips.view import View
from rips.case import Case
import rips.generated.Commands_pb2 as Cmd
from rips.generated.pdm_objects import GridCaseGroup
class GridCaseGroup(PdmObject):
"""ResInsight Grid Case Group class
Operate on a ResInsight case group specified by a Case Group Id integer.
Attributes:
group_id (int): Grid Case Group Id corresponding to case group Id in ResInsight project.
"""
def __init__(self, pdm_object):
self.group_id = pdm_object.get_value("GroupId")
PdmObject.__init__(self, pdm_object._pb2_object, pdm_object._channel, pdm_object._project)
@add_method(GridCaseGroup)
def create_statistics_case(self):
"""Create a Statistics case in the Grid Case Group
@@ -33,19 +22,22 @@ class GridCaseGroup(PdmObject):
return Case(self.channel,
command_reply.createStatisticsCaseResult.caseId)
@add_method(GridCaseGroup)
def statistics_cases(self):
"""Get a list of all statistics cases in the Grid Case Group"""
stat_case_collection = self.children("StatisticsCaseCollection")[0]
return stat_case_collection.children("Reservoirs")
@add_method(GridCaseGroup)
def views(self):
"""Get a list of views belonging to a grid case group"""
pdm_objects = self.descendants("ReservoirView")
pdm_objects = self.descendants(EclipseView)
view_list = []
for pdm_object in pdm_objects:
view_list.append(View(pdm_object))
view_list.append(pdm_object)
return view_list
@add_method(GridCaseGroup)
def view(self, view_id):
"""Get a particular view belonging to a case group by providing view id
Arguments:
@@ -60,6 +52,7 @@ class GridCaseGroup(PdmObject):
return view_object
return None
@add_method(GridCaseGroup)
def compute_statistics(self, case_ids=None):
""" Compute statistics for the given case ids

View File

@@ -204,7 +204,7 @@ class Instance:
self.client_version_string())
# Service packages
self.project = Project(self.channel)
self.project = Project.create(self.channel)
path = os.getcwd()
self.set_start_dir(path=path)

View File

@@ -3,18 +3,41 @@
ResInsight caf::PdmObject connection module
"""
from functools import partial, wraps
import grpc
import re
import builtins
import importlib
import inspect
import sys
import rips.generated.PdmObject_pb2 as PdmObject_pb2
import rips.generated.PdmObject_pb2_grpc as PdmObject_pb2_grpc
import rips.generated.Commands_pb2 as Cmd
import rips.generated.Commands_pb2_grpc as CmdRpc
from rips.generated.pdm_objects import PdmObject
class PdmObject:
"""
Generic ResInsight object. Corresponds to items in the Project Tree
"""
def camel_to_snake(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
def add_method(cls):
def decorator(func):
setattr(cls, func.__name__, func)
return func # returning func means func can still be used normally
return decorator
def add_static_method(cls):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
setattr(cls, func.__name__, wrapper)
# Note we are not binding func, but wrapper which accepts self but does exactly the same as func
return func # returning func means func can still be used normally
return decorator
@add_method(PdmObject)
def _execute_command(self, **command_params):
self.__warnings = []
response, call = self._commands.Execute.with_call(Cmd.CommandParams(**command_params))
@@ -25,37 +48,67 @@ class PdmObject:
return response
def __init__(self, pb2_object, channel, project):
self._pb2_object = pb2_object
self._channel = channel
self._pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self._channel)
self._commands = CmdRpc.CommandsStub(channel)
self._project = project
@add_method(PdmObject)
def __custom_init__(self, pb2_object, channel):
self.__warnings = []
self.__keyword_translation = {}
@classmethod
def create(cls, class_keyword, channel, project):
pb2_object = PdmObject_pb2.PdmObject(class_keyword=class_keyword)
return cls(pb2_object, channel, project)
if pb2_object is not None:
self._pb2_object = pb2_object
else:
self._pb2_object = PdmObject_pb2.PdmObject(class_keyword=self.__class__.__name__)
self._channel = channel
if self.pb2_object() is not None and self.channel() is not None:
if self.channel() is not None:
self._pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel())
self._commands = CmdRpc.CommandsStub(self.channel())
for camel_keyword in self._pb2_object.parameters:
snake_keyword = camel_to_snake(camel_keyword)
setattr(self, snake_keyword, self.__get_grpc_value(camel_keyword))
self.__keyword_translation[snake_keyword] = camel_keyword
self._superclasses = self.superclasses()
@add_method(PdmObject)
def copy_from(self, object):
"""Copy attribute values from object to self
"""
for attribute in dir(object):
if not attribute.startswith('__'):
value = getattr(object, attribute)
if not callable(value):
setattr(self, attribute, value)
@add_method(PdmObject)
def cast(self, class_definition):
if class_definition.__name__ == self.class_keyword() or class_definition.__name__ in self._superclasses:
new_object = class_definition(self.pb2_object(), self.channel())
new_object.copy_from(self)
return new_object
return None
@add_method(PdmObject)
def warnings(self):
return self.__warnings
@add_method(PdmObject)
def has_warnings(self):
return len(self.__warnings) > 0
@add_method(PdmObject)
def pb2_object(self):
""" Private method"""
return self._pb2_object
@add_method(PdmObject)
def channel(self):
""" Private method"""
return self._channel
def project(self):
""" Private method"""
return self._project
@add_method(PdmObject)
def address(self):
"""Get the unique address of the PdmObject
@@ -65,33 +118,36 @@ class PdmObject:
return self._pb2_object.address
@add_method(PdmObject)
def class_keyword(self):
"""Get the class keyword in the ResInsight Data Model for the given PdmObject"""
return self._pb2_object.class_keyword
@add_method(PdmObject)
def set_visible(self, visible):
"""Set the visibility of the object in the ResInsight project tree"""
self._pb2_object.visible = visible
@add_method(PdmObject)
def visible(self):
"""Get the visibility of the object in the ResInsight project tree"""
return self._pb2_object.visible
def keywords(self):
"""Get a list of all parameter keywords available in the object"""
list_of_keywords = []
for keyword in self._pb2_object.parameters:
list_of_keywords.append(keyword)
return list_of_keywords
@add_method(PdmObject)
def print_object_info(self):
"""Print the structure and data content of the PdmObject"""
print("Class Keyword: " + self.class_keyword())
for keyword in self.keywords():
print(keyword + " [" + type(self.get_value(keyword)).__name__ +
"]: " + str(self.get_value(keyword)))
print("=========== " + self.class_keyword() + " =================")
print("Object Attributes: ")
for snake_kw, camel_kw in self.__keyword_translation.items():
print(" " + snake_kw + " [" + type(getattr(self, snake_kw)).__name__ +
"]: " + str(getattr(self, snake_kw)))
print("Object Methods:")
for method in dir(self):
if not method.startswith("_") and callable(getattr(self, method)):
print (" " + method)
def __to_value(self, value):
@add_method(PdmObject)
def __convert_from_grpc_value(self, value):
if value.lower() == 'false':
return False
if value.lower() == 'true':
@@ -110,7 +166,8 @@ class PdmObject:
return self.__makelist(value)
return value
def __from_value(self, value):
@add_method(PdmObject)
def __convert_to_grpc_value(self, value):
if isinstance(value, bool):
if value:
return "true"
@@ -118,61 +175,79 @@ class PdmObject:
if isinstance(value, list):
list_of_strings = []
for val in value:
list_of_strings.append(self.__from_value('\"' + val + '\"'))
list_of_strings.append(self.__convert_to_grpc_value('\"' + val + '\"'))
return "[" + ", ".join(list_of_strings) + "]"
return str(value)
def get_value(self, keyword):
"""Get the value associated with the provided keyword
Arguments:
keyword(str): A string containing the parameter keyword
@add_method(PdmObject)
def __get_grpc_value(self, camel_keyword):
return self.__convert_from_grpc_value(self._pb2_object.parameters[camel_keyword])
Returns:
The value of the parameter. Can be int, str or list.
"""
value = self._pb2_object.parameters[keyword]
return self.__to_value(value)
@add_method(PdmObject)
def __set_grpc_value(self, camel_keyword, value):
self._pb2_object.parameters[camel_keyword] = self.__convert_to_grpc_value(value)
def __islist(self, value):
return value.startswith("[") and value.endswith("]")
def __makelist(self, list_string):
list_string = list_string.lstrip("[")
list_string = list_string.rstrip("]")
strings = list_string.split(", ")
values = []
for string in strings:
values.append(self.__to_value(string))
return values
def set_value(self, keyword, value):
"""Set the value associated with the provided keyword
@add_method(PdmObject)
def set_value(self, snake_keyword, value):
"""Set the value associated with the provided keyword and updates ResInsight
Arguments:
keyword(str): A string containing the parameter keyword
value(varying): A value matching the type of the parameter.
See keyword documentation and/or print_object_info() to find
the correct data type.
"""
self._pb2_object.parameters[keyword] = self.__from_value(value)
setattr(self, snake_keyword, value)
self.update()
def descendants(self, class_keyword):
@add_method(PdmObject)
def __islist(self, value):
return value.startswith("[") and value.endswith("]")
@add_method(PdmObject)
def __makelist(self, list_string):
list_string = list_string.lstrip("[")
list_string = list_string.rstrip("]")
strings = list_string.split(", ")
values = []
for string in strings:
values.append(self.__convert_from_grpc_value(string))
return values
@add_method(PdmObject)
def descendants(self, class_keyword_or_class):
"""Get a list of all project tree descendants matching the class keyword
Arguments:
class_keyword[str]: A class keyword matching the type of class wanted
class_keyword_or_class[str/Class]: A class keyword matching the type of class wanted or a Class definition
Returns:
A list of PdmObjects matching the keyword provided
"""
class_definition = PdmObject
class_keyword = ""
if isinstance(class_keyword_or_class, str):
class_keyword = class_keyword_or_class
else:
assert(inspect.isclass(class_keyword_or_class))
class_keyword = class_keyword_or_class.__name__
class_definition = class_keyword_or_class
request = PdmObject_pb2.PdmDescendantObjectRequest(
object=self._pb2_object, child_keyword=class_keyword)
object_list = self._pdm_object_stub.GetDescendantPdmObjects(
request).objects
child_list = []
for pdm_object in object_list:
child_list.append(PdmObject(pdm_object, self._channel, self._project))
for pb2_object in object_list:
pdm_object = PdmObject(pb2_object=pb2_object, channel=self.channel())
if class_definition.__name__ == PdmObject.__name__:
child_list.append(pdm_object)
else:
casted_object = pdm_object.cast(class_definition)
if casted_object:
child_list.append(casted_object)
return child_list
def children(self, child_field):
@add_method(PdmObject)
def children(self, child_field, class_definition=PdmObject):
"""Get a list of all direct project tree children inside the provided child_field
Arguments:
child_field[str]: A field name
@@ -184,29 +259,66 @@ class PdmObject:
try:
object_list = self._pdm_object_stub.GetChildPdmObjects(request).objects
child_list = []
for pdm_object in object_list:
child_list.append(PdmObject(pdm_object, self._channel, self._project))
for pb2_object in object_list:
pdm_object = PdmObject(pb2_object=pb2_object, channel=self.channel())
if class_definition.__name__ == PdmObject.__name__:
child_list.append(pdm_object)
else:
child_list.append(pdm_object.cast(class_definition))
return child_list
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.NOT_FOUND:
return []
raise e
def ancestor(self, class_keyword):
@add_method(PdmObject)
def ancestor(self, class_keyword_or_class):
"""Find the first ancestor that matches the provided class_keyword
Arguments:
class_keyword[str]: A class keyword matching the type of class wanted
class_keyword_or_class[str/Class]: A class keyword matching the type of class wanted or a Class definition
"""
class_definition = PdmObject
class_keyword = ""
if isinstance(class_keyword_or_class, str):
class_keyword = class_keyword_or_class
else:
assert(inspect.isclass(class_keyword_or_class))
class_keyword = class_keyword_or_class.__name__
class_definition = class_keyword_or_class
request = PdmObject_pb2.PdmParentObjectRequest(
object=self._pb2_object, parent_keyword=class_keyword)
try:
return PdmObject(self._pdm_object_stub.GetAncestorPdmObject(request),
self._channel, self._project)
pb2_object = self._pdm_object_stub.GetAncestorPdmObject(request)
pdm_object = PdmObject(pb2_object=pb2_object,
channel=self._channel)
if class_definition.__name__ == PdmObject.__name__:
return pdm_object
else:
return pdm_object.cast(class_definition)
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.NOT_FOUND:
return None
raise e
@add_method(PdmObject)
def update(self):
"""Sync all fields from the Python Object to ResInsight"""
if self._pdm_object_stub is not None and self._pb2_object is not None:
for snake_kw, camel_kw in self.__keyword_translation.items():
self.__set_grpc_value(camel_kw, getattr(self, snake_kw))
self._pdm_object_stub.UpdateExistingPdmObject(self._pb2_object)
else:
raise Exception("Object is not connected to GRPC service so cannot update ResInsight")
@add_method(PdmObject)
def superclasses(self):
names = []
mod = importlib.import_module("rips.generated.pdm_objects")
for name, obj in inspect.getmembers(mod):
if (inspect.isclass(obj) and name == self.class_keyword()):
class_hierarchy = inspect.getmro(obj)
for cls in class_hierarchy:
names.append(cls.__name__)
return names

View File

@@ -4,18 +4,10 @@ ResInsight 2d plot module
import rips.generated.Commands_pb2 as Cmd
from rips.pdmobject import PdmObject
from rips.generated.pdm_objects import PlotWindow, Plot
from rips.pdmobject import add_method
class Plot(PdmObject):
"""ResInsight plot class
Attributes:
view_id(int): View Id corresponding to the View Id in ResInsight project.
"""
def __init__(self, pdm_object):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), pdm_object.project())
self.view_id = pdm_object.get_value("ViewId")
@add_method(PlotWindow)
def export_snapshot(self, export_folder='', file_prefix='', output_format='PNG'):
""" Export snapshot for the current plot
@@ -28,7 +20,7 @@ class Plot(PdmObject):
return self._execute_command(
exportSnapshots=Cmd.ExportSnapshotsRequest(type='PLOTS',
prefix=file_prefix,
viewId=self.view_id,
viewId=self.id,
exportFolder=export_folder,
plotOutputFormat=output_format))

View File

@@ -3,31 +3,36 @@
"""
The ResInsight project module
"""
import builtins
import grpc
from rips.case import Case
from rips.gridcasegroup import GridCaseGroup
from rips.pdmobject import PdmObject
from rips.pdmobject import PdmObject, add_method, add_static_method
from rips.plot import Plot
from rips.view import View
from rips.well import Well
from rips.wellpath import WellPathBase
from rips.contour_map import ContourMap, ContourMapType
import rips.generated.Commands_pb2 as Cmd
from rips.generated.Definitions_pb2 import Empty
import rips.generated.Project_pb2_grpc as Project_pb2_grpc
import rips.generated.Project_pb2 as Project_pb2
import rips.generated.PdmObject_pb2 as PdmObject_pb2
from rips.generated.pdm_objects import Project, PlotWindow
class Project(PdmObject):
"""ResInsight project. Not intended to be created separately.
@add_method(Project)
def __custom_init__(self, pb2_object, channel):
self._project_stub = Project_pb2_grpc.ProjectStub(self._channel)
Automatically created and assigned to Instance.
"""
def __init__(self, channel):
self._project_stub = Project_pb2_grpc.ProjectStub(channel)
PdmObject.__init__(self, self._project_stub.GetPdmObject(Empty()),
channel, self)
@add_static_method(Project)
def create(channel):
project_stub = Project_pb2_grpc.ProjectStub(channel)
pb2_object = project_stub.GetPdmObject(Empty())
return Project(pb2_object, channel)
@add_method(Project)
def open(self, path):
"""Open a new project from the given path
@@ -38,6 +43,7 @@ class Project(PdmObject):
self._execute_command(openProject=Cmd.FilePathRequest(path=path))
return self
@add_method(Project)
def save(self, path=""):
"""Save the project to the existing project file, or to a new file
Arguments:
@@ -46,10 +52,12 @@ class Project(PdmObject):
self._execute_command(saveProject=Cmd.SaveProjectRequest(filePath=path))
return self
@add_method(Project)
def close(self):
"""Close the current project (and open new blank project)"""
self._execute_command(closeProject=Empty())
@add_method(Project)
def load_case(self, path):
"""Load a new case from the given file path
@@ -60,8 +68,9 @@ class Project(PdmObject):
"""
command_reply = self._execute_command(loadCase=Cmd.FilePathRequest(
path=path))
return Case(self._channel, command_reply.loadCaseResult.id, self)
return self.case(command_reply.loadCaseResult.id)
@add_method(Project)
def selected_cases(self):
"""Get a list of all cases selected in the project tree
@@ -71,28 +80,24 @@ class Project(PdmObject):
case_infos = self._project_stub.GetSelectedCases(Empty())
cases = []
for case_info in case_infos.data:
cases.append(Case(self._channel, case_info.id, self))
cases.append(self.case(case_info.id))
return cases
@add_method(Project)
def cases(self):
"""Get a list of all cases in the project
Returns:
A list of rips Case objects
"""
try:
case_infos = self._project_stub.GetAllCases(Empty())
pdm_objects = self.descendants(Case.__name__)
cases = []
for case_info in case_infos.data:
cases.append(Case(self._channel, case_info.id, self))
for pdm_object in pdm_objects:
cases.append(pdm_object.cast(Case))
return cases
except grpc.RpcError as rpc_error:
if rpc_error.code() == grpc.StatusCode.NOT_FOUND:
return []
print("ERROR: ", rpc_error)
return []
@add_method(Project)
def case(self, case_id):
"""Get a specific case from the provided case Id
@@ -101,12 +106,13 @@ class Project(PdmObject):
Returns:
A rips Case object
"""
try:
case = Case(self._channel, case_id, self)
allCases = self.cases()
for case in allCases:
if case.id == case_id:
return case
except grpc.RpcError:
return None
@add_method(Project)
def replace_source_cases(self, grid_list_file, case_group_id=0):
"""Replace all source cases within a case group
@@ -118,6 +124,7 @@ class Project(PdmObject):
replaceSourceCases=Cmd.ReplaceSourceCasesRequest(
gridListFile=grid_list_file, caseGroupId=case_group_id))
@add_method(Project)
def create_grid_case_group(self, case_paths):
"""Create a Grid Case Group from a list of cases
@@ -132,14 +139,16 @@ class Project(PdmObject):
return self.grid_case_group(
command_reply.createGridCaseGroupResult.groupId)
@add_method(Project)
def views(self):
"""Get a list of views belonging to a project"""
pdm_objects = self.descendants("ReservoirView")
view_list = []
for pdm_object in pdm_objects:
view_list.append(View(pdm_object, self._project))
view_list.append(View(pdm_object))
return view_list
@add_method(Project)
def view(self, view_id):
"""Get a particular view belonging to a case by providing view id
@@ -149,20 +158,21 @@ class Project(PdmObject):
"""
views = self.views()
for view_object in views:
if view_object.view_id == view_id:
if view_object.id == view_id:
return view_object
return None
@add_method(Project)
def plots(self):
"""Get a list of all plots belonging to a project"""
pdm_objects = self.descendants("RimPlotWindow")
pdm_objects = self.descendants(PlotWindow)
plot_list = []
for pdm_object in pdm_objects:
plot = Plot(pdm_object)
if plot.view_id != -1:
plot_list.append(plot)
if pdm_object.id != -1:
plot_list.append(pdm_object)
return plot_list
@add_method(Project)
def plot(self, view_id):
"""Get a particular plot by providing view id
Arguments:
@@ -171,36 +181,27 @@ class Project(PdmObject):
"""
plots = self.plots()
for plot_object in plots:
if plot_object.view_id == view_id:
if plot_object.id == view_id:
return plot_object
return None
@add_method(Project)
def contour_maps(self, map_type=ContourMapType.ECLIPSE):
"""Get a list of all contour maps belonging to a project"""
pdm_objects = self.descendants(ContourMapType.get_identifier(map_type))
contour_maps = []
for pdm_object in pdm_objects:
contour_maps.append(ContourMap(pdm_object, self._project, map_type))
contour_maps.append(ContourMap(pdm_object, map_type))
return contour_maps
def well_paths(self):
"""Get a list of all the well path names in the project"""
pdm_objects = self.descendants("WellPathBase")
well_path_list = []
for pdm_object in pdm_objects:
well_path_list.append(pdm_object.get_value("WellPathName"))
return well_path_list
@add_method(Project)
def grid_case_groups(self):
"""Get a list of all grid case groups in the project"""
case_groups = self.descendants("RimIdenticalGridCaseGroup")
case_group_list = []
for pdm_group in case_groups:
case_group_list.append(GridCaseGroup(pdm_group))
return case_group_list
case_groups = self.descendants(GridCaseGroup)
return case_groups
@add_method(Project)
def grid_case_group(self, group_id):
"""Get a particular grid case group belonging to a project
@@ -215,6 +216,7 @@ class Project(PdmObject):
return case_group
return None
@add_method(Project)
def export_multi_case_snapshots(self, grid_list_file):
"""Export snapshots for a set of cases
@@ -225,6 +227,7 @@ class Project(PdmObject):
exportMultiCaseSnapshot=Cmd.ExportMultiCaseRequest(
gridListFile=grid_list_file))
@add_method(Project)
def export_snapshots(self, snapshot_type='ALL', prefix='', plot_format='PNG'):
""" Export all snapshots of a given type
@@ -237,6 +240,7 @@ class Project(PdmObject):
exportSnapshots=Cmd.ExportSnapshotsRequest(
type=snapshot_type, prefix=prefix, caseId=-1, viewId=-1, plotOutputFormat=plot_format))
@add_method(Project)
def export_well_paths(self, well_paths=None, md_step_size=5.0):
""" Export a set of well paths
@@ -251,6 +255,7 @@ class Project(PdmObject):
return self._execute_command(exportWellPaths=Cmd.ExportWellPathRequest(
wellPathNames=well_paths, mdStepSize=md_step_size))
@add_method(Project)
def scale_fracture_template(self, template_id, half_length, height,
d_factor, conductivity):
""" Scale fracture template parameters
@@ -270,6 +275,7 @@ class Project(PdmObject):
dFactor=d_factor,
conductivity=conductivity))
@add_method(Project)
def set_fracture_containment(self, template_id, top_layer, base_layer):
""" Set fracture template containment parameters
@@ -282,6 +288,7 @@ class Project(PdmObject):
setFractureContainment=Cmd.SetFracContainmentRequest(
id=template_id, topLayer=top_layer, baseLayer=base_layer))
@add_method(Project)
def import_well_paths(self, well_path_files=None, well_path_folder=''):
""" Import well paths into project
@@ -290,28 +297,41 @@ class Project(PdmObject):
well_path_folder(str): A folder path containing files to import
Returns:
A list of well path names (strings)
A list of WellPathBase objects
"""
if well_path_files is None:
well_path_files = []
res = self._execute_command(importWellPaths=Cmd.ImportWellPathsRequest(wellPathFolder=well_path_folder,
wellPathFiles=well_path_files))
return res.importWellPathsResult.wellPathNames
well_paths = []
for well_path_name in res.importWellPathsResult.wellPathNames:
well_paths.append(self.well_path_by_name(well_path_name))
return well_paths
def wells(self):
"""Get a list of all wells in the project
@add_method(Project)
def well_paths(self):
"""Get a list of all well paths in the project
Returns:
A list of rips Well objects
A list of rips WellPathBase objects
"""
pdm_objects = self.descendants("WellPathBase")
wells = []
for pdm_object in pdm_objects:
wells.append(Well(pdm_object.get_value("WellPathName"), pdm_object))
return wells
return self.descendants(WellPathBase)
@add_method(Project)
def well_path_by_name(self, well_path_name):
"""Get a specific well path by name from the project
Returns:
A WellPathBase object
"""
all_well_paths = self.well_paths()
for well_path in all_well_paths:
if well_path.name == well_path_name:
return well_path
return None
@add_method(Project)
def import_well_log_files(self, well_log_files=None, well_log_folder=''):
""" Import well log files into project
@@ -329,6 +349,7 @@ class Project(PdmObject):
wellLogFiles=well_log_files))
return res.importWellLogFilesResult.wellPathNames
@add_method(Project)
def import_formation_names(self, formation_files=None):
""" Import formation names into project

View File

@@ -10,30 +10,29 @@ import rips.generated.Properties_pb2 as Properties_pb2
import rips.generated.Properties_pb2_grpc as Properties_pb2_grpc
import rips.generated.Commands_pb2 as Cmd
from rips.generated.pdm_objects import SimulationWell
from rips.pdmobject import PdmObject
from rips.pdmobject import PdmObject, add_method
import rips.case
class SimulationWell(PdmObject):
"""ResInsight simulation well class
Attributes:
name(string): Name of the well.
"""
def __init__(self, name, case_id, pdm_object):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), pdm_object.project())
self._simulation_well_stub = SimulationWell_pb2_grpc.SimulationWellStub(pdm_object.channel())
self.name = name
self.case_id = case_id
@add_method(SimulationWell)
def __custom_init__(self, pb2_object, channel):
self._simulation_well_stub = SimulationWell_pb2_grpc.SimulationWellStub(channel)
@add_method(SimulationWell)
def status(self, timestep):
sim_well_request = SimulationWell_pb2.SimulationWellRequest(case_id=self.case_id,
sim_well_request = SimulationWell_pb2.SimulationWellRequest(case_id=self.case().id,
well_name=self.name,
timestep=timestep)
return self._simulation_well_stub.GetSimulationWellStatus(sim_well_request)
@add_method(SimulationWell)
def cells(self, timestep):
sim_well_request = SimulationWell_pb2.SimulationWellRequest(case_id=self.case_id,
sim_well_request = SimulationWell_pb2.SimulationWellRequest(case_id=self.case().id,
well_name=self.name,
timestep=timestep)
return self._simulation_well_stub.GetSimulationWellCells(sim_well_request).data
@add_method(SimulationWell)
def case(self):
return self.ancestor(rips.case.Case)

View File

@@ -20,7 +20,7 @@ def test_EmptyProject(rips_instance, initialize_test):
def test_OneCase(rips_instance, initialize_test):
case = rips_instance.project.load_case(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
assert(case.name == "TEST10K_FLT_LGR_NNC")
assert(case.case_id == 0)
assert(case.id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
@@ -120,11 +120,9 @@ def test_10k(rips_instance, initialize_test):
def test_PdmObject(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.case_id == 0)
assert(case.id == 0)
assert(case.address() is not 0)
assert(case.class_keyword() == "EclipseCase")
case_id = case.get_value('CaseId')
assert(case_id == case.case_id)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_brugge_0010(rips_instance, initialize_test):
@@ -146,21 +144,21 @@ def test_replaceCase(rips_instance, initialize_test):
case = project.case(case_id=0)
assert(case is not None)
assert(case.name == "TEST10K_FLT_LGR_NNC")
assert(case.case_id == 0)
assert(case.id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
case.replace(new_grid_file=case_path)
# Check that the case object has been changed
assert(case.name == "Real0--BRUGGE_0000.EGRID")
assert(case.case_id == 0)
assert(case.id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
# Check that retrieving the case object again will yield the changed object
case = project.case(case_id=0)
assert(case.name == "Real0--BRUGGE_0000.EGRID")
assert(case.case_id == 0)
assert(case.id == 0)
def test_loadNonExistingCase(rips_instance, initialize_test):
case_path = "Nonsense/Nonsense/Nonsense"

View File

@@ -14,7 +14,7 @@ def test_loadProject(rips_instance, initialize_test):
case = project.cases()[0]
assert(case is not None)
assert(case.name == "TEST10K_FLT_LGR_NNC")
assert(case.case_id == 0)
assert(case.id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
@@ -23,15 +23,17 @@ def test_well_log_plots(rips_instance, initialize_test):
plots = project.plots()
well_log_plots = []
for plot in plots:
well_log_plot = rips.WellLogPlot.from_pdm_object(plot)
well_log_plot = plot.cast(rips.WellLogPlot)
if well_log_plot is not None:
assert(well_log_plot.depth_type() == "MEASURED_DEPTH")
well_log_plot.print_object_info()
assert(well_log_plot.depth_type == "MEASURED_DEPTH")
well_log_plots.append(well_log_plot)
assert(len(well_log_plots) == 2)
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
for well_log_plot in well_log_plots:
well_log_plot.set_depth_type("TRUE_VERTICAL_DEPTH_RKB")
well_log_plot.depth_type = "TRUE_VERTICAL_DEPTH_RKB"
well_log_plot.update()
if rips_instance.is_gui():
well_log_plot.export_snapshot(tmpdirname)
well_log_plot.export_data_as_las(tmpdirname)
@@ -44,9 +46,9 @@ def test_well_log_plots(rips_instance, initialize_test):
plots2 = project.plots()
for plot2 in plots2:
well_log_plot2 = rips.WellLogPlot.from_pdm_object(plot)
well_log_plot2 = plot2.cast(rips.WellLogPlot)
if well_log_plot2 is not None:
assert(well_log_plot2.depth_type() == "TRUE_VERTICAL_DEPTH_RKB")
assert(well_log_plot2.depth_type == "TRUE_VERTICAL_DEPTH_RKB")
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_loadGridCaseGroup(rips_instance, initialize_test):

View File

@@ -12,8 +12,8 @@ def test_10k(rips_instance, initialize_test):
case = rips_instance.project.load_case(path=case_path)
assert(len(case.grids()) == 2)
well_path_files = [case_root_path + "/wellpath_a.dev", case_root_path + "/wellpath_b.dev"]
well_paths = rips_instance.project.import_well_paths(well_path_files)
wells = rips_instance.project.wells()
well_path_names = rips_instance.project.import_well_paths(well_path_files)
wells = rips_instance.project.well_paths()
assert(len(wells) == 2)
assert(wells[0].name == "Well Path A")
assert(wells[1].name == "Well Path B")

View File

@@ -1,49 +1,28 @@
"""
ResInsight 3d view module
"""
import builtins
import rips.generated.Commands_pb2 as Cmd
import rips.case # Circular import of Case, which already imports View. Use full name.
from rips.pdmobject import PdmObject
class View(PdmObject):
"""ResInsight view class
Attributes:
view_id(int): View Id corresponding to the View Id in ResInsight project.
"""
def __init__(self, pdm_object, project):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), project)
self.view_id = pdm_object.get_value("ViewId")
from rips.pdmobject import add_method
from rips.generated.pdm_objects import View, ViewWindow, ReservoirView, GeoMechView
@add_method(View)
def is_eclipse_view(self):
return self.class_keyword() == "ReservoirView"
return isinstance(self, ReservoirView)
@add_method(View)
def is_geomech_view(self):
return self.class_keyword() == "GeoMechView"
return isinstance(self, GeoMechView)
def show_grid_box(self):
"""Check if the grid box is meant to be shown in the view"""
return self.get_value("ShowGridBox")
def set_show_grid_box(self, value):
"""Set if the grid box is meant to be shown in the view"""
self.set_value("ShowGridBox", value)
def background_color(self):
"""Get the current background color in the view"""
return self.get_value("ViewBackgroundColor")
def set_background_color(self, bgcolor):
"""Set the background color in the view"""
self.set_value("ViewBackgroundColor", bgcolor)
def set_cell_result(self):
@add_method(View)
def cell_result(self):
"""Retrieve the current cell results"""
return self.children("GridCellResult")[0]
@add_method(View)
def apply_cell_result(self, result_type, result_variable):
"""Apply a regular cell result
@@ -59,11 +38,12 @@ class View(PdmObject):
- INJECTION_FLOODING
result_variable (str): String representing the result variable.
"""
cell_result = self.set_cell_result()
cell_result.set_value("ResultType", result_type)
cell_result.set_value("ResultVariable", result_variable)
cell_result = self.cell_result()
cell_result.result_type = result_type
cell_result.result_variable = result_variable
cell_result.update()
@add_method(View)
def apply_flow_diagnostics_cell_result(
self,
result_variable='TOF',
@@ -93,36 +73,30 @@ class View(PdmObject):
injectors = []
if producers is None:
producers = []
cell_result = self.set_cell_result()
cell_result.set_value("ResultType", "FLOW_DIAGNOSTICS")
cell_result.set_value("ResultVariable", result_variable)
cell_result.set_value("FlowTracerSelectionMode", selection_mode)
cell_result = self.cell_result()
cell_result.result_type = "FLOW_DIAGNOSTICS"
cell_result.result_variable = result_variable
cell_result.flow_tracer_selection_mode = selection_mode
if selection_mode == 'FLOW_TR_BY_SELECTION':
cell_result.set_value("SelectedInjectorTracers", injectors)
cell_result.set_value("SelectedProducerTracers", producers)
cell_result.selected_injector_tracers = injectors
cell_result.selected_producer_tracers = producers
cell_result.update()
def case(self):
"""Get the case the view belongs to"""
pdm_case = self.ancestor("EclipseCase")
if pdm_case is None:
pdm_case = self.ancestor("ResInsightGeoMechCase")
if pdm_case is None:
return None
return rips.case.Case(self._channel, pdm_case.get_value("CaseId"), self._project)
@add_method(View)
def clone(self):
"""Clone the current view"""
view_id = self._execute_command(cloneView=Cmd.CloneViewRequest(
viewId=self.view_id)).createViewResult.viewId
viewId=self.id)).createViewResult.viewId
return self.case().view(view_id)
@add_method(View)
def set_time_step(self, time_step):
"""Set the time step for current view"""
case_id = self.case().case_id
case_id = self.case().id
return self._execute_command(setTimeStep=Cmd.SetTimeStepParams(
caseId=case_id, viewId=self.view_id, timeStep=time_step))
caseId=case_id, viewId=self.id, timeStep=time_step))
@add_method(View)
def export_sim_well_fracture_completions(self, time_step,
simulation_well_names, file_split,
compdat_export):
@@ -154,16 +128,17 @@ class View(PdmObject):
if isinstance(simulation_well_names, str):
simulation_well_names = [simulation_well_names]
case_id = self.case().case_id
case_id = self.case().id
return self._execute_command(
exportSimWellFractureCompletions=Cmd.ExportSimWellPathFracRequest(
caseId=case_id,
viewId=self.view_id,
viewId=self.id,
timeStep=time_step,
simulationWellNames=simulation_well_names,
fileSplit=file_split,
compdatExport=compdat_export))
@add_method(View)
def export_visible_cells(self,
export_keyword='FLUXNUM',
visible_active_cells_value=1,
@@ -178,29 +153,38 @@ class View(PdmObject):
hidden_active_cells_value (int): Value to export for hidden active cells. Default: 0
inactive_cells_value (int): Value to export for inactive cells. Default: 0
"""
case_id = self.case().case_id
case_id = self.case().id
return self._execute_command(
exportVisibleCells=Cmd.ExportVisibleCellsRequest(
caseId=case_id,
viewId=self.view_id,
viewId=self.id,
exportKeyword=export_keyword,
visibleActiveCellsValue=visible_active_cells_value,
hiddenActiveCellsValue=hidden_active_cells_value,
inactiveCellsValue=inactive_cells_value))
@add_method(View)
def export_property(self, undefined_value=0.0):
""" Export the current Eclipse property from the view
Arguments:
undefined_value (double): Value to use for undefined values. Defaults to 0.0
"""
case_id = self.case().case_id
case_id = self.case().id
return self._execute_command(
exportPropertyInViews=Cmd.ExportPropertyInViewsRequest(
caseId=case_id,
viewIds=[self.view_id],
viewIds=[self.id],
undefinedValue=undefined_value))
@add_method(ViewWindow)
def case(self):
"""Get the case the view belongs to"""
mycase = self.ancestor(rips.case.Case)
assert(mycase is not None)
return mycase
@add_method(ViewWindow)
def export_snapshot(self, prefix='', export_folder=''):
""" Export snapshot for the current view
@@ -208,10 +192,10 @@ class View(PdmObject):
prefix (str): Exported file name prefix
export_folder(str): The path to export to. By default will use the global export folder
"""
case_id = self.case().case_id
case_id = self.case().id
return self._execute_command(
exportSnapshots=Cmd.ExportSnapshotsRequest(type='VIEWS',
prefix=prefix,
caseId=case_id,
viewId=self.view_id,
viewId=self.id,
exportFolder=export_folder))

View File

@@ -1,17 +0,0 @@
"""
ResInsight Well
"""
import rips.generated.Commands_pb2 as Cmd
from rips.pdmobject import PdmObject
class Well(PdmObject):
"""ResInsight well class
Attributes:
name(string): Name of the well.
"""
def __init__(self, name, pdm_object):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), pdm_object.project())
self.name = name

View File

@@ -2,38 +2,14 @@
ResInsight Well Bore Stability Plot module
"""
from rips.pdmobject import PdmObject
from rips.pdmobject import PdmObject, add_method
from rips.well_log_plot import WellLogPlot
from rips.generated.pdm_objects import WellBoreStabilityPlot, WbsParameters
class WbsParameters:
"""Well Bore Stability parameters
Note that any parameter sources left at "UNDEFINED" will get ResInsight defaults
which depends on the available data.
Attributes:
pore_pressure_in_reservoir_source(enum string): can be "GRID", "LAS_FILE" and "ELEMENT_PROPERTY_TABLE".
pore_pressure_outside_reservoir_source(enum string): can be "HYDROSTATIC" and "USER_DEFINED".
poisson_ratio_source(enum string): can be "LAS_FILE", "ELEMENT_PROPERTY_TABLE" or "USER_DEFINED".
ucs_source(enum string): can be "LAS_FILE", "ELEMENT_PROPERTY_TABLE" or "USER_DEFINED".
obg0_source(enum string): can be "GRID" or "LAS_FILE".
df_source(enum string): can be "LAS_FILE", "ELEMENT_PROPERTY_TABLE" or "USER_DEFINED".
fg_shale_source(enum string): can be "DERIVED_FROM_K0FG" or "PROPORTIONAL_TO_SH".
k0fg_source(enum string): can be "LAS_FILE" or "USER_DEFINED"". Only relevant if fg_shale_source is "DERIVED_FROM_K0FG".
user_pp_outside_reservoir(double): Used if pore_pressure_outside_reservoir_source is "USED_DEFINED". Default 1.05.
user_poission_ratio(double): Used if poisson_ratio_source is "USER_DEFINED", default 0.35.
user_ucs(double): Used if ucs_soruce is "USER_DEFINED", default 100.
user_df(double): Used if df is "USER_DEFINED", default 0.7.
user_k0sh(double): Used if k0sh_source is "USER_DEFINED", default 0.65.
fg_shale_sh_multiplier(double): Used if fg_shale_source is "PROPORTIONAL_TO_SH", default 1.05.
user_k0fg(double): Used if fg_shale_source is "DERIVED_FROM_K0FG" and k0fg_source is "USER_DEFINED", default 0.75.
"""
def __init__(self):
self.pore_pressure_in_reservoir_source = "UNDEFINED"
self.pore_pressure_outside_reservoir_source = "UNDEFINED"
@add_method(WbsParameters)
def __custom_init__(self, pb2_object=None, channel=None):
self.pore_pressure_reservoir_source = "UNDEFINED"
self.pore_pressure_non_reservoir_source = "UNDEFINED"
self.poisson_ratio_source = "UNDEFINED"
self.ucs_source = "UNDEFINED"
@@ -43,83 +19,27 @@ class WbsParameters:
self.fg_shale_source = "UNDEFINED"
self.k0fg_source = "UNDEFINED"
self.user_pp_outside_reservoir = 1.05
self.user_pp_non_reservoir = 1.05
self.user_poission_ratio = 0.35
self.user_ucs = 100
self.user_df = 0.7
self.user_k0sh = 0.65
self.fg_shale_multiplier = 1.05
self.fg_multiplier = 1.05
self.user_k0fg = 0.75
@classmethod
def from_pdm_object(cls, pdm_object):
params = cls()
params.pore_pressure_in_reservoir_source = pdm_object.get_value("PorePressureReservoirSource")
params.pore_pressure_outside_reservoir_source = pdm_object.get_value("PorePressureNonReservoirSource")
params.poisson_ratio_source = pdm_object.get_value("PoissonRatioSource")
params.ucs_source = pdm_object.get_value("UcsSource")
params.obg0_source = pdm_object.get_value("OBG0Source")
params.df_source = pdm_object.get_value("DFSource")
params.k0sh_source = pdm_object.get_value("K0SHSource")
params.fg_shale_source = pdm_object.get_value("FGShaleSource")
params.k0fg_source = pdm_object.get_value("K0FGSource")
params.user_pp_outside_reservoir = pdm_object.get_value("UserPPNonReservoir")
params.user_poisson_ratio = pdm_object.get_value("UserPoissonRatio")
params.user_ucs = pdm_object.get_value("UserUcs")
params.user_df = pdm_object.get_value("UserDF")
params.user_k0fg = pdm_object.get_value("UserK0FG")
params.user_k0sh = pdm_object.get_value("UserK0SH")
params.user_fg_shale = pdm_object.get_value("FGMultiplier")
return params
def to_pdm_object(self, pdm_object):
pdm_object.set_value("PorePressureReservoirSource", self.pore_pressure_in_reservoir_source)
pdm_object.set_value("PorePressureNonReservoirSource", self.pore_pressure_outside_reservoir_source)
pdm_object.set_value("UserPPNonReservoir", self.user_pp_outside_reservoir)
pdm_object.set_value("PoissonRatioSource", self.poisson_ratio_source)
pdm_object.set_value("UcsSource", self.ucs_source)
pdm_object.set_value("OBG0Source", self.obg0_source)
pdm_object.set_value("DFSource", self.df_source)
pdm_object.set_value("K0SHSource", self.k0sh_source)
pdm_object.set_value("FGShaleSource", self.fg_shale_source)
pdm_object.set_value("K0FGSource", self.k0fg_source)
pdm_object.set_value("UserPoissonRatio", self.user_poisson_ratio)
pdm_object.set_value("UserUcs", self.user_ucs)
pdm_object.set_value("UserDF", self.user_df)
pdm_object.set_value("UserK0FG", self.user_k0fg)
pdm_object.set_value("UserK0SH", self.user_k0sh)
pdm_object.set_value("FGMultiplier", self.user_fg_shale)
class WellBoreStabilityPlot(WellLogPlot):
"""ResInsight Well Bore Stability Plot
"""
def __init__(self, pdm_object):
WellLogPlot.__init__(self, pdm_object)
@classmethod
def from_pdm_object(cls, pdm_object):
if isinstance(pdm_object, PdmObject):
if pdm_object.class_keyword() == "WellBoreStabilityPlot":
return cls(pdm_object)
return None
@add_method(WellBoreStabilityPlot)
def parameters(self):
"""Retrieve the parameters of the Plot
"""
children = self.children("WbsParameters")
children = self.children("WbsParameters", WbsParameters)
if len(children) == 1:
child = children[0]
return WbsParameters.from_pdm_object(child)
return child
return None
@add_method(WellBoreStabilityPlot)
def set_parameters(self, wbs_parameters):
children = self.children("WbsParameters")
children = self.children("WbsParameters", WbsParameters)
if len(children) == 1:
pdm_params = children[0]
wbs_parameters.to_pdm_object(pdm_params)
pdm_params.update()
pdm_params.copy_from(wbs_parameters)

View File

@@ -6,21 +6,10 @@ import rips.generated.Commands_pb2 as Cmd
from rips.plot import Plot
from rips.pdmobject import PdmObject
from rips.generated.pdm_objects import WellLogPlot
from rips.pdmobject import add_method
class WellLogPlot(Plot):
"""ResInsight well log plot class
"""
def __init__(self, pdm_object):
Plot.__init__(self, pdm_object)
@classmethod
def from_pdm_object(cls, pdm_object):
if isinstance(pdm_object, PdmObject):
if pdm_object.class_keyword() == "WellLogPlot":
return cls(pdm_object)
return None
@add_method(WellLogPlot)
def export_data_as_las(self, export_folder, file_prefix='', export_tvdrkb=False, capitalize_file_names=False, resample_interval=0.0, convert_to_standard_units=False):
""" Export LAS file(s) for the current plot
@@ -35,7 +24,7 @@ class WellLogPlot(Plot):
A list of files exported
"""
res = self._execute_command(exportWellLogPlotData=Cmd.ExportWellLogPlotDataRequest(exportFormat='LAS',
viewId=self.view_id,
viewId=self.id,
exportFolder=export_folder,
filePrefix=file_prefix,
exportTvdRkb=export_tvdrkb,
@@ -44,6 +33,7 @@ class WellLogPlot(Plot):
convertCurveUnits=convert_to_standard_units))
return res.exportWellLogPlotDataResult.exportedFiles
@add_method(WellLogPlot)
def export_data_as_ascii(self, export_folder, file_prefix='', capitalize_file_names=False):
""" Export LAS file(s) for the current plot
@@ -56,65 +46,10 @@ class WellLogPlot(Plot):
A list of files exported
"""
res = self._execute_command(exportWellLogPlotData=Cmd.ExportWellLogPlotDataRequest(exportFormat='ASCII',
viewId=self.view_id,
viewId=self.id,
exportFolder=export_folder,
filePrefix=file_prefix,
exportTvdRkb=False,
capitalizeFileNames=capitalize_file_names,
resampleInterval=0.0))
return res.exportWellLogPlotDataResult.exportedFiles
def depth_range(self):
"""Get the depth range of the Plot
"""
return self.get_value("MinimumDepth"), self.get_value("MaximumDepth")
def set_depth_range(self, min_depth, max_depth, update=True):
""" Set the visible depth range minimum
Arguments:
min_depth(double): The new minimum depth
max_depth(double): The new maximum depth
update(bool, optional): Update the plot after setting the value?
"""
self.set_value("MinimumDepth", min_depth)
self.set_value("MaximumDepth", max_depth)
self.set_value("AutoScaleDepthEnabled", False)
if update:
self.update()
def depth_type(self):
"""Get the plot depth type
Returns: an enum string. Can be "MEASURED_DEPTH", "TRUE_VERTICAL_DEPTH" or "TRUE_VERTICAL_DEPTH_RKB".
"""
return self.get_value("DepthType")
def set_depth_type(self, depth_type, update=True):
"""Set the depth type
Arguments:
depth_type(enum string): can be "MEASURED_DEPTH", "TRUE_VERTICAL_DEPTH" or "TRUE_VERTICAL_DEPTH_RKB".
update(bool, optional): Update the plot after setting the value?
"""
self.set_value("DepthType", depth_type)
if update:
self.update()
def depth_unit(self):
"""Get the plot depth units
Returns: an enum string. Can be "UNIT_METER", "UNIT_FEET" or "UNIT_NONE".
"""
def set_depth_unit(self, depth_unit, update=True):
"""Set the depth unit
Arguments:
depth_unit(enum string): can be "UNIT_METER", "UNIT_FEET" or "UNIT_NONE".
update(bool, optional): Update the plot after setting the value?
"""
self.set_value("DepthUnit", depth_unit)
if update:
self.update()

View File

@@ -0,0 +1,6 @@
"""
ResInsight Well
"""
import rips.generated.Commands_pb2 as Cmd
from rips.generated.pdm_objects import WellPathBase

View File

@@ -74,7 +74,7 @@ void caf::AppEnum<Rim3dView::SurfaceModeType>::setUp()
} // End namespace caf
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( Rim3dView, "GenericView" ); // Do not use. Abstract class
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( Rim3dView, "View", "GenericView" ); // Do not use. Abstract class
//--------------------------------------------------------------------------------------------------
///
@@ -86,7 +86,10 @@ Rim3dView::Rim3dView( void )
RiaPreferences* preferences = app->preferences();
CVF_ASSERT( preferences );
RICF_InitField( &m_id, "ViewId", -1, "View ID", "", "", "" );
CAF_PDM_InitObject( "3d View", "", "", "" );
RICF_InitField( &m_id, "Id", -1, "View ID", "", "", "" );
m_id.xmlCapability()->registerKeywordAlias( "ViewId" );
m_id.uiCapability()->setUiReadOnly( true );
m_id.uiCapability()->setUiHidden( true );
m_id.capability<RicfFieldHandle>()->setIOWriteable( false );
@@ -104,20 +107,21 @@ Rim3dView::Rim3dView( void )
CAF_PDM_InitField( &m_cameraPointOfInterest, "CameraPointOfInterest", cvf::Vec3d::ZERO, "", "", "", "" );
m_cameraPointOfInterest.uiCapability()->setUiHidden( true );
CAF_PDM_InitField( &isPerspectiveView, "PerspectiveProjection", true, "Perspective Projection", "", "", "" );
RICF_InitField( &isPerspectiveView, "PerspectiveProjection", true, "Perspective Projection", "", "", "" );
double defaultScaleFactor = preferences->defaultScaleFactorZ();
CAF_PDM_InitField( &scaleZ, "GridZScale", defaultScaleFactor, "Z Scale", "", "Scales the scene in the Z direction", "" );
RICF_InitField( &scaleZ, "GridZScale", defaultScaleFactor, "Z Scale", "", "Scales the scene in the Z direction", "" );
cvf::Color3f defBackgColor = preferences->defaultViewerBackgroundColor();
RICF_InitField( &m_backgroundColor, "ViewBackgroundColor", defBackgColor, "Background", "", "", "" );
RICF_InitField( &m_backgroundColor, "BackgroundColor", defBackgColor, "Background", "", "", "" );
m_backgroundColor.xmlCapability()->registerKeywordAlias( "ViewBackgroundColor" );
CAF_PDM_InitField( &maximumFrameRate, "MaximumFrameRate", 10, "Maximum Frame Rate", "", "", "" );
maximumFrameRate.uiCapability()->setUiHidden( true );
CAF_PDM_InitField( &hasUserRequestedAnimation, "AnimationMode", false, "Animation Mode", "", "", "" );
hasUserRequestedAnimation.uiCapability()->setUiHidden( true );
CAF_PDM_InitField( &m_currentTimeStep, "CurrentTimeStep", 0, "Current Time Step", "", "", "" );
RICF_InitField( &m_currentTimeStep, "CurrentTimeStep", 0, "Current Time Step", "", "", "" );
m_currentTimeStep.uiCapability()->setUiHidden( true );
caf::AppEnum<RiaDefines::MeshModeType> defaultMeshType = preferences->defaultMeshModeType();
@@ -126,7 +130,7 @@ Rim3dView::Rim3dView( void )
RICF_InitField( &m_showGridBox, "ShowGridBox", true, "Show Grid Box", "", "", "" );
CAF_PDM_InitField( &m_disableLighting,
RICF_InitField( &m_disableLighting,
"DisableLighting",
false,
"Disable Results Lighting",
@@ -134,7 +138,7 @@ Rim3dView::Rim3dView( void )
"Disable light model for scalar result colors",
"" );
CAF_PDM_InitField( &m_showZScaleLabel, "ShowZScale", true, "Show Z Scale Label", "", "", "" );
RICF_InitField( &m_showZScaleLabel, "ShowZScale", true, "Show Z Scale Label", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_comparisonView, "ComparisonView", "Comparison View", "", "", "" );
@@ -879,10 +883,13 @@ void Rim3dView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const
}
}
else if ( changedField == &m_showZScaleLabel )
{
if ( m_viewer )
{
m_viewer->showZScaleLabel( m_showZScaleLabel() );
m_viewer->update();
}
}
else if ( changedField == &m_comparisonView )
{
createDisplayModelAndRedraw();

View File

@@ -110,7 +110,7 @@
#include <climits>
CAF_PDM_SOURCE_INIT( RimEclipseView, "ReservoirView" );
CAF_PDM_XML_SCRIPTABLE_SOURCE_INIT( RimEclipseView, "ReservoirView" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -120,7 +120,7 @@ RimEclipseView::RimEclipseView()
RiaPreferences* preferences = app->preferences();
CVF_ASSERT( preferences );
CAF_PDM_InitObject( "Reservoir View", ":/3DView16x16.png", "", "" );
CAF_PDM_InitObject( "Reservoir View", ":/3DView16x16.png", "", "The Eclipse 3d Reservoir View" );
CAF_PDM_InitFieldNoDefault( &m_cellResult, "GridCellResult", "Cell Result", ":/CellResult.png", "", "" );
m_cellResult = new RimEclipseCellColors();

View File

@@ -5,7 +5,7 @@
#include "RimTools.h"
#include "cafUtils.h"
CAF_PDM_SOURCE_INIT( RimFileWellPath, "WellPath" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimFileWellPath, "WellPath" );
//--------------------------------------------------------------------------------------------------
///

View File

@@ -77,7 +77,7 @@
#include <QMessageBox>
CAF_PDM_SOURCE_INIT( RimGeoMechView, "GeoMechView" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimGeoMechView, "GeoMechView" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -87,7 +87,7 @@ RimGeoMechView::RimGeoMechView( void )
RiaPreferences* preferences = app->preferences();
CVF_ASSERT( preferences );
CAF_PDM_InitObject( "Geomechanical View", ":/3DViewGeoMech16x16.png", "", "" );
CAF_PDM_InitObject( "Geomechanical View", ":/3DViewGeoMech16x16.png", "", "The Geomechanical 3d View" );
CAF_PDM_InitFieldNoDefault( &cellResult, "GridCellResult", "Color Result", ":/CellResult.png", "", "" );
cellResult = new RimGeoMechCellColors();

View File

@@ -48,7 +48,7 @@
#include <QDir>
#include <QMessageBox>
CAF_PDM_SOURCE_INIT( RimIdenticalGridCaseGroup, "RimIdenticalGridCaseGroup" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimIdenticalGridCaseGroup, "GridCaseGroup", "RimIdenticalGridCaseGroup" );
//--------------------------------------------------------------------------------------------------
///

View File

@@ -32,7 +32,7 @@
#include "RimWellPathFractureCollection.h"
#include "cafPdmUiTreeOrdering.h"
CAF_PDM_SOURCE_INIT( RimModeledWellPath, "ModeledWellPath" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimModeledWellPath, "ModeledWellPath" );
//--------------------------------------------------------------------------------------------------
///

View File

@@ -25,7 +25,7 @@ void RimPlot::RowOrColSpanEnum::setUp()
}
} // namespace caf
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlot, "RimPlot" ); // Do not use. Abstract class
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlot, "Plot", "RimPlot" ); // Do not use. Abstract class
//--------------------------------------------------------------------------------------------------
///

View File

@@ -30,7 +30,7 @@
#include <QPainter>
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotWindow, "RimPlotWindow" ); // Do not use. Abstract class
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotWindow, "PlotWindow", "RimPlotWindow" ); // Do not use. Abstract class
//--------------------------------------------------------------------------------------------------
///
@@ -39,7 +39,8 @@ RimPlotWindow::RimPlotWindow()
{
CAF_PDM_InitObject( "PlotWindow", "", "", "" );
RICF_InitField( &m_id, "ViewId", -1, "View ID", "", "", "" );
RICF_InitField( &m_id, "Id", -1, "View ID", "", "", "" );
m_id.xmlCapability()->registerKeywordAlias( "ViewId" );
m_id.uiCapability()->setUiReadOnly( true );
m_id.uiCapability()->setUiHidden( true );
m_id.capability<RicfFieldHandle>()->setIOWriteable( false );

View File

@@ -101,7 +101,7 @@
#include <QMenu>
#include <algorithm>
CAF_PDM_SOURCE_INIT( RimProject, "ResInsightProject" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimProject, "Project", "ResInsightProject" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -55,16 +55,17 @@
//--------------------------------------------------------------------------------------------------
Rim2dIntersectionView* corresponding2dIntersectionView( RimSimWellInView* simWellInView );
CAF_PDM_SOURCE_INIT( RimSimWellInView, "Well" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimSimWellInView, "SimulationWell", "Well" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSimWellInView::RimSimWellInView()
{
CAF_PDM_InitObject( "Well", ":/Well.png", "", "" );
CAF_PDM_InitObject( "Simulation Well", ":/Well.png", "", "" );
RICF_InitFieldNoDefault( &name, "WellName", "Name", "", "", "" );
RICF_InitFieldNoDefault( &name, "Name", "Name", "", "", "" );
name.xmlCapability()->registerKeywordAlias( "WellName" );
CAF_PDM_InitField( &showWell, "ShowWell", true, "Show well ", "", "", "" );

View File

@@ -26,7 +26,7 @@
#include "RimWellLogFile.h"
#include "RimWellPath.h"
CAF_PDM_SOURCE_INIT( RimWbsParameters, "WbsParameters" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimWbsParameters, "WbsParameters" );
//--------------------------------------------------------------------------------------------------
///

View File

@@ -33,7 +33,7 @@
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiGroup.h"
CAF_PDM_SOURCE_INIT( RimWellBoreStabilityPlot, "WellBoreStabilityPlot" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimWellBoreStabilityPlot, "WellBoreStabilityPlot" );
//--------------------------------------------------------------------------------------------------
///

View File

@@ -64,14 +64,17 @@ void RimWellLogPlot::AxisGridEnum::setUp()
} // End namespace caf
CAF_PDM_SOURCE_INIT( RimWellLogPlot, "WellLogPlot" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimWellLogPlot, "WellLogPlot" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogPlot::RimWellLogPlot()
{
CAF_PDM_InitObject( "Well Log Plot", ":/WellLogPlot16x16.png", "", "" );
CAF_PDM_InitObject( "Well Log Plot",
":/WellLogPlot16x16.png",
"",
"A Well Log Plot With a shared Depth Axis and Multiple Tracks" );
CAF_PDM_InitFieldNoDefault( &m_commonDataSource,
"CommonDataSource",

View File

@@ -61,7 +61,7 @@
#include <regex>
CAF_PDM_SOURCE_INIT( RimWellPath, "WellPathBase" );
CAF_PDM_SCRIPTABLE_SOURCE_INIT( RimWellPath, "WellPathBase" );
//--------------------------------------------------------------------------------------------------
///
@@ -75,7 +75,8 @@ RimWellPath::RimWellPath()
{
CAF_PDM_InitObject( "WellPath", ":/Well.png", "", "" );
RICF_InitFieldNoDefault( &m_name, "WellPathName", "Name", "", "", "" );
RICF_InitFieldNoDefault( &m_name, "Name", "Name", "", "", "" );
m_name.xmlCapability()->registerKeywordAlias( "WellPathName" );
m_name.uiCapability()->setUiReadOnly( true );
m_name.uiCapability()->setUiHidden( true );
m_name.xmlCapability()->disableIO();