mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5792 Python : Add import_summary_case and find summary case from ID
Add example of use and updated documentation
This commit is contained in:
committed by
Gaute Lindkvist
parent
dfc93164d0
commit
8662ff90d2
@@ -1,18 +1,31 @@
|
||||
import rips
|
||||
import time
|
||||
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
project = resinsight.project
|
||||
summary_cases = project.descendants(rips.SummaryCase)
|
||||
|
||||
# Assumes at least one summery case loaded
|
||||
firstCase = summary_cases[0]
|
||||
# Use the following commented lines to import a file from disk
|
||||
# filename = "path/to/file/1_R001_REEK-0.SMSPEC"
|
||||
# summary_case = project.import_summary_case(filename)
|
||||
|
||||
# Assumes at least one summery case loaded with case_id 1
|
||||
summary_case = project.summary_case(1)
|
||||
if summary_case is None:
|
||||
print("No summary case found")
|
||||
exit()
|
||||
|
||||
vector_name = "FOPT"
|
||||
summary_data = firstCase.summary_vector_values(vector_name)
|
||||
summary_data = summary_case.summary_vector_values(vector_name)
|
||||
|
||||
print("Data for summary vector " + vector_name)
|
||||
print(summary_data.values)
|
||||
|
||||
time_steps = firstCase.available_time_steps()
|
||||
time_steps = summary_case.available_time_steps()
|
||||
print(time_steps.values)
|
||||
|
||||
summary_data_sampled = summary_case.resample_values("FOPT", "QUARTER")
|
||||
print("\nResampled data")
|
||||
|
||||
for t, value in zip(summary_data_sampled.time_steps, summary_data_sampled.values):
|
||||
print(time.strftime("%a, %d %b %Y ", time.gmtime(t)) + " | " + str(value))
|
||||
|
||||
@@ -5,6 +5,22 @@
|
||||
|
||||
"""
|
||||
Module containing the Case class
|
||||
|
||||
ResInsight Case class
|
||||
|
||||
Operate on a ResInsight case specified by a Case Id integer.
|
||||
Not meant to be constructed separately but created by one of the following
|
||||
methods in Project: loadCase, case, allCases, selectedCases
|
||||
|
||||
Attributes:
|
||||
id (int): Case Id corresponding to case Id in ResInsight project.
|
||||
name (str): Case name
|
||||
group_id (int): Case Group id
|
||||
chunkSize(int): The size of each chunk during value streaming.
|
||||
A good chunk size is 64KiB = 65536B.
|
||||
Meaning the ideal number of doubles would be 8192.
|
||||
However we need overhead space, so the default is 8160.
|
||||
This leaves 256B for overhead.
|
||||
"""
|
||||
|
||||
import builtins
|
||||
@@ -29,22 +45,6 @@ from rips.view import View
|
||||
from rips.generated.pdm_objects import WellBoreStabilityPlot, WbsParameters
|
||||
from rips.simulation_well import SimulationWell
|
||||
|
||||
"""ResInsight case class
|
||||
|
||||
Operate on a ResInsight case specified by a Case Id integer.
|
||||
Not meant to be constructed separately but created by one of the following
|
||||
methods in Project: loadCase, case, allCases, selectedCases
|
||||
|
||||
Attributes:
|
||||
id (int): Case Id corresponding to case Id in ResInsight project.
|
||||
name (str): Case name
|
||||
group_id (int): Case Group id
|
||||
chunkSize(int): The size of each chunk during value streaming.
|
||||
A good chunk size is 64KiB = 65536B.
|
||||
Meaning the ideal number of doubles would be 8192.
|
||||
However we need overhead space, so the default is 8160.
|
||||
This leaves 256B for overhead.
|
||||
"""
|
||||
@add_method(Case)
|
||||
def __custom_init__(self, pb2_object, channel):
|
||||
self.__case_stub = Case_pb2_grpc.CaseStub(self._channel)
|
||||
@@ -102,18 +102,21 @@ def __generate_property_input_chunks(self, array, parameters):
|
||||
|
||||
@add_method(Case)
|
||||
def grid(self, index):
|
||||
"""Get Grid of a given index. Returns a rips Grid object
|
||||
"""Get Grid of a given index
|
||||
|
||||
Arguments:
|
||||
index (int): The grid index
|
||||
|
||||
Returns: Grid object
|
||||
Returns: :class:`rips.grid.Grid`
|
||||
"""
|
||||
return Grid(index, self, self.channel())
|
||||
|
||||
@add_method(Case)
|
||||
def grids(self):
|
||||
"""Get a list of all rips Grid objects in the case"""
|
||||
"""Get a list of all rips Grid objects in the case
|
||||
|
||||
Returns: List of :class:`rips.grid.Grid`
|
||||
"""
|
||||
grid_list = []
|
||||
for i in range(0, self.__grid_count()):
|
||||
grid_list.append(Grid(i, self, self.channel()))
|
||||
@@ -870,8 +873,8 @@ def import_formation_names(self, formation_files=None):
|
||||
elif isinstance(formation_files, str):
|
||||
formation_files = [formation_files]
|
||||
|
||||
res = self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files,
|
||||
applyToCaseId=self.id))
|
||||
self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files,
|
||||
applyToCaseId=self.id))
|
||||
|
||||
@add_method(Case)
|
||||
def simulation_wells(self):
|
||||
|
||||
@@ -366,6 +366,9 @@ def _call_pdm_method(self, method_name, **kwargs):
|
||||
pb2_object = self._pdm_object_stub.CallPdmObjectMethod(request)
|
||||
|
||||
child_class_definition = class_from_keyword(pb2_object.class_keyword)
|
||||
if child_class_definition is None:
|
||||
return None
|
||||
|
||||
pdm_object = child_class_definition(pb2_object=pb2_object, channel=self.channel())
|
||||
return pdm_object
|
||||
|
||||
|
||||
@@ -341,5 +341,6 @@ def import_formation_names(self, formation_files=None):
|
||||
elif isinstance(formation_files, str):
|
||||
formation_files = [formation_files]
|
||||
|
||||
res = self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files,
|
||||
self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files,
|
||||
applyToCaseId=-1))
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import sys
|
||||
import os
|
||||
import math
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_summary_import_and_find(rips_instance, initialize_test):
|
||||
casePath = dataroot.PATH + "/flow_diagnostics_test/SIMPLE_SUMMARY2.SMSPEC"
|
||||
summary_case = rips_instance.project.import_summary_case(casePath)
|
||||
assert(summary_case.id == 1)
|
||||
|
||||
case_id = 234
|
||||
found_summary_case = rips_instance.project.summary_case(case_id)
|
||||
assert(found_summary_case is None)
|
||||
|
||||
correct_case_id = 1
|
||||
found_summary_case = rips_instance.project.summary_case(correct_case_id)
|
||||
assert(found_summary_case is not None)
|
||||
|
||||
rips_instance.project.close()
|
||||
correct_case_id = 1
|
||||
found_summary_case = rips_instance.project.summary_case(correct_case_id)
|
||||
assert(found_summary_case is None)
|
||||
|
||||
|
||||
def test_summary_data(rips_instance, initialize_test):
|
||||
casePath = dataroot.PATH + "/flow_diagnostics_test/SIMPLE_SUMMARY2.SMSPEC"
|
||||
summary_case = rips_instance.project.import_summary_case(casePath)
|
||||
assert(summary_case.id == 1)
|
||||
|
||||
addresses = summary_case.available_addresses()
|
||||
assert(len(addresses.values) == 343)
|
||||
|
||||
summary_data = summary_case.summary_vector_values("FOPT")
|
||||
assert(len(summary_data.values) == 60)
|
||||
|
||||
def test_summary_resample(rips_instance, initialize_test):
|
||||
casePath = dataroot.PATH + "/flow_diagnostics_test/SIMPLE_SUMMARY2.SMSPEC"
|
||||
summary_case = rips_instance.project.import_summary_case(casePath)
|
||||
assert(summary_case.id == 1)
|
||||
|
||||
summary_data_sampled = summary_case.resample_values("FOPT", "NONE")
|
||||
assert(len(summary_data_sampled.values) == 60)
|
||||
assert(len(summary_data_sampled.time_steps) == 60)
|
||||
|
||||
summary_data_sampled = summary_case.resample_values("FOPT", "DAY")
|
||||
assert(len(summary_data_sampled.values) == 721)
|
||||
assert(len(summary_data_sampled.time_steps) == 721)
|
||||
|
||||
summary_data_sampled = summary_case.resample_values("FOPT", "MONTH")
|
||||
assert(len(summary_data_sampled.values) == 24)
|
||||
assert(len(summary_data_sampled.time_steps) == 24)
|
||||
|
||||
summary_data_sampled = summary_case.resample_values("FOPT", "QUARTER")
|
||||
assert(len(summary_data_sampled.values) == 8)
|
||||
assert(len(summary_data_sampled.time_steps) == 8)
|
||||
|
||||
summary_data_sampled = summary_case.resample_values("FOPT", "YEAR")
|
||||
assert(len(summary_data_sampled.values) == 3)
|
||||
assert(len(summary_data_sampled.time_steps) == 3)
|
||||
@@ -538,6 +538,11 @@ grpc::Status RiaGrpcPdmObjectService::CallPdmObjectMethod( grpc::ServerContext*
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( method->isNullptrValidResult() )
|
||||
{
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
return grpc::Status( grpc::NOT_FOUND, "No result returned from Method" );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user