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_avg_surface2(loadsfile1):
cube1 = loadsfile1
surf1 = xtgeo.surface_from_cube(cube1, 2540.0)
surf2 = xtgeo.surface_from_cube(cube1, 2548.0)
# values taken from IB spreadsheet but not variance
# http://www.alcula.com/calculators/statistics/variance/ --> 45.1597
attributes = {
"mean": 176.438,
"var": 22.5797,
}
attrs = surf1.slice_cube_window(
cube1,
other=surf2,
other_position="below",
attribute=list(attributes.keys()),
sampling="discrete",
1007: -226.576,
1097.9: -90,
1421.9: 121.104,
}
chks["trilinear"] = {
1007: -228.49601,
1098: -87.6320,
1422: 123.9200,
}
methods = ["nearest", "trilinear"]
for method in methods:
for tslice, tval in chks[method].items():
surf1 = xtgeo.surface_from_cube(cube1, tslice)
surf1.slice_cube(cube1, sampling=method, snapxy=True)
assert surf1.values.mean() == pytest.approx(tval, abs=1e-3)
def test_avg_surface2(loadsfile1):
cube1 = loadsfile1
surf1 = xtgeo.surface_from_cube(cube1, 2540.0)
surf2 = xtgeo.surface_from_cube(cube1, 2548.0)
# values taken from IB spreadsheet but not variance
# http://www.alcula.com/calculators/statistics/variance/ --> 45.1597
attributes = {
"mean": 176.438,
"var": 22.5797,
}
attrs = surf1.slice_cube_window(
cube1,
other=surf2,
other_position="below",
attribute=list(attributes.keys()),
sampling="discrete",
snapxy=True,
def test_single_slice_yflip_positive_snapxy(loadsfile1):
cube1 = loadsfile1
cube1.swapaxes()
samplings = ["nearest", "trilinear"]
for sampling in samplings:
surf1 = xtgeo.surface_from_cube(cube1, 1000.0)
surf1.slice_cube(cube1, sampling=sampling, snapxy=True)
assert surf1.values.mean() == pytest.approx(cube1.values[0, 0, 0], abs=0.01)
print(surf1.values.mean())
print(cube1.values[0, 0, 0])
def test_slice_nearest_snapxy(load_cube_rsgy1):
"""Slice a cube with a surface, nearest node, snapxy, algorithm 1 + 2"""
kube = load_cube_rsgy1
xs1 = xtgeo.surface_from_cube(kube, 1670)
xs2 = xtgeo.surface_from_cube(kube, 1670)
t1 = xtg.timer()
xs1.slice_cube(kube, algorithm=1, snapxy=True)
logger.info("Slicing alg 1...done in {} seconds".format(xtg.timer(t1)))
t1 = xtg.timer()
xs2.slice_cube(kube, algorithm=2, snapxy=True)
logger.info("Slicing alg 2...done in {} seconds".format(xtg.timer(t1)))
xs1.quickplot(
filename=td + "/surf_slice_cube_near_snapxy_v1.png",
colortable="seismic",
minmax=(-1, 1),
title="Reek",
infotext="Method: nearest, snapxy, algorithm 1",
)
def _slice_cube_v2_resample(
self, cube, zsurf=None, sampling="nearest", mask=True, deadtraces=True
):
"""Slicing with surfaces that not match the cube geometry, snapxy=False
The idea here is to resample the surface to the cube, then afterwards
do an inverse sampling
"""
scube = xtgeo.surface_from_cube(cube, 0)
if self.compare_topology(scube, strict=False):
return _slice_cube_v2(self, cube, zsurf, sampling, mask, deadtraces)
scube.resample(self)
zcube = None
if zsurf:
zcube = scube.copy()
zcube.resample(zsurf)
istat = _slice_cube_v2(
scube,
cube=cube,
zsurf=zcube,
sampling=sampling,
other,
other_position,
sampling,
mask,
zrange,
ndiv,
attribute,
maskthreshold,
showprogress,
deadtraces,
):
"""Makes a resample from origonal surfaces first to fit cube topology"""
logger.info("Attributes between surfaces, resampling version")
scube = xtgeo.surface_from_cube(cube, 0.0)
scube.resample(self)
szsurf = None
if zsurf:
szsurf = scube.copy()
szsurf.resample(zsurf)
sother = None
if other:
sother = scube.copy()
sother.resample(other)
attrs = _slice_cube_window(
scube,
cube,
def attribute_around_constant_cube_slices():
"""Get attribute around a constant cube slices"""
cubefile = join(EXPATH1, "ib_test_cube2.segy")
level1 = 1010
level2 = 1100
mycube = xtgeo.cube_from_file(cubefile)
# instead of using zrange, we make some tmp surfaces that
# reflects the assymmetric; here sample slices from cube
sabove = xtgeo.surface_from_cube(mycube, level1)
sbelow = xtgeo.surface_from_cube(mycube, level2)
if DEBUG:
sabove.describe()
sbelow.describe()
attrs = "all"
myattrs = sabove.slice_cube_window(
mycube, attribute=attrs, sampling="trilinear", zsurf=sabove, other=sbelow
)
for attr in myattrs.keys():
if DEBUG:
myattrs[attr].describe()
myattrs[attr].to_file("myfile_constlevels_" + attr + ".dat", fformat="ijxyz")