Ejemplo n.º 1
0
def test_topology():
    """Testing topology between two surfaces."""

    logger.info("Test if surfaces are similar...")

    mfile = TESTSET1

    x = xtgeo.RegularSurface(mfile)
    y = xtgeo.RegularSurface(mfile)

    status = x.compare_topology(y)
    assert status is True

    y.xori = y.xori - 100.0
    status = x.compare_topology(y)
    assert status is False
Ejemplo n.º 2
0
def test_irapbin_import1_engine_python():
    """Import Reek Irap binary using python read engine"""
    logger.info("Import and export...")

    xsurf = xtgeo.RegularSurface(TESTSET2,
                                 fformat="irap_binary",
                                 engine="python")
    assert xsurf.ncol == 1264
    assert xsurf.nrow == 2010
    tsetup.assert_almostequal(xsurf.values[11, 0], 1678.89733887, 0.001)
    tsetup.assert_almostequal(xsurf.values[1263, 2009], 1893.75, 0.01)

    xsurf2 = xtgeo.RegularSurface(TESTSET2,
                                  fformat="irap_binary",
                                  engine="cxtgeo")
    assert xsurf.values.mean() == xsurf2.values.mean()
Ejemplo n.º 3
0
def test_surface_comparisons():
    """Test the surface comparison overload"""
    surf1 = xtgeo.RegularSurface()
    id1 = id(surf1)

    surf2 = surf1.copy()

    cmp = surf1 == surf2
    np.testing.assert_equal(cmp, True)

    cmp = surf1 != surf2
    np.testing.assert_equal(cmp, False)

    cmp = surf1 <= surf2
    np.testing.assert_equal(cmp, True)

    cmp = surf1 < surf2
    np.testing.assert_equal(cmp, False)

    cmp = surf1 > surf2
    np.testing.assert_equal(cmp, False)

    surf2.values[0, 0] = -2
    cmp = surf1 == surf2
    assert bool(cmp[0, 0]) is False

    assert id(surf1) == id1
Ejemplo n.º 4
0
def test_get_randomline_frompolygon():

    fence = xtgeo.Polygons(FENCE1)
    xs = xtgeo.RegularSurface(TESTSET1)

    # get the polygon
    fspec = fence.get_fence(distance=10, nextend=2, asnumpy=False)
    tsetup.assert_almostequal(fspec.dataframe[fspec.dhname][4], 10, 1)

    fspec = fence.get_fence(distance=20, nextend=5, asnumpy=True)

    arr = xs.get_randomline(fspec)

    x = arr[:, 0]
    y = arr[:, 1]

    print(arr)
    print(arr.shape)

    if XTGSHOW:
        import matplotlib.pyplot as plt

        plt.figure()
        plt.plot(x, y)
        plt.gca().invert_yaxis()
        plt.show()
Ejemplo n.º 5
0
def test_set_values1d():
    """Test behaviour of set_values1d method"""
    srf = xtgeo.RegularSurface()
    new = srf.copy()
    assert np.ma.count_masked(new.values) == 1

    # values is a new np array; hence old mask shall not be reused
    vals = np.zeros((new.dimensions)) + 100
    vals[1, 1] = srf.undef

    new.set_values1d(vals.ravel())
    assert not np.array_equal(srf.values.mask, new.values.mask)
    assert np.ma.count_masked(new.values) == 1

    # values are modified from existing, hence mask will be additive
    new = srf.copy()
    vals = new.values.copy()
    vals[vals < 2] = new.undef
    new.values = vals
    assert np.ma.count_masked(new.values) == 2

    # values are modified from existing and set via set_values1d
    new = srf.copy()
    vals = new.values.copy()
    vals = vals.flatten()
    vals[vals < 2] = new.undef
    assert np.ma.count_masked(vals) == 1
    new.set_values1d(vals)
    assert np.ma.count_masked(new.values) == 2
Ejemplo n.º 6
0
def test_detect_fformat_hdf_stream(testpath, filename):
    stream = io.BytesIO()
    surf = xtgeo.RegularSurface(testpath / filename)
    surf.to_hdf(stream)
    sfile = xtgeo._XTGeoFile(stream)
    assert sfile.memstream is True
    assert sfile.detect_fformat() == "hdf"
