def test_slice_trilinear_snapxy(tmpdir, load_cube_rsgy1):
    """Slice a cube with a surface, trilinear, 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, sampling="trilinear")
    logger.info("Slicing alg 1...done in {} seconds".format(xtg.timer(t1)))

    t1 = xtg.timer()
    xs2.slice_cube(kube, algorithm=2, snapxy=True, sampling="trilinear")
    logger.info("Slicing alg 2...done in {} seconds".format(xtg.timer(t1)))

    xs1.quickplot(
        filename=join(tmpdir, "surf_slice_cube_tri_snapxy_v1.png"),
        colortable="seismic",
        minmax=(-1, 1),
        title="Reek",
        infotext="Method: trilinear, snapxy, algorithm 1",
    )

    xs2.quickplot(
        filename=join(tmpdir, "surf_slice_cube_tri_snapxy_v2.png"),
        colortable="seismic",
        minmax=(-1, 1),
        title="Reek",
        infotext="Method: trilinear, snapxy, algorithm 2",
    )

    logger.info("%s vs %s", xs1.values.mean(), xs2.values.mean())
    tsetup.assert_almostequal(xs1.values.mean(), xs2.values.mean(), 0.0001)
示例#2
0
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,
        ndiv=None,
        algorithm=2,
    )

    for name in attributes.keys():
        assert attributes[name] == pytest.approx(attrs[name].values.mean(),
                                                 abs=0.001)
示例#3
0
def attribute_around_constant_cube_slices():
    """Get attribute around a constant cube slices"""

    cubefile = 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(TMPDIR / ("myfile_constlevels_" + attr + ".dat"),
                              fformat="ijxyz")
示例#4
0
def test_avg_surface(loadsfile1):
    cube1 = loadsfile1
    surf1 = xtgeo.surface_from_cube(cube1, 1100.0)
    surf2 = xtgeo.surface_from_cube(cube1, 2900.0)

    # values taken from IB spreadsheet except variance
    attributes = {
        "min": -85.2640,
        "max": 250.0,
        "rms": 196.571,
        "mean": 157.9982,
        "var": 13676.7175,
        "sumneg": -2160.80,
        "sumpos": 73418,
        "meanabs": 167.5805,
        "meanpos": 194.7427,
        "meanneg": -29.2,
        "maxneg": -85.264,
        "maxpos": 250.0,
    }

    attrs = surf1.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute=list(attributes.keys()),
        sampling="cube",
        snapxy=True,
        ndiv=None,
        algorithm=2,
        showprogress=False,
    )

    for name in attributes.keys():
        print(attrs[name].values.mean())
        assert attributes[name] == pytest.approx(attrs[name].values.mean(),
                                                 abs=0.001)

    attrs = surf1.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute=list(attributes.keys()),
        sampling="trilinear",
        snapxy=True,
        ndiv=None,
        algorithm=2,
    )

    # less strict abs using relative 1%:
    for name in attributes.keys():
        assert attributes[name] == pytest.approx(attrs[name].values.mean(),
                                                 rel=0.01)
示例#5
0
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,
        mask=mask,
        deadtraces=deadtraces,
    )

    # sample back
    self.resample(scube, mask=mask)

    return istat
def test_cube_slice_w_dead_traces_trilinear():
    """Get cube slice trilinear aka Auto4D input, with scrambled data with
    dead traces to be ignored, various YFLIP cases."""

    cube1 = Cube(xcub2)

    surf1 = xtgeo.surface_from_cube(cube1, 1000.0)

    cells = [(18, 12)]

    surf1.slice_cube(cube1, sampling='trilinear', snapxy=True, deadtraces=True)
    plotfile = ojn(td, 'slice_tri1_dead.png')
    title = 'Cube with dead traces; trilinear; UNDEF at dead traces'
    surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title)

    ndead = (cube1.traceidcodes == 2).sum()

    for cell in cells:
        icell, jcell = cell
        assert surf1.values[icell, jcell] == \
            pytest.approx(cube1.values[icell, jcell, 0], 0.1)
    assert ma.count_masked(surf1.values) == ndead

    # swap cube only
    surf2 = surf1.copy()
    surf2.values = 1000.0
    cube2 = cube1.copy()
    cube2.swapaxes()
    surf2.slice_cube(cube2, sampling='trilinear', deadtraces=True)
    plotfile = ojn(td, 'slice_tri1__dead_cubeswap.png')
    surf2.quickplot(filename=plotfile, minmax=(-10000, 10000))
    assert ma.count_masked(surf2.values) == ndead
    assert surf2.values.mean() == surf1.values.mean()
示例#7
0
def test_single_slice_yflip_snapxy_both2(loadsfile1):
    """Test cube values with vertically interpolated location of maps"""
    cube1 = loadsfile1

    # checks are from spreadsheet ib_synth_iainb.odf under testdata
    chks = {}
    chks["nearest"] = {
        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_cube_slice_w_dead_traces_trilinear(tmpdir):
    """Get cube slice trilinear aka Auto4D input, with scrambled data with
    dead traces to be ignored, various YFLIP cases."""

    cube1 = Cube(XCUB2)

    surf1 = xtgeo.surface_from_cube(cube1, 1000.0)

    cells = [(18, 12)]

    surf1.slice_cube(cube1, sampling="trilinear", snapxy=True, deadtraces=True)
    plotfile = join(tmpdir, "slice_tri1_dead.png")
    title = "Cube with dead traces; trilinear; UNDEF at dead traces"
    surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title)

    ndead = (cube1.traceidcodes == 2).sum()

    for cell in cells:
        icell, jcell = cell
        assert surf1.values[icell, jcell] == pytest.approx(
            cube1.values[icell, jcell, 0], 0.1
        )
    assert ma.count_masked(surf1.values) == ndead

    # swap cubes and map
    surf2 = surf1.copy()
    surf2.values = 1000.0
    cube2 = cube1.copy()
    cube2.swapaxes()
    surf2.swapaxes()
    surf2.slice_cube(cube2, sampling="trilinear", deadtraces=True)
    plotfile = join(tmpdir, "slice_tri1__dead_cubeswap.png")
    surf2.quickplot(filename=plotfile, minmax=(-10000, 10000))
    assert ma.count_masked(surf2.values) == ndead
    tsetup.assert_almostequal(surf2.values.mean(), surf1.values.mean(), 0.01)
示例#9
0
def test_various_attrs_algorithm2(loadsfile1):
    cube1 = loadsfile1
    surf1 = xtgeo.surface_from_cube(cube1, 2540)
    surf2 = xtgeo.surface_from_cube(cube1, 2548)

    surfx = surf1.copy()
    surfx.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute="mean",
        sampling="trilinear",
        snapxy=True,
        ndiv=None,
        algorithm=2,
    )

    assert surfx.values.mean() == pytest.approx(176.44, abs=0.01)

    surfx = surf1.copy()
    surfx.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute="maxneg",
        sampling="trilinear",
        snapxy=True,
        ndiv=None,
        algorithm=2,
    )

    assert surfx.values.count() == 0  # no nonmasked elements

    surfx = surf1.copy()
    surfx.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute="sumabs",
        sampling="cube",
        snapxy=True,
        ndiv=None,
        algorithm=2,
    )

    assert surfx.values.mean() == pytest.approx(529.328, abs=0.01)
示例#10
0
def _slice_cube_window_resample(
    self,
    cube,
    zsurf,
    other,
    other_position,
    sampling,
    mask,
    zrange,
    ndiv,
    attribute,
    maskthreshold,
    showprogress,
    deadtraces,
):
    """Makes a resample from original 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,
        szsurf,
        sother,
        other_position,
        sampling,
        mask,
        zrange,
        ndiv,
        attribute,
        maskthreshold,
        showprogress,
        deadtraces,
    )

    # now resample attrs back to a copy of self
    zelf = self.copy()
    for key, _val in attrs.items():
        zelf.resample(attrs[key])
        attrs[key] = zelf.copy()

    return attrs
