From 8192b65869712cfd982149dc5a299f71925852e4 Mon Sep 17 00:00:00 2001 From: mferrera Date: Fri, 27 Oct 2023 09:58:35 +0200 Subject: [PATCH] CLN: add typing to `_gridprop_op1` --- src/xtgeo/grid3d/_gridprop_op1.py | 33 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/xtgeo/grid3d/_gridprop_op1.py b/src/xtgeo/grid3d/_gridprop_op1.py index c768532f2..07095d196 100644 --- a/src/xtgeo/grid3d/_gridprop_op1.py +++ b/src/xtgeo/grid3d/_gridprop_op1.py @@ -1,5 +1,8 @@ """Various grid property operations""" +# pylint: disable=protected-access +from __future__ import annotations +from typing import TYPE_CHECKING, List, Optional, Tuple, Union import numpy as np @@ -12,11 +15,20 @@ 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, grid: Optional[Union[Grid, GridProperty]] = None, mask: Optional[bool] = None +) -> XYValueLists: """Get values for webportal format Two cells: @@ -28,11 +40,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") @@ -76,11 +83,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, + poly: Polygons, + value: Union[float, int], + opname: str = "add", + inside: bool = True, +) -> None: """A generic function for doing operations restricted to inside or outside polygon(s). - """ + """ grid = self.geometry grid._xtgformat1() @@ -135,7 +148,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 value == 0.0: xtg.warn( "Dividing a surface with value or surface with zero " "elements; may get unexpected results, try to "