mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-18 09:05:11 -05:00
Python ruff fixes
* Python: Clean up imports. * Python: Clean up error handling example. * Python: Remove unused local variables * Python: Avoid comparing against True/False. * Python: Remove unused name variable. * Python: Reuse class definition type variable. * Python: Fix more unused imports * Black fixes
This commit is contained in:
@@ -3,9 +3,8 @@
|
||||
# and actnum configuration.
|
||||
######################################################################
|
||||
import rips
|
||||
import xtgeo
|
||||
from xtgeo.grid3d._egrid import EGrid, RockModel
|
||||
from xtgeo.io._file import FileFormat, FileWrapper
|
||||
from xtgeo.grid3d._egrid import EGrid
|
||||
from xtgeo.io._file import FileFormat
|
||||
import numpy as np
|
||||
|
||||
grid_filepath = "/home/resinsight/testdata/01_drogon_ahm/realization-0/iter-0/eclipse/model/DROGON-0.EGRID"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import math, time
|
||||
import rips
|
||||
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import os
|
||||
import grpc
|
||||
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import rips
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
###################################################################
|
||||
|
||||
import rips
|
||||
import grpc
|
||||
import tempfile
|
||||
|
||||
|
||||
@@ -49,8 +48,8 @@ if case is not None:
|
||||
try:
|
||||
case.set_active_cell_property(results, "GENERATED", "POROAPPENDED", 0)
|
||||
print("Everything went well as expected")
|
||||
except: # Match any exception, but it should not happen
|
||||
print("Ooops!")
|
||||
except Exception as e: # Match any exception, but it should not happen
|
||||
print("Ooops!", e)
|
||||
|
||||
# Add another value, so this is outside the bounds of the active cell result storage
|
||||
results.append(1.0)
|
||||
@@ -59,7 +58,7 @@ if case is not None:
|
||||
try:
|
||||
case.set_active_cell_property(results, "GENERATED", "POROAPPENDED", 0)
|
||||
print("Everything went well??")
|
||||
except RipsError as e:
|
||||
except rips.RipsError as e:
|
||||
print("Server Exception Received: ", e)
|
||||
except IndexError:
|
||||
print("Got index out of bounds error. This shouldn't happen here")
|
||||
@@ -72,7 +71,7 @@ if case is not None:
|
||||
try:
|
||||
case.set_active_cell_property(results, "GENERATED", "POROAPPENDED", 0)
|
||||
print("Everything went well??")
|
||||
except grpc.RpcError as e:
|
||||
except rips.RipsError as e:
|
||||
print("Got unexpected server exception", e, "This should not happen now")
|
||||
except IndexError:
|
||||
print("Got expected index out of bounds error on client side")
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
import os
|
||||
import rips
|
||||
|
||||
# Load instance
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import rips
|
||||
import time
|
||||
|
||||
# Connect to ResInsight instance
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
import rips
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import rips
|
||||
import tempfile
|
||||
from os.path import expanduser
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import rips
|
||||
import tempfile
|
||||
from os.path import expanduser
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
###########################################################################################
|
||||
|
||||
import rips
|
||||
import itertools
|
||||
import time
|
||||
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# This example will synchronously calculate the average value for SOIL for all time steps
|
||||
###########################################################################################
|
||||
import rips
|
||||
import itertools
|
||||
import time
|
||||
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
@@ -11,7 +11,6 @@ import time
|
||||
def create_result(soil_chunks, porv_chunks):
|
||||
for soil_chunk, porv_chunk in zip(soil_chunks, porv_chunks):
|
||||
resultChunk = []
|
||||
number = 0
|
||||
for soil_value, porv_value in zip(soil_chunk.values, porv_chunk.values):
|
||||
resultChunk.append(soil_value * porv_value)
|
||||
# Return a Python generator
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
name = "rips"
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -7,16 +5,19 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "generated"))
|
||||
|
||||
from .resinsight_classes import *
|
||||
|
||||
from .case import Case, EclipseCase, GeoMechCase
|
||||
from .grid import Grid
|
||||
from .instance import Instance
|
||||
from .view import View
|
||||
from .project import Project
|
||||
from .plot import Plot, PlotWindow
|
||||
from .contour_map import EclipseContourMap, GeoMechContourMap
|
||||
from .well_log_plot import WellLogPlot
|
||||
from .simulation_well import SimulationWell
|
||||
from .exception import RipsError
|
||||
from .case import Case as Case, EclipseCase as EclipseCase, GeoMechCase as GeoMechCase
|
||||
from .grid import Grid as Grid
|
||||
from .instance import Instance as Instance
|
||||
from .view import View as View
|
||||
from .project import Project as Project
|
||||
from .plot import Plot as Plot, PlotWindow as PlotWindow
|
||||
from .contour_map import (
|
||||
EclipseContourMap as EclipseContourMap,
|
||||
GeoMechContourMap as GeoMechContourMap,
|
||||
)
|
||||
from .well_log_plot import WellLogPlot as WellLogPlot
|
||||
from .simulation_well import SimulationWell as SimulationWell
|
||||
from .exception import RipsError as RipsError
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ result
|
||||
|
||||
"""
|
||||
|
||||
import builtins
|
||||
import grpc
|
||||
from typing import List, Tuple
|
||||
|
||||
@@ -49,16 +48,16 @@ import Properties_pb2_grpc
|
||||
import NNCProperties_pb2
|
||||
import NNCProperties_pb2_grpc
|
||||
from .resinsight_classes import (
|
||||
Case,
|
||||
EclipseCase,
|
||||
GeoMechCase,
|
||||
WellBoreStabilityPlot,
|
||||
WbsParameters,
|
||||
Case as Case,
|
||||
EclipseCase as EclipseCase,
|
||||
GeoMechCase as GeoMechCase,
|
||||
WellBoreStabilityPlot as WellBoreStabilityPlot,
|
||||
WbsParameters as WbsParameters,
|
||||
)
|
||||
|
||||
from .grid import Grid
|
||||
from .grid import Grid as Grid
|
||||
from .pdmobject import add_method
|
||||
from .view import View
|
||||
from .view import View as View
|
||||
from .simulation_well import SimulationWell
|
||||
import rips.project # full name import due to circular dependency
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ ResInsight 3d contour map module
|
||||
import Commands_pb2
|
||||
|
||||
from .pdmobject import add_method
|
||||
from .view import View
|
||||
from .view import View as View
|
||||
from .resinsight_classes import EclipseContourMap, GeoMechContourMap
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import Grid_pb2
|
||||
import Grid_pb2_grpc
|
||||
import Definitions_pb2
|
||||
|
||||
from typing import Tuple, Optional, List
|
||||
from typing import Optional, List
|
||||
from grpc import Channel
|
||||
|
||||
from .case import Case
|
||||
|
||||
@@ -3,8 +3,8 @@ Grid Case Group statistics module
|
||||
"""
|
||||
|
||||
from .pdmobject import add_method
|
||||
from .view import View
|
||||
from .case import Case
|
||||
from .view import View as View
|
||||
from .case import Case as Case
|
||||
|
||||
import Commands_pb2
|
||||
from .resinsight_classes import GridCaseGroup
|
||||
|
||||
@@ -31,7 +31,6 @@ from .grpc_retry_interceptor import RetryOnRpcErrorClientInterceptor
|
||||
from .generated.generated_classes import CommandRouter
|
||||
|
||||
from typing import List, Optional, Tuple
|
||||
from typing_extensions import Self
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
@@ -3,13 +3,10 @@
|
||||
ResInsight caf::PdmObject connection module
|
||||
"""
|
||||
|
||||
from functools import partial, wraps
|
||||
from functools import wraps
|
||||
import grpc
|
||||
import re
|
||||
import builtins
|
||||
import importlib
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
import PdmObject_pb2
|
||||
import PdmObject_pb2_grpc
|
||||
@@ -18,8 +15,8 @@ import Commands_pb2_grpc
|
||||
|
||||
from .exception import RipsError
|
||||
|
||||
from typing import Any, Callable, TypeVar, Tuple, cast, Union, List, Optional, Type
|
||||
from typing_extensions import ParamSpec, Self
|
||||
from typing import Any, Callable, TypeVar, Union, List, Optional, Type
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
|
||||
def camel_to_snake(name: str) -> str:
|
||||
@@ -180,7 +177,6 @@ class PdmObjectBase:
|
||||
print("Object Attributes: ")
|
||||
for snake_kw in dir(self):
|
||||
if not snake_kw.startswith("_") and not callable(getattr(self, snake_kw)):
|
||||
camel_kw = snake_to_camel(snake_kw)
|
||||
print(
|
||||
" "
|
||||
+ snake_kw
|
||||
@@ -502,11 +498,9 @@ class PdmObjectBase:
|
||||
except grpc.RpcError as exc:
|
||||
raise RipsError("%s" % exc.details()) from None
|
||||
|
||||
O = TypeVar("O")
|
||||
|
||||
def _call_pdm_method_return_optional_value(
|
||||
self, method_name: str, class_definition: Type[O], **kwargs: Any
|
||||
) -> Optional[O]:
|
||||
self, method_name: str, class_definition: Type[X], **kwargs: Any
|
||||
) -> Optional[X]:
|
||||
pb2_params = PdmObject_pb2.PdmObject(class_keyword=method_name)
|
||||
for key, value in kwargs.items():
|
||||
pb2_params.parameters[snake_to_camel(key)] = self.__convert_to_grpc_value(
|
||||
|
||||
@@ -5,7 +5,7 @@ ResInsight 2d plot module
|
||||
import Commands_pb2
|
||||
|
||||
from .pdmobject import add_method
|
||||
from .resinsight_classes import PlotWindow, Plot
|
||||
from .resinsight_classes import PlotWindow as PlotWindow, Plot as Plot
|
||||
|
||||
|
||||
@add_method(PlotWindow)
|
||||
|
||||
@@ -4,24 +4,21 @@
|
||||
The ResInsight project module
|
||||
"""
|
||||
|
||||
import builtins
|
||||
import grpc
|
||||
import uuid
|
||||
|
||||
from .case import Case
|
||||
from .gridcasegroup import GridCaseGroup
|
||||
from .pdmobject import PdmObjectBase, add_method, add_static_method
|
||||
from .plot import Plot
|
||||
from .pdmobject import add_method, add_static_method
|
||||
from .plot import Plot as Plot
|
||||
from .view import View
|
||||
|
||||
import Commands_pb2
|
||||
from Definitions_pb2 import Empty
|
||||
import Project_pb2_grpc
|
||||
import Project_pb2
|
||||
import KeyValueStore_pb2_grpc
|
||||
import KeyValueStore_pb2
|
||||
|
||||
import PdmObject_pb2
|
||||
from .resinsight_classes import Project, PlotWindow, WellPath, SummaryCase, Reservoir
|
||||
|
||||
from typing import Optional, List
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
name = "rips"
|
||||
from .generated.generated_classes import *
|
||||
|
||||
@@ -7,15 +7,13 @@ import grpc
|
||||
import SimulationWell_pb2
|
||||
import SimulationWell_pb2_grpc
|
||||
|
||||
import Properties_pb2
|
||||
import Properties_pb2_grpc
|
||||
import PdmObject_pb2
|
||||
|
||||
from .resinsight_classes import SimulationWell
|
||||
|
||||
from .case import Case
|
||||
from .view import View
|
||||
from .pdmobject import PdmObjectBase, add_method
|
||||
from .pdmobject import add_method
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
@@ -2,7 +2,6 @@ import sys
|
||||
import os
|
||||
import math
|
||||
import pytest
|
||||
import grpc
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
@@ -215,4 +214,5 @@ def test_multiple_load_of_same_case(rips_instance, initialize_test):
|
||||
path_name = dataroot.PATH + "/flow_diagnostics_test/SIMPLE_SUMMARY2.EGRID"
|
||||
case_count = 3
|
||||
for i in range(case_count):
|
||||
case = rips_instance.project.load_case(path_name)
|
||||
c = rips_instance.project.load_case(path_name)
|
||||
assert c
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import pytest
|
||||
import grpc
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
from rips.generated.generated_classes import (
|
||||
ModeledWellPath,
|
||||
StimPlanModel,
|
||||
WellPathGeometry,
|
||||
WellPathTarget,
|
||||
)
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -49,8 +43,8 @@ def test_add_well_path_targets(rips_instance, initialize_test):
|
||||
target = geometry.append_well_target(
|
||||
coord, use_fixed_azimuth=True, fixed_azimuth_value=110.1
|
||||
)
|
||||
assert target.use_fixed_inclination == False
|
||||
assert target.use_fixed_azimuth == True
|
||||
assert not target.use_fixed_inclination
|
||||
assert target.use_fixed_azimuth
|
||||
assert target.azimuth == 110.1
|
||||
assert target.inclination == 0.0
|
||||
|
||||
@@ -60,7 +54,7 @@ def test_add_well_path_targets(rips_instance, initialize_test):
|
||||
coord, use_fixed_inclination=True, fixed_inclination_value=25.6
|
||||
)
|
||||
|
||||
assert target.use_fixed_inclination == True
|
||||
assert target.use_fixed_azimuth == False
|
||||
assert target.use_fixed_inclination
|
||||
assert not target.use_fixed_azimuth
|
||||
assert target.azimuth == 0.0
|
||||
assert target.inclination == 25.6
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sys
|
||||
import os
|
||||
from typing import Any, Dict, List, TypedDict
|
||||
from typing import TypedDict
|
||||
import math
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import sys
|
||||
import os
|
||||
import math
|
||||
import pytest
|
||||
import grpc
|
||||
import tempfile
|
||||
import time
|
||||
import multiprocessing
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
|
||||
def launch_resinsight(sec=1):
|
||||
resinsight_executable_from_env = os.environ.get("RESINSIGHT_EXECUTABLE")
|
||||
@@ -23,7 +17,7 @@ def launch_resinsight(sec=1):
|
||||
|
||||
print(f"Sleeping for {sec} second(s): ", instance.location)
|
||||
time.sleep(sec)
|
||||
print(f"Done sleeping", instance.location)
|
||||
print("Done sleeping", instance.location)
|
||||
|
||||
instance.exit()
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
import grpc
|
||||
import pytest
|
||||
|
||||
import rips.generated.NNCProperties_pb2 as NNCProperties_pb2
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import math
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import grpc
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
import grpc
|
||||
import pytest
|
||||
import tempfile
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
@@ -13,6 +12,8 @@ def test_10k(rips_instance, initialize_test):
|
||||
case.create_view()
|
||||
assert len(case.grids()) == 2
|
||||
cell_count_info = case.cell_count()
|
||||
assert cell_count_info.active_cell_count == 11125
|
||||
assert cell_count_info.reservoir_cell_count == 316224
|
||||
|
||||
sim_wells = case.simulation_wells()
|
||||
assert len(sim_wells) == 3
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import sys
|
||||
import os
|
||||
import math
|
||||
import contextlib
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import sys
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
@@ -21,6 +21,7 @@ def test_10k_well_log_extraction(rips_instance, initialize_test):
|
||||
view.set_time_step(1)
|
||||
|
||||
well_path_names = rips_instance.project.import_well_paths(well_path_files)
|
||||
assert len(well_path_names) == 1
|
||||
wells = rips_instance.project.well_paths()
|
||||
well_path = wells[0]
|
||||
|
||||
@@ -41,6 +42,7 @@ def test_10k_well_log_extraction(rips_instance, initialize_test):
|
||||
for prop_type, prop_name, time_step in properties:
|
||||
track = well_log_plot.new_well_log_track("Track: " + prop_name, case, well_path)
|
||||
c = track.add_extraction_curve(case, well_path, prop_type, prop_name, time_step)
|
||||
assert c
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
well_log_plot.export_data_as_las(export_folder=tmpdirname)
|
||||
|
||||
@@ -19,6 +19,7 @@ def test_10k(rips_instance, initialize_test):
|
||||
case_root_path + "/wellpath_b.dev",
|
||||
]
|
||||
well_path_names = rips_instance.project.import_well_paths(well_path_files)
|
||||
assert len(well_path_names) == 2
|
||||
wells = rips_instance.project.well_paths()
|
||||
assert len(wells) == 2
|
||||
assert wells[0].name == "Well Path A"
|
||||
@@ -38,6 +39,7 @@ def test_10k_intersection(rips_instance, initialize_test):
|
||||
view.set_time_step(1)
|
||||
|
||||
well_path_names = rips_instance.project.import_well_paths(well_path_files)
|
||||
assert len(well_path_names) == 1
|
||||
wells = rips_instance.project.well_paths()
|
||||
well_path = wells[0]
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ def test_add_well_path_completions(rips_instance, initialize_test):
|
||||
completions_settings.update() # Commit updates back to ResInsight
|
||||
|
||||
completions_settings_updated = well_path.completion_settings()
|
||||
assert completions_settings_updated.allow_well_cross_flow == True
|
||||
assert completions_settings_updated.allow_well_cross_flow
|
||||
assert completions_settings_updated.auto_well_shut_in == "STOP"
|
||||
assert completions_settings_updated.drainage_radius_for_pi == "1.56"
|
||||
assert completions_settings_updated.fluid_in_place_region == 99
|
||||
@@ -76,8 +76,8 @@ def test_add_well_path_completions(rips_instance, initialize_test):
|
||||
msw_settings.update()
|
||||
|
||||
msw_settings_updated = well_path.msw_settings()
|
||||
assert msw_settings_updated.custom_values_for_lateral == True
|
||||
assert msw_settings_updated.enforce_max_segment_length == True
|
||||
assert msw_settings_updated.custom_values_for_lateral
|
||||
assert msw_settings_updated.enforce_max_segment_length
|
||||
assert msw_settings_updated.liner_diameter == 20.0
|
||||
assert msw_settings_updated.max_segment_length == 123.05
|
||||
assert msw_settings_updated.pressure_drop == "HFA"
|
||||
@@ -137,7 +137,7 @@ def test_add_well_path_fracture_template(rips_instance, initialize_test):
|
||||
assert fracture_template_updated.relative_gas_density == 0.1
|
||||
assert fracture_template_updated.relative_permeability == 0.2
|
||||
assert fracture_template_updated.user_defined_d_factor == 14
|
||||
assert fracture_template_updated.user_defined_perforation_length == True
|
||||
assert fracture_template_updated.user_defined_perforation_length
|
||||
assert fracture_template_updated.user_description == "my frac name"
|
||||
assert fracture_template_updated.width_scale_factor == 7
|
||||
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
ResInsight 3d view module
|
||||
"""
|
||||
|
||||
import builtins
|
||||
import Commands_pb2 as Cmd
|
||||
|
||||
import rips.case # Circular import of Case, which already imports View. Use full name.
|
||||
from .pdmobject import add_method
|
||||
from .resinsight_classes import View, ViewWindow, EclipseView, GeoMechView
|
||||
from .resinsight_classes import (
|
||||
View as View,
|
||||
ViewWindow as ViewWindow,
|
||||
EclipseView as EclipseView,
|
||||
GeoMechView as GeoMechView,
|
||||
)
|
||||
|
||||
|
||||
@add_method(View)
|
||||
|
||||
@@ -4,8 +4,7 @@ ResInsight Well Log Plot plot module
|
||||
|
||||
import Commands_pb2
|
||||
|
||||
from .plot import Plot
|
||||
from .pdmobject import PdmObjectBase, add_method
|
||||
from .pdmobject import add_method
|
||||
from .resinsight_classes import WellLogPlot
|
||||
|
||||
from typing import List
|
||||
|
||||
Reference in New Issue
Block a user