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_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")
def test_slice_trilinear_nosnapxy(load_cube_rsgy1):
"""Slice a cube with a surface, nearest node, algorithm 1 + 2, other map layout"""
kube = load_cube_rsgy1
# kube.swapaxes()
xs1 = xtgeo.RegularSurface(
yori=5927600, xori=457000, xinc=50, yinc=50, ncol=200, nrow=220, values=1670
)
xs2 = xs1.copy()
t1 = xtg.timer()
xs1.slice_cube(kube, algorithm=1, snapxy=False, sampling="trilinear")
logger.info("Slicing alg 1...done in {} seconds".format(xtg.timer(t1)))
t1 = xtg.timer()
xs2.slice_cube(kube, algorithm=2, snapxy=False, sampling="trilinear")
logger.info("Slicing alg 2...done in {} seconds".format(xtg.timer(t1)))
xs1.quickplot(
filename=td + "/surf_slice_cube_tri_nosnapxy_v1.png",
colortable="seismic",
minmax=(-1, 1),
def save_surface(fns, statistic) -> io.BytesIO:
surfaces = xtgeo.Surfaces(fns)
if len(surfaces.surfaces) == 0:
surface = xtgeo.RegularSurface()
elif statistic == "Mean":
surface = surfaces.apply(np.nanmean, axis=0)
elif statistic == "StdDev":
surface = surfaces.apply(np.nanstd, axis=0)
elif statistic == "Min":
surface = surfaces.apply(np.nanmin, axis=0)
elif statistic == "Max":
surface = surfaces.apply(np.nanmax, axis=0)
elif statistic == "P10":
surface = surfaces.apply(np.nanpercentile, 10, axis=0)
elif statistic == "P90":
surface = surfaces.apply(np.nanpercentile, 90, axis=0)
else:
surface = xtgeo.RegularSurface()
return io.BytesIO(surface_to_json(surface).encode())
If they are already created, the no need to recreate
"""
if "onegrid" not in self._tmp or force:
logger.info("Make a tmp onegrid instance...")
self._tmp["onegrid"] = self.copy()
self._tmp["onegrid"].reduce_to_one_layer()
one = self._tmp["onegrid"]
logger.info("Make a tmp onegrid instance... DONE")
logger.info("Make a set of tmp surfaces for I J locations + depth...")
self._tmp["topd"] = xtgeo.RegularSurface()
self._tmp["topi"], self._tmp["topj"] = self._tmp["topd"].from_grid3d(
one, where="top", rfactor=4
)
self._tmp["basd"] = xtgeo.RegularSurface()
self._tmp["basi"], self._tmp["basj"] = self._tmp["basd"].from_grid3d(
one, where="base", rfactor=4
)
self._tmp["topi"].fill()
self._tmp["topj"].fill()
self._tmp["basi"].fill()
self._tmp["basj"].fill()
self._tmp["topi_carr"] = rl.get_carr_double(self._tmp["topi"])
self._tmp["topj_carr"] = rl.get_carr_double(self._tmp["topj"])
self._tmp["basi_carr"] = rl.get_carr_double(self._tmp["basi"])
self._tmp["basj_carr"] = rl.get_carr_double(self._tmp["basj"])
logger.info("Make a set of tmp surfaces for I J locations + depth... DONE")
else:
def surface_from_json(surfaceobj):
return xtgeo.RegularSurface(**json.loads(surfaceobj))