Skip to content

Commit

Permalink
fixup: testing with old
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Jan 13, 2025
1 parent b4bd808 commit 7e900f6
Showing 1 changed file with 11 additions and 104 deletions.
115 changes: 11 additions & 104 deletions tests/test_internal/test_regsurf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,11 @@

import xtgeo
import xtgeo._internal as _internal # type: ignore
from xtgeo.common.log import functimer, null_logger
from xtgeo.common.log import null_logger

logger = null_logger(__name__)


@pytest.fixture(scope="module", name="get_drogondata")
def fixture_get_drogondata(testdata_path):
grid = xtgeo.grid_from_file(f"{testdata_path}/3dgrids/drogon/2/geogrid.roff")
poro = xtgeo.gridproperty_from_file(
f"{testdata_path}/3dgrids/drogon/2/geogrid--phit.roff"
)
facies = xtgeo.gridproperty_from_file(
f"{testdata_path}/3dgrids/drogon/2/geogrid--facies.roff"
)

surf = xtgeo.surface_from_file(
f"{testdata_path}/surfaces/drogon/1/01_topvolantis.gri"
)
return grid, poro, facies, surf


def test_find_cell_range_simple_norotated():
surf = xtgeo.RegularSurface(
xori=0, yori=0, xinc=1, yinc=2, ncol=3, nrow=4, rotation=0
Expand Down Expand Up @@ -214,97 +198,20 @@ def test_get_xy_from_ij():
assert point.y == pytest.approx(4.4641016151)


@pytest.mark.parametrize(
"x, y, rotation, expected",
[
(2.746, 1.262, 0, 17.73800),
(2.096, 4.897, 0, 17.473),
(2.746, 2.262, 0, np.nan),
(1.9999999999, 1.999999999, 0, 14.0),
(1999, 1999, 0, np.nan), # far outside
(2.746, 1.262, 10, 18.3065),
(2.096, 4.897, 10, 21.9457),
(2.746, 1.262, 20, 18.319),
(2.096, 4.897, 20, 25.751),
(-0.470, -3.354, 210, np.nan),
(-0.013, -5.148, 210, 19.963), # rms gets 19.959
(-1.433, -5.359, 210, 27.448), # rms gets 27.452
],
)
def test_get_z_from_xy_simple(x, y, rotation, expected):
"""Test values are manually verified by inspection in RMS"""
values = np.array(range(30)).reshape(5, 6).astype(float)

values[2, 3] = np.nan
values[4, 5] = np.nan

surf = xtgeo.RegularSurface(
xori=0, yori=0, xinc=1, yinc=1, ncol=5, nrow=6, rotation=rotation, values=values
@pytest.fixture(scope="module", name="get_drogondata")
def fixture_get_drogondata(testdata_path):
grid = xtgeo.grid_from_file(f"{testdata_path}/3dgrids/drogon/2/geogrid.roff")
poro = xtgeo.gridproperty_from_file(
f"{testdata_path}/3dgrids/drogon/2/geogrid--phit.roff"
)

z_value = _internal.regsurf.get_z_from_xy(
x,
y,
surf.xori,
surf.yori,
surf.xinc,
surf.yinc,
surf.ncol,
surf.nrow,
surf.rotation,
surf.values,
facies = xtgeo.gridproperty_from_file(
f"{testdata_path}/3dgrids/drogon/2/geogrid--facies.roff"
)

if np.isnan(expected):
assert np.isnan(z_value)
else:
assert z_value == pytest.approx(expected, abs=0.001)


@functimer
def test_get_z_from_xy(get_drogondata):
_, _, _, srf = get_drogondata

surf = srf.copy()

z_value = _internal.regsurf.get_z_from_xy(
460103.00,
5934855.00,
surf.xori,
surf.yori,
surf.xinc,
surf.yinc,
surf.ncol,
surf.nrow,
surf.rotation,
surf.values,
surf = xtgeo.surface_from_file(
f"{testdata_path}/surfaces/drogon/1/01_topvolantis.gri"
)

assert z_value == pytest.approx(1594.303, abs=0.001)

# make ntimes random points and check the time (cf. @functimer with debug logging)
ntimes = 100000
xmin = 458000
xmax = 468000
ymin = 5927000
ymax = 5938000
logger.debug("Start random points loop... %s", ntimes)
for _ in range(ntimes):
x = np.random.uniform(xmin, xmax)
y = np.random.uniform(ymin, ymax)
_internal.regsurf.get_z_from_xy(
x,
y,
surf.xori,
surf.yori,
surf.xinc,
surf.yinc,
surf.ncol,
surf.nrow,
surf.rotation,
surf.values,
)
logger.debug("End random points loop")
return grid, poro, facies, surf


def test_sample_grid3d_layer(get_drogondata):
Expand Down

0 comments on commit 7e900f6

Please sign in to comment.