Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JB Lovland committed Nov 8, 2023
1 parent 0ec9069 commit f777c35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/xtgeo/grid3d/_grid3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
logger = xtg.functionlogger(__name__)


class _Grid3D(object):
class _Grid3D:
"""Abstract base class for Grid3D."""

def __init__(self, ncol: int = 4, nrow: int = 3, nlay: int = 5):
Expand Down
50 changes: 27 additions & 23 deletions src/xtgeo/grid3d/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import warnings
from collections import OrderedDict
from pathlib import Path
import pathlib
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -24,7 +24,6 @@
import numpy.ma as ma

import xtgeo
from xtgeo import types as _xttypes
from xtgeo.common import XTGDescription, _XTGeoFile

from . import (
Expand All @@ -49,6 +48,7 @@

if TYPE_CHECKING:
import pandas as pd
from xtgeo.types import FileLike

from xtgeo.xyz.points import Points

Expand All @@ -71,7 +71,7 @@
# METHODS as wrappers to class init + import
def _handle_import(
grid_constructor: Callable,
gfile: Union[_xttypes.FileLike, _XTGeoFile],
gfile: Union[FileLike, _XTGeoFile],
fformat: Optional[str] = None,
**kwargs: dict,
) -> Callable:
Expand Down Expand Up @@ -99,7 +99,7 @@ def _handle_import(


def grid_from_file(
gfile: Union[str, Path],
gfile: Union[str, pathlib.Path],
fformat: Optional[str] = None,
**kwargs: dict[str, Any],
) -> Callable:
Expand Down Expand Up @@ -296,7 +296,7 @@ def wrapper(self, *args, **kwargs): # type: ignore
# from file and raise a deprecation warning if
# we are.
if "gfile" in kwargs or (
len(args) >= 1 and isinstance(args[0], (str, Path, _XTGeoFile))
len(args) >= 1 and isinstance(args[0], (str, pathlib.Path, _XTGeoFile))
):
warnings.warn(
"Initializing directly from file name is deprecated and will be "
Expand Down Expand Up @@ -384,7 +384,7 @@ def __init__(
dualperm: bool = False,
subgrids: Optional[OrderedDict] = None,
units: Optional[Units] = None,
filesrc: Optional[Union[Path, str]] = None,
filesrc: Optional[Union[pathlib.Path, str]] = None,
props: Optional[GridProperties] = None,
name: Optional[str] = None,
roxgrid: Optional[Any] = None,
Expand Down Expand Up @@ -450,7 +450,7 @@ def _reset(
dualperm: bool = False,
subgrids: Optional[OrderedDict[str, Union[range, list[int]]]] = None,
units: Optional[Units] = None,
filesrc: Optional[Union[Path, str]] = None,
filesrc: Optional[Union[pathlib.Path, str]] = None,
props: Optional[GridProperties] = None,
name: Optional[str] = None,
roxgrid: Optional[Any] = None,
Expand Down Expand Up @@ -531,7 +531,7 @@ def metadata(self, obj: xtgeo.MetaDataCPGeometry) -> None:
self._metadata = obj # checking is currently missing! TODO

@property
def filesrc(self) -> Optional[Union[str, Path]]:
def filesrc(self) -> Optional[Union[str, pathlib.Path]]:
"""str: Source for grid (filepath or name in RMS)."""
return self._filesrc

Expand Down Expand Up @@ -826,7 +826,7 @@ def create_box(

self._reset(**kwargs)

def to_file(self, gfile: _xttypes.FileLike, fformat: str = "roff") -> None:
def to_file(self, gfile: FileLike, fformat: str = "roff") -> None:
"""Export grid geometry to file, various vendor formats.
Args:
Expand Down Expand Up @@ -875,11 +875,11 @@ def to_file(self, gfile: _xttypes.FileLike, fformat: str = "roff") -> None:

def to_hdf(
self,
gfile: Union[str, Path],
gfile: Union[str, pathlib.Path],
compression: Optional[str] = None,
chunks: Optional[bool] = False,
subformat: Optional[int] = 844,
) -> _xttypes.FileLike:
) -> FileLike:
"""Export grid geometry to HDF5 storage format (experimental!).
Args:
Expand Down Expand Up @@ -911,9 +911,9 @@ def to_hdf(

def to_xtgf(
self,
gfile: Union[str, Path],
gfile: Union[str, pathlib.Path],
subformat: Optional[int] = 844,
) -> Path:
) -> pathlib.Path:
"""Export grid geometry to xtgeo native binary file format (experimental!).
Args:
Expand Down Expand Up @@ -975,7 +975,7 @@ def to_roxar(
)
def from_file(
self,
gfile: _xttypes.FileLike,
gfile: FileLike,
fformat: Optional[str] = None,
**kwargs: Any,
) -> Grid:
Expand Down Expand Up @@ -1038,7 +1038,7 @@ def constructor(*args, **kwargs): # type: ignore
)
def from_hdf(
self,
gfile: _xttypes.FileLike,
gfile: FileLike,
ijkrange: Optional[Sequence[int]] = None,
zerobased: bool = False,
) -> None:
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def from_hdf(
current_version=xtgeo.version,
details="Use xtgeo.grid_from_file() instead",
)
def from_xtgf(self, gfile: _xttypes.FileLike, mmap: bool = False) -> None:
def from_xtgf(self, gfile: FileLike, mmap: bool = False) -> None:
"""Import grid geometry from native xtgeo file format (experimental!).
Args:
Expand Down Expand Up @@ -1288,6 +1288,10 @@ def get_dataframe(
details="Method dataframe is deprecated, use get_dataframe instead.",
)
def dataframe(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
"""
Returns:
A Pandas dataframe
"""
return self.get_dataframe(*args, **kwargs)

def get_vtk_esg_geometry_data(
Expand Down Expand Up @@ -1592,11 +1596,11 @@ def get_dualactnum_indices(
actnumvf[(actnumv == 3) | (actnumv == 2)] = 1
actnumvf[(actnumv == 1) | (actnumv == 0)] = 0
return np.flatnonzero(actnumvf)
else:
actnumvm = actnumv.copy()
actnumvm[(actnumv == 3) | (actnumv == 1)] = 1
actnumvm[(actnumv == 2) | (actnumv == 0)] = 0
return np.flatnonzero(actnumvm)

actnumvm = actnumv.copy()
actnumvm[(actnumv == 3) | (actnumv == 1)] = 1
actnumvm[(actnumv == 2) | (actnumv == 0)] = 0
return np.flatnonzero(actnumvm)

@deprecation.deprecated(
deprecated_in="2.16",
Expand Down Expand Up @@ -1869,7 +1873,7 @@ def get_cell_volume(
ijk: tuple[int, int, int] = (1, 1, 1),
activeonly: bool = True,
zerobased: bool = False,
precision: int = 2,
precision: Literal[1, 2, 4] = 2,
) -> float:
"""Return the bulk volume for a given cell.
Expand Down Expand Up @@ -1914,7 +1918,7 @@ def get_bulk_volume(
self,
name: str = "bulkvol",
asmasked: bool = True,
precision: int = 2,
precision: Literal[1, 2, 4] = 2,
) -> GridProperty:
"""Return the geometric cell volume for all cells as a GridProperty object.
Expand Down
4 changes: 2 additions & 2 deletions src/xtgeo/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This file contains commen types used in xtgeo, keep it free some logic.
"""

from io import BytesIO, StringIO, TextIOWrapper
from io import BytesIO, StringIO
from pathlib import Path
from typing import Union

FileLike = Union[str, Path, StringIO, TextIOWrapper, BytesIO]
FileLike = Union[str, Path, StringIO, BytesIO]

0 comments on commit f777c35

Please sign in to comment.