mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Ensemble surface import and statistics
This commit is contained in:
committed by
GitHub
parent
d1e81f3c1e
commit
966bcd1e77
@@ -0,0 +1,62 @@
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import rips
|
||||
import tempfile
|
||||
from os.path import expanduser
|
||||
from pathlib import Path
|
||||
|
||||
# Connect to ResInsight instance
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
|
||||
home_dir = expanduser("~")
|
||||
|
||||
export_folder = tempfile.mkdtemp()
|
||||
|
||||
directory_path = "resprojects/webviz-subsurface-testdata/reek_history_match/"
|
||||
|
||||
|
||||
case_file_paths = []
|
||||
num_realizations = 9
|
||||
num_iterations = 4
|
||||
|
||||
|
||||
for realization in range(0, num_realizations):
|
||||
for iteration in range(0, num_iterations):
|
||||
realization_dir = "realization-" + str(realization)
|
||||
iteration_dir = "iter-" + str(iteration)
|
||||
egrid_name = "eclipse/model/5_R001_REEK-" + str(realization) + ".EGRID"
|
||||
path = Path(
|
||||
home_dir, directory_path, realization_dir, iteration_dir, egrid_name
|
||||
)
|
||||
case_file_paths.append(path)
|
||||
|
||||
k_indexes = [4, 10]
|
||||
|
||||
for path in case_file_paths:
|
||||
# Load a case
|
||||
path_name = path.as_posix()
|
||||
case = resinsight.project.load_case(path_name)
|
||||
|
||||
if resinsight.project.has_warnings():
|
||||
for warning in resinsight.project.warnings():
|
||||
print(warning)
|
||||
|
||||
surface_collection = resinsight.project.descendants(rips.SurfaceCollection)[0]
|
||||
|
||||
for k_index in k_indexes:
|
||||
print("Generating surface K layer " + str(k_index) + " for case " + path_name)
|
||||
|
||||
surface = surface_collection.new_surface(case, k_index)
|
||||
print("Surface: ", surface)
|
||||
|
||||
parent_path = path.parent
|
||||
export_folder_path = Path(parent_path, "surfaceexport")
|
||||
export_folder_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
export_file = Path(export_folder_path, "surf_" + str(k_index) + ".ts")
|
||||
print("Exporting to " + export_file.as_posix())
|
||||
surface.export_to_file(export_file.as_posix())
|
||||
|
||||
# Close project to avoid aggregated memory usage
|
||||
# Can be replaced when case.close() is implemented
|
||||
resinsight.project.close()
|
||||
34
GrpcInterface/Python/rips/tests/test_surfaces.py
Normal file
34
GrpcInterface/Python/rips/tests/test_surfaces.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.platform.startswith("linux"),
|
||||
reason="Brugge is currently exceptionally slow on Linux",
|
||||
)
|
||||
def test_create_and_export_surface(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
|
||||
case = rips_instance.project.load_case(path=case_path)
|
||||
assert len(case.grids()) == 1
|
||||
|
||||
surface_collection = rips_instance.project.descendants(rips.SurfaceCollection)[0]
|
||||
|
||||
surface = surface_collection.new_surface(case, 5)
|
||||
assert surface
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
path = Path(tmpdirname, "mysurface.ts")
|
||||
print("Temporary folder: ", path.as_posix())
|
||||
|
||||
fname = surface.export_to_file(path.as_posix())
|
||||
assert len(fname.values) == 1
|
||||
|
||||
assert path.exists()
|
||||
Reference in New Issue
Block a user