示例#11
0
def test_avg_surface_large_cube():

    logger.info("Make cube...")
    cube1 = xtgeo.Cube(ncol=1200, nrow=1200, nlay=1000, zori=2000, zinc=4)

    cube1.values[400:800, 400:800, :] = 12

    logger.info("Make cube... done")
    surf1 = xtgeo.surface_from_cube(cube1, 2040.0)
    surf2 = xtgeo.surface_from_cube(cube1, 2880.0)

    t1 = xtg.timer()

    _ = surf1.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute="all",
        sampling="cube",
        snapxy=True,
        ndiv=None,
        algorithm=2,
        showprogress=True,
    )
    print("Algorithm 2: ", xtg.timer(t1))

    t1 = xtg.timer()
    _ = surf1.slice_cube_window(
        cube1,
        other=surf2,
        other_position="below",
        attribute="all",
        sampling="discrete",
        snapxy=True,
        ndiv=None,
        algorithm=1,
        showprogress=True,
    )
    print("Algorithm 1: ", xtg.timer(t1))

    logger.info("Testing done")
示例#12
0
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, algorithm=2)

        assert surf1.values.mean() == pytest.approx(cube1.values[0, 0, 0],
                                                    abs=0.000001)
        print(surf1.values.mean())
        print(cube1.values[0, 0, 0])
示例#13
0
def test_single_slice_yflip_snapxy_both(loadsfile1):
    """Test cube values with exact location of maps, compared to cube samples"""
    cube1 = loadsfile1

    # checks are from spreadsheet ib_synth_iainb.odf under testdata
    chks = {
        1000: -242.064,
        1008: -226.576,
        1096: -90,
        1420: 121.104,
        2984: -211.6,
        3000: -242.064,
    }

    methods = ["nearest", "trilinear"]

    for method in methods:
        for tslice, tval in chks.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-4)