Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_import_init():
"""Import INIT Reek"""
g = Grid()
g.from_file(GFILE1, fformat="egrid")
x = GridProperties()
names = ['PORO', 'PORV']
x.from_file(IFILE1, fformat="init",
names=names, grid=g)
# get the object
poro = x.get_prop_by_name('PORO')
logger.info("PORO avg {}".format(poro.values.mean()))
porv = x.get_prop_by_name('PORV')
logger.info("PORV avg {}".format(porv.values.mean()))
assert poro.values.mean() == pytest.approx(0.1677402, abs=0.00001)
# -*- coding: utf-8 -*-
from os.path import join
import pytest
import xtgeo
xtg = xtgeo.common.XTGeoDialog()
logger = xtg.basiclogger(__name__)
if not xtg.testsetup():
raise SystemExit("Cannot find test setup")
TMD = xtg.tmpdir
TPATH = xtg.testpath
SFILE1 = join(TPATH, "cubes/etc/ib_synth_iainb.segy")
# ======================================================================================
# This is a a set of tests towards a synthetic small cube made by I Bush in order to
# test all attributes in detail
# ======================================================================================
# coding: utf-8
from __future__ import division, absolute_import
from __future__ import print_function
import os
from os.path import join
import io
import threading
import pytest
import xtgeo
from xtgeo.common import XTGeoDialog
import test_common.test_xtg as tsetup
xtg = XTGeoDialog()
logger = xtg.basiclogger(__name__)
if not xtg.testsetup():
raise SystemExit
TMPD = xtg.tmpdir
TPATH = xtg.testpath
XTGSHOW = False
if "XTG_SHOW" in os.environ:
XTGSHOW = True
# =============================================================================
# Do tests
# =============================================================================
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import
from __future__ import print_function
from os.path import join
import pytest
import xtgeo
xtg = xtgeo.common.XTGeoDialog()
logger = xtg.basiclogger(__name__)
if not xtg.testsetup():
raise SystemExit
TMPDIR = xtg.tmpdir
TESTPATH = xtg.testpath
WFILE = join(TESTPATH, "wells/battle/1/WELLX.rmswell")
SFILE = join(TESTPATH, "surfaces/etc/battle_1330.gri")
def test_get_well_x_surf():
"""Getting XYZ, MD for well where crossing a surface"""
wll = xtgeo.Well(WFILE, mdlogname="Q_MDEPTH")
# coding: utf-8
from __future__ import division, absolute_import
from __future__ import print_function
import os
import numpy as np
import xtgeo
from xtgeo.common import XTGeoDialog
import test_common.test_xtg as tsetup
xtg = XTGeoDialog()
logger = xtg.basiclogger(__name__)
if not xtg.testsetup():
raise SystemExit
TMPDIR = xtg.tmpdir
TESTPATH = xtg.testpath
DUALFILE1 = "../xtgeo-testdata/3dgrids/etc/TEST_DP"
DUALFILE2 = "../xtgeo-testdata/3dgrids/etc/TEST_DPDK" # dual poro + dual perm oil/water
DUALFILE3 = "../xtgeo-testdata/3dgrids/etc/TEST2_DPDK_WG" # aa but gas/water
# =============================================================================
# Do tests
# =============================================================================
def test_get_well_x_surf():
"""Getting XYZ, MD for well where crossing a surface"""
wll = xtgeo.Well(WFILE, mdlogname="Q_MDEPTH")
surf = xtgeo.RegularSurface(SFILE)
top = wll.get_surface_picks(surf)
assert top.dataframe.Q_MDEPTH[5] == pytest.approx(5209.636860, abs=0.001)
def test_get_regsurfi():
sfile = TESTSET1
with open(sfile, "rb") as fin:
stream = io.BytesIO(fin.read())
logger.info("File is %s", sfile)
for _itmp in range(20):
rf = xtgeo.RegularSurface(stream, fformat="irap_binary")
assert abs(rf.values.mean() - 1698.648) < 0.01
print(_itmp)
def test_petromodbin_import_export():
"""Import Petromod PDM binary example."""
logger.info("Import and export...")
petromod = xtgeo.RegularSurface(TESTSET6A)
irapbin = xtgeo.RegularSurface(TESTSET6B)
assert petromod.ncol == irapbin.ncol
assert petromod.nrow == irapbin.nrow
assert petromod.values1d[200000] == irapbin.values1d[200000]
testfile = os.path.join(TMPD, "petromod.pmd")
petromod.to_file(testfile, fformat="petromod")
petromod_again = xtgeo.RegularSurface(testfile)
assert petromod_again.values1d[200000] == irapbin.values1d[200000]
# test with roation 0 and rotation origins 0
petromod = xtgeo.RegularSurface(TESTSET6C)
assert petromod.ncol == irapbin.ncol
assert petromod.nrow == irapbin.nrow
assert petromod.values1d[200000] == irapbin.values1d[200000]
testfile = os.path.join(TMPD, "petromod_other_units.pmd")
def test_operator_overload():
"""Test operations between two surface in different ways"""
surf1 = xtgeo.RegularSurface(ncol=100, nrow=50, rotation=10, values=100)
assert surf1.values.mean() == 100.0
id1 = id(surf1)
id1v = id(surf1.values)
surf2 = xtgeo.RegularSurface(ncol=100, nrow=50, rotation=0, values=100)
diff = surf1 - surf2
assert id(diff) != id1
assert diff.values.mean() == 0.0
assert id(surf1) == id1
surf1 += diff
assert id(surf1) == id1
assert id(surf1.values) == id1v
surf1 /= diff
assert (surf1.values.count()) == 0
def test_xtgeo():
stream = io.BytesIO()
surface = xtgeo.RegularSurface()
surface.to_file(stream)
print("XTGeo succeeded")