Skip to content

Commit

Permalink
CLN: add typing to _gridprop_op1
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Nov 1, 2023
1 parent dee2817 commit fccaa83
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/xtgeo/grid3d/_gridprop_op1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Various grid property operations"""
# pylint: disable=protected-access
from __future__ import annotations

from typing import TYPE_CHECKING, List, Literal, Optional, Tuple, Union

import numpy as np

Expand All @@ -9,14 +12,24 @@
from xtgeo.grid3d import _gridprop_lowlevel as gl

xtg = XTGeoDialog()

logger = xtg.functionlogger(__name__)

if TYPE_CHECKING:
from xtgeo.grid3d import Grid, GridProperty
from xtgeo.xyz import Polygons

# pylint: disable=protected-access

XYCoordinate = Tuple[Union[float, int], Union[float, int]]
XYCoordList = List[List[List[XYCoordinate]]]
ValueList = List[List[Union[float, int]]]
XYValueLists = Tuple[XYCoordList, ValueList]

def get_xy_value_lists(self, **kwargs):

def get_xy_value_lists(
self: GridProperty,
grid: Optional[Union[Grid, GridProperty]] = None,
mask: Optional[bool] = None,
) -> XYValueLists:
"""Get values for webportal format
Two cells:
Expand All @@ -28,11 +41,6 @@ def get_xy_value_lists(self, **kwargs):
will have a -999 value.
"""

grid = kwargs.get("grid", None)

mask = kwargs.get("mask", True)

if grid is None:
raise RuntimeError("Missing grid object")

Expand Down Expand Up @@ -76,11 +84,17 @@ def get_xy_value_lists(self, **kwargs):
return coordlist, valuelist


def operation_polygons(self, poly, value, opname="add", inside=True):
def operation_polygons(
self: GridProperty,
poly: Polygons,
value: Union[float, int],
opname: Literal["add", "sub", "mul", "div", "set"] = "add",
inside: bool = True,
) -> None:
"""A generic function for doing operations restricted to inside
or outside polygon(s).
"""
"""
grid = self.geometry
grid._xtgformat1()

Expand Down Expand Up @@ -116,7 +130,7 @@ def operation_polygons(self, poly, value, opname="add", inside=True):
1,
)
if ier == -9:
print(f"## Polygon no {id_ + 1} is not closed")
logger.warning(f"Polygon no {id_ + 1} is not closed")

gl.update_values_from_carray(proxy, cvals, np.float64, delete=True)

Expand All @@ -135,7 +149,7 @@ def operation_polygons(self, poly, value, opname="add", inside=True):
elif opname == "div":
# Dividing a map of zero is always a hazzle; try to obtain 0.0
# as result in these cases
if 0.0 in value:
if np.isclose(value, 0.0):
xtg.warn(
"Dividing a surface with value or surface with zero "
"elements; may get unexpected results, try to "
Expand Down

0 comments on commit fccaa83

Please sign in to comment.