Skip to content

Commit

Permalink
DEP: Complete xtgeo 4 wells deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Aug 13, 2024
1 parent 3a48d2c commit 855fc0a
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 398 deletions.
71 changes: 1 addition & 70 deletions src/xtgeo/well/_well_aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@

from __future__ import annotations

import functools
import warnings
from pathlib import Path
from typing import TYPE_CHECKING

import pandas as pd

from xtgeo.common._xyz_enum import _AttrName
from xtgeo.common.exceptions import InvalidFileFormatError
from xtgeo.common.log import null_logger
from xtgeo.io._file import FileFormat, FileWrapper
from xtgeo.io._file import FileFormat

from . import _well_io

if TYPE_CHECKING:
from collections.abc import Callable

logger = null_logger(__name__)


Expand All @@ -39,61 +28,3 @@ def _data_reader_factory(file_format: FileFormat):
f"File format {file_format} is invalid for Well types. "
f"Supported formats are {extensions}."
)


def allow_deprecated_init(func: Callable):
# This decorator is here to maintain backwards compatibility in the
# construction of Well and should be deleted once the deprecation period
# has expired, the construction will then follow the new pattern.
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
if not args and not kwargs:
warnings.warn(
"Initializing empty well is deprecated, please provide "
"non-defaulted values, or use mywell = "
"xtgeo.well_from_file('filename')",
DeprecationWarning,
)
return func(
self,
*([0.0] * 3),
"",
pd.DataFrame(
{
_AttrName.XNAME.value: [],
_AttrName.YNAME.value: [],
_AttrName.ZNAME.value: [],
}
),
)

# Checking if we are doing an initialization from file and raise a
# deprecation warning if we are.
if "wfile" in kwargs or (
len(args) >= 1 and isinstance(args[0], (str, Path, FileWrapper))
):
warnings.warn(
"Initializing directly from file name is deprecated and will be "
"removed in xtgeo version 4.0. Use: "
"mywell = xtgeo.well_from_file('filename') instead",
DeprecationWarning,
)
if len(args) >= 1:
wfile = args[0]
args = args[1:]
else:
wfile = kwargs.pop("wfile", None)
if len(args) >= 1:
fformat = args[0]
args = args[1:]
else:
fformat = kwargs.pop("fformat", None)

mfile = FileWrapper(wfile)
fmt = mfile.fileformat(fformat)
kwargs = _data_reader_factory(fmt)(mfile, *args, **kwargs)
kwargs["filesrc"] = mfile.file
return func(self, **kwargs)
return func(self, *args, **kwargs)

return wrapper
46 changes: 0 additions & 46 deletions src/xtgeo/well/blocked_well.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""XTGeo blockedwell module"""

import deprecation
import pandas as pd

from xtgeo.common._xyz_enum import _AttrName
from xtgeo.common.log import null_logger
from xtgeo.common.version import __version__

from . import _blockedwell_roxapi
from .well1 import Well
Expand Down Expand Up @@ -170,50 +168,6 @@ def copy(self):

return newbw

@deprecation.deprecated(
deprecated_in="2.16",
removed_in="4.0",
current_version=__version__,
details="Use xtgeo.blockedwell_from_roxar() instead",
)
def from_roxar(self, *args, **kwargs):
"""Import (retrieve) a single blocked well from roxar project.
Note this method works only when inside RMS, or when RMS license is
activated.
Args:
project (str): Magic string `project` or file path to project
gname (str): Name of GridModel icon in RMS
bwname (str): Name of Blocked Well icon in RMS, usually 'BW'
wname (str): Name of well, as shown in RMS.
lognames (list): List of lognames to include, or use 'all' for
all current blocked logs for this well. Default is 'all'.
realisation (int): Realisation index (0 is default)
ijk (bool): If True, then make additional logs with grid IJK as I_INDEX,
etc, default is False
"""
project = args[0]
gname = args[1]
bwname = args[2]
wname = args[3]
lognames = kwargs.get("lognames", "all")
ijk = kwargs.get("ijk", False)
realisation = kwargs.get("realisation", 0)

_blockedwell_roxapi.import_bwell_roxapi(
self,
project,
gname,
bwname,
wname,
lognames=lognames,
ijk=ijk,
realisation=realisation,
)

self._ensure_consistency()

def to_roxar(self, *args, **kwargs):
"""Set (export) a single blocked well item inside roxar project.
Expand Down
94 changes: 0 additions & 94 deletions src/xtgeo/well/blocked_wells.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""BlockedWells module, (collection of BlockedWell objects)"""

import deprecation

from xtgeo.common.log import null_logger
from xtgeo.common.version import __version__
from xtgeo.common.xtgeo_dialog import XTGeoDialog

from . import _blockedwells_roxapi
Expand Down Expand Up @@ -97,97 +94,6 @@ def get_blocked_well(self, name):
logger.debug("Calling super...")
return super().get_well(name)

@deprecation.deprecated(
deprecated_in="2.16",
removed_in="4.0",
current_version=__version__,
details="Use xtgeo.blockedwells_from_files() instead",
)
def from_files(
self,
filelist,
fformat="rms_ascii",
mdlogname=None,
zonelogname=None,
strict=True,
append=True,
):
"""Import blocked wells from a list of files (filelist).
Args:
filelist (list of str): List with file names
fformat (str): File format, rms_ascii (rms well) is
currently supported and default format.
mdlogname (str): Name of measured depth log, if any
zonelogname (str): Name of zonation log, if any
strict (bool): If True, then import will fail if
zonelogname or mdlogname are asked for but not present
in wells.
append (bool): If True, new wells will be added to existing
wells.
Example:
Here the from_file method is used to initiate the object
directly::
mywells = BlockedWells(['31_2-6.w', '31_2-7.w', '31_2-8.w'])
"""

if not append:
self._wells = []

# file checks are done within the Well() class
for wfile in filelist:
try:
wll = blockedwell_from_file(
wfile,
fformat=fformat,
mdlogname=mdlogname,
zonelogname=zonelogname,
strict=strict,
)
self._wells.append(wll)
except ValueError as err:
xtg.warn(f"SKIP this well: {err}")
continue
if not self._wells:
xtg.warn("No wells imported!")

@deprecation.deprecated(
deprecated_in="2.16",
removed_in="4.0",
current_version=__version__,
details="Use xtgeo.blockedwells_from_roxar() instead",
)
def from_roxar(self, *args, **kwargs): # pragma: no cover
"""Import (retrieve) blocked wells from roxar project.
Note this method works only when inside RMS, or when RMS license is
activated.
All the wells present in the bwname icon will be imported.
Args:
project (str): Magic string 'project' or file path to project
gname (str): Name of GridModel icon in RMS
bwname (str): Name of Blocked Well icon in RMS, usually 'BW'
lognames (list): List of lognames to include, or use 'all' for
all current blocked logs for this well.
ijk (bool): If True, then logs with grid IJK as I_INDEX, etc
realisation (int): Realisation index (0 is default)
"""
project = args[0]
gname = args[1]
bwname = args[2]
lognames = kwargs.get("lognames", None)
ijk = kwargs.get("ijk", True)

_blockedwells_roxapi.import_bwells_roxapi(
self, project, gname, bwname, lognames=lognames, ijk=ijk
)

# this is a temporary solution to avoid the deprecation warning; ideally a class
# method shall be applied
def _from_roxar(self, *args, **kwargs): # pragma: no cover
"""Import (retrieve) blocked wells from roxar project.
Expand Down
69 changes: 0 additions & 69 deletions src/xtgeo/well/well1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from copy import deepcopy
from typing import TYPE_CHECKING

