mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4821 Add python objects for Contour Map export.
This commit is contained in:
parent
c615c7507b
commit
8e076b3acb
@ -37,7 +37,7 @@
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
|
||||
RICF_SOURCE_INIT( RicExportContourMapToAsciiFeature, "RicExportContourMapToAsciiFeature", "exportContourMapToAscii" );
|
||||
RICF_SOURCE_INIT( RicExportContourMapToAsciiFeature, "RicExportContourMapToAsciiFeature", "exportContourMapToText" );
|
||||
|
||||
RicExportContourMapToAsciiFeature::RicExportContourMapToAsciiFeature()
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))
|
@ -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
|
||||
from rips.plot import Plot
|
||||
from rips.contour_map import ContourMap, ContourMapType
|
||||
|
@ -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))
|
||||
applyToCaseId=self.case_id))
|
||||
|
48
ApplicationCode/GrpcInterface/Python/rips/contour_map.py
Normal file
48
ApplicationCode/GrpcInterface/Python/rips/contour_map.py
Normal file
@ -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))
|
@ -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))
|
||||
applyToCaseId=-1))
|
||||
|
Loading…
Reference in New Issue
Block a user