diff --git a/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp b/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp index ef2b8a5f83..5098ae1877 100644 --- a/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp +++ b/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp @@ -37,7 +37,7 @@ #include #include -RICF_SOURCE_INIT( RicExportContourMapToAsciiFeature, "RicExportContourMapToAsciiFeature", "exportContourMapToAscii" ); +RICF_SOURCE_INIT( RicExportContourMapToAsciiFeature, "RicExportContourMapToAsciiFeature", "exportContourMapToText" ); RicExportContourMapToAsciiFeature::RicExportContourMapToAsciiFeature() { diff --git a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto index c140a77e8b..2a5d703243 100644 --- a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto +++ b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto @@ -314,6 +314,14 @@ message ExportWellLogPlotDataRequest double resampleInterval = 7; } +message ExportContourMapToTextRequest +{ + string exportFileName = 1; + bool exportLocalCoordinates = 2; + string undefinedValueLabel = 3; + int32 viewId = 4; +} + /* CommandParams handles both command name and parameters in one. * The message type and content is used as parameters and * the name of the variable is used to find the command name. */ @@ -325,43 +333,44 @@ message CommandParams * the FilePathRequest message. */ oneof params { - FilePathRequest openProject = 1; - Empty closeProject = 2; - FilePathRequest setStartDir = 3; - FilePathRequest loadCase = 4; - ReplaceCaseRequest replaceCase = 5; - ReplaceSourceCasesRequest replaceSourceCases = 6; - ExportMultiCaseRequest exportMultiCaseSnapshots = 7; - ExportSnapshotsRequest exportSnapshots = 8; - ExportPropertyRequest exportProperty = 9; - ExportPropertyInViewsRequest exportPropertyInViews = 10; - ExportWellPathCompRequest exportWellPathCompletions = 11; - ExportSimWellPathFracRequest exportSimWellFractureCompletions = 12; - ExportMswRequest exportMsw = 13; - ExportWellPathRequest exportWellPaths = 14; - ExportVisibleCellsRequest exportVisibleCells = 15; - SetExportFolderRequest setExportFolder = 16; - RunOctaveScriptRequest runOctaveScript = 17; - SetWindowSizeParams setMainWindowSize = 18; - ComputeCaseGroupStatRequest computeCaseGroupStatistics = 19; - SetTimeStepParams setTimeStep = 20; - ScaleFractureTemplateRequest scaleFractureTemplate = 21; - SetFracContainmentRequest setFractureContainment = 22; - CreateMultipleFracRequest createMultipleFractures = 23; - CreateLgrForCompRequest createLgrForCompletions = 24; - CreateSatPressPlotRequest createSaturationPressurePlots = 25; - ReplaceCaseRequests replaceMultipleCases = 26; - CreateGridCaseGroupRequest createGridCaseGroup = 27; - CreateStatisticsCaseRequest createStatisticsCase = 28; - ExportFlowInfoRequest exportFlowCharacteristics = 29; - CreateViewRequest createView = 30; - CloneViewRequest cloneView = 31; - CreateWbsPlotRequest createWellBoreStabilityPlot = 32; - ImportWellPathsRequest importWellPaths = 33; - ImportWellLogFilesRequest importWellLogFiles = 34; - ImportFormationNamesRequest importFormationNames = 35; - ExportWellLogPlotDataRequest exportWellLogPlotData = 36; - SetWindowSizeParams setPlotWindowSize = 37; + FilePathRequest openProject = 1; + Empty closeProject = 2; + FilePathRequest setStartDir = 3; + FilePathRequest loadCase = 4; + ReplaceCaseRequest replaceCase = 5; + ReplaceSourceCasesRequest replaceSourceCases = 6; + ExportMultiCaseRequest exportMultiCaseSnapshots = 7; + ExportSnapshotsRequest exportSnapshots = 8; + ExportPropertyRequest exportProperty = 9; + ExportPropertyInViewsRequest exportPropertyInViews = 10; + ExportWellPathCompRequest exportWellPathCompletions = 11; + ExportSimWellPathFracRequest exportSimWellFractureCompletions = 12; + ExportMswRequest exportMsw = 13; + ExportWellPathRequest exportWellPaths = 14; + ExportVisibleCellsRequest exportVisibleCells = 15; + SetExportFolderRequest setExportFolder = 16; + RunOctaveScriptRequest runOctaveScript = 17; + SetWindowSizeParams setMainWindowSize = 18; + ComputeCaseGroupStatRequest computeCaseGroupStatistics = 19; + SetTimeStepParams setTimeStep = 20; + ScaleFractureTemplateRequest scaleFractureTemplate = 21; + SetFracContainmentRequest setFractureContainment = 22; + CreateMultipleFracRequest createMultipleFractures = 23; + CreateLgrForCompRequest createLgrForCompletions = 24; + CreateSatPressPlotRequest createSaturationPressurePlots = 25; + ReplaceCaseRequests replaceMultipleCases = 26; + CreateGridCaseGroupRequest createGridCaseGroup = 27; + CreateStatisticsCaseRequest createStatisticsCase = 28; + ExportFlowInfoRequest exportFlowCharacteristics = 29; + CreateViewRequest createView = 30; + CloneViewRequest cloneView = 31; + CreateWbsPlotRequest createWellBoreStabilityPlot = 32; + ImportWellPathsRequest importWellPaths = 33; + ImportWellLogFilesRequest importWellLogFiles = 34; + ImportFormationNamesRequest importFormationNames = 35; + ExportWellLogPlotDataRequest exportWellLogPlotData = 36; + SetWindowSizeParams setPlotWindowSize = 37; + ExportContourMapToTextRequest exportContourMapToText = 38; } } diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/export_contour_maps.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/export_contour_maps.py new file mode 100644 index 0000000000..448c706b2b --- /dev/null +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/export_contour_maps.py @@ -0,0 +1,32 @@ +# Load ResInsight Processing Server Client Library +import rips +import tempfile +import pathlib + +# Connect to ResInsight instance +resInsight = rips.Instance.find() + +# Data will be written to temp +tmpdir = pathlib.Path(tempfile.gettempdir()) + +# Find all eclipse contour maps of the project +contour_maps = resInsight.project.contour_maps(rips.ContourMapType.ECLIPSE) +print("Number of eclipse contour maps:", len(contour_maps)) + +# Export the contour maps to a text file +for (index, contour_map) in enumerate(contour_maps): + filename = "eclipse_contour_map" + str(index) + ".txt" + filepath = tmpdir / filename + print("Exporting to:", filepath) + contour_map.export_to_text(str(filepath)) + +# The contour maps is also available for a Case +cases = resInsight.project.cases() +for case in cases: + contour_maps = case.contour_maps(rips.ContourMapType.GEO_MECH) + # Export the contour maps to a text file + for (index, contour_map) in enumerate(contour_maps): + filename = "geomech_contour_map" + str(index) + ".txt" + filepath = tmpdir / filename + print("Exporting to:", filepath) + contour_map.export_to_text(str(filepath)) diff --git a/ApplicationCode/GrpcInterface/Python/rips/__init__.py b/ApplicationCode/GrpcInterface/Python/rips/__init__.py index 9b4b5a42b1..a85ad5ec55 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/__init__.py +++ b/ApplicationCode/GrpcInterface/Python/rips/__init__.py @@ -10,4 +10,5 @@ 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 \ No newline at end of file +from rips.plot import Plot +from rips.contour_map import ContourMap, ContourMapType diff --git a/ApplicationCode/GrpcInterface/Python/rips/case.py b/ApplicationCode/GrpcInterface/Python/rips/case.py index fe08d9f7de..1a3a105444 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/case.py +++ b/ApplicationCode/GrpcInterface/Python/rips/case.py @@ -18,7 +18,7 @@ import rips.generated.Properties_pb2_grpc as Properties_pb2_grpc from rips.grid import Grid from rips.pdmobject import PdmObject from rips.view import View - +from rips.contour_map import ContourMap, ContourMapType class Case(PdmObject): """ResInsight case class @@ -250,6 +250,15 @@ class Case(PdmObject): self._execute_command(createView=Cmd.CreateViewRequest( caseId=self.case_id)).createViewResult.viewId) + 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)) + return contour_maps + def export_snapshots_of_all_views(self, prefix="", export_folder=""): """ Export snapshots for all views in the case @@ -764,4 +773,4 @@ class Case(PdmObject): formation_files = [formation_files] res = self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files, - applyToCaseId=self.case_id)) \ No newline at end of file + applyToCaseId=self.case_id)) diff --git a/ApplicationCode/GrpcInterface/Python/rips/contour_map.py b/ApplicationCode/GrpcInterface/Python/rips/contour_map.py new file mode 100644 index 0000000000..696dd483b6 --- /dev/null +++ b/ApplicationCode/GrpcInterface/Python/rips/contour_map.py @@ -0,0 +1,48 @@ +""" +ResInsight 3d contour map module +""" +import rips.generated.Commands_pb2 as Cmd + +from rips.pdmobject import PdmObject +from rips.view import View +from enum import Enum + +class ContourMapType(Enum): + ECLIPSE = 1 + GEO_MECH = 2 + + @staticmethod + def get_identifier(map_type): + if map_type==ContourMapType.ECLIPSE: + return "RimContourMapView" + elif map_type==ContourMapType.GEO_MECH: + return "RimGeoMechContourMapView" + else: + raise Exception("Unknown contour map type: must be ECLIPSE or GEO_MECH") + +class ContourMap(View): + """ResInsight contour map class + + Attributes: + 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") + self.map_type = map_type + + + def export_to_text(self, export_file_name='', export_local_coordinates=False, undefined_value_label="NaN"): + """ Export snapshot for the current view + Arguments: + export_file_name(str): The file location to store results in. + export_local_coordinates(bool): Should we export local coordinates, or UTM. + undefined_value_label(str): Replace undefined values with this label. + """ + return self._execute_command( + exportContourMapToText=Cmd.ExportContourMapToTextRequest( + exportFileName=export_file_name, + exportLocalCoordinates=export_local_coordinates, + undefinedValueLabel=undefined_value_label, + viewId=self.view_id)) diff --git a/ApplicationCode/GrpcInterface/Python/rips/project.py b/ApplicationCode/GrpcInterface/Python/rips/project.py index 4f12ca6a6b..1269ab748a 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/project.py +++ b/ApplicationCode/GrpcInterface/Python/rips/project.py @@ -10,6 +10,7 @@ from rips.gridcasegroup import GridCaseGroup from rips.pdmobject import PdmObject from rips.plot import Plot from rips.view import View +from rips.contour_map import ContourMap, ContourMapType import rips.generated.Commands_pb2 as Cmd from rips.generated.Definitions_pb2 import Empty @@ -163,6 +164,15 @@ class Project(PdmObject): return plot_object return None + 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)) + return contour_maps + def well_paths(self): """Get a list of all the well path names in the project""" pdm_objects = self.descendants("WellPathBase") @@ -307,4 +317,4 @@ class Project(PdmObject): formation_files = [formation_files] res = self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files, - applyToCaseId=-1)) \ No newline at end of file + applyToCaseId=-1))