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:
@@ -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" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSummaryPlotCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSummaryCase.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSummaryResampleData.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcProject.h
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerDouble.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerString.h
|
||||
@@ -13,6 +14,7 @@ set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSummaryPlotCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSummaryCase.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSummaryResampleData.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcProject.cpp
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerDouble.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerString.cpp
|
||||
|
||||
141
ApplicationCode/ProjectDataModelCommands/RimcProject.cpp
Normal file
141
ApplicationCode/ProjectDataModelCommands/RimcProject.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RimcProject.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RicImportSummaryCasesFeature.h"
|
||||
|
||||
#include "RimFileSummaryCase.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
|
||||
#include "cafPdmFieldIOScriptability.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_importSummaryCase, "importSummaryCase" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimProject_importSummaryCase::RimProject_importSummaryCase( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Import Summary Case", "", "", "Import Summary Case" );
|
||||
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_fileName, "FileName", "", "", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* RimProject_importSummaryCase::execute()
|
||||
{
|
||||
QStringList summaryFileNames{m_fileName};
|
||||
std::vector<RimSummaryCase*> newCases;
|
||||
|
||||
if ( RicImportSummaryCasesFeature::createSummaryCasesFromFiles( summaryFileNames, &newCases ) )
|
||||
{
|
||||
RicImportSummaryCasesFeature::addSummaryCases( newCases );
|
||||
|
||||
if ( RiaGuiApplication::isRunning() )
|
||||
{
|
||||
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
|
||||
if ( mainPlotWindow && !newCases.empty() )
|
||||
{
|
||||
mainPlotWindow->updateSummaryPlotToolBar();
|
||||
}
|
||||
}
|
||||
|
||||
if ( newCases.size() == 1 )
|
||||
{
|
||||
return newCases[0];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimProject_importSummaryCase::resultIsPersistent() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimProject_importSummaryCase::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( new RimFileSummaryCase );
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_summaryCase, "summaryCase" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimProject_summaryCase::RimProject_summaryCase( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Find Summary Case", "", "", "Find Summary Case" );
|
||||
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_caseId, "CaseId", "", "", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* RimProject_summaryCase::execute()
|
||||
{
|
||||
auto proj = RiaApplication::instance()->project();
|
||||
auto sumCases = proj->allSummaryCases();
|
||||
|
||||
for ( auto s : sumCases )
|
||||
{
|
||||
if ( s->caseId() == m_caseId ) return s;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimProject_summaryCase::resultIsPersistent() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimProject_summaryCase::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( new RimFileSummaryCase );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimProject_summaryCase::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
64
ApplicationCode/ProjectDataModelCommands/RimcProject.h
Normal file
64
ApplicationCode/ProjectDataModelCommands/RimcProject.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmObjectMethod.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimProject_importSummaryCase : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimProject_importSummaryCase( caf::PdmObjectHandle* self );
|
||||
|
||||
caf::PdmObjectHandle* execute();
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_fileName;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimProject_summaryCase : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimProject_summaryCase( caf::PdmObjectHandle* self );
|
||||
|
||||
caf::PdmObjectHandle* execute();
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<int> m_caseId;
|
||||
};
|
||||
@@ -225,22 +225,31 @@ caf::PdmObjectHandle* RimSummaryCase_resampleValues::execute()
|
||||
QString periodString = m_resamplingPeriod().trimmed();
|
||||
RiaQDateTimeTools::DateTimePeriod period = RiaQDateTimeTools::DateTimePeriodEnum::fromText( periodString );
|
||||
|
||||
RiaTimeHistoryCurveResampler resampler;
|
||||
resampler.setCurveData( values, timeValues );
|
||||
auto dataObject = new RimcSummaryResampleData();
|
||||
|
||||
if ( RiaSummaryTools::hasAccumulatedData( adr ) )
|
||||
if ( period != RiaQDateTimeTools::DateTimePeriod::NONE )
|
||||
{
|
||||
resampler.resampleAndComputePeriodEndValues( period );
|
||||
RiaTimeHistoryCurveResampler resampler;
|
||||
resampler.setCurveData( values, timeValues );
|
||||
|
||||
if ( RiaSummaryTools::hasAccumulatedData( adr ) )
|
||||
{
|
||||
resampler.resampleAndComputePeriodEndValues( period );
|
||||
}
|
||||
else
|
||||
{
|
||||
resampler.resampleAndComputeWeightedMeanValues( period );
|
||||
}
|
||||
|
||||
dataObject->m_timeValues = resampler.resampledTimeSteps();
|
||||
dataObject->m_doubleValues = resampler.resampledValues();
|
||||
}
|
||||
else
|
||||
{
|
||||
resampler.resampleAndComputeWeightedMeanValues( period );
|
||||
dataObject->m_timeValues = timeValues;
|
||||
dataObject->m_doubleValues = values;
|
||||
}
|
||||
|
||||
auto dataObject = new RimcSummaryResampleData();
|
||||
dataObject->m_timeValues = resampler.resampledTimeSteps();
|
||||
dataObject->m_doubleValues = resampler.resampledValues();
|
||||
|
||||
return dataObject;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user