Skip to content

Commit

Permalink
CLN: Import constants directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Feb 12, 2024
1 parent b55b25a commit 5bd5e34
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 86 deletions.
1 change: 0 additions & 1 deletion src/xtgeo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def _xprint(msg):

_xprint("Import various XTGeo modules... metadata...")


from xtgeo.roxutils import roxutils
from xtgeo.roxutils.roxutils import RoxUtils

Expand Down
33 changes: 16 additions & 17 deletions src/xtgeo/cube/_cube_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@
import segyio
from segyio import TraceField as TF

import xtgeo.common.calc as xcalc
import xtgeo.common.constants as const
import xtgeo.common.sys as xsys
from xtgeo import _cxtgeo
from xtgeo.common import XTGeoDialog, null_logger
from xtgeo.common import calc
from xtgeo.common.constants import UNDEF
from xtgeo.common.log import null_logger
from xtgeo.common.xtgeo_dialog import XTGeoDialog
from xtgeo.metadata.metadata import MetaDataRegularCube

if TYPE_CHECKING:
Expand Down Expand Up @@ -141,22 +142,22 @@ def _segy_all_traces_attributes(
traceidcodes = segyfile.attributes(trcode)[:].reshape(ncol, nrow)

# need positions in corners for making vectors to compute geometries
c1v = xcalc.ijk_to_ib(1, 1, 1, ncol, nrow, 1, forder=False)
c2v = xcalc.ijk_to_ib(ncol, 1, 1, ncol, nrow, 1, forder=False)
c3v = xcalc.ijk_to_ib(1, nrow, 1, ncol, nrow, 1, forder=False)
c1v = calc.ijk_to_ib(1, 1, 1, ncol, nrow, 1, forder=False)
c2v = calc.ijk_to_ib(ncol, 1, 1, ncol, nrow, 1, forder=False)
c3v = calc.ijk_to_ib(1, nrow, 1, ncol, nrow, 1, forder=False)

xori, yori, zori, zinc = _get_coordinate(segyfile, c1v)
point_x1, point_y1, _, _ = _get_coordinate(segyfile, c2v)
point_x2, point_y2, _, _ = _get_coordinate(segyfile, c3v)

slen1, _, rotation = xcalc.vectorinfo2(xori, point_x1, yori, point_y1)
slen1, _, rotation = calc.vectorinfo2(xori, point_x1, yori, point_y1)
xinc = slen1 / (ncol - 1)

slen2, _, _ = xcalc.vectorinfo2(xori, point_x2, yori, point_y2)
slen2, _, _ = calc.vectorinfo2(xori, point_x2, yori, point_y2)
yinc = slen2 / (nrow - 1)

# find YFLIP by cross products
yflip = xcalc.find_flip(
yflip = calc.find_flip(
(point_x1 - xori, point_y1 - yori, 0), (point_x2 - xori, point_y2 - yori, 0)
)

Expand Down Expand Up @@ -207,7 +208,7 @@ def _import_segy_incomplete_traces(segyfile: segyio.segy.SegyFile) -> dict:
nrow = int(abs(xlines_case.min() - xlines_case.max()) / xspacing) + 1
nlay = data.shape[1]

values = np.full((ncol, nrow, nlay), const.UNDEF, dtype=np.float32)
values = np.full((ncol, nrow, nlay), UNDEF, dtype=np.float32)
traceidcodes = np.full((ncol, nrow), 2, dtype=np.int64)

ilines_shifted = (ilines_case / ispacing).astype(np.int64)
Expand Down Expand Up @@ -327,19 +328,17 @@ def _geometry_incomplete_traces(
jl1x, jl1y, _, _ = _get_coordinate(segyfile, jnd1)
jl2x, jl2y, _, _ = _get_coordinate(segyfile, jnd2)

xslen, _, rot1 = xcalc.vectorinfo2(il1x, il2x, il1y, il2y)
xslen, _, rot1 = calc.vectorinfo2(il1x, il2x, il1y, il2y)
xinc = ispacing * xslen / (abs(ilines_case[ind1] - ilines_case[ind2]))
yslen, _, _ = xcalc.vectorinfo2(jl1x, jl2x, jl1y, jl2y)
yslen, _, _ = calc.vectorinfo2(jl1x, jl2x, jl1y, jl2y)
yinc = xspacing * yslen / (abs(xlines_case[jnd1] - xlines_case[jnd2]))

yflip = xcalc.find_flip(
(il2x - il1x, il2y - il1y, 0), (jl2x - jl1x, jl2y - jl1y, 0)
)
yflip = calc.find_flip((il2x - il1x, il2y - il1y, 0), (jl2x - jl1x, jl2y - jl1y, 0))

# need to compute xori and yori from 'case' I J indices with known x y and
# (iline, xline); use ind1 with assosiated coordinates il1x il1y
i_use, j_use = reverseindex_full[index_case[ind1]]
xori, yori = xcalc.xyori_from_ij(
xori, yori = calc.xyori_from_ij(
i_use, j_use, il1x, il1y, xinc, yinc, ncol, nrow, yflip, rot1
)

Expand Down Expand Up @@ -613,7 +612,7 @@ def import_xtgregcube(mfile, values=True):
# although we do not support initializing with any other value.
# As xtgeo-format is only written/read by xtgeo as far as we know, this should
# be unproblematic for now.
if results.pop("undef", None) != const.UNDEF:
if results.pop("undef", None) != UNDEF:
raise ValueError(
f"File {mfile.file} has non-standard undef, not supported by xtgeo"
)
Expand Down
6 changes: 3 additions & 3 deletions src/xtgeo/cube/_cube_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import numpy as np

import xtgeo.common.constants as const
from xtgeo import _cxtgeo
from xtgeo._cxtgeo import XTGeoCLibError
from xtgeo.common import null_logger
from xtgeo.common.calc import _swap_axes
from xtgeo.common.constants import UNDEF_LIMIT
from xtgeo.common.log import null_logger
from xtgeo.xyz.polygons import Polygons

logger = null_logger(__name__)
Expand Down Expand Up @@ -264,7 +264,7 @@ def get_randomline(
option,
)

values[values > const.UNDEF_LIMIT] = np.nan
values[values > UNDEF_LIMIT] = np.nan
arr = values.reshape((xcoords.shape[0], nzsam)).T

return (hcoords[0], hcoords[-1], zmin, zmax, arr)
Expand Down
7 changes: 4 additions & 3 deletions src/xtgeo/cube/cube1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import deprecation
import numpy as np

import xtgeo.common.constants as const
from xtgeo.common import XTGDescription, null_logger
from xtgeo.common.constants import UNDEF
from xtgeo.common.log import null_logger
from xtgeo.common.sys import generic_hash
from xtgeo.common.types import Dimensions
from xtgeo.common.version import __version__
from xtgeo.common.xtgeo_dialog import XTGDescription
from xtgeo.grid3d.grid import grid_from_cube
from xtgeo.io._file import FileFormat, FileWrapper
from xtgeo.metadata.metadata import MetaDataRegularCube
Expand Down Expand Up @@ -278,7 +279,7 @@ def _reset(
else:
self._traceidcodes = traceidcodes
self._segyfile = segyfile
self.undef = const.UNDEF
self.undef = UNDEF

self._metadata = MetaDataRegularCube()
self._metadata.required = self
Expand Down
5 changes: 2 additions & 3 deletions src/xtgeo/io/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from typing import TYPE_CHECKING, Literal, Union

import xtgeo._cxtgeo
from xtgeo.common import null_logger

logger = null_logger(__name__)
from xtgeo.common.log import null_logger

if TYPE_CHECKING:
from xtgeo.common.types import FileLike
Expand All @@ -42,6 +40,7 @@
Wells,
]

logger = null_logger(__name__)

VALID_FILE_ALIASES = ["$fmu-v1", "$md5sum", "$random"]

Expand Down
10 changes: 5 additions & 5 deletions src/xtgeo/metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"""

import xtgeo
import xtgeo.common.constants as const
from xtgeo.common import null_logger
from xtgeo.common.constants import UNDEF
from xtgeo.common.log import null_logger

logger = null_logger(__name__)

Expand Down Expand Up @@ -110,7 +110,7 @@ def description(self, newstr):
raise ValueError("The description length must less or equal 64 letters.")
invalids = r"/$<>[]:\&%"
if set(invalids).intersection(newstr):
raise ValueError("The description constains invalid characters such as /.")
raise ValueError("The description contains invalid characters such as /.")

self._description = newstr

Expand Down Expand Up @@ -235,7 +235,7 @@ class MetaDataRegularSurface(MetaData):
"yinc": 1.0,
"yflip": 1,
"rotation": 0.0,
"undef": const.UNDEF,
"undef": UNDEF,
}

def __init__(self):
Expand Down Expand Up @@ -282,7 +282,7 @@ class MetaDataRegularCube(MetaData):
"yflip": 1,
"zflip": 1,
"rotation": 0.0,
"undef": const.UNDEF,
"undef": UNDEF,
}

def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion src/xtgeo/roxutils/_roxutils_etc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Private module for etc functions"""

import contextlib

with contextlib.suppress(ImportError):
import roxar

from xtgeo.common import null_logger
from xtgeo.common.log import null_logger

logger = null_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/xtgeo/well/_blockedwell_roxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import numpy.ma as npma
import pandas as pd

from xtgeo.common import null_logger
from xtgeo.common._xyz_enum import _AttrName, _AttrType
from xtgeo.common.constants import INT_MIN
from xtgeo.common.exceptions import WellNotFoundError
from xtgeo.common.log import null_logger
from xtgeo.roxutils import RoxUtils

try:
Expand Down
3 changes: 2 additions & 1 deletion src/xtgeo/well/_blockedwells_roxapi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Well input and output, private module for ROXAPI"""

from xtgeo.common import XTGeoDialog, null_logger
from xtgeo.common.log import null_logger
from xtgeo.common.xtgeo_dialog import XTGeoDialog
from xtgeo.roxutils import RoxUtils

from .blocked_well import blockedwell_from_roxar
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 @@ -13,8 +13,8 @@

import pandas as pd

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

from . import _well_io
Expand Down
2 changes: 1 addition & 1 deletion src/xtgeo/well/_well_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import numpy as np
import pandas as pd

from xtgeo.common import null_logger
from xtgeo.common._xyz_enum import _AttrName, _AttrType
from xtgeo.common.log import null_logger
from xtgeo.metadata.metadata import MetaDataWell

logger = null_logger(__name__)
Expand Down
23 changes: 12 additions & 11 deletions src/xtgeo/well/_well_oper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import pandas as pd

from xtgeo import _cxtgeo
from xtgeo.common import constants as const, null_logger
from xtgeo.common._xyz_enum import _AttrType
from xtgeo.common.constants import UNDEF_INT, UNDEF_INT_LIMIT
from xtgeo.common.log import null_logger
from xtgeo.common.sys import _get_carray
from xtgeo.xyz.points import Points

Expand Down Expand Up @@ -122,7 +123,7 @@ def make_zone_qual_log(self, zqname):
else:
prev_ = seq[ind - 1]
next_ = seq[ind + 1]
if prev_ > const.UNDEF_INT_LIMIT or next_ > const.UNDEF_INT_LIMIT:
if prev_ > UNDEF_INT_LIMIT or next_ > UNDEF_INT_LIMIT:
code.append(9)
elif next_ > iseq > prev_:
code.append(1)
Expand Down Expand Up @@ -357,32 +358,32 @@ def report_zonation_holes(self, threshold=5):
xvv = self._wdata.data[self.xname].values
yvv = self._wdata.data[self.yname].values
zvv = self._wdata.data[self.zname].values
zlog[np.isnan(zlog)] = const.UNDEF_INT
zlog[np.isnan(zlog)] = UNDEF_INT

ncv = 0
first = True
hole = False
for ind, zone in np.ndenumerate(zlog):
ino = ind[0]
if zone > const.UNDEF_INT_LIMIT and first:
if zone > UNDEF_INT_LIMIT and first:
continue

if zone < const.UNDEF_INT_LIMIT and first:
if zone < UNDEF_INT_LIMIT and first:
first = False
continue

if zone > const.UNDEF_INT_LIMIT:
if zone > UNDEF_INT_LIMIT:
ncv += 1
hole = True

if zone > const.UNDEF_INT_LIMIT and ncv > threshold:
if zone > UNDEF_INT_LIMIT and ncv > threshold:
logger.debug("Restart first (bigger hole)")
hole = False
first = True
ncv = 0
continue

if hole and zone < const.UNDEF_INT_LIMIT and ncv <= threshold:
if hole and zone < UNDEF_INT_LIMIT and ncv <= threshold:
# here we have a hole that fits criteria
if mdlog is not None:
entry = (
Expand All @@ -403,7 +404,7 @@ def report_zonation_holes(self, threshold=5):
hole = False
ncv = 0

if hole and zone < const.UNDEF_INT_LIMIT and ncv > threshold:
if hole and zone < UNDEF_INT_LIMIT and ncv > threshold:
hole = False
ncv = 0

Expand Down Expand Up @@ -531,11 +532,11 @@ def _get_bseries_by_distance(depth, inseries, distance):

bseries = pd.Series(np.zeros(inseries.values.size), dtype="int32").values
try:
inseries = np.nan_to_num(inseries.values, nan=const.UNDEF_INT).astype("int32")
inseries = np.nan_to_num(inseries.values, nan=UNDEF_INT).astype("int32")
except TypeError:
# for older numpy version
inseries = inseries.values
inseries[np.isnan(inseries)] = const.UNDEF_INT
inseries[np.isnan(inseries)] = UNDEF_INT
inseries = inseries.astype("int32")

res = _cxtgeo.well_mask_shoulder(
Expand Down
22 changes: 14 additions & 8 deletions src/xtgeo/well/_wellmarkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import numpy as np
import pandas as pd

import xtgeo.common.constants as const
from xtgeo import _cxtgeo
from xtgeo.common import null_logger
from xtgeo.common.constants import (
UNDEF,
UNDEF_DISC,
UNDEF_INT,
UNDEF_INT_LIMIT,
UNDEF_LIMIT,
)
from xtgeo.common.log import null_logger
from xtgeo.xyz.points import Points

logger = null_logger(__name__)
Expand All @@ -27,7 +33,7 @@ def get_zonation_points(self, tops, incl_limit, top_prefix, zonelist, use_undef)
if use_undef:
dataframe.dropna(subset=[scopy.zonelogname], inplace=True)
zlog = dataframe[scopy.zonelogname].values
zlog[np.isnan(zlog)] = const.UNDEF_DISC
zlog[np.isnan(zlog)] = UNDEF_DISC
zlog = np.rint(zlog).astype(int)
else:
return None
Expand Down Expand Up @@ -139,8 +145,8 @@ def _extract_ztops(
f" was {usezonerange}"
)

iundef = const.UNDEF_INT
iundeflimit = const.UNDEF_INT_LIMIT
iundef = UNDEF_INT
iundeflimit = UNDEF_INT_LIMIT
pzone = iundef

if use_undef:
Expand Down Expand Up @@ -382,7 +388,7 @@ def get_fraction_per_zone(
if dseries.size < count_limit: # interval too short for fraction
logger.debug("Skipped due to too few values %s", dseries.size)
continue
if dseries.max() > const.UNDEF_INT_LIMIT:
if dseries.max() > UNDEF_INT_LIMIT:
logger.debug("Skipped due to too missing/undef value(s)")
continue

Expand Down Expand Up @@ -422,7 +428,7 @@ def get_surface_picks(self, surf):
if self.mdlogname:
mcor = dataframe[self.mdlogname].values
else:
mcor = np.zeros(xcor.size, dtype=np.float64) + const.UNDEF
mcor = np.zeros(xcor.size, dtype=np.float64) + UNDEF

nval, xres, yres, zres, mres, dres = _cxtgeo.well_surf_picks(
xcor,
Expand All @@ -448,7 +454,7 @@ def get_surface_picks(self, surf):
if nval > 0:
poi = Points()

mres[mres > const.UNDEF_LIMIT] = np.nan
mres[mres > UNDEF_LIMIT] = np.nan

res = {}
res[poi.xname] = xres[:nval]
Expand Down
Loading

0 comments on commit 5bd5e34

Please sign in to comment.