import deprecation
import numpy as np
import pandas as pd

Expand All @@ -15,7 +14,6 @@
from xtgeo.common.constants import UNDEF, UNDEF_INT, UNDEF_LIMIT
from xtgeo.common.exceptions import InvalidFileFormatError
from xtgeo.common.log import null_logger
from xtgeo.common.version import __version__
from xtgeo.common.xtgeo_dialog import XTGDescription
from xtgeo.io._file import FileFormat, FileWrapper
from xtgeo.metadata.metadata import MetaDataWell
Expand Down Expand Up @@ -177,7 +175,6 @@ class Well:
defaults to None.
"""

@_well_aux.allow_deprecated_init
def __init__(
self,
rkb: float = 0.0,
Expand Down Expand Up @@ -208,8 +205,6 @@ def __init__(
self._metadata = MetaDataWell()
self._metadata.required = self

_reset = __init__ # workaround until deprecation .from_file(), etc are removed

def __repr__(self): # noqa: D105
# should (in theory...) be able to newobject = eval(repr(thisobject))
return (
Expand Down Expand Up @@ -492,26 +487,6 @@ def describe(self, flush=True):

return dsc.astext()

@deprecation.deprecated(
deprecated_in="2.16",
removed_in="4.0",
current_version=__version__,
details="Use xtgeo.well_from_file() instead",
)
def from_file(
self,
wfile,
fformat="rms_ascii",
**kwargs,
):
"""Deprecated, see :meth:`xtgeo.well_from_file`"""

wfile = FileWrapper(wfile)
fmt = wfile.fileformat(fformat)
kwargs = _well_aux._data_reader_factory(fmt)(wfile, **kwargs)
self._reset(**kwargs)
return self

@classmethod
def _read_file(
cls,
Expand Down Expand Up @@ -603,19 +578,6 @@ def to_file(

return wfile.file

@deprecation.deprecated(
deprecated_in="3.6",
removed_in="4.0",
current_version=__version__,
details="Use xtgeo.well_from_file() instead",
)
def from_hdf(
self,
wfile: str | Path,
):
"""Deprecated, use :meth:`xtgeo.well_from_file()`"""
return self.from_file(wfile, fformat="hdf")

def to_hdf(
self,
wfile: str | Path,
Expand Down Expand Up @@ -643,37 +605,6 @@ def to_hdf(

return wfile.file

@deprecation.deprecated(
deprecated_in="2.16",
removed_in="4.0",
current_version=__version__,
details="Use xtgeo.well_from_roxar() instead",
)
def from_roxar(
self,
project: str | object,
name: str,
trajectory: str | None = "Drilled trajectory",
logrun: str | None = "log",
lognames: str | list[str] | None = "all",
lognames_strict: bool | None = False,
inclmd: bool | None = False,
inclsurvey: bool | None = False,
):
"""Deprecated, use :meth:`xtgeo.well_from_roxar()`"""
kwargs = _well_roxapi.import_well_roxapi(
project,
name,
trajectory=trajectory,
logrun=logrun,
lognames=lognames,
lognames_strict=lognames_strict,
inclmd=inclmd,
inclsurvey=inclsurvey,
)
self._reset(**kwargs)
return self

@classmethod
def _read_roxar(
cls,
Expand Down
Loading

0 comments on commit 855fc0a

Please sign in to comment.