diff --git a/src/xtgeo/xyz/_xyz.py b/src/xtgeo/xyz/_xyz.py index 03cbec588..f342f88f5 100644 --- a/src/xtgeo/xyz/_xyz.py +++ b/src/xtgeo/xyz/_xyz.py @@ -51,17 +51,6 @@ def __init__( self._yname = yname self._zname = zname - def _reset( - self, - xname: str = "X_UTME", - yname: str = "Y_UTMN", - zname: str = "Z_TVDSS", - ): - """Used in deprecated methods.""" - self._xname = xname - self._yname = yname - self._zname = zname - @property def xname(self): """Returns or set the name of the X column.""" @@ -143,67 +132,6 @@ def describe(self, flush=True): return dsc.astext() - @abstractmethod - def from_file(self, pfile, fformat="xyz"): - """Import Points or Polygons from a file (deprecated). - - Supported import formats (fformat): - - * 'xyz' or 'poi' or 'pol': Simple XYZ format - - * 'zmap': ZMAP line format as exported from RMS (e.g. fault lines) - - * 'rms_attr': RMS points formats with attributes (extra columns) - - * 'guess': Try to choose file format based on extension - - Args: - pfile (str): Name of file or pathlib.Path instance - fformat (str): File format, see list above - - Returns: - Object instance (needed optionally) - - Raises: - OSError: if file is not present or wrong permissions. - - .. deprecated:: 2.16 - Use e.g. xtgeo.points_from_file() - """ - ... - - @abstractmethod - def from_list(self, plist): - """Create Points or Polygons from a list-like input (deprecated). - - This method is deprecated in favor of using e.g. xtgeo.Points(plist) - or xtgeo.Polygons(plist) instead. - - The following inputs are possible: - - * List of tuples [(x1, y1, z1, ), (x2, y2, z2, ), ...]. - * List of lists [[x1, y1, z1, ], [x2, y2, z2, ], ...]. - * List of numpy arrays [nparr1, nparr2, ...] where nparr1 is first row. - * A numpy array with shape [??1, ??2] ... - * An existing pandas dataframe - - It is currently not much error checking that lists/tuples are consistent, e.g. - if there always is either 3 or 4 elements per tuple, or that 4 number is - an integer. - - Args: - plist (str): List of tuples, each tuple is length 3 or 4. - - Raises: - ValueError: If something is wrong with input - - .. versionadded:: 2.6 - .. versionchanged:: 2.16 - .. deprecated:: 2.16 - Use e.g. xtgeo.Points(list_like). - """ - ... - @abstractmethod def get_dataframe(self, copy=True) -> pd.DataFrame: """Return the Pandas dataframe object.""" diff --git a/src/xtgeo/xyz/points.py b/src/xtgeo/xyz/points.py index afe7e7a56..3b14a5c4c 100644 --- a/src/xtgeo/xyz/points.py +++ b/src/xtgeo/xyz/points.py @@ -2,26 +2,24 @@ from __future__ import annotations -import functools -import pathlib import warnings from copy import deepcopy -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING -import deprecation import numpy as np import pandas as pd -import xtgeo from xtgeo.common.exceptions import InvalidFileFormatError from xtgeo.common.log import null_logger from xtgeo.common.sys import inherit_docstring -from xtgeo.common.version import __version__ from xtgeo.io._file import FileFormat, FileWrapper from xtgeo.xyz import XYZ, _xyz_io, _xyz_oper, _xyz_roxapi if TYPE_CHECKING: import io + import pathlib + + from xtgeo.well import Well logger = null_logger(__name__) @@ -47,7 +45,7 @@ def _file_importer( points_file: str | pathlib.Path | io.BytesIO, fformat: str | None = None, ): - """General function for points_from_file and (deprecated) method from_file.""" + """General function for points_from_file""" pfile = FileWrapper(points_file) fmt = pfile.fileformat(fformat) kwargs = _data_reader_factory(fmt)(pfile) @@ -57,7 +55,7 @@ def _file_importer( def _surface_importer(surf, zname="Z_TVDSS"): - """General function for _read_surface() and (deprecated) method from_surface().""" + """General function for _read_surface()""" val = surf.values xc, yc = surf.get_xy_values() @@ -93,7 +91,7 @@ def _roxar_importer( def _wells_importer( - wells: list[xtgeo.Well], + wells: list[Well], tops: bool = True, incl_limit: float | None = None, top_prefix: str = "Top", @@ -135,7 +133,7 @@ def _wells_importer( def _wells_dfrac_importer( - wells: list[xtgeo.Well], + wells: list[Well], dlogname: str, dcodes: list[int], incl_limit: float = 90, @@ -273,7 +271,7 @@ def points_from_surface( def points_from_wells( - wells: list[xtgeo.Well], + wells: list[Well], tops: bool = True, incl_limit: float | None = None, top_prefix: str = "Top", @@ -300,19 +298,6 @@ def points_from_wells( wells = [xtgeo.well_from_file("w1.w"), xtgeo.well_from_file("w2.w")] points = xtgeo.points_from_wells(wells) - - Note: - The deprecated method :py:meth:`~Points.from_wells` returns the number of - wells that contribute with points. This is now implemented through the - function `get_nwells()`. Hence the following code:: - - nwells_applied = poi.from_wells(...) # deprecated method - # vs - poi = xtgeo.points_from_wells(...) - nwells_applied = poi.get_nwells() - - .. versionadded:: 2.16 Replaces :meth:`~Points.from_wells` - """ return Points( **_wells_importer(wells, tops, incl_limit, top_prefix, zonelist, use_undef) @@ -320,7 +305,7 @@ def points_from_wells( def points_from_wells_dfrac( - wells: list[xtgeo.Well], + wells: list[Well], dlogname: str, dcodes: list[int], incl_limit: float = 90, @@ -353,18 +338,6 @@ def points_from_wells_dfrac( points = xtgeo.points_from_wells_dfrac( wells, dlogname="Facies", dcodes=[4], zonelogname="ZONELOG" ) - - Note: - The deprecated method :py:meth:`~Points.dfrac_from_wells` returns the number of - wells that contribute with points. This is now implemented through the - method `get_nwells()`. Hence the following code:: - - nwells_applied = poi.dfrac_from_wells(...) # deprecated method - # vs - poi = xtgeo.points_from_wells_dfrac(...) - nwells_applied = poi.get_nwells() - - .. versionadded:: 2.16 Replaces :meth:`~Points.dfrac_from_wells` """ return Points( **_wells_dfrac_importer( @@ -373,40 +346,6 @@ def points_from_wells_dfrac( ) -def _allow_deprecated_init(func): - # This decorator is here to maintain backwards compatibility in the construction - # of Points and should be deleted once the deprecation period has expired, - # the construction will then follow the new pattern. - # Introduced post xtgeo version 2.15 - @functools.wraps(func) - def wrapper(cls, *args, **kwargs): - # Checking if we are doing an initialization from file or surface and raise a - # deprecation warning if we are. - if len(args) == 1: - if isinstance(args[0], (str, pathlib.Path)): - warnings.warn( - "Initializing directly from file name is deprecated and will be " - "removed in xtgeo version 4.0. Use: " - "poi = xtgeo.points_from_file('some_file.xx') instead!", - DeprecationWarning, - ) - fformat = kwargs.get("fformat", "guess") - return func(cls, **_file_importer(args[0], fformat)) - - if isinstance(args[0], xtgeo.RegularSurface): - warnings.warn( - "Initializing directly from RegularSurface is deprecated " - "and will be removed in xtgeo version 4.0. Use: " - "poi = xtgeo.points_from_surface(regsurf) instead", - DeprecationWarning, - ) - zname = kwargs.get("zname", "Z_TVDSS") - return func(cls, **_surface_importer(args[0], zname=zname)) - return func(cls, *args, **kwargs) - - return wrapper - - class Points(XYZ): """Class for a Points data in XTGeo. @@ -481,7 +420,6 @@ class Points(XYZ): and is to name and type the extra attribute columns in a point set. """ - @_allow_deprecated_init def __init__( self, values: list | np.ndarray | pd.DataFrame = None, @@ -495,26 +433,6 @@ def __init__( super().__init__(xname, yname, zname) if values is None: values = [] - self._reset( - values=values, - xname=xname, - yname=yname, - zname=zname, - attributes=attributes, - filesrc=filesrc, - ) - - def _reset( - self, - values: list | np.ndarray | pd.DataFrame = None, - xname: str = "X_UTME", - yname: str = "Y_UTMN", - zname: str = "Z_TVDSS", - attributes: dict | None = None, - filesrc: str = None, - ): - """Used in deprecated methods.""" - super()._reset(xname, yname, zname) self._attrs = attributes if attributes is not None else {} self._filesrc = filesrc @@ -626,127 +544,6 @@ def _random(self, nrandom=10): np.random.rand(nrandom, 3), columns=[self._xname, self._yname, self._zname] ) - @inherit_docstring(inherit_from=XYZ.from_file) - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.points_from_file() instead", - ) - def from_file(self, pfile, fformat="xyz"): - self._reset(**_file_importer(pfile, fformat)) - - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.points_from_roxar() instead.", - ) - def from_roxar( - self, - project: str | Any, - name: str, - category: str, - stype: str = "horizons", - realisation: int = 0, - attributes: bool | list[str] = False, - ): # pragma: no cover - """Load a points/polygons item from a Roxar RMS project (deprecated). - - The import from the RMS project can be done either within the project - or outside the project. - - Note that the preferred shortform for (use polygons as example):: - - import xtgeo - mypoly = xtgeo.xyz.Polygons() - mypoly.from_roxar(project, 'TopAare', 'DepthPolys') - - is now:: - - import xtgeo - mysurf = xtgeo.polygons_from_roxar(project, 'TopAare', 'DepthPolys') - - Note also that horizon/zone/faults name and category must exists - in advance, otherwise an Exception will be raised. - - Args: - project (str or special): Name of project (as folder) if - outside RMS, og just use the magic project word if within RMS. - name (str): Name of points item, or name of well pick set if - well picks. - category: For horizons/zones/faults: for example 'DL_depth' - or use a folder notation on clipboard/general2d_data. - For well picks it is the well pick type: 'horizon' or 'fault'. - stype: RMS folder type, 'horizons' (default), 'zones', 'clipboard', - 'general2d_data', 'faults' or 'well_picks' - realisation (int): Realisation number, default is 0 - attributes (bool): Bool or list with attribute names to collect. - If True, all attributes are collected. - - Returns: - Object instance updated - - Raises: - ValueError: Various types of invalid inputs. - - .. deprecated:: 2.16 - Use xtgeo.points_from_roxar() or xtgeo.polygons_from_roxar() - """ - self._reset( - **_roxar_importer( - project, - name, - category, - stype, - realisation, - attributes, - ) - ) - - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use " - "xtgeo.Points(" - "values=dfr[[east, nort, tvdsml]], xname=east, yname=north, zname=tvdmsl" - ") instead", - ) - def from_dataframe(self, dfr, east="X", north="Y", tvdmsl="Z", attributes=None): - """Import points/polygons from existing Pandas dataframe. - - Args: - dfr (dataframe): Pandas dataframe. - east (str): Name of easting column in input dataframe. - north (str): Name of northing column in input dataframe. - tvdmsl (str): Name of depth column in input dataframe. - attributes (dict): Additional metadata columns, on form {"IX": "I", ...}; - "IX" here is the name of the target column, and "I" is the name in the - input dataframe. - - .. versionadded:: 2.13 - .. deprecated:: 2.16 Use points constructor directly instead - """ - if not all(item in dfr.columns for item in (east, north, tvdmsl)): - raise ValueError("One or more column names are not correct") - - if attributes and not all(item in dfr.columns for item in attributes.values()): - raise ValueError("One or more attribute column names are not correct") - - input_ = {} - input_["X_UTME"] = dfr[east] - input_["Y_UTMN"] = dfr[north] - input_["Z_TVDSS"] = dfr[tvdmsl] - - if attributes: - for target, source in attributes.items(): - input_[target] = dfr[source] - - df = pd.DataFrame(input_) - df.dropna(inplace=True) - self._reset(values=df, filesrc="DataFrame input") - def to_file( self, pfile, @@ -799,101 +596,6 @@ def to_file( **kwargs, ) - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.points_from_wells() instead.", - ) - def from_wells( - self, - wells, - tops=True, - incl_limit=None, - top_prefix="Top", - zonelist=None, - use_undef=False, - ): - """Get tops or zone points data from a list of wells. - - Args: - wells (list): List of XTGeo well objects - tops (bool): Get the tops if True (default), otherwise zone - incl_limit (float): Inclination limit for zones (thickness points) - top_prefix (str): Prefix used for Tops - zonelist (list-like): Which zone numbers to apply. - use_undef (bool): If True, then transition from UNDEF within zonelog - is also used. - - Returns: - None if well list is empty; otherwise the number of wells. - - Raises: - Todo - - .. deprecated:: 2.16 - Use classmethod :py:func:`points_from_wells()` instead - """ - self._reset( - **_wells_importer(wells, tops, incl_limit, top_prefix, zonelist, use_undef) - ) - return self.get_dataframe(copy=False)["WellName"].nunique() - - @inherit_docstring(inherit_from=XYZ.from_list) - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use direct Points() initialisation instead", - ) - def from_list(self, plist): - self._reset(_xyz_io._from_list_like(plist, "Z_TVDSS", None, False)) - - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.points_from_wells_dfrac() instead.", - ) - def dfrac_from_wells( - self, - wells, - dlogname, - dcodes, - incl_limit=90, - count_limit=3, - zonelist=None, - zonelogname=None, - ): - """Get fraction of discrete code(s) (e.g. facies) per zone. - - Args: - wells (list): List of XTGeo well objects - dlogname (str): Name of discrete log (e.g. Facies) - dcodes (list of int): Code(s) to get fraction for, e.g. [3] - incl_limit (float): Inclination limit for zones (thickness points) - count_limit (int): Min. no of counts per segment for valid result - zonelist (list of int): Whihc zones to compute for (default None - means that all zones will be evaluated) - zonelogname (str): Name of zonelog; if None than the - well.zonelogname property will be applied. - - Returns: - None if well list is empty; otherwise the number of wells. - - Raises: - Todo - - .. deprecated:: 2.16 - Use classmethod :py:func:`points_from_wells_dfrac()` instead. - """ - - self._reset( - **_wells_dfrac_importer( - wells, dlogname, dcodes, incl_limit, count_limit, zonelist, zonelogname - ) - ) - def to_roxar( self, project, @@ -963,33 +665,6 @@ def copy(self): return mycopy - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.points_from_surface() instead", - ) - def from_surface(self, surf, zname="Z_TVDSS"): - """Get points as X Y Value from a surface object nodes (deprecated). - - Note that undefined surface nodes will not be included. - - Args: - surf (RegularSurface): A XTGeo RegularSurface object instance. - zname (str): Name of value column (3'rd column) - - Example:: - - topx = xtgeo.surface_from_file("topx.gri") - topx_aspoints = xtgeo.points_from_surface(topx) - - topx_aspoints.to_file("mypoints.poi") # export as XYZ file - - .. deprecated:: 2.16 Use xtgeo.points_from_surface() instead. - """ - - self._reset(**_surface_importer(surf, zname=zname)) - def snap_surface(self, surf, activeonly=True): """Snap (transfer) the points Z values to a RegularSurface diff --git a/src/xtgeo/xyz/polygons.py b/src/xtgeo/xyz/polygons.py index 548d87ffa..b5bffbdc9 100644 --- a/src/xtgeo/xyz/polygons.py +++ b/src/xtgeo/xyz/polygons.py @@ -5,13 +5,10 @@ # which identifies each polygon piece. from __future__ import annotations -import functools -import pathlib import warnings from copy import deepcopy from typing import TYPE_CHECKING, Any -import deprecation import numpy as np import pandas as pd import shapely.geometry as sg @@ -19,7 +16,6 @@ from xtgeo.common.exceptions import InvalidFileFormatError from xtgeo.common.log import null_logger from xtgeo.common.sys import inherit_docstring -from xtgeo.common.version import __version__ from xtgeo.io._file import FileFormat, FileWrapper from xtgeo.xyz import _xyz_io, _xyz_roxapi @@ -29,6 +25,7 @@ if TYPE_CHECKING: import io + import pathlib from xtgeo.well.well1 import Well @@ -52,7 +49,7 @@ def _file_importer( pfile: str | pathlib.Path | io.BytesIO, fformat: str | None = None, ): - """General function for polygons_from_file and (deprecated) method from_file.""" + """General function for polygons_from_file""" pfile = FileWrapper(pfile) fmt = pfile.fileformat(fformat) kwargs = _data_reader_factory(fmt)(pfile) @@ -202,47 +199,10 @@ def polygons_from_wells( wells = ["w1.w", "w2.w"] points = xtgeo.polygons_from_wells(wells, zone=2) - - Note: - This method replaces the deprecated method :py:meth:`~Polygons.from_wells`. - The latter returns the number of wells that contribute with polygon segments. - This is now implemented through the function `get_nwells()`. Hence the - following code:: - - nwells_applied = poly.from_wells(...) # deprecated method - # vs - poly = xtgeo.polygons_from_wells(...) - nwells_applied = poly.get_nwells() - - .. versionadded: 2.16 """ return Polygons(**_wells_importer(wells, zone, resample)) -def _allow_deprecated_init(func): - # This decorator is here to maintain backwards compatibility in the construction - # of Polygons and should be deleted once the deprecation period has expired, - # the construction will then follow the new pattern. - # Introduced post xtgeo version 2.15 - @functools.wraps(func) - def wrapper(cls, *args, **kwargs): - # Checking if we are doing an initialization from file or surface and raise a - # deprecation warning if we are. - if len(args) == 1 and isinstance(args[0], (str, pathlib.Path)): - warnings.warn( - "Initializing directly from file name is deprecated and will be " - "removed in xtgeo version 4.0. Use: " - "pol = xtgeo.polygons_from_file('some_file.xx') instead!", - DeprecationWarning, - ) - fformat = kwargs.get("fformat", "guess") - return func(cls, **_file_importer(args[0], fformat)) - - return func(cls, *args, **kwargs) - - return wrapper - - class Polygons(XYZ): """Class for a Polygons object (connected points) in the XTGeo framework. @@ -284,7 +244,6 @@ class Polygons(XYZ): and is to name and type the extra attribute columns in a point set. """ - @_allow_deprecated_init def __init__( self, values: list | np.ndarray | pd.DataFrame = None, @@ -306,39 +265,6 @@ def __init__( if values is None: values = [] - logger.info("Legacy fformat key with value %s shall be removed in 4.0", fformat) - - self._reset( - values=values, - xname=xname, - yname=yname, - zname=zname, - pname=pname, - hname=hname, - dhname=dhname, - tname=tname, - dtname=dtname, - name=name, - attributes=attributes, - ) - - def _reset( # pylint: disable=arguments-renamed - self, - values: list | np.ndarray | pd.DataFrame, - xname: str = "X_UTME", - yname: str = "Y_UTMN", - zname: str = "Z_TVDSS", - pname: str = "POLY_ID", - hname: str = "H_CUMLEN", - dhname: str = "H_DELTALEN", - tname: str = "T_CUMLEN", - dtname: str = "T_DELTALEN", - name: str = "poly", - attributes: dict | None = None, - ): # pylint: disable=arguments-differ - """Used in deprecated methods.""" - - super()._reset(xname, yname, zname) # additonal state properties for Polygons self._pname = pname @@ -522,16 +448,6 @@ def boundary_from_points( def protected_columns(self): return super().protected_columns() + [self.pname] - @inherit_docstring(inherit_from=XYZ.from_file) - @deprecation.deprecated( - deprecated_in="2.21", # should have been 2.16, but was forgotten until 2.21 - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.polygons_from_file() instead", - ) - def from_file(self, pfile, fformat="xyz"): - self._reset(**_file_importer(pfile, fformat)) - def to_file( self, pfile, @@ -549,41 +465,6 @@ def to_file( return _xyz_io.to_file(self, pfile, fformat=fformat, ispolygons=True) - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use xtgeo.polygons_from_wells(...) instead", - ) - def from_wells(self, wells, zone, resample=1): - """Get line segments from a list of wells and a single zone number. - - Args: - wells (list): List of XTGeo well objects - zone (int): Which zone to apply - resample (int): If given, resample every N'th sample to make - polylines smaller in terms of bits and bytes. - 1 = No resampling which means well sampling (which can be rather - dense; typically 15 cm). - - Returns: - None if well list is empty; otherwise the number of wells that - have one or more line segments to return - - """ - if not wells: - return None - - self._reset(**_wells_importer(wells, zone, resample)) - - dataframe = self.get_dataframe() - nwells = dataframe["WellName"].nunique() - # as the previous versions did not have the WellName column, this is dropped - # here for backward compatibility: - self.set_dataframe(dataframe.drop("WellName", axis=1)) - - return None if nwells == 0 else nwells - def to_roxar( self, project, @@ -652,18 +533,6 @@ def copy(self): return mycopy - @inherit_docstring(inherit_from=XYZ.from_list) - @deprecation.deprecated( - deprecated_in="2.16", - removed_in="4.0", - current_version=__version__, - details="Use direct Polygons() initialisation instead", - ) - def from_list(self, plist): - kwargs = {} - kwargs["values"] = _xyz_io._from_list_like(plist, "Z_TVDSS", None, True) - self._reset(**kwargs) - def get_xyz_dataframe(self): """Get a dataframe copy from the Polygons points with no ID column. diff --git a/tests/test_surface/test_regular_surface_resample.py b/tests/test_surface/test_regular_surface_resample.py index 1d47f4323..40d60f9c0 100644 --- a/tests/test_surface/test_regular_surface_resample.py +++ b/tests/test_surface/test_regular_surface_resample.py @@ -7,7 +7,6 @@ import xtgeo from xtgeo.common import XTGeoDialog from xtgeo.surface import RegularSurface -from xtgeo.xyz import Points xtg = XTGeoDialog() logger = xtg.basiclogger(__name__) @@ -308,7 +307,7 @@ def test_points_gridding(tmp_path, reek_map, generate_plot): xs = reek_map assert xs.ncol == 554 - xyz = Points(xs) + xyz = xtgeo.points_from_surface(xs) dataframe = xyz.get_dataframe() dataframe["Z_TVDSS"] = dataframe["Z_TVDSS"] + 300 diff --git a/tests/test_xyz/test_points.py b/tests/test_xyz/test_points.py index 5a69ab68f..fc77ab742 100644 --- a/tests/test_xyz/test_points.py +++ b/tests/test_xyz/test_points.py @@ -147,16 +147,13 @@ def test_export_load_rmsformatted_points(testdata_path, tmp_path): def test_import_rmsattr_format(testdata_path, tmp_path): """Import points with attributes from RMS attr format.""" - orig_points = Points() - test_points_path = testdata_path / POINTSET3 - orig_points.from_file(test_points_path, fformat="rms_attr") + orig_points = xtgeo.points_from_file(test_points_path, fformat="rms_attr") export_path = tmp_path / "attrs.rmsattr" orig_points.to_file(export_path, fformat="rms_attr") - reloaded_points = Points() - reloaded_points.from_file(export_path, fformat="rms_attr") + reloaded_points = xtgeo.points_from_file(export_path, fformat="rms_attr") pd.testing.assert_frame_equal( orig_points.get_dataframe(), reloaded_points.get_dataframe() ) diff --git a/tests/test_xyz/test_xyz_deprecated.py b/tests/test_xyz/test_xyz_deprecated.py deleted file mode 100644 index d977fd51b..000000000 --- a/tests/test_xyz/test_xyz_deprecated.py +++ /dev/null @@ -1,202 +0,0 @@ -"""Collect deprecated stuff for Points() and Polygons().""" - -import glob -import pathlib - -import pandas as pd -import pytest -import xtgeo -from packaging import version -from xtgeo.common.version import __version__ as xtgeo_version - -PFILE1A = pathlib.Path("polygons/reek/1/top_upper_reek_faultpoly.zmap") -PFILE1B = pathlib.Path("polygons/reek/1/top_upper_reek_faultpoly.xyz") -PFILE1C = pathlib.Path("polygons/reek/1/top_upper_reek_faultpoly.pol") -SURFACE = pathlib.Path("surfaces/reek/1/topreek_rota.gri") -WFILES1 = pathlib.Path("wells/reek/1/OP_1.w") -WFILES2 = pathlib.Path("wells/reek/1/OP_[1-5]*.w") -POLSET2 = pathlib.Path("polygons/reek/1/polset2.pol") -POINTSET2 = pathlib.Path("points/reek/1/pointset2.poi") -CSV1 = pathlib.Path("3dgrids/etc/gridqc1_rms_cellcenter.csv") - - -def test_load_points_polygons_file_deprecated(testdata_path): - """Load from file.""" - with pytest.warns( - DeprecationWarning, match="Initializing directly from file name is deprecated" - ): - poi = xtgeo.Points(testdata_path / POINTSET2) - - assert poi.nrow == 30 - - with pytest.warns( - DeprecationWarning, match="Initializing directly from file name is deprecated" - ): - pol = xtgeo.Polygons(testdata_path / POLSET2) - - assert pol.nrow == 25 - - -def test_points_from_list_deprecated(): - plist = [(234, 556, 11), (235, 559, 14), (255, 577, 12)] - - with pytest.warns(DeprecationWarning, match="Use direct"): - mypoints = xtgeo.Points(plist) - - old_points = xtgeo.Points() - old_points.from_list(plist) - assert mypoints.get_dataframe().equals(old_points.get_dataframe()) - - -def test_import_from_dataframe_deprecated(testdata_path): - """Import Points via Pandas dataframe, deprecated behaviour.""" - - dfr = pd.read_csv(testdata_path / CSV1, skiprows=3) - - mypoints = xtgeo.Points() - attr = {"IX": "I", "JY": "J", "KZ": "K"} - with pytest.warns(DeprecationWarning): - mypoints.from_dataframe(dfr, east="X", north="Y", tvdmsl="Z", attributes=attr) - - assert mypoints.get_dataframe().X_UTME.mean() == dfr.X.mean() - - -@pytest.mark.parametrize( - "filename, fformat", - [ - (PFILE1A, "zmap"), - (PFILE1B, "xyz"), - (PFILE1C, "pol"), - ], -) -def test_polygons_from_file_alternatives_with_deprecated( - testdata_path, filename, fformat -): - if version.parse(xtgeo_version) < version.parse("2.21"): - # to avoid test failure before tag is actually set - pytest.skip() - else: - with pytest.warns(DeprecationWarning): - polygons1 = xtgeo.Polygons(testdata_path / filename) - - polygons2 = xtgeo.Polygons() - with pytest.warns(DeprecationWarning): - polygons2.from_file(testdata_path / filename, fformat=fformat) - - polygons3 = xtgeo.polygons_from_file(testdata_path / filename, fformat=fformat) - polygons4 = xtgeo.polygons_from_file(testdata_path / filename) - - pd.testing.assert_frame_equal( - polygons1.get_dataframe(), polygons2.get_dataframe() - ) - pd.testing.assert_frame_equal( - polygons2.get_dataframe(), polygons3.get_dataframe() - ) - pd.testing.assert_frame_equal( - polygons3.get_dataframe(), polygons4.get_dataframe() - ) - - -def test_get_polygons_one_well_deprecated(testdata_path, tmp_path): - """Import a well and get the polygon segments.""" - wlist = [xtgeo.well_from_file((testdata_path / WFILES1), zonelogname="Zonelog")] - - mypoly = xtgeo.Polygons() - with pytest.warns(DeprecationWarning): - mypoly.from_wells(wlist, 2) - - assert mypoly.nrow == 29 - mypoly.to_file(tmp_path / "poly_w1.irapasc") - - -def test_get_polygons_many_wells_deprecated(testdata_path, tmp_path): - """Import some wells and get the polygon segments.""" - wlist = [ - xtgeo.well_from_file(wpath, zonelogname="Zonelog") - for wpath in glob.glob(str(testdata_path / WFILES2)) - ] - - mypoly = xtgeo.Polygons() - with pytest.warns(DeprecationWarning): - mypoly.from_wells(wlist, 2, resample=10) - - mypoly.to_file(tmp_path / "poly_w1_many.irapasc") - - # compare with new class initialization (which also adds a well column) - mypoly2 = xtgeo.polygons_from_wells(wlist, 2, resample=10) - mypoly2.to_file(tmp_path / "poly_w1_many_new.irapasc") - - pd.testing.assert_frame_equal( - mypoly.get_dataframe().iloc[:, 0:4], mypoly2.get_dataframe().iloc[:, 0:4] - ) - - -def test_init_with_surface_deprecated(testdata_path): - """Initialise points object with surface instance, to be deprecated.""" - surf = xtgeo.surface_from_file(testdata_path / SURFACE) - with pytest.warns( - DeprecationWarning, - match="Initializing directly from RegularSurface is deprecated", - ): - poi = xtgeo.Points(surf) - - poi.zname = "VALUES" - pd.testing.assert_frame_equal(poi.get_dataframe(), surf.get_dataframe()) - - -def test_get_zone_tops_one_well_deprecated(testdata_path): - """Import a well and get the zone tops, old method to be depr.""" - - wlist = [xtgeo.well_from_file(testdata_path / WFILES1, zonelogname="Zonelog")] - - mypoints = xtgeo.Points() - with pytest.warns(DeprecationWarning, match="from_wells is deprecated"): - mypoints.from_wells(wlist) - - mypoints_new = xtgeo.points_from_wells(wlist) - - pd.testing.assert_frame_equal( - mypoints.get_dataframe(), mypoints_new.get_dataframe() - ) - - -def test_get_zone_tops_some_wells_deprecated(testdata_path): - """Import some well and get the zone tops""" - - wlist = [ - xtgeo.well_from_file(wpath, zonelogname="Zonelog") - for wpath in glob.glob(str(testdata_path / WFILES2)) - ] - - # legacy - p1 = xtgeo.Points() - with pytest.warns(DeprecationWarning, match="from_wells is deprecated as of"): - p1.from_wells(wlist) - assert p1.nrow == 28 - - # classmethod - p2 = xtgeo.points_from_wells(wlist) - assert p1.get_dataframe().equals(p2.get_dataframe()) - - -def test_get_faciesfraction_some_wells_deprecated(testdata_path): - """Import some wells and get the facies fractions per zone.""" - wlist = [ - xtgeo.well_from_file(wpath, zonelogname="Zonelog") - for wpath in glob.glob(str(testdata_path / WFILES2)) - ] - - mypoints = xtgeo.Points() - facname = "Facies" - fcode = [1] - - with pytest.warns(DeprecationWarning, match="dfrac_from_wells is deprecated"): - mypoints.dfrac_from_wells(wlist, facname, fcode, zonelist=None, incl_limit=70) - - # rename column - mypoints.zname = "FACFRAC" - - myquery = 'WELLNAME == "OP_1" and ZONE == 1' - usedf = mypoints.get_dataframe().query(myquery) - - assert abs(usedf[mypoints.zname].values[0] - 0.86957) < 0.001