mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-01 08:38:00 -06:00
#14772 Python: Add View.export_contour_map_to_text as object method and forward exportContourMapToText to it
Rim3dView_exportContourMapToText exports the contour map of an Eclipse or GeoMech contour map view. The implementation is extracted from the RICF_SOURCE_INIT feature RicExportContourMapToTextFeature into a static helper returning std::expected, used by both the object method and the legacy command. The Python EclipseContourMap/GeoMechContourMap.export_to_text() wrappers are kept as aliases of the generated method.
This commit is contained in:
1 parent
b1a822e7ac
commit
ebf7a061d8
6 files changed
+145
-64
No files matched your search
@@ -2,22 +2,21 @@
|
||||
ResInsight 3d contour map module
|
||||
"""
|
||||
|
||||
import Commands_pb2
|
||||
|
||||
from .pdmobject import add_method
|
||||
from .view import View as View
|
||||
from .resinsight_classes import EclipseContourMap, GeoMechContourMap
|
||||
|
||||
|
||||
@add_method(EclipseContourMap)
|
||||
def export_to_text(
|
||||
self: EclipseContourMap,
|
||||
self,
|
||||
export_file_name: str = "",
|
||||
export_local_coordinates: bool = False,
|
||||
undefined_value_label: str = "NaN",
|
||||
exclude_undefined_values: bool = False,
|
||||
):
|
||||
"""Export snapshot for the current view
|
||||
"""Export the contour map to a text file
|
||||
|
||||
Alias of View.export_contour_map_to_text().
|
||||
|
||||
Arguments:
|
||||
export_file_name(str): The file location to store results in.
|
||||
@@ -25,39 +24,13 @@ def export_to_text(
|
||||
undefined_value_label(str): Replace undefined values with this label.
|
||||
exclude_undefined_values(bool): Skip undefined values.
|
||||
"""
|
||||
return self._execute_command(
|
||||
exportContourMapToText=Commands_pb2.ExportContourMapToTextRequest(
|
||||
exportFileName=export_file_name,
|
||||
exportLocalCoordinates=export_local_coordinates,
|
||||
undefinedValueLabel=undefined_value_label,
|
||||
excludeUndefinedValues=exclude_undefined_values,
|
||||
viewId=self.id,
|
||||
)
|
||||
self.export_contour_map_to_text(
|
||||
export_file_name=export_file_name,
|
||||
export_local_coordinates=export_local_coordinates,
|
||||
undefined_value_label=undefined_value_label,
|
||||
exclude_undefined_values=exclude_undefined_values,
|
||||
)
|
||||
|
||||
|
||||
@add_method(GeoMechContourMap)
|
||||
def export_to_text( # noqa: F811
|
||||
self: GeoMechContourMap,
|
||||
export_file_name: str = "",
|
||||
export_local_coordinates: bool = False,
|
||||
undefined_value_label: str = "NaN",
|
||||
exclude_undefined_values: bool = False,
|
||||
):
|
||||
"""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.
|
||||
exclude_undefined_values(bool): Skip undefined values.
|
||||
"""
|
||||
return self._execute_command(
|
||||
exportContourMapToText=Commands_pb2.ExportContourMapToTextRequest(
|
||||
exportFileName=export_file_name,
|
||||
exportLocalCoordinates=export_local_coordinates,
|
||||
undefinedValueLabel=undefined_value_label,
|
||||
excludeUndefinedValues=exclude_undefined_values,
|
||||
viewId=self.id,
|
||||
)
|
||||
)
|
||||
add_method(EclipseContourMap)(export_to_text)
|
||||
add_method(GeoMechContourMap)(export_to_text)
|
||||
@@ -1,8 +1,11 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
|
||||
import rips
|
||||
import dataroot
|
||||
|
||||
|
||||
@@ -62,3 +65,19 @@ def test_visible_cells_different_timesteps(rips_instance, initialize_test):
|
||||
|
||||
# Both should have the same number of cells
|
||||
assert len(visibility_ts0) == len(visibility_ts1)
|
||||
|
||||
|
||||
def test_export_contour_map_to_text_requires_contour_map(
|
||||
rips_instance, initialize_test
|
||||
):
|
||||
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.load_case(case_path)
|
||||
view = case.create_view()
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
# A regular 3D view is not a contour map
|
||||
with pytest.raises(rips.RipsError):
|
||||
view.export_contour_map_to_text(
|
||||
export_file_name=os.path.join(tmpdirname, "map.txt")
|
||||
)
|
||||
with pytest.raises(rips.RipsError):
|
||||
view.export_contour_map_to_text()
|
||||
Reference in new issue
Block a user