Ejemplo n.º 7
0
def test_fence():
    """Test sampling a fence from a surface."""

    myfence = np.array([
        [462174.6191406, 5930073.3461914, 721.711059],
        [462429.4677734, 5930418.2055664, 720.909423],
        [462654.6738281, 5930883.9331054, 712.587158],
        [462790.8710937, 5931501.4443359, 676.873901],
        [462791.5273437, 5932040.4306640, 659.938476],
        [462480.2958984, 5932846.7387695, 622.102172],
        [462226.7070312, 5933397.8632812, 628.067138],
        [462214.4921875, 5933753.4936523, 593.260864],
        [462161.5048828, 5934327.8398437, 611.253540],
        [462325.0673828, 5934688.7519531, 626.485107],
        [462399.0429687, 5934975.2934570, 640.868774],
    ])

    logger.debug("NP:")
    logger.debug(myfence)
    print(myfence)

    x = xtgeo.RegularSurface(TESTSET1)

    newfence = x.get_fence(myfence)

    logger.debug("updated NP:")
    logger.debug(newfence)
    print(newfence)

    tsetup.assert_almostequal(newfence[1][2], 1720.9094, 0.01)
Ejemplo n.º 8
0
def test_get_randomline_frompolygon(xtgshow):
    """Test randomline with both bilinear and nearest sampling for surfaces."""
    fence = xtgeo.Polygons(FENCE1)
    xs = xtgeo.RegularSurface(TESTSET1)

    # get the polygon
    fspec = fence.get_fence(distance=10, nextend=2, asnumpy=False)
    assert_almostequal(fspec.dataframe[fspec.dhname][4], 10, 1)

    fspec = fence.get_fence(distance=20, nextend=5, asnumpy=True)

    arr1 = xs.get_randomline(fspec)
    arr2 = xs.get_randomline(fspec, sampling="nearest")

    x = arr1[:, 0]
    y1 = arr1[:, 1]
    y2 = arr2[:, 1]

    assert y1.mean() == pytest.approx(1706.7514, abs=0.001)
    assert y2.mean() == pytest.approx(1706.6995, abs=0.001)

    if xtgshow:
        import matplotlib.pyplot as plt

        plt.figure()
        plt.plot(x, y1)
        plt.plot(x, y2)
        plt.gca().invert_yaxis()
        plt.show()
Ejemplo n.º 9
0
def test_detect_fformat_hdf_to_file(tmp_path, testpath, filename):
    newfile = tmp_path / "hdf_surf.hdf"
    surf = xtgeo.RegularSurface(testpath / filename)
    surf.to_hdf(newfile)
    gfile = xtgeo._XTGeoFile(newfile)
    assert gfile.detect_fformat() == "hdf"
    assert gfile.detect_fformat(details=True) == "hdf RegularSurface xtgeo"
Ejemplo n.º 10
0
def sum_running_stats_bytestream():
    """Find avg per realisation and do a cumulative rolling mean.

    Memory consumption shall be very low.
    """

    for irel in range(NRUN):
        # load as Eclipse run; this will look for EGRID, INIT, UNRST

        print("Loading realization no {}".format(irel))

        with open(EXPATH1, "rb") as myfile:
            stream = io.BytesIO(myfile.read())

        srf = xtgeo.RegularSurface(stream, fformat="irap_binary")

        nnum = float(irel + 1)
        srf.values += irel * 1  # just to mimic variability

        if irel == 0:
            pcum = srf.values1d
        else:
            pavg = srf.values1d / nnum
            pcum = pcum * (nnum - 1) / nnum
            pcum = npma.vstack([pcum, pavg])
            pcum = pcum.sum(axis=0)

    # find the averages:
    print(pcum)
    print(pcum.mean())
    return pcum.mean()
Ejemplo n.º 11
0
def test_irapbin_import_metadatafirst_simple():
    srf = xtgeo.RegularSurface(TESTSET2, values=False)
    assert set(srf.values.data.flatten().tolist()) == {0.0}
    assert srf.ncol == 1264

    srf.load_values()
    assert srf.values.mean() == pytest.approx(1672.8242448561361)
