Skip to content

Commit

Permalink
fixup (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Oct 25, 2023
1 parent f35de11 commit 0bbea16
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 104 deletions.
15 changes: 15 additions & 0 deletions src/xtgeo/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@
"""The XTGeo common package"""


from xtgeo.common._xyz_data import _XYZData
from xtgeo.common._xyz_enum import _AttrName, _AttrType, _XYZType
from xtgeo.common.exceptions import WellNotFoundError
from xtgeo.common.sys import _XTGeoFile, inherit_docstring

# flake8: noqa
from xtgeo.common.xtgeo_dialog import XTGDescription, XTGeoDialog, XTGShowProgress

__all__ = [
"_XYZData",
"_AttrName",
"_AttrType",
"_XYZType",
"WellNotFoundError",
"_XTGeoFile",
"inherit_docstring",
"XTGDescription",
"XTGeoDialog",
"XTGShowProgress",
]
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
from joblib import hash as jhash

import xtgeo.common.constants as const
from xtgeo import XTGeoCLibError # type: ignore[attr-defined]
from xtgeo.common import XTGeoDialog
from xtgeo.common.sys import _convert_carr_double_np, _get_carray
from xtgeo.common.xtgeo_dialog import XTGeoDialog
from xtgeo.cxtgeo import _cxtgeo
from xtgeo.cxtgeo._cxtgeo import XTGeoCLibError # type: ignore[attr-defined]

from ._xyz_enum import _AttrName, _AttrType, _XYZType

Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(
zname: str = _AttrName.ZNAME.value,
idname: Optional[str] = None, # Well, Polygon, ...
undef: Union[float, Sequence[float, float]] = -999.0,
xyztype: str = "well",
xyztype: Literal["well", "points", "polygons"] = "well",
floatbits: Literal["float32", "float64"] = "float64",
):
logger.info("Running init for: %s", __name__)
Expand Down Expand Up @@ -291,7 +291,7 @@ def _ensure_consistency_df_dtypes(self):
self._df[col[3:]] = self._df.iloc[:, 3:].astype(self._floatbits)

for name, attr_type in self._attr_types.items():
if attr_type == "CONT":
if attr_type == _AttrType.CONT.value:
logger.debug("Replacing CONT undef...")
self._df[name].replace(
self._undef_cont,
Expand Down Expand Up @@ -364,9 +364,9 @@ def set_attr_type(self, name: str, attrtype: str) -> None:

apply_attrtype = attrtype.upper()
if "FLOAT" in apply_attrtype:
apply_attrtype = "CONT"
apply_attrtype = _AttrType.CONT.value
if "INT" in apply_attrtype:
apply_attrtype = "DISC"
apply_attrtype = _AttrType.DISC.value

if name not in self._attr_types:
raise ValueError(f"No such log name present: {name}")
Expand Down Expand Up @@ -436,7 +436,7 @@ def get_dataframe_copy(
dfr = self._df.copy()
if infer_dtype:
for name, attrtype in self._attr_types.items():
if attrtype.name == "DISC":
if attrtype.name == _AttrType.DISC.value:
dfr[name] = dfr[name].fillna(fill_value_int)
dfr[name] = dfr[name].astype("int32")

Expand Down Expand Up @@ -485,7 +485,10 @@ def rename_attr(self, attrname: str, newname: str):
def create_attr(
self,
attrname: str,
attr_type: str = Literal["CONT", "DISC"],
attr_type: str = Literal[
_AttrType.CONT.value, # type: ignore
_AttrType.DISC.value, # type: ignore
],
attr_record: Optional[dict] = None,
value: float = 0.0,
force: bool = True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class _AttrName(ExtendedEnum):
class _AttrType(ExtendedEnum):
"""Enumerate type of attribute/log"""

CONT = 1
DISC = 2
CONT = "CONT"
DISC = "DISC"


@unique
Expand Down
3 changes: 2 additions & 1 deletion src/xtgeo/common/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from xtgeo.cxtgeo import _cxtgeo

from ._xyz_enum import _AttrType
from .xtgeo_dialog import XTGeoDialog

xtg = XTGeoDialog()
Expand Down Expand Up @@ -740,7 +741,7 @@ def _get_carray(dataframe, attributes, attrname: str):
return None

nlen = len(dataframe.index)
if attributes[attrname] == "DISC":
if attributes[attrname] == _AttrType.DISC.value:
carr = _convert_np_carr_int(nlen, np_array)
else:
carr = _convert_np_carr_double(nlen, np_array)
Expand Down
26 changes: 14 additions & 12 deletions src/xtgeo/well/_blockedwell_roxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import pandas as pd

from xtgeo.common import XTGeoDialog
from xtgeo.common._xyz_enum import _AttrName, _AttrType
from xtgeo.common.exceptions import WellNotFoundError
from xtgeo.roxutils import RoxUtils

from ..xyz_common._xyz_enum import _AttrName

try:
import roxar # type: ignore
except ImportError:
Expand All @@ -27,7 +26,7 @@ def import_bwell_roxapi(
):
"""Private function for loading project and ROXAPI blockwell import"""

logger.info("Opening RMS project ...")
logger.debug("Opening RMS project ...")
rox = RoxUtils(project, readonly=True)

_roxapi_import_bwell(self, rox, gname, bwname, wname, lognames, ijk, realisation)
Expand All @@ -40,7 +39,7 @@ def export_bwell_roxapi(
):
"""Private function for blockwell export (store in RMS) from XTGeo to RoxarAPI"""

logger.info("Opening RMS project ...")
logger.debug("Opening RMS project ...")
rox = RoxUtils(project, readonly=False)

_roxapi_export_bwell(self, rox, gname, bwname, wname, lognames, ijk, realisation)
Expand All @@ -58,13 +57,13 @@ def _roxapi_import_bwell(

if gname in rox.project.grid_models:
gmodel = rox.project.grid_models[gname]
logger.info("RMS grid model <%s> OK", gname)
logger.debug("RMS grid model <%s> OK", gname)
else:
raise ValueError(f"No such grid name present: {gname}")

if bwname in gmodel.blocked_wells_set:
bwset = gmodel.blocked_wells_set[bwname]
logger.info("Blocked well set <%s> OK", bwname)
logger.debug("Blocked well set <%s> OK", bwname)
else:
raise ValueError(f"No such blocked well set: {bwname}")

Expand Down Expand Up @@ -111,10 +110,10 @@ def _roxapi_import_bwell(
tmplog = npma.filled(tmplog, fill_value=np.nan)
tmplog[tmplog == -999] = np.nan
if "discrete" in str(bwprop.type):
self.set_logtype(lname, "DISC")
self.set_logtype(lname, _AttrType.DISC.value)
self.set_logrecord(lname, bwprop.code_names)
else:
self.set_logtype(lname, "CONT")
self.set_logtype(lname, _AttrType.CONT.value)
self.set_logrecord(lname, None)

logs[lname] = tmplog
Expand All @@ -132,7 +131,10 @@ def _roxapi_import_bwell(
self._xpos, self._ypos = rox.project.wells[wname].wellhead
else:
self._rkb = None
self._xpos, self._ypos = self._df["X_UTME"][0], self._df["Y_UTMN"][0]
self._xpos, self._ypos = (
self._df[_AttrName.XNAME][0],
self._df[_AttrName.YNAME][0],
)


def _roxapi_export_bwell(
Expand All @@ -142,13 +144,13 @@ def _roxapi_export_bwell(

if gname in rox.project.grid_models:
gmodel = rox.project.grid_models[gname]
logger.info("RMS grid model <%s> OK", gname)
logger.debug("RMS grid model <%s> OK", gname)
else:
raise ValueError(f"No such grid name present: {gname}")

if bwname in gmodel.blocked_wells_set:
bwset = gmodel.blocked_wells_set[bwname]
logger.info("Blocked well set <%s> OK", bwname)
logger.debug("Blocked well set <%s> OK", bwname)
bwprops = bwset.properties
else:
raise ValueError(f"No such blocked well set: {bwname}")
Expand Down Expand Up @@ -179,7 +181,7 @@ def _roxapi_export_bwell(
continue

if lname not in bwnames:
if self._wlogtypes[lname] == "CONT":
if self._wlogtypes[lname] == _AttrType.CONT.value:
print("Create CONT", lname, "for", wname)
bwlog = bwset.properties.create(
lname, roxar.GridPropertyType.continuous, np.float32
Expand Down
12 changes: 6 additions & 6 deletions src/xtgeo/well/_blockedwells_roxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def import_bwells_roxapi(
): # pragma: no cover
"""Private function for loading project and ROXAPI blockwell import"""

logger.info("Opening RMS project ...")
logger.debug("Opening RMS project ...")
rox = RoxUtils(project, readonly=True)

_roxapi_import_bwells(self, rox, gname, bwname, lognames, ijk, realisation)
Expand All @@ -33,24 +33,24 @@ def _roxapi_import_bwells(

if gname in rox.project.grid_models:
gmodel = rox.project.grid_models[gname]
logger.info("RMS grid model <%s> OK", gname)
logger.debug("RMS grid model <%s> OK", gname)
else:
raise ValueError(f"No such grid name present: {gname}")

if bwname in gmodel.blocked_wells_set:
bwset = gmodel.blocked_wells_set[bwname]
logger.info("Blocked well set <%s> OK", bwname)
logger.debug("Blocked well set <%s> OK", bwname)
else:
raise ValueError(f"No such blocked well set: {bwname}")

wnames = bwset.get_well_names()

logger.info("Lognames are %s", lnames)
logger.debug("Lognames are %s", lnames)

bwlist = []
logger.info("Loading wells ...")
logger.debug("Loading wells ...")
for wname in wnames:
logger.info("Loading well %s", wname)
logger.debug("Loading well %s", wname)
bwtmp = BlockedWell()
bwtmp.from_roxar(
rox.project,
Expand Down
2 changes: 1 addition & 1 deletion src/xtgeo/well/_well_aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import xtgeo
from xtgeo.common import XTGeoDialog
from xtgeo.common._xyz_enum import _AttrName

from ..xyz_common._xyz_enum import _AttrName
from . import _well_io

xtg = XTGeoDialog()
Expand Down
17 changes: 8 additions & 9 deletions src/xtgeo/well/_well_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import xtgeo
from xtgeo.common import XTGeoDialog

from ..xyz_common._xyz_enum import _AttrName
from xtgeo.common._xyz_enum import _AttrName, _AttrType

xtg = XTGeoDialog()

Expand Down Expand Up @@ -97,7 +96,7 @@ def import_rms_ascii(

logger.debug("Reading log name %s of type %s", lname, ltype)

if ltype == "DISC":
if ltype == _AttrType.DISC.value:
xdict = {int(rxv[i]): rxv[i + 1] for i in range(0, len(rxv), 2)}
wlogrecords[lname] = xdict
else:
Expand Down Expand Up @@ -232,7 +231,7 @@ def export_rms_ascii(self, wfile, precision=4):

# make the disc as is np.int
for lname in self.wlogtypes:
if self.wlogtypes[lname] == "DISC":
if self.wlogtypes[lname] == _AttrType.DISC.value:
tmpdf[[lname]] = tmpdf[[lname]].astype(int)

cformat = "%-." + str(precision) + "f"
Expand All @@ -249,7 +248,7 @@ def export_rms_ascii(self, wfile, precision=4):

def export_hdf5_well(self, wfile, compression="lzf"):
"""Save to HDF5 format."""
logger.info("Export to hdf5 format...")
logger.debug("Export to hdf5 format...")

self._ensure_consistency()

Expand All @@ -266,13 +265,13 @@ def export_hdf5_well(self, wfile, compression="lzf"):
complevel = 0

with pd.HDFStore(wfile.file, "w", complevel=complevel, complib=complib) as store:
logger.info("export to HDF5 %s", wfile.name)
logger.debug("export to HDF5 %s", wfile.name)
store.put("Well", self._wdata.data)
store.get_storer("Well").attrs["metadata"] = jmeta
store.get_storer("Well").attrs["provider"] = "xtgeo"
store.get_storer("Well").attrs["format_idcode"] = 1401

logger.info("Export to hdf5 format... done!")
logger.debug("Export to hdf5 format... done!")


def import_wlogs(wlogs: OrderedDict):
Expand All @@ -294,7 +293,7 @@ def import_wlogs(wlogs: OrderedDict):
for key in wlogs.keys():
typ, rec = wlogs[key]

if typ in {"DISC", "CONT"}:
if typ in {_AttrType.DISC.value, _AttrType.CONT.value}:
wlogtypes[key] = deepcopy(typ)
else:
raise ValueError(f"Invalid log type found in input: {typ}")
Expand All @@ -308,7 +307,7 @@ def import_wlogs(wlogs: OrderedDict):

def import_hdf5_well(wfile, **kwargs):
"""Load from HDF5 format."""
logger.info("The kwargs may be unused: %s", kwargs)
logger.debug("The kwargs may be unused: %s", kwargs)
reqattrs = xtgeo.MetaDataWell.REQUIRED

with pd.HDFStore(wfile.file, "r") as store:
Expand Down
Loading

0 comments on commit 0bbea16

Please sign in to comment.