Ejemplo n.º 12
0
def test_fence_sampling(infence, sampling, expected):
    """Test a very simple fence with different sampling methods."""
    surf = xtgeo.RegularSurface()

    myfence = np.array(infence)
    myfence[myfence == -999] = np.nan
    newfence = surf.get_fence(myfence, sampling=sampling)
    assert np.allclose(newfence[:, 2], expected, equal_nan=True)
Ejemplo n.º 13
0
def test_get_regsurff():

    sfile = TESTSET1
    logger.info("File is %s", sfile)
    for _itmp in range(20):
        rf = xtgeo.RegularSurface(sfile, fformat="irap_binary")
        assert abs(rf.values.mean() - 1698.648) < 0.01
        print(_itmp)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
def fixture_regsurf():
    """Create an xtgeo surface."""
    logger.info("Ran %s", inspect.currentframe().f_code.co_name)
    return xtgeo.RegularSurface(ncol=12,
                                nrow=10,
                                xinc=20,
                                yinc=20,
                                values=1234.0)
Ejemplo n.º 16
0
def test_create_init_mixlist():
    """Create simple Surfaces instance, initiate with a list of files."""
    top = xtgeo.RegularSurface(TESTSET1A)
    flist = [top, TESTSET1B]
    surfs = xtgeo.Surfaces(flist)

    assert isinstance(surfs.surfaces[0], xtgeo.RegularSurface)
    assert isinstance(surfs, xtgeo.Surfaces)
Ejemplo n.º 17
0
def test_ijxyz_import3():
    """Import some IJ XYZ small set yet again"""
    logger.info("Import and export...")

    xsurf = xtgeo.RegularSurface()
    xsurf.from_file(TESTSET4C, fformat="ijxyz")
    xsurf.describe()
    xsurf.to_file(os.path.join(TMPD, "ijxyz_set4c.gri"))
Ejemplo n.º 18
0
def test_dataframe_simple():
    """Get a pandas Dataframe object"""

    xmap = xtgeo.RegularSurface(TESTSET1)

    dfrc = xmap.dataframe(ijcolumns=True, order="C", activeonly=True)

    tsetup.assert_almostequal(dfrc["X_UTME"][2], 465956.274, 0.01)
Ejemplo n.º 19
0
def test_surface_file_roundtrip_stream(testpath, filename):
    stream = io.BytesIO()
    surf = xtgeo.RegularSurface(testpath / filename)
    surf.to_file(stream)
    stream_file = xtgeo._XTGeoFile(stream)

    assert stream_file.memstream is True
    assert stream_file.detect_fformat() == "irap_binary"
Ejemplo n.º 20
0
def test_irapasc_import1():
    """Import Reek Irap ascii."""
    logger.info("Import and export...")

    xsurf = xtgeo.RegularSurface(TESTSET3, fformat="irap_ascii")
    assert xsurf.ncol == 1264
    assert xsurf.nrow == 2010
    tsetup.assert_almostequal(xsurf.values[11, 0], 1678.89733887, 0.00001)
    tsetup.assert_almostequal(xsurf.values[1263, 2009], 1893.75, 0.01)
Ejemplo n.º 21
0
def test_irapasc_io_engine_python():
    """Test IO using pure python read/write"""
    xsurf1 = xtgeo.RegularSurface()

    usefile1 = os.path.join(TMPD, "surf3a.fgr")
    usefile2 = os.path.join(TMPD, "surf3b.fgr")

    print(xsurf1[1, 1])

    xsurf1.to_file(usefile1, fformat="irap_ascii", engine="cxtgeo")
    xsurf1.to_file(usefile2, fformat="irap_ascii", engine="python")

    xsurf2 = xtgeo.RegularSurface(usefile2, fformat="irap_ascii", engine="python")
    xsurf3 = xtgeo.RegularSurface(usefile2, fformat="irap_ascii", engine="cxtgeo")

    assert xsurf1.ncol == xsurf3.ncol == xsurf3.ncol

    assert xsurf1.values[1, 1] == xsurf2.values[1, 1] == xsurf3.values[1, 1]
def save_statistical_surface(fns: List[str], calculation: str) -> io.BytesIO:
    """Wrapper function to store a calculated surface as BytesIO"""
    surfaces = xtgeo.Surfaces(fns)
    if len(surfaces.surfaces) == 0:
        surface = xtgeo.RegularSurface(ncol=1, nrow=1, xinc=1,
                                       yinc=1)  # 1's as input is required
    elif calculation in ["Mean", "StdDev", "Min", "Max", "P10", "P90"]:
        # Suppress numpy warnings when surfaces have undefined z-values
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "All-NaN slice encountered")
            warnings.filterwarnings("ignore", "Mean of empty slice")
            warnings.filterwarnings("ignore",
                                    "Degrees of freedom <= 0 for slice")
            surface = get_statistical_surface(surfaces, calculation)
    else:
        surface = xtgeo.RegularSurface(ncol=1, nrow=1, xinc=1,
                                       yinc=1)  # 1's as input is required
    return io.BytesIO(surface_to_json(surface).encode())
Ejemplo n.º 23
0
def test_irapasc_import1_engine_python():
    """Import Reek Irap ascii using python read engine"""
    logger.info("Import and export...")

    xsurf = xtgeo.RegularSurface(TESTSET3, fformat="irap_ascii", engine="python")
    assert xsurf.ncol == 1264
    assert xsurf.nrow == 2010
    assert_almostequal(xsurf.values[11, 0], 1678.89733887, 0.001)
    assert_almostequal(xsurf.values[1263, 2009], 1893.75, 0.01)
Ejemplo n.º 24
0
def test_irapbin_import_use_pathib():
    """Import Reek Irap binary."""
    logger.info("Import and export...")

    pobj = Path(TESTSET2)

    xsurf = xtgeo.RegularSurface(pobj)
    assert xsurf.ncol == 1264
    assert xsurf.nrow == 2010
Ejemplo n.º 25
0
def _get_regsurff(i):
    logger.info("Start %s", i)

    sfile = TESTFILE

    logger.info("File is %s", sfile)
    rf = xtgeo.RegularSurface(sfile)
    logger.info("End %s", i)
    return rf
Ejemplo n.º 26
0
def test_fill():
    """Fill the undefined values for the surface"""

    srf = xtgeo.RegularSurface()
    srf.from_file(TESTSET1, fformat="irap_binary")

    minv1 = srf.values.min()
    tsetup.assert_almostequal(srf.values.mean(), 1698.648, 0.001)

    srf.fill()
    minv2 = srf.values.min()
    tsetup.assert_almostequal(srf.values.mean(), 1705.201, 0.001)
    tsetup.assert_almostequal(minv1, minv2, 0.000001)

    srf = xtgeo.RegularSurface()
    srf.from_file(TESTSET1, fformat="irap_binary")
    srf.fill(444)
    tsetup.assert_almostequal(srf.values.mean(), 1342.10498, 0.001)
Ejemplo n.º 27
0
def test_unrotate():
    """Change a rotated map to an unrotated instance"""

    x = xtgeo.RegularSurface()
    x.from_file(TESTSET1, fformat="irap_binary")

    logger.info(x)
    x.unrotate()
    logger.info(x)
Ejemplo n.º 28
0
def test_distance_from_point():
    """Distance from point."""

    x = xtgeo.RegularSurface()
    x.from_file(TESTSET1, fformat="irap_binary")

    x.distance_from_point(point=(464960, 7336900), azimuth=30)

    x.to_file("TMP/reek1_dist_point.gri", fformat="irap_binary")
Ejemplo n.º 29
0
def test_irapbin_import1():
    """Import Reek Irap binary."""
    logger.info("Import and export...")

    xsurf = xtgeo.RegularSurface(TESTSET2)
    assert xsurf.ncol == 1264
    assert xsurf.nrow == 2010
    tsetup.assert_almostequal(xsurf.values[11, 0], 1678.89733887, 0.00001)
    tsetup.assert_almostequal(xsurf.values[1263, 2009], 1893.75, 0.01)
    xsurf.describe()
Ejemplo n.º 30
0
def test_similarity():
    """Testing similarity of two surfaces. 0.0 means identical in
    terms of mean value.
    """

    logger.info("Test if surfaces are similar...")

    mfile = TESTSET1

    x = xtgeo.RegularSurface(mfile)
    y = xtgeo.RegularSurface(mfile)

    si = x.similarity_index(y)
    tsetup.assert_equal(si, 0.0)

    y.values = y.values * 2

    si = x.similarity_index(y)
    tsetup.assert_equal(si, 